1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[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
This commit is contained in:
Yuta Saito 2022-07-16 18:21:15 +00:00 committed by git
parent 5081d0dd5c
commit fab8f3bde6
2 changed files with 29 additions and 9 deletions

View file

@ -616,18 +616,11 @@ class Gem::SilentUI < Gem::StreamUI
# 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
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

View file

@ -113,4 +113,10 @@ class TestGemSilentUI < Gem::TestCase
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