bin/autoproj_bootstrap in autoproj-1.13.0.b2 vs bin/autoproj_bootstrap in autoproj-1.13.0.b3

- old
+ new

@@ -3,21 +3,10 @@ if RUBY_VERSION < "1.9.2" STDERR.puts "autoproj requires Ruby >= 1.9.2" exit 1 end -if defined? Encoding # This is a 1.9-only thing - Encoding.default_internal = Encoding::UTF_8 - Encoding.default_external = Encoding::UTF_8 -end - -if ENV['AUTOPROJ_CURRENT_ROOT'] && ENV['AUTOPROJ_CURRENT_ROOT'] != Dir.pwd - STDERR.puts "the env.sh from #{ENV['AUTOPROJ_CURRENT_ROOT']} seem to already be sourced" - STDERR.puts "start a new shell and try to bootstrap again" - exit 1 -end - require 'rbconfig' module Autobuild @windows = RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw|[Ww]indows)! def self.windows? @windows @@ -27,42 +16,10 @@ def self.macos? @macos end end -require 'set' -curdir_entries = Dir.entries('.').to_set - [".", "..", "autoproj_bootstrap", ".gems", 'env.sh'].to_set -if !curdir_entries.empty? && ENV['AUTOPROJ_BOOTSTRAP_IGNORE_NONEMPTY_DIR'] != '1' - while true - print "The current directory is not empty, continue bootstrapping anyway ? [yes] " - STDOUT.flush - answer = STDIN.readline.chomp - if answer == "no" - exit - elsif answer == "" || answer == "yes" - # Set the environment variable since we might restart the - # autoproj_bootstrap script and -- anyway -- will run "autoproj - # bootstrap" later on - break - else - STDOUT.puts "invalid answer. Please answer 'yes' or 'no'" - STDOUT.flush - end - end -end - -# Environment is clean, so just mark it as so unconditionally -ENV['AUTOPROJ_BOOTSTRAP_IGNORE_NONEMPTY_DIR'] = '1' - -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'] = gem_home -ENV['GEM_PATH'] = gem_path -ENV['PATH'] = "#{ENV['GEM_HOME']}/bin:#{ENV['PATH']}" - require 'yaml' require 'set' module Autoproj class ConfigError < RuntimeError; end @@ -1111,20 +1068,11 @@ Autobuild.env_push_path 'PATH', "#{gem_home}/bin" # Now, reset the directories in our own RubyGems instance Gem.paths = ENV - # If there is a cache directory, make sure .gems/cache points to - # it (there are no programmatic ways to override this) - if cache = cache_dir - gem_cache_dir = File.join(gem_home, 'cache') - if !File.symlink?(gem_cache_dir) || File.readlink(gem_cache_dir) != cache - FileUtils.mkdir_p gem_home - FileUtils.rm_rf gem_cache_dir - Autoproj.create_symlink(cache, gem_cache_dir) - end - end + use_cache_dir end # A global cache directory that should be used to avoid # re-downloading gems def self.cache_dir @@ -1133,10 +1081,23 @@ FileUtils.mkdir_p dir dir end end + def self.use_cache_dir + # If there is a cache directory, make sure .gems/cache points to + # it (there are no programmatic ways to override this) + if cache = cache_dir + gem_cache_dir = File.join(gem_home, 'cache') + if !File.symlink?(gem_cache_dir) || File.readlink(gem_cache_dir) != cache + FileUtils.mkdir_p gem_home + FileUtils.rm_rf gem_cache_dir + Autoproj.create_symlink(cache, gem_cache_dir) + end + end + 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") end @@ -2869,18 +2830,10 @@ end end -# Override Autoproj.root_dir -module Autoproj - def self.root_dir - @root_dir - end - @root_dir = Dir.pwd -end - DEFS = <<EODEFS --- none: ignore ruby19: debian: @@ -3068,10 +3021,69 @@ sudo: default: sudo EODEFS +# Override Autoproj.root_dir +module Autoproj + def self.root_dir + @root_dir + end + @root_dir = Dir.pwd +end + +if File.directory?(File.join(Autoproj.root_dir, 'autoproj')) + STDERR.puts "there is already an autoproj/ directory here, cannot bootstrap" + STDERR.puts "Either delete it and attempt bootstrapping again, or source env.sh" + STDERR.puts "and use the usual autoproj workflow" + exit 1 +end + +if defined? Encoding # This is a 1.9-only thing + Encoding.default_internal = Encoding::UTF_8 + Encoding.default_external = Encoding::UTF_8 +end + +if ENV['AUTOPROJ_CURRENT_ROOT'] && ENV['AUTOPROJ_CURRENT_ROOT'] != Dir.pwd + STDERR.puts "the env.sh from #{ENV['AUTOPROJ_CURRENT_ROOT']} seem to already be sourced" + STDERR.puts "start a new shell and try to bootstrap again" + exit 1 +end + +require 'set' +curdir_entries = Dir.entries('.').to_set - [".", "..", "autoproj_bootstrap", ".gems", 'env.sh'].to_set +if !curdir_entries.empty? && ENV['AUTOPROJ_BOOTSTRAP_IGNORE_NONEMPTY_DIR'] != '1' + while true + print "The current directory is not empty, continue bootstrapping anyway ? [yes] " + STDOUT.flush + answer = STDIN.readline.chomp + if answer == "no" + exit + elsif answer == "" || answer == "yes" + # Set the environment variable since we might restart the + # autoproj_bootstrap script and -- anyway -- will run "autoproj + # bootstrap" later on + break + else + STDOUT.puts "invalid answer. Please answer 'yes' or 'no'" + STDOUT.flush + end + end +end + +# Environment is clean, so just mark it as so unconditionally +ENV['AUTOPROJ_BOOTSTRAP_IGNORE_NONEMPTY_DIR'] = '1' + +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'] = gem_home +ENV['GEM_PATH'] = gem_path +ENV['PATH'] = "#{ENV['GEM_HOME']}/bin:#{ENV['PATH']}" + + Autoproj::OSDependencies.define_osdeps_mode_option osdeps_mode = Autoproj::OSDependencies.osdeps_mode.join(",") ENV['AUTOPROJ_OSDEPS_MODE'] = osdeps_mode # First thing we do is install a proper ruby environment. We make sure that we @@ -3086,9 +3098,10 @@ Autoproj::OSDependencies.load(ENV['AUTOPROJ_DEFAULT_OSDEPS']) else Autoproj::OSDependencies.new(YAML.load(DEFS)) end osdeps_management.silent = false +Autoproj::PackageManagers::GemManager.use_cache_dir begin STDERR.puts "autoproj: installing a proper Ruby environment (this can take a long time)" osdeps_management.install(['ruby']) rescue Autoproj::ConfigError => e