Skip to content

Commit

Permalink
Merge RubyGems 3.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Dec 20, 2019
1 parent fac60be commit e672494
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 58 deletions.
2 changes: 1 addition & 1 deletion lib/rubygems.rb
Expand Up @@ -9,7 +9,7 @@
require 'rbconfig'

module Gem
VERSION = "3.1.1".freeze
VERSION = "3.1.2".freeze
end

# Must be first since it unloads the prelude from 1.9.2
Expand Down
43 changes: 29 additions & 14 deletions lib/rubygems/commands/setup_command.rb
Expand Up @@ -17,6 +17,7 @@ def initialize

super 'setup', 'Install RubyGems',
:format_executable => true, :document => %w[ri],
:force => true,
:site_or_vendor => 'sitelibdir',
:destdir => '', :prefix => '', :previous_version => '',
:regenerate_binstubs => true
Expand Down Expand Up @@ -88,6 +89,11 @@ def initialize
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|
Expand Down Expand Up @@ -199,10 +205,10 @@ def execute
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
Expand Down Expand Up @@ -235,8 +241,6 @@ def execute
end

def install_executables(bin_dir)
@bin_file_names = []

prog_mode = options[:prog_mode] || 0755

executables = { 'gem' => 'bin' }
Expand All @@ -249,13 +253,7 @@ def install_executables(bin_dir)
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
Expand All @@ -267,7 +265,7 @@ def install_executables(bin_dir)
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
Expand Down Expand Up @@ -429,13 +427,15 @@ def install_default_bundler_gem(bin_dir)
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

Expand Down Expand Up @@ -592,7 +592,7 @@ def show_release_notes
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

Expand Down Expand Up @@ -626,4 +626,19 @@ def regenerate_binstubs
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
44 changes: 44 additions & 0 deletions lib/rubygems/test_case.rb
Expand Up @@ -164,6 +164,50 @@ def vendordir(value)
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" }
Expand Down
15 changes: 5 additions & 10 deletions test/rubygems/test_gem.rb
Expand Up @@ -1917,16 +1917,11 @@ def ruby_install_name(name)
end

def with_bindir_and_exeext(bindir, exeext)
orig_bindir = RbConfig::CONFIG['bindir']
orig_exe_ext = RbConfig::CONFIG['EXEEXT']

RbConfig::CONFIG['bindir'] = bindir
RbConfig::CONFIG['EXEEXT'] = exeext

yield
ensure
RbConfig::CONFIG['bindir'] = orig_bindir
RbConfig::CONFIG['EXEEXT'] = orig_exe_ext
bindir(bindir) do
exeext(exeext) do
yield
end
end
end

def with_clean_path_to_ruby
Expand Down
66 changes: 56 additions & 10 deletions test/rubygems/test_gem_commands_setup_command.rb
Expand Up @@ -123,6 +123,18 @@ def test_execute_no_regenerate_binstubs
assert_equal "I changed it!\n", File.read(gem_bin_path)
end

def test_execute_informs_about_installed_executables
use_ui @ui do
@cmd.execute
end

out = @ui.output.split "\n"

exec_line = out.shift until exec_line == "RubyGems installed the following executables:"
assert_equal "\t#{default_gem_bin_path}", out.shift
assert_equal "\t#{default_bundle_bin_path}", out.shift
end

def test_env_shebang_flag
gem_bin_path = gem_install 'a'
write_file gem_bin_path do |io|
Expand All @@ -133,10 +145,6 @@ def test_env_shebang_flag
@cmd.options[:env_shebang] = true
@cmd.execute

gem_exec = sprintf Gem.default_exec_format, 'gem'
default_gem_bin_path = File.join @install_dir, 'bin', gem_exec
bundle_exec = sprintf Gem.default_exec_format, 'bundle'
default_bundle_bin_path = File.join @install_dir, 'bin', bundle_exec
ruby_exec = sprintf Gem.default_exec_format, 'ruby'

if Gem.win_platform?
Expand Down Expand Up @@ -212,10 +220,41 @@ def test_install_default_bundler_gem

# TODO: We need to assert to remove same version of bundler on gem_dir directory(It's not site_ruby dir)

# expect to not remove bundler-* direcotyr.
# expect to not remove bundler-* directory.
assert_path_exists 'default/gems/bundler-audit-1.0.0'
end

def test_install_default_bundler_gem_with_force_flag
@cmd.extend FileUtils

bin_dir = File.join(@gemhome, 'bin')
bundle_bin = File.join(bin_dir, 'bundle')

write_file bundle_bin do |f|
f.puts '#!/usr/bin/ruby'
f.puts ''
f.puts 'echo "hello"'
end

bindir(bin_dir) do
@cmd.options[:force] = true

@cmd.install_default_bundler_gem bin_dir

bundler_spec = Gem::Specification.load("bundler/bundler.gemspec")
default_spec_path = File.join(Gem.default_specifications_dir, "#{bundler_spec.full_name}.gemspec")
spec = Gem::Specification.load(default_spec_path)

spec.executables.each do |e|
if Gem.win_platform?
assert_path_exists File.join(bin_dir, "#{e}.bat")
end

assert_path_exists File.join bin_dir, Gem.default_exec_format % e
end
end
end

def test_remove_old_lib_files
lib = File.join @install_dir, 'lib'
lib_rubygems = File.join lib, 'rubygems'
Expand Down Expand Up @@ -308,11 +347,6 @@ def test_show_release_notes
* Fixed release note display for LANG=C when installing rubygems
* π is tasty
=== 2.0.2 / 2013-03-06
* Bug fixes:
* Other bugs fixed
EXPECTED

output = @ui.output
Expand All @@ -323,4 +357,16 @@ def test_show_release_notes
@ui.outs.set_encoding @default_external if @default_external
end

private

def default_gem_bin_path
gem_exec = sprintf Gem.default_exec_format, 'gem'
File.join @install_dir, 'bin', gem_exec
end

def default_bundle_bin_path
bundle_exec = sprintf Gem.default_exec_format, 'bundle'
File.join @install_dir, 'bin', bundle_exec
end

end unless Gem.java_platform?
33 changes: 10 additions & 23 deletions test/rubygems/test_gem_installer.rb
Expand Up @@ -104,32 +104,19 @@ def test_check_executable_overwrite
def test_check_executable_overwrite_default_bin_dir
installer = setup_base_installer

if defined?(RUBY_FRAMEWORK_VERSION)
orig_RUBY_FRAMEWORK_VERSION = RUBY_FRAMEWORK_VERSION
Object.send :remove_const, :RUBY_FRAMEWORK_VERSION
end
orig_bindir = RbConfig::CONFIG['bindir']
RbConfig::CONFIG['bindir'] = Gem.bindir
bindir(Gem.bindir) do
util_conflict_executable false

util_conflict_executable false
ui = Gem::MockGemUi.new "n\n"
use_ui ui do
e = assert_raises Gem::InstallError do
installer.generate_bin
end

ui = Gem::MockGemUi.new "n\n"
use_ui ui do
e = assert_raises Gem::InstallError do
installer.generate_bin
conflicted = File.join @gemhome, 'bin', 'executable'
assert_match %r%\A"executable" from a conflicts with (?:#{Regexp.quote(conflicted)}|installed executable from conflict)\z%,
e.message
end

conflicted = File.join @gemhome, 'bin', 'executable'
assert_match %r%\A"executable" from a conflicts with (?:#{Regexp.quote(conflicted)}|installed executable from conflict)\z%,
e.message
end
ensure
Object.const_set :RUBY_FRAMEWORK_VERSION, orig_RUBY_FRAMEWORK_VERSION if
orig_RUBY_FRAMEWORK_VERSION
if orig_bindir
RbConfig::CONFIG['bindir'] = orig_bindir
else
RbConfig::CONFIG.delete 'bindir'
end
end

Expand Down

0 comments on commit e672494

Please sign in to comment.