Skip to content

Commit 97f974c

Browse files
authored
Fix bootstrap.py script to not depend on tools/shared.py (#24424)
Fix bootstrap.py script to not depend on tools/shared.py so that it can be run during emsdk installation phase when no .emscripten config yet exists. Fixes emscripten-core/emsdk#1545
1 parent e0dd016 commit 97f974c

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

bootstrap.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@
1010
import argparse
1111
import os
1212
import shutil
13+
import subprocess
1314
import sys
1415

1516
__rootdir__ = os.path.dirname(os.path.abspath(__file__))
1617
sys.path.insert(0, __rootdir__)
1718

1819
STAMP_DIR = os.path.join(__rootdir__, 'out')
1920

20-
from tools import shared, utils
21+
# N.b. This script bootstrap.py cannot use 'from tools import shared',
22+
# because shared.py requires that a valid .emscripten config is already
23+
# created. Bootstrap.py needs to be run before an .emscripten config exists.
24+
from tools import utils
2125

2226
actions = [
2327
('npm packages', [
@@ -93,7 +97,7 @@ def main(args):
9397
if not cmd[0]:
9498
utils.exit_with_error(f'command not found: {orig_exe}')
9599
print(' -> %s' % ' '.join(cmd))
96-
shared.run_process(cmd, cwd=utils.path_from_root())
100+
subprocess.run(cmd, check=True, text=True, encoding='utf-8', cwd=utils.path_from_root())
97101
utils.safe_ensure_dirs(STAMP_DIR)
98102
utils.write_file(stamp_file, 'Timestamp file created by bootstrap.py')
99103
return 0

test/test_sanity.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,3 +817,20 @@ def test_bootstrap(self):
817817

818818
# Now the compiler should work again
819819
self.run_process([EMCC, test_file('hello_world.c')])
820+
821+
# Verify that running bootstrap.py in a first-time run scenario should not
822+
# cause an exception. (A first time run scenario is before .emscripten, env.
823+
# vars nor PATH has been configured)
824+
def test_bootstrap_without_em_config(self):
825+
# Remove all environment variables that might help config.py to locate Emscripten tools.
826+
env = os.environ.copy()
827+
for e in ['LLVM_ROOT', 'EMSDK_NODE', 'EMSDK_PYTHON', 'EMSDK', 'EMSCRIPTEN', 'BINARYEN_ROOT', 'EMCC_SKIP_SANITY_CHECK', 'EM_CONFIG']:
828+
env.pop(e, None)
829+
830+
# Remove from PATH every directory that contains clang.exe so that bootstrap.py cannot
831+
# accidentally succeed by virtue of locating tools in PATH.
832+
new_path = [d for d in env['PATH'].split(os.pathsep) if not os.path.isfile(os.path.join(d, shared.exe_suffix('clang')))]
833+
env['PATH'] = os.pathsep.join(new_path)
834+
835+
# Running bootstrap.py should not fail
836+
self.run_process([shared.bat_suffix(shared.path_from_root('bootstrap'))], env=env)

0 commit comments

Comments
 (0)