build: tolerate legacy source encodings

This commit is contained in:
mrxiaocheng4519 2026-08-07 15:14:53 +08:00
parent 27b3e2883d
commit 224b261537

View file

@ -44,8 +44,8 @@ def process_component_test(source_directory):
for root, dirs, files in chain.from_iterable(os.walk(path.strip()) for path in \ for root, dirs, files in chain.from_iterable(os.walk(path.strip()) for path in \
re.findall(location, config_mk_str)[0].split(":= ")[1:]): re.findall(location, config_mk_str)[0].split(":= ")[1:]):
for source in [source for source in files if source.endswith(".c")]: for source in [source for source in files if source.endswith(".c")]:
with open(os.path.join(root, source), "r") as head: with open(os.path.join(root, source), "rb") as head:
codes = head.read() codes = head.read().decode("utf-8", errors="ignore")
# find AOS_TESTCASE macro function # find AOS_TESTCASE macro function
for code in re.findall("AOS_TESTCASE\s*\((.+\)\s*;)", codes): for code in re.findall("AOS_TESTCASE\s*\((.+\)\s*;)", codes):
code_list.append(code[:len(code)-2]) code_list.append(code[:len(code)-2])
@ -94,8 +94,8 @@ def process_component_init(init_dir):
for root, dirs, files in chain.from_iterable(os.walk(path.strip()) for path in \ for root, dirs, files in chain.from_iterable(os.walk(path.strip()) for path in \
re.findall("AOS_SDK_INCLUDES\s+\+\=\s+(.+\n)", config_mk_str)[0].split("-I")[1:]): re.findall("AOS_SDK_INCLUDES\s+\+\=\s+(.+\n)", config_mk_str)[0].split("-I")[1:]):
for include in [include for include in files if include.endswith(".h")]: for include in [include for include in files if include.endswith(".h")]:
with open(os.path.join(root, include), "r") as head: with open(os.path.join(root, include), "rb") as head:
code = head.read() code = head.read().decode("utf-8", errors="ignore")
# find AOS_COMPONENT_INIT macro function # find AOS_COMPONENT_INIT macro function
for init in re.findall("AOS_COMPONENT_INIT\s*\((.+\)\s*;)", code): for init in re.findall("AOS_COMPONENT_INIT\s*\((.+\)\s*;)", code):
init_code = init.replace(',', '(', 1) init_code = init.replace(',', '(', 1)
@ -125,4 +125,3 @@ if __name__ == "__main__":
main() main()