lib/autoproj/package_managers/bundler_manager.rb in autoproj-2.0.0.rc5 vs lib/autoproj/package_managers/bundler_manager.rb in autoproj-2.0.0.rc6

- old
+ new

@@ -28,51 +28,37 @@ def initialize_environment env = ws.env env.inherit 'GEM_PATH' env.init_from_env 'GEM_PATH' - orig_gem_path = (env['GEM_PATH'] || "").split(File::PATH_SEPARATOR).find_all do |p| - !Workspace.in_autoproj_project?(p) - end env.system_env['GEM_PATH'] = Gem.default_path - env.original_env['GEM_PATH'] = orig_gem_path.join(File::PATH_SEPARATOR) - if Workspace.in_autoproj_project?(env['GEM_HOME']) + if env.original_env['GEM_HOME'].empty? env.unset('GEM_HOME') end env.init_from_env 'RUBYLIB' env.inherit 'RUBYLIB' original_rubylib = (env['RUBYLIB'] || "").split(File::PATH_SEPARATOR).find_all do |p| - !Workspace.in_autoproj_project?(p) - !p.start_with?(Bundler.rubygems.gem_dir) && + !p.start_with?(Bundler.rubygems.gem_dir) && !Bundler.rubygems.gem_path.any? { |gem_p| p.start_with?(p) } end if system_rubylib = discover_rubylib env.system_env['RUBYLIB'] = [] env.original_env['RUBYLIB'] = (original_rubylib - system_rubylib).join(File::PATH_SEPARATOR) end - dot_autoproj = ws.dot_autoproj_dir - if ws.config.private_bundler? - env.add_path 'GEM_PATH', File.join(dot_autoproj, 'bundler') - end - if ws.config.private_autoproj? - env.add_path 'GEM_PATH', File.join(dot_autoproj, 'autoproj') - end - - ws.manifest.each_reused_autoproj_installation do |p| + ws.config.each_reused_autoproj_installation do |p| reused_w = ws.new(p) reused_c = reused_w.load_config if reused_c.private_gems? env.add_path 'GEM_PATH', File.join(reused_w.prefix_dir, 'gems') end env.add_path 'PATH', File.join(reused_w.prefix_dir, 'gems', 'bin') end - gem_home = File.join(ws.prefix_dir, "gems") if ws.config.private_gems? env.set 'GEM_HOME', gem_home env.add_path 'GEM_PATH', gem_home end @@ -84,21 +70,31 @@ io.puts "eval_gemfile \"#{File.join(ws.dot_autoproj_dir, 'autoproj', 'Gemfile')}\"" end end env.set 'BUNDLE_GEMFILE', File.join(gem_home, 'Gemfile') + env.add_path 'PATH', Gem.bindir env.add_path 'PATH', File.join(gem_home, 'bin') - env.add_path 'PATH', File.join(ws.dot_autoproj_dir, 'autoproj', 'bin') - Autobuild.programs['bundler'] = File.join(ws.dot_autoproj_dir, 'autoproj', 'bin', 'bundler') + dot_autoproj = ws.dot_autoproj_dir + if ws.config.private_bundler? + env.add_path 'PATH', File.join(dot_autoproj, 'bundler', 'bin') + env.add_path 'GEM_PATH', File.join(dot_autoproj, 'bundler') + end + env.add_path 'PATH', File.join(dot_autoproj, 'autoproj', 'bin') + if ws.config.private_autoproj? + env.add_path 'GEM_PATH', File.join(dot_autoproj, 'autoproj') + end + Autobuild.programs['bundler'] = 'bundler' + if bundle_rubylib = discover_bundle_rubylib update_env_rubylib(bundle_rubylib, system_rubylib) end end def update_env_rubylib(bundle_rubylib, system_rubylib = discover_rubylib) - current = ws.env.resolved_env['RUBYLIB'].split(File::PATH_SEPARATOR) + system_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 @@ -146,10 +142,15 @@ ] # Back up the existing gemfile, we'll restore it if something is # wrong to avoid leaving bundler in an inconsistent state backup_files(backups) + if !File.file?("#{gemfile_path}.orig") + File.open("#{gemfile_path}.orig", 'w') do |io| + io.puts "eval_gemfile \"#{File.join(ws.dot_autoproj_dir, 'autoproj', 'Gemfile')}\"" + end + end # Generate the gemfile and remove the lockfile gems = gems.sort.map do |name| name, version = parse_package_entry(name) "gem \"#{name}\", \"#{version || ">= 0"}\"" @@ -159,20 +160,18 @@ io.puts "eval_gemfile \"#{File.join(ws.dot_autoproj_dir, 'autoproj', 'Gemfile')}\"" io.puts gems end FileUtils.rm File.join(root_dir, 'Gemfile.lock') - if ws.config.private_gems? - options = ['--path', root_dir] - end - + binstubs_path = File.join(root_dir, 'bin') Bundler.with_clean_env do connections = Set.new Autobuild::Subprocess.run 'autoproj', 'osdeps', Autobuild.tool('bundler'), 'install', "--gemfile=#{gemfile_path}", *options, - "--binstubs", File.join(root_dir, 'bin'), + "--binstubs", binstubs_path, + "--shebang", Gem.ruby, env: Hash['BUNDLE_GEMFILE' => gemfile_path] do |line| case line when /Installing (.*)/ Autobuild.message " bundler: installing #{$1}" @@ -194,20 +193,21 @@ rescue Exception => e backup_restore(backups) raise ensure + FileUtils.rm_f File.join(binstubs_path, 'bundler') backup_clean(backups) end def discover_rubylib Tempfile.open 'autoproj-rubylib' do |io| result = Bundler.clean_system( Hash['RUBYLIB' => nil], Autobuild.tool('ruby'), '-e', 'puts $LOAD_PATH', - out: io) - #err: '/dev/null') + out: io, + err: '/dev/null') if result io.readlines.map { |l| l.chomp }.find_all { |l| !l.empty? } end end end @@ -216,11 +216,11 @@ gemfile = File.join(ws.prefix_dir, 'gems', 'Gemfile') Tempfile.open 'autoproj-rubylib' do |io| result = Bundler.clean_system( Hash['BUNDLE_GEMFILE' => gemfile], Autobuild.tool('bundler'), 'exec', 'ruby', '-e', 'puts $LOAD_PATH', - out: io) - #err: '/dev/null') + out: io, + err: '/dev/null') if result io.readlines.map { |l| l.chomp }.find_all { |l| !l.empty? } end end end