End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Gem::Commands::SetupCommand#install_default_bundler_gem
install_default_bundler_gem(bin_dir)
lib/rubygems/commands/setup_command.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/lib/rubygems/commands/setup_command.rb, line 362
def install_default_bundler_gem(bin_dir)
specs_dir = File.join(default_dir, "specifications", "default")
mkdir_p specs_dir, :mode => 0755
bundler_spec = Dir.chdir("bundler") { Gem::Specification.load("bundler.gemspec") }
# Remove bundler-*.gemspec in default specification directory.
Dir.entries(specs_dir).
select {|gs| gs.start_with?("bundler-") }.
each {|gs| File.delete(File.join(specs_dir, gs)) }
default_spec_path = File.join(specs_dir, "#{bundler_spec.full_name}.gemspec")
Gem.write_binary(default_spec_path, bundler_spec.to_ruby)
bundler_spec = Gem::Specification.load(default_spec_path)
# The base_dir value for a specification is inferred by walking up from the
# folder where the spec was `loaded_from`. In the case of default gems, we
# walk up two levels, because they live at `specifications/default/`, whereas
# in the case of regular gems we walk up just one level because they live at
# `specifications/`. However, in this case, the gem we are installing is
# misdetected as a regular gem, when it's a default gem in reality. This is
# because when there's a `:destdir`, the `loaded_from` path has changed and
# doesn't match `Gem.default_specifications_dir` which is the criteria to
# tag a gem as a default gem. So, in that case, write the correct
# `@base_dir` directly.
bundler_spec.instance_variable_set(:@base_dir, File.dirname(File.dirname(specs_dir)))
# Remove gemspec that was same version of vendored bundler.
normal_gemspec = File.join(default_dir, "specifications", "bundler-#{bundler_spec.version}.gemspec")
if File.file? normal_gemspec
File.delete normal_gemspec
end
# Remove gem files that were same version of vendored bundler.
if File.directory? bundler_spec.gems_dir
Dir.entries(bundler_spec.gems_dir).
select {|default_gem| File.basename(default_gem) == "bundler-#{bundler_spec.version}" }.
each {|default_gem| rm_r File.join(bundler_spec.gems_dir, default_gem) }
end
bundler_bin_dir = bundler_spec.bin_dir
mkdir_p bundler_bin_dir, :mode => 0755
bundler_spec.executables.each do |e|
cp File.join("bundler", bundler_spec.bindir, e), File.join(bundler_bin_dir, e)
end
require_relative '../installer'
Dir.chdir("bundler") do
built_gem = Gem::Package.build(bundler_spec)
begin
Gem::Installer.at(
built_gem,
env_shebang: options[:env_shebang],
format_executable: options[:format_executable],
force: options[:force],
install_as_default: true,
bin_dir: bin_dir,
install_dir: default_dir,
wrappers: true
).install
ensure
FileUtils.rm_f built_gem
end
end
bundler_spec.executables.each {|executable| bin_file_names << target_bin_path(bin_dir, executable) }
say "Bundler #{bundler_spec.version} installed"
end
No documentation available
See also
#generate_default_man_dir
#install_executables
#generate_default_dirs
#install_file
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1