Skip to content

Commit 5311c0d

Browse files
authored
Fix utf-8 encoding (#8565)
* Fix utf-8 encoding Issue posted to commit d1d4212#r73517358 * Added python source code encoding * for touch operations open/create file in binary mode
1 parent 33afdc2 commit 5311c0d

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

tools/mkbuildoptglobals.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
23

34
# This script manages the use of a file with a unique name, like
45
# `Sketch.ino.globals.h`, in the Sketch source directory to provide compiler
@@ -290,18 +291,18 @@ def copy_create_build_file(source_fqfn, build_target_fqfn):
290291
else:
291292
# Place holder - Must have an empty file to satisfy parameter list
292293
# specifications in platform.txt.
293-
with open(build_target_fqfn, 'w'):
294+
with open(build_target_fqfn, 'w', encoding="utf-8"):
294295
pass
295296
return True # file changed
296297

297298

298299
def add_include_line(build_opt_fqfn, include_fqfn):
299300
if not os.path.exists(include_fqfn):
300301
# If file is missing, we need an place holder
301-
with open(include_fqfn, 'w'):
302+
with open(include_fqfn, 'w', encoding="utf-8"):
302303
pass
303304
print("add_include_line: Created " + include_fqfn)
304-
with open(build_opt_fqfn, 'a') as build_opt:
305+
with open(build_opt_fqfn, 'a', encoding="utf-8") as build_opt:
305306
build_opt.write('-include "' + include_fqfn.replace('\\', '\\\\') + '"\n')
306307

307308

@@ -313,7 +314,7 @@ def extract_create_build_opt_file(globals_h_fqfn, file_name, build_opt_fqfn):
313314
"""
314315
global build_opt_signature
315316

316-
build_opt = open(build_opt_fqfn, 'w')
317+
build_opt = open(build_opt_fqfn, 'w', encoding="utf-8")
317318
if not os.path.exists(globals_h_fqfn) or (0 == os.path.getsize(globals_h_fqfn)):
318319
build_opt.close()
319320
return False
@@ -324,7 +325,7 @@ def extract_create_build_opt_file(globals_h_fqfn, file_name, build_opt_fqfn):
324325
# If the source sketch did not have the file Sketch.ino.globals.h, an empty
325326
# file was created in the ./core/ folder.
326327
# By using the copy, open will always succeed.
327-
with open(globals_h_fqfn, 'r') as src:
328+
with open(globals_h_fqfn, 'r', encoding="utf-8") as src:
328329
for line in src:
329330
line = line.strip()
330331
line_no += 1
@@ -389,7 +390,7 @@ def enable_override(enable, commonhfile_fqfn):
389390
return
390391
elif not enable:
391392
return
392-
with open(commonhfile_fqfn, 'w') as file:
393+
with open(commonhfile_fqfn, 'w', encoding="utf-8") as file:
393394
if enable:
394395
file.write("//Override aggressive caching\n")
395396
# enable workaround when getsize(commonhfile_fqfn) is non-zero, disabled when zero
@@ -481,7 +482,7 @@ def get_preferences_txt(file_fqfn, key):
481482
# Get Key Value, key is allowed to be missing.
482483
# We assume file file_fqfn exists
483484
basename = os.path.basename(file_fqfn)
484-
with open(file_fqfn) as file:
485+
with open(file_fqfn, encoding="utf-8") as file:
485486
for line in file:
486487
name, value = line.partition("=")[::2]
487488
if name.strip().lower() == key:
@@ -527,16 +528,16 @@ def check_preferences_txt(runtime_ide_path, preferences_file):
527528

528529

529530
def touch(fname, times=None):
530-
with open(fname, "a") as file:
531+
with open(fname, "ab") as file:
531532
os.utime(file.fileno(), times)
532533

533534
def synchronous_touch(globals_h_fqfn, commonhfile_fqfn):
534535
global debug_enabled
535536
# touch both files with the same timestamp
536537
touch(globals_h_fqfn)
537-
with open(globals_h_fqfn, 'r') as file:
538+
with open(globals_h_fqfn, "rb") as file:
538539
ts = os.stat(file.fileno())
539-
with open(commonhfile_fqfn, 'a') as file2:
540+
with open(commonhfile_fqfn, "ab") as file2:
540541
os.utime(file2.fileno(), ns=(ts.st_atime_ns, ts.st_mtime_ns))
541542

542543
if debug_enabled:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy