#! /usr/bin/ruby if RUBY_VERSION < "1.8.7" STDERR.puts "autoproj requires Ruby >= 1.8.7" 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 end @macos = RbConfig::CONFIG["host_os"] =~ %r!([Dd]arwin)! 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 class << self attr_reader :verbose end def self.color(string, *args) string end def self.warn(str, *args) STDERR.puts "WARN #{str}" end def self.message(str) STDERR.puts " #{str}" end end module Autobuild def self.do_update true end def self.message(str) STDERR.puts " #{str}" end def self.progress(key, str) STDERR.puts " #{str}" end def self.progress_done(key) end def self.message(str) STDERR.puts " #{str}" end class << self attr_reader :programs end @programs = Hash.new def self.tool(name) # Let the ability to set programs[name] to nil to make sure we don't use # that program. This is used later on in this file to make sure we # aren't using the wrong rubygems binary if programs.has_key?(name) programs[name] else name end end module Subprocess def self.run(name, phase, *cmd) output = `#{cmd.join(" ")}` if $?.exitstatus != 0 STDERR.puts "ERROR: failed to run #{cmd.join(" ")}" STDERR.puts "ERROR: command output is: #{output}" exit 1 end end end end OSDEPS_CODE TOOLS_CODE OPTIONS_CODE SYSTEM_CODE # Override Autoproj.root_dir module Autoproj def self.root_dir @root_dir end @root_dir = Dir.pwd end DEFS = < e STDERR.puts "failed: #{e.message}" exit(1) end # Now try to find out the name of the gem binary PACKAGES = [] STDERR.puts "autoproj: installing autoproj and its dependencies (this can take a long time)" # First install the dependencies of autoproj, as we don't want them to be # affected by the prerelease flag begin if !PACKAGES.empty? osdeps_management.install(PACKAGES) end rescue Autoproj::ConfigError => e STDERR.puts "failed: #{e.message}" exit(1) end File.open('env.sh', 'w') do |io| io.write <<-EOSHELL export RUBYOPT=-rubygems export GEM_PATH=#{gem_path} 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 # version of autoproj. If it is "localdev", expect him to install autoproj and # run autoproj bootstrap manually. if ARGV.first != "localdev" if ARGV.first == "dev" Autoproj::PackageManagers::GemManager.with_prerelease = true ARGV.shift end begin osdeps_management.install(['build-essential']) osdeps_management.install(['autobuild']) osdeps_management.install(['autoproj']) rescue Autoproj::ConfigError => e STDERR.puts "failed: #{e.message}" exit(1) end Autoproj::PackageManagers::GemManager.with_prerelease = false if !system('autoproj', 'bootstrap', *ARGV) STDERR.puts "ERROR: failed to run autoproj bootstrap #{ARGV.join(", ")}" exit 1 end end