Skip to content

Commit e3136a8

Browse files
authored
Remove shared.PYTHON. NFC (#17197)
This was nothing more than an alias for sys.executable. While this is used a fair amount in testing, emscripten itself should not be forking python subprocesses itself, but instead using the launcher scripts.
1 parent c564124 commit e3136a8

File tree

10 files changed

+27
-24
lines changed

10 files changed

+27
-24
lines changed

emcc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,10 @@ def run(args):
11041104
args = [x for x in args if x != '--cflags']
11051105
with misc_temp_files.get_file(suffix='.o') as temp_target:
11061106
input_file = 'hello_world.c'
1107-
cmd = [shared.PYTHON, "-E", sys.argv[0], utils.path_from_root('tests', input_file), '-v', '-c', '-o', temp_target] + args
1107+
compiler = shared.EMCC
1108+
if run_via_emxx:
1109+
compiler = shared.EMXX
1110+
cmd = [compiler, utils.path_from_root('tests', input_file), '-v', '-c', '-o', temp_target] + args
11081111
proc = run_process(cmd, stderr=PIPE, check=False)
11091112
if proc.returncode != 0:
11101113
print(proc.stderr)

tests/benchmark_sse.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
__rootpath__ = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1616
sys.path.append(__rootpath__)
1717

18-
from tools.shared import PYTHON, WINDOWS, CLANG_CXX, EMCC, PIPE, V8_ENGINE
19-
from tools.shared import path_from_root, run_process, test_file
18+
from tools.shared import WINDOWS, CLANG_CXX, EMCC, PIPE
19+
from tools.shared import run_process
20+
from tools.config import V8_ENGINE
21+
from tests.common import EMRUN, test_file
2022
import clang_native
2123

2224
temp_dir = tempfile.mkdtemp()
2325

2426
# System info
25-
system_info = Popen([PYTHON, path_from_root('emrun'), '--system_info'], stdout=PIPE, stderr=PIPE).communicate()
27+
system_info = Popen([EMRUN, '--system_info'], stdout=PIPE, stderr=PIPE).communicate()
2628

2729
# Native info
2830
native_info = Popen(['clang', '-v'], stdout=PIPE, stderr=PIPE).communicate()

tests/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@
7878

7979
EMBUILDER = shared.bat_suffix(path_from_root('embuilder'))
8080
EMMAKE = shared.bat_suffix(path_from_root('emmake'))
81+
EMRUN = shared.bat_suffix(shared.path_from_root('emrun'))
8182
WASM_DIS = Path(building.get_binaryen_bin(), 'wasm-dis')
8283
LLVM_OBJDUMP = os.path.expanduser(shared.build_llvm_tool_path(shared.exe_suffix('llvm-objdump')))
84+
PYTHON = sys.executable
8385

8486

8587
def delete_contents(pathname):

tests/test_browser.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from common import BrowserCore, RunnerCore, path_from_root, has_browser, EMTEST_BROWSER, Reporting
2424
from common import create_file, parameterized, ensure_dir, disabled, test_file, WEBIDL_BINDER
25-
from common import read_file, requires_v8, also_with_minimal_runtime
25+
from common import read_file, requires_v8, also_with_minimal_runtime, EMRUN
2626
from tools import shared
2727
from tools import ports
2828
from tools.shared import EMCC, WINDOWS, FILE_PACKAGER, PIPE
@@ -5404,9 +5404,6 @@ def test_full_js_library_strict(self):
54045404
self.btest_exit(test_file('hello_world.c'), args=['-sINCLUDE_FULL_LIBRARY', '-sSTRICT_JS'])
54055405

54065406

5407-
EMRUN = path_from_root('emrun')
5408-
5409-
54105407
class emrun(RunnerCore):
54115408
def test_emrun_info(self):
54125409
if not has_browser():

tests/test_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
raise Exception('do not run this file directly; do something like: tests/runner')
2121

2222
from tools.shared import try_delete, PIPE
23-
from tools.shared import PYTHON, EMCC, EMAR
23+
from tools.shared import EMCC, EMAR
2424
from tools.utils import WINDOWS, MACOS, write_file
2525
from tools import shared, building, config, webassembly
2626
import common
2727
from common import RunnerCore, path_from_root, requires_native_clang, test_file, create_file
2828
from common import skip_if, needs_dylink, no_windows, no_mac, is_slow_test, parameterized
2929
from common import env_modify, with_env_modify, disabled, node_pthreads, also_with_wasm_bigint
3030
from common import read_file, read_binary, requires_v8, requires_node
31-
from common import NON_ZERO, WEBIDL_BINDER, EMBUILDER
31+
from common import NON_ZERO, WEBIDL_BINDER, EMBUILDER, PYTHON
3232
import clang_native
3333

3434
# decorators for limiting which modes a test can run in

tests/test_other.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
raise Exception('do not run this file directly; do something like: tests/runner other')
3030

3131
from tools.shared import try_delete, config
32-
from tools.shared import EMCC, EMXX, EMAR, EMRANLIB, PYTHON, FILE_PACKAGER, WINDOWS
32+
from tools.shared import EMCC, EMXX, EMAR, EMRANLIB, FILE_PACKAGER, WINDOWS
3333
from tools.shared import CLANG_CC, CLANG_CXX, LLVM_AR, LLVM_DWARFDUMP, LLVM_DWP, EMCMAKE, EMCONFIGURE
3434
from common import RunnerCore, path_from_root, is_slow_test, ensure_dir, disabled, make_executable
3535
from common import env_modify, no_mac, no_windows, requires_native_clang, with_env_modify
3636
from common import create_file, parameterized, NON_ZERO, node_pthreads, TEST_ROOT, test_file
3737
from common import compiler_for, read_file, read_binary, EMBUILDER, requires_v8, requires_node
38-
from common import also_with_minimal_runtime, also_with_wasm_bigint, EMTEST_BUILD_VERBOSE
38+
from common import also_with_minimal_runtime, also_with_wasm_bigint, EMTEST_BUILD_VERBOSE, PYTHON
3939
from tools import shared, building, utils, deps_info, response_file
4040
import common
4141
import jsrun

tests/test_sockets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import clang_native
1818
import common
1919
from common import BrowserCore, no_windows, create_file, test_file, read_file
20-
from common import parameterized, requires_native_clang
20+
from common import parameterized, requires_native_clang, PYTHON
2121
from tools import shared, config, utils
22-
from tools.shared import PYTHON, EMCC, path_from_root, run_process, CLANG_CC
22+
from tools.shared import EMCC, path_from_root, run_process, CLANG_CC
2323

2424
npm_checked = False
2525

tools/building.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from . import webassembly
2323
from . import config
2424
from . import utils
25-
from .shared import CLANG_CC, CLANG_CXX, PYTHON
25+
from .shared import CLANG_CC, CLANG_CXX
2626
from .shared import LLVM_NM, EMCC, EMAR, EMXX, EMRANLIB, WASM_LD, LLVM_AR
2727
from .shared import LLVM_LINK, LLVM_OBJCOPY
2828
from .shared import try_delete, run_process, check_call, exit_with_error
@@ -1432,7 +1432,7 @@ def emit_wasm_source_map(wasm_file, map_file, final_wasm):
14321432
# source file paths must be relative to the location of the map (which is
14331433
# emitted alongside the wasm)
14341434
base_path = os.path.dirname(os.path.abspath(final_wasm))
1435-
sourcemap_cmd = [PYTHON, "-E", path_from_root('tools/wasm-sourcemap.py'),
1435+
sourcemap_cmd = [sys.executable, '-E', path_from_root('tools/wasm-sourcemap.py'),
14361436
wasm_file,
14371437
'--dwarfdump=' + LLVM_DWARFDUMP,
14381438
'-o', map_file,

tools/emcoverage.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@
4242

4343

4444
def main():
45-
# We hack sys.executable to point to this file, which is executable via #! line.
46-
# Emscripten uses sys.executable to populate shared.PYTHON, which is used to
47-
# invoke all python subprocesses. By making this script run all python subprocesses,
48-
# all of them will execute under the watchful eye of emcoverage.py, and resulting
49-
# in their code coverage being tracked.
50-
sys.executable = os.path.abspath(__file__)
51-
os.environ['EMSDK_PYTHON'] = sys.executable
45+
# We set EMSDK_PYTHON to point to this file, which is executable via #! line.
46+
# Emscripten uses EMSDK_PYTHON to invoke all python subprocesses. By making this
47+
# script run all python subprocesses, all of them will execute under the
48+
# watchful eye of emcoverage.py, and resulting in their code coverage being
49+
# tracked.
50+
os.environ['EMSDK_PYTHON'] = os.path.abspath(__file__)
5251

5352
store = os.path.join(SCRIPT_DIR, 'coverage')
5453

tools/shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
DEBUG_SAVE = DEBUG or int(os.environ.get('EMCC_DEBUG_SAVE', '0'))
4848
MINIMUM_NODE_VERSION = (4, 1, 1)
4949
EXPECTED_LLVM_VERSION = "15.0"
50-
PYTHON = sys.executable
5150

5251
# Used only when EM_PYTHON_MULTIPROCESSING=1 env. var is set.
5352
multiprocessing_pool = None
@@ -705,6 +704,7 @@ def get_llvm_target():
705704
EMCONFIGURE = bat_suffix(path_from_root('emconfigure'))
706705
EM_NM = bat_suffix(path_from_root('emnm'))
707706
FILE_PACKAGER = bat_suffix(path_from_root('tools/file_packager'))
707+
WASM_SOURCEMAP = bat_suffix(path_from_root('tools/wasm-sourcemap'))
708708

709709
setup_temp_dirs()
710710

0 commit comments

Comments
 (0)