Debian Codegraph @

crt/aws-c-common/verification/cbmc/proofs/scripts/fixup_makefiles.py

raw symbols SCIP
1 #!/usr/bin/env python3
2
3 import re
4 import sys
5 import pathlib
6
7
8 def replace(makefile, included):
9 if included == "../Makefile.common":
10 return "../../Makefile.common"
11 if included == "../Makefile.aws_array_list":
12 return "../../aws_array_list/Makefile"
13 if included == "../Makefile.aws_string":
14 return "../../aws_string/Makefile"
15 if included == "../Makefile.aws_byte_buf":
16 return "../../aws_byte_buf/Makefile"
17 if included == "../Makefile.aws_linked_list":
18 return "../../aws_linked_list/Makefile"
19 if included == "../Makefile.aws_hash_table":
20 return "../../aws_hash_table/Makefile"
21 if included == "../Makefile.aws_priority_queue_sift":
22 return "../../aws_priority_queue_sift/Makefile"
23 return None
24
25 ok = True
26
27 pat = re.compile("include\s+(?P<path>[-/.\w]+)")
28 for fyle in pathlib.Path(".").rglob("Makefile"):
29 this_ok = True
30 buf = []
31 with open(fyle) as handle:
32 for line in handle:
33 line = line.rstrip()
34 m = pat.match(line)
35 if not m:
36 buf.append(line)
37 continue
38 included = fyle.parent / m["path"]
39 if included.exists():
40 buf.append(line)
41 else:
42 rep = replace(fyle, m["path"])
43 if rep and (fyle.parent / rep).exists():
44 buf.append(f"include {rep}")
45 else:
46 print(f"{fyle}: {line}", file=sys.stderr)
47 ok = False
48 if this_ok:
49 with open(fyle, "w") as handle:
50 print("\n".join(buf), file=handle)
51
52 if not ok:
53 sys.exit(1)