Skip to content

Commit 945a6aa

Browse files
committed
Do not store options while parsing in polyglotOptions
* Otherwise, if we exec() to JVM, we'll have them twice as the launcher keeps the original arguments, and we would pass experimental options on the command line which would make it fail. * We need to check if --embedded or --ruby.embedded is passed on the command line, which we do by looking at polyglotOptions.
1 parent bc1bd0e commit 945a6aa

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.truffleruby.shared.options.StringArrayOptionType;
3535

3636
import java.util.ArrayList;
37+
import java.util.Collections;
38+
import java.util.HashMap;
3739
import java.util.List;
3840
import java.util.Map;
3941

@@ -50,16 +52,25 @@ public class CommandLineOptions {
5052
/** A thing to be executed: a file, inline script, etc. Used by executionAction when applicable. */
5153
String toExecute = "";
5254

53-
private Map<String, String> options;
55+
/** This should not be modified, as otherwise when exec()-ing to JVM from a native launcher,
56+
* these options would be passed on the command line, which fails if they are experimental.
57+
* This would also cause parsing the options twice with the current Launcher design. */
58+
private final Map<String, String> polyglotOptions;
59+
private final Map<String, String> options;
5460
private String[] arguments;
5561
private final List<String> unknownArguments;
5662

57-
public CommandLineOptions(Map<String, String> options) {
58-
this.options = options;
59-
this.arguments = new String[]{};
63+
public CommandLineOptions(Map<String, String> polyglotOptions) {
64+
this.polyglotOptions = Collections.unmodifiableMap(polyglotOptions);
65+
this.options = new HashMap<>();
66+
this.arguments = new String[0];
6067
this.unknownArguments = new ArrayList<>();
6168
}
6269

70+
boolean isSetInPolyglotOptions(String optionName) {
71+
return polyglotOptions.containsKey(optionName);
72+
}
73+
6374
public Map<String, String> getOptions() {
6475
return options;
6576
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,12 @@ private static void debugPreInitialization() {
248248
}
249249

250250
private Context createContext(Context.Builder builder, CommandLineOptions config) {
251-
if (!config.getOptions().containsKey(OptionsCatalog.EMBEDDED.getName())) {
252-
builder.option(OptionsCatalog.EMBEDDED.getName(), Boolean.FALSE.toString());
251+
if (!config.isSetInPolyglotOptions(OptionsCatalog.EMBEDDED.getName())) {
252+
builder.option(OptionsCatalog.EMBEDDED.getName(), "false");
253253
}
254254

255+
builder.options(config.getOptions());
256+
255257
builder.arguments(TruffleRuby.LANGUAGE_ID, config.getArguments());
256258

257259
return builder.build();

0 commit comments

Comments
 (0)