|
14 | 14 |
|
15 | 15 | import os
|
16 | 16 | import re
|
| 17 | +import subprocess |
| 18 | +import shlex |
17 | 19 | import sys
|
18 | 20 | import locale
|
19 | 21 | from os.path import isfile, join
|
@@ -378,48 +380,43 @@ def firmware_metrics(target, source, env):
|
378 | 380 | print(f"Error: Map file not found: {map_file}")
|
379 | 381 | print("Make sure the project is built first with 'pio run'")
|
380 | 382 | return
|
381 |
| - |
382 |
| - try: |
383 |
| - import subprocess |
384 |
| - import shlex |
385 |
| - |
386 |
| - cmd = [env.subst("$PYTHONEXE"), "-m", "esp_idf_size", "--ng"] |
387 |
| - |
388 |
| - # Parameters from platformio.ini |
389 |
| - extra_args = env.GetProjectOption("custom_esp_idf_size_args", "") |
390 |
| - if extra_args: |
391 |
| - cmd.extend(shlex.split(extra_args)) |
392 |
| - |
393 |
| - # Command Line Parameter, after -- |
394 |
| - cli_args = [] |
395 |
| - if "--" in sys.argv: |
396 |
| - dash_index = sys.argv.index("--") |
397 |
| - if dash_index + 1 < len(sys.argv): |
398 |
| - cli_args = sys.argv[dash_index + 1:] |
399 |
| - cmd.extend(cli_args) |
400 |
| - |
401 |
| - # Map-file as last argument |
402 |
| - cmd.append(map_file) |
| 383 | + |
| 384 | + cmd = [env.subst("$PYTHONEXE"), "-m", "esp_idf_size", "--ng"] |
| 385 | + |
| 386 | + # Parameters from platformio.ini |
| 387 | + extra_args = env.GetProjectOption("custom_esp_idf_size_args", "") |
| 388 | + if extra_args: |
| 389 | + cmd.extend(shlex.split(extra_args)) |
| 390 | + |
| 391 | + # Command Line Parameter, after -- |
| 392 | + cli_args = [] |
| 393 | + if "--" in sys.argv: |
| 394 | + dash_index = sys.argv.index("--") |
| 395 | + if dash_index + 1 < len(sys.argv): |
| 396 | + cli_args = sys.argv[dash_index + 1:] |
| 397 | + |
| 398 | + # Map-file as last argument |
| 399 | + cmd.append(map_file) |
403 | 400 |
|
404 |
| - # Debug-Info if wanted |
405 |
| - if env.GetProjectOption("custom_esp_idf_size_verbose", False): |
406 |
| - print(f"Running command: {' '.join(cmd)}") |
407 |
| - |
408 |
| - # Call esp-idf-size |
409 |
| - result = subprocess.run(cmd, check=False, capture_output=False) |
410 |
| - |
411 |
| - if result.returncode != 0: |
412 |
| - print(f"Warning: esp-idf-size exited with code {result.returncode}") |
| 401 | + # Debug-Info if wanted |
| 402 | + if env.GetProjectOption("custom_esp_idf_size_verbose", False): |
| 403 | + print(f"Running command: {' '.join(cmd)}") |
| 404 | + |
| 405 | + # Call esp-idf-size |
| 406 | + result = subprocess.run(cmd, check=False, capture_output=False) |
| 407 | + |
| 408 | + if result.returncode != 0: |
| 409 | + print(f"Warning: esp-idf-size exited with code {result.returncode}") |
413 | 410 |
|
414 |
| - except ImportError: |
415 |
| - print("Error: esp-idf-size module not found.") |
416 |
| - print("Install with: pip install esp-idf-size") |
417 |
| - except FileNotFoundError: |
418 |
| - print("Error: Python executable not found.") |
419 |
| - print("Check your Python installation.") |
420 |
| - except Exception as e: |
421 |
| - print(f"Error: Failed to run firmware metrics: {e}") |
422 |
| - print("Make sure esp-idf-size is installed: pip install esp-idf-size") |
| 411 | +except ImportError: |
| 412 | + print("Error: esp-idf-size module not found.") |
| 413 | + print("Install with: pip install esp-idf-size") |
| 414 | +except FileNotFoundError: |
| 415 | + print("Error: Python executable not found.") |
| 416 | + print("Check your Python installation.") |
| 417 | +except Exception as e: |
| 418 | + print(f"Error: Failed to run firmware metrics: {e}") |
| 419 | + print("Make sure esp-idf-size is installed: pip install esp-idf-size") |
423 | 420 |
|
424 | 421 | #
|
425 | 422 | # Target: Build executable and linkable firmware or FS image
|
|
0 commit comments