summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorMichael Spencer <bigcheesegs@gmail.com>2019-10-30 15:15:39 -0700
committerMichael Spencer <bigcheesegs@gmail.com>2019-10-30 15:16:38 -0700
commit1c88d662230e79bc2dd2283d753d950c1ad0bed6 (patch)
treeff84a7a15b9af35d2e2c40967113107be59ae85d /clang/lib
parent577dca62e918eb3e766324e3dda48675ab1fa292 (diff)
downloadbcm5719-llvm-1c88d662230e79bc2dd2283d753d950c1ad0bed6.tar.gz
bcm5719-llvm-1c88d662230e79bc2dd2283d753d950c1ad0bed6.zip
Revert "[clang][clang-scan-deps] Add support for extracting full module dependencies."
This reverts commit d8a4ef0e685cec1fc73d4953b48220b649d05b40. This commit broke some of the bots. I believe it's due to nondeterminism. Will fix and recommit.
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Tooling/DependencyScanning/CMakeLists.txt1
-rw-r--r--clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp8
-rw-r--r--clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp112
-rw-r--r--clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp30
-rw-r--r--clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp136
5 files changed, 21 insertions, 266 deletions
diff --git a/clang/lib/Tooling/DependencyScanning/CMakeLists.txt b/clang/lib/Tooling/DependencyScanning/CMakeLists.txt
index c6fe207ab2f..05e1aa54f8d 100644
--- a/clang/lib/Tooling/DependencyScanning/CMakeLists.txt
+++ b/clang/lib/Tooling/DependencyScanning/CMakeLists.txt
@@ -8,7 +8,6 @@ add_clang_library(clangDependencyScanning
DependencyScanningService.cpp
DependencyScanningWorker.cpp
DependencyScanningTool.cpp
- ModuleDepCollector.cpp
DEPENDS
ClangDriverOptions
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp
index 93bb0cde439..e5cebe38100 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp
@@ -12,8 +12,8 @@ using namespace clang;
using namespace tooling;
using namespace dependencies;
-DependencyScanningService::DependencyScanningService(
- ScanningMode Mode, ScanningOutputFormat Format, bool ReuseFileManager,
- bool SkipExcludedPPRanges)
- : Mode(Mode), Format(Format), ReuseFileManager(ReuseFileManager),
+DependencyScanningService::DependencyScanningService(ScanningMode Mode,
+ bool ReuseFileManager,
+ bool SkipExcludedPPRanges)
+ : Mode(Mode), ReuseFileManager(ReuseFileManager),
SkipExcludedPPRanges(SkipExcludedPPRanges) {}
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
index 927a04c7cc1..d2af1a9d110 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
@@ -8,15 +8,6 @@
#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
#include "clang/Frontend/Utils.h"
-#include "llvm/Support/JSON.h"
-
-static llvm::json::Array toJSON(const llvm::StringSet<> &Set) {
- llvm::json::Array Ret;
- for (auto &&I : Set) {
- Ret.push_back(std::string(I.getKey()));
- }
- return Ret;
-}
namespace clang{
namespace tooling{
@@ -25,14 +16,13 @@ namespace dependencies{
DependencyScanningTool::DependencyScanningTool(
DependencyScanningService &Service,
const tooling::CompilationDatabase &Compilations)
- : Format(Service.getFormat()), Worker(Service), Compilations(Compilations) {
-}
+ : Worker(Service), Compilations(Compilations) {}
llvm::Expected<std::string>
DependencyScanningTool::getDependencyFile(const std::string &Input,
StringRef CWD) {
/// Prints out all of the gathered dependencies into a string.
- class MakeDependencyPrinterConsumer : public DependencyConsumer {
+ class DependencyPrinterConsumer : public DependencyConsumer {
public:
void handleFileDependency(const DependencyOutputOptions &Opts,
StringRef File) override {
@@ -41,14 +31,6 @@ DependencyScanningTool::getDependencyFile(const std::string &Input,
Dependencies.push_back(File);
}
- void handleModuleDependency(ModuleDeps MD) override {
- // These are ignored for the make format as it can't support the full
- // set of deps, and handleFileDependency handles enough for implicitly
- // built modules to work.
- }
-
- void handleContextHash(std::string Hash) override {}
-
void printDependencies(std::string &S) {
if (!Opts)
return;
@@ -77,88 +59,14 @@ DependencyScanningTool::getDependencyFile(const std::string &Input,
std::vector<std::string> Dependencies;
};
- class FullDependencyPrinterConsumer : public DependencyConsumer {
- public:
- void handleFileDependency(const DependencyOutputOptions &Opts,
- StringRef File) override {
- Dependencies.push_back(File);
- }
-
- void handleModuleDependency(ModuleDeps MD) override {
- ModuleDeps[MD.ContextHash + MD.ModuleName] = std::move(MD);
- }
-
- void handleContextHash(std::string Hash) override {
- ContextHash = std::move(Hash);
- }
-
- void printDependencies(std::string &S, StringRef MainFile) {
- // Sort the modules by name to get a deterministic order.
- std::vector<StringRef> Modules;
- for (auto &&Dep : ModuleDeps)
- Modules.push_back(Dep.first);
- std::sort(Modules.begin(), Modules.end());
-
- llvm::raw_string_ostream OS(S);
-
- using namespace llvm::json;
-
- Array Imports;
- for (auto &&ModName : Modules) {
- auto &MD = ModuleDeps[ModName];
- if (MD.ImportedByMainFile)
- Imports.push_back(MD.ModuleName);
- }
-
- Array Mods;
- for (auto &&ModName : Modules) {
- auto &MD = ModuleDeps[ModName];
- Object Mod{
- {"name", MD.ModuleName},
- {"file-deps", toJSON(MD.FileDeps)},
- {"clang-module-deps", toJSON(MD.ClangModuleDeps)},
- {"clang-modulemap-file", MD.ClangModuleMapFile},
- };
- Mods.push_back(std::move(Mod));
- }
-
- 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> ModuleDeps;
- std::string ContextHash;
- };
-
- 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;
- }
+ DependencyPrinterConsumer Consumer;
+ auto Result =
+ Worker.computeDependencies(Input, CWD, Compilations, Consumer);
+ if (Result)
+ return std::move(Result);
+ std::string Output;
+ Consumer.printDependencies(Output);
+ return Output;
}
} // end namespace dependencies
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index edf2cf8bd70..f382c202f8c 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -14,7 +14,6 @@
#include "clang/Frontend/Utils.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
-#include "clang/Tooling/DependencyScanning/ModuleDepCollector.h"
#include "clang/Tooling/Tooling.h"
using namespace clang;
@@ -73,11 +72,9 @@ public:
DependencyScanningAction(
StringRef WorkingDirectory, DependencyConsumer &Consumer,
llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS,
- ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings,
- ScanningOutputFormat Format)
+ ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings)
: WorkingDirectory(WorkingDirectory), Consumer(Consumer),
- DepFS(std::move(DepFS)), PPSkipMappings(PPSkipMappings),
- Format(Format) {}
+ DepFS(std::move(DepFS)), PPSkipMappings(PPSkipMappings) {}
bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
FileManager *FileMgr,
@@ -134,20 +131,9 @@ public:
// We need at least one -MT equivalent for the generator to work.
if (Opts->Targets.empty())
Opts->Targets = {"clang-scan-deps dependency"};
-
- switch (Format) {
- case ScanningOutputFormat::Make:
- Compiler.addDependencyCollector(
- std::make_shared<DependencyConsumerForwarder>(std::move(Opts),
- Consumer));
- break;
- case ScanningOutputFormat::Full:
- Compiler.addDependencyCollector(
- std::make_shared<ModuleDepCollector>(Compiler, Consumer));
- break;
- }
-
- Consumer.handleContextHash(Compiler.getInvocation().getModuleHash());
+ Compiler.addDependencyCollector(
+ std::make_shared<DependencyConsumerForwarder>(std::move(Opts),
+ Consumer));
auto Action = std::make_unique<PreprocessOnlyAction>();
const bool Result = Compiler.ExecuteAction(*Action);
@@ -161,14 +147,12 @@ private:
DependencyConsumer &Consumer;
llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS;
ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings;
- ScanningOutputFormat Format;
};
} // end anonymous namespace
DependencyScanningWorker::DependencyScanningWorker(
- DependencyScanningService &Service)
- : Format(Service.getFormat()) {
+ DependencyScanningService &Service) {
DiagOpts = new DiagnosticOptions();
PCHContainerOps = std::make_shared<PCHContainerOperations>();
RealFS = new ProxyFileSystemWithoutChdir(llvm::vfs::getRealFileSystem());
@@ -211,7 +195,7 @@ llvm::Error DependencyScanningWorker::computeDependencies(
Tool.setPrintErrorMessage(false);
Tool.setDiagnosticConsumer(&DC);
DependencyScanningAction Action(WorkingDirectory, Consumer, DepFS,
- PPSkipMappings.get(), Format);
+ PPSkipMappings.get());
return !Tool.run(&Action);
});
}
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
deleted file mode 100644
index 7f20ec7056c..00000000000
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-//===- ModuleDepCollector.cpp - Callbacks to collect deps -------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/Tooling/DependencyScanning/ModuleDepCollector.h"
-
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Lex/Preprocessor.h"
-#include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h"
-
-using namespace clang;
-using namespace tooling;
-using namespace dependencies;
-
-void ModuleDepCollectorPP::FileChanged(SourceLocation Loc,
- FileChangeReason Reason,
- SrcMgr::CharacteristicKind FileType,
- FileID PrevFID) {
- if (Reason != PPCallbacks::EnterFile)
- return;
-
- SourceManager &SM = Instance.getSourceManager();
-
- // Dependency generation really does want to go all the way to the
- // file entry for a source location to find out what is depended on.
- // We do not want #line markers to affect dependency generation!
- Optional<FileEntryRef> File =
- SM.getFileEntryRefForID(SM.getFileID(SM.getExpansionLoc(Loc)));
- if (!File)
- return;
-
- StringRef FileName =
- llvm::sys::path::remove_leading_dotslash(File->getName());
-
- MDC.MainDeps.push_back(FileName);
-}
-
-void ModuleDepCollectorPP::InclusionDirective(
- SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
- StringRef SearchPath, StringRef RelativePath, const Module *Imported,
- SrcMgr::CharacteristicKind FileType) {
- if (!File && !Imported) {
- // This is a non-modular include that HeaderSearch failed to find. Add it
- // here as `FileChanged` will never see it.
- MDC.MainDeps.push_back(FileName);
- }
-
- if (!Imported)
- return;
-
- MDC.Deps[MDC.ContextHash + Imported->getTopLevelModule()->getFullModuleName()]
- .ImportedByMainFile = true;
- DirectDeps.insert(Imported->getTopLevelModule());
-}
-
-void ModuleDepCollectorPP::EndOfMainFile() {
- FileID MainFileID = Instance.getSourceManager().getMainFileID();
- MDC.MainFile =
- Instance.getSourceManager().getFileEntryForID(MainFileID)->getName();
-
- for (const Module *M : DirectDeps) {
- handleTopLevelModule(M);
- }
-
- for (auto &&I : MDC.Deps)
- MDC.Consumer.handleModuleDependency(I.second);
-
- DependencyOutputOptions Opts;
- for (auto &&I : MDC.MainDeps)
- MDC.Consumer.handleFileDependency(Opts, I);
-}
-
-void ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
- assert(M == M->getTopLevelModule() && "Expected top level module!");
-
- auto ModI = MDC.Deps.insert(
- std::make_pair(MDC.ContextHash + M->getFullModuleName(), ModuleDeps{}));
-
- if (!ModI.first->second.ModuleName.empty())
- return;
-
- ModuleDeps &MD = ModI.first->second;
-
- const FileEntry *ModuleMap = Instance.getPreprocessor()
- .getHeaderSearchInfo()
- .getModuleMap()
- .getContainingModuleMapFile(M);
-
- MD.ClangModuleMapFile = ModuleMap ? ModuleMap->getName() : "";
- MD.ModuleName = M->getFullModuleName();
- MD.ModulePCMPath = M->getASTFile()->getName();
- MD.ContextHash = MDC.ContextHash;
- serialization::ModuleFile *MF =
- MDC.Instance.getModuleManager()->getModuleManager().lookup(
- M->getASTFile());
- MDC.Instance.getModuleManager()->visitInputFiles(
- *MF, true, true, [&](const serialization::InputFile &IF, bool isSystem) {
- MD.FileDeps.insert(IF.getFile()->getName());
- });
-
- addAllSubmoduleDeps(M, MD);
-}
-
-void ModuleDepCollectorPP::addAllSubmoduleDeps(const Module *M,
- ModuleDeps &MD) {
- addModuleDep(M, MD);
-
- for (const Module *SubM : M->submodules())
- addAllSubmoduleDeps(SubM, MD);
-}
-
-void ModuleDepCollectorPP::addModuleDep(const Module *M, ModuleDeps &MD) {
- for (const Module *Import : M->Imports) {
- if (Import->getTopLevelModule() != M->getTopLevelModule()) {
- MD.ClangModuleDeps.insert(Import->getTopLevelModuleName());
- handleTopLevelModule(Import->getTopLevelModule());
- }
- }
-}
-
-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));
-}
-
-void ModuleDepCollector::attachToASTReader(ASTReader &R) {}
OpenPOWER on IntegriCloud