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
4150 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/maintains the python launcher scripts for all the emscripten
8
python tools.
9
10
This tools 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 use the shell script
13
launcher but don't have symlink support.
14
"""
15
16
import os
17
import sys
18
import stat
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
tools/file_packager
47
tools/webidl_binder
48
test/runner
49
'''.split()
50
51
52
# For some tools the entry point doesn't live alongside the python
53
# script.
54
entry_remap = {
55
'emprofile': 'tools/emprofile',
56
'emdwp': 'tools/emdwp',
57
'emnm': 'tools/emnm',
58
}
59
60
61
def make_executable(filename):
62
old_mode = stat.S_IMODE(os.stat(filename).st_mode)
63
os.chmod(filename, old_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
64
65
66
def main(all_platforms):
67
is_windows = sys.platform.startswith('win')
68
do_unix = all_platforms or not is_windows
69
do_windows = all_platforms or is_windows
70
71
def generate_entry_points(cmd, path):
72
sh_file = path + '.sh'
73
bat_file = path + '.bat'
74
ps1_file = path + '.ps1'
75
with open(sh_file) as f:
76
sh_file = f.read()
77
with open(bat_file) as f:
78
bat_file = f.read()
79
with open(ps1_file) as f:
80
ps1_file = f.read()
81
82
for entry_point in cmd:
83
sh_data = sh_file
84
bat_data = bat_file
85
ps1_data = ps1_file
86
if entry_point in entry_remap:
87
sh_data = sh_data.replace('$0', '$(dirname $0)/' + entry_remap[entry_point])
88
bat_data = bat_data.replace('%~n0', entry_remap[entry_point].replace('/', '\\'))
89
ps1_data = ps1_data.replace(r"$MyInvocation.MyCommand.Path -replace '\.ps1$', '.py'", fr'"$PSScriptRoot/{entry_remap[entry_point]}.py"')
90
91
if do_unix:
92
out_sh_file = os.path.join(__rootdir__, entry_point)
93
with open(out_sh_file, 'w') as f:
94
f.write(sh_data)
95
make_executable(out_sh_file)
96
97
if do_windows:
98
with open(os.path.join(__rootdir__, entry_point + '.bat'), 'w') as f:
99
f.write(bat_data)
100
101
with open(os.path.join(__rootdir__, entry_point + '.ps1'), 'w') as f:
102
f.write(ps1_data)
103
104
generate_entry_points(entry_points, os.path.join(__scriptdir__, 'run_python'))
105
generate_entry_points(compiler_entry_points, os.path.join(__scriptdir__, 'run_python_compiler'))
106
107
108
if __name__ == '__main__':
109
sys.exit(main('--all' in sys.argv))
110
111