Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/bootstrap.py
4091 views
1
#!/usr/bin/env python3
2
"""Bootstrap script for emscripten developers / git users.
3
4
After checking out emscripten there are certain steps that need to be
5
taken before it can be used. This script enumerates and automates
6
these steps and is able to run just the steps that are needed based
7
on the timestamps of various input files (kind of like a dumb version
8
of a Makefile).
9
"""
10
import argparse
11
import os
12
import shutil
13
import subprocess
14
import sys
15
16
__rootdir__ = os.path.dirname(os.path.abspath(__file__))
17
sys.path.insert(0, __rootdir__)
18
19
STAMP_DIR = os.path.join(__rootdir__, 'out')
20
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
25
26
actions = [
27
('npm packages', [
28
'package.json',
29
'package-lock.json',
30
], ['npm', 'ci']),
31
('create entry points', [
32
'tools/maint/create_entry_points.py',
33
'tools/maint/run_python.bat',
34
'tools/maint/run_python.sh',
35
'tools/maint/run_python.ps1',
36
], [sys.executable, 'tools/maint/create_entry_points.py']),
37
('git submodules', [
38
'test/third_party/posixtestsuite/',
39
'test/third_party/googletest',
40
'test/third_party/wasi-test-suite',
41
], ['git', 'submodule', 'update', '--init']),
42
]
43
44
45
def get_stamp_file(action_name):
46
return os.path.join(STAMP_DIR, action_name.replace(' ', '_') + '.stamp')
47
48
49
def check_deps(name, deps):
50
stamp_file = get_stamp_file(name)
51
if not os.path.exists(stamp_file):
52
return False
53
for dep in deps:
54
dep = utils.path_from_root(dep)
55
if os.path.getmtime(dep) > os.path.getmtime(stamp_file):
56
return False
57
return True
58
59
60
def check():
61
for name, deps, _ in actions:
62
if not check_deps(name, deps):
63
utils.exit_with_error(f'emscripten setup is not complete ("{name}" is out-of-date). Run `bootstrap` to update')
64
65
66
def main(args):
67
parser = argparse.ArgumentParser(description=__doc__)
68
parser.add_argument('-v', '--verbose', action='store_true', help='verbose', default=False)
69
parser.add_argument('-n', '--dry-run', action='store_true', help='dry run', default=False)
70
parser.add_argument('-i', '--install-git-hooks', action='store_true', help='install emscripten git hooks', default=False)
71
args = parser.parse_args()
72
73
if args.install_git_hooks:
74
if not os.path.exists(utils.path_from_root('.git')):
75
print('--install-git-hooks requires git checkout')
76
return 1
77
78
dst = utils.path_from_root('.git/hooks')
79
if not os.path.exists(dst):
80
os.mkdir(dst)
81
82
src = utils.path_from_root('tools/maint/post-checkout')
83
for src in ('tools/maint/post-checkout', 'tools/maint/pre-push'):
84
shutil.copy(utils.path_from_root(src), dst)
85
return 0
86
87
for name, deps, cmd in actions:
88
if check_deps(name, deps):
89
print('Up-to-date: %s' % name)
90
continue
91
print('Out-of-date: %s' % name)
92
stamp_file = get_stamp_file(name)
93
if args.dry_run:
94
print(' (skipping: dry run) -> %s' % ' '.join(cmd))
95
continue
96
orig_exe = cmd[0]
97
if not os.path.isabs(orig_exe):
98
cmd[0] = shutil.which(orig_exe)
99
if not cmd[0]:
100
utils.exit_with_error(f'command not found: {orig_exe}')
101
print(' -> %s' % ' '.join(cmd))
102
subprocess.run(cmd, check=True, text=True, encoding='utf-8', cwd=utils.path_from_root())
103
utils.safe_ensure_dirs(STAMP_DIR)
104
utils.write_file(stamp_file, 'Timestamp file created by bootstrap.py')
105
return 0
106
107
108
if __name__ == '__main__':
109
main(sys.argv[1:])
110
111