forked from llvm/llvm-project
- Notifications
You must be signed in to change notification settings - Fork 339
/
Copy pathmodule-deps-to-rsp.py
executable file
·88 lines (68 loc) · 2.26 KB
/
module-deps-to-rsp.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
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
# Converts clang-scan-deps output into response files.
#
# Usage:
#
# clang-scan-deps -compilation-database compile_commands.json ... > deps.json
# module-deps-to-rsp.py deps.json --module-name=ModuleName > module_name.cc1.rsp
# module-deps-to-rsp.py deps.json --tu-index=0 > tu.rsp
# clang @module_name.cc1.rsp
# clang @tu.rsp
importargparse
importjson
importsys
classModuleNotFoundError(Exception):
def__init__(self, module_name):
self.module_name=module_name
classFullDeps:
def__init__(self):
self.modules= {}
self.translation_units= []
deffindModule(module_name, full_deps):
forminfull_deps.modules.values():
ifm["name"] ==module_name:
returnm
raiseModuleNotFoundError(module_name)
defparseFullDeps(json):
ret=FullDeps()
forminjson["modules"]:
ret.modules[m["name"] +"-"+m["context-hash"]] =m
ret.translation_units=json["translation-units"]
returnret
defquote(str):
return'"'+str.replace("\\", "\\\\") +'"'
defmain():
parser=argparse.ArgumentParser()
parser.add_argument(
"full_deps_file", help="Path to the full dependencies json file", type=str
)
action=parser.add_mutually_exclusive_group(required=True)
action.add_argument(
"--module-name", help="The name of the module to get arguments for", type=str
)
action.add_argument(
"--tu-index",
help="The index of the translation unit to get arguments for",
type=int,
)
parser.add_argument(
"--tu-cmd-index",
help="The index of the command within the translation unit (default=0)",
type=int,
default=0,
)
args=parser.parse_args()
full_deps=parseFullDeps(json.load(open(args.full_deps_file, "r")))
try:
cmd= []
ifargs.module_name:
cmd=findModule(args.module_name, full_deps)["command-line"]
elifargs.tu_indexisnotNone:
tu=full_deps.translation_units[args.tu_index]
cmd=tu["commands"][args.tu_cmd_index]["command-line"]
print(" ".join(map(quote, cmd)))
except:
print("Unexpected error:", sys.exc_info()[0])
raise
if__name__=="__main__":
main()