Skip to content

Commit 0425d9e

Browse files
committed
Simplify the logic for *RUBYOPT now that Launcher handles it on its own
(cherry picked from commit 5d65f02)
1 parent a661883 commit 0425d9e

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

src/launcher/java/org/truffleruby/launcher/CommandLineParser.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class CommandLineParser {
5555

5656
private final List<String> arguments;
5757
private int argumentIndex;
58-
private boolean processArgv;
58+
private final boolean processArgv;
5959
private final boolean rubyOpts;
6060
final CommandLineOptions config;
6161
private int lastInterpreterArgumentIndex;
@@ -96,10 +96,6 @@ public void processArguments() throws CommandLineException {
9696
}
9797
}
9898

99-
public int getLastInterpreterArgumentIndex() {
100-
return lastInterpreterArgumentIndex;
101-
}
102-
10399
private boolean endOfInterpreterArguments() {
104100
return lastInterpreterArgumentIndex != -1;
105101
}

src/launcher/java/org/truffleruby/launcher/RubyLauncher.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,18 @@ protected List<String> preprocessArguments(List<String> args, Map<String, String
7878
argumentCommandLineParser.processArguments();
7979

8080
if (config.readRubyOptEnv) {
81+
/* Calling processArguments() here will also add any unrecognized arguments such as
82+
* --jvm/--native/--vm.* arguments and polyglot options to `config.getUnknownArguments()`, which will
83+
* then be processed by AbstractLanguageLauncher and Launcher. If we are going to run Native, Launcher
84+
* will apply VM options to the current process. If we are going to run on JVM, Launcher will collect
85+
* them and pass them when execve()'ing to bin/java. Polyglot options are parsed by
86+
* AbstractLanguageLauncher in the final process. */
8187
// Process RUBYOPT
8288
final List<String> rubyoptArgs = getArgsFromEnvVariable("RUBYOPT");
8389
new CommandLineParser(rubyoptArgs, config, false, true).processArguments();
8490
// Process TRUFFLERUBYOPT
8591
final List<String> trufflerubyoptArgs = getArgsFromEnvVariable("TRUFFLERUBYOPT");
8692
new CommandLineParser(trufflerubyoptArgs, config, false, false).processArguments();
87-
88-
if (isAOT()) {
89-
/* Append options from ENV variables to args after the last interpreter option, which makes sure
90-
* that maybeExec() processes the --vm.* options. These options are removed and are not passed to
91-
* the new process if exec() is being called as these options need to be passed when starting the
92-
* new VM process. The new process gets all arguments and options including those from ENV
93-
* variables. To avoid processing options from ENV variables twice, --disable-rubyopt is passed.
94-
* Only the native launcher can apply native and jvm options (it is too late for the running JVM to
95-
* apply --vm options), therefore this is not done on JVM. */
96-
final int index = argumentCommandLineParser.getLastInterpreterArgumentIndex();
97-
args.add(index, "--disable-rubyopt");
98-
args.addAll(index + 1, rubyoptArgs);
99-
args.addAll(index + 1 + rubyoptArgs.size(), trufflerubyoptArgs);
100-
}
10193
}
10294

10395
// Process RUBYLIB, must be after arguments and RUBYOPT

0 commit comments

Comments
 (0)