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));
50 llvm::BumpPtrAllocator Alloc;
64 std::shared_ptr<clang::PCHContainerOperations> &PCHContainerOps,
70 return Action.
runInvocation(CommandLine[0], std::move(Invocation),
71 std::move(FS), PCHContainerOps,
75bool DependencyScanningWorker::scanDependencies(
76 StringRef WorkingDirectory, ArrayRef<std::string> CommandLine,
78 DiagnosticConsumer &DC,
79 IntrusiveRefCntPtr<llvm::vfs::FileSystem> OverlayFS) {
80 IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = DepFS;
83 bool SawDepFS =
false;
85 [&](llvm::vfs::FileSystem &
VFS) { SawDepFS |= &
VFS == DepFS.get(); });
86 assert(SawDepFS &&
"OverlayFS not based on DepFS");
88 FS = std::move(OverlayFS);
91 DiagnosticsEngineWithDiagOpts DiagEngineWithCmdAndOpts(CommandLine, FS, DC);
92 DependencyScanningAction Action(Service, WorkingDirectory, Consumer,
96 if (CommandLine[1] ==
"-cc1") {
99 *DiagEngineWithCmdAndOpts.DiagEngine);
102 CommandLine, *DiagEngineWithCmdAndOpts.DiagEngine, FS,
103 [&](
const driver::Command &Cmd) {
104 if (StringRef(Cmd.getCreator().getName()) !=
"clang") {
107 Consumer.handleBuildCommand(
108 {Cmd.getExecutable(),
109 {Cmd.getArguments().begin(), Cmd.getArguments().end()}});
114 std::vector<std::string> Argv;
123 std::move(Argv), Action, FS, PCHContainerOps,
124 *DiagEngineWithCmdAndOpts.DiagEngine);
128 if (
Success && !Action.hasScanned())
129 DiagEngineWithCmdAndOpts.DiagEngine->Report(
130 diag::err_fe_expected_compiler_job)
131 << llvm::join(CommandLine,
" ");
134 if (!Action.hasDiagConsumerFinished())
137 return Success && Action.hasScanned();
146 DepFS, CommandLine, WorkingDirectory, *TUBuffer);
147 return scanDependencies(WorkingDirectory, FinalCommandLine, Consumer,
148 Controller, DC, FinalFS);
151 DepFS->setCurrentWorkingDirectory(WorkingDirectory);
152 return scanDependencies(WorkingDirectory, CommandLine, Consumer, Controller,
158 auto [OverlayFS, ModifiedCommandLine] =
160 auto DiagEngineWithCmdAndOpts =
161 std::make_unique<DiagnosticsEngineWithDiagOpts>(ModifiedCommandLine,
164 CWD, ModifiedCommandLine, std::move(DiagEngineWithCmdAndOpts), OverlayFS);
169 std::unique_ptr<DiagnosticsEngineWithDiagOpts> DiagEngineWithDiagOpts,
172 std::make_unique<CompilerInstanceWithContext>(*
this, CWD, CommandLine);
173 return CIWithContext->initialize(std::move(DiagEngineWithDiagOpts),
180 assert(CIWithContext &&
"CompilerInstance with context required!");
181 return CIWithContext->computeDependencies(ModuleName, Consumer, Controller);
185 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
@ 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)
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.