diff options
author | Hiroshi SHIBATA <[email protected]> | 2019-12-20 11:50:32 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2019-12-20 11:50:32 +0900 |
commit | e672494cd737b8fea3a186aeb5c2c17d1a18cb96 (patch) | |
tree | 7c10a5af0630284fc69342e9598a3c0176e0b27c /lib/rubygems | |
parent | fac60be324260cd834478fedf934e59b97935dbf (diff) |
Merge RubyGems 3.1.2
Diffstat (limited to 'lib/rubygems')
-rw-r--r-- | lib/rubygems/commands/setup_command.rb | 43 | ||||
-rw-r--r-- | lib/rubygems/test_case.rb | 44 |
2 files changed, 73 insertions, 14 deletions
diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index 7844e9d199..579776df7e 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -17,6 +17,7 @@ class Gem::Commands::SetupCommand < Gem::Command super 'setup', 'Install RubyGems', :format_executable => true, :document => %w[ri], + :force => true, :site_or_vendor => 'sitelibdir', :destdir => '', :prefix => '', :previous_version => '', :regenerate_binstubs => true @@ -88,6 +89,11 @@ class Gem::Commands::SetupCommand < Gem::Command options[:regenerate_binstubs] = value end + add_option '-f', '--[no-]force', + 'Forcefully overwrite binstubs' do |value, options| + options[:force] = value + end + add_option('-E', '--[no-]env-shebang', 'Rewrite executables with a shebang', 'of /usr/bin/env') do |value, options| @@ -199,10 +205,10 @@ By default, this RubyGems will install gem as: say say "RubyGems installed the following executables:" - say @bin_file_names.map { |name| "\t#{name}\n" } + say bin_file_names.map { |name| "\t#{name}\n" } say - unless @bin_file_names.grep(/#{File::SEPARATOR}gem$/) + unless bin_file_names.grep(/#{File::SEPARATOR}gem$/) say "If `gem` was installed by a previous RubyGems installation, you may need" say "to remove it by hand." say @@ -235,8 +241,6 @@ By default, this RubyGems will install gem as: end def install_executables(bin_dir) - @bin_file_names = [] - prog_mode = options[:prog_mode] || 0755 executables = { 'gem' => 'bin' } @@ -249,13 +253,7 @@ By default, this RubyGems will install gem as: bin_files -= %w[update_rubygems] bin_files.each do |bin_file| - bin_file_formatted = if options[:format_executable] - Gem.default_exec_format % bin_file - else - bin_file - end - - dest_file = File.join bin_dir, bin_file_formatted + dest_file = target_bin_path(bin_dir, bin_file) bin_tmp_file = File.join Dir.tmpdir, "#{bin_file}.#{$$}" begin @@ -267,7 +265,7 @@ By default, this RubyGems will install gem as: end install bin_tmp_file, dest_file, :mode => prog_mode - @bin_file_names << dest_file + bin_file_names << dest_file ensure rm bin_tmp_file end @@ -429,13 +427,15 @@ By default, this RubyGems will install gem as: Dir.chdir("bundler") do built_gem = Gem::Package.build(bundler_spec) begin - installer = Gem::Installer.at(built_gem, env_shebang: options[:env_shebang], format_executable: options[:format_executable], install_as_default: true, bin_dir: bin_dir, wrappers: true) + installer = 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, wrappers: true) installer.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 @@ -592,7 +592,7 @@ abort "#{deprecation_message}" history_string = "" until versions.length == 0 or - versions.shift < options[:previous_version] do + versions.shift <= options[:previous_version] do history_string += version_lines.shift + text.shift end @@ -626,4 +626,19 @@ abort "#{deprecation_message}" command.invoke(*args) end + private + + def target_bin_path(bin_dir, bin_file) + bin_file_formatted = if options[:format_executable] + Gem.default_exec_format % bin_file + else + bin_file + end + File.join bin_dir, bin_file_formatted + end + + def bin_file_names + @bin_file_names ||= [] + end + end diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index 5ecf2ab1d8..206497c651 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -164,6 +164,50 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni end end + ## + # Sets the bindir entry in RbConfig::CONFIG to +value+ and restores the + # original value when the block ends + # + def bindir(value) + bindir = RbConfig::CONFIG['bindir'] + + if value + RbConfig::CONFIG['bindir'] = value + else + RbConfig::CONFIG.delete 'bindir' + end + + yield + ensure + if bindir + RbConfig::CONFIG['bindir'] = bindir + else + RbConfig::CONFIG.delete 'bindir' + end + end + + ## + # Sets the EXEEXT entry in RbConfig::CONFIG to +value+ and restores the + # original value when the block ends + # + def exeext(value) + exeext = RbConfig::CONFIG['EXEEXT'] + + if value + RbConfig::CONFIG['EXEEXT'] = value + else + RbConfig::CONFIG.delete 'EXEEXT' + end + + yield + ensure + if exeext + RbConfig::CONFIG['EXEEXT'] = exeext + else + RbConfig::CONFIG.delete 'EXEEXT' + end + end + # TODO: move to minitest def refute_path_exists(path, msg = nil) msg = message(msg) { "Expected path '#{path}' to not exist" } |