From 8246410c8a3fc66efd7ff8548b7e671bbb509d56 Mon Sep 17 00:00:00 2001 From: blakadder Date: Wed, 13 Sep 2023 15:06:01 +0200 Subject: [PATCH] fix compile errors on exotic windows codepages (#19508) --- lib/libesp32/berry/tools/coc/block_builder.py | 2 +- lib/libesp32/berry/tools/coc/coc | 2 +- lib/libesp32/berry/tools/coc/macro_table.py | 2 +- lib/libesp32_lvgl/lv_binding_berry/tools/preprocessor.py | 6 +++--- pio-tools/metrics-firmware.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/libesp32/berry/tools/coc/block_builder.py b/lib/libesp32/berry/tools/coc/block_builder.py index 2d76465df..6535fd40b 100644 --- a/lib/libesp32/berry/tools/coc/block_builder.py +++ b/lib/libesp32/berry/tools/coc/block_builder.py @@ -159,7 +159,7 @@ class block_builder: def writefile(self, filename, text): otext = "#include \"be_constobj.h\"\n\n" + text - with open(filename, "w") as f: + with open(filename, "w", encoding='utf-8') as f: f.write(otext) def dumpfile(self, path): diff --git a/lib/libesp32/berry/tools/coc/coc b/lib/libesp32/berry/tools/coc/coc index 2111b1ea2..1a12c01e6 100755 --- a/lib/libesp32/berry/tools/coc/coc +++ b/lib/libesp32/berry/tools/coc/coc @@ -34,7 +34,7 @@ class builder: if re.search(r"\.(h|c|cc|cpp)$", filename): # print(f"> parse {filename}") text = "" - with open(filename) as f: + with open(filename, encoding='utf-8') as f: text = f.read() # print(f"> len(text)={len(text)}") parser = coc_parser(text) diff --git a/lib/libesp32/berry/tools/coc/macro_table.py b/lib/libesp32/berry/tools/coc/macro_table.py index 8b4518ddc..de741040e 100644 --- a/lib/libesp32/berry/tools/coc/macro_table.py +++ b/lib/libesp32/berry/tools/coc/macro_table.py @@ -22,7 +22,7 @@ class macro_table: def scan_file(self, filename): str = "" - with open(filename) as f: + with open(filename, encoding='utf-8') as f: str = f.read() r = macro_table.pat.findall(str) for it in r: diff --git a/lib/libesp32_lvgl/lv_binding_berry/tools/preprocessor.py b/lib/libesp32_lvgl/lv_binding_berry/tools/preprocessor.py index f71335eb9..c829c484b 100644 --- a/lib/libesp32_lvgl/lv_binding_berry/tools/preprocessor.py +++ b/lib/libesp32_lvgl/lv_binding_berry/tools/preprocessor.py @@ -86,7 +86,7 @@ headers_names += list_files("../../LVGL_assets/src/", ["lv_theme_haspmota.h"]) # headers_names = [ '../../lib/libesp32_lvgl/LVGL/src/lv_api_map.h' ] output_filename = "../mapping/lv_funcs.h" -sys.stdout = open(output_filename, 'w') +sys.stdout = open(output_filename, 'w', encoding='utf-8') print(""" // Automatically generated from LVGL source with `python3 preprocessor.py` @@ -121,7 +121,7 @@ lv_coord_t lv_get_ver_res(void); """) for header_name in headers_names: - with open(header_name) as f: + with open(header_name, encoding='utf-8') as f: print("// " + header_name) raw = clean_source(f.read()) @@ -198,7 +198,7 @@ lv_fun_globs = [ headers_names = list_files(lv_src_prefix, lv_fun_globs) output_filename = "../mapping/lv_enum.h" -sys.stdout = open(output_filename, 'w') +sys.stdout = open(output_filename, 'w', encoding='utf-8') print("""// ====================================================================== // Functions // ====================================================================== diff --git a/pio-tools/metrics-firmware.py b/pio-tools/metrics-firmware.py index 623256245..2d7cae427 100644 --- a/pio-tools/metrics-firmware.py +++ b/pio-tools/metrics-firmware.py @@ -10,7 +10,7 @@ def firm_metrics(source, target, env): env.Execute("$PYTHONEXE -m tasmota_metrics \"" + str(tasmotapiolib.get_source_map_path(env).resolve()) + "\"") elif env["PIOPLATFORM"] == "espressif8266": map_file = join(env.subst("$BUILD_DIR")) + os.sep + "firmware.map" - with open(map_file,'r') as f: + with open(map_file,'r', encoding='utf-8') as f: phrase = "_text_end = ABSOLUTE (.)" for line in f: if phrase in line: