|
44 | 44 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
|
45 | 45 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
|
46 | 46 |
|
| 47 | +import java.io.IOException; |
| 48 | +import java.nio.file.Files; |
| 49 | +import java.nio.file.Path; |
47 | 50 | import java.util.Arrays;
|
48 | 51 | import java.util.List;
|
49 | 52 |
|
| 53 | +import org.graalvm.nativeimage.ImageInfo; |
| 54 | + |
50 | 55 | import com.oracle.graal.python.annotations.ArgumentClinic;
|
51 | 56 | import com.oracle.graal.python.annotations.ArgumentClinic.ClinicConversion;
|
52 | 57 | import com.oracle.graal.python.annotations.ClinicConverterFactory;
|
@@ -281,7 +286,7 @@ static int forkExec(VirtualFrame frame, Object[] args, Object executableList, bo
|
281 | 286 | Object[] executables = new Object[length];
|
282 | 287 | for (int i = 0; i < length; ++i) {
|
283 | 288 | 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)) { |
285 | 290 | TruffleString[] additionalArgs = PythonOptions.getExecutableList(context);
|
286 | 291 | if (length != 1 && additionalArgs.length != 1) {
|
287 | 292 | 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
|
315 | 320 | }
|
316 | 321 | }
|
317 | 322 |
|
| 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 | + |
318 | 347 | /**
|
319 | 348 | * Checks that the tuple contains only valid fds (positive integers fitting into an int) in
|
320 | 349 | * ascending order.
|
|
0 commit comments