From 3ffd1a3ae10bf86fef2d292629294f415c528a68 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 16 Mar 2021 08:37:55 -0700 Subject: [PATCH] Enable custom locations in create_entry_points.py As and example the python code for the emdump tool lives in tools/emdump.py, but we want the entey point to be at the top level of emscripten. Hopefully this will help with #13464 --- tools/emdump => emdump | 2 +- tools/emdump.bat => emdump.bat | 2 +- emprofile | 2 +- emprofile.bat | 2 +- tools/create_entry_points.py | 43 ++++++++++++++++++++++++---------- 5 files changed, 35 insertions(+), 16 deletions(-) rename tools/emdump => emdump (92%) rename tools/emdump.bat => emdump.bat (86%) mode change 100644 => 100755 emprofile diff --git a/tools/emdump b/emdump similarity index 92% rename from tools/emdump rename to emdump index b9fcf9532af82..e8f8724b100c1 100755 --- a/tools/emdump +++ b/emdump @@ -26,4 +26,4 @@ if [ -z "$PYTHON" ]; then exit 1 fi -exec "$PYTHON" "$0.py" "$@" +exec "$PYTHON" "$(dirname $0)/tools/emdump.py" "$@" diff --git a/tools/emdump.bat b/emdump.bat similarity index 86% rename from tools/emdump.bat rename to emdump.bat index 37eee09d6abea..19d5a5e056249 100644 --- a/tools/emdump.bat +++ b/emdump.bat @@ -8,4 +8,4 @@ set EM_PY=python ) -@"%EM_PY%" "%~dp0\%~n0.py" %* +@"%EM_PY%" "%~dp0\tools\emdump.py" %* diff --git a/emprofile b/emprofile old mode 100644 new mode 100755 index c85fb4dd4b900..b8f704f19a0c9 --- a/emprofile +++ b/emprofile @@ -26,4 +26,4 @@ if [ -z "$PYTHON" ]; then exit 1 fi -exec "$PYTHON" "tools/$0.py" "$@" +exec "$PYTHON" "$(dirname $0)/tools/emprofile.py" "$@" diff --git a/emprofile.bat b/emprofile.bat index 72043adae9b22..5b47011316aed 100644 --- a/emprofile.bat +++ b/emprofile.bat @@ -8,4 +8,4 @@ set EM_PY=python ) -@"%EM_PY%" "%~dp0\tools\%~n0.py" %* +@"%EM_PY%" "%~dp0\tools\emprofile.py" %* diff --git a/tools/create_entry_points.py b/tools/create_entry_points.py index 6a214f0db8358..3dfc01bd11134 100755 --- a/tools/create_entry_points.py +++ b/tools/create_entry_points.py @@ -14,8 +14,8 @@ """ import os -import shutil import sys +import stat compiler_entry_points = ''' emcc @@ -33,29 +33,48 @@ emrun emscons emsize -tools/emdump +emdump +emprofile tools/file_packager tests/runner '''.split() +# For some tools the entry point doesn't live alongside the python +# script. +entry_remap = { + 'emdump': 'tools/emdump', + 'emprofile': 'tools/emprofile', +} + +tools_dir = os.path.dirname(os.path.abspath(__file__)) + + def main(): - tools_dir = os.path.dirname(os.path.abspath(__file__)) 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: - dst = os.path.join(root_dir, entry_point) - if os.path.exists(dst): - os.remove(dst) - shutil.copy2(sh_file, dst) - - dst += '.bat' - if os.path.exists(dst): - os.remove(dst) - shutil.copy2(bat_file, dst) + 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'))