ruby-changes:72582
From: Yuta <ko1@a...>
Date: Sun, 17 Jul 2022 19:45:03 +0900 (JST)
Subject: [ruby-changes:72582] fab8f3bde6 (master): [rubygems/rubygems] Stop using `/dev/null` for silent ui for WASI platform
https://git.ruby-lang.org/ruby.git/commit/?id=fab8f3bde6 From fab8f3bde6e4d1ac78aa63e4768452b3da0f955e Mon Sep 17 00:00:00 2001 From: Yuta Saito <kateinoigakukun@g...> Date: Sat, 16 Jul 2022 18:21:15 +0000 Subject: [rubygems/rubygems] Stop using `/dev/null` for silent ui for WASI platform WASI doesn't guarantee that `/dev/null` is present. So without this patch, we needed to mount host's `/dev` directory to WASI guest process to avoid `ENOTCAPABLE` error while `require "bundler/setup"` https://github.com/rubygems/rubygems/commit/e9187ab61f --- lib/rubygems/user_interaction.rb | 32 +++++++++++++++++++++++--------- test/rubygems/test_gem_silent_ui.rb | 6 ++++++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb index e632f418a9..c726fd21c1 100644 --- a/lib/rubygems/user_interaction.rb +++ b/lib/rubygems/user_interaction.rb @@ -616,18 +616,11 @@ class Gem::SilentUI < Gem::StreamUI https://github.com/ruby/ruby/blob/trunk/lib/rubygems/user_interaction.rb#L616 # The SilentUI has no arguments as it does not use any stream. def initialize - reader, writer = nil, nil - - reader = File.open(IO::NULL, 'r') - writer = File.open(IO::NULL, 'w') - - super reader, writer, writer, false + io = NullIO.new + super io, io, io, false end def close - super - @ins.close - @outs.close end def download_reporter(*args) # :nodoc: @@ -637,4 +630,25 @@ class Gem::SilentUI < Gem::StreamUI https://github.com/ruby/ruby/blob/trunk/lib/rubygems/user_interaction.rb#L630 def progress_reporter(*args) # :nodoc: SilentProgressReporter.new(@outs, *args) end + + ## + # An absolutely silent IO. + + class NullIO + def puts(*args) + end + + def print(*args) + end + + def flush + end + + def gets(*args) + end + + def tty? + false + end + end end diff --git a/test/rubygems/test_gem_silent_ui.rb b/test/rubygems/test_gem_silent_ui.rb index 355255fb48..d23d6f4cba 100644 --- a/test/rubygems/test_gem_silent_ui.rb +++ b/test/rubygems/test_gem_silent_ui.rb @@ -113,4 +113,10 @@ class TestGemSilentUI < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_silent_ui.rb#L113 assert_empty out, 'No output' assert_empty err, 'No output' end + + def test_new_without_dev_null + File.stub(:open, ->(path, mode) { raise Errno::ENOTCAPABLE if path == IO::NULL }) do + Gem::SilentUI.new + end + end end -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/