|
7 | 7 | import os |
8 | 8 | import pathlib |
9 | 9 | import pickle |
| 10 | +import platform |
10 | 11 | import shutil |
11 | 12 | import subprocess |
12 | 13 | import sys |
@@ -288,15 +289,24 @@ def sign(self, command, build_dir, bcfg, formats): |
288 | 289 | @staticmethod |
289 | 290 | def find_imgtool(command, args): |
290 | 291 | if args.tool_path: |
291 | | - command.check_force(shutil.which(args.tool_path), |
292 | | - '--tool-path {}: not an executable'. |
293 | | - format(args.tool_path)) |
294 | | - return [args.tool_path] |
| 292 | + imgtool = args.tool_path |
| 293 | + if not os.path.isfile(imgtool): |
| 294 | + log.die(f'--tool-path {imgtool}: no such file') |
| 295 | + else: |
| 296 | + imgtool = shutil.which('imgtool') or shutil.which('imgtool.py') |
| 297 | + if not imgtool: |
| 298 | + log.die('imgtool not found; either install it', |
| 299 | + '(e.g. "pip3 install imgtool") or provide --tool-path') |
| 300 | + |
| 301 | + if platform.system() == 'Windows' and imgtool.endswith('.py'): |
| 302 | + # Windows users may not be able to run .py files |
| 303 | + # as executables in subprocesses, regardless of |
| 304 | + # what the mode says. Always run imgtool as |
| 305 | + # 'python path/to/imgtool.py' instead of |
| 306 | + # 'path/to/imgtool.py' in these cases. |
| 307 | + # https://github.com/zephyrproject-rtos/zephyr/issues/31876 |
| 308 | + return [sys.executable, imgtool] |
295 | 309 |
|
296 | | - imgtool = shutil.which('imgtool') or shutil.which('imgtool.py') |
297 | | - if not imgtool: |
298 | | - log.die('imgtool not found; either install it', |
299 | | - '(e.g. "pip3 install imgtool") or provide --tool-path') |
300 | 310 | return [imgtool] |
301 | 311 |
|
302 | 312 | @staticmethod |
|
0 commit comments