16#include "llvm/Support/VirtualFileSystem.h"
25 PCHContainerOps = std::make_shared<PCHContainerOperations>();
27 PCHContainerOps->registerReader(
28 std::make_unique<ObjectFilePCHContainerReader>());
30 PCHContainerOps->registerWriter(std::make_unique<RawPCHContainerWriter>());
32 if (Service.shouldTraceVFS())
33 BaseFS = llvm::makeIntrusiveRefCnt<llvm::vfs::TracingFileSystem>(
36 DepFS = llvm::makeIntrusiveRefCnt<DependencyScanningWorkerFilesystem>(
37 Service.getSharedCache(), std::move(BaseFS));
46 std::optional<llvm::MemoryBufferRef> TUBuffer) {
53 return llvm::Error::success();
54 return llvm::make_error<llvm::StringError>(
55 DiagPrinterWithOS.
DiagnosticsOS.str(), llvm::inconvertibleErrorCode());
65 llvm::BumpPtrAllocator Alloc;
79 std::shared_ptr<clang::PCHContainerOperations> &PCHContainerOps,
85 return Action.
runInvocation(CommandLine[0], std::move(Invocation),
86 std::move(FS), PCHContainerOps,
90bool DependencyScanningWorker::scanDependencies(
91 StringRef WorkingDirectory, ArrayRef<std::string> CommandLine,
93 DiagnosticConsumer &DC,
94 IntrusiveRefCntPtr<llvm::vfs::FileSystem> OverlayFS) {
95 IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = DepFS;
98 bool SawDepFS =
false;
100 [&](llvm::vfs::FileSystem &
VFS) { SawDepFS |= &
VFS == DepFS.get(); });
101 assert(SawDepFS &&
"OverlayFS not based on DepFS");
103 FS = std::move(OverlayFS);
106 DiagnosticsEngineWithDiagOpts DiagEngineWithCmdAndOpts(CommandLine, FS, DC);
107 DependencyScanningAction Action(Service, WorkingDirectory, Consumer,
111 if (CommandLine[1] ==
"-cc1") {
114 *DiagEngineWithCmdAndOpts.DiagEngine);
117 CommandLine, *DiagEngineWithCmdAndOpts.DiagEngine, FS,
118 [&](
const driver::Command &Cmd) {
119 if (StringRef(Cmd.getCreator().getName()) !=
"clang") {
122 Consumer.handleBuildCommand(
123 {Cmd.getExecutable(),
124 {Cmd.getArguments().begin(), Cmd.getArguments().end()}});
129 std::vector<std::string> Argv;
138 std::move(Argv), Action, FS, PCHContainerOps,
139 *DiagEngineWithCmdAndOpts.DiagEngine);
143 if (
Success && !Action.hasScanned())
144 DiagEngineWithCmdAndOpts.DiagEngine->Report(
145 diag::err_fe_expected_compiler_job)
146 << llvm::join(CommandLine,
" ");
149 if (!Action.hasDiagConsumerFinished())
152 return Success && Action.hasScanned();
161 DepFS, CommandLine, WorkingDirectory, *TUBuffer);
162 return scanDependencies(WorkingDirectory, FinalCommandLine, Consumer,
163 Controller, DC, FinalFS);
166 DepFS->setCurrentWorkingDirectory(WorkingDirectory);
167 return scanDependencies(WorkingDirectory, CommandLine, Consumer, Controller,
173 auto OverlayFSAndArgs =
175 auto &OverlayFS = OverlayFSAndArgs.first;
176 const auto &ModifiedCommandLine = OverlayFSAndArgs.second;
178 auto DiagEngineWithCmdAndOpts =
179 std::make_unique<DiagnosticsEngineWithDiagOpts>(ModifiedCommandLine,
183 CWD, ModifiedCommandLine, std::move(DiagEngineWithCmdAndOpts), OverlayFS);
188 std::unique_ptr<DiagnosticsEngineWithDiagOpts> DiagEngineWithDiagOpts,
191 std::make_unique<CompilerInstanceWithContext>(*
this, CWD, CommandLine);
192 return CIWithContext->initialize(std::move(DiagEngineWithDiagOpts),
199 assert(CIWithContext &&
"CompilerInstance with context required!");
200 return CIWithContext->computeDependencies(ModuleName, Consumer, Controller);
204 return CIWithContext->finalize();
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)
static bool forEachDriverJob(ArrayRef< std::string > ArgStrs, DiagnosticsEngine &Diags, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS, llvm::function_ref< bool(const driver::Command &Cmd)> Callback)
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()
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.
bool computeDependencies(StringRef WorkingDirectory, ArrayRef< std::string > CommandLine, DependencyConsumer &DepConsumer, DependencyActionController &Controller, DiagnosticConsumer &DiagConsumer, std::optional< llvm::MemoryBufferRef > TUBuffer=std::nullopt)
Run the dependency scanning tool for a given clang driver command-line, and report the discovered dep...
~DependencyScanningWorker()
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.
Command - An executable path/name and argument vector to execute.
const llvm::opt::ArgStringList & getArguments() const
const char * getExecutable() const
std::pair< IntrusiveRefCntPtr< llvm::vfs::FileSystem >, std::vector< std::string > > initVFSForTUBufferScanning(IntrusiveRefCntPtr< llvm::vfs::FileSystem > BaseFS, ArrayRef< std::string > CommandLine, StringRef WorkingDirectory, llvm::MemoryBufferRef TUBuffer)
@ VFS
Remove unused -ivfsoverlay arguments.
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)
std::pair< std::unique_ptr< driver::Driver >, std::unique_ptr< driver::Compilation > > buildCompilation(ArrayRef< std::string > ArgStrs, DiagnosticsEngine &Diags, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS, llvm::BumpPtrAllocator &Alloc)
The JSON file list parser is used to communicate input to InstallAPI.
@ Success
Annotation was successful.
TextDiagnosticPrinter DiagPrinter
llvm::raw_string_ostream DiagnosticsOS