bin/autoproj_bootstrap in autoproj-1.9.7.rc2 vs bin/autoproj_bootstrap in autoproj-1.9.7.rc3

- old
+ new

@@ -51,24 +51,16 @@ end # Environment is clean, so just mark it as so unconditionally ENV['AUTOPROJ_BOOTSTRAP_IGNORE_NONEMPTY_DIR'] = '1' -needed_gem_home = ENV['AUTOPROJ_GEM_HOME'] || "#{Dir.pwd}/.gems" -if $LOADED_FEATURES.find { |str| str =~ /bygems/ } - if ENV['GEM_HOME'] != needed_gem_home - require 'rbconfig' - RUBY = RbConfig::CONFIG['RUBY_INSTALL_NAME'] +gem_home = ENV['AUTOPROJ_GEM_HOME'] || File.join(Dir.pwd, '.gems') +gem_path = ([gem_home] + Gem.default_path).join(":") +Gem.paths = Hash['GEM_HOME' => gem_home, 'GEM_PATH' => gem_path] - ENV['GEM_HOME'] = needed_gem_home - ENV['GEM_PATH'] = nil - exec RUBY, __FILE__, *ARGV - end -end - - -ENV['GEM_HOME'] = needed_gem_home +ENV['GEM_HOME'] = gem_home +ENV['GEM_PATH'] = gem_path ENV['PATH'] = "#{ENV['GEM_HOME']}/bin:#{ENV['PATH']}" require 'yaml' require 'set' @@ -477,13 +469,11 @@ Autobuild.env_add_path 'GEM_PATH', gem_home Autobuild.env_set 'GEM_HOME', gem_home Autobuild.env_add_path 'PATH', "#{gem_home}/bin" # Now, reset the directories in our own RubyGems instance - if Gem::Specification.respond_to?(:dirs=) - Gem::Specification.dirs = ENV['GEM_PATH'].split(':') - end + Gem.paths = ENV end # Return the directory in which RubyGems package should be installed def self.gem_home ENV['AUTOPROJ_GEM_HOME'] || File.join(Autoproj.root_dir, ".gems") @@ -806,10 +796,18 @@ def self.ruby_version_keyword "ruby#{RUBY_VERSION.split('.')[0, 2].join("")}" end + def self.autodetect_ruby_program + ruby = RbConfig::CONFIG['RUBY_INSTALL_NAME'] + ruby_bindir = RbConfig::CONFIG['bindir'] + ruby_executable = File.join(ruby_bindir, ruby) + Autobuild.programs['ruby'] = ruby_executable + ruby_executable + end + def self.autodetect_ruby self.alias(ruby_version_keyword, "ruby") end self.suffixes << ruby_version_keyword autodetect_ruby @@ -1700,10 +1698,73 @@ end end end +module Autobuild + class << self + # Configure the programs used by different packages + attr_reader :programs + # A cache of entries in programs to their resolved full path + # + # @return [{String=>[String,String,String]}] the triplet (full path, + # tool name, value of ENV['PATH']). The last two values are used to + # invalidate the cache when needed + # + # @see tool_in_path + attr_reader :programs_in_path + + # Get a given program, using its name as default value. For + # instance + # tool('automake') + # will return 'automake' unless the autobuild script defined + # another automake program in Autobuild.programs by doing + # Autobuild.programs['automake'] = 'automake1.9' + def tool(name) + programs[name.to_sym] || programs[name.to_s] || name.to_s + end + + # Resolves the absolute path to a given tool + def tool_in_path(name) + path, path_name, path_env = programs_in_path[name] + current = tool(name) + if path_env != ENV['PATH'] || path_name != current + # Delete the current entry given that it is invalid + programs_in_path.delete(name) + if current[0, 1] == "/" + # This is already a full path + path = current + else + path = ENV['PATH'].split(':'). + find { |dir| File.exists?(File.join(dir, current)) } + if path + path = File.join(path, current) + end + end + + if !path + raise ArgumentError, "tool #{name}, set to #{current}, can not be found in PATH=#{path_env}" + end + + # Verify that the new value is a file and is executable + if !File.file?(path) + raise ArgumentError, "tool #{name} is set to #{current}, but this resolves to #{path} which is not a file" + elsif !File.executable?(path) + raise ArgumentError, "tool #{name} is set to #{current}, but this resolves to #{path} which is not executable" + end + programs_in_path[name] = [path, current, ENV['PATH']] + end + + return path + end + end + + @programs = Hash.new + @programs_in_path = Hash.new +end + + module Autoproj class InputError < RuntimeError; end class << self # Programatically overriden autoproj options @@ -2338,10 +2399,11 @@ # First thing we do is install a proper ruby environment. We make sure that we # aren't installing any gems for now (as we need to choose the right gem # binary) by setting Autobuild.programs['gem'] to nil Autobuild.programs['gem'] = nil Autoproj::OSDependencies.autodetect_ruby +Autoproj::OSDependencies.autodetect_ruby_program osdeps_management = if ENV['AUTOPROJ_DEFAULT_OSDEPS'] Autoproj::OSDependencies.load(ENV['AUTOPROJ_DEFAULT_OSDEPS']) else @@ -2374,11 +2436,11 @@ end File.open('env.sh', 'w') do |io| io.write <<-EOSHELL export RUBYOPT=-rubygems -export GEM_PATH=#{needed_gem_home}:$GEM_PATH -export GEM_HOME=#{needed_gem_home} +export GEM_PATH=#{gem_path.join(":")} +export GEM_HOME=#{gem_home} export PATH=$GEM_HOME/bin:$PATH EOSHELL end # If the user specifies "dev" on the command line, install the prerelease