Fixes for Windows native exec#6746
Merged
headius merged 6 commits intojruby:jruby-9.2from Jul 7, 2021
Merged
Conversation
The exec logic calls through these methods to build a command line that runs the windows cmd.exe to launch the desired executable. Unfortunately this logic has two problems: * The eventual jnr-posix `exec` implementation uses CreateProcess, which requires a full path to cmd.exe. Because all other paths use the JDK ProcessBuilder, we did not perform a search for this executable and the CreateProcess fails. * The desired executable does run through the path and extension search logic, but the resulting discovered executable (such as .cmd or .bat) is not used in the cmd.exe command line. This patch makes the following changes: * Perform the executable search for cmd.exe, so we can provide a full path to CreateProcess * Use the result of the executable search in place of the original desired executable name, so it will pick up non-exe files like .bat and .cmd. See jruby#6745
On Windows, the default logic (from rubygems/defaults/jruby) will see that we are running the build from within the 9.1.17.0 jar file, and produce .bat wrappers that attempt to run JRuby using a `java` command line. This breaks those .bat files, as described in jruby#6745, because the `java` command line gets completely wrapped in quotes and no longer can be run as a single executable. This patch un-patches the default Gem.ruby so that it goes back to just using `jruby` as the command line to launch JRuby. This is a pretty nasty hack only necessary because the build runs the gem installation from within the 9.1.17.0 jar file. If the installs were run from a normal JRuby command line (i.e. the current working copy's bin/jruby) the wrappers are generated correctly.
This argument to cmd.exe is passed directly as a self-contained exec argv, so added quotes break cases where we are calling into a native process-launching function like ProcessBuilder. Removing the quoting does not appear to break non-native launching.
a23e940 to
57aff6c
Compare
global_bin seems to not be readable from within the block under some circumstances.
57aff6c to
ed88810
Compare
We parse out single-string commands along this path, which may result in a single script with embedded spaces being broken into individual args. Here we check that the original rawArgs length matches the parsed args length so we know we will only replace the argv[0] executable and not the entire script.
57092ef to
0184797
Compare
eb905a1 to
f1ad815
Compare
Member
Author
|
I have added a small test for this behavior, but it will only run in the master/9.3 builds. The 9.2 branch has not received @kares fixes for running I did confirm the test works on 9.2 branch. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains various small fixes for the native
execsupport on Windows, mostly relating to finding the full paths to cmd.exe and the .exe/.com/.bat/.cmd executables that go with a given command.See #6745.