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): # Context-aware args if opts.build_this or opts.start_with_this: # Determine the enclosing package try: ws_path = find_enclosing_workspace(getcwd()) # Suppress warnings since this won't necessaraly find all packages # in the workspace (it stops when it finds one package), and # relying on it for warnings could mislead people. this_package = find_enclosing_package(search_start_path=getcwd(), ws_path=ws_path, warnings=[]) except (InvalidPackage, RuntimeError): this_package = None # Handle context-based package building if opts.build_this: if this_package: opts.packages += [this_package] else: sys.exit( "catkin build: --this was specified, but this directory is not in a catkin package." ) # If --start--with was used without any packages and --this was specified, start with this package if opts.start_with_this: if this_package: opts.start_with = this_package else: sys.exit( "catkin build: --this was specified, but this directory is not in a catkin package." ) if opts.no_deps and not opts.packages: sys.exit("With --no-deps, you must specify packages to build.") # Load the context ctx = Context.load(opts.workspace, opts.profile, opts, append=True) # Initialize the build configuration make_args, makeflags, cli_flags, jobserver = configure_make_args( ctx.make_args, ctx.use_internal_make_jobserver) # Set the jobserver memory limit if jobserver and opts.mem_limit: log( clr("@!@{pf}EXPERIMENTAL: limit memory to '%s'@|" % str(opts.mem_limit))) # At this point psuitl will be required, check for it and bail out if not set try: import psutil # noqa except ImportError as exc: log("Could not import psutil, but psutil is required when using --mem-limit." ) log("Please either install psutil or avoid using --mem-limit.") sys.exit("Exception: {0}".format(exc)) set_jobserver_max_mem(opts.mem_limit) ctx.make_args = make_args # Load the environment of the workspace to extend if ctx.extend_path is not None: try: load_resultspace_environment(ctx.extend_path) except IOError as exc: log( clr("@!@{rf}Error:@| Unable to extend workspace from \"%s\": %s" % (ctx.extend_path, exc.message))) return 1 # Display list and leave the file system untouched if opts.dry_run: dry_run(ctx, opts.packages, opts.no_deps, opts.start_with) return # Check if the context is valid before writing any metadata if not ctx.source_space_exists(): print("catkin build: error: Unable to find source space `%s`" % ctx.source_space_abs) return 1 # Always save the last context under the build verb update_metadata(ctx.workspace, ctx.profile, 'build', ctx.get_stored_dict()) build_metadata = get_metadata(ctx.workspace, ctx.profile, 'build') if build_metadata.get('needs_force', False): opts.force_cmake = True update_metadata(ctx.workspace, ctx.profile, 'build', {'needs_force': False}) # Save the context as the configuration if opts.save_config: Context.save(ctx) start = time.time() try: return build_isolated_workspace( ctx, packages=opts.packages, start_with=opts.start_with, no_deps=opts.no_deps, jobs=opts.parallel_jobs, force_cmake=opts.force_cmake, force_color=opts.force_color, quiet=not opts.verbose, interleave_output=opts.interleave_output, no_status=opts.no_status, limit_status_rate=opts.limit_status_rate, lock_install=not opts.no_install_lock, no_notify=opts.no_notify, continue_on_failure=opts.continue_on_failure, summarize_build=opts.summarize # Can be True, False, or None ) finally: log("[build] Runtime: {0}".format( format_time_delta(time.time() - start)))
def main(opts): # Context-aware args if opts.build_this or opts.start_with_this: # Determine the enclosing package try: this_package = find_enclosing_package() except InvalidPackage: pass # Handle context-based package building if opts.build_this: if this_package: opts.packages += [this_package] else: sys.exit( "catkin build: --this was specified, but this directory is not in a catkin package." ) # If --start--with was used without any packages and --this was specified, start with this package if opts.start_with_this: if this_package: opts.start_with = this_package else: sys.exit( "catkin build: --this was specified, but this directory is not in a catkin package." ) if opts.no_deps and not opts.packages: sys.exit("With --no-deps, you must specify packages to build.") if not opts.force_color and not is_tty(sys.stdout): set_color(False) # Load the context ctx = Context.Load(opts.workspace, opts.profile, opts) # Load the environment of the workspace to extend if ctx.extend_path is not None: try: load_resultspace_environment(ctx.extend_path) except IOError as exc: log( clr("@!@{rf}Error:@| Unable to extend workspace from \"%s\": %s" % (ctx.extend_path, exc.message))) return 1 # Display list and leave the filesystem untouched if opts.dry_run: dry_run(ctx, opts.packages, opts.no_deps, opts.start_with) return # Check if the context is valid before writing any metadata if not ctx.source_space_exists(): print("catkin build: error: Unable to find source space `%s`" % ctx.source_space_abs) return 1 # Always save the last context under the build verb update_metadata(ctx.workspace, ctx.profile, 'build', ctx.get_stored_dict()) build_metadata = get_metadata(ctx.workspace, ctx.profile, 'build') if build_metadata.get('needs_force', False): opts.force_cmake = True update_metadata(ctx.workspace, ctx.profile, 'build', {'needs_force': False}) # Save the context as the configuration if opts.save_config: Context.Save(ctx) start = time.time() try: return build_isolated_workspace( ctx, packages=opts.packages, start_with=opts.start_with, no_deps=opts.no_deps, jobs=opts.parallel_jobs, force_cmake=opts.force_cmake, force_color=opts.force_color, quiet=not opts.verbose, interleave_output=opts.interleave_output, no_status=opts.no_status, limit_status_rate=opts.limit_status_rate, lock_install=not opts.no_install_lock, no_notify=opts.no_notify) finally: log("[build] Runtime: {0}".format( format_time_delta(time.time() - start)))
def main(opts): # Check for develdebug mode if opts.develdebug is not None: os.environ['TROLLIUSDEBUG'] = opts.develdebug.lower() logging.basicConfig(level=opts.develdebug.upper()) # Set color options if (opts.force_color or is_tty(sys.stdout)) and not opts.no_color: set_color(True) else: set_color(False) # Context-aware args if opts.build_this or opts.start_with_this: # Determine the enclosing package try: ws_path = find_enclosing_workspace(getcwd()) # Suppress warnings since this won't necessaraly find all packages # in the workspace (it stops when it finds one package), and # relying on it for warnings could mislead people. this_package = find_enclosing_package( search_start_path=getcwd(), ws_path=ws_path, warnings=[]) except (InvalidPackage, RuntimeError): this_package = None # Handle context-based package building if opts.build_this: if this_package: opts.packages += [this_package] else: sys.exit( "[build] Error: In order to use --this, the current directory must be part of a catkin package.") # If --start--with was used without any packages and --this was specified, start with this package if opts.start_with_this: if this_package: opts.start_with = this_package else: sys.exit( "[build] Error: In order to use --this, the current directory must be part of a catkin package.") if opts.no_deps and not opts.packages and not opts.unbuilt: sys.exit(clr("[build] @!@{rf}Error:@| With --no-deps, you must specify packages to build.")) # Load the context ctx = Context.load(opts.workspace, opts.profile, opts, append=True) # Initialize the build configuration make_args, makeflags, cli_flags, jobserver = configure_make_args( ctx.make_args, ctx.jobs_args, ctx.use_internal_make_jobserver) # Set the jobserver memory limit if jobserver and opts.mem_limit: log(clr("@!@{pf}EXPERIMENTAL: limit memory to '%s'@|" % str(opts.mem_limit))) # At this point psuitl will be required, check for it and bail out if not set try: import psutil # noqa except ImportError as exc: log("Could not import psutil, but psutil is required when using --mem-limit.") log("Please either install psutil or avoid using --mem-limit.") sys.exit("Exception: {0}".format(exc)) job_server.set_max_mem(opts.mem_limit) ctx.make_args = make_args # Load the environment of the workspace to extend if ctx.extend_path is not None: try: load_resultspace_environment(ctx.extend_path) except IOError as exc: sys.exit(clr("[build] @!@{rf}Error:@| Unable to extend workspace from \"%s\": %s" % (ctx.extend_path, exc.message))) # Check if the context is valid before writing any metadata if not ctx.source_space_exists(): sys.exit(clr("[build] @!@{rf}Error:@| Unable to find source space `%s`") % ctx.source_space_abs) # ensure the build space was previously built by catkin_tools previous_tool = get_previous_tool_used_on_the_space(ctx.build_space_abs) if previous_tool is not None and previous_tool != 'catkin build': if opts.override_build_tool_check: log(clr( "@{yf}Warning: build space at '%s' was previously built by '%s', " "but --override-build-tool-check was passed so continuing anyways." % (ctx.build_space_abs, previous_tool))) else: sys.exit(clr( "@{rf}The build space at '%s' was previously built by '%s'. " "Please remove the build space or pick a different build space." % (ctx.build_space_abs, previous_tool))) # the build space will be marked as catkin build's if dry run doesn't return # ensure the devel space was previously built by catkin_tools previous_tool = get_previous_tool_used_on_the_space(ctx.devel_space_abs) if previous_tool is not None and previous_tool != 'catkin build': if opts.override_build_tool_check: log(clr( "@{yf}Warning: devel space at '%s' was previously built by '%s', " "but --override-build-tool-check was passed so continuing anyways." % (ctx.devel_space_abs, previous_tool))) else: sys.exit(clr( "@{rf}The devel space at '%s' was previously built by '%s'. " "Please remove the devel space or pick a different devel space." % (ctx.devel_space_abs, previous_tool))) # the devel space will be marked as catkin build's if dry run doesn't return # Display list and leave the file system untouched if opts.dry_run: # TODO: Add unbuilt dry_run(ctx, opts.packages, opts.no_deps, opts.start_with) return # Print the build environment for a given package and leave the filesystem untouched if opts.get_env: return print_build_env(ctx, opts.get_env[0]) # Now mark the build and devel spaces as catkin build's since dry run didn't return. mark_space_as_built_by(ctx.build_space_abs, 'catkin build') mark_space_as_built_by(ctx.devel_space_abs, 'catkin build') # Get the last build context build_metadata = get_metadata(ctx.workspace, ctx.profile, 'build') if build_metadata.get('cmake_args') != ctx.cmake_args or build_metadata.get('cmake_args') != opts.cmake_args: opts.force_cmake = True if build_metadata.get('needs_force', False): opts.force_cmake = True update_metadata(ctx.workspace, ctx.profile, 'build', {'needs_force': False}) # Always save the last context under the build verb update_metadata(ctx.workspace, ctx.profile, 'build', ctx.get_stored_dict()) # Save the context as the configuration if opts.save_config: Context.save(ctx) # Get parallel toplevel jobs try: parallel_jobs = int(opts.parallel_jobs) except TypeError: parallel_jobs = None # Set VERBOSE environment variable if opts.verbose: os.environ['VERBOSE'] = '1' return build_isolated_workspace( ctx, packages=opts.packages, start_with=opts.start_with, no_deps=opts.no_deps, unbuilt=opts.unbuilt, n_jobs=parallel_jobs, force_cmake=opts.force_cmake, pre_clean=opts.pre_clean, force_color=opts.force_color, quiet=not opts.verbose, interleave_output=opts.interleave_output, no_status=opts.no_status, limit_status_rate=opts.limit_status_rate, lock_install=not opts.no_install_lock, no_notify=opts.no_notify, continue_on_failure=opts.continue_on_failure, summarize_build=opts.summarize # Can be True, False, or None )
def main(opts): # Context-aware args if opts.build_this or opts.start_with_this: # Determine the enclosing package try: this_package = find_enclosing_package() except InvalidPackage: pass # Handle context-based package building if opts.build_this: if this_package: opts.packages += [this_package] else: sys.exit("catkin build: --this was specified, but this directory is not contained by a catkin package.") # If --start--with was used without any packages and --this was specified, start with this package if opts.start_with_this: if this_package: opts.start_with = this_package else: sys.exit("catkin build: --this was specified, but this directory is not contained by a catkin package.") if opts.no_deps and not opts.packages: sys.exit("With --no-deps, you must specify packages to build.") if not opts.force_color and not is_tty(sys.stdout): set_color(False) # Load the context ctx = Context.Load(opts.workspace, opts.profile, opts) # Load the environment of the workspace to extend if ctx.extend_path is not None: try: load_resultspace_environment(ctx.extend_path) except IOError as exc: log(clr("@!@{rf}Error:@| Unable to extend workspace from \"%s\": %s" % (ctx.extend_path, exc.message))) return 1 # Display list and leave the filesystem untouched if opts.dry_run: dry_run(ctx, opts.packages, opts.no_deps, opts.start_with) return # Check if the context is valid before writing any metadata if not ctx.source_space_exists(): print("catkin build: error: Unable to find source space `%s`" % ctx.source_space_abs) return 1 # Always save the last context under the build verb update_metadata(ctx.workspace, ctx.profile, 'build', ctx.get_stored_dict()) build_metadata = get_metadata(ctx.workspace, ctx.profile, 'build') if build_metadata.get('needs_force', False): opts.force_cmake = True update_metadata(ctx.workspace, ctx.profile, 'build', {'needs_force': False}) # Save the context as the configuration if opts.save_config: Context.Save(ctx) start = time.time() try: return build_isolated_workspace( ctx, packages=opts.packages, start_with=opts.start_with, no_deps=opts.no_deps, jobs=opts.parallel_jobs, force_cmake=opts.force_cmake, force_color=opts.force_color, quiet=not opts.verbose, interleave_output=opts.interleave_output, no_status=opts.no_status, lock_install=not opts.no_install_lock, no_notify=opts.no_notify ) finally: log("[build] Runtime: {0}".format(format_time_delta(time.time() - start)))
def main(opts): # Context-aware args if opts.build_this or opts.start_with_this: # Determine the enclosing package try: ws_path = find_enclosing_workspace(getcwd()) # Suppress warnings since this won't necessaraly find all packages # in the workspace (it stops when it finds one package), and # relying on it for warnings could mislead people. this_package = find_enclosing_package( search_start_path=getcwd(), ws_path=ws_path, warnings=[]) except (InvalidPackage, RuntimeError): this_package = None # Handle context-based package building if opts.build_this: if this_package: opts.packages += [this_package] else: sys.exit("catkin build: --this was specified, but this directory is not in a catkin package.") # If --start--with was used without any packages and --this was specified, start with this package if opts.start_with_this: if this_package: opts.start_with = this_package else: sys.exit("catkin build: --this was specified, but this directory is not in a catkin package.") if opts.no_deps and not opts.packages: sys.exit("With --no-deps, you must specify packages to build.") # Load the context ctx = Context.load(opts.workspace, opts.profile, opts, append=True) # Initialize the build configuration make_args, makeflags, cli_flags, jobserver = configure_make_args(ctx.make_args, ctx.use_internal_make_jobserver) # Set the jobserver memory limit if jobserver and opts.mem_limit: log(clr("@!@{pf}EXPERIMENTAL: limit memory to '%s'@|" % str(opts.mem_limit))) # At this point psuitl will be required, check for it and bail out if not set try: import psutil # noqa except ImportError as exc: log("Could not import psutil, but psutil is required when using --mem-limit.") log("Please either install psutil or avoid using --mem-limit.") sys.exit("Exception: {0}".format(exc)) set_jobserver_max_mem(opts.mem_limit) ctx.make_args = make_args # Load the environment of the workspace to extend if ctx.extend_path is not None: try: load_resultspace_environment(ctx.extend_path) except IOError as exc: log(clr("@!@{rf}Error:@| Unable to extend workspace from \"%s\": %s" % (ctx.extend_path, exc.message))) return 1 # Display list and leave the file system untouched if opts.dry_run: dry_run(ctx, opts.packages, opts.no_deps, opts.start_with) return # Check if the context is valid before writing any metadata if not ctx.source_space_exists(): print("catkin build: error: Unable to find source space `%s`" % ctx.source_space_abs) return 1 # Always save the last context under the build verb update_metadata(ctx.workspace, ctx.profile, 'build', ctx.get_stored_dict()) build_metadata = get_metadata(ctx.workspace, ctx.profile, 'build') if build_metadata.get('needs_force', False): opts.force_cmake = True update_metadata(ctx.workspace, ctx.profile, 'build', {'needs_force': False}) # Save the context as the configuration if opts.save_config: Context.save(ctx) start = time.time() try: return build_isolated_workspace( ctx, packages=opts.packages, start_with=opts.start_with, no_deps=opts.no_deps, jobs=opts.parallel_jobs, force_cmake=opts.force_cmake, force_color=opts.force_color, quiet=not opts.verbose, interleave_output=opts.interleave_output, no_status=opts.no_status, limit_status_rate=opts.limit_status_rate, lock_install=not opts.no_install_lock, no_notify=opts.no_notify, continue_on_failure=opts.continue_on_failure, summarize_build=opts.summarize # Can be True, False, or None ) finally: log("[build] Runtime: {0}".format(format_time_delta(time.time() - start)))
def main(opts): # Check for develdebug mode if opts.develdebug is not None: os.environ['TROLLIUSDEBUG'] = opts.develdebug.lower() logging.basicConfig(level=opts.develdebug.upper()) # Set color options opts.force_color = os.environ.get('CATKIN_TOOLS_FORCE_COLOR', opts.force_color) if (opts.force_color or is_tty(sys.stdout)) and not opts.no_color: set_color(True) else: set_color(False) # Context-aware args if opts.build_this or opts.start_with_this: # Determine the enclosing package try: ws_path = find_enclosing_workspace(getcwd()) # Suppress warnings since this won't necessaraly find all packages # in the workspace (it stops when it finds one package), and # relying on it for warnings could mislead people. this_package = find_enclosing_package(search_start_path=getcwd(), ws_path=ws_path, warnings=[]) except (InvalidPackage, RuntimeError): this_package = None # Handle context-based package building if opts.build_this: if this_package: opts.packages += [this_package] else: sys.exit( "[build] Error: In order to use --this, the current directory must be part of a catkin package." ) # If --start--with was used without any packages and --this was specified, start with this package if opts.start_with_this: if this_package: opts.start_with = this_package else: sys.exit( "[build] Error: In order to use --this, the current directory must be part of a catkin package." ) if opts.no_deps and not opts.packages and not opts.unbuilt: sys.exit( clr("[build] @!@{rf}Error:@| With --no-deps, you must specify packages to build." )) # Load the context ctx = Context.load(opts.workspace, opts.profile, opts, append=True) # Initialize the build configuration make_args, makeflags, cli_flags, jobserver = configure_make_args( ctx.make_args, ctx.jobs_args, ctx.use_internal_make_jobserver) # Set the jobserver memory limit if jobserver and opts.mem_limit: log( clr("@!@{pf}EXPERIMENTAL: limit memory to '%s'@|" % str(opts.mem_limit))) # At this point psuitl will be required, check for it and bail out if not set try: import psutil # noqa except ImportError as exc: log("Could not import psutil, but psutil is required when using --mem-limit." ) log("Please either install psutil or avoid using --mem-limit.") sys.exit("Exception: {0}".format(exc)) job_server.set_max_mem(opts.mem_limit) ctx.make_args = make_args # Load the environment of the workspace to extend if ctx.extend_path is not None: try: load_resultspace_environment(ctx.extend_path) except IOError as exc: sys.exit( clr("[build] @!@{rf}Error:@| Unable to extend workspace from \"%s\": %s" % (ctx.extend_path, exc.message))) # Check if the context is valid before writing any metadata if not ctx.source_space_exists(): sys.exit( clr("[build] @!@{rf}Error:@| Unable to find source space `%s`") % ctx.source_space_abs) # ensure the build space was previously built by catkin_tools previous_tool = get_previous_tool_used_on_the_space(ctx.build_space_abs) if previous_tool is not None and previous_tool != 'catkin build': if opts.override_build_tool_check: log( clr("@{yf}Warning: build space at '%s' was previously built by '%s', " "but --override-build-tool-check was passed so continuing anyways." % (ctx.build_space_abs, previous_tool))) else: sys.exit( clr("@{rf}The build space at '%s' was previously built by '%s'. " "Please remove the build space or pick a different build space." % (ctx.build_space_abs, previous_tool))) # the build space will be marked as catkin build's if dry run doesn't return # ensure the devel space was previously built by catkin_tools previous_tool = get_previous_tool_used_on_the_space(ctx.devel_space_abs) if previous_tool is not None and previous_tool != 'catkin build': if opts.override_build_tool_check: log( clr("@{yf}Warning: devel space at '%s' was previously built by '%s', " "but --override-build-tool-check was passed so continuing anyways." % (ctx.devel_space_abs, previous_tool))) else: sys.exit( clr("@{rf}The devel space at '%s' was previously built by '%s'. " "Please remove the devel space or pick a different devel space." % (ctx.devel_space_abs, previous_tool))) # the devel space will be marked as catkin build's if dry run doesn't return # Display list and leave the file system untouched if opts.dry_run: # TODO: Add unbuilt dry_run(ctx, opts.packages, opts.no_deps, opts.start_with) return # Print the build environment for a given package and leave the filesystem untouched if opts.get_env: return print_build_env(ctx, opts.get_env[0]) # Now mark the build and devel spaces as catkin build's since dry run didn't return. mark_space_as_built_by(ctx.build_space_abs, 'catkin build') mark_space_as_built_by(ctx.devel_space_abs, 'catkin build') # Get the last build context build_metadata = get_metadata(ctx.workspace, ctx.profile, 'build') # Force cmake if the CMake arguments have changed if build_metadata.get('cmake_args') != ctx.cmake_args: opts.force_cmake = True # Check the devel layout compatibility last_devel_layout = build_metadata.get('devel_layout', ctx.devel_layout) if last_devel_layout != ctx.devel_layout: sys.exit( clr("@{rf}@!Error:@|@{rf} The current devel space layout, `{}`," "is incompatible with the configured layout, `{}`.@|").format( last_devel_layout, ctx.devel_layout)) # Check if some other verb has changed the workspace in such a way that it needs to be forced if build_metadata.get('needs_force', False): opts.force_cmake = True update_metadata(ctx.workspace, ctx.profile, 'build', {'needs_force': False}) # Always save the last context under the build verb update_metadata(ctx.workspace, ctx.profile, 'build', ctx.get_stored_dict()) # Save the context as the configuration if opts.save_config: Context.save(ctx) # Get parallel toplevel jobs try: parallel_jobs = int(opts.parallel_jobs) except TypeError: parallel_jobs = None # Set VERBOSE environment variable if opts.verbose: os.environ['VERBOSE'] = '1' return build_isolated_workspace( ctx, packages=opts.packages, start_with=opts.start_with, no_deps=opts.no_deps, unbuilt=opts.unbuilt, n_jobs=parallel_jobs, force_cmake=opts.force_cmake, pre_clean=opts.pre_clean, force_color=opts.force_color, quiet=not opts.verbose, interleave_output=opts.interleave_output, no_status=opts.no_status, limit_status_rate=opts.limit_status_rate, lock_install=not opts.no_install_lock, no_notify=opts.no_notify, continue_on_failure=opts.continue_on_failure, summarize_build=opts.summarize # Can be True, False, or None )
def clean_profile(opts, profile): # Load the context ctx = Context.load(opts.workspace, profile, opts, strict=True, load_env=False) if not ctx: if not opts.workspace: log(clr("[clean] @!@{rf}Error:@| The current or desired workspace could not be " "determined. Please run `catkin clean` from within a catkin " "workspace or specify the workspace explicitly with the " "`--workspace` option.")) else: log(clr("[clean] @!@{rf}Error:@| Could not clean workspace \"%s\" because it " "either does not exist or it has no catkin_tools metadata." % opts.workspace)) return False profile = ctx.profile # Check if the user wants to do something explicit actions = ['spaces', 'packages', 'clean_this', 'orphans', 'deinit', 'setup_files'] paths = {} # noqa paths_exists = {} # noqa paths['install'] = ( os.path.join(ctx.destdir, ctx.install_space_abs.lstrip(os.sep)) if ctx.destdir else ctx.install_space_abs) paths_exists['install'] = os.path.exists(paths['install']) and os.path.isdir(paths['install']) for space in Context.SPACES.keys(): if space in paths: continue paths[space] = getattr(ctx, '{}_space_abs'.format(space)) paths_exists[space] = getattr(ctx, '{}_space_exists'.format(space))() # Default is to clean all products for this profile no_specific_action = not any([ v for (k, v) in vars(opts).items() if k in actions]) clean_all = opts.deinit or no_specific_action # Initialize action options if clean_all: opts.spaces = [k for k in Context.SPACES.keys() if k != 'source'] # Make sure the user intends to clean everything spaces_to_clean_msgs = [] if opts.spaces and not (opts.yes or opts.dry_run): for space in opts.spaces: if getattr(ctx, '{}_space_exists'.format(space))(): space_name = Context.SPACES[space]['space'] space_abs = getattr(ctx, '{}_space_abs'.format(space)) spaces_to_clean_msgs.append(clr("[clean] {:14} @{yf}{}").format(space_name + ':', space_abs)) if len(spaces_to_clean_msgs) == 0 and not opts.deinit: log("[clean] Nothing to be cleaned for profile: `{}`".format(profile)) return True if len(spaces_to_clean_msgs) > 0: log("") log(clr("[clean] @!@{yf}Warning:@| This will completely remove the " "following directories. (Use `--yes` to skip this check)")) for msg in spaces_to_clean_msgs: log(msg) try: yes = yes_no_loop( "\n[clean] Are you sure you want to completely remove the directories listed above?") if not yes: log(clr("[clean] Not removing any workspace directories for" " this profile.")) return True except KeyboardInterrupt: log("\n[clean] No actions performed.") sys.exit(0) # Initialize flag to be used on the next invocation needs_force = False try: for space in opts.spaces: if space == 'devel': # Remove all develspace files if paths_exists['devel']: log("[clean] Removing {}: {}".format(Context.SPACES['devel']['space'], ctx.devel_space_abs)) if not opts.dry_run: safe_rmtree(ctx.devel_space_abs, ctx.workspace, opts.force) # Clear the cached metadata from the last build run _, build_metadata_file = get_metadata_paths(ctx.workspace, profile, 'build') if os.path.exists(build_metadata_file): os.unlink(build_metadata_file) # Clear the cached packages data, if it exists packages_metadata_path = ctx.package_metadata_path() if os.path.exists(packages_metadata_path): safe_rmtree(packages_metadata_path, ctx.workspace, opts.force) else: if paths_exists[space]: space_name = Context.SPACES[space]['space'] space_path = paths[space] log("[clean] Removing {}: {}".format(space_name, space_path)) if not opts.dry_run: safe_rmtree(space_path, ctx.workspace, opts.force) # Setup file removal if opts.setup_files: if paths_exists['devel']: log("[clean] Removing setup files from {}: {}".format(Context.SPACES['devel']['space'], paths['devel'])) opts.packages.append('catkin') opts.packages.append('catkin_tools_prebuild') else: log("[clean] No {} exists, no setup files to clean.".format(Context.SPACES['devel']['space'])) # Find orphaned packages if ctx.link_devel or ctx.isolate_devel and not ('devel' in opts.spaces or 'build' in opts.spaces): if opts.orphans: if os.path.exists(ctx.build_space_abs): log("[clean] Determining orphaned packages...") # Get all existing packages in source space and the # Suppress warnings since this is looking for packages which no longer exist found_source_packages = [ pkg.name for (path, pkg) in find_packages(ctx.source_space_abs, warnings=[]).items()] built_packages = [ pkg.name for (path, pkg) in find_packages(ctx.package_metadata_path(), warnings=[]).items()] # Look for orphaned products in the build space orphans = [p for p in built_packages if (p not in found_source_packages and p != 'catkin_tools_prebuild')] if len(orphans) > 0: opts.packages.extend(list(orphans)) else: log("[clean] No orphans in the workspace.") else: log("[clean] No {} exists, no potential for orphans.".format(Context.SPACES['build']['space'])) # Remove specific packages if len(opts.packages) > 0 or opts.clean_this: # Determine the enclosing package try: ws_path = find_enclosing_workspace(getcwd()) # Suppress warnings since this won't necessarily find all packages # in the workspace (it stops when it finds one package), and # relying on it for warnings could mislead people. this_package = find_enclosing_package( search_start_path=getcwd(), ws_path=ws_path, warnings=[]) except InvalidPackage as ex: sys.exit(clr("[clean] @!@{rf}Error:@| The file {} is an invalid package.xml file." " See below for details:\n\n{}").format(ex.package_path, ex.msg)) # Handle context-based package cleaning if opts.clean_this: if this_package: opts.packages += [this_package] else: sys.exit( clr("[clean] @!@{rf}Error:@| In order to use --this, the current directory" " must be part of a catkin package.")) try: # Clean the packages needs_force = clean_packages( ctx, opts.packages, opts.dependents, opts.verbose, opts.dry_run) except KeyboardInterrupt: wide_log("[clean] User interrupted!") return False elif opts.orphans or len(opts.packages) > 0 or opts.clean_this: log(clr("[clean] @!@{rf}Error:@| Individual packages cannot be cleaned from " "workspaces with merged develspaces, use a symbolically-linked " "or isolated develspace instead.")) except: # noqa: E722 # Silencing E722 here since we immediately re-raise the exception. log("[clean] Failed to clean profile `{}`".format(profile)) needs_force = True raise finally: if needs_force: log(clr( "[clean] @/@!Note:@| @/Parts of the workspace have been cleaned which will " "necessitate re-configuring CMake on the next build.@|")) update_metadata(ctx.workspace, ctx.profile, 'build', {'needs_force': True}) return True
def main(opts): # Set color options opts.force_color = os.environ.get('CATKIN_TOOLS_FORCE_COLOR', opts.force_color) if (opts.force_color or is_tty(sys.stdout)) and not opts.no_color: set_color(True) else: set_color(False) # Context-aware args if opts.build_this: # Determine the enclosing package try: ws_path = find_enclosing_workspace(getcwd()) # Suppress warnings since this won't necessarily find all packages # in the workspace (it stops when it finds one package), and # relying on it for warnings could mislead people. this_package = find_enclosing_package(search_start_path=getcwd(), ws_path=ws_path, warnings=[]) except InvalidPackage as ex: sys.exit( clr("[test] @!@{rf}Error:@| The file {} is an invalid package.xml file." " See below for details:\n\n{}").format( ex.package_path, ex.msg)) # Handle context-based package building if this_package: opts.packages += [this_package] else: sys.exit( clr("[test] @!@{rf}Error:@| In order to use --this, " "the current directory must be part of a catkin package.")) # Load the context ctx = Context.load(opts.workspace, opts.profile, opts, append=True) # Load the environment of the workspace to extend if ctx.extend_path is not None: try: load_resultspace_environment(ctx.extend_path) except IOError as exc: sys.exit( clr("[test] @!@{rf}Error:@| Unable to extend workspace from \"{}\": {}" ).format(ctx.extend_path, str(exc))) # Check if the context is valid before writing any metadata if not ctx.source_space_exists(): sys.exit( clr("[test] @!@{rf}Error:@| Unable to find source space `{}`"). format(ctx.source_space_abs)) # Extract make arguments make_args, _, _, _ = configure_make_args(ctx.make_args, ctx.jobs_args, ctx.use_internal_make_jobserver) ctx.make_args = make_args # Get parallel toplevel jobs try: parallel_jobs = int(opts.parallel_jobs) except TypeError: parallel_jobs = None # Set VERBOSE environment variable if opts.verbose and 'VERBOSE' not in os.environ: os.environ['VERBOSE'] = '1' # Get test targets catkin_test_target = 'run_tests' cmake_test_target = 'test' if opts.test_target: catkin_test_target = opts.test_target cmake_test_target = opts.test_target if opts.catkin_test_target: catkin_test_target = opts.catkin_test_target return test_workspace( ctx, packages=opts.packages, n_jobs=parallel_jobs, quiet=not opts.verbose, interleave_output=opts.interleave_output, no_status=opts.no_status, limit_status_rate=opts.limit_status_rate, no_notify=opts.no_notify, continue_on_failure=opts.continue_on_failure, summarize_build=opts.summarize, catkin_test_target=catkin_test_target, cmake_test_target=cmake_test_target, )
def main(opts): # Initialize dictionary version of opts namespace opts_vars = vars(opts) if opts else {} # Check for special locations root_resource_path = os.path.join(os.path.dirname(__file__), '..', '..') if opts.shell_verbs: shell_verbs = os.path.join(root_resource_path, 'verbs', 'catkin_shell_verbs.bash') print(os.path.normpath(shell_verbs)) sys.exit(0) elif opts.examples: shell_verbs = os.path.join(root_resource_path, '..', 'docs', 'examples') print(os.path.normpath(shell_verbs)) sys.exit(0) # Get the workspace (either the given directory or the enclosing ws) workspace_hint = opts_vars.get('workspace', None) or getcwd() workspace = find_enclosing_workspace(workspace_hint) if not workspace: if not opts.quiet: print(clr( "[locate] @!@{rf}Error:@| No workspace found containing '{}'"). format(workspace_hint), file=sys.stderr) sys.exit(1) # Load the context to get the subspaces ctx = Context.load(workspace, opts.profile, opts, load_env=False) path = None if opts.space: path = getattr(ctx, "{}_space_abs".format(opts.space)) package = None if opts.package or opts.this: if opts.this: try: package = find_enclosing_package(search_start_path=getcwd(), ws_path=ctx.workspace, warnings=[]) if package is None: sys.exit( clr("[locate] @!@{rf}Error:@| Passed '--this' but could not determine enclosing package. " "Is '{}' in a package in '{}' workspace?").format( getcwd(), ctx.workspace)) except InvalidPackage as ex: sys.exit( clr("[locate] @!@{rf}Error:@| The file {} is an invalid package.xml file." " See below for details:\n\n{}").format( ex.package_path, ex.msg)) else: package = opts.package # Get the path to the given package path = path or ctx.source_space_abs if not opts.space or opts.space == 'source': try: packages = find_packages(path, warnings=[]) catkin_package = [ pkg_path for pkg_path, p in packages.items() if p.name == package ] if catkin_package: path = os.path.join(path, catkin_package[0]) else: sys.exit( clr("[locate] @!@{rf}Error:@| Could not locate a package named '{}' in path '{}'" ).format(package, path)) except RuntimeError as e: sys.exit(clr('[locate] @!@{rf}Error:@| {}').format(str(e))) elif opts.space in ['devel', 'install']: path = os.path.join(path, 'share', package) else: path = os.path.join(path, package) if not opts.space and package is None: # Get the path to the workspace root path = workspace # Check if the path exists if opts.existing_only and not os.path.exists(path): sys.exit( clr("[locate] @!@{rf}Error:@| Requested path '{}' does not exist." ).format(path)) # Make the path relative if desired if opts.relative: path = os.path.relpath(path, getcwd()) # Print the path print(path)
def main(opts): # Initialize dictionary version of opts namespace opts_vars = vars(opts) if opts else {} # Check for special locations root_resource_path = os.path.join(os.path.dirname(__file__), '..', '..') if opts.shell_verbs: shell_verbs = os.path.join(root_resource_path, 'verbs', 'catkin_shell_verbs.bash') print(os.path.normpath(shell_verbs)) sys.exit(0) elif opts.examples: shell_verbs = os.path.join(root_resource_path, '..', 'docs', 'examples') print(os.path.normpath(shell_verbs)) sys.exit(0) # Get the workspace (either the given directory or the enclosing ws) workspace_hint = opts_vars.get('workspace', None) or os.getcwd() workspace = find_enclosing_workspace(workspace_hint) if not workspace: if not opts.quiet: print(clr("@{rf}ERROR: No workspace found containing '%s'@|" % workspace_hint), file=sys.stderr) sys.exit(1) # Load the context to get the subspaces ctx = Context.load(workspace, opts.profile, opts, load_env=False) path = None if opts.space: # Get the subspace if opts.space == 'src': path = ctx.source_space_abs elif opts.space == 'build': path = ctx.build_space_abs elif opts.space == 'devel': path = ctx.devel_space_abs elif opts.space == 'install': path = ctx.install_space_abs package = None if opts.package or opts.this: if opts.this: package = find_enclosing_package( search_start_path=getcwd(), ws_path=ctx.workspace, warnings=[]) if package is None: print(clr("@{rf}ERROR: Passed '--this' but could not determine enclosing package. " "Is '%s' in a package in '%s' workspace?@|" % (getcwd(), ctx.workspace)), file=sys.stderr) sys.exit(2) else: package = opts.package # Get the path to the given package path = path or ctx.source_space_abs if opts.space == 'build': path = os.path.join(path, package) elif opts.space in ['devel', 'install']: path = os.path.join(path, 'share', package) else: try: packages = find_packages(path, warnings=[]) catkin_package = [pkg_path for pkg_path, p in packages.items() if p.name == package] if catkin_package: path = os.path.join(path, catkin_package[0]) else: print(clr("@{rf}ERROR: Could not locate a package named '%s' in path '%s'@|" % (package, path)), file=sys.stderr) sys.exit(2) except RuntimeError as e: print(clr('@{rf}ERROR: %s@|' % str(e)), file=sys.stderr) sys.exit(1) if not opts.space and package is None: # Get the path to the workspace root path = workspace # Check if the path exists if opts.existing_only and not os.path.exists(path): print(clr("@{rf}ERROR: Requested path '%s' does not exist.@|" % path), file=sys.stderr) sys.exit(1) # Make the path relative if desired if opts.relative: path = os.path.relpath(path, os.getcwd()) # Print the path print(path)
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)