Skip to content

Commit

Permalink
[rubygems/rubygems] Stream output from ext builds when --verbose
Browse files Browse the repository at this point in the history
Uses Open3.popen2e in place of Open3.capture2e in Gem::Ext::Builder.
This change aims to stream stdout/stderr of ext builds when in verbose
mode, instead of printing everything at once when the build completes.

Nice for debugging gem builds that consumes longer times.

rubygems/rubygems@dcdcb5adda
  • Loading branch information
osyoyu authored and matzbot committed Dec 11, 2023
1 parent 655aacc commit 1ab91b1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/rubygems/ext/builder.rb
Expand Up @@ -88,13 +88,20 @@ def self.run(command, results, command_name = nil, dir = Dir.pwd, env = {})
# Set $SOURCE_DATE_EPOCH for the subprocess.
build_env = { "SOURCE_DATE_EPOCH" => Gem.source_date_epoch_string }.merge(env)
output, status = begin
Open3.capture2e(build_env, *command, chdir: dir)
Open3.popen2e(build_env, *command, chdir: dir) do |_stdin, stdouterr, wait_thread|
output = String.new
while line = stdouterr.gets
output << line
if verbose
print line
end
end
[output, wait_thread.value]
end
rescue StandardError => error
raise Gem::InstallError, "#{command_name || class_name} failed#{error.message}"
end
if verbose
puts output
else
unless verbose
results << output
end
ensure
Expand Down

0 comments on commit 1ab91b1

Please sign in to comment.