aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2019-04-29 09:07:16 +0200
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2019-07-31 07:47:00 +0800
commitd64cc80b660c30577945f3cac452ca16db44ce9f (patch)
treeef0775362501e852e0c651b5a8471a15fc6d0206 /lib/rubygems
parent4e27319c2c0a58ed5ee7276f5f69946161fb6367 (diff)
downloadruby-d64cc80b660c30577945f3cac452ca16db44ce9f.tar.gz
[rubygems/rubygems] Migrate extension builder to use Open3
Since it works on jruby. https://github.com/rubygems/rubygems/commit/5229e00df4
Diffstat (limited to 'lib/rubygems')
-rw-r--r--lib/rubygems/ext/builder.rb27
-rw-r--r--lib/rubygems/ext/ext_conf_builder.rb16
2 files changed, 23 insertions, 20 deletions
diff --git a/lib/rubygems/ext/builder.rb b/lib/rubygems/ext/builder.rb
index 581d420bc4..974e1799a1 100644
--- a/lib/rubygems/ext/builder.rb
+++ b/lib/rubygems/ext/builder.rb
@@ -6,6 +6,7 @@
#++
require 'rubygems/user_interaction'
+require "open3"
class Gem::Ext::Builder
@@ -67,13 +68,11 @@ class Gem::Ext::Builder
results << "current directory: #{Dir.pwd}"
results << (command.respond_to?(:shelljoin) ? command.shelljoin : command)
- redirections = verbose ? {} : {err: [:child, :out]}
- IO.popen(command, "r", redirections) do |io|
- if verbose
- IO.copy_stream(io, $stdout)
- else
- results << io.read
- end
+ output, status = Open3.capture2e(*command)
+ if verbose
+ puts output
+ else
+ results << output
end
rescue => error
raise Gem::InstallError, "#{command_name || class_name} failed#{error.message}"
@@ -81,14 +80,18 @@ class Gem::Ext::Builder
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
end
- unless $?.success?
+ unless status.success?
results << "Building has failed. See above output for more information on the failure." if verbose
+ end
+
+ yield(status, results) if block_given?
+ unless status.success?
exit_reason =
- if $?.exited?
- ", exit code #{$?.exitstatus}"
- elsif $?.signaled?
- ", uncaught signal #{$?.termsig}"
+ if status.exited?
+ ", exit code #{status.exitstatus}"
+ elsif status.signaled?
+ ", uncaught signal #{status.termsig}"
end
raise Gem::InstallError, "#{command_name || class_name} failed#{exit_reason}"
diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb
index 169da438ba..9068f9a5df 100644
--- a/lib/rubygems/ext/ext_conf_builder.rb
+++ b/lib/rubygems/ext/ext_conf_builder.rb
@@ -45,15 +45,15 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
cmd.push(*args)
begin
- run cmd, results
- ensure
- if File.exist? 'mkmf.log'
- unless $?.success?
- results << "To see why this extension failed to compile, please check" \
- " the mkmf.log which can be found here:\n"
- results << " " + File.join(dest_path, 'mkmf.log') + "\n"
+ run(cmd, results) do |status, results|
+ if File.exist? 'mkmf.log'
+ unless status.success?
+ results << "To see why this extension failed to compile, please check" \
+ " the mkmf.log which can be found here:\n"
+ results << " " + File.join(dest_path, 'mkmf.log') + "\n"
+ end
+ FileUtils.mv 'mkmf.log', dest_path
end
- FileUtils.mv 'mkmf.log', dest_path
end
siteconf.unlink
end