3 # Converts clang-scan-deps output into response files.
7 # clang-scan-deps -compilation-database compile_commands.json ... > deps.json
8 # module-deps-to-rsp.py deps.json --module-name=ModuleName > module_name.cc1.rsp
9 # module-deps-to-rsp.py deps.json --tu-index=0 > tu.rsp
10 # clang @module_name.cc1.rsp
18 class ModuleNotFoundError(Exception):
19 def __init__(self
, module_name
):
20 self
.module_name
= module_name
26 self
.translation_units
= []
29 def findModule(module_name
, full_deps
):
30 for m
in full_deps
.modules
.values():
31 if m
["name"] == module_name
:
33 raise ModuleNotFoundError(module_name
)
36 def parseFullDeps(json
):
38 for m
in json
["modules"]:
39 ret
.modules
[m
["name"] + "-" + m
["context-hash"]] = m
40 ret
.translation_units
= json
["translation-units"]
45 return '"' + str.replace("\\", "\\\\") + '"'
49 parser
= argparse
.ArgumentParser()
51 "full_deps_file", help="Path to the full dependencies json file", type=str
53 action
= parser
.add_mutually_exclusive_group(required
=True)
55 "--module-name", help="The name of the module to get arguments for", type=str
59 help="The index of the translation unit to get arguments for",
64 help="The index of the command within the translation unit (default=0)",
68 args
= parser
.parse_args()
70 full_deps
= parseFullDeps(json
.load(open(args
.full_deps_file
, "r")))
76 cmd
= findModule(args
.module_name
, full_deps
)["command-line"]
77 elif args
.tu_index
is not None:
78 tu
= full_deps
.translation_units
[args
.tu_index
]
79 cmd
= tu
["commands"][args
.tu_cmd_index
]["command-line"]
81 print(" ".join(map(quote
, cmd
)))
83 print("Unexpected error:", sys
.exc_info()[0])
87 if __name__
== "__main__":