Class: Autoproj::PackageManagers::BundlerManager
- Defined in:
- lib/autoproj/package_managers/bundler_manager.rb
Overview
Package manager interface for the RubyGems system
Defined Under Namespace
Classes: GemEntry, NotCleanState
Class Attribute Summary collapse
-
.with_doc ⇒ Object
Returns the value of attribute with_doc.
- .with_prerelease(*value) ⇒ Object
Instance Attribute Summary collapse
-
#cache_dir ⇒ String
Directory with cached .gem packages.
Attributes inherited from Manager
Class Method Summary collapse
-
.add_build_configuration_for(gem_name, build_config, ws: Autoproj.workspace) ⇒ Object
Add new build configuration arguments for a given gem.
-
.apply_build_config(ws) ⇒ void
private
Apply configured per-gem build configuration options.
- .bundle_gem_path(ws, gem_name, bundler_version: ws.config.bundler_version, gem_home: nil, gemfile: nil) ⇒ Object
-
.configure_build_for(gem_name, build_config, ws: Autoproj.workspace) ⇒ Object
Set the build configuration for the given gem.
- .default_bundler(ws) ⇒ Object
- .default_gemfile_path(ws) ⇒ Object
-
.per_gem_build_config(ws) ⇒ Object
Enumerate the per-gem build configurations.
-
.remove_build_configuration_for(gem_name, ws: Autoproj.workspace) ⇒ Object
Removes build configuration flags for the given gem.
- .rubylib_for_bundler ⇒ Object
- .run_bundler(ws, *commandline, bundler_version: ws.config.bundler_version, gem_home: ws.config.gems_gem_home, gemfile: default_gemfile_path(ws)) ⇒ Object
- .run_bundler_install(ws, gemfile, *options, update: true, binstubs: nil, bundler_version: ws.config.bundler_version, gem_home: ws.config.gems_gem_home, gem_path: ws.config.gems_install_path) ⇒ Object
Instance Method Summary collapse
-
#backup_clean(mapping) ⇒ Object
private
Remove backups created by #backup_files.
-
#backup_files(mapping) ⇒ Object
private
Create backup files matching a certain file mapping.
-
#backup_restore(mapping) ⇒ Object
private
Restore backups saved by #backup_file.
-
#call_while_empty? ⇒ Boolean
Whether this package manager should be called even if no packages should be installed.
- #create_cache_copy(cache_dir, bundler_cache_dir) ⇒ Object
- #create_cache_symlink(cache_dir, bundler_cache_dir) ⇒ Object
- #discover_bundle_rubylib(silent_errors: false) ⇒ Object
- #discover_rubylib ⇒ Object
-
#initialize_environment ⇒ Object
Set up the workspace environment to work with the bundler-managed gems.
- #install(gems, filter_uptodate_packages: false, install_only: false) ⇒ Object
-
#merge_gemfiles(*path, ruby_version: nil, unlock: []) ⇒ Object
Parse the contents of a gemfile into a set of.
-
#prepare_osdeps_gemfile(gems) ⇒ File
Prepare a Gemfile that contains osdeps gem declarations.
-
#strict? ⇒ Boolean
Whether this package manager needs to maintain a list of all the packages that are needed for the whole installation (true), or needs only to be called with packages to install.
-
#update_env_rubylib(bundle_rubylib, system_rubylib = discover_rubylib) ⇒ Object
private
Update RUBYLIB to add the gems that are part of the bundler install.
- #workspace_configuration_gemfiles ⇒ Object
Methods inherited from Manager
#configure_manager, #enabled?, #initialize, #os_dependencies, #silent?
Constructor Details
This class inherits a constructor from Autoproj::PackageManagers::Manager
Class Attribute Details
.with_doc ⇒ Object
Returns the value of attribute with_doc.
8 9 10 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 8 def with_doc @with_doc end |
.with_prerelease(*value) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 13 def self.with_prerelease(*value) if value.empty? @with_prerelease else begin saved_flag = @with_prerelease @with_prerelease = value.first yield ensure @with_prerelease = saved_flag end end end |
Instance Attribute Details
#cache_dir ⇒ String
Directory with cached .gem packages
The directory must exist, but may be empty. It is initialized with #cache_dir
33 34 35 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 33 def cache_dir @cache_dir end |
Class Method Details
.add_build_configuration_for(gem_name, build_config, ws: Autoproj.workspace) ⇒ Object
Add new build configuration arguments for a given gem
This is meant to be used from the Autoproj configuration files, e.g. overrides.rb or package configuration
175 176 177 178 179 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 175 def self.add_build_configuration_for(gem_name, build_config, ws: Autoproj.workspace) c = ws.config.get("bundler.build", {}) c[gem_name] = [c[gem_name], build_config].compact.join(" ") ws.config.set("bundler.build", c) end |
.apply_build_config(ws) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Apply configured per-gem build configuration options
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 208 def self.apply_build_config(ws) root_dir = File.join(ws.prefix_dir, "gems") current_config_path = File.join(root_dir, ".bundle", "config") current_config = if File.file?(current_config_path) File.readlines(current_config_path) else [] end build_config = {} per_gem_build_config(ws).each do |name, conf| build_config[name.upcase] = conf end new_config = current_config.map do |line| next(line) unless (m = line.match(/BUNDLE_BUILD__(.*): "(.*)"$/)) next unless (desired_config = build_config.delete(m[1])) if m[2] == desired_config line else "BUNDLE_BUILD__#{m[1]}: \"#{desired_config}\"" end end.compact build_config.each do |name, config| new_config << "BUNDLE_BUILD__#{name}: \"#{config}\"" end if new_config != current_config FileUtils.mkdir_p File.dirname(current_config_path) File.open(current_config_path, "w") do |io| io.write new_config.join end end end |
.bundle_gem_path(ws, gem_name, bundler_version: ws.config.bundler_version, gem_home: nil, gemfile: nil) ⇒ Object
343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 343 def self.bundle_gem_path(ws, gem_name, bundler_version: ws.config.bundler_version, gem_home: nil, gemfile: nil) path = String.new run_bundler( ws, "show", gem_name, bundler_version: bundler_version, gem_home: gem_home, gemfile: gemfile ) { |line| path << line } path.chomp end |
.configure_build_for(gem_name, build_config, ws: Autoproj.workspace) ⇒ Object
Set the build configuration for the given gem
This is meant to be used from the Autoproj configuration files, e.g. overrides.rb or package configuration
185 186 187 188 189 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 185 def self.configure_build_for(gem_name, build_config, ws: Autoproj.workspace) c = ws.config.get("bundler.build", {}) c[gem_name] = build_config ws.config.set("bundler.build", c) end |
.default_bundler(ws) ⇒ Object
355 356 357 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 355 def self.default_bundler(ws) File.join(ws.dot_autoproj_dir, "bin", "bundle") end |
.default_gemfile_path(ws) ⇒ Object
472 473 474 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 472 def self.default_gemfile_path(ws) File.join(ws.prefix_dir, "gems", "Gemfile") end |
.per_gem_build_config(ws) ⇒ Object
Enumerate the per-gem build configurations
167 168 169 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 167 def self.per_gem_build_config(ws) ws.config.get("bundler.build", {}) end |
.remove_build_configuration_for(gem_name, ws: Autoproj.workspace) ⇒ Object
Removes build configuration flags for the given gem
This is meant to be used from the Autoproj configuration files, e.g. overrides.rb or package configuration
195 196 197 198 199 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 195 def self.remove_build_configuration_for(gem_name, ws: Autoproj.workspace) c = ws.config.get("bundler.build", {}) c.delete(gem_name) ws.config.set("bundler.build", c) end |
.rubylib_for_bundler ⇒ Object
633 634 635 636 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 633 def self.rubylib_for_bundler rx = Regexp.new("/gems/#{Regexp.quote("bundler-#{Bundler::VERSION}")}/") $LOAD_PATH.grep(rx).join(File::PATH_SEPARATOR) end |
.run_bundler(ws, *commandline, bundler_version: ws.config.bundler_version, gem_home: ws.config.gems_gem_home, gemfile: default_gemfile_path(ws)) ⇒ Object
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 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 359 def self.run_bundler(ws, *commandline, bundler_version: ws.config.bundler_version, gem_home: ws.config.gems_gem_home, gemfile: default_gemfile_path(ws)) bundle = Autobuild.programs["bundle"] || default_bundler(ws) Autoproj.bundler_with_unbundled_env do bundler_version_env = if bundler_version { "BUNDLER_VERSION" => bundler_version } else {} end target_env = Hash[ "GEM_HOME" => gem_home, "GEM_PATH" => nil, "BUNDLE_GEMFILE" => gemfile, "BUNDLE_LOCKFILE" => "#{gemfile}.lock", "RUBYOPT" => nil, "RUBYLIB" => rubylib_for_bundler, ].merge(bundler_version_env) ws.run("autoproj", "osdeps", bundle, *commandline, working_directory: File.dirname(gemfile), env: target_env) { |line| yield(line) if block_given? } end end |
.run_bundler_install(ws, gemfile, *options, update: true, binstubs: nil, bundler_version: ws.config.bundler_version, gem_home: ws.config.gems_gem_home, gem_path: ws.config.gems_install_path) ⇒ Object
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 300 def self.run_bundler_install( ws, gemfile, *, update: true, binstubs: nil, bundler_version: ws.config.bundler_version, gem_home: ws.config.gems_gem_home, gem_path: ws.config.gems_install_path ) FileUtils.rm "#{gemfile}.lock" if update && File.file?("#{gemfile}.lock") run_bundler(ws, "config", "set", "--local", "path", gem_path, bundler_version: bundler_version) run_bundler(ws, "config", "set", "--local", "shebang", Gem.ruby, bundler_version: bundler_version) if binstubs run_bundler(ws, "config", "set", "--local", "bin", binstubs, bundler_version: bundler_version) end apply_build_config(ws) connections = Set.new run_bundler(ws, "install", *, bundler_version: bundler_version, gem_home: gem_home, gemfile: gemfile) do |line| case line when /Installing (.*)/ Autobuild. " bundler: installing #{$1}" when /Fetching.*from (.*)/ host = $1.gsub(/\.+$/, "") unless connections.include?(host) Autobuild. " bundler: connected to #{host}" connections << host end end end if binstubs run_bundler(ws, "binstubs", "--all", bundler_version: bundler_version, gem_home: gem_home, gemfile: gemfile) end end |
Instance Method Details
#backup_clean(mapping) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Remove backups created by #backup_files
294 295 296 297 298 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 294 def backup_clean(mapping) mapping.each do |_file, backup_file| FileUtils.rm backup_file if File.file?(backup_file) end end |
#backup_files(mapping) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create backup files matching a certain file mapping
272 273 274 275 276 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 272 def backup_files(mapping) mapping.each do |file, backup_file| FileUtils.cp file, backup_file if File.file?(file) end end |
#backup_restore(mapping) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Restore backups saved by #backup_file
283 284 285 286 287 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 283 def backup_restore(mapping) mapping.each do |file, backup_file| FileUtils.cp backup_file, file if File.file?(backup_file) end end |
#call_while_empty? ⇒ Boolean
Whether this package manager should be called even if no packages should be installed
This is needed if the installer has ways to get specifications of packages to install through other means than the osdep system, as e.g. Autoproj::PackageManagers::BundlerManager that would install gems listed in autoproj/Gemfile
36 37 38 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 36 def call_while_empty? !workspace_configuration_gemfiles.empty? end |
#create_cache_copy(cache_dir, bundler_cache_dir) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 143 def create_cache_copy(cache_dir, bundler_cache_dir) valid = !File.exist?(bundler_cache_dir) || File.directory?(bundler_cache_dir) || File.symlink?(bundler_cache_dir) unless valid Autoproj.warn "cannot use #{cache_dir} as gem cache as "\ "#{bundler_cache_dir} already exists" return end # Gracefully upgrade from the symlinks FileUtils.rm_f bundler_cache_dir if File.symlink?(bundler_cache_dir) FileUtils.mkdir_p bundler_cache_dir Dir.glob(File.join(cache_dir, "*.gem")) do |path_src| path_dest = File.join(bundler_cache_dir, File.basename(path_src)) next if File.exist?(path_dest) FileUtils.cp path_src, path_dest end end |
#create_cache_symlink(cache_dir, bundler_cache_dir) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 128 def create_cache_symlink(cache_dir, bundler_cache_dir) if File.exist?(bundler_cache_dir) if !File.symlink?(bundler_cache_dir) Autoproj.warn "cannot use #{cache_dir} as gem cache as "\ "#{bundler_cache_dir} already exists" return elsif File.readlink(bundler_cache_dir) == cache_dir return end end FileUtils.rm_f bundler_cache_dir FileUtils.ln_s cache_dir, bundler_cache_dir end |
#discover_bundle_rubylib(silent_errors: false) ⇒ Object
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 638 def discover_bundle_rubylib(silent_errors: false) require "bundler" gemfile = File.join(ws.prefix_dir, "gems", "Gemfile") silent_redirect = Hash.new silent_redirect[:err] = :close if silent_errors env = ws.env.resolved_env Tempfile.open "autoproj-rubylib" do |io| result = Autoproj.bundler_unbundled_system( Hash["GEM_HOME" => env["GEM_HOME"], "GEM_PATH" => env["GEM_PATH"], "BUNDLE_GEMFILE" => gemfile, "BUNDLE_LOCKFILE" => "#{gemfile}.lock", "RUBYOPT" => nil, "RUBYLIB" => self.class.rubylib_for_bundler], Autobuild.tool("ruby"), "-rbundler/setup", "-e", "puts $LOAD_PATH", out: io, **silent_redirect ) if result io.rewind io.readlines.map(&:chomp).find_all { |l| !l.empty? } end end end |
#discover_rubylib ⇒ Object
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 617 def discover_rubylib require "bundler" Tempfile.open "autoproj-rubylib" do |io| result = Autoproj.bundler_unbundled_system( Hash["RUBYLIB" => nil], Autobuild.tool("ruby"), "-e", "puts $LOAD_PATH", out: io, err: "/dev/null" ) if result io.rewind io.readlines.map(&:chomp).find_all { |l| !l.empty? } end end end |
#initialize_environment ⇒ Object
Set up the workspace environment to work with the bundler-managed gems
47 48 49 50 51 52 53 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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 47 def initialize_environment env = ws.env config = ws.config env.add_path "PATH", File.join(ws.prefix_dir, "gems", "bin") env.add_path "PATH", File.join(ws.dot_autoproj_dir, "bin") env.set "GEM_HOME", config.gems_gem_home env.clear "GEM_PATH" if (bundler_version = config.bundler_version) env.set "BUNDLER_VERSION", bundler_version else env.clear "BUNDLER_VERSION" end gemfile_path = File.join(ws.prefix_dir, "gems", "Gemfile") if File.file?(gemfile_path) env.set("BUNDLE_GEMFILE", gemfile_path) env.set("BUNDLE_LOCKFILE", "#{gemfile_path}.lock") end if cache_dir && File.exist?(cache_dir) vendor_dir = File.join(File.dirname(gemfile_path), "vendor") FileUtils.mkdir_p vendor_dir bundler_cache_dir = File.join(vendor_dir, "cache") if File.writable?(cache_dir) create_cache_symlink(cache_dir, bundler_cache_dir) else Autoproj.warn "BundlerManager: #{cache_dir} is read-only "\ "copying the cache instead of symlinking it" create_cache_copy(cache_dir, bundler_cache_dir) end end Autobuild.programs["bundler"] = Autobuild.programs["bundle"] = File.join(ws.dot_autoproj_dir, "bin", "bundle") env.init_from_env "RUBYLIB" env.inherit "RUBYLIB" # Sanitize the rubylib we get from the environment by removing # anything that comes from Gem or Bundler original_rubylib = (env["RUBYLIB"] || "").split(File::PATH_SEPARATOR).find_all do |p| !p.start_with?(Bundler.rubygems.gem_dir) && Bundler.rubygems.gem_path .none? { |gem_p| p.start_with?(gem_p) } end # And discover the system's rubylib if (system_rubylib = discover_rubylib) # Do not explicitely add the system rubylib to the # environment, the interpreter will do it for us. # # This allows to use a binstub generated for one of ruby # interpreter version on our workspace env.system_env["RUBYLIB"] = [] env.original_env["RUBYLIB"] = (original_rubylib - system_rubylib) .join(File::PATH_SEPARATOR) end ws.config.each_reused_autoproj_installation do |p| reused_w = ws.new(p) env.add_path "PATH", File.join(reused_w.prefix_dir, "gems", "bin") end prefix_gems = File.join(ws.prefix_dir, "gems") FileUtils.mkdir_p prefix_gems gemfile = File.join(prefix_gems, "Gemfile") unless File.exist?(gemfile) Ops.atomic_write(gemfile) do |io| dot_autoproj_gemfile = File.join(ws.dot_autoproj_dir, "Gemfile") io.puts "eval_gemfile \"#{dot_autoproj_gemfile}\"" end end if (bundle_rubylib = discover_bundle_rubylib(silent_errors: true)) update_env_rubylib(bundle_rubylib, system_rubylib) end end |
#install(gems, filter_uptodate_packages: false, install_only: false) ⇒ Object
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 527 def install(gems, filter_uptodate_packages: false, install_only: false) gemfile_path = self.class.default_gemfile_path(ws) root_dir = File.dirname(gemfile_path) gemfile_lock_path = "#{gemfile_path}.lock" backups = Hash[ gemfile_path => "#{gemfile_path}.orig", gemfile_lock_path => "#{gemfile_lock_path}.orig" ] # Back up the existing gemfile, we'll restore it if something is # wrong to avoid leaving bundler in an inconsistent state backup_files(backups) unless File.file?("#{gemfile_path}.orig") Ops.atomic_write("#{gemfile_path}.orig") do |io| dot_autoproj_gemfile = File.join(ws.dot_autoproj_dir, "Gemfile") io.puts "eval_gemfile \"#{dot_autoproj_gemfile}\"" end end gemfiles = [] unless gems.empty? osdeps_gemfile_io = prepare_osdeps_gemfile(gems) gemfiles << osdeps_gemfile_io.path end gemfiles += workspace_configuration_gemfiles # The autoproj gemfile needs to be last, we really don't # want to mess it up gemfiles << File.join(ws.dot_autoproj_dir, "Gemfile") ruby_version = RUBY_VERSION.gsub(/\.\d+$/, ".0") gemfile_contents = merge_gemfiles(*gemfiles, ruby_version: "~> #{ruby_version}") FileUtils.mkdir_p root_dir updated = (!File.exist?(gemfile_path) || File.read(gemfile_path) != gemfile_contents) if updated Ops.atomic_write(gemfile_path) do |io| io.puts gemfile_contents end end = [] binstubs_path = File.join(root_dir, "bin") if updated || !install_only || !File.file?("#{gemfile_path}.lock") self.class.run_bundler_install(ws, gemfile_path, *, binstubs: binstubs_path) end if (bundle_rubylib = discover_bundle_rubylib) update_env_rubylib(bundle_rubylib) else raise NotCleanState, "bundler executed successfully, "\ "but the result was not in a clean state" end rescue Exception Autoproj.warn "saved the new Gemfile in #{gemfile_path}.FAILED "\ "and restored the last Gemfile version" FileUtils.cp gemfile_path, "#{gemfile_path}.FAILED" backup_restore(backups) raise ensure if binstubs_path FileUtils.rm_f File.join(binstubs_path, "bundle") FileUtils.rm_f File.join(binstubs_path, "bundler") end backup_clean(backups) end |
#merge_gemfiles(*path, ruby_version: nil, unlock: []) ⇒ Object
Parse the contents of a gemfile into a set of
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 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 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 387 def merge_gemfiles(*path, ruby_version: nil, unlock: []) gems_remotes = Set.new dependencies = Hash.new do |h, k| h[k] = Hash.new do |i, j| i[j] = Hash.new do |a, b| a[b] = Array.new end end end path.each do |gemfile| bundler_def = begin Bundler::Dsl.evaluate(gemfile, nil, []) rescue Exception => e = e . .gsub(/There was an error parsing([^:]+)/, "Error in gem definitions") .gsub(/# from.*/, "") raise ConfigError, end gems_remotes |= bundler_def.send(:sources).rubygems_sources.flat_map(&:remotes).to_set bundler_def.dependencies.each do |d| d.groups.each do |group_name| if d.platforms.empty? dependencies[group_name][""][d.name] = d else d.platforms.each do |platform_name| dependencies[group_name][platform_name][d.name] = d end end end end end contents = [] gems_remotes.each do |g| g = g.to_s g = g[0..-2] if g.end_with?("/") contents << "source '#{g}'" end if ruby_version contents << "ruby \"#{ruby_version}\" if respond_to?(:ruby)" end valid_keys = %w[group groups git path glob name branch ref tag require submodules platform platforms type source install_if] dependencies.each do |group_name, by_platform| contents << "group :#{group_name} do" by_platform.each do |platform_name, deps| deps = deps.values.sort_by(&:name) unless platform_name.empty? contents << " platform :#{platform_name} do" platform_indent = " " end deps.each do |d| if d.source = d.source..dup .delete_if { |k, _| !valid_keys.include?(k) } = .map { |k, v| "#{k}: \"#{v}\"" } end contents << [" #{platform_indent}gem \"#{d.name}\", \"#{d.requirement}\"", *].join(", ") end contents << " end" unless platform_name.empty? end contents << "end" end contents.join("\n") end |
#prepare_osdeps_gemfile(gems) ⇒ File
Prepare a Gemfile that contains osdeps gem declarations
603 604 605 606 607 608 609 610 611 612 613 614 615 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 603 def prepare_osdeps_gemfile(gems) io = Tempfile.open "autoproj-gemfile" io.puts "source \"https://rubygems.org\"" gems.map { |entry| GemEntry.parse(entry) } .sort_by(&:name) .each { |entry| io.puts entry.to_gemfile_line } io.flush io rescue Exception io&.close raise end |
#strict? ⇒ Boolean
Whether this package manager needs to maintain a list of all the packages that are needed for the whole installation (true), or needs only to be called with packages to install
OS package managers are generally non-strict (once a package is installed, it’s available to all). Package managers like Autoproj::PackageManagers::BundlerManager are strict as they maintain a list of gems that are then made available to the whole installation
The default is false, reimplement in subclasses to return true
41 42 43 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 41 def strict? true end |
#update_env_rubylib(bundle_rubylib, system_rubylib = discover_rubylib) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Update RUBYLIB to add the gems that are part of the bundler install
255 256 257 258 259 260 261 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 255 def update_env_rubylib(bundle_rubylib, system_rubylib = discover_rubylib) current = (ws.env.resolved_env["RUBYLIB"] || "") .split(File::PATH_SEPARATOR) + system_rubylib (bundle_rubylib - current).each do |p| ws.env.add_path("RUBYLIB", p) end end |
#workspace_configuration_gemfiles ⇒ Object
457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 457 def workspace_configuration_gemfiles gemfiles = [] ws.manifest.each_package_set do |source| pkg_set_gemfile = File.join(source.local_dir, "Gemfile") if source.local_dir && File.file?(pkg_set_gemfile) gemfiles << pkg_set_gemfile end end # In addition, look into overrides.d Dir.glob(File.join(ws.overrides_dir, "*.gemfile")) do |overrides_gemfile| gemfiles << overrides_gemfile end gemfiles end |