Skip to content

Commit ab3fc99

Browse files
committed
[GR-21200] Pass polyglot options to the engine when in multi-context mode
PullRequest: graalpython/819
2 parents e224de3 + 2150281 commit ab3fc99

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@
3535
import java.nio.file.NoSuchFileException;
3636
import java.nio.file.Paths;
3737
import java.util.ArrayList;
38+
import java.util.HashMap;
3839
import java.util.List;
3940
import java.util.ListIterator;
4041
import java.util.Map;
4142
import java.util.Set;
4243

43-
import com.oracle.truffle.llvm.toolchain.launchers.common.Driver;
44-
4544
import org.graalvm.launcher.AbstractLanguageLauncher;
4645
import org.graalvm.nativeimage.ImageInfo;
4746
import org.graalvm.nativeimage.ProcessProperties;
@@ -55,6 +54,8 @@
5554
import org.graalvm.polyglot.SourceSection;
5655
import org.graalvm.polyglot.Value;
5756

57+
import com.oracle.truffle.llvm.toolchain.launchers.common.Driver;
58+
5859
import jline.console.UserInterruptException;
5960

6061
public class GraalPythonMain extends AbstractLanguageLauncher {
@@ -82,6 +83,7 @@ public static void main(String[] args) {
8283
private List<String> givenArguments;
8384
private List<String> relaunchArgs;
8485
private boolean wantsExperimental = false;
86+
private Map<String, String> enginePolyglotOptions;
8587

8688
@Override
8789
protected List<String> preprocessArguments(List<String> givenArgs, Map<String, String> polyglotOptions) {
@@ -267,6 +269,16 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
267269
return unrecognized;
268270
}
269271

272+
@Override
273+
protected void validateArguments(Map<String, String> polyglotOptions) {
274+
if (multiContext) {
275+
// Hack to pass polyglot options to the shared engine, not to the context which would
276+
// refuse them
277+
this.enginePolyglotOptions = new HashMap<>(polyglotOptions);
278+
polyglotOptions.clear();
279+
}
280+
}
281+
270282
private void addRelaunchArg(String arg) {
271283
if (relaunchArgs == null) {
272284
relaunchArgs = new ArrayList<>();
@@ -371,7 +383,7 @@ protected void launch(Builder contextBuilder) {
371383
contextBuilder.option("python.TerminalHeight", Integer.toString(consoleHandler.getTerminalHeight()));
372384

373385
if (multiContext) {
374-
contextBuilder.engine(Engine.create());
386+
contextBuilder.engine(Engine.newBuilder().allowExperimentalOptions(true).options(enginePolyglotOptions).build());
375387
}
376388

377389
int rc = 1;

0 commit comments

Comments
 (0)