|
7 | 7 | """Tool for creating/maintaining the python launcher scripts for all the emscripten |
8 | 8 | python tools. |
9 | 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. |
| 10 | +This tool makes copies of the launcher for UNIX and/or windows for each of the |
| 11 | +python entry points. |
| 12 | +
|
| 13 | +For UNIX we use a `run_python.sh` script that will exex that python executable. |
| 14 | +
|
| 15 | +For windows we use `launcher.exe` which is small C program that launches python. |
| 16 | +
|
| 17 | +Hitorically we used `run_python.bat` on windows but found that it was a constant |
| 18 | +source of bugs, as well we bring slower than the dedicated launcher.exe. |
| 19 | +
|
| 20 | +On UNIX we previously used symbolic links for simplicity but this breaks MINGW |
| 21 | +users on windows who want to use the shell script launcher but don't have |
| 22 | +symlink support. |
14 | 23 | """ |
15 | 24 |
|
16 | 25 | import os |
| 26 | +import shutil |
17 | 27 | import stat |
18 | 28 | import sys |
19 | 29 |
|
|
61 | 71 | } |
62 | 72 |
|
63 | 73 |
|
| 74 | +windows_exe = os.path.join(__rootdir__, 'tools/pylauncher/pylauncher.exe') |
| 75 | + |
| 76 | + |
64 | 77 | def make_executable(filename): |
65 | 78 | old_mode = stat.S_IMODE(os.stat(filename).st_mode) |
66 | 79 | os.chmod(filename, old_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) |
67 | 80 |
|
68 | 81 |
|
69 | | -def main(all_platforms): |
| 82 | +def maybe_remove(filename): |
| 83 | + if os.path.exists(filename): |
| 84 | + os.remove(filename) |
| 85 | + |
| 86 | + |
| 87 | +def main(all_platforms, use_bat_files): |
70 | 88 | is_windows = sys.platform.startswith('win') |
71 | 89 | is_msys2 = 'MSYSTEM' in os.environ |
72 | 90 | do_unix = all_platforms or not is_windows or is_msys2 |
@@ -99,15 +117,23 @@ def generate_entry_points(cmd, path): |
99 | 117 | make_executable(launcher) |
100 | 118 |
|
101 | 119 | if do_windows: |
102 | | - with open(launcher + '.bat', 'w') as f: |
103 | | - f.write(bat_data) |
104 | | - |
105 | | - with open(launcher + '.ps1', 'w') as f: |
106 | | - f.write(ps1_data) |
| 120 | + maybe_remove(launcher + '.bat') |
| 121 | + maybe_remove(launcher + '.ps1') |
| 122 | + maybe_remove(launcher + '.exe') |
| 123 | + # We use windows executables these days rather than `.bat` files, but for an |
| 124 | + # interim period we still support the old `.bat` files via the `EMCC_USE_BAT_FILES` |
| 125 | + # environment variable. |
| 126 | + if use_bat_files: |
| 127 | + with open(launcher + '.bat', 'w') as f: |
| 128 | + f.write(bat_data) |
| 129 | + with open(launcher + '.ps1', 'w') as f: |
| 130 | + f.write(ps1_data) |
| 131 | + else: |
| 132 | + shutil.copyfile(windows_exe, launcher + '.exe') |
107 | 133 |
|
108 | 134 | generate_entry_points(entry_points, os.path.join(__scriptdir__, 'run_python')) |
109 | 135 | generate_entry_points(compiler_entry_points, os.path.join(__scriptdir__, 'run_python_compiler')) |
110 | 136 |
|
111 | 137 |
|
112 | 138 | if __name__ == '__main__': |
113 | | - sys.exit(main('--all' in sys.argv)) |
| 139 | + sys.exit(main('--all' in sys.argv, '--bat-files' in sys.argv)) |
0 commit comments