Class: Autoproj::Workspace
- Inherits:
-
Ops::Loader
- Object
- Ops::Loader
- Autoproj::Workspace
- Defined in:
- lib/autoproj/workspace.rb
Defined Under Namespace
Classes: RegisteredWorkspace
Constant Summary collapse
- OVERRIDES_DIR =
"overrides.d".freeze
- IMPORT_REPORT_BASENAME =
"import_report.json".freeze
- BUILD_REPORT_BASENAME =
"build_report.json".freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#loader ⇒ Object
readonly
Returns the value of attribute loader.
-
#manifest ⇒ Manifest
readonly
The installation manifest.
-
#os_package_installer ⇒ Object
readonly
Returns the value of attribute os_package_installer.
-
#os_package_resolver ⇒ Object
readonly
Returns the value of attribute os_package_resolver.
-
#os_repository_installer ⇒ Object
readonly
Returns the value of attribute os_repository_installer.
-
#os_repository_resolver ⇒ Object
readonly
Returns the value of attribute os_repository_resolver.
-
#osdep_suffixes ⇒ Object
readonly
Suffixes that should be considered when loading osdep files.
-
#root_dir ⇒ Object
readonly
The workspace root as a string.
-
#root_path ⇒ Object
readonly
The workspace root.
-
#ruby_version_keyword ⇒ String
The keyword used to represent the current ruby version.
Attributes inherited from Ops::Loader
Class Method Summary collapse
-
.autoproj_current_root ⇒ String?
Returns the root of the current autoproj workspace.
-
.default(**workspace_options) ⇒ Object
Returns the default workspace.
- .find_path(xdg_var, xdg_path, home_path) ⇒ Object
- .find_user_cache_path(xdg_path, home_path = xdg_path) ⇒ Object
- .find_user_config_path(xdg_path, home_path = xdg_path) ⇒ Object
- .find_user_data_path(xdg_path, home_path = xdg_path) ⇒ Object
-
.from_dir(dir, **workspace_options) ⇒ Workspace
Returns the workspace a directory is part of.
- .from_environment(**workspace_options) ⇒ Object
-
.from_pwd(**workspace_options) ⇒ Workspace
Returns the workspace the current directory is part of.
-
.in_autoproj_project?(path) ⇒ Boolean
Tests whether the given path is under a directory tree managed by autoproj.
- .rcfile_path ⇒ Object
- .registered_workspaces ⇒ Object
- .save_registered_workspaces(workspaces) ⇒ Object
Instance Method Summary collapse
-
#all_os_packages(import_missing: false, parallel: config.parallel_import_level) ⇒ Array<String>
Returns the list of all OS packages required by the state of the workspace.
- #all_present_packages ⇒ Object
- #autodetect_operating_system(force: false) ⇒ Object
-
#build_dir ⇒ String
Defines the temporary area in which packages should put their build files.
-
#build_dir=(path) ⇒ Object
Change #build_dir.
-
#build_report_path ⇒ String
The full path to the build report.
- #clear_main_workspace ⇒ Object
- #compute_builddir(pkg) ⇒ Object
-
#config_dir ⇒ String
Returns the configuration directory for this autoproj installation.
-
#config_file_path ⇒ Object
The path to the workspace configuration file.
-
#define_package(package_type, package_name, block = nil, package_set = manifest.main_package_set, file = nil) ⇒ PackageDefinition
Define and register an autobuild package on this workspace.
-
#dot_autoproj_dir ⇒ Object
The directory under which autoproj saves all its internal configuration and files.
-
#export_env_sh(_package_names = nil, shell_helpers: true) ⇒ Boolean
Export the workspace’s env.sh file.
-
#export_installation_manifest ⇒ Object
Update this workspace’s installation manifest.
-
#finalize_package_setup ⇒ Object
Finalizes the configuration loading.
-
#finalize_setup(read_only: false) ⇒ Object
Finalizes the complete setup.
-
#full_env ⇒ Object
The environment as initialized by all selected packages.
-
#import_report_path ⇒ String
The full path to the update report.
-
#initialize(root_dir, os_package_resolver: OSPackageResolver.new, package_managers: OSPackageInstaller::PACKAGE_MANAGERS, os_repository_resolver: OSRepositoryResolver.new( operating_system: os_package_resolver.operating_system ), os_repository_installer: OSRepositoryInstaller.new(self)) ⇒ Workspace
constructor
A new instance of Workspace.
- #install_os_packages(packages, all: all_os_packages, **options) ⇒ Object
- #install_os_repositories ⇒ Object
- #install_ruby_shims ⇒ Object
-
#installation_manifest ⇒ InstallationManifest
Generate a InstallationManifest with the currently known information.
-
#installation_manifest_path ⇒ Object
The installation manifest.
- #load(*args) ⇒ Object
- #load_all_available_package_manifests ⇒ Object
-
#load_autoprojrc ⇒ Object
Loads the .autoprojrc file.
- #load_cached_env ⇒ Object
-
#load_config(reconfigure = false) ⇒ Configuration
Load the configuration for this workspace from config_file_path.
-
#load_main_initrb ⇒ Object
Loads autoproj/init.rb.
- #load_package_sets(only_local: false, checkout_only: true, reconfigure: false, keep_going: false, mainline: nil, reset: false, retry_count: nil) ⇒ Object
- #load_packages(selection = manifest.default_packages(false), options = {}) ⇒ Object
- #log_dir ⇒ Object
-
#manifest_file_path ⇒ Object
The path to the workspace’s manifest file.
- #migrate_bundler_and_autoproj_gem_layout ⇒ Object
- #operating_system ⇒ Object
-
#overrides_dir ⇒ String
Returns the directory containing overrides files.
-
#prefix_dir ⇒ String
The directory in which packages will be installed.
-
#prefix_dir=(path) ⇒ Object
Change #prefix_dir.
- #pristine_os_packages(packages, options = Hash.new) ⇒ Object
-
#register_package(package, block = nil, package_set = manifest.main_package_set, file = nil) ⇒ PackageDefinition
Register an autobuild package on this workspace.
- #register_workspace ⇒ Object
-
#remotes_dir ⇒ Object
Return the directory in which remote package set definition should be checked out.
- #rewrite_shims ⇒ Object
- #run(*args, &block) ⇒ Object
- #save_cached_env(env = full_env) ⇒ Object
- #save_config ⇒ Object
- #set_as_main_workspace ⇒ Object
-
#setup(load_global_configuration: true, read_only: false) ⇒ Object
Perform initial configuration load and workspace setup.
- #setup_all_package_directories ⇒ Object
- #setup_os_package_installer ⇒ Object
- #setup_package_directories(pkg) ⇒ Object
- #setup_ruby_version_handling ⇒ Object
-
#source_dir ⇒ String?
Defines a folder to which source packages will be layed out relative to.
-
#source_dir=(path) ⇒ Object
Change #source_dir.
- #supported_operating_system? ⇒ Boolean
- #update_autoproj(restart_on_update: true) ⇒ Object
- #update_bundler ⇒ Object
-
#utility_report_path(name) ⇒ String
The full path to the report generated by the given utility.
-
#which(cmd, _path_entries: nil) ⇒ String
Find the given executable file in PATH.
Methods inherited from Ops::Loader
#current_file, #current_package_set, #filter_load_exception, #import_autobuild_file, #in_package_set, #load_if_present
Constructor Details
#initialize(root_dir, os_package_resolver: OSPackageResolver.new, package_managers: OSPackageInstaller::PACKAGE_MANAGERS, os_repository_resolver: OSRepositoryResolver.new( operating_system: os_package_resolver.operating_system ), os_repository_installer: OSRepositoryInstaller.new(self)) ⇒ Workspace
Returns a new instance of Workspace.
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 |
# File 'lib/autoproj/workspace.rb', line 54 def initialize(root_dir, os_package_resolver: OSPackageResolver.new, package_managers: OSPackageInstaller::PACKAGE_MANAGERS, os_repository_resolver: OSRepositoryResolver.new( operating_system: os_package_resolver. ), os_repository_installer: OSRepositoryInstaller.new(self)) @root_dir = root_dir @root_path = Pathname.new(root_dir) @ruby_version_keyword = "ruby#{RUBY_VERSION.split('.')[0, 2].join('')}" @osdep_suffixes = Array.new @loader = loader @env = Environment.new env.prepare(root_dir) env.source_before(File.join(dot_autoproj_dir, "env.sh")) @os_repository_resolver = os_repository_resolver @os_repository_installer = os_repository_installer @os_package_resolver = os_package_resolver @manifest = Manifest.new(self, os_package_resolver: os_package_resolver) @config = Configuration.new(config_file_path) @os_package_installer = OSPackageInstaller.new( self, os_package_resolver, package_managers: package_managers ) super(root_dir) end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
16 17 18 |
# File 'lib/autoproj/workspace.rb', line 16 def config @config end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
17 18 19 |
# File 'lib/autoproj/workspace.rb', line 17 def env @env end |
#loader ⇒ Object (readonly)
Returns the value of attribute loader.
24 25 26 |
# File 'lib/autoproj/workspace.rb', line 24 def loader @loader end |
#manifest ⇒ Manifest (readonly)
The installation manifest
22 23 24 |
# File 'lib/autoproj/workspace.rb', line 22 def manifest @manifest end |
#os_package_installer ⇒ Object (readonly)
Returns the value of attribute os_package_installer.
29 30 31 |
# File 'lib/autoproj/workspace.rb', line 29 def os_package_installer @os_package_installer end |
#os_package_resolver ⇒ Object (readonly)
Returns the value of attribute os_package_resolver.
28 29 30 |
# File 'lib/autoproj/workspace.rb', line 28 def os_package_resolver @os_package_resolver end |
#os_repository_installer ⇒ Object (readonly)
Returns the value of attribute os_repository_installer.
27 28 29 |
# File 'lib/autoproj/workspace.rb', line 27 def os_repository_installer @os_repository_installer end |
#os_repository_resolver ⇒ Object (readonly)
Returns the value of attribute os_repository_resolver.
26 27 28 |
# File 'lib/autoproj/workspace.rb', line 26 def os_repository_resolver @os_repository_resolver end |
#osdep_suffixes ⇒ Object (readonly)
Suffixes that should be considered when loading osdep files
#ruby_version_keyword is automatically added there in #setup
52 53 54 |
# File 'lib/autoproj/workspace.rb', line 52 def osdep_suffixes @osdep_suffixes end |
#root_dir ⇒ Object (readonly)
The workspace root as a string
New code should prefer #root_path
9 10 11 |
# File 'lib/autoproj/workspace.rb', line 9 def root_dir @root_dir end |
#root_path ⇒ Object (readonly)
The workspace root
This should be used rather than #root_dir in new code
14 15 16 |
# File 'lib/autoproj/workspace.rb', line 14 def root_path @root_path end |
#ruby_version_keyword ⇒ String
The keyword used to represent the current ruby version.
It is e.g. ruby21 for ruby 2.1.
It is initialized to the local ruby version in #initialize. If one intends to override it, one must do it before #setup gets called
This is aliased to ‘ruby’ in the osdep system, so one that depends on ruby should only refer to ‘ruby’ unless a specific version is requested.
It is also used as an osdep suffix when loading osdep files (i.e. the osdep system will attempt to load ‘.osdep-ruby21` files on ruby 2.1 in addition to the plain .osdep files.
47 48 49 |
# File 'lib/autoproj/workspace.rb', line 47 def ruby_version_keyword @ruby_version_keyword end |
Class Method Details
.autoproj_current_root ⇒ String?
Returns the root of the current autoproj workspace
87 88 89 90 91 |
# File 'lib/autoproj/workspace.rb', line 87 def self.autoproj_current_root if (env = ENV["AUTOPROJ_CURRENT_ROOT"]) env unless env.empty? end end |
.default(**workspace_options) ⇒ Object
Returns the default workspace
It uses the AUTOPROJ_CURRENT_ROOT environment variable if available, falling back to the current directory
AUTOPROJ_CURRENT_ROOT does not match the one containing the current directory
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/autoproj/workspace.rb', line 147 def self.default(**) ws = from_environment(**) from_pwd = Autoproj.find_workspace_dir(Dir.pwd) if from_pwd && (from_pwd != ws.root_dir) raise MismatchingWorkspace, "the current environment points to "\ "#{ws.root_dir}, but you are in #{from_pwd}, make sure you "\ "are loading the right #{ENV_FILENAME} script !" end ws end |
.find_path(xdg_var, xdg_path, home_path) ⇒ Object
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/autoproj/workspace.rb', line 560 def self.find_path(xdg_var, xdg_path, home_path) home_dir = begin Dir.home rescue ArgumentError return end xdg_path = File.join(XDG[xdg_var].to_path, "autoproj", xdg_path) home_path = File.join(home_dir, home_path) if File.exist?(xdg_path) xdg_path elsif File.exist?(home_path) home_path else xdg_path end end |
.find_user_cache_path(xdg_path, home_path = xdg_path) ⇒ Object
590 591 592 |
# File 'lib/autoproj/workspace.rb', line 590 def self.find_user_cache_path(xdg_path, home_path = xdg_path) find_path("CACHE_HOME", xdg_path, File.join(".autoproj", home_path)) end |
.find_user_config_path(xdg_path, home_path = xdg_path) ⇒ Object
578 579 580 |
# File 'lib/autoproj/workspace.rb', line 578 def self.find_user_config_path(xdg_path, home_path = xdg_path) find_path("CONFIG_HOME", xdg_path, home_path) end |
.find_user_data_path(xdg_path, home_path = xdg_path) ⇒ Object
586 587 588 |
# File 'lib/autoproj/workspace.rb', line 586 def self.find_user_data_path(xdg_path, home_path = xdg_path) find_path("DATA_HOME", xdg_path, File.join(".autoproj", home_path)) end |
.from_dir(dir, **workspace_options) ⇒ Workspace
Returns the workspace a directory is part of
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/autoproj/workspace.rb', line 107 def self.from_dir(dir, **) if (path = Autoproj.find_workspace_dir(dir)) Workspace.new(path, **) elsif Autoproj.find_v1_workspace_dir(dir) raise OutdatedWorkspace, "#{dir} looks like a v1 workspace, "\ "run autoproj upgrade before continuing" else raise NotWorkspace, "not in a Autoproj installation" end end |
.from_environment(**workspace_options) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/autoproj/workspace.rb', line 118 def self.from_environment(**) if (path = Autoproj.find_workspace_dir) from_dir(path, **) elsif Autoproj.find_v1_workspace_dir(dir = Autoproj.default_find_base_dir) raise OutdatedWorkspace, "#{dir} looks like a v1 workspace, "\ "run autoproj upgrade before continuing" elsif (envvar = ENV["AUTOPROJ_CURRENT_ROOT"]) raise NotWorkspace, "AUTOPROJ_CURRENT_ROOT is currently set "\ "to #{envvar}, but that is not an Autoproj workspace" else raise NotWorkspace, "not in an Autoproj installation, "\ "and no env.sh has been loaded so far" end end |
.from_pwd(**workspace_options) ⇒ Workspace
Returns the workspace the current directory is part of
97 98 99 |
# File 'lib/autoproj/workspace.rb', line 97 def self.from_pwd(**) from_dir(Dir.pwd, **) end |
.in_autoproj_project?(path) ⇒ Boolean
Tests whether the given path is under a directory tree managed by autoproj
135 136 137 |
# File 'lib/autoproj/workspace.rb', line 135 def self.in_autoproj_project?(path) Autoproj.find_workspace_dir(path) end |
.rcfile_path ⇒ Object
582 583 584 |
# File 'lib/autoproj/workspace.rb', line 582 def self.rcfile_path find_user_config_path("rc", ".autoprojrc") end |
.registered_workspaces ⇒ Object
596 597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/autoproj/workspace.rb', line 596 def self.registered_workspaces path = find_user_data_path("workspaces.yml") if File.file?(path) yaml = (YAML.safe_load(File.read(path)) || []) fields = RegisteredWorkspace.members.map(&:to_s) yaml.map do |h| values = h.values_at(*fields) RegisteredWorkspace.new(*values) end.compact else [] end end |
.save_registered_workspaces(workspaces) ⇒ Object
610 611 612 613 614 615 616 617 618 619 620 621 622 |
# File 'lib/autoproj/workspace.rb', line 610 def self.save_registered_workspaces(workspaces) workspaces = workspaces.map do |w| Hash["root_dir" => w.root_dir, "prefix_dir" => w.prefix_dir, "build_dir" => w.build_dir] end path = find_user_data_path("workspaces.yml") FileUtils.mkdir_p(File.dirname(path)) Ops.atomic_write(path) do |io| io.write YAML.dump(workspaces) end end |
Instance Method Details
#all_os_packages(import_missing: false, parallel: config.parallel_import_level) ⇒ Array<String>
Returns the list of all OS packages required by the state of the workspace
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 |
# File 'lib/autoproj/workspace.rb', line 867 def all_os_packages(import_missing: false, parallel: config.parallel_import_level) if import_missing ops = Autoproj::Ops::Import.new(self) _, all_os_packages = ops.import_packages( manifest.default_packages, checkout_only: true, only_local: true, reset: false, recursive: true, keep_going: true, parallel: parallel, retry_count: 0 ) all_os_packages else manifest.all_selected_osdep_packages end end |
#all_present_packages ⇒ Object
782 783 784 785 786 |
# File 'lib/autoproj/workspace.rb', line 782 def all_present_packages manifest.each_autobuild_package .find_all { |pkg| File.directory?(pkg.srcdir) } .map(&:name) end |
#autodetect_operating_system(force: false) ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/autoproj/workspace.rb', line 310 def (force: false) if force || !os_package_resolver. begin Autobuild.progress_start( :operating_system_autodetection, "autodetecting the operating system" ) names, versions = OSPackageResolver. os_package_resolver. = [names, versions] os_repository_resolver. = [names, versions] Autobuild.progress( :operating_system_autodetection, "operating system: #{(names - ['default']).join(',')} -"\ " #{(versions - ['default']).join(',')}" ) ensure Autobuild.progress_done :operating_system_autodetection end config.set("operating_system", os_package_resolver., true) end end |
#build_dir ⇒ String
Defines the temporary area in which packages should put their build files
If absolute, it is handled as #prefix_dir: the package name will be appended to it. If relative, it is relative to the package’s source directory
The default is “build”
213 214 215 |
# File 'lib/autoproj/workspace.rb', line 213 def build_dir config.build_dir end |
#build_dir=(path) ⇒ Object
Change #build_dir
218 219 220 |
# File 'lib/autoproj/workspace.rb', line 218 def build_dir=(path) config.set "build", path, true end |
#build_report_path ⇒ String
The full path to the build report
263 264 265 |
# File 'lib/autoproj/workspace.rb', line 263 def build_report_path File.join(log_dir, BUILD_REPORT_BASENAME) end |
#clear_main_workspace ⇒ Object
544 545 546 547 548 |
# File 'lib/autoproj/workspace.rb', line 544 def clear_main_workspace Autoproj.workspace = nil Autoproj.root_dir = nil Autobuild.env = nil end |
#compute_builddir(pkg) ⇒ Object
732 733 734 735 736 737 738 739 740 |
# File 'lib/autoproj/workspace.rb', line 732 def compute_builddir(pkg) # If we're given an absolute build dir, we have to append the # package name to it to make it unique if Pathname.new(build_dir).absolute? File.join(build_dir, pkg.name) else build_dir end end |
#config_dir ⇒ String
Returns the configuration directory for this autoproj installation.
171 172 173 |
# File 'lib/autoproj/workspace.rb', line 171 def config_dir File.join(root_dir, "autoproj") end |
#config_file_path ⇒ Object
The path to the workspace configuration file
187 188 189 |
# File 'lib/autoproj/workspace.rb', line 187 def config_file_path File.join(dot_autoproj_dir, "config.yml") end |
#define_package(package_type, package_name, block = nil, package_set = manifest.main_package_set, file = nil) ⇒ PackageDefinition
Define and register an autobuild package on this workspace
905 906 907 908 909 |
# File 'lib/autoproj/workspace.rb', line 905 def define_package(package_type, package_name, block = nil, package_set = manifest.main_package_set, file = nil) autobuild_package = Autobuild.send(package_type, package_name) register_package(autobuild_package, block, package_set, file) end |
#dot_autoproj_dir ⇒ Object
The directory under which autoproj saves all its internal configuration and files
177 178 179 |
# File 'lib/autoproj/workspace.rb', line 177 def dot_autoproj_dir File.join(root_dir, ".autoproj") end |
#export_env_sh(_package_names = nil, shell_helpers: true) ⇒ Boolean
Export the workspace’s env.sh file
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 |
# File 'lib/autoproj/workspace.rb', line 829 def export_env_sh(_package_names = nil, shell_helpers: true) full_env = self.full_env changed = save_cached_env(full_env) full_env.export_env_sh(shell_helpers: shell_helpers) build_dir = Pathname(self.build_dir) full_env.each_env_filename do |_, filename| basename = File.basename(filename) File.open(File.join(prefix_dir, basename), "w") do |io| io.puts "source \"#{filename}\"" end if build_dir.absolute? build_dir.mkpath (build_dir + basename).open("w") do |io| io.puts "source \"#{filename}\"" end end end changed end |
#export_installation_manifest ⇒ Object
Update this workspace’s installation manifest
813 814 815 |
# File 'lib/autoproj/workspace.rb', line 813 def export_installation_manifest installation_manifest.save end |
#finalize_package_setup ⇒ Object
Finalizes the configuration loading
This must be done before before we run any dependency-sensitive operation (e.g. import)
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 |
# File 'lib/autoproj/workspace.rb', line 746 def finalize_package_setup set_as_main_workspace # Now call the blocks that the user defined in the autobuild files. We do it # now so that the various package directories are properly setup manifest.each_package_definition do |pkg| pkg.user_blocks.each do |blk| blk[pkg.autobuild] end pkg.setup = true end manifest.each_package_set do |source| if source.local_dir load_if_present(source, source.local_dir, "overrides.rb") end end main_package_set = manifest.main_package_set Dir.glob(File.join(overrides_dir, "*.rb")).sort.each do |file| load main_package_set, file end end |
#finalize_setup(read_only: false) ⇒ Object
Finalizes the complete setup
This must be done after all ignores/excludes and package selection have been properly set up (a.k.a. after package import)
773 774 775 776 777 778 779 780 |
# File 'lib/autoproj/workspace.rb', line 773 def finalize_setup(read_only: false) # Finally, disable all ignored packages on the autobuild side manifest.each_ignored_package(&:disable) # We now have processed the process setup blocks. All configuration # should be done and we can save the configuration data. config.save unless read_only end |
#full_env ⇒ Object
The environment as initialized by all selected packages
818 819 820 821 822 823 824 |
# File 'lib/autoproj/workspace.rb', line 818 def full_env env = self.env.dup manifest.all_selected_source_packages.each do |pkg| pkg.autobuild.apply_env(env) end env end |
#import_report_path ⇒ String
The full path to the update report
254 255 256 |
# File 'lib/autoproj/workspace.rb', line 254 def import_report_path File.join(log_dir, IMPORT_REPORT_BASENAME) end |
#install_os_packages(packages, all: all_os_packages, **options) ⇒ Object
883 884 885 |
# File 'lib/autoproj/workspace.rb', line 883 def install_os_packages(packages, all: all_os_packages, **) os_package_installer.install(packages, all: all, **) end |
#install_os_repositories ⇒ Object
887 888 889 890 891 |
# File 'lib/autoproj/workspace.rb', line 887 def install_os_repositories return unless os_package_installer.osdeps_mode.include?("os") os_repository_installer.install_os_repositories end |
#install_ruby_shims ⇒ Object
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'lib/autoproj/workspace.rb', line 402 def install_ruby_shims install_suffix = "" if (match = /ruby(.*)$/.match(RbConfig::CONFIG["RUBY_INSTALL_NAME"])) install_suffix = match[1] end prefixdir = if config.isolate_ruby_shims? File.join(prefix_dir, "autoproj") else prefix_dir end bindir = File.join(prefixdir, "bin") FileUtils.mkdir_p bindir env.add "PATH", bindir Ops.atomic_write(File.join(bindir, "ruby")) do |io| io.puts "#! /bin/sh" io.puts "exec #{config.ruby_executable} \"$@\"" end FileUtils.chmod 0o755, File.join(bindir, "ruby") %w[gem irb testrb].each do |name| # Look for the corresponding gem program prg_name = "#{name}#{install_suffix}" if File.file?(prg_path = File.join(RbConfig::CONFIG["bindir"], prg_name)) Ops.atomic_write(File.join(bindir, name)) do |io| io.puts "#! #{config.ruby_executable}" io.puts "exec \"#{prg_path}\", *ARGV" end FileUtils.chmod 0o755, File.join(bindir, name) end end end |
#installation_manifest ⇒ InstallationManifest
Generate a InstallationManifest with the currently known information
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 |
# File 'lib/autoproj/workspace.rb', line 791 def installation_manifest selected_packages = manifest.all_selected_source_packages install_manifest = InstallationManifest.new(installation_manifest_path) # Update the new entries manifest.each_package_set do |pkg_set| next if pkg_set.main? install_manifest.add_package_set(pkg_set) end selected_packages.each do |pkg_name| pkg = manifest.package_definition_by_name(pkg_name) install_manifest.add_package(pkg) end # And save install_manifest end |
#installation_manifest_path ⇒ Object
The installation manifest
182 183 184 |
# File 'lib/autoproj/workspace.rb', line 182 def installation_manifest_path InstallationManifest.path_for_workspace_root(root_dir) end |
#load(*args) ⇒ Object
159 160 161 162 163 164 165 166 |
# File 'lib/autoproj/workspace.rb', line 159 def load(*args) set_as_main_workspace flag = Autoproj.warn_deprecated_level Autoproj.warn_deprecated_level = 1 super ensure Autoproj.warn_deprecated_level = flag end |
#load_all_available_package_manifests ⇒ Object
674 675 676 |
# File 'lib/autoproj/workspace.rb', line 674 def load_all_available_package_manifests manifest.load_all_available_package_manifests end |
#load_autoprojrc ⇒ Object
Loads the .autoprojrc file
This is included in #setup
643 644 645 646 647 |
# File 'lib/autoproj/workspace.rb', line 643 def load_autoprojrc set_as_main_workspace rcfile = Workspace.rcfile_path Kernel.load(rcfile) if File.file?(rcfile) end |
#load_cached_env ⇒ Object
854 855 856 |
# File 'lib/autoproj/workspace.rb', line 854 def load_cached_env Ops.load_cached_env(root_dir) end |
#load_config(reconfigure = false) ⇒ Configuration
Load the configuration for this workspace from config_file_path
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/autoproj/workspace.rb', line 280 def load_config(reconfigure = false) if File.file?(config_file_path) config.reset config.load(path: config_file_path, reconfigure: reconfigure) manifest.vcs = if (raw_vcs = config.get("manifest_source", nil)) VCSDefinition.from_raw(raw_vcs) else local_vcs = { type: "local", url: config_dir } VCSDefinition.from_raw(local_vcs) end if config.source_dir && Pathname.new(config.source_dir).absolute? raise ConfigError, "source dir path configuration must be relative" end os_package_resolver.prefer_indep_over_os_packages = config.prefer_indep_over_os_packages? os_package_resolver. ||= config.get("operating_system", nil) os_repository_resolver. ||= config.get("operating_system", nil) end @config end |
#load_main_initrb ⇒ Object
Loads autoproj/init.rb
This is included in #setup
553 554 555 556 557 558 |
# File 'lib/autoproj/workspace.rb', line 553 def load_main_initrb set_as_main_workspace local_source = manifest.main_package_set load_if_present(local_source, config_dir, "init.rb") end |
#load_package_sets(only_local: false, checkout_only: true, reconfigure: false, keep_going: false, mainline: nil, reset: false, retry_count: nil) ⇒ Object
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 |
# File 'lib/autoproj/workspace.rb', line 649 def load_package_sets(only_local: false, checkout_only: true, reconfigure: false, keep_going: false, mainline: nil, reset: false, retry_count: nil) return unless File.file?(manifest_file_path) # empty install, just return Ops::Configuration.new(self) .load_package_sets(only_local: only_local, checkout_only: checkout_only, keep_going: keep_going, reset: reset, retry_count: retry_count, mainline: mainline) end |
#load_packages(selection = manifest.default_packages(false), options = {}) ⇒ Object
667 668 669 670 671 672 |
# File 'lib/autoproj/workspace.rb', line 667 def load_packages(selection = manifest.default_packages(false), = {}) = Hash[warn_about_ignored_packages: true, checkout_only: true] .merge() ops = Ops::Import.new(self) ops.import_packages(selection, ) end |
#log_dir ⇒ Object
236 237 238 |
# File 'lib/autoproj/workspace.rb', line 236 def log_dir File.join(prefix_dir, "log") end |
#manifest_file_path ⇒ Object
The path to the workspace’s manifest file
192 193 194 |
# File 'lib/autoproj/workspace.rb', line 192 def manifest_file_path File.join(root_dir, "autoproj", config.get("manifest_name", "manifest")) end |
#migrate_bundler_and_autoproj_gem_layout ⇒ Object
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
# File 'lib/autoproj/workspace.rb', line 513 def migrate_bundler_and_autoproj_gem_layout if File.directory?(File.join(dot_autoproj_dir, "autoproj")) config_path = File.join(dot_autoproj_dir, "config.yml") config = YAML.safe_load(File.read(config_path)) return if config["gems_install_path"] else return end Autoproj.silent = false Autoproj.warn "The way bundler and autoproj are installed changed" Autoproj.warn "You must download" Autoproj.warn " https://raw.githubusercontent.com/rock-core/autoproj/master/bin/autoproj_install" Autoproj.warn "and run it at the root of this workspace" exit 2 end |
#operating_system ⇒ Object
332 333 334 |
# File 'lib/autoproj/workspace.rb', line 332 def os_package_resolver. end |
#overrides_dir ⇒ String
Returns the directory containing overrides files
245 246 247 |
# File 'lib/autoproj/workspace.rb', line 245 def overrides_dir File.join(config_dir, OVERRIDES_DIR) end |
#prefix_dir ⇒ String
The directory in which packages will be installed.
If it is a relative path, it is relative to the root dir of the installation.
The default is “install”
203 204 205 |
# File 'lib/autoproj/workspace.rb', line 203 def prefix_dir File.(config.prefix_dir, root_dir) end |
#prefix_dir=(path) ⇒ Object
Change #prefix_dir
208 209 210 |
# File 'lib/autoproj/workspace.rb', line 208 def prefix_dir=(path) config.prefix_dir = path end |
#pristine_os_packages(packages, options = Hash.new) ⇒ Object
858 859 860 |
# File 'lib/autoproj/workspace.rb', line 858 def pristine_os_packages(packages, = Hash.new) os_package_installer.pristine(packages, ) end |
#register_package(package, block = nil, package_set = manifest.main_package_set, file = nil) ⇒ PackageDefinition
Register an autobuild package on this workspace
921 922 923 924 925 926 |
# File 'lib/autoproj/workspace.rb', line 921 def register_package(package, block = nil, package_set = manifest.main_package_set, file = nil) pkg = manifest.register_package(package, block, package_set, file) pkg.autobuild.ws = self pkg end |
#register_workspace ⇒ Object
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
# File 'lib/autoproj/workspace.rb', line 624 def register_workspace current_workspaces = Workspace.registered_workspaces existing = current_workspaces.find { |w| w.root_dir == root_dir } if existing if existing.prefix_dir == prefix_dir && existing.build_dir == build_dir return end existing.prefix_dir = prefix_dir existing.build_dir = build_dir else current_workspaces << self end Workspace.save_registered_workspaces(current_workspaces) end |
#remotes_dir ⇒ Object
Return the directory in which remote package set definition should be checked out
198 199 200 |
# File 'lib/autoproj/workspace.rb', line 198 def remotes_dir File.join(dot_autoproj_dir, "remotes") end |
#rewrite_shims ⇒ Object
438 439 440 441 442 443 |
# File 'lib/autoproj/workspace.rb', line 438 def rewrite_shims gemfile = File.join(dot_autoproj_dir, "Gemfile") binstubs = File.join(dot_autoproj_dir, "bin") Ops::Install.rewrite_shims(binstubs, config.ruby_executable, root_dir, gemfile, config.gems_gem_home) end |
#run(*args, &block) ⇒ Object
501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/autoproj/workspace.rb', line 501 def run(*args, &block) = if args.last.kind_of?(Hash) args.pop else Hash.new end = .fetch(:env, Hash.new) [:env] = env.resolved_env.merge() Autobuild::Subprocess.run(*args, , &block) end |
#save_cached_env(env = full_env) ⇒ Object
850 851 852 |
# File 'lib/autoproj/workspace.rb', line 850 def save_cached_env(env = full_env) Ops.save_cached_env(root_dir, env) end |
#save_config ⇒ Object
306 307 308 |
# File 'lib/autoproj/workspace.rb', line 306 def save_config config.save(config_file_path) end |
#set_as_main_workspace ⇒ Object
530 531 532 533 534 535 536 537 538 539 540 541 542 |
# File 'lib/autoproj/workspace.rb', line 530 def set_as_main_workspace Autoproj.workspace = self Autoproj.root_dir = root_dir Autobuild.env = env if block_given? begin yield ensure clear_main_workspace end end end |
#setup(load_global_configuration: true, read_only: false) ⇒ Object
Perform initial configuration load and workspace setup
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/autoproj/workspace.rb', line 358 def setup(load_global_configuration: true, read_only: false) setup_ruby_version_handling migrate_bundler_and_autoproj_gem_layout load_config unless read_only register_workspace rewrite_shims end config.validate_ruby_executable Autobuild.programs["ruby"] = config.ruby_executable config.apply_autobuild_configuration load_autoprojrc if load_global_configuration load_main_initrb config.each_reused_autoproj_installation do |p| manifest.reuse(p) end manifest.load(manifest_file_path) if File.exist?(manifest_file_path) Autobuild.prefix = prefix_dir unless read_only FileUtils.mkdir_p File.join(prefix_dir, ".autoproj") Ops.atomic_write(File.join(prefix_dir, ".autoproj", "config.yml")) do |io| io.puts "workspace: \"#{root_dir}\"" end end Autobuild.srcdir = source_dir Autobuild.logdir = log_dir if (cache_dir = config.importer_cache_dir) Autobuild::Importer.default_cache_dirs = cache_dir os_package_installer.each_manager_with_name do |name, manager| next unless manager.respond_to?(:cache_dir=) manager_cache_path = File.join(cache_dir, "package_managers", name) if File.directory?(manager_cache_path) manager.cache_dir = manager_cache_path end end end setup_os_package_installer install_ruby_shims unless read_only end |
#setup_all_package_directories ⇒ Object
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 |
# File 'lib/autoproj/workspace.rb', line 678 def setup_all_package_directories # Override the package directories from our reused installations imported_packages = Set.new manifest.reused_installations.each do |imported_manifest| imported_manifest.each do |imported_pkg| imported_packages << imported_pkg.name if (pkg = manifest.find_package_definition(imported_pkg.name)) pkg.autobuild.srcdir = imported_pkg.srcdir pkg.autobuild.prefix = imported_pkg.prefix end end end manifest.each_package_definition do |pkg_def| pkg = pkg_def.autobuild next if imported_packages.include?(pkg_def.name) setup_package_directories(pkg) end end |
#setup_os_package_installer ⇒ Object
340 341 342 343 344 345 346 347 |
# File 'lib/autoproj/workspace.rb', line 340 def setup_os_package_installer os_package_installer.each_manager(&:initialize_environment) os_package_resolver.load_default os_package_installer.define_osdeps_mode_option os_package_installer.osdeps_mode os_package_installer.configure_manager end |
#setup_package_directories(pkg) ⇒ Object
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 |
# File 'lib/autoproj/workspace.rb', line 699 def setup_package_directories(pkg) pkg_name = pkg.name layout = if config.randomize_layout? Digest::SHA256.hexdigest(pkg_name)[0, 12] else manifest.whereis(pkg_name) end srcdir = if (target = manifest.moved_packages[pkg_name]) File.join(layout, target) else File.join(layout, pkg_name) end prefixdir = if config.separate_prefixes? pkg_name else layout end pkg = manifest.find_autobuild_package(pkg_name) pkg.srcdir = File.join(source_dir, srcdir) pkg.builddir = compute_builddir(pkg) if pkg.respond_to?(:builddir) pkg.prefix = File.join(prefix_dir, prefixdir) pkg.doc_target_dir = File.join(prefix_dir, "doc", pkg_name) pkg.logdir = File.join(pkg.prefix, "log") end |
#setup_ruby_version_handling ⇒ Object
349 350 351 352 |
# File 'lib/autoproj/workspace.rb', line 349 def setup_ruby_version_handling os_package_resolver.add_aliases("ruby" => ruby_version_keyword) osdep_suffixes << ruby_version_keyword end |
#source_dir ⇒ String?
Defines a folder to which source packages will be layed out relative to
If nil, packages will be layed out relative to root_dir Only relative paths are allowed
The default is nil
223 224 225 226 227 228 229 |
# File 'lib/autoproj/workspace.rb', line 223 def source_dir if config.source_dir File.(config.source_dir, root_dir) else root_dir end end |
#source_dir=(path) ⇒ Object
Change #source_dir
232 233 234 |
# File 'lib/autoproj/workspace.rb', line 232 def source_dir=(path) config.set "source", path, true end |
#supported_operating_system? ⇒ Boolean
336 337 338 |
# File 'lib/autoproj/workspace.rb', line 336 def os_package_resolver. end |
#update_autoproj(restart_on_update: true) ⇒ Object
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'lib/autoproj/workspace.rb', line 457 def update_autoproj(restart_on_update: true) config.validate_ruby_executable # This is a guard to avoid infinite recursion in case the user is # running autoproj osdeps --force return if ENV["AUTOPROJ_RESTARTING"] == "1" gemfile = File.join(dot_autoproj_dir, "Gemfile") binstubs = File.join(dot_autoproj_dir, "bin") if restart_on_update old_autoproj_path = PackageManagers::BundlerManager.bundle_gem_path( self, "autoproj", gemfile: gemfile ) end begin Autoproj. " updating autoproj" PackageManagers::BundlerManager.run_bundler_install( self, gemfile, binstubs: binstubs ) ensure rewrite_shims end if restart_on_update new_autoproj_path = PackageManagers::BundlerManager.bundle_gem_path( self, "autoproj", gemfile: gemfile ) end # First things first, see if we need to update ourselves if new_autoproj_path != old_autoproj_path puts Autoproj. "autoproj has been updated, restarting" puts # We updated autobuild or autoproj themselves ... Restart ! # # ...But first save the configuration (!) config.save ENV["AUTOPROJ_RESTARTING"] = "1" require "rbconfig" exec(config.ruby_executable, $PROGRAM_NAME, *ARGV) end end |
#update_bundler ⇒ Object
445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/autoproj/workspace.rb', line 445 def update_bundler require "autoproj/ops/install" gem_program = Ops::Install.guess_gem_program install = Ops::Install.new(root_dir) Autoproj. " updating bundler" install.install_bundler( gem_program, version: config.bundler_version, silent: true ) end |
#utility_report_path(name) ⇒ String
The full path to the report generated by the given utility
270 271 272 |
# File 'lib/autoproj/workspace.rb', line 270 def utility_report_path(name) File.join(log_dir, "#{name}_report.json") end |
#which(cmd, _path_entries: nil) ⇒ String
Find the given executable file in PATH
If ‘cmd` is an absolute path, it will either return it or raise if `cmd` is not executable. Otherwise, looks for an executable named `cmd` in PATH and returns it, or raises if it cannot be found. The exception contains a more detailed reason for failure
940 941 942 |
# File 'lib/autoproj/workspace.rb', line 940 def which(cmd, _path_entries: nil) Ops.which(cmd, path_entries: -> { full_env.value("PATH") || Array.new }) end |