11 #include "llvm/Support/JSON.h" 13 static llvm::json::Array
toJSONSorted(
const llvm::StringSet<> &Set) {
14 std::vector<llvm::StringRef> Strings;
16 Strings.push_back(I.getKey());
17 std::sort(Strings.begin(), Strings.end());
18 return llvm::json::Array(Strings);
23 namespace dependencies{
27 : Format(Service.getFormat()), Worker(Service) {
36 StringRef File)
override {
38 this->Opts = std::make_unique<DependencyOutputOptions>(Opts);
39 Dependencies.push_back(File);
42 void handleModuleDependency(
ModuleDeps MD)
override {
48 void handleContextHash(std::string Hash)
override {}
50 void printDependencies(std::string &S) {
59 for (
const auto &Dep : Dependencies)
63 void printDependencies(std::string &S) {
64 llvm::raw_string_ostream OS(S);
65 outputDependencyFile(OS);
69 DependencyPrinter Generator(*Opts, Dependencies);
70 Generator.printDependencies(S);
74 std::unique_ptr<DependencyOutputOptions> Opts;
75 std::vector<std::string> Dependencies;
81 StringRef File)
override {
82 Dependencies.push_back(File);
85 void handleModuleDependency(
ModuleDeps MD)
override {
89 void handleContextHash(std::string Hash)
override {
90 ContextHash = std::move(Hash);
93 void printDependencies(std::string &S, StringRef MainFile) {
95 std::vector<StringRef> Modules;
96 for (
auto &&Dep : ClangModuleDeps)
97 Modules.push_back(Dep.first);
98 std::sort(Modules.begin(), Modules.end());
100 llvm::raw_string_ostream OS(S);
102 using namespace llvm::json;
105 for (
auto &&ModName : Modules) {
106 auto &MD = ClangModuleDeps[ModName];
112 for (
auto &&ModName : Modules) {
113 auto &MD = ClangModuleDeps[ModName];
120 Mods.push_back(std::move(Mod));
124 {
"input-file", MainFile},
125 {
"clang-context-hash", ContextHash},
126 {
"file-deps", Dependencies},
127 {
"clang-module-deps", std::move(Imports)},
128 {
"clang-modules", std::move(Mods)},
131 S = llvm::formatv(
"{0:2},\n",
Value(std::move(O))).str();
136 std::vector<std::string> Dependencies;
137 std::unordered_map<std::string, ModuleDeps> ClangModuleDeps;
138 std::string ContextHash;
148 "Expected a compilation database with a single command!");
152 MakeDependencyPrinterConsumer Consumer;
154 Worker.computeDependencies(Input, CWD, Compilations, Consumer);
156 return std::move(Result);
158 Consumer.printDependencies(Output);
161 FullDependencyPrinterConsumer Consumer;
163 Worker.computeDependencies(Input, CWD, Compilations, Consumer);
165 return std::move(Result);
167 Consumer.printDependencies(Output, Input);
Builds a dependency file when attached to a Preprocessor (for includes) and ASTReader (for module imp...
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
Dataflow Directional Tag Classes.