File: fixup_makefiles.py

package info (click to toggle)
aws-crt-python 0.20.4%2Bdfsg-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 72,656 kB
  • sloc: ansic: 381,805; python: 23,008; makefile: 6,251; sh: 4,536; cpp: 699; ruby: 208; java: 77; perl: 73; javascript: 46; xml: 11
file content (53 lines) | stat: -rwxr-xr-x 1,652 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python3

import re
import sys
import pathlib


def replace(makefile, included):
    if included == "../Makefile.common":
        return "../../Makefile.common"
    if included == "../Makefile.aws_array_list":
        return "../../aws_array_list/Makefile"
    if included == "../Makefile.aws_string":
        return "../../aws_string/Makefile"
    if included == "../Makefile.aws_byte_buf":
        return "../../aws_byte_buf/Makefile"
    if included == "../Makefile.aws_linked_list":
        return "../../aws_linked_list/Makefile"
    if included == "../Makefile.aws_hash_table":
        return "../../aws_hash_table/Makefile"
    if included == "../Makefile.aws_priority_queue_sift":
        return "../../aws_priority_queue_sift/Makefile"
    return None

ok = True

pat = re.compile("include\s+(?P<path>[-/.\w]+)")
for fyle in pathlib.Path(".").rglob("Makefile"):
    this_ok = True
    buf = []
    with open(fyle) as handle:
        for line in handle:
            line = line.rstrip()
            m = pat.match(line)
            if not m:
                buf.append(line)
                continue
            included = fyle.parent / m["path"]
            if included.exists():
                buf.append(line)
            else:
                rep = replace(fyle, m["path"])
                if rep and (fyle.parent / rep).exists():
                    buf.append(f"include {rep}")
                else:
                    print(f"{fyle}: {line}", file=sys.stderr)
                    ok = False
    if this_ok:
        with open(fyle, "w") as handle:
            print("\n".join(buf), file=handle)

if not ok:
    sys.exit(1)