[rubygems/rubygems] Stream output from ext builds when --verbose

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.

https://github.com/rubygems/rubygems/commit/dcdcb5adda
This commit is contained in:
Daisuke Aritomo 2023-12-09 13:13:53 +09:00 коммит произвёл git
Родитель 655aacc43a
Коммит 1ab91b12fa
1 изменённых файлов: 11 добавлений и 4 удалений

Просмотреть файл

@ -88,13 +88,20 @@ class Gem::Ext::Builder
# 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