-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-iwyu.py
60 lines (52 loc) · 1.79 KB
/
auto-iwyu.py
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
56
57
58
59
60
import argparse
import json
from pathlib import Path
from lib.utils import perform_iwyu
def main(commands, fixer_path, filters):
current_dir = Path(__file__).resolve().parent
filters += [Path(current_dir, "filter.imp"), Path(current_dir, "symbol.imp")]
with open(commands, encoding="utf-8") as file:
data = json.load(file)
count = 0
skipped = False
for part in data:
count += 1
print(count, part["file"])
if not ".c" in part["file"]:
continue
if "core.c" in part["file"]:
skipped = True
continue
if not skipped:
continue
if not "arch" in part["file"] and not perform_iwyu(
fixer_path,
part,
filters + [Path(current_dir, "nonarch.imp")],
current_dir,
):
continue
elif not perform_iwyu(fixer_path, part, filters, current_dir):
return
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="""This script attempts to refactor multiple
include lists without touching the headers themselves."""
)
parser.add_argument(
"-c", "--commands", type=Path, help="Path to compile_commands.json"
)
parser.add_argument(
"-f",
"--fixer_path",
type=Path,
help="Path to the fix_includes.py",
default=Path(
Path(__file__).resolve().parent, "include-what-you-use/fix_includes.py"
),
)
parser.add_argument(
"-fi", "--filters", nargs="*", help="List of additional filters", default=[]
)
args = parser.parse_args()
main(args.commands, args.fixer_path, args.filters)