|
4 | 4 | import contextlib |
5 | 5 | import functools |
6 | 6 | import os |
7 | | - |
8 | | -try: |
9 | | - from os import process_cpu_count as cpu_count |
10 | | -except ImportError: |
11 | | - from os import cpu_count |
12 | | -from pathlib import Path |
13 | 7 | import shutil |
14 | 8 | import subprocess |
15 | 9 | import sys |
16 | 10 | import sysconfig |
17 | 11 | import tempfile |
| 12 | +from pathlib import Path |
| 13 | +from textwrap import dedent |
| 14 | + |
| 15 | +try: |
| 16 | + from os import process_cpu_count as cpu_count |
| 17 | +except ImportError: |
| 18 | + from os import cpu_count |
18 | 19 |
|
19 | | -WASM_DIR = Path(__file__).parent.parent |
20 | | -CHECKOUT = WASM_DIR.parent.parent |
| 20 | + |
| 21 | +EMSCRIPTEN_DIR = Path(__file__).parent |
| 22 | +CHECKOUT = EMSCRIPTEN_DIR.parent.parent.parent |
21 | 23 |
|
22 | 24 | CROSS_BUILD_DIR = CHECKOUT / "cross-build" |
23 | 25 | BUILD_DIR = CROSS_BUILD_DIR / "build" |
@@ -72,7 +74,7 @@ def wrapper(context): |
72 | 74 | print("⎯" * terminal_width) |
73 | 75 | print("📁", working_dir) |
74 | 76 | if clean_ok and getattr(context, "clean", False) and working_dir.exists(): |
75 | | - print(f"🚮 Deleting directory (--clean)...") |
| 77 | + print("🚮 Deleting directory (--clean)...") |
76 | 78 | shutil.rmtree(working_dir) |
77 | 79 |
|
78 | 80 | working_dir.mkdir(parents=True, exist_ok=True) |
@@ -207,9 +209,21 @@ def configure_emscripten_python(context, working_dir): |
207 | 209 | quiet=context.quiet, |
208 | 210 | ) |
209 | 211 |
|
210 | | - python_js = working_dir / "python.js" |
| 212 | + shutil.copy(EMSCRIPTEN_DIR / "node_entry.mjs", working_dir / "node_entry.mjs") |
| 213 | + |
| 214 | + node_entry = working_dir / "node_entry.mjs" |
211 | 215 | exec_script = working_dir / "python.sh" |
212 | | - exec_script.write_text(f'#!/bin/sh\nexec {host_runner} {python_js} "$@"\n') |
| 216 | + exec_script.write_text( |
| 217 | + dedent( |
| 218 | + f"""\ |
| 219 | + #!/bin/sh |
| 220 | +
|
| 221 | + # We compute our own path, not following symlinks and pass it in so that |
| 222 | + # node_entry.mjs can set sys.executable correctly. |
| 223 | + exec {host_runner} {node_entry} "$(realpath -s $0)" "$@" |
| 224 | + """ |
| 225 | + ) |
| 226 | + ) |
213 | 227 | exec_script.chmod(0o755) |
214 | 228 | print(f"🏃♀️ Created {exec_script} ... ") |
215 | 229 | sys.stdout.flush() |
|
0 commit comments