clang 23.0.0git
DependencyScannerImpl.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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_DEPENDENCYSCANNING_DEPENDENCYSCANNERIMPL_H
10#define LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYSCANNERIMPL_H
11
17#include "llvm/Support/VirtualFileSystem.h"
18
19namespace clang {
21
22namespace dependencies {
25
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 bool runInvocation(std::string Executable,
40 std::unique_ptr<CompilerInvocation> Invocation,
42 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
43 DiagnosticConsumer *DiagConsumer);
44
45 bool hasScanned() const { return Scanned; }
46
47private:
49 StringRef WorkingDirectory;
50 DependencyConsumer &Consumer;
53 std::optional<CompilerInstance> ScanInstanceStorage;
54 std::shared_ptr<ModuleDepCollector> MDC;
55 bool Scanned = false;
56};
57
58// Helper functions and data types.
59std::unique_ptr<DiagnosticOptions>
61
63 // We need to bound the lifetime of the DiagOpts used to create the
64 // DiganosticsEngine with the DiagnosticsEngine itself.
65 std::unique_ptr<DiagnosticOptions> DiagOpts;
67
71};
72
74 // We need to bound the lifetime of the data that supports the DiagPrinter
75 // with it together so they have the same lifetime.
76 std::string DiagnosticOutput;
77 llvm::raw_string_ostream DiagnosticsOS;
78 std::unique_ptr<DiagnosticOptions> DiagOpts;
80
85};
86
87std::unique_ptr<CompilerInvocation>
89 DiagnosticsEngine &Diags);
90
91/// Canonicalizes command-line macro defines (e.g. removing "-DX -UX").
93
94/// Creates a CompilerInvocation suitable for the dependency scanner.
95std::shared_ptr<CompilerInvocation>
97 const DependencyScanningService &Service,
98 DependencyActionController &Controller);
99
100/// Creates dependency output options to be reported to the dependency consumer,
101/// deducing missing information if necessary.
102std::unique_ptr<DependencyOutputOptions>
104
106 CompilerInstance &ScanInstance,
108 DiagnosticConsumer *DiagConsumer, DependencyScanningService &Service,
110
112getInitialStableDirs(const CompilerInstance &ScanInstance);
113
114std::optional<PrebuiltModulesAttrsMap>
116 SmallVector<StringRef> &StableDirs);
117
118/// Create the dependency collector that will collect the produced
119/// dependencies. May return the created ModuleDepCollector depending
120/// on the scanning format.
121std::shared_ptr<ModuleDepCollector> initializeScanInstanceDependencyCollector(
122 CompilerInstance &ScanInstance,
123 std::unique_ptr<DependencyOutputOptions> DepOutputOpts,
124 StringRef WorkingDirectory, DependencyConsumer &Consumer,
125 DependencyScanningService &Service, CompilerInvocation &Inv,
126 DependencyActionController &Controller,
127 PrebuiltModulesAttrsMap PrebuiltModulesASTMap,
128 llvm::SmallVector<StringRef> &StableDirs);
129} // namespace dependencies
130} // namespace clang
131
132#endif // LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYSCANNERIMPL_H
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:233
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
Dependency scanner callbacks that are used during scanning to influence the behaviour of the scan - f...
DependencyScanningAction(DependencyScanningService &Service, StringRef WorkingDirectory, DependencyConsumer &Consumer, DependencyActionController &Controller, IntrusiveRefCntPtr< DependencyScanningWorkerFilesystem > DepFS, std::optional< StringRef > ModuleName=std::nullopt)
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...
A virtual file system optimized for the dependency discovery.
An individual dependency scanning worker that is able to run on its own thread.
SmallVector< StringRef > getInitialStableDirs(const CompilerInstance &ScanInstance)
std::shared_ptr< CompilerInvocation > createScanCompilerInvocation(const CompilerInvocation &Invocation, const DependencyScanningService &Service, DependencyActionController &Controller)
Creates a CompilerInvocation suitable for the dependency scanner.
void initializeScanCompilerInstance(CompilerInstance &ScanInstance, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS, DiagnosticConsumer *DiagConsumer, DependencyScanningService &Service, IntrusiveRefCntPtr< DependencyScanningWorkerFilesystem > DepFS)
llvm::StringMap< PrebuiltModuleASTAttrs > PrebuiltModulesAttrsMap
Attributes loaded from AST files of prebuilt modules collected prior to ModuleDepCollector creation.
std::unique_ptr< CompilerInvocation > createCompilerInvocation(ArrayRef< std::string > CommandLine, DiagnosticsEngine &Diags)
void canonicalizeDefines(PreprocessorOptions &PPOpts)
Canonicalizes command-line macro defines (e.g. removing "-DX -UX").
std::unique_ptr< DependencyOutputOptions > createDependencyOutputOptions(const CompilerInvocation &Invocation)
Creates dependency output options to be reported to the dependency consumer, deducing missing informa...
std::optional< PrebuiltModulesAttrsMap > computePrebuiltModulesASTMap(CompilerInstance &ScanInstance, SmallVector< StringRef > &StableDirs)
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::unique_ptr< DiagnosticOptions > createDiagOptions(ArrayRef< std::string > CommandLine)
The JSON file list parser is used to communicate input to InstallAPI.
IntrusiveRefCntPtr< DiagnosticsEngine > DiagEngine
DiagnosticsEngineWithDiagOpts(ArrayRef< std::string > CommandLine, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS, DiagnosticConsumer &DC)
TextDiagnosticsPrinterWithOutput(ArrayRef< std::string > CommandLine)