def main(opts): try: # Load a context with initialization ctx = Context.Load(opts.workspace, strict=True) # Initialize the workspace if necessary if ctx: print( 'Catkin workspace `%s` is already initialized. No action taken.' % (ctx.workspace)) else: print('Initializing catkin workspace in `%s`.' % (opts.workspace or os.getcwd())) # initialize the workspace init_metadata_root(opts.workspace or os.getcwd(), opts.reset) ctx = Context.Load(opts.workspace) print(ctx.summary()) except IOError as exc: # Usually happens if workspace is already underneath another catkin_tools workspace print('error: could not initialize catkin workspace: %s' % exc.message) return 1 return 0
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
def main(opts): actions = ['all', 'build', 'devel', 'install', 'cmake_cache', 'orphans', 'setup_files'] if not any([v for (k, v) in vars(opts).items() if k in actions]): print("[clean] No actions performed. See `catkin clean -h` for usage.") return 0 needs_force = False # Load the context ctx = Context.Load(opts.workspace, opts.profile, opts, strict=True) if not ctx: if not opts.workspace: print( "catkin clean: 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: print( "catkin clean: error: Could not clean workspace \"%s\" because it " "either does not exist or it has no catkin_tools metadata." % opts.workspace) return 1 # Remove the requested spaces if opts.all: opts.build = opts.devel = opts.install = True if opts.build: if os.path.exists(ctx.build_space_abs): print("[clean] Removing buildspace: %s" % ctx.build_space_abs) shutil.rmtree(ctx.build_space_abs) else: # Orphan removal if opts.orphans: if os.path.exists(ctx.build_space_abs): # TODO: Check for merged build and report error # Get all enabled packages in source space found_source_packages = [pkg.name for (path, pkg) in find_packages(ctx.source_space_abs).items()] # Iterate over all packages with build dirs print("[clean] Removing orphaned build directories from %s" % ctx.build_space_abs) no_orphans = True for pkg_build_name in os.listdir(ctx.build_space_abs): if pkg_build_name not in exempt_build_files: pkg_build_path = os.path.join(ctx.build_space_abs, pkg_build_name) # Remove package build dir if not found if pkg_build_name not in found_source_packages: no_orphans = False print(" - Removing %s" % pkg_build_path) shutil.rmtree(pkg_build_path) if no_orphans: print("[clean] No orphans found, nothing removed from buildspace.") else: # Remove the develspace # TODO: For isolated devel, this could just remove individual packages if os.path.exists(ctx.devel_space_abs): print("Removing develspace: %s" % ctx.devel_space_abs) shutil.rmtree(ctx.devel_space_abs) needs_force = True else: print("[clean] No buildspace exists, no potential for orphans.") return 0 # CMake Cache removal if opts.cmake_cache: # Clear the CMakeCache for each package if os.path.exists(ctx.build_space_abs): # Remove CMakeCaches print("[clean] Removing CMakeCache.txt files from %s" % ctx.build_space_abs) for pkg_build_name in os.listdir(ctx.build_space_abs): if pkg_build_name not in exempt_build_files: pkg_build_path = os.path.join(ctx.build_space_abs, pkg_build_name) ccache_path = os.path.join(pkg_build_path, 'CMakeCache.txt') if os.path.exists(ccache_path): print(" - Removing %s" % ccache_path) os.remove(ccache_path) needs_force = True else: print("[clean] No buildspace exists, no CMake caches to clear.") if opts.devel: if os.path.exists(ctx.devel_space_abs): print("[clean] Removing develspace: %s" % ctx.devel_space_abs) shutil.rmtree(ctx.devel_space_abs) else: if opts.setup_files: print("[clean] Removing setup files from develspace: %s" % ctx.devel_space_abs) for filename in setup_files: full_path = os.path.join(ctx.devel_space_abs, filename) if os.path.exists(full_path): print(" - Removing %s" % full_path) os.remove(full_path) needs_force = True if opts.install: if os.path.exists(ctx.install_space_abs): print("[clean] Removing installspace: %s" % ctx.install_space_abs) shutil.rmtree(ctx.install_space_abs) if needs_force: print( "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 0