14
14
15
15
import os
16
16
import re
17
- import sys
17
+ import locale
18
18
from os .path import isfile , join
19
19
20
20
from SCons .Script import (
28
28
env = DefaultEnvironment ()
29
29
platform = env .PioPlatform ()
30
30
projectconfig = env .GetProjectConfig ()
31
- IS_WINDOWS = sys . platform . startswith ( "win" )
31
+ terminal_cp = locale . getpreferredencoding (). lower ( )
32
32
33
33
#
34
34
# Helpers
@@ -360,6 +360,9 @@ def check_lib_archive_exists():
360
360
361
361
362
362
def firmware_metrics (target , source , env ):
363
+ if terminal_cp != "utf-8" :
364
+ print ("Firmware metrics can not be shown. Set the terminal codepage to \" utf-8\" " )
365
+ return
363
366
map_file = os .path .join (env .subst ("$BUILD_DIR" ), env .subst ("$PROGNAME" ) + ".map" )
364
367
if not os .path .isfile (map_file ):
365
368
# map file can be in project dir
@@ -371,6 +374,7 @@ def firmware_metrics(target, source, env):
371
374
python_exe = env .subst ("$PYTHONEXE" )
372
375
run_env = os .environ .copy ()
373
376
run_env ["PYTHONIOENCODING" ] = "utf-8"
377
+ run_env ["PYTHONUTF8" ] = "1"
374
378
# Show output of esp_idf_size, but suppresses the command echo
375
379
subprocess .run ([
376
380
python_exe , "-m" , "esp_idf_size" , "--ng" , map_file
@@ -393,11 +397,9 @@ def firmware_metrics(target, source, env):
393
397
target_firm = join ("$BUILD_DIR" , "${PROGNAME}.bin" )
394
398
else :
395
399
target_elf = env .BuildProgram ()
396
- # python charmap is crashing with Windows and esp-idf-size
397
- if not IS_WINDOWS :
398
- silent_action = env .Action (firmware_metrics )
399
- silent_action .strfunction = lambda target , source , env : '' # hack to silence scons command output
400
- env .AddPostAction (target_elf , silent_action )
400
+ silent_action = env .Action (firmware_metrics )
401
+ silent_action .strfunction = lambda target , source , env : '' # hack to silence scons command output
402
+ env .AddPostAction (target_elf , silent_action )
401
403
if set (["buildfs" , "uploadfs" , "uploadfsota" ]) & set (COMMAND_LINE_TARGETS ):
402
404
target_firm = env .DataToBin (
403
405
join ("$BUILD_DIR" , "${ESP32_FS_IMAGE_NAME}" ), "$PROJECT_DATA_DIR"
@@ -532,7 +534,6 @@ def firmware_metrics(target, source, env):
532
534
UPLOADCMD = '"$UPLOADER" $UPLOADERFLAGS "$SOURCE"' ,
533
535
)
534
536
535
-
536
537
elif upload_protocol in debug_tools :
537
538
_parse_partitions (env )
538
539
openocd_args = ["-d%d" % (2 if int (ARGUMENTS .get ("PIOVERBOSE" , 0 )) else 1 )]
0 commit comments