bin/autoproj_install in autoproj-2.0.0.rc37 vs bin/autoproj_install in autoproj-2.0.0.rc38

- old
+ new

@@ -41,10 +41,11 @@ def initialize(root_dir) @root_dir = root_dir @gem_source = "https://rubygems.org" @gemfile = nil + @skip_stage2 = false @autoproj_options = Array.new @env = Hash.new env['RUBYLIB'] = [] @@ -111,10 +112,15 @@ # The path to the autoproj configuration file # # @return [String] def autoproj_config_path; File.join(dot_autoproj, 'config.yml') end + # Whether the stage2 install should be called or not + def skip_stage2?; !!@skip_stage2 end + # (see #skip_stage2?) + def skip_stage2=(flag); @skip_stage2 = flag end + # Whether we can access the network while installing def local?; !!@local end # (see #local?) def local=(flag); @local = flag end @@ -194,10 +200,13 @@ def parse_options(args = ARGV) options = OptionParser.new do |opt| opt.on '--local', 'do not access the network (may fail)' do @local = true end + opt.on '--skip-stage2', 'do not run the stage2 install' do + @skip_stage2 = true + end opt.on '--gem-source=URL', String, "use this source for RubyGems instead of rubygems.org" do |url| @gem_source = url end opt.on '--gems-path=PATH', "install gems under this path instead of ~/.autoproj/gems" do |path| self.gems_install_path = path @@ -301,10 +310,12 @@ end ensure self.class.rewrite_shims(shims_path, ruby_executable, autoproj_gemfile_path, gems_gem_home) end + EXCLUDED_FROM_SHIMS = %w{rake thor} + def self.rewrite_shims(shim_path, ruby_executable, autoproj_gemfile_path, gems_gem_home) FileUtils.mkdir_p shim_path File.open(File.join(shim_path, 'ruby'), 'w') do |io| io.puts "#! /bin/sh" io.puts "exec #{ruby_executable} \"$@\"" @@ -314,10 +325,14 @@ FileUtils.touch File.join(shim_path, 'bundler') FileUtils.touch File.join(shim_path, 'bundle') Dir.glob(File.join(shim_path, '*')) do |bin_script| next if !File.file?(bin_script) bin_name = File.basename(bin_script) + if EXCLUDED_FROM_SHIMS.include?(bin_name) + FileUtils.rm_f bin_script + next + end next if bin_name == 'ruby' bin_shim = File.join(shim_path, bin_name) bin_script_lines = File.readlines(bin_script) File.open(bin_shim, 'w') do |io| @@ -339,10 +354,11 @@ Bundler.with_clean_env do exec($0, *ARGV) end end +ENV['BUNDLE_GEMFILE'] ||= '#{autoproj_gemfile_path}' ENV['GEM_HOME'] = '#{gems_gem_home}' ENV.delete('GEM_PATH') Gem.paths = Hash['GEM_HOME' => '#{gems_gem_home}', 'GEM_PATH' => ''] load Gem.bin_path('bundler', 'bundler')" @@ -351,12 +367,14 @@ def self.shim_script(ruby_executable, autoproj_gemfile_path, gems_gem_home, load_line) "#! #{ruby_executable} if defined?(Bundler) Bundler.with_clean_env do - exec($0, *ARGV) + exec(Hash['RUBYLIB' => nil], $0, *ARGV) end +elsif ENV['RUBYLIB'] + exec(Hash['RUBYLIB' => nil], $0, *ARGV) end ENV['BUNDLE_GEMFILE'] = '#{autoproj_gemfile_path}' require 'rubygems' Gem.paths = Hash['GEM_HOME' => '#{gems_gem_home}', 'GEM_PATH' => ''] @@ -399,10 +417,22 @@ File.read(autoproj_gemfile_path) else default_gemfile_contents end + gemfile += [ + "", + "config_path = File.join(__dir__, 'config.yml')", + "if File.file?(config_path)", + " require 'yaml'", + " config = YAML.load(File.read(config_path))", + " (config['plugins'] || Hash.new).each do |plugin_name, (version, options)|", + " gem plugin_name, version, **options", + " end", + "end" + ].join("\n") + FileUtils.mkdir_p File.dirname(autoproj_gemfile_path) File.open(autoproj_gemfile_path, 'w') do |io| io.write gemfile end end @@ -565,6 +595,8 @@ ENV.delete('BUNDLE_GEMFILE') ENV.delete('RUBYLIB') ops = Autoproj::Ops::Install.new(Dir.pwd) ops.parse_options(ARGV) ops.stage1 -ops.call_stage2 +if !ops.skip_stage2? + ops.call_stage2 +end