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
15#include "clang/Driver/Driver.h"
19#include "llvm/Support/VirtualFileSystem.h"
20
21namespace clang {
23
24namespace dependencies {
27
31
33public:
35 DependencyScanningService &Service, StringRef WorkingDirectory,
38 std::optional<StringRef> ModuleName = std::nullopt)
39 : Service(Service), WorkingDirectory(WorkingDirectory),
40 Consumer(Consumer), Controller(Controller), DepFS(std::move(DepFS)) {}
41 bool runInvocation(std::string Executable,
42 std::unique_ptr<CompilerInvocation> Invocation,
44 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
45 DiagnosticConsumer *DiagConsumer);
46
47 bool hasScanned() const { return Scanned; }
48
49private:
51 StringRef WorkingDirectory;
52 DependencyConsumer &Consumer;
55 std::optional<CompilerInstance> ScanInstanceStorage;
56 std::shared_ptr<ModuleDepCollector> MDC;
57 bool Scanned = false;
58};
59
60// Helper functions and data types.
61std::unique_ptr<DiagnosticOptions>
63
65 // We need to bound the lifetime of the DiagOpts used to create the
66 // DiganosticsEngine with the DiagnosticsEngine itself.
67 std::unique_ptr<DiagnosticOptions> DiagOpts;
69
73};
74
76 // We need to bound the lifetime of the data that supports the DiagPrinter
77 // with it together so they have the same lifetime.
78 std::string DiagnosticOutput;
79 llvm::raw_string_ostream DiagnosticsOS;
80 std::unique_ptr<DiagnosticOptions> DiagOpts;
82
87};
88
89std::unique_ptr<CompilerInvocation>
91 DiagnosticsEngine &Diags);
92
93/// Canonicalizes command-line macro defines (e.g. removing "-DX -UX").
95
96/// Creates a CompilerInvocation suitable for the dependency scanner.
97std::shared_ptr<CompilerInvocation>
99 const DependencyScanningService &Service,
100 DependencyActionController &Controller);
101
102/// Creates dependency output options to be reported to the dependency consumer,
103/// deducing missing information if necessary.
104std::unique_ptr<DependencyOutputOptions>
106
108 CompilerInstance &ScanInstance,
110 DiagnosticConsumer *DiagConsumer, DependencyScanningService &Service,
112
114getInitialStableDirs(const CompilerInstance &ScanInstance);
115
116std::optional<PrebuiltModulesAttrsMap>
118 SmallVector<StringRef> &StableDirs);
119
120/// Create the dependency collector that will collect the produced
121/// dependencies. May return the created ModuleDepCollector depending
122/// on the scanning format.
123std::shared_ptr<ModuleDepCollector> initializeScanInstanceDependencyCollector(
124 CompilerInstance &ScanInstance,
125 std::unique_ptr<DependencyOutputOptions> DepOutputOpts,
126 StringRef WorkingDirectory, DependencyConsumer &Consumer,
127 DependencyScanningService &Service, CompilerInvocation &Inv,
128 DependencyActionController &Controller,
129 PrebuiltModulesAttrsMap PrebuiltModulesASTMap,
130 llvm::SmallVector<StringRef> &StableDirs);
131} // namespace dependencies
132} // namespace clang
133
134#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:232
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)