Class: Autoproj::CLI::Exec
- Inherits:
-
Object
- Object
- Autoproj::CLI::Exec
- Defined in:
- lib/autoproj/cli/exec.rb
Constant Summary collapse
- PACKAGE_ROOT_PATH_RX =
/^(srcdir|builddir|prefix):(.*)$/
Instance Method Summary collapse
-
#initialize ⇒ Exec
constructor
A new instance of Exec.
- #load_cached_env ⇒ Object
- #resolve_package_root_path(package, manifest) ⇒ Object
- #run(cmd, *args, use_cached_env: Ops.watch_running?(@root_dir), interactive: nil, package: nil, chdir: nil) ⇒ Object
- #try_loading_installation_manifest ⇒ Object
Constructor Details
#initialize ⇒ Exec
Returns a new instance of Exec.
9 10 11 12 13 14 15 16 17 |
# File 'lib/autoproj/cli/exec.rb', line 9 def initialize @root_dir = Autoproj.find_workspace_dir unless @root_dir require "autoproj/workspace" # Will do all sorts of error reporting, # or may be able to resolve @root_dir = Workspace.default.root_dir end end |
Instance Method Details
#load_cached_env ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/autoproj/cli/exec.rb', line 19 def load_cached_env env = Ops.load_cached_env(@root_dir) return unless env Autobuild::Environment .environment_from_export(env, ENV) end |
#resolve_package_root_path(package, manifest) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/autoproj/cli/exec.rb', line 34 def resolve_package_root_path(package, manifest) if (m = PACKAGE_ROOT_PATH_RX.match(package)) kind = m[1] name = m[2] else kind = "srcdir" name = package end unless (pkg = manifest.find_package_by_name(name)) raise ArgumentError, "no package #{name} in this workspace" end unless (dir = pkg.send(kind)) raise CLIInvalidArguments, "package #{pkg.name} has no #{kind}" end dir end |
#run(cmd, *args, use_cached_env: Ops.watch_running?(@root_dir), interactive: nil, package: nil, chdir: nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/autoproj/cli/exec.rb', line 54 def run( cmd, *args, use_cached_env: Ops.watch_running?(@root_dir), interactive: nil, package: nil, chdir: nil ) env = load_cached_env if use_cached_env manifest = try_loading_installation_manifest if use_cached_env if !env || (package && !manifest) require "autoproj" require "autoproj/cli/inspection_tool" ws = Workspace.from_dir(@root_dir) ws.config.interactive = interactive unless interactive.nil? loader = InspectionTool.new(ws) loader.initialize_and_load(read_only: true) loader.finalize_setup(read_only: true) env = ws.full_env.resolved_env manifest = ws.installation_manifest if package end root_path = resolve_package_root_path(package, manifest) if package chdir ||= root_path if chdir chdir = File.(chdir, root_path) chdir_kw = { chdir: chdir } end path = env["PATH"].split(File::PATH_SEPARATOR) program = begin Ops.which(cmd, path_entries: [chdir, *path].compact) rescue ::Exception => e require "autoproj" raise CLIInvalidArguments, e., e.backtrace end begin ::Process.exec(env, program, *args, **(chdir_kw || {})) rescue ::Exception => e require "autoproj" raise CLIInvalidArguments, e., e.backtrace end end |
#try_loading_installation_manifest ⇒ Object
27 28 29 30 |
# File 'lib/autoproj/cli/exec.rb', line 27 def try_loading_installation_manifest Autoproj::InstallationManifest.from_workspace_root(@root_dir) rescue end |