-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_dependencies.py
More file actions
55 lines (38 loc) · 1.66 KB
/
make_dependencies.py
File metadata and controls
55 lines (38 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import subprocess
from pathlib import Path
def get_file_dependencies(file_path):
result = []
cmd = ['cl', '/nologo', '/Zs', '-Iinclude', '/showIncludes', '/DUSE_ST6', file_path]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
for line in proc.stdout:
line = line.strip()
if not line.startswith("Note: including file:"):
continue
stripped_line = line.removeprefix("Note: including file:").lstrip()
abs_path = os.path.join(os.getcwd(), stripped_line)
if (Path(os.getcwd()) in Path(abs_path).parents):
result.append(abs_path)
return result
def write_file_dependencies(deps_file, src_dirs, obj_dir):
f = open(deps_file, "w")
for src_dir in src_dirs:
for file_name in os.listdir(src_dir):
if os.path.splitext(file_name)[1] != ".cpp":
continue
deps = get_file_dependencies(os.path.join(src_dir, file_name))
obj_file = os.path.join(obj_dir, Path(file_name).stem + ".obj")
cpp_file = os.path.join(src_dir, file_name)
f.write(obj_file + ":\\\n")
#f.write((" " * 4) + cpp_file + " \\\n")
for i, dep in enumerate(deps):
newline_escape = "" if i == len(deps) - 1 else "\\"
f.write((" " * 4) + os.path.relpath(dep) + newline_escape + "\n")
#f.write((" " * 4) + deps_file + " \\\n")
#f.write((" " * 4) + "makefile\n")
f.write("\n")
f.close()
def run():
write_file_dependencies(deps_file='makefile.deps', src_dirs=['src', 'test'], obj_dir='obj')
if __name__ == "__main__":
run()