Path: blob/main/tools/maint/create_entry_points.py
6174 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/maintaining the python launcher scripts for all the emscripten7python tools.89This tool 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 to use the shell script12launcher but don't have symlink support.13"""1415import os16import stat17import sys1819__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-deps45empath-split46tools/file_packager47tools/webidl_binder48test/runner49'''.split()505152# For some tools the entry point doesn't live alongside the python53# script.54entry_remap = {55'emprofile': 'tools/emprofile',56'emdwp': 'tools/emdwp',57'emnm': 'tools/emnm',58'emsymbolizer': 'tools/emsymbolizer',59'empath-split': 'tools/empath-split',60}616263def make_executable(filename):64old_mode = stat.S_IMODE(os.stat(filename).st_mode)65os.chmod(filename, old_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)666768def main(all_platforms):69is_windows = sys.platform.startswith('win')70is_msys2 = 'MSYSTEM' in os.environ71do_unix = all_platforms or not is_windows or is_msys272do_windows = all_platforms or is_windows7374def generate_entry_points(cmd, path):75sh_file = path + '.sh'76bat_file = path + '.bat'77ps1_file = path + '.ps1'78with open(sh_file) as f:79sh_file = f.read()80with open(bat_file) as f:81bat_file = f.read()82with open(ps1_file) as f:83ps1_file = f.read()8485for entry_point in cmd:86sh_data = sh_file87bat_data = bat_file88ps1_data = ps1_file89if entry_point in entry_remap:90sh_data = sh_data.replace('$0', '$(dirname $0)/' + entry_remap[entry_point])91bat_data = bat_data.replace('%~n0', entry_remap[entry_point].replace('/', '\\'))92ps1_data = ps1_data.replace(r"$MyInvocation.MyCommand.Path -replace '\.ps1$', '.py'", fr'"$PSScriptRoot/{entry_remap[entry_point]}.py"')9394if do_unix:95out_sh_file = os.path.join(__rootdir__, entry_point)96with open(out_sh_file, 'w') as f:97f.write(sh_data)98make_executable(out_sh_file)99100if do_windows:101with open(os.path.join(__rootdir__, entry_point + '.bat'), 'w') as f:102f.write(bat_data)103104with open(os.path.join(__rootdir__, entry_point + '.ps1'), 'w') as f:105f.write(ps1_data)106107generate_entry_points(entry_points, os.path.join(__scriptdir__, 'run_python'))108generate_entry_points(compiler_entry_points, os.path.join(__scriptdir__, 'run_python_compiler'))109110111if __name__ == '__main__':112sys.exit(main('--all' in sys.argv))113114115