Skip to content

Commit 92697cf

Browse files
authored
better check for codepage utf-8 in terminal
1 parent b3d6614 commit 92697cf

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

builder/main.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import os
1616
import re
17-
import sys
17+
import locale
1818
from os.path import isfile, join
1919

2020
from SCons.Script import (
@@ -28,7 +28,7 @@
2828
env = DefaultEnvironment()
2929
platform = env.PioPlatform()
3030
projectconfig = env.GetProjectConfig()
31-
IS_WINDOWS = sys.platform.startswith("win")
31+
terminal_cp = locale.getpreferredencoding().lower()
3232

3333
#
3434
# Helpers
@@ -360,6 +360,9 @@ def check_lib_archive_exists():
360360

361361

362362
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
363366
map_file = os.path.join(env.subst("$BUILD_DIR"), env.subst("$PROGNAME") + ".map")
364367
if not os.path.isfile(map_file):
365368
# map file can be in project dir
@@ -371,6 +374,7 @@ def firmware_metrics(target, source, env):
371374
python_exe = env.subst("$PYTHONEXE")
372375
run_env = os.environ.copy()
373376
run_env["PYTHONIOENCODING"] = "utf-8"
377+
run_env["PYTHONUTF8"] = "1"
374378
# Show output of esp_idf_size, but suppresses the command echo
375379
subprocess.run([
376380
python_exe, "-m", "esp_idf_size", "--ng", map_file
@@ -393,11 +397,9 @@ def firmware_metrics(target, source, env):
393397
target_firm = join("$BUILD_DIR", "${PROGNAME}.bin")
394398
else:
395399
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)
401403
if set(["buildfs", "uploadfs", "uploadfsota"]) & set(COMMAND_LINE_TARGETS):
402404
target_firm = env.DataToBin(
403405
join("$BUILD_DIR", "${ESP32_FS_IMAGE_NAME}"), "$PROJECT_DATA_DIR"
@@ -532,7 +534,6 @@ def firmware_metrics(target, source, env):
532534
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS "$SOURCE"',
533535
)
534536

535-
536537
elif upload_protocol in debug_tools:
537538
_parse_partitions(env)
538539
openocd_args = ["-d%d" % (2 if int(ARGUMENTS.get("PIOVERBOSE", 0)) else 1)]

0 commit comments

Comments
 (0)