Skip to content

Commit cac7b0c

Browse files
committed
Bytecode DSL: forward the flag to venv lanuchers
1 parent 22bb7e0 commit cac7b0c

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixSubprocessModuleBuiltins.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@
4444
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
4545
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
4646

47+
import java.io.IOException;
48+
import java.nio.file.Files;
49+
import java.nio.file.Path;
4750
import java.util.Arrays;
4851
import java.util.List;
4952

53+
import org.graalvm.nativeimage.ImageInfo;
54+
5055
import com.oracle.graal.python.annotations.ArgumentClinic;
5156
import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
5257
import com.oracle.graal.python.annotations.ClinicConverterFactory;
@@ -281,7 +286,7 @@ static int forkExec(VirtualFrame frame, Object[] args, Object executableList, bo
281286
Object[] executables = new Object[length];
282287
for (int i = 0; i < length; ++i) {
283288
byte[] bytes = toBytesNode.execute(frame, getItem.execute(frame, inliningTarget, executableList, i));
284-
if (Arrays.equals(bytes, sysExecutable)) {
289+
if (Arrays.equals(bytes, sysExecutable) || isBytecodeDSLJvmVenvLauncher(context, bytes)) {
285290
TruffleString[] additionalArgs = PythonOptions.getExecutableList(context);
286291
if (length != 1 && additionalArgs.length != 1) {
287292
throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.UNSUPPORTED_USE_OF_SYS_EXECUTABLE);
@@ -315,6 +320,30 @@ static int forkExec(VirtualFrame frame, Object[] args, Object executableList, bo
315320
}
316321
}
317322

323+
// On Bytecode DSL in JVM mode it is important to forward the Bytecode DSL flag
324+
// Otherwise we do not forward flags for venv launchers and on Native Image the Bytecode DSL
325+
// flag is baked into the image already
326+
private static boolean isBytecodeDSLJvmVenvLauncher(PythonContext context, byte[] bytes) {
327+
if (!PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER || ImageInfo.inImageRuntimeCode()) {
328+
return false;
329+
}
330+
// best effort to find our if we are executing venv launcher
331+
Path executablePath = Path.of(context.getOption(PythonOptions.Executable).toJavaStringUncached()).toAbsolutePath();
332+
Path path = Path.of(new String(bytes));
333+
while (Files.isSymbolicLink(path)) {
334+
try {
335+
Path symlink = Files.readSymbolicLink(path);
336+
path = path.getParent().resolve(symlink).toAbsolutePath();
337+
} catch (IOException ignore) {
338+
return false;
339+
}
340+
if (path.equals(executablePath)) {
341+
return true;
342+
}
343+
}
344+
return false;
345+
}
346+
318347
/**
319348
* Checks that the tuple contains only valid fds (positive integers fitting into an int) in
320349
* ascending order.

0 commit comments

Comments
 (0)