summaryrefslogtreecommitdiffstats
path: root/clang/lib/Tooling
diff options
context:
space:
mode:
authorMichael Spencer <bigcheesegs@gmail.com>2019-12-11 16:34:31 -0800
committerMichael Spencer <bigcheesegs@gmail.com>2019-12-11 16:35:55 -0800
commit5bcd34a03ff343674c106b9a6a0406bf249b9b31 (patch)
tree97201e7167eef5151b15dd0bc6973e62f0b57604 /clang/lib/Tooling
parent56232f950d34b6c04a86ce916d456e599d77ec27 (diff)
downloadbcm5719-llvm-5bcd34a03ff343674c106b9a6a0406bf249b9b31.tar.gz
bcm5719-llvm-5bcd34a03ff343674c106b9a6a0406bf249b9b31.zip
Revert "[clang][clang-scan-deps] Aggregate the full dependency information."
This reverts commit f978ea498309adaebab8fbf1cd6e520e7e0e11f1. It broke clang-ppc64be-linux, but not sure why yet.
Diffstat (limited to 'clang/lib/Tooling')
-rw-r--r--clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp127
-rw-r--r--clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp11
-rw-r--r--clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp85
3 files changed, 80 insertions, 143 deletions
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
index 31b8346b4ef..f643c538f8f 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
@@ -8,25 +8,24 @@
#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
#include "clang/Frontend/Utils.h"
+#include "llvm/Support/JSON.h"
+
+static llvm::json::Array toJSONSorted(const llvm::StringSet<> &Set) {
+ std::vector<llvm::StringRef> Strings;
+ for (auto &&I : Set)
+ Strings.push_back(I.getKey());
+ std::sort(Strings.begin(), Strings.end());
+ return llvm::json::Array(Strings);
+}
namespace clang{
namespace tooling{
namespace dependencies{
-std::vector<std::string> FullDependencies::getAdditionalCommandLine(
- std::function<StringRef(ClangModuleDep)> LookupPCMPath,
- std::function<const ModuleDeps &(ClangModuleDep)> LookupModuleDeps) const {
- std::vector<std::string> Ret = AdditionalNonPathCommandLine;
-
- dependencies::detail::appendCommonModuleArguments(
- ClangModuleDeps, LookupPCMPath, LookupModuleDeps, Ret);
-
- return Ret;
-}
-
DependencyScanningTool::DependencyScanningTool(
DependencyScanningService &Service)
- : Worker(Service) {}
+ : Format(Service.getFormat()), Worker(Service) {
+}
llvm::Expected<std::string> DependencyScanningTool::getDependencyFile(
const tooling::CompilationDatabase &Compilations, StringRef CWD) {
@@ -76,33 +75,8 @@ 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);
- if (Result)
- return std::move(Result);
- std::string Output;
- Consumer.printDependencies(Output);
- return Output;
-}
-
-llvm::Expected<FullDependenciesResult>
-DependencyScanningTool::getFullDependencies(
- const tooling::CompilationDatabase &Compilations, StringRef CWD,
- const llvm::StringSet<> &AlreadySeen) {
class FullDependencyPrinterConsumer : public DependencyConsumer {
public:
- FullDependencyPrinterConsumer(const llvm::StringSet<> &AlreadySeen)
- : AlreadySeen(AlreadySeen) {}
-
void handleFileDependency(const DependencyOutputOptions &Opts,
StringRef File) override {
Dependencies.push_back(File);
@@ -116,41 +90,55 @@ DependencyScanningTool::getFullDependencies(
ContextHash = std::move(Hash);
}
- FullDependenciesResult getFullDependencies() const {
- FullDependencies FD;
+ void printDependencies(std::string &S, StringRef MainFile) {
+ // Sort the modules by name to get a deterministic order.
+ std::vector<StringRef> Modules;
+ for (auto &&Dep : ClangModuleDeps)
+ Modules.push_back(Dep.first);
+ std::sort(Modules.begin(), Modules.end());
- FD.ContextHash = std::move(ContextHash);
+ llvm::raw_string_ostream OS(S);
- FD.FileDeps.assign(Dependencies.begin(), Dependencies.end());
+ using namespace llvm::json;
- for (auto &&M : ClangModuleDeps) {
- auto &MD = M.second;
+ Array Imports;
+ for (auto &&ModName : Modules) {
+ auto &MD = ClangModuleDeps[ModName];
if (MD.ImportedByMainFile)
- FD.ClangModuleDeps.push_back({MD.ModuleName, ContextHash});
+ Imports.push_back(MD.ModuleName);
}
- FullDependenciesResult FDR;
-
- for (auto &&M : ClangModuleDeps) {
- // TODO: Avoid handleModuleDependency even being called for modules
- // we've already seen.
- if (AlreadySeen.count(M.first))
- continue;
- FDR.DiscoveredModules.push_back(std::move(M.second));
+ Array Mods;
+ for (auto &&ModName : Modules) {
+ auto &MD = ClangModuleDeps[ModName];
+ Object Mod{
+ {"name", MD.ModuleName},
+ {"file-deps", toJSONSorted(MD.FileDeps)},
+ {"clang-module-deps", toJSONSorted(MD.ClangModuleDeps)},
+ {"clang-modulemap-file", MD.ClangModuleMapFile},
+ };
+ Mods.push_back(std::move(Mod));
}
- FDR.FullDeps = std::move(FD);
- return FDR;
+ Object O{
+ {"input-file", MainFile},
+ {"clang-context-hash", ContextHash},
+ {"file-deps", Dependencies},
+ {"clang-module-deps", std::move(Imports)},
+ {"clang-modules", std::move(Mods)},
+ };
+
+ S = llvm::formatv("{0:2},\n", Value(std::move(O))).str();
+ return;
}
private:
std::vector<std::string> Dependencies;
std::unordered_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
@@ -159,13 +147,26 @@ DependencyScanningTool::getFullDependencies(
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);
- if (Result)
- return std::move(Result);
- return Consumer.getFullDependencies();
+
+ if (Format == ScanningOutputFormat::Make) {
+ MakeDependencyPrinterConsumer Consumer;
+ auto Result =
+ Worker.computeDependencies(Input, CWD, Compilations, Consumer);
+ if (Result)
+ return std::move(Result);
+ std::string Output;
+ Consumer.printDependencies(Output);
+ return Output;
+ } else {
+ FullDependencyPrinterConsumer Consumer;
+ auto Result =
+ Worker.computeDependencies(Input, CWD, Compilations, Consumer);
+ if (Result)
+ return std::move(Result);
+ std::string Output;
+ Consumer.printDependencies(Output, Input);
+ return Output;
+ }
}
} // end namespace dependencies
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index 51bd8ec3957..edf2cf8bd70 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -142,18 +142,11 @@ public:
Consumer));
break;
case ScanningOutputFormat::Full:
- Compiler.addDependencyCollector(std::make_shared<ModuleDepCollector>(
- std::move(Opts), Compiler, Consumer));
+ Compiler.addDependencyCollector(
+ std::make_shared<ModuleDepCollector>(Compiler, Consumer));
break;
}
- // Consider different header search and diagnostic options to create
- // different modules. This avoids the unsound aliasing of module PCMs.
- //
- // TODO: Implement diagnostic bucketing and header search pruning to reduce
- // the impact of strict context hashing.
- Compiler.getHeaderSearchOpts().ModulesStrictContextHash = false;
-
Consumer.handleContextHash(Compiler.getInvocation().getModuleHash());
auto Action = std::make_unique<PreprocessOnlyAction>();
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 0d3f9cda634..422940047f2 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -17,47 +17,6 @@ using namespace clang;
using namespace tooling;
using namespace dependencies;
-std::vector<std::string> ModuleDeps::getFullCommandLine(
- std::function<StringRef(ClangModuleDep)> LookupPCMPath,
- std::function<const ModuleDeps &(ClangModuleDep)> LookupModuleDeps) const {
- std::vector<std::string> Ret = NonPathCommandLine;
-
- // TODO: Build full command line. That also means capturing the original
- // command line into NonPathCommandLine.
-
- dependencies::detail::appendCommonModuleArguments(
- ClangModuleDeps, LookupPCMPath, LookupModuleDeps, Ret);
-
- return Ret;
-}
-
-void dependencies::detail::appendCommonModuleArguments(
- llvm::ArrayRef<ClangModuleDep> Modules,
- std::function<StringRef(ClangModuleDep)> LookupPCMPath,
- std::function<const ModuleDeps &(ClangModuleDep)> LookupModuleDeps,
- std::vector<std::string> &Result) {
- llvm::StringSet<> AlreadyAdded;
-
- std::function<void(llvm::ArrayRef<ClangModuleDep>)> AddArgs =
- [&](llvm::ArrayRef<ClangModuleDep> Modules) {
- for (const ClangModuleDep &CMD : Modules) {
- if (!AlreadyAdded.insert(CMD.ModuleName + CMD.ContextHash).second)
- continue;
- const ModuleDeps &M = LookupModuleDeps(CMD);
- // Depth first traversal.
- AddArgs(M.ClangModuleDeps);
- Result.push_back(("-fmodule-file=" + LookupPCMPath(CMD)).str());
- if (!M.ClangModuleMapFile.empty()) {
- Result.push_back("-fmodule-map-file=" + M.ClangModuleMapFile);
- }
- }
- };
-
- Result.push_back("-fno-implicit-modules");
- Result.push_back("-fno-implicit-module-maps");
- AddArgs(Modules);
-}
-
void ModuleDepCollectorPP::FileChanged(SourceLocation Loc,
FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
@@ -91,16 +50,7 @@ void ModuleDepCollectorPP::InclusionDirective(
// here as `FileChanged` will never see it.
MDC.MainDeps.push_back(FileName);
}
- handleImport(Imported);
-}
-void ModuleDepCollectorPP::moduleImport(SourceLocation ImportLoc,
- ModuleIdPath Path,
- const Module *Imported) {
- handleImport(Imported);
-}
-
-void ModuleDepCollectorPP::handleImport(const Module *Imported) {
if (!Imported)
return;
@@ -121,8 +71,9 @@ void ModuleDepCollectorPP::EndOfMainFile() {
for (auto &&I : MDC.Deps)
MDC.Consumer.handleModuleDependency(I.second);
+ DependencyOutputOptions Opts;
for (auto &&I : MDC.MainDeps)
- MDC.Consumer.handleFileDependency(*MDC.Opts, I);
+ MDC.Consumer.handleFileDependency(Opts, I);
}
void ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
@@ -143,7 +94,7 @@ void ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
MD.ClangModuleMapFile = ModuleMap ? ModuleMap->getName() : "";
MD.ModuleName = M->getFullModuleName();
- MD.ImplicitModulePCMPath = M->getASTFile()->getName();
+ MD.ModulePCMPath = M->getASTFile()->getName();
MD.ContextHash = MDC.ContextHash;
serialization::ModuleFile *MF =
MDC.Instance.getASTReader()->getModuleManager().lookup(M->getASTFile());
@@ -152,38 +103,30 @@ void ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
MD.FileDeps.insert(IF.getFile()->getName());
});
- llvm::DenseSet<const Module *> AddedModules;
- addAllSubmoduleDeps(M, MD, AddedModules);
+ addAllSubmoduleDeps(M, MD);
}
-void ModuleDepCollectorPP::addAllSubmoduleDeps(
- const Module *M, ModuleDeps &MD,
- llvm::DenseSet<const Module *> &AddedModules) {
- addModuleDep(M, MD, AddedModules);
+void ModuleDepCollectorPP::addAllSubmoduleDeps(const Module *M,
+ ModuleDeps &MD) {
+ addModuleDep(M, MD);
for (const Module *SubM : M->submodules())
- addAllSubmoduleDeps(SubM, MD, AddedModules);
+ addAllSubmoduleDeps(SubM, MD);
}
-void ModuleDepCollectorPP::addModuleDep(
- const Module *M, ModuleDeps &MD,
- llvm::DenseSet<const Module *> &AddedModules) {
+void ModuleDepCollectorPP::addModuleDep(const Module *M, ModuleDeps &MD) {
for (const Module *Import : M->Imports) {
if (Import->getTopLevelModule() != M->getTopLevelModule()) {
- if (AddedModules.insert(Import->getTopLevelModule()).second)
- MD.ClangModuleDeps.push_back(
- {Import->getTopLevelModuleName(),
- Instance.getInvocation().getModuleHash()});
+ MD.ClangModuleDeps.insert(Import->getTopLevelModuleName());
handleTopLevelModule(Import->getTopLevelModule());
}
}
}
-ModuleDepCollector::ModuleDepCollector(
- std::unique_ptr<DependencyOutputOptions> Opts, CompilerInstance &I,
- DependencyConsumer &C)
- : Instance(I), Consumer(C), ContextHash(I.getInvocation().getModuleHash()),
- Opts(std::move(Opts)) {}
+ModuleDepCollector::ModuleDepCollector(CompilerInstance &I,
+ DependencyConsumer &C)
+ : Instance(I), Consumer(C), ContextHash(I.getInvocation().getModuleHash()) {
+}
void ModuleDepCollector::attachToPreprocessor(Preprocessor &PP) {
PP.addPPCallbacks(std::make_unique<ModuleDepCollectorPP>(Instance, *this));
OpenPOWER on IntegriCloud