lib/autoproj/package_managers/bundler_manager.rb in autoproj-2.0.0.rc32 vs lib/autoproj/package_managers/bundler_manager.rb in autoproj-2.0.0.rc33

- old
+ new

@@ -36,12 +36,12 @@ 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(ws) - env.set 'GEM_PATH', config.autoproj_gem_home + env.set 'GEM_HOME', config.gems_gem_home + env.clear 'GEM_PATH' gemfile_path = File.join(ws.prefix_dir, 'gems', 'Gemfile') if File.file?(gemfile_path) env.set('BUNDLE_GEMFILE', gemfile_path) end @@ -126,38 +126,58 @@ FileUtils.rm backup_file end end end - def self.run_bundler_install(ws, gemfile, *options, update: true, binstubs: nil) + def self.run_bundler_install(ws, gemfile, *options, update: true, binstubs: nil, gem_path: ws.config.gems_install_path) if update && File.file?("#{gemfile}.lock") FileUtils.rm "#{gemfile}.lock" end + options << '--path' << gem_path options << "--shebang" << Gem.ruby if binstubs options << "--binstubs" << binstubs end + connections = Set.new + run_bundler(ws, 'install', *options, gemfile: gemfile) do |line| + case line + when /Installing (.*)/ + Autobuild.message " bundler: installing #{$1}" + when /Fetching.*from (.*)/ + host = $1.gsub(/\.+$/, '') + if !connections.include?(host) + Autobuild.message " bundler: connected to #{host}" + connections << host + end + end + end + end + + def self.bundle_gem_path(ws, gem_name, gemfile: nil) + path = String.new + PackageManagers::BundlerManager.run_bundler(ws, 'show', gem_name, gemfile: gemfile) do |line| + path << line + end + path.chomp + end + + def self.run_bundler(ws, *commandline, gemfile: nil) Bundler.with_clean_env do - connections = Set.new + target_env = Hash[ + 'GEM_HOME' => nil, + 'GEM_PATH' => nil, + 'BUNDLE_GEMFILE' => gemfile, + 'RUBYOPT' => nil, + 'RUBYLIB' => nil + ] ws.run 'autoproj', 'osdeps', - Autobuild.tool('bundler'), 'install', - *options, - working_directory: File.dirname(gemfile), env: Hash['BUNDLE_GEMFILE' => nil, 'RUBYOPT' => nil] do |line| - - case line - when /Installing (.*)/ - Autobuild.message " bundler: installing #{$1}" - when /Fetching.*from (.*)/ - host = $1.gsub(/\.+$/, '') - if !connections.include?(host) - Autobuild.message " bundler: connected to #{host}" - connections << host - end + Autobuild.tool('bundler'), *commandline, + working_directory: File.dirname(gemfile), env: target_env do |line| + yield(line) if block_given? end - end end end # Parse the contents of a gemfile into a set of def merge_gemfiles(*path, unlock: []) @@ -311,15 +331,16 @@ def discover_bundle_rubylib(silent_errors: false) require 'bundler' gemfile = File.join(ws.prefix_dir, 'gems', 'Gemfile') silent_redirect = Hash.new if silent_errors - silent_redirect[:err] = '/dev/null' + silent_redirect[:err] = :close end + env = ws.env.resolved_env Tempfile.open 'autoproj-rubylib' do |io| result = Bundler.clean_system( - Hash['BUNDLE_GEMFILE' => gemfile, 'RUBYLIB' => nil], - Autobuild.tool('bundler'), 'exec', Autobuild.tool('ruby'), '-rbundler/setup', '-e', 'puts $LOAD_PATH', + Hash['GEM_HOME' => env['GEM_HOME'], 'GEM_PATH' => env['GEM_PATH'], 'BUNDLE_GEMFILE' => gemfile, 'RUBYOPT' => nil, 'RUBYLIB' => nil], + Autobuild.tool('ruby'), '-rbundler/setup', '-e', 'puts $LOAD_PATH', out: io, **silent_redirect) if result io.rewind io.readlines.map { |l| l.chomp }.find_all { |l| !l.empty? }