def main(opts): try: # Determine if the user is trying to perform some action, in which # case, the workspace should be automatically initialized ignored_opts = ['main', 'verb'] actions = [v for k, v in vars(opts).items() if k not in ignored_opts] no_action = not any(actions) # Try to find a metadata directory to get context defaults # Otherwise use the specified directory context = Context.Load(opts.workspace, opts.profile, opts) do_init = opts.init or not no_action summary_notes = [] if not context.initialized() and do_init: summary_notes.append( clr('@!@{cf}Initialized new catkin workspace in `%s`@|' % context.workspace)) if context.initialized() or do_init: Context.Save(context) if opts.mkdirs and not context.source_space_exists(): os.makedirs(context.source_space_abs) print(context.summary(notes=summary_notes)) except IOError as exc: # Usually happens if workspace is already underneath another catkin_tools workspace print('error: could not configure catkin workspace: %s' % exc.message) return 1 return 0
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): try: # Load a context with initialization ctx = Context.Load(opts.workspace) if not ctx.initialized(): print( "A catkin workspace must be initialized before profiles can be managed." ) return 1 profiles = get_profile_names(ctx.workspace) active_profile = get_active_profile(ctx.workspace) if opts.subcommand == 'list': print(list_profiles(profiles, active_profile)) elif opts.subcommand == 'add': if opts.name in profiles: if opts.force: print( clr('[profile] @{yf}Warning:@| Overwriting existing profile named @{cf}%s@|' % (opts.name))) else: print( clr('catkin profile: error: A profile named ' '@{cf}%s@| already exists. Use `--force` to ' 'overwrite.' % (opts.name))) return 1 if opts.copy_active: ctx.profile = opts.name Context.Save(ctx) print( clr('[profile] Created a new profile named @{cf}%s@| ' 'based on active profile @{cf}%s@|' % (opts.name, active_profile))) elif opts.copy: if opts.copy in profiles: new_ctx = Context.Load(opts.workspace, profile=opts.copy) new_ctx.profile = opts.name Context.Save(new_ctx) print( clr('[profile] Created a new profile named @{cf}%s@| ' 'based on profile @{cf}%s@|' % (opts.name, opts.copy))) else: print( clr('[profile] @{rf}A profile with this name does not exist: %s@|' % opts.copy)) else: new_ctx = Context(workspace=ctx.workspace, profile=opts.name) Context.Save(new_ctx) print( clr('[profile] Created a new profile named @{cf}%s@| with default settings.' % (opts.name))) profiles = get_profile_names(ctx.workspace) active_profile = get_active_profile(ctx.workspace) print(list_profiles(profiles, active_profile)) elif opts.subcommand == 'set': if opts.name in profiles: set_active_profile(ctx.workspace, opts.name) active_profile = get_active_profile(ctx.workspace) print( clr('[profile] Activated catkin metadata profile: @{cf}%s@|' % active_profile)) else: print( 'catkin profile: error: Profile `%s` does not exist in workspace `%s`.' % (opts.name[0], ctx.workspace)) return 1 profiles = get_profile_names(ctx.workspace) active_profile = get_active_profile(ctx.workspace) print(list_profiles(profiles, active_profile)) elif opts.subcommand == 'rename': if opts.current_name in profiles: if opts.new_name in profiles: if opts.force: print( clr('[profile] @{yf}Warning:@| Overwriting ' 'existing profile named @{cf}%s@|' % (opts.new_name))) else: print( clr('catkin profile: error: A profile named ' '@{cf}%s@| already exists. Use `--force` to ' 'overwrite.' % (opts.new_name))) return 1 ctx.profile = opts.new_name Context.Save(ctx) remove_profile(ctx.workspace, opts.current_name) if opts.current_name == active_profile: set_active_profile(ctx.workspace, opts.new_name) print( clr('[profile] Renamed profile @{cf}%s@| to @{cf}%s@|' % (opts.current_name, opts.new_name))) else: print( 'catkin profile: error: Profile `%s` does not exist in workspace `%s`.' % (opts.current_name, ctx.workspace)) return 1 profiles = get_profile_names(ctx.workspace) active_profile = get_active_profile(ctx.workspace) print(list_profiles(profiles, active_profile)) elif opts.subcommand == 'remove': for name in opts.name: if name == active_profile: print( 'Profile `%s` is currently active. Re-setting active profile to `%s`.' % (name, DEFAULT_PROFILE_NAME)) set_active_profile(ctx.workspace, DEFAULT_PROFILE_NAME) if name in profiles: remove_profile(ctx.workspace, name) else: print( 'catkin profile: error: Profile `%s` does not exist in workspace `%s`.' % (name, ctx.workspace)) return 1 print(clr('[profile] Removed profile: @{rf}%s@|' % name)) profiles = get_profile_names(ctx.workspace) active_profile = get_active_profile(ctx.workspace) print(list_profiles(profiles, active_profile)) except IOError as exc: # Usually happens if workspace is already underneath another catkin_tools workspace print('error: could not %s catkin profile: %s' % (opts.subcommand, exc.message)) return 1 return 0