bin/autoproj_install in autoproj-2.15.0 vs bin/autoproj_install in autoproj-2.15.1
- old
+ new
@@ -170,20 +170,27 @@
end
# (see #local?)
attr_writer :local
# The user-wide place where RubyGems installs gems
- def dot_gem_dir
- File.join(Gem.user_home, ".gem")
+ def self.dot_gem_dir
+ if Gem.respond_to?(:data_home) # Debian 11+
+ File.join(Gem.data_home, "gem")
+ else
+ File.join(Gem.user_home, ".gem")
+ end
end
# The version and platform-specific suffix under {#dot_gem_dir}
#
# This is also the suffix used by bundler to install gems
- def gem_path_suffix
- @gem_path_suffix ||= Pathname.new(Gem.user_dir)
- .relative_path_from(Pathname.new(dot_gem_dir)).to_s
+ def self.gems_path_suffix
+ @gems_path_suffix ||=
+ Pathname
+ .new(Gem.user_dir)
+ .relative_path_from(Pathname.new(dot_gem_dir))
+ .to_s
end
# The path into which the workspace's gems should be installed
#
# They are installed in a versioned subdirectory of this path, e.g.
@@ -194,17 +201,17 @@
# The GEM_HOME under which the workspace's gems should be installed
#
# @return [String]
def gems_gem_home
- File.join(gems_install_path, gem_path_suffix)
+ File.join(gems_install_path, self.class.gems_path_suffix)
end
# Sets where the workspace's gems should be installed
#
# @param [String] path the absolute path that should be given to
# bundler. The gems themselves will be installed in the
- # {#gem_path_suffix} subdirectory under this
+ # {.gems_path_suffix} subdirectory under this
private def xdg_var(varname, default)
if (env = ENV[varname]) && !env.empty?
env
else
@@ -437,36 +444,46 @@
# Force bundler to update. If the user does not want this, let
# him specify a Gemfile with tighter version constraints
lockfile = File.join(dot_autoproj, "Gemfile.lock")
FileUtils.rm lockfile if File.exist?(lockfile)
- clean_env = env_for_child.dup
+ run_bundler(bundler, "config", "set", "--local", "path", gems_install_path,
+ bundler_version: bundler_version)
+ run_bundler(bundler, "config", "set", "--local", "shebang", Gem.ruby,
+ bundler_version: bundler_version)
- opts = Array.new
- opts << "--local" if local?
- opts << "--path=#{gems_install_path}"
+ install_args = ["--gemfile=#{autoproj_gemfile_path}"]
+ install_args << "--local" if local?
+ run_bundler(bundler, "install", *install_args,
+ bundler_version: bundler_version)
+
shims_path = File.join(dot_autoproj, "bin")
+ run_bundler(bundler, "binstubs", "--all", "--force", "--path", shims_path,
+ bundler_version: bundler_version)
+ self.class.rewrite_shims(
+ shims_path, ruby_executable, root_dir,
+ autoproj_gemfile_path, gems_gem_home
+ )
+ end
+ class BundlerFailed < RuntimeError; end
+
+ def run_bundler(bundler, *args, bundler_version: self.bundler_version)
+ clean_env = env_for_child.dup
+
version_arg = []
version_arg << "_#{bundler_version}_" if bundler_version
result = system(
- clean_env,
- Gem.ruby, bundler, *version_arg, "install",
- "--gemfile=#{autoproj_gemfile_path}",
- "--shebang=#{Gem.ruby}",
- "--binstubs=#{shims_path}",
- *opts, chdir: dot_autoproj
+ clean_env, Gem.ruby, bundler, *version_arg,
+ *args, chdir: dot_autoproj
)
unless result
- STDERR.puts "FATAL: failed to install autoproj in #{dot_autoproj}"
- exit 1
+ raise BundlerFailed,
+ "FAILED: bundler #{args.join(', ')} in #{dot_autoproj}"
end
- ensure
- self.class.rewrite_shims(shims_path, ruby_executable,
- root_dir, autoproj_gemfile_path, gems_gem_home)
end
EXCLUDED_FROM_SHIMS = %w[rake thor].freeze
def self.rewrite_shims(shim_path, ruby_executable,
@@ -489,10 +506,11 @@
next if bin_name == "ruby"
bin_shim = File.join(shim_path, bin_name)
bin_script_lines = File.readlines(bin_script)
next if has_autoproj_preamble?(bin_script_lines)
+ next unless ruby_script?(bin_script_lines)
File.open(bin_shim, "w") do |io|
if bin_name == "bundler" || bin_name == "bundle"
io.puts shim_bundler(bin_script_lines, ruby_executable,
autoproj_gemfile_path, gems_gem_home)
@@ -501,9 +519,13 @@
autoproj_gemfile_path, gems_gem_home)
end
end
FileUtils.chmod 0755, bin_shim
end
+ end
+
+ def self.ruby_script?(script_lines)
+ script_lines.first =~ /\#\s*!(.*ruby.*)/
end
def self.new_style_bundler_binstub?(script_lines)
script_lines.any? { |l| l =~ /This file was generated by Bundler/ }
end