Skip to content

Commit

Permalink
[rubygems/rubygems] Migrate extension builder to use Open3
Browse files Browse the repository at this point in the history
Since it works on jruby.

rubygems/rubygems@5229e00df4
  • Loading branch information
deivid-rodriguez authored and hsbt committed Jul 30, 2019
1 parent 4e27319 commit d64cc80
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
27 changes: 15 additions & 12 deletions lib/rubygems/ext/builder.rb
Expand Up @@ -6,6 +6,7 @@
#++

require 'rubygems/user_interaction'
require "open3"

class Gem::Ext::Builder

Expand Down Expand Up @@ -67,28 +68,30 @@ def self.run(command, results, command_name = nil)
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}"
ensure
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}"
Expand Down
16 changes: 8 additions & 8 deletions lib/rubygems/ext/ext_conf_builder.rb
Expand Up @@ -45,15 +45,15 @@ def self.build(extension, dest_path, results, args=[], lib_dir=nil)
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
Expand Down

0 comments on commit d64cc80

Please sign in to comment.