Skip to content
Merged
Prev Previous commit
Next Next commit
Use default locale encode for writing file names in build.opt
Continue using "utf-8" to read or write "C/C++" source filess.

Tested on Windows 10 (en-US) with Arduino IDE 2.0.3 Under an
account with a diacritic charcter in the user ID path.

Needs testing on Japanese Windows
  • Loading branch information
mhightower83 committed Feb 20, 2023
commit 338159ffaaf06cb0e6d92999d8bebf8584218f5a
21 changes: 17 additions & 4 deletions tools/mkbuildoptglobals.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@
import textwrap
import time

import locale

# Need to work on signature line used for match to avoid conflicts with
# existing embedded documentation methods.
build_opt_signature = "/*@create-file:build.opt@"
Expand Down Expand Up @@ -296,14 +298,22 @@ def copy_create_build_file(source_fqfn, build_target_fqfn):
pass
return True # file changed


def add_include_line(build_opt_fqfn, include_fqfn):
# Given that GCC will insert (or process as if interted) these lines into
# the command line. I assume that the contents of @file need to be encoded
# to match that of the shell running GCC runs. I am not 100% sure this API
# gives me that, but it appears to work.
#
# However, elsewhere when dealing with source code we continue to use 'utf-8',
# ref. https://gcc.gnu.org/onlinedocs/gcc-4.1.2/cpp/Character-sets.html
shell_encoding = locale.getdefaultlocale()[1]
if not os.path.exists(include_fqfn):
# If file is missing, we need an place holder
with open(include_fqfn, 'w', encoding="utf-8"):
with open(include_fqfn, 'w', encoding=shell_encoding):
pass
print("add_include_line: Created " + include_fqfn)
with open(build_opt_fqfn, 'a', encoding="utf-8") as build_opt:
print_msg("add_include_line: Created " + include_fqfn)

with open(build_opt_fqfn, 'a', encoding=shell_encoding) as build_opt:
build_opt.write('-include "' + include_fqfn.replace('\\', '\\\\') + '"\n')

def extract_create_build_opt_file(globals_h_fqfn, file_name, build_opt_fqfn):
Expand Down Expand Up @@ -611,6 +621,9 @@ def main():
global debug_enabled
num_include_lines = 1

def_locale = locale.getdefaultlocale()
print_msg(f'default locale: {def_locale}')

args = parse_args()
debug_enabled = args.debug
runtime_ide_path = os.path.normpath(args.runtime_ide_path)
Expand Down