mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Fix utf-8 encoding (#8565)
* Fix utf-8 encoding
Issue posted to commit
d1d4212e8b (r73517358)
* Added python source code encoding
* for touch operations open/create file in binary mode
This commit is contained in:
parent
33afdc2723
commit
5311c0d20a
@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# This script manages the use of a file with a unique name, like
|
# This script manages the use of a file with a unique name, like
|
||||||
# `Sketch.ino.globals.h`, in the Sketch source directory to provide compiler
|
# `Sketch.ino.globals.h`, in the Sketch source directory to provide compiler
|
||||||
@ -290,7 +291,7 @@ def copy_create_build_file(source_fqfn, build_target_fqfn):
|
|||||||
else:
|
else:
|
||||||
# Place holder - Must have an empty file to satisfy parameter list
|
# Place holder - Must have an empty file to satisfy parameter list
|
||||||
# specifications in platform.txt.
|
# specifications in platform.txt.
|
||||||
with open(build_target_fqfn, 'w'):
|
with open(build_target_fqfn, 'w', encoding="utf-8"):
|
||||||
pass
|
pass
|
||||||
return True # file changed
|
return True # file changed
|
||||||
|
|
||||||
@ -298,10 +299,10 @@ def copy_create_build_file(source_fqfn, build_target_fqfn):
|
|||||||
def add_include_line(build_opt_fqfn, include_fqfn):
|
def add_include_line(build_opt_fqfn, include_fqfn):
|
||||||
if not os.path.exists(include_fqfn):
|
if not os.path.exists(include_fqfn):
|
||||||
# If file is missing, we need an place holder
|
# If file is missing, we need an place holder
|
||||||
with open(include_fqfn, 'w'):
|
with open(include_fqfn, 'w', encoding="utf-8"):
|
||||||
pass
|
pass
|
||||||
print("add_include_line: Created " + include_fqfn)
|
print("add_include_line: Created " + include_fqfn)
|
||||||
with open(build_opt_fqfn, 'a') as build_opt:
|
with open(build_opt_fqfn, 'a', encoding="utf-8") as build_opt:
|
||||||
build_opt.write('-include "' + include_fqfn.replace('\\', '\\\\') + '"\n')
|
build_opt.write('-include "' + include_fqfn.replace('\\', '\\\\') + '"\n')
|
||||||
|
|
||||||
|
|
||||||
@ -313,7 +314,7 @@ def extract_create_build_opt_file(globals_h_fqfn, file_name, build_opt_fqfn):
|
|||||||
"""
|
"""
|
||||||
global build_opt_signature
|
global build_opt_signature
|
||||||
|
|
||||||
build_opt = open(build_opt_fqfn, 'w')
|
build_opt = open(build_opt_fqfn, 'w', encoding="utf-8")
|
||||||
if not os.path.exists(globals_h_fqfn) or (0 == os.path.getsize(globals_h_fqfn)):
|
if not os.path.exists(globals_h_fqfn) or (0 == os.path.getsize(globals_h_fqfn)):
|
||||||
build_opt.close()
|
build_opt.close()
|
||||||
return False
|
return False
|
||||||
@ -324,7 +325,7 @@ def extract_create_build_opt_file(globals_h_fqfn, file_name, build_opt_fqfn):
|
|||||||
# If the source sketch did not have the file Sketch.ino.globals.h, an empty
|
# If the source sketch did not have the file Sketch.ino.globals.h, an empty
|
||||||
# file was created in the ./core/ folder.
|
# file was created in the ./core/ folder.
|
||||||
# By using the copy, open will always succeed.
|
# By using the copy, open will always succeed.
|
||||||
with open(globals_h_fqfn, 'r') as src:
|
with open(globals_h_fqfn, 'r', encoding="utf-8") as src:
|
||||||
for line in src:
|
for line in src:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
line_no += 1
|
line_no += 1
|
||||||
@ -389,7 +390,7 @@ def enable_override(enable, commonhfile_fqfn):
|
|||||||
return
|
return
|
||||||
elif not enable:
|
elif not enable:
|
||||||
return
|
return
|
||||||
with open(commonhfile_fqfn, 'w') as file:
|
with open(commonhfile_fqfn, 'w', encoding="utf-8") as file:
|
||||||
if enable:
|
if enable:
|
||||||
file.write("//Override aggressive caching\n")
|
file.write("//Override aggressive caching\n")
|
||||||
# enable workaround when getsize(commonhfile_fqfn) is non-zero, disabled when zero
|
# enable workaround when getsize(commonhfile_fqfn) is non-zero, disabled when zero
|
||||||
@ -481,7 +482,7 @@ def get_preferences_txt(file_fqfn, key):
|
|||||||
# Get Key Value, key is allowed to be missing.
|
# Get Key Value, key is allowed to be missing.
|
||||||
# We assume file file_fqfn exists
|
# We assume file file_fqfn exists
|
||||||
basename = os.path.basename(file_fqfn)
|
basename = os.path.basename(file_fqfn)
|
||||||
with open(file_fqfn) as file:
|
with open(file_fqfn, encoding="utf-8") as file:
|
||||||
for line in file:
|
for line in file:
|
||||||
name, value = line.partition("=")[::2]
|
name, value = line.partition("=")[::2]
|
||||||
if name.strip().lower() == key:
|
if name.strip().lower() == key:
|
||||||
@ -527,16 +528,16 @@ def check_preferences_txt(runtime_ide_path, preferences_file):
|
|||||||
|
|
||||||
|
|
||||||
def touch(fname, times=None):
|
def touch(fname, times=None):
|
||||||
with open(fname, "a") as file:
|
with open(fname, "ab") as file:
|
||||||
os.utime(file.fileno(), times)
|
os.utime(file.fileno(), times)
|
||||||
|
|
||||||
def synchronous_touch(globals_h_fqfn, commonhfile_fqfn):
|
def synchronous_touch(globals_h_fqfn, commonhfile_fqfn):
|
||||||
global debug_enabled
|
global debug_enabled
|
||||||
# touch both files with the same timestamp
|
# touch both files with the same timestamp
|
||||||
touch(globals_h_fqfn)
|
touch(globals_h_fqfn)
|
||||||
with open(globals_h_fqfn, 'r') as file:
|
with open(globals_h_fqfn, "rb") as file:
|
||||||
ts = os.stat(file.fileno())
|
ts = os.stat(file.fileno())
|
||||||
with open(commonhfile_fqfn, 'a') as file2:
|
with open(commonhfile_fqfn, "ab") as file2:
|
||||||
os.utime(file2.fileno(), ns=(ts.st_atime_ns, ts.st_mtime_ns))
|
os.utime(file2.fileno(), ns=(ts.st_atime_ns, ts.st_mtime_ns))
|
||||||
|
|
||||||
if debug_enabled:
|
if debug_enabled:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user