16#include "llvm/ADT/IntrusiveRefCntPtr.h"
17#include "llvm/Support/VirtualFileSystem.h"
26 PCHContainerOps = std::make_shared<PCHContainerOperations>();
28 PCHContainerOps->registerReader(
29 std::make_unique<ObjectFilePCHContainerReader>());
31 PCHContainerOps->registerWriter(std::make_unique<RawPCHContainerWriter>());
33 if (Service.shouldTraceVFS())
34 BaseFS = llvm::makeIntrusiveRefCnt<llvm::vfs::TracingFileSystem>(
37 DepFS = llvm::makeIntrusiveRefCnt<DependencyScanningWorkerFilesystem>(
38 Service.getSharedCache(), std::move(BaseFS));
47 std::shared_ptr<clang::PCHContainerOperations> &PCHContainerOps,
53 return Action.
runInvocation(CommandLine[0], std::move(Invocation),
54 std::move(FS), PCHContainerOps,
65 DepConsumer, Controller, DiagConsumer, OverlayFS);
76 bool SawDepFS =
false;
78 [&](llvm::vfs::FileSystem &
VFS) { SawDepFS |= &
VFS == DepFS.get(); });
79 assert(SawDepFS &&
"OverlayFS not based on DepFS");
81 FS = std::move(OverlayFS);
84 FS->setCurrentWorkingDirectory(WorkingDirectory);
90 const bool Success = llvm::all_of(CommandLines, [&](
const auto &Cmd) {
91 if (StringRef(Cmd[1]) !=
"-cc1") {
94 {Cmd.front(), {Cmd.begin() + 1, Cmd.end()}});
98 auto DiagEngineWithDiagOpts =
100 auto &Diags = *DiagEngineWithDiagOpts.DiagEngine;
117 auto [OverlayFS, ModifiedCommandLine] =
119 auto DiagEngineWithCmdAndOpts =
120 std::make_unique<DiagnosticsEngineWithDiagOpts>(ModifiedCommandLine,
123 CWD, ModifiedCommandLine, std::move(DiagEngineWithCmdAndOpts), OverlayFS);
128 std::unique_ptr<DiagnosticsEngineWithDiagOpts> DiagEngineWithDiagOpts,
131 std::make_unique<CompilerInstanceWithContext>(*
this, CWD, CommandLine);
132 return CIWithContext->initialize(std::move(DiagEngineWithDiagOpts),
139 assert(CIWithContext &&
"CompilerInstance with context required!");
140 return CIWithContext->computeDependencies(ModuleName, Consumer, Controller);
144 return CIWithContext->finalize();
147std::pair<IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>,
148 std::vector<std::string>>
152 llvm::MemoryBufferRef TUBuffer) {
154 BaseFS->setCurrentWorkingDirectory(WorkingDirectory);
157 llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(BaseFS);
158 auto InMemoryFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
159 InMemoryFS->setCurrentWorkingDirectory(WorkingDirectory);
160 auto InputPath = TUBuffer.getBufferIdentifier();
162 InputPath, 0, llvm::MemoryBuffer::getMemBufferCopy(TUBuffer.getBuffer()));
165 OverlayFS->pushOverlay(InMemoryOverlay);
166 std::vector<std::string> ModifiedCommandLine(CommandLine);
167 ModifiedCommandLine.emplace_back(InputPath);
169 return std::make_pair(OverlayFS, ModifiedCommandLine);
172std::pair<IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>,
173 std::vector<std::string>>
177 StringRef ModuleName) {
179 BaseFS->setCurrentWorkingDirectory(WorkingDirectory);
185 llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(BaseFS);
186 auto InMemoryFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
187 InMemoryFS->setCurrentWorkingDirectory(WorkingDirectory);
190 llvm::sys::fs::createUniquePath(ModuleName +
"-%%%%%%%%.input", FakeInputPath,
192 InMemoryFS->addFile(FakeInputPath, 0, llvm::MemoryBuffer::getMemBuffer(
""));
194 OverlayFS->pushOverlay(InMemoryOverlay);
196 std::vector<std::string> ModifiedCommandLine(CommandLine);
197 ModifiedCommandLine.emplace_back(FakeInputPath);
199 return std::make_pair(OverlayFS, ModifiedCommandLine);
Defines the Diagnostic-related interfaces.
static bool createAndRunToolInvocation(ArrayRef< std::string > CommandLine, DependencyScanningAction &Action, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS, std::shared_ptr< clang::PCHContainerOperations > &PCHContainerOps, DiagnosticsEngine &Diags)
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
virtual void finish()
Callback to inform the diagnostic client that processing of all source files has ended.
Concrete class used by the front-end to report problems and issues.
DiagnosticConsumer * getClient()
Dependency scanner callbacks that are used during scanning to influence the behaviour of the scan - f...
virtual ~DependencyActionController()
virtual void handleBuildCommand(Command Cmd)
bool hasDiagConsumerFinished() const
bool runInvocation(std::string Executable, std::unique_ptr< CompilerInvocation > Invocation, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS, std::shared_ptr< PCHContainerOperations > PCHContainerOps, DiagnosticConsumer *DiagConsumer)
The dependency scanning service contains shared configuration and state that is used by the individua...
bool computeDependenciesByNameWithContext(StringRef ModuleName, DependencyConsumer &Consumer, DependencyActionController &Controller)
Performaces dependency scanning for the module whose name is specified.
DependencyScanningWorker(DependencyScanningService &Service, IntrusiveRefCntPtr< llvm::vfs::FileSystem > BaseFS)
Construct a dependency scanning worker.
~DependencyScanningWorker()
bool computeDependencies(StringRef WorkingDirectory, ArrayRef< std::string > CommandLine, DependencyConsumer &DepConsumer, DependencyActionController &Controller, DiagnosticConsumer &DiagConsumer, llvm::IntrusiveRefCntPtr< llvm::vfs::OverlayFileSystem > OverlayFS=nullptr)
Run the dependency scanning worker for the given frontend command-line, and report the discovered dep...
bool initializeCompilerInstanceWithContext(StringRef CWD, ArrayRef< std::string > CommandLine, DiagnosticConsumer &DC)
The three method below implements a new interface for by name dependency scanning.
bool finalizeCompilerInstanceWithContext()
Finalizes the diagnostics engine and deletes the compiler instance.
@ VFS
Remove unused -ivfsoverlay arguments.
std::pair< IntrusiveRefCntPtr< llvm::vfs::OverlayFileSystem >, std::vector< std::string > > initVFSForTUBufferScanning(IntrusiveRefCntPtr< llvm::vfs::FileSystem > BaseFS, ArrayRef< std::string > CommandLine, StringRef WorkingDirectory, llvm::MemoryBufferRef TUBuffer)
std::unique_ptr< CompilerInvocation > createCompilerInvocation(ArrayRef< std::string > CommandLine, DiagnosticsEngine &Diags)
std::pair< IntrusiveRefCntPtr< llvm::vfs::OverlayFileSystem >, std::vector< std::string > > initVFSForByNameScanning(IntrusiveRefCntPtr< llvm::vfs::FileSystem > BaseFS, ArrayRef< std::string > CommandLine, StringRef WorkingDirectory, StringRef ModuleName)
The JSON file list parser is used to communicate input to InstallAPI.
@ Success
Annotation was successful.