def determine_packages_to_be_cleaned(context, include_dependents, packages): """Returns list of packages which should be cleaned, and those packages' deps. :param context: Workspace context :type context: :py:class:`catkin_tools.verbs.catkin_build.context.Context` :param packages: list of package names to be cleaned :type packages: list :returns: full list of package names to be cleaned :rtype: list """ # Get all the cached packages in the context source space workspace_packages = find_packages(context.package_metadata_path(), exclude_subspaces=True, warnings=[]) # Order the packages by topology ordered_packages = topological_order_packages(workspace_packages) # Create a dict of all packages in the workspace by name workspace_packages_by_name = dict([(pkg.name, (path, pkg)) for path, pkg in ordered_packages]) # Initialize empty output packages_to_be_cleaned = set() # Expand glob patterns in packages expanded_packages = [] for package_name in packages: expanded_packages.extend( expand_glob_package(package_name, workspace_packages_by_name)) packages = expanded_packages # Expand metapackages into their constituents for package_name in packages: # This is ok if it's orphaned if package_name not in workspace_packages_by_name: packages_to_be_cleaned.add(package_name) else: # Get the package object package = workspace_packages_by_name[package_name][1] # If metapackage, include run depends which are in the workspace if 'metapackage' in [e.tagname for e in package.exports]: for rdep in package.run_depends: if rdep.name in workspace_packages_by_name: packages_to_be_cleaned.add(rdep.name) else: packages_to_be_cleaned.add(package_name) # Determine the packages that depend on the given packages if include_dependents: for package_name in list(packages_to_be_cleaned): # Get the packages that depend on the packages to be cleaned dependents = get_recursive_build_dependents_in_workspace( package_name, ordered_packages) packages_to_be_cleaned.update([pkg.name for _, pkg in dependents]) return [ workspace_packages_by_name[n] for n in packages_to_be_cleaned if n in workspace_packages_by_name ]
def determine_packages_to_be_cleaned(context, include_dependents, packages): """Returns list of packages which should be cleaned, and those packages' deps. :param context: Workspace context :type context: :py:class:`catkin_tools.verbs.catkin_build.context.Context` :param packages: list of package names to be cleaned :type packages: list :returns: full list of package names to be cleaned :rtype: list """ # Get all the cached packages in the context source space workspace_packages = find_packages(context.package_metadata_path(), exclude_subspaces=True, warnings=[]) # Order the packages by topology ordered_packages = topological_order_packages(workspace_packages) # Create a dict of all packages in the workspace by name workspace_packages_by_name = dict([(pkg.name, (path, pkg)) for path, pkg in ordered_packages]) # Initialize empty output packages_to_be_cleaned = set() # Expand metapackages into their constituents for package_name in packages: # This is ok if it's orphaned if package_name not in workspace_packages_by_name: packages_to_be_cleaned.add(package_name) else: # Get the package object package = workspace_packages_by_name[package_name][1] # If metapackage, include run depends which are in the workspace if 'metapackage' in [e.tagname for e in package.exports]: for rdep in package.run_depends: if rdep.name in workspace_packages_by_name: packages_to_be_cleaned.add(rdep.name) else: packages_to_be_cleaned.add(package_name) # Determine the packages that depend on the given packages if include_dependents: for package_name in list(packages_to_be_cleaned): # Get the packages that depend on the packages to be cleaned dependents = get_recursive_build_dependents_in_workspace(package_name, ordered_packages) packages_to_be_cleaned.update([pkg.name for _, pkg in dependents]) return [workspace_packages_by_name[n] for n in packages_to_be_cleaned if n in workspace_packages_by_name]
def main(opts): # Load the context ctx = Context.load(opts.workspace, opts.profile, load_env=False) if not ctx: sys.exit(clr("@{rf}ERROR: Could not determine workspace.@|"), file=sys.stderr) if opts.directory: folders = opts.directory else: folders = [ctx.source_space_abs] list_entry_format = '@{pf}-@| @{cf}%s@|' if not opts.unformatted else '%s' opts.depends_on = set(opts.depends_on) if opts.depends_on else set() warnings = [] for folder in folders: try: packages = find_packages(folder, warnings=warnings) ordered_packages = topological_order_packages(packages) if ordered_packages and ordered_packages[-1][0] is None: sys.exit( clr("@{rf}ERROR: Circular dependency within packages:@| " + ordered_packages[-1][1]), file=sys.stderr) packages_by_name = { pkg.name: (pth, pkg) for pth, pkg in ordered_packages } if opts.depends_on or opts.rdepends_on: dependents = set() for pth, pkg in ordered_packages: is_dep = opts.depends_on.intersection( [p.name for p in pkg.build_depends + pkg.run_depends]) if is_dep: dependents.add(pkg.name) for pth, pkg in [ packages_by_name.get(n) for n in opts.rdepends_on ]: if pkg is None: continue rbd = get_recursive_build_dependents_in_workspace( pkg.name, ordered_packages) rrd = get_recursive_run_dependents_in_workspace( pkg.name, ordered_packages) dependents.update([p.name for _, p in rbd]) dependents.update([p.name for _, p in rrd]) filtered_packages = [(pth, pkg) for pth, pkg in ordered_packages if pkg.name in dependents] elif opts.this: this_package = find_enclosing_package( search_start_path=getcwd(), ws_path=ctx.workspace, warnings=[]) if this_package is None: sys.exit(1) if this_package in packages_by_name: filtered_packages = [packages_by_name[this_package]] else: filtered_packages = [] else: filtered_packages = ordered_packages for pkg_pth, pkg in filtered_packages: print(clr(list_entry_format % pkg.name)) if opts.rdeps: build_deps = [ p for dp, p in get_recursive_build_depends_in_workspace( pkg, ordered_packages) ] run_deps = [ p for dp, p in get_recursive_run_depends_in_workspace( [pkg], ordered_packages) ] else: build_deps = [ dep for dep in pkg.build_depends if dep.evaluated_condition ] run_deps = [ dep for dep in pkg.run_depends if dep.evaluated_condition ] if opts.deps or opts.rdeps: if len(build_deps) > 0: print(clr(' @{yf}build_depend:@|')) for dep in build_deps: print(clr(' @{pf}-@| %s' % dep.name)) if len(run_deps) > 0: print(clr(' @{yf}run_depend:@|')) for dep in run_deps: print(clr(' @{pf}-@| %s' % dep.name)) except InvalidPackage as ex: sys.exit( clr("@{rf}Error:@| The file %s is an invalid package.xml file." " See below for details:\n\n%s" % (ex.package_path, ex.msg))) # Print out warnings if not opts.quiet: for warning in warnings: print(clr("@{yf}Warning:@| %s" % warning), file=sys.stderr)
def main(opts): # Load the context ctx = Context.load(opts.workspace, opts.profile, load_env=False) if not ctx: print(clr("@{rf}ERROR: Could not determine workspace.@|"), file=sys.stderr) sys.exit(1) folders = [ctx.source_space_abs] list_entry_format = '@{pf}-@| @{cf}%s@|' if not opts.unformatted else '%s' opts.depends_on = set(opts.depends_on) if opts.depends_on else set() warnings = [] for folder in folders: try: packages = find_packages(folder, warnings=warnings) ordered_packages = topological_order_packages(packages) packages_by_name = {pkg.name: (pth, pkg) for pth, pkg in ordered_packages} if opts.depends_on or opts.rdepends_on: dependents = set() for pth, pkg in ordered_packages: is_dep = opts.depends_on.intersection([ p.name for p in pkg.build_depends + pkg.run_depends]) if is_dep: dependents.add(pkg.name) for pth, pkg in [packages_by_name.get(n) for n in opts.rdepends_on]: if pkg is None: continue rbd = get_recursive_build_dependents_in_workspace(pkg.name, ordered_packages) rrd = get_recursive_run_dependents_in_workspace(pkg.name, ordered_packages) dependents.update([p.name for _, p in rbd]) dependents.update([p.name for _, p in rrd]) filtered_packages = [ (pth, pkg) for pth, pkg in ordered_packages if pkg.name in dependents] elif opts.this: this_package = find_enclosing_package( search_start_path=getcwd(), ws_path=ctx.workspace, warnings=[]) if this_package is None: sys.exit(1) if this_package in packages_by_name: filtered_packages = [packages_by_name[this_package]] else: filtered_packages = [] else: filtered_packages = ordered_packages for pkg_pth, pkg in filtered_packages: print(clr(list_entry_format % pkg.name)) if opts.rdeps: build_deps = [p for dp, p in get_recursive_build_depends_in_workspace(pkg, ordered_packages)] run_deps = [p for dp, p in get_recursive_run_depends_in_workspace([pkg], ordered_packages)] else: build_deps = pkg.build_depends run_deps = pkg.run_depends if opts.deps or opts.rdeps: if len(build_deps) > 0: print(clr(' @{yf}build_depend:@|')) for dep in build_deps: print(clr(' @{pf}-@| %s' % dep.name)) if len(run_deps) > 0: print(clr(' @{yf}run_depend:@|')) for dep in run_deps: print(clr(' @{pf}-@| %s' % dep.name)) except InvalidPackage as ex: message = '\n'.join(ex.args) print(clr("@{rf}Error:@| The directory %s contains an invalid package." " See below for details:\n\n%s" % (folder, message))) # Print out warnings if not opts.quiet: for warning in warnings: print(clr("@{yf}Warning:@| %s" % warning), file=sys.stderr)