ruby-changes:70127
From: Charles <ko1@a...>
Date: Thu, 9 Dec 2021 19:34:28 +0900 (JST)
Subject: [ruby-changes:70127] eb06b37c46 (master): [ruby/open3] Update to match JRuby 9.4
https://git.ruby-lang.org/ruby.git/commit/?id=eb06b37c46 From eb06b37c460a8237fd0f02a075307e1229b0359b Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter <headius@h...> Date: Thu, 30 Sep 2021 10:38:25 -0500 Subject: [ruby/open3] Update to match JRuby 9.4 This allows the wrapper functions in the main open3 to be defined while using our ProcessBuilder logic for the internal popen implementation. Note this adds logic to reject redirects from a numeric fd to a live IO object (or not a String or to_path object) since we cannot support direct IO redirects with ProcesBuilder. This patch allows tests to complete with the ProcessBuilder impl. Only three tests fail: * test_numeric_file_descriptor2 and test_numeric_file_descriptor2 fail due to redirecting streams to a pipe IO. * test_pid fails expecting a real PID which we cannot provide via ProcessBuilder. https://github.com/ruby/open3/commit/73f986c233 --- lib/open3.rb | 9 ++++----- lib/open3/jruby_windows.rb | 9 +++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/open3.rb b/lib/open3.rb index 2f035e3bcd4..9652b271946 100644 --- a/lib/open3.rb +++ b/lib/open3.rb @@ -31,12 +31,8 @@ https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L31 require 'open3/version' -if RUBY_ENGINE == 'jruby' && JRuby::Util::ON_WINDOWS - require_relative 'open3/jruby_windows' - return -end - module Open3 + # Open stdin, stdout, and stderr streams and start external executable. # In addition, a thread to wait for the started process is created. # The thread has a pid method and a thread variable :pid which is the pid of @@ -763,3 +759,6 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L759 end end + +# JRuby uses different popen logic on Windows, require it here to reuse wrapper methods above. +require 'open3/jruby_windows' if RUBY_ENGINE == 'jruby' && JRuby::Util::ON_WINDOWS diff --git a/lib/open3/jruby_windows.rb b/lib/open3/jruby_windows.rb index 24b9a1ba7ee..064c38b597c 100644 --- a/lib/open3/jruby_windows.rb +++ b/lib/open3/jruby_windows.rb @@ -57,6 +57,15 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3/jruby_windows.rb#L57 module_function :popen2e def processbuilder_run(cmd, opts, build: nil, io:) + opts.each do |k, v| + if Integer === k + if IO == v || !(String === v || v.respond_to?(:to_path)) + # target is an open IO or a non-pathable object, bail out + raise NotImplementedError.new("redirect to an open IO is not implemented on this platform") + end + end + end + if Hash === cmd[0] env = cmd.shift; else -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/