-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle_iwyu.py
executable file
·76 lines (63 loc) · 2.19 KB
/
single_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
"""Calls include-what-you-use on a kernel .c file"""
import argparse
import json
from pathlib import Path
from typing import List
from lib.utils import warn, perform_iwyu
DEBUG = False
def main(commands: Path, fixer_path: Path, filters: List[Path], specific: str):
"""Chooses a specific file to call perform_iwyu on"""
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:
eligible = [x for x in json.load(file) if specific in x["file"]]
if len(eligible) == 0:
warn("NO FILE WITH IDENTIFIER FOUND")
for part in eligible:
if not "/arch/" in part["file"]:
perform_iwyu(
fixer_path,
part,
filters + [Path(current_dir, "nonarch.imp")],
current_dir,
debug=DEBUG,
)
else:
perform_iwyu(fixer_path, part, filters, current_dir, debug=DEBUG)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="""This script attempts to automatically refactor a
include list without touching the headers themselves."""
)
parser.add_argument(
"-c",
"--commands",
type=Path,
required=True,
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(
"-s",
"--specific_command",
required=True,
help="Name of the .c file to refactor",
)
parser.add_argument(
"-fi", "--filters", nargs="*", help="List of additional filters", default=[]
)
parser.add_argument(
"-d", action="store_true", help="Debug mode on. Prints IWYU output."
)
args = parser.parse_args()
DEBUG = args.d
main(args.commands, args.fixer_path, args.filters, args.specific_command)