|
14 | 14 | """ |
15 | 15 |
|
16 | 16 | import os |
| 17 | +import shutil |
17 | 18 | import stat |
18 | 19 | import sys |
19 | 20 |
|
|
61 | 62 | } |
62 | 63 |
|
63 | 64 |
|
| 65 | +windows_exe = os.path.join(__rootdir__, 'tools/pylauncher/pylauncher.exe') |
| 66 | + |
| 67 | + |
64 | 68 | def make_executable(filename): |
65 | 69 | old_mode = stat.S_IMODE(os.stat(filename).st_mode) |
66 | 70 | os.chmod(filename, old_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) |
67 | 71 |
|
68 | 72 |
|
69 | | -def main(all_platforms): |
| 73 | +def maybe_remove(filename): |
| 74 | + if os.path.exists(filename): |
| 75 | + os.remove(filename) |
| 76 | + |
| 77 | + |
| 78 | +def main(all_platforms, use_exe_files): |
70 | 79 | is_windows = sys.platform.startswith('win') |
71 | 80 | is_msys2 = 'MSYSTEM' in os.environ |
72 | 81 | do_unix = all_platforms or not is_windows or is_msys2 |
@@ -99,15 +108,20 @@ def generate_entry_points(cmd, path): |
99 | 108 | make_executable(launcher) |
100 | 109 |
|
101 | 110 | 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) |
| 111 | + maybe_remove(launcher + '.bat') |
| 112 | + maybe_remove(launcher + '.ps1') |
| 113 | + maybe_remove(launcher + '.exe') |
| 114 | + if use_exe_files: |
| 115 | + shutil.copyfile(windows_exe, launcher + '.exe') |
| 116 | + else: |
| 117 | + with open(launcher + '.bat', 'w') as f: |
| 118 | + f.write(bat_data) |
| 119 | + with open(launcher + '.ps1', 'w') as f: |
| 120 | + f.write(ps1_data) |
107 | 121 |
|
108 | 122 | generate_entry_points(entry_points, os.path.join(__scriptdir__, 'run_python')) |
109 | 123 | generate_entry_points(compiler_entry_points, os.path.join(__scriptdir__, 'run_python_compiler')) |
110 | 124 |
|
111 | 125 |
|
112 | 126 | if __name__ == '__main__': |
113 | | - sys.exit(main('--all' in sys.argv)) |
| 127 | + sys.exit(main('--all' in sys.argv, '--exe-files' in sys.argv)) |
0 commit comments