Nearly match CARAMManager

Former-commit-id: e70cf7d4b3c97c15deaac6e0af4051476d301f39
This commit is contained in:
2023-10-12 04:10:49 -07:00
parent 5e47494749
commit 9843b74547
6 changed files with 272 additions and 27 deletions

View File

@@ -17,7 +17,10 @@ import re
script_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = os.path.abspath(os.path.join(script_dir, ".."))
src_dir = os.path.join(root_dir, "src")
include_dir = os.path.join(root_dir, "include")
include_dirs = [
os.path.join(root_dir, "include"),
os.path.join(root_dir, "libc"),
]
include_pattern = re.compile(r'^#include\s*[<"](.+?)[>"]$')
guard_pattern = re.compile(r'^#ifndef\s+(.*)$')
@@ -26,14 +29,15 @@ defines = set()
def import_h_file(in_file: str, r_path: str) -> str:
rel_path = os.path.join(root_dir, r_path, in_file)
inc_path = os.path.join(include_dir, in_file)
if os.path.exists(rel_path):
return import_c_file(rel_path)
elif os.path.exists(inc_path):
return import_c_file(inc_path)
return import_c_file(rel_path)
for include_dir in include_dirs:
inc_path = os.path.join(include_dir, in_file)
if os.path.exists(inc_path):
return import_c_file(inc_path)
else:
print("Failed to locate", in_file)
exit(1)
print("Failed to locate", in_file)
return ""
def import_c_file(in_file) -> str:
in_file = os.path.relpath(in_file, root_dir)
@@ -84,4 +88,4 @@ def main():
if __name__ == "__main__":
main()
main()