Class: Autoproj::CLI::Base
- Inherits:
-
Object
- Object
- Autoproj::CLI::Base
- Includes:
- Ops::Tools
- Defined in:
- lib/autoproj/cli/base.rb
Direct Known Subclasses
InspectionTool, Log, Manifest, Reconfigure, SwitchConfig, Tag, Update, Version
Instance Attribute Summary collapse
-
#ws ⇒ Workspace
readonly
The underlying workspace.
Class Method Summary collapse
Instance Method Summary collapse
- #export_env_sh(shell_helpers: ws.config.shell_helpers?) ⇒ Object
-
#initialize(ws = Workspace.default) ⇒ Base
constructor
A new instance of Base.
-
#normalize_command_line_package_selection(selection) ⇒ (Array<String>,Boolean)
Normalizes the arguments given by the user on the command line.
- #notify_env_sh_updated ⇒ Object
-
#resolve_selection(user_selection, checkout_only: true, only_local: false, recursive: true, non_imported_packages: :ignore, auto_exclude: false) ⇒ (Array<String>,Array<String>,PackageSelection)
Resolves the user-provided selection into the set of packages that should be processed further.
-
#resolve_user_selection(selected_packages, **options) ⇒ (PackageSelection,Array<String>)
Resolve a user-provided selection.
- #validate_options(args, options) ⇒ Object
-
#validate_user_selection(user_selection, resolved_selection) ⇒ Object
Check whether the user selection refers to non-existant/unknown packages.
Methods included from Ops::Tools
#common_options, #create_autobuild_package, #load_autoprojrc, #load_main_initrb
Constructor Details
Instance Attribute Details
#ws ⇒ Workspace (readonly)
The underlying workspace
14 15 16 |
# File 'lib/autoproj/cli/base.rb', line 14 def ws @ws end |
Class Method Details
.validate_options(args, options) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/autoproj/cli/base.rb', line 185 def self.(args, ) , remaining = , silent: false, verbose: false, debug: false, color: TTY::Color.color?, progress: TTY::Color.color?, parallel: nil Autoproj.silent = [:silent] Autobuild.color = [:color] Autobuild.progress_display_enabled = [:progress] if [:verbose] Autoproj.verbose = true Autobuild.verbose = true Rake.application..trace = false Autobuild.debug = false end if [:debug] Autoproj.verbose = true Autobuild.verbose = true Rake.application..trace = true Autobuild.debug = true end if (level = [:parallel]) Autobuild.parallel_build_level = Integer(level) remaining[:parallel] = Integer(level) end [args, remaining.to_sym_keys] end |
Instance Method Details
#export_env_sh(shell_helpers: ws.config.shell_helpers?) ⇒ Object
220 221 222 223 224 225 226 227 228 229 |
# File 'lib/autoproj/cli/base.rb', line 220 def export_env_sh(shell_helpers: ws.config.shell_helpers?) # @env_sh_updated == nil means "did not even export". # make sure that it is set to 'true' or 'false' @env_sh_updated = if ws.export_env_sh(shell_helpers: shell_helpers) true else false end end |
#normalize_command_line_package_selection(selection) ⇒ (Array<String>,Boolean)
Normalizes the arguments given by the user on the command line
This converts relative paths to full paths, and removes mentions of the configuration directory (as it is handled separately in autoproj)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/autoproj/cli/base.rb', line 30 def normalize_command_line_package_selection(selection) selection = selection.map do |name| if File.directory?(name) "#{File.(name)}/" else name end end config_selected = false selection.delete_if do |name| if name =~ /^#{Regexp.quote(ws.config_dir)}(?:#{File::SEPARATOR}|$)/ || name =~ /^#{Regexp.quote(ws.remotes_dir)}(?:#{File::SEPARATOR}|$)/ config_selected = true elsif (ws.config_dir + File::SEPARATOR) =~ /^#{Regexp.quote(name)}/ config_selected = true false end end [selection, config_selected] end |
#notify_env_sh_updated ⇒ Object
231 232 233 234 235 236 237 238 239 |
# File 'lib/autoproj/cli/base.rb', line 231 def notify_env_sh_updated return if @env_sh_updated.nil? if @env_sh_updated Autoproj. " updated environment", :green else Autoproj. " environment already up-to-date", :green end end |
#resolve_selection(user_selection, checkout_only: true, only_local: false, recursive: true, non_imported_packages: :ignore, auto_exclude: false) ⇒ (Array<String>,Array<String>,PackageSelection)
Resolves the user-provided selection into the set of packages that should be processed further
While #resolve_user_selection really only considers packages and strings, this methods takes care of doing recursive resolution of dependencies, as well as splitting the packages into source and osdep packages.
It loads the packages in sequence (that’s the only way the full selection can be computed), and is therefore responsible for updating the packages if needed (disabled by default)
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/autoproj/cli/base.rb', line 142 def resolve_selection(user_selection, checkout_only: true, only_local: false, recursive: true, non_imported_packages: :ignore, auto_exclude: false) resolved_selection, = resolve_user_selection(user_selection, filter: false) ops = Ops::Import.new(ws) source_packages, osdep_packages = ops.import_packages( resolved_selection, checkout_only: checkout_only, only_local: only_local, recursive: recursive, warn_about_ignored_packages: false, non_imported_packages: non_imported_packages, auto_exclude: auto_exclude ) [source_packages, osdep_packages, resolved_selection] rescue ExcludedSelection => e raise CLIInvalidSelection, e., e.backtrace end |
#resolve_user_selection(selected_packages, **options) ⇒ (PackageSelection,Array<String>)
Resolve a user-provided selection
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 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/autoproj/cli/base.rb', line 59 def resolve_user_selection(selected_packages, **) if selected_packages.empty? selection = begin ws.manifest.default_packages rescue ExcludedSelection => e raise CLIInvalidSelection, e., e.backtrace end if Autoproj.verbose Autoproj. "selected packages: #{selection.each_package_name.to_a.sort.join(', ')}" end return selection, [] end selected_packages = selected_packages.to_set selected_packages, nonresolved = begin ws.manifest.(selected_packages, **) rescue ExcludedSelection => e raise CLIInvalidSelection, e., e.backtrace end # Try to auto-add stuff if nonresolved nonresolved.delete_if do |sel| sel = File.(sel) next unless File.directory?(sel) while sel != "/" handler, srcdir = Autoproj.package_handler_for(sel) if handler Autoproj. " auto-adding #{srcdir} using the #{handler.gsub(/_package/, '')} package handler" srcdir = File.(srcdir) relative_to_root = Pathname.new(srcdir).relative_path_from(Pathname.new(ws.source_dir)) pkg = ws.in_package_set(ws.manifest.main_package_set, ws.manifest.file) do send(handler, relative_to_root.to_s, workspace: ws) end ws.setup_package_directories(pkg) selected_packages.select(sel, pkg.name, weak: true) break(true) end sel = File.dirname(sel) end end if Autoproj.verbose Autoproj. "selected packages: #{selected_packages.each_package_name.to_a.sort.join(', ')}" end [selected_packages, nonresolved] end |
#validate_options(args, options) ⇒ Object
179 180 181 182 183 |
# File 'lib/autoproj/cli/base.rb', line 179 def (args, ) interactive = .delete(:interactive) ws.config.interactive = interactive unless interactive.nil? self.class.(args, ) end |
#validate_user_selection(user_selection, resolved_selection) ⇒ Object
Check whether the user selection refers to non-existant/unknown packages
168 169 170 171 172 173 174 175 176 177 |
# File 'lib/autoproj/cli/base.rb', line 168 def validate_user_selection(user_selection, resolved_selection) not_matched = user_selection.find_all do |pkg_name| !resolved_selection.has_match_for?(pkg_name) && !(resolved_selection.ignored?(pkg_name) || resolved_selection.excluded?(pkg_name)) end unless not_matched.empty? raise CLIInvalidArguments, "autoproj: wrong package selection on command line, cannot find a match for #{not_matched.to_a.sort.join(', ')}" end end |