1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Merge upstream from rubygems/rubygems master branch.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65470 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
hsbt 2018-10-31 03:23:30 +00:00
parent 6f5eb28507
commit 3e047420d6
8 changed files with 92 additions and 42 deletions

View file

@ -1,28 +1,45 @@
# frozen_string_literal: true # frozen_string_literal: true
# `uplevel` keyword argument of Kernel#warn is available since ruby 2.5.
if RUBY_VERSION >= "2.5" if RUBY_VERSION >= "2.5"
module Kernel module Kernel
path = "#{__dir__}/" path = "#{__dir__}/" # Frames to be skipped start with this path.
# Suppress "method redefined" warning
original_warn = instance_method(:warn) original_warn = instance_method(:warn)
Module.new {define_method(:warn, original_warn)} Module.new {define_method(:warn, original_warn)}
original_warn = method(:warn) original_warn = method(:warn)
module_function define_method(:warn) {|*messages, uplevel: nil| module_function define_method(:warn) {|*messages, uplevel: nil|
if uplevel unless uplevel
return original_warn.call(*messages)
end
# Ensure `uplevel` fits a `long`
uplevel, = [uplevel].pack("l!").unpack("l!") uplevel, = [uplevel].pack("l!").unpack("l!")
if uplevel >= 0 if uplevel >= 0
start = 0 start = 0
begin while uplevel >= 0
loc, = caller_locations(start, 1) loc, = caller_locations(start, 1)
break start += uplevel unless loc unless loc
# No more backtrace
start += uplevel
break
end
start += 1 start += 1
end while (loc.path.start_with?(path) or (uplevel -= 1) >= 0)
unless loc.path.start_with?(path)
# Non-rubygems frames
uplevel -= 1
end
end
uplevel = start uplevel = start
end end
original_warn.call(*messages, uplevel: uplevel) original_warn.call(*messages, uplevel: uplevel)
else
original_warn.call(*messages)
end
} }
end end
end end

View file

@ -56,6 +56,7 @@ class Gem::Ext::Builder
end end
def self.redirector def self.redirector
warn "#{caller[0]}: Use IO.popen(..., err: [:child, :out])"
'2>&1' '2>&1'
end end
@ -63,7 +64,6 @@ class Gem::Ext::Builder
verbose = Gem.configuration.really_verbose verbose = Gem.configuration.really_verbose
begin begin
# TODO use Process.spawn when ruby 1.8 support is dropped.
rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], nil rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], nil
if verbose if verbose
puts("current directory: #{Dir.pwd}") puts("current directory: #{Dir.pwd}")
@ -71,9 +71,11 @@ class Gem::Ext::Builder
system(command) system(command)
else else
results << "current directory: #{Dir.pwd}" results << "current directory: #{Dir.pwd}"
results << command results << (command.respond_to?(:shelljoin) ? command.shelljoin : command)
results << `#{command} #{redirector}` results << IO.popen(command, "r", err: [:child, :out], &:read)
end end
rescue => error
raise Gem::InstallError, "#{command_name || class_name} failed#{error.message}"
ensure ensure
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
end end

View file

@ -7,6 +7,7 @@
require 'fileutils' require 'fileutils'
require 'tempfile' require 'tempfile'
require 'shellwords'
class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
FileEntry = FileUtils::Entry_ # :nodoc: FileEntry = FileUtils::Entry_ # :nodoc:
@ -38,7 +39,9 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
destdir = ENV["DESTDIR"] destdir = ENV["DESTDIR"]
begin begin
cmd = [Gem.ruby, "-I", File.expand_path("../../..", __FILE__), "-r", get_relative_path(siteconf.path), File.basename(extension), *args].join ' ' cmd = Gem.ruby.shellsplit << "-I" << File.expand_path("../../..", __FILE__) <<
"-r" << get_relative_path(siteconf.path) << File.basename(extension)
cmd.push(*args)
begin begin
run cmd, results run cmd, results

View file

@ -11,22 +11,23 @@ class Gem::Ext::RakeBuilder < Gem::Ext::Builder
def self.build(extension, dest_path, results, args=[], lib_dir=nil) def self.build(extension, dest_path, results, args=[], lib_dir=nil)
if File.basename(extension) =~ /mkrf_conf/i then if File.basename(extension) =~ /mkrf_conf/i then
cmd = "#{Gem.ruby} #{File.basename extension}".dup run([Gem.ruby, File.basename(extension), *args], results)
cmd << " #{args.join " "}" unless args.empty?
run cmd, results
end end
rake = ENV['rake'] rake = ENV['rake']
rake ||= begin if rake
"#{Gem.ruby} -rrubygems #{Gem.bin_path('rake', 'rake')}" rake = rake.shellsplit
else
begin
rake = [Gem.ruby, "-rrubygems", Gem.bin_path('rake', 'rake')]
rescue Gem::Exception rescue Gem::Exception
rake = [Gem.default_exec_format % 'rake']
end
end end
rake ||= Gem.default_exec_format % 'rake'
rake_args = ["RUBYARCHDIR=#{dest_path}", "RUBYLIBDIR=#{dest_path}", *args] rake_args = ["RUBYARCHDIR=#{dest_path}", "RUBYLIBDIR=#{dest_path}", *args]
run "#{rake} #{rake_args.shelljoin}", results run(rake + rake_args, results)
results results
end end

View file

@ -771,33 +771,38 @@ TEXT
# return the stub script text used to launch the true Ruby script # return the stub script text used to launch the true Ruby script
def windows_stub_script(bindir, bin_file_name) def windows_stub_script(bindir, bin_file_name)
rb_bindir = RbConfig::CONFIG["bindir"] rb_config = RbConfig::CONFIG
# All comparisons should be case insensitive rb_topdir = RbConfig::TOPDIR || File.dirname(rb_config["bindir"])
if bindir.downcase == rb_bindir.downcase
# get ruby executable file name from RbConfig
ruby_exe = "#{rb_config['RUBY_INSTALL_NAME']}#{rb_config['EXEEXT']}"
ruby_exe = "ruby.exe" if ruby_exe.empty?
if File.exist?(File.join bindir, ruby_exe)
# stub & ruby.exe withing same folder. Portable # stub & ruby.exe withing same folder. Portable
<<-TEXT <<-TEXT
@ECHO OFF @ECHO OFF
@"%~dp0ruby.exe" "%~dpn0" %* @"%~dp0ruby.exe" "%~dpn0" %*
TEXT TEXT
elsif bindir.downcase.start_with?((RbConfig::TOPDIR || File.dirname(rb_bindir)).downcase) elsif bindir.downcase.start_with? rb_topdir.downcase
# stub within ruby folder, but not standard bin. Not portable # stub within ruby folder, but not standard bin. Portable
require 'pathname' require 'pathname'
from = Pathname.new bindir from = Pathname.new bindir
to = Pathname.new rb_bindir to = Pathname.new "#{rb_topdir}/bin"
rel = to.relative_path_from from rel = to.relative_path_from from
<<-TEXT <<-TEXT
@ECHO OFF @ECHO OFF
@"%~dp0#{rel}/ruby.exe" "%~dpn0" %* @"%~dp0#{rel}/ruby.exe" "%~dpn0" %*
TEXT TEXT
else else
# outside ruby folder, maybe -user-install or bundler. Portable # outside ruby folder, maybe -user-install or bundler. Portable, but ruby
# is dependent on PATH
<<-TEXT <<-TEXT
@ECHO OFF @ECHO OFF
@ruby.exe "%~dpn0" %* @ruby.exe "%~dpn0" %*
TEXT TEXT
end end
end end
## ##
# Builds extensions. Valid types of extensions are extconf.rb files, # Builds extensions. Valid types of extensions are extconf.rb files,
# configure scripts and rakefiles or mkrf_conf files. # configure scripts and rakefiles or mkrf_conf files.

View file

@ -1319,9 +1319,26 @@ Also, a list:
end end
end end
class << self
# :nodoc:
##
# Return the join path, with escaping backticks, dollars, and
# double-quotes. Unlike `shellescape`, equal-sign is not escaped.
private
def escape_path(*path)
path = File.join(*path)
if %r'\A[-+:/=@,.\w]+\z' =~ path
path
else
"\"#{path.gsub(/[`$"]/, '\\&')}\""
end
end
end
@@ruby = rubybin @@ruby = rubybin
@@good_rake = "#{rubybin} \"#{File.expand_path('../../../test/rubygems/good_rake.rb', __FILE__)}\"" gempath = File.expand_path('../../../test/rubygems', __FILE__)
@@bad_rake = "#{rubybin} \"#{File.expand_path('../../../test/rubygems/bad_rake.rb', __FILE__)}\"" @@good_rake = "#{rubybin} #{escape_path(gempath, 'good_rake.rb')}"
@@bad_rake = "#{rubybin} #{escape_path(gempath, 'bad_rake.rb')}"
## ##
# Construct a new Gem::Dependency. # Construct a new Gem::Dependency.

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'rubygems/test_case' require 'rubygems/test_case'
require 'rubygems' require 'rubygems'
require 'shellwords'
class TestConfig < Gem::TestCase class TestConfig < Gem::TestCase
@ -13,12 +14,16 @@ class TestConfig < Gem::TestCase
def test_good_rake_path_is_escaped def test_good_rake_path_is_escaped
path = Gem::TestCase.class_eval('@@good_rake') path = Gem::TestCase.class_eval('@@good_rake')
assert_match(/#{Gem.ruby} "[^"]*good_rake.rb"/, path) ruby, rake = path.shellsplit
assert_equal(Gem.ruby, ruby)
assert_match(/\/good_rake.rb\z/, rake)
end end
def test_bad_rake_path_is_escaped def test_bad_rake_path_is_escaped
path = Gem::TestCase.class_eval('@@bad_rake') path = Gem::TestCase.class_eval('@@bad_rake')
assert_match(/#{Gem.ruby} "[^"]*bad_rake.rb"/, path) ruby, rake = path.shellsplit
assert_equal(Gem.ruby, ruby)
assert_match(/\/bad_rake.rb\z/, rake)
end end
end end

View file

@ -10,7 +10,7 @@ class TestGemExtCmakeBuilder < Gem::TestCase
# Details: https://github.com/rubygems/rubygems/issues/1270#issuecomment-177368340 # Details: https://github.com/rubygems/rubygems/issues/1270#issuecomment-177368340
skip "CmakeBuilder doesn't work on Windows." if Gem.win_platform? skip "CmakeBuilder doesn't work on Windows." if Gem.win_platform?
`cmake #{Gem::Ext::Builder.redirector}` system('cmake', out: IO::NULL, err: [:child, :out])
skip 'cmake not present' unless $?.success? skip 'cmake not present' unless $?.success?