clang 22.0.0git
DependencyScannerImpl.h
Go to the documentation of this file.
1//===- DependencyScanner.h - Performs module dependency scanning *- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNER_H
10#define LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNER_H
11
19
20namespace clang {
22
23namespace tooling {
24namespace dependencies {
29
31public:
33 DependencyScanningService &Service, StringRef WorkingDirectory,
36 std::optional<StringRef> ModuleName = std::nullopt)
37 : Service(Service), WorkingDirectory(WorkingDirectory),
38 Consumer(Consumer), Controller(Controller), DepFS(std::move(DepFS)),
39 ModuleName(ModuleName) {}
40 bool runInvocation(std::unique_ptr<CompilerInvocation> Invocation,
42 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
43 DiagnosticConsumer *DiagConsumer);
44
45 bool hasScanned() const { return Scanned; }
46 bool hasDiagConsumerFinished() const { return DiagConsumerFinished; }
47
48 /// Take the cc1 arguments corresponding to the most recent invocation used
49 /// with this action. Any modifications implied by the discovered dependencies
50 /// will have already been applied.
51 std::vector<std::string> takeLastCC1Arguments() {
52 std::vector<std::string> Result;
53 std::swap(Result, LastCC1Arguments); // Reset LastCC1Arguments to empty.
54 return Result;
55 }
56
57private:
58 void setLastCC1Arguments(CompilerInvocation &&CI) {
59 if (MDC)
60 MDC->applyDiscoveredDependencies(CI);
61 LastCC1Arguments = CI.getCC1CommandLine();
62 }
63
64 DependencyScanningService &Service;
65 StringRef WorkingDirectory;
66 DependencyConsumer &Consumer;
67 DependencyActionController &Controller;
69 std::optional<StringRef> ModuleName;
70 std::optional<CompilerInstance> ScanInstanceStorage;
71 std::shared_ptr<ModuleDepCollector> MDC;
72 std::vector<std::string> LastCC1Arguments;
73 bool Scanned = false;
74 bool DiagConsumerFinished = false;
75};
76
77// Helper functions and data types.
78std::unique_ptr<DiagnosticOptions>
80
82 // We need to bound the lifetime of the DiagOpts used to create the
83 // DiganosticsEngine with the DiagnosticsEngine itself.
84 std::unique_ptr<DiagnosticOptions> DiagOpts;
86
90};
91
93 // We need to bound the lifetime of the data that supports the DiagPrinter
94 // with it together so they have the same lifetime.
95 std::string DiagnosticOutput;
96 llvm::raw_string_ostream DiagnosticsOS;
97 std::unique_ptr<DiagnosticOptions> DiagOpts;
99
104};
105
106std::pair<std::unique_ptr<driver::Driver>, std::unique_ptr<driver::Compilation>>
109
110std::unique_ptr<CompilerInvocation>
112 DiagnosticsEngine &Diags);
113
114std::pair<IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::vector<std::string>>
116 ArrayRef<std::string> CommandLine,
117 StringRef WorkingDirectory,
118 llvm::MemoryBufferRef TUBuffer);
119
120std::pair<IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::vector<std::string>>
122 ArrayRef<std::string> CommandLine,
123 StringRef WorkingDirectory, StringRef ModuleName);
124
126 CompilerInstance &ScanInstance,
128 DiagnosticConsumer *DiagConsumer, DependencyScanningService &Service,
130
132getInitialStableDirs(const CompilerInstance &ScanInstance);
133
134std::optional<PrebuiltModulesAttrsMap>
136 SmallVector<StringRef> &StableDirs);
137
138std::unique_ptr<DependencyOutputOptions>
140
141/// Create the dependency collector that will collect the produced
142/// dependencies. May return the created ModuleDepCollector depending
143/// on the scanning format.
144std::shared_ptr<ModuleDepCollector> initializeScanInstanceDependencyCollector(
145 CompilerInstance &ScanInstance,
146 std::unique_ptr<DependencyOutputOptions> DepOutputOpts,
147 StringRef WorkingDirectory, DependencyConsumer &Consumer,
148 DependencyScanningService &Service, CompilerInvocation &Inv,
149 DependencyActionController &Controller,
150 PrebuiltModulesAttrsMap PrebuiltModulesASTMap,
151 llvm::SmallVector<StringRef> &StableDirs);
152} // namespace dependencies
153} // namespace tooling
154} // namespace clang
155
156#endif
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Helper class for holding the data necessary to invoke the compiler.
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:232
Dependency scanner callbacks that are used during scanning to influence the behaviour of the scan - f...
bool runInvocation(std::unique_ptr< CompilerInvocation > Invocation, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS, std::shared_ptr< PCHContainerOperations > PCHContainerOps, DiagnosticConsumer *DiagConsumer)
std::vector< std::string > takeLastCC1Arguments()
Take the cc1 arguments corresponding to the most recent invocation used with this action.
DependencyScanningAction(DependencyScanningService &Service, StringRef WorkingDirectory, DependencyConsumer &Consumer, DependencyActionController &Controller, IntrusiveRefCntPtr< DependencyScanningWorkerFilesystem > DepFS, std::optional< StringRef > ModuleName=std::nullopt)
The dependency scanning service contains shared configuration and state that is used by the individua...
A virtual file system optimized for the dependency discovery.
llvm::SmallVector< StringRef > getInitialStableDirs(const CompilerInstance &ScanInstance)
std::unique_ptr< DiagnosticOptions > createDiagOptions(ArrayRef< std::string > CommandLine)
std::pair< std::unique_ptr< driver::Driver >, std::unique_ptr< driver::Compilation > > buildCompilation(ArrayRef< std::string > ArgStrs, DiagnosticsEngine &Diags, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS)
bool initializeScanCompilerInstance(CompilerInstance &ScanInstance, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS, DiagnosticConsumer *DiagConsumer, DependencyScanningService &Service, IntrusiveRefCntPtr< DependencyScanningWorkerFilesystem > DepFS)
std::unique_ptr< CompilerInvocation > createCompilerInvocation(ArrayRef< std::string > CommandLine, DiagnosticsEngine &Diags)
std::shared_ptr< ModuleDepCollector > initializeScanInstanceDependencyCollector(CompilerInstance &ScanInstance, std::unique_ptr< DependencyOutputOptions > DepOutputOpts, StringRef WorkingDirectory, DependencyConsumer &Consumer, DependencyScanningService &Service, CompilerInvocation &Inv, DependencyActionController &Controller, PrebuiltModulesAttrsMap PrebuiltModulesASTMap, llvm::SmallVector< StringRef > &StableDirs)
Create the dependency collector that will collect the produced dependencies.
std::optional< PrebuiltModulesAttrsMap > computePrebuiltModulesASTMap(CompilerInstance &ScanInstance, llvm::SmallVector< StringRef > &StableDirs)
std::pair< IntrusiveRefCntPtr< llvm::vfs::FileSystem >, std::vector< std::string > > initVFSForByNameScanning(IntrusiveRefCntPtr< llvm::vfs::FileSystem > BaseFS, ArrayRef< std::string > CommandLine, StringRef WorkingDirectory, StringRef ModuleName)
llvm::StringMap< PrebuiltModuleASTAttrs > PrebuiltModulesAttrsMap
Attributes loaded from AST files of prebuilt modules collected prior to ModuleDepCollector creation.
std::unique_ptr< DependencyOutputOptions > takeDependencyOutputOptionsFrom(CompilerInstance &ScanInstance)
std::pair< IntrusiveRefCntPtr< llvm::vfs::FileSystem >, std::vector< std::string > > initVFSForTUBuferScanning(IntrusiveRefCntPtr< llvm::vfs::FileSystem > BaseFS, ArrayRef< std::string > CommandLine, StringRef WorkingDirectory, llvm::MemoryBufferRef TUBuffer)
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
Definition TypeBase.h:905
DignosticsEngineWithDiagOpts(ArrayRef< std::string > CommandLine, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS, DiagnosticConsumer &DC)