Path: blob/main/tools/maint/create_entry_points.py
4150 views
#!/usr/bin/env python31# Copyright 2020 The Emscripten Authors. All rights reserved.2# Emscripten is available under two separate licenses, the MIT license and the3# University of Illinois/NCSA Open Source License. Both these licenses can be4# found in the LICENSE file.56"""Tool for creating/maintains the python launcher scripts for all the emscripten7python tools.89This tools makes copies or `run_python.sh/.bat` and `run_python_compiler.sh/.bat`10script for each entry point. On UNIX we previously used symbolic links for11simplicity but this breaks MINGW users on windows who want use the shell script12launcher but don't have symlink support.13"""1415import os16import sys17import stat1819__scriptdir__ = os.path.dirname(os.path.abspath(__file__))20__rootdir__ = os.path.dirname(os.path.dirname(__scriptdir__))2122compiler_entry_points = '''23emcc24em++25'''.split()2627entry_points = '''28bootstrap29emar30embuilder31emcmake32em-config33emconfigure34emmake35emranlib36emrun37emscons38emsize39emprofile40emdwp41emnm42emstrip43emsymbolizer44emscan-deps45tools/file_packager46tools/webidl_binder47test/runner48'''.split()495051# For some tools the entry point doesn't live alongside the python52# script.53entry_remap = {54'emprofile': 'tools/emprofile',55'emdwp': 'tools/emdwp',56'emnm': 'tools/emnm',57}585960def make_executable(filename):61old_mode = stat.S_IMODE(os.stat(filename).st_mode)62os.chmod(filename, old_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)636465def main(all_platforms):66is_windows = sys.platform.startswith('win')67do_unix = all_platforms or not is_windows68do_windows = all_platforms or is_windows6970def generate_entry_points(cmd, path):71sh_file = path + '.sh'72bat_file = path + '.bat'73ps1_file = path + '.ps1'74with open(sh_file) as f:75sh_file = f.read()76with open(bat_file) as f:77bat_file = f.read()78with open(ps1_file) as f:79ps1_file = f.read()8081for entry_point in cmd:82sh_data = sh_file83bat_data = bat_file84ps1_data = ps1_file85if entry_point in entry_remap:86sh_data = sh_data.replace('$0', '$(dirname $0)/' + entry_remap[entry_point])87bat_data = bat_data.replace('%~n0', entry_remap[entry_point].replace('/', '\\'))88ps1_data = ps1_data.replace(r"$MyInvocation.MyCommand.Path -replace '\.ps1$', '.py'", fr'"$PSScriptRoot/{entry_remap[entry_point]}.py"')8990if do_unix:91out_sh_file = os.path.join(__rootdir__, entry_point)92with open(out_sh_file, 'w') as f:93f.write(sh_data)94make_executable(out_sh_file)9596if do_windows:97with open(os.path.join(__rootdir__, entry_point + '.bat'), 'w') as f:98f.write(bat_data)99100with open(os.path.join(__rootdir__, entry_point + '.ps1'), 'w') as f:101f.write(ps1_data)102103generate_entry_points(entry_points, os.path.join(__scriptdir__, 'run_python'))104generate_entry_points(compiler_entry_points, os.path.join(__scriptdir__, 'run_python_compiler'))105106107if __name__ == '__main__':108sys.exit(main('--all' in sys.argv))109110111