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 : Service(Service), WorkingDirectory(WorkingDirectory),
37 Consumer(Consumer), Controller(Controller), DepFS(std::move(DepFS)) {}
38 bool runInvocation(std::string Executable,
39 std::unique_ptr<CompilerInvocation> Invocation,
41 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
42 DiagnosticConsumer *DiagConsumer);
43
44 bool hasScanned() const { return Scanned; }
45
46private:
48 StringRef WorkingDirectory;
49 DependencyConsumer &Consumer;
52 std::optional<CompilerInstance> ScanInstanceStorage;
53 std::shared_ptr<ModuleDepCollector> MDC;
54 bool Scanned = false;
55};
56
57// Helper functions and data types.
58std::unique_ptr<DiagnosticOptions>
60
62 // We need to bound the lifetime of the DiagOpts used to create the
63 // DiganosticsEngine with the DiagnosticsEngine itself.
64 std::unique_ptr<DiagnosticOptions> DiagOpts;
66
70};
71
73 // We need to bound the lifetime of the data that supports the DiagPrinter
74 // with it together so they have the same lifetime.
75 std::string DiagnosticOutput;
76 llvm::raw_string_ostream DiagnosticsOS;
77 std::unique_ptr<DiagnosticOptions> DiagOpts;
79
84};
85
86std::unique_ptr<CompilerInvocation>
88 DiagnosticsEngine &Diags);
89
90/// Canonicalizes command-line macro defines (e.g. removing "-DX -UX").
92
93/// Creates a CompilerInvocation suitable for the dependency scanner.
94std::shared_ptr<CompilerInvocation>
96 const DependencyScanningService &Service,
97 DependencyActionController &Controller);
98
99/// Creates dependency output options to be reported to the dependency consumer,
100/// deducing missing information if necessary.
101std::unique_ptr<DependencyOutputOptions>
103
105 CompilerInstance &ScanInstance,
107 DiagnosticConsumer *DiagConsumer, DependencyScanningService &Service,
109
111getInitialStableDirs(const CompilerInstance &ScanInstance);
112
113std::optional<PrebuiltModulesAttrsMap>
115 SmallVector<StringRef> &StableDirs);
116
117/// Create the dependency collector that will collect the produced
118/// dependencies. May return the created ModuleDepCollector depending
119/// on the scanning format.
120std::shared_ptr<ModuleDepCollector> initializeScanInstanceDependencyCollector(
121 CompilerInstance &ScanInstance,
122 std::unique_ptr<DependencyOutputOptions> DepOutputOpts,
123 DependencyScanningService &Service, CompilerInvocation &Inv,
124 DependencyActionController &Controller,
125 PrebuiltModulesAttrsMap PrebuiltModulesASTMap,
126 SmallVector<StringRef> &StableDirs);
127} // namespace dependencies
128} // namespace clang
129
130#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)
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::unique_ptr< DiagnosticOptions > createDiagOptions(ArrayRef< std::string > CommandLine)
std::shared_ptr< ModuleDepCollector > initializeScanInstanceDependencyCollector(CompilerInstance &ScanInstance, std::unique_ptr< DependencyOutputOptions > DepOutputOpts, DependencyScanningService &Service, CompilerInvocation &Inv, DependencyActionController &Controller, PrebuiltModulesAttrsMap PrebuiltModulesASTMap, SmallVector< StringRef > &StableDirs)
Create the dependency collector that will collect the produced dependencies.
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)