Skip to content

Commit 4933fa8

Browse files
[Buildsystem] Fix encoding when reading files
1 parent 99ff024 commit 4933fa8

10 files changed

+24
-24
lines changed

core/input/input_builders.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def make_default_controller_mappings(target, source, env):
1313
# ensure mappings have a consistent order
1414
platform_mappings: dict = OrderedDict()
1515
for src_path in source:
16-
with open(str(src_path), "r") as f:
16+
with open(str(src_path), "r", encoding="utf-8") as f:
1717
# read mapping file and skip header
1818
mapping_file_lines = f.readlines()[2:]
1919

gles3_builders.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self):
3131

3232

3333
def include_file_in_gles3_header(filename: str, header_data: GLES3HeaderStruct, depth: int):
34-
with open(filename, "r") as fs:
34+
with open(filename, "r", encoding="utf-8") as fs:
3535
line = fs.readline()
3636

3737
while line:

glsl_builders.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self):
3838

3939

4040
def include_file_in_rd_header(filename: str, header_data: RDHeaderStruct, depth: int) -> RDHeaderStruct:
41-
with open(filename, "r") as fs:
41+
with open(filename, "r", encoding="utf-8") as fs:
4242
line = fs.readline()
4343

4444
while line:
@@ -172,7 +172,7 @@ def __init__(self):
172172

173173

174174
def include_file_in_raw_header(filename: str, header_data: RAWHeaderStruct, depth: int) -> None:
175-
with open(filename, "r") as fs:
175+
with open(filename, "r", encoding="utf-8") as fs:
176176
line = fs.readline()
177177

178178
while line:

methods.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def get_version_info(module_version_string="", silent=False):
179179
gitfolder = ".git"
180180

181181
if os.path.isfile(".git"):
182-
with open(".git", "r") as file:
182+
with open(".git", "r", encoding="utf-8") as file:
183183
module_folder = file.readline().strip()
184184
if module_folder.startswith("gitdir: "):
185185
gitfolder = module_folder[8:]
@@ -196,12 +196,12 @@ def get_version_info(module_version_string="", silent=False):
196196
head = os.path.join(gitfolder, ref)
197197
packedrefs = os.path.join(gitfolder, "packed-refs")
198198
if os.path.isfile(head):
199-
with open(head, "r") as file:
199+
with open(head, "r", encoding="utf-8") as file:
200200
githash = file.readline().strip()
201201
elif os.path.isfile(packedrefs):
202202
# Git may pack refs into a single file. This code searches .git/packed-refs file for the current ref's hash.
203203
# https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-pack-refs.html
204-
for line in open(packedrefs, "r").read().splitlines():
204+
for line in open(packedrefs, "r", encoding="utf-8").read().splitlines():
205205
if line.startswith("#"):
206206
continue
207207
(line_hash, line_ref) = line.split(" ")
@@ -270,7 +270,7 @@ def generate_version_header(module_version_string=""):
270270

271271

272272
def parse_cg_file(fname, uniforms, sizes, conditionals):
273-
with open(fname, "r") as fs:
273+
with open(fname, "r", encoding="utf-8") as fs:
274274
line = fs.readline()
275275

276276
while line:
@@ -1243,7 +1243,7 @@ def format_key_value(v):
12431243
).hexdigest()
12441244

12451245
if os.path.exists(f"{project_name}.vcxproj.filters"):
1246-
with open(f"{project_name}.vcxproj.filters", "r") as file:
1246+
with open(f"{project_name}.vcxproj.filters", "r", encoding="utf-8") as file:
12471247
existing_filters = file.read()
12481248
match = re.search(r"(?ms)^<!-- CHECKSUM$.([0-9a-f]{32})", existing_filters)
12491249
if match is not None and md5 == match.group(1):
@@ -1255,7 +1255,7 @@ def format_key_value(v):
12551255
if not skip_filters:
12561256
print(f"Regenerating {project_name}.vcxproj.filters")
12571257

1258-
with open("misc/msvs/vcxproj.filters.template", "r") as file:
1258+
with open("misc/msvs/vcxproj.filters.template", "r", encoding="utf-8") as file:
12591259
filters_template = file.read()
12601260
for i in range(1, 10):
12611261
filters_template = filters_template.replace(f"%%UUID{i}%%", str(uuid.uuid4()))
@@ -1409,7 +1409,7 @@ def format_key_value(v):
14091409
)
14101410
output = f'bin\\godot{env["PROGSUFFIX"]}'
14111411

1412-
with open("misc/msvs/props.template", "r") as file:
1412+
with open("misc/msvs/props.template", "r", encoding="utf-8") as file:
14131413
props_template = file.read()
14141414

14151415
props_template = props_template.replace("%%VSCONF%%", vsconf)
@@ -1478,7 +1478,7 @@ def format_key_value(v):
14781478
sln_uuid = str(uuid.uuid4())
14791479

14801480
if os.path.exists(f"{project_name}.sln"):
1481-
for line in open(f"{project_name}.sln", "r").read().splitlines():
1481+
for line in open(f"{project_name}.sln", "r", encoding="utf-8").read().splitlines():
14821482
if line.startswith('Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}")'):
14831483
proj_uuid = re.search(
14841484
r"\"{(\b[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-\b[0-9a-fA-F]{12}\b)}\"$",
@@ -1567,7 +1567,7 @@ def format_key_value(v):
15671567
section2 = sorted(section2)
15681568

15691569
if not get_bool(original_args, "vsproj_props_only", False):
1570-
with open("misc/msvs/vcxproj.template", "r") as file:
1570+
with open("misc/msvs/vcxproj.template", "r", encoding="utf-8") as file:
15711571
proj_template = file.read()
15721572
proj_template = proj_template.replace("%%UUID%%", proj_uuid)
15731573
proj_template = proj_template.replace("%%CONFS%%", "\n ".join(configurations))
@@ -1579,7 +1579,7 @@ def format_key_value(v):
15791579
f.write(proj_template)
15801580

15811581
if not get_bool(original_args, "vsproj_props_only", False):
1582-
with open("misc/msvs/sln.template", "r") as file:
1582+
with open("misc/msvs/sln.template", "r", encoding="utf-8") as file:
15831583
sln_template = file.read()
15841584
sln_template = sln_template.replace("%%NAME%%", project_name)
15851585
sln_template = sln_template.replace("%%UUID%%", proj_uuid)

misc/scripts/check_ci_log.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
fname = sys.argv[1]
1111

12-
with open(fname.strip(), "r") as fileread:
12+
with open(fname.strip(), "r", encoding="utf-8") as fileread:
1313
file_contents = fileread.read()
1414

1515
# If find "ERROR: AddressSanitizer:", then happens invalid read or write

misc/scripts/copyright_headers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
# In a second pass, we skip all consecutive comment lines starting with "/*",
7070
# then we can append the rest (step 2).
7171

72-
with open(fname.strip(), "r") as fileread:
72+
with open(fname.strip(), "r", encoding="utf-8") as fileread:
7373
line = fileread.readline()
7474
header_done = False
7575

modules/raycast/godot_update_embree.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
)
188188

189189

190-
with open("CMakeLists.txt", "r") as cmake_file:
190+
with open("CMakeLists.txt", "r", encoding="utf-8") as cmake_file:
191191
cmake_content = cmake_file.read()
192192
major_version = int(re.compile(r"EMBREE_VERSION_MAJOR\s(\d+)").findall(cmake_content)[0])
193193
minor_version = int(re.compile(r"EMBREE_VERSION_MINOR\s(\d+)").findall(cmake_content)[0])

tests/create_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def main():
101101

102102
if args.invasive:
103103
print("Trying to insert include directive in test_main.cpp...")
104-
with open("test_main.cpp", "r") as file:
104+
with open("test_main.cpp", "r", encoding="utf-8") as file:
105105
contents = file.read()
106106
match = re.search(r'#include "tests.*\n', contents)
107107

tests/python_build/test_gles3_builder.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ def test_gles3_builder(shader_files, builder, header_struct):
1717

1818
builder(shader_files["path_input"], "drivers/gles3/shader_gles3.h", "GLES3", header_data=header)
1919

20-
with open(shader_files["path_expected_parts"], "r") as f:
20+
with open(shader_files["path_expected_parts"], "r", encoding="utf-8") as f:
2121
expected_parts = json.load(f)
2222
assert expected_parts == header.__dict__
2323

24-
with open(shader_files["path_output"], "r") as f:
24+
with open(shader_files["path_output"], "r", encoding="utf-8") as f:
2525
actual_output = f.read()
2626
assert actual_output
2727

28-
with open(shader_files["path_expected_full"], "r") as f:
28+
with open(shader_files["path_expected_full"], "r", encoding="utf-8") as f:
2929
expected_output = f.read()
3030

3131
assert actual_output == expected_output

tests/python_build/test_glsl_builder.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ def test_glsl_builder(shader_files, builder, header_struct):
2323
header = header_struct()
2424
builder(shader_files["path_input"], header_data=header)
2525

26-
with open(shader_files["path_expected_parts"], "r") as f:
26+
with open(shader_files["path_expected_parts"], "r", encoding="utf-8") as f:
2727
expected_parts = json.load(f)
2828
assert expected_parts == header.__dict__
2929

30-
with open(shader_files["path_output"], "r") as f:
30+
with open(shader_files["path_output"], "r", encoding="utf-8") as f:
3131
actual_output = f.read()
3232
assert actual_output
3333

34-
with open(shader_files["path_expected_full"], "r") as f:
34+
with open(shader_files["path_expected_full"], "r", encoding="utf-8") as f:
3535
expected_output = f.read()
3636

3737
assert actual_output == expected_output

0 commit comments

Comments
 (0)