Skip to content

Commit f4a899d

Browse files
committed
Simplify logic for launcher options with a different default
(cherry picked from commit 3e9a83d)
1 parent bf6c8ff commit f4a899d

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

src/launcher/java/org/truffleruby/launcher/CommandLineOptions.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import java.io.File;
3333
import java.util.ArrayList;
34-
import java.util.Collections;
3534
import java.util.HashMap;
3635
import java.util.List;
3736
import java.util.Map;
@@ -58,26 +57,17 @@ public class CommandLineOptions {
5857
/** A thing to be executed: a file, inline script, etc. Used by executionAction when applicable. */
5958
String toExecute = "";
6059

61-
/** This should not be modified, as otherwise when exec()-ing to JVM from a native launcher, these options would be
62-
* passed on the command line, which fails if they are experimental. This would also cause parsing the options twice
63-
* with the current Launcher design. */
64-
private final Map<String, String> polyglotOptions;
6560
private final Map<String, String> options;
6661
private String[] arguments;
6762
private final List<String> unknownArguments;
6863
private Boolean gemOrBundle = null;
6964

70-
public CommandLineOptions(Map<String, String> polyglotOptions) {
71-
this.polyglotOptions = Collections.unmodifiableMap(polyglotOptions);
65+
public CommandLineOptions() {
7266
this.options = new HashMap<>();
7367
this.arguments = EMPTY_STRING_ARRAY;
7468
this.unknownArguments = new ArrayList<>();
7569
}
7670

77-
boolean isSetInPolyglotOptions(String optionName) {
78-
return polyglotOptions.containsKey(optionName);
79-
}
80-
8171
public Map<String, String> getOptions() {
8272
return options;
8373
}

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ protected void printVersion() {
6161

6262
@Override
6363
protected List<String> preprocessArguments(List<String> args, Map<String, String> polyglotOptions) {
64-
config = new CommandLineOptions(polyglotOptions);
64+
// Set default options for the launcher which don't match the OptionKey's default.
65+
// These options can still be overridden if set explicitly.
66+
polyglotOptions.put(OptionsCatalog.EMBEDDED.getName(), "false");
67+
if (isAOT()) {
68+
final String launcher = ProcessProperties.getExecutableName();
69+
polyglotOptions.put(OptionsCatalog.LAUNCHER.getName(), launcher);
70+
}
71+
72+
config = new CommandLineOptions();
6573

6674
try {
6775
config.executionAction = ExecutionAction.UNSET;
@@ -236,15 +244,6 @@ private int runRubyMain(Context.Builder contextBuilder, CommandLineOptions confi
236244
}
237245

238246
private Context createContext(Context.Builder builder, CommandLineOptions config) {
239-
if (isAOT() && !config.isSetInPolyglotOptions(OptionsCatalog.LAUNCHER.getName())) {
240-
final String launcher = ProcessProperties.getExecutableName();
241-
builder.option(OptionsCatalog.LAUNCHER.getName(), launcher);
242-
}
243-
244-
if (!config.isSetInPolyglotOptions(OptionsCatalog.EMBEDDED.getName())) {
245-
builder.option(OptionsCatalog.EMBEDDED.getName(), "false");
246-
}
247-
248247
if (config.isGemOrBundle() && getImplementationNameFromEngine().contains("Graal")) {
249248
// Apply options to run gem/bundle more efficiently
250249
builder.option("engine.Mode", "latency");

0 commit comments

Comments
 (0)