def run_rsync(args): cwd = os.getcwd() ws = find_enclosing_workspace(cwd) context = Context.load(ws) if ws: sync_pathes = get_sync_pathes(context, args.space) run_sync_pathes(sync_pathes, args.remote) else: logging.error( f'No catkin workspace found. Is "{cwd}" contained in a workspace?')
def try_find_ros_compilation_database(filename): try: from catkin_tools.metadata import find_enclosing_workspace from catkin_tools.context import Context import rospkg workspace = find_enclosing_workspace(filename) ctx = Context.load(workspace, {}, {}, load_env=False) package = rospkg.get_package_name(filename) path = os.path.join(ctx.build_space_abs, package) candidate = os.path.join(path, 'compile_commands.json') if os.path.isfile(candidate) or os.path.isdir(candidate): logging.info("Found ROS compilation database for " + filename + " at " + candidate) return candidate except: pass return None
def find_project_path(project_name): # type: (str) -> Union[str, None] workspace = find_enclosing_workspace(getcwd()) if not workspace: return None src_path = path.join(workspace, "src") packages = find_packages(src_path, warnings=[]) catkin_package = [ pkg_path for pkg_path, p in packages.items() if p.name == project_name ] if catkin_package: project_path = path.join(src_path, catkin_package[0]) else: project_path = None return project_path
def main(opts): opts = sys.argv[1:] if opts is None else opts #print(opts) workspace = os.getcwd() if opts.workspace is None else opts.workspace workspace = find_enclosing_workspace(workspace) if not workspace: print("No workspace found") sys.exit(1) ctx = Context.load(workspace, opts.profile, opts, load_env=False) packages = find_packages(ctx.source_space_abs) pkg_path = [pkg_path for pkg_path, p in packages.items() if p.name == opts.package] pkg_path = None if not pkg_path else pkg_path[0] if not pkg_path: print("Package '{}' not found!".format(opts.package)) sys.exit(2) pkg_name = packages[pkg_path].name build_space = ctx.build_space_abs + os.path.sep + pkg_name compile_db = build_space + os.path.sep + "compile_commands.json" if not os.path.isfile(compile_db): print("No compile_commands.json in {}".format(build_space)) sys.exit(3) pkg_root = ctx.source_space_abs + os.path.sep + pkg_path if len(opts.src_file) == 0: opts.src_file = findSrcFiles(pkg_root) if len(opts.src_file) == 0: print("No .cpp files found!") sys.exit(4) export_file = None if opts.export is None else opts.export[0] if export_file: opts.fix = False runClangTidy(clang_binary=opts.clang_tidy, pkg_root=pkg_root, package=opts.package, filenames=opts.src_file, cfg=None, compile_db=build_space, fix=opts.fix, export_file=export_file, dry_run = False) return 0
def run_cppcheck(args): enable_checks = args.enable quiet = args.quiet verbose = args.verbose cwd = os.getcwd() # Find root of catkin workspace ws = find_enclosing_workspace(cwd) if ws: # Find all packages in the workspace package_paths = find_package_paths(ws) # Get absolute paths package_paths = [os.path.join(ws, p) for p in package_paths] # Run cppcheck on the catkin package paths cppcheck.check(package_paths, enable_checks, quiet=quiet, verbose=verbose) else: logging.error( 'No catkin workspace found. Is "{}" contained in a workspace?'. format(cwd))
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 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): # 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 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 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 find_enclosing_workspace(cls, path): try: from catkin_tools.metadata import find_enclosing_workspace return find_enclosing_workspace(path) except: return None
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 if 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, opts.package) elif opts.space in ['devel', 'install']: path = os.path.join(path, 'share', opts.package) else: try: packages = find_packages(path, warnings=[]) catkin_package = [pkg_path for pkg_path, p in packages.items() if p.name == opts.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'@|" % (opts.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) elif not opts.space: # 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): # Initialize dictionary version of opts namespace opts_vars = vars(opts) if opts else {} # 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: 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 if 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, opts.package) elif opts.space in ['devel', 'install']: path = os.path.join(path, 'share', opts.package) else: try: packages = find_packages(path, warnings=[]) catkin_package = [ pkg_path for pkg_path, p in packages.items() if p.name == opts.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'@|" % (opts.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) elif not opts.space: # 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): # Check for exclusivity full_options = opts.deinit package_options = len(opts.packages) > 0 or opts.orphans or opts.clean_this advanced_options = opts.setup_files if opts.spaces is None: opts.spaces = [] if full_options: if opts.spaces or package_options or advanced_options: log(clr("[clean] @!@{rf}Error:@| Using `--deinit` will remove all spaces, so" " additional partial cleaning options will be ignored.")) elif opts.spaces: if package_options: log(clr("[clean] @!@{rf}Error:@| Package arguments are not allowed with space" " arguments. See usage.")) elif advanced_options: log(clr("[clean] @!@{rf}Error:@| Advanced arguments are not allowed with space" " arguments. See usage.")) # Check for all profiles option if opts.all_profiles: profiles = get_profile_names(opts.workspace or find_enclosing_workspace(getcwd())) else: profiles = [opts.profile] # Initialize job server job_server.initialize( max_jobs=1, max_load=None, gnu_make_enabled=False) # Clean the requested profiles retcode = 0 for profile in profiles: if not clean_profile(opts, profile): retcode = 1 # Warn before nuking .catkin_tools if retcode == 0: if opts.deinit and not opts.yes: log("") log(clr("[clean] @!@{yf}Warning:@| If you deinitialize this workspace" " you will lose all profiles and all saved build" " configuration. (Use `--yes` to skip this check)")) try: opts.deinit = yes_no_loop("\n[clean] Are you sure you want to deinitialize this workspace?") if not opts.deinit: log(clr("[clean] Not deinitializing workspace.")) except KeyboardInterrupt: log("\n[clean] No actions performed.") sys.exit(0) # Nuke .catkin_tools if opts.deinit: ctx = Context.load(opts.workspace, profile, opts, strict=True, load_env=False) metadata_dir = get_metadata_root_path(ctx.workspace) log("[clean] Deinitializing workspace by removing catkin_tools config: %s" % metadata_dir) if not opts.dry_run: safe_rmtree(metadata_dir, ctx.workspace, opts.force) return retcode