forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_entry_points.py
executable file
·91 lines (74 loc) · 2.25 KB
/
create_entry_points.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3
# Copyright 2020 The Emscripten Authors. All rights reserved.
# Emscripten is available under two separate licenses, the MIT license and the
# University of Illinois/NCSA Open Source License. Both these licenses can be
# found in the LICENSE file.
"""Tool for creating/maintains the python launcher scripts for all the emscripten
python tools.
This tools makes copies or `run_python.sh/.bat` and `run_python_compiler.sh/.bat`
script for each entry point. On UNIX we previously used symbolic links for
simplicity but this breaks MINGW users on windows who want use the shell script
launcher but don't have symlink support.
"""
import os
import sys
import stat
compiler_entry_points = '''
emcc
em++
'''.split()
entry_points = '''
emar
embuilder
emcmake
em-config
emconfigure
emmake
emranlib
emrun
emscons
emsize
emdump
emprofile
emdwp
emnm
emstrip
emsymbolizer
tools/file_packager
tools/webidl_binder
test/runner
'''.split()
# For some tools the entry point doesn't live alongside the python
# script.
entry_remap = {
'emdump': 'tools/emdump',
'emprofile': 'tools/emprofile',
'emdwp': 'tools/emdwp',
'emnm': 'tools/emnm',
}
tools_dir = os.path.dirname(os.path.abspath(__file__))
def main():
root_dir = os.path.dirname(tools_dir)
def generate_entry_points(cmd, path):
sh_file = path + '.sh'
bat_file = path + '.bat'
with open(sh_file) as f:
sh_file = f.read()
with open(bat_file) as f:
bat_file = f.read()
for entry_point in cmd:
sh_data = sh_file
bat_data = bat_file
if entry_point in entry_remap:
sh_data = sh_data.replace('$0', '$(dirname $0)/' + entry_remap[entry_point])
bat_data = bat_data.replace('%~n0', entry_remap[entry_point].replace('/', '\\'))
out_sh_file = os.path.join(root_dir, entry_point)
with open(out_sh_file, 'w') as f:
f.write(sh_data)
os.chmod(out_sh_file, stat.S_IMODE(os.stat(out_sh_file).st_mode) | stat.S_IXUSR)
with open(os.path.join(root_dir, entry_point + '.bat'), 'w') as f:
f.write(bat_data)
generate_entry_points(entry_points, os.path.join(tools_dir, 'run_python'))
generate_entry_points(compiler_entry_points, os.path.join(tools_dir, 'run_python_compiler'))
if __name__ == '__main__':
sys.exit(main())