Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/tools/maint/create_entry_points.py
6174 views
1
#!/usr/bin/env python3
2
# Copyright 2020 The Emscripten Authors. All rights reserved.
3
# Emscripten is available under two separate licenses, the MIT license and the
4
# University of Illinois/NCSA Open Source License. Both these licenses can be
5
# found in the LICENSE file.
6
7
"""Tool for creating/maintaining the python launcher scripts for all the emscripten
8
python tools.
9
10
This tool makes copies or `run_python.sh/.bat` and `run_python_compiler.sh/.bat`
11
script for each entry point. On UNIX we previously used symbolic links for
12
simplicity but this breaks MINGW users on windows who want to use the shell script
13
launcher but don't have symlink support.
14
"""
15
16
import os
17
import stat
18
import sys
19
20
__scriptdir__ = os.path.dirname(os.path.abspath(__file__))
21
__rootdir__ = os.path.dirname(os.path.dirname(__scriptdir__))
22
23
compiler_entry_points = '''
24
emcc
25
em++
26
'''.split()
27
28
entry_points = '''
29
bootstrap
30
emar
31
embuilder
32
emcmake
33
em-config
34
emconfigure
35
emmake
36
emranlib
37
emrun
38
emscons
39
emsize
40
emprofile
41
emdwp
42
emnm
43
emstrip
44
emsymbolizer
45
emscan-deps
46
empath-split
47
tools/file_packager
48
tools/webidl_binder
49
test/runner
50
'''.split()
51
52
53
# For some tools the entry point doesn't live alongside the python
54
# script.
55
entry_remap = {
56
'emprofile': 'tools/emprofile',
57
'emdwp': 'tools/emdwp',
58
'emnm': 'tools/emnm',
59
'emsymbolizer': 'tools/emsymbolizer',
60
'empath-split': 'tools/empath-split',
61
}
62
63
64
def make_executable(filename):
65
old_mode = stat.S_IMODE(os.stat(filename).st_mode)
66
os.chmod(filename, old_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
67
68
69
def main(all_platforms):
70
is_windows = sys.platform.startswith('win')
71
is_msys2 = 'MSYSTEM' in os.environ
72
do_unix = all_platforms or not is_windows or is_msys2
73
do_windows = all_platforms or is_windows
74
75
def generate_entry_points(cmd, path):
76
sh_file = path + '.sh'
77
bat_file = path + '.bat'
78
ps1_file = path + '.ps1'
79
with open(sh_file) as f:
80
sh_file = f.read()
81
with open(bat_file) as f:
82
bat_file = f.read()
83
with open(ps1_file) as f:
84
ps1_file = f.read()
85
86
for entry_point in cmd:
87
sh_data = sh_file
88
bat_data = bat_file
89
ps1_data = ps1_file
90
if entry_point in entry_remap:
91
sh_data = sh_data.replace('$0', '$(dirname $0)/' + entry_remap[entry_point])
92
bat_data = bat_data.replace('%~n0', entry_remap[entry_point].replace('/', '\\'))
93
ps1_data = ps1_data.replace(r"$MyInvocation.MyCommand.Path -replace '\.ps1$', '.py'", fr'"$PSScriptRoot/{entry_remap[entry_point]}.py"')
94
95
if do_unix:
96
out_sh_file = os.path.join(__rootdir__, entry_point)
97
with open(out_sh_file, 'w') as f:
98
f.write(sh_data)
99
make_executable(out_sh_file)
100
101
if do_windows:
102
with open(os.path.join(__rootdir__, entry_point + '.bat'), 'w') as f:
103
f.write(bat_data)
104
105
with open(os.path.join(__rootdir__, entry_point + '.ps1'), 'w') as f:
106
f.write(ps1_data)
107
108
generate_entry_points(entry_points, os.path.join(__scriptdir__, 'run_python'))
109
generate_entry_points(compiler_entry_points, os.path.join(__scriptdir__, 'run_python_compiler'))
110
111
112
if __name__ == '__main__':
113
sys.exit(main('--all' in sys.argv))
114
115