diff options
Diffstat (limited to 'clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp')
| -rw-r--r-- | clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp | 41 |
1 files changed, 11 insertions, 30 deletions
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp index 2fd12f7e12b1..739712baadd0 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp @@ -24,8 +24,6 @@ std::vector<std::string> FullDependencies::getAdditionalArgs( ClangModuleDeps, LookupPCMPath, LookupModuleDeps, PCMPaths, ModMapPaths); for (const std::string &PCMPath : PCMPaths) Ret.push_back("-fmodule-file=" + PCMPath); - for (const std::string &ModMapPath : ModMapPaths) - Ret.push_back("-fmodule-map-file=" + ModMapPath); return Ret; } @@ -37,10 +35,8 @@ FullDependencies::getAdditionalArgsWithoutModulePaths() const { "-fno-implicit-module-maps", }; - for (const PrebuiltModuleDep &PMD : PrebuiltModuleDeps) { - Args.push_back("-fmodule-file=" + PMD.ModuleName + "=" + PMD.PCMFile); - Args.push_back("-fmodule-map-file=" + PMD.ModuleMapFile); - } + for (const PrebuiltModuleDep &PMD : PrebuiltModuleDeps) + Args.push_back("-fmodule-file=" + PMD.PCMFile); return Args; } @@ -50,7 +46,8 @@ DependencyScanningTool::DependencyScanningTool( : Worker(Service) {} llvm::Expected<std::string> DependencyScanningTool::getDependencyFile( - const tooling::CompilationDatabase &Compilations, StringRef CWD) { + const std::vector<std::string> &CommandLine, StringRef CWD, + llvm::Optional<StringRef> ModuleName) { /// Prints out all of the gathered dependencies into a string. class MakeDependencyPrinterConsumer : public DependencyConsumer { public: @@ -102,17 +99,9 @@ llvm::Expected<std::string> DependencyScanningTool::getDependencyFile( std::vector<std::string> Dependencies; }; - // We expect a single command here because if a source file occurs multiple - // times in the original CDB, then `computeDependencies` would run the - // `DependencyScanningAction` once for every time the input occured in the - // CDB. Instead we split up the CDB into single command chunks to avoid this - // behavior. - assert(Compilations.getAllCompileCommands().size() == 1 && - "Expected a compilation database with a single command!"); - std::string Input = Compilations.getAllCompileCommands().front().Filename; - MakeDependencyPrinterConsumer Consumer; - auto Result = Worker.computeDependencies(Input, CWD, Compilations, Consumer); + auto Result = + Worker.computeDependencies(CWD, CommandLine, Consumer, ModuleName); if (Result) return std::move(Result); std::string Output; @@ -122,8 +111,9 @@ llvm::Expected<std::string> DependencyScanningTool::getDependencyFile( llvm::Expected<FullDependenciesResult> DependencyScanningTool::getFullDependencies( - const tooling::CompilationDatabase &Compilations, StringRef CWD, - const llvm::StringSet<> &AlreadySeen) { + const std::vector<std::string> &CommandLine, StringRef CWD, + const llvm::StringSet<> &AlreadySeen, + llvm::Optional<StringRef> ModuleName) { class FullDependencyPrinterConsumer : public DependencyConsumer { public: FullDependencyPrinterConsumer(const llvm::StringSet<> &AlreadySeen) @@ -180,24 +170,15 @@ DependencyScanningTool::getFullDependencies( private: std::vector<std::string> Dependencies; std::vector<PrebuiltModuleDep> PrebuiltModuleDeps; - std::unordered_map<std::string, ModuleDeps> ClangModuleDeps; + std::map<std::string, ModuleDeps> ClangModuleDeps; std::string ContextHash; std::vector<std::string> OutputPaths; const llvm::StringSet<> &AlreadySeen; }; - // We expect a single command here because if a source file occurs multiple - // times in the original CDB, then `computeDependencies` would run the - // `DependencyScanningAction` once for every time the input occured in the - // CDB. Instead we split up the CDB into single command chunks to avoid this - // behavior. - assert(Compilations.getAllCompileCommands().size() == 1 && - "Expected a compilation database with a single command!"); - std::string Input = Compilations.getAllCompileCommands().front().Filename; - FullDependencyPrinterConsumer Consumer(AlreadySeen); llvm::Error Result = - Worker.computeDependencies(Input, CWD, Compilations, Consumer); + Worker.computeDependencies(CWD, CommandLine, Consumer, ModuleName); if (Result) return std::move(Result); return Consumer.getFullDependencies(); |
