clang 24.0.0git
DependencyScanningService.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_DEPENDENCYSCANNINGSERVICE_H
10#define LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYSCANNINGSERVICE_H
11
15#include "llvm/ADT/BitmaskEnum.h"
16
17namespace clang {
18namespace dependencies {
19
20/// The mode in which the dependency scanner will operate to find the
21/// dependencies.
22enum class ScanningMode {
23 /// This mode is used to compute the dependencies by running the preprocessor
24 /// over the source files.
26
27 /// This mode is used to compute the dependencies by running the preprocessor
28 /// with special kind of lexing after scanning header and source files to get
29 /// the minimum necessary preprocessor directives for evaluating includes.
31};
32
33#define DSS_LAST_BITMASK_ENUM(Id) \
34 LLVM_MARK_AS_BITMASK_ENUM(Id), All = llvm::NextPowerOf2(Id) - 1
35
37 None = 0,
38
39 /// Remove unused header search paths including header maps.
41
42 /// Remove warnings from system modules.
43 SystemWarnings = (1 << 1),
44
45 /// Remove unused -ivfsoverlay arguments.
46 VFS = (1 << 2),
47
48 /// Canonicalize -D and -U options.
49 Macros = (1 << 3),
50
51 /// Ignore the compiler's working directory if it is safe.
52 IgnoreCWD = (1 << 4),
53
55
56 // The build system needs to be aware that the current working
57 // directory is ignored. Without a good way of notifying the build
58 // system, it is less risky to default to off.
60};
61
62#undef DSS_LAST_BITMASK_ENUM
63
65
66/// \return true if failed stats for files with this name should be cached,
67/// false otherwise.
68bool shouldCacheNegativeStatsForPath(StringRef Path);
69
70/// The configuration knobs for the dependency scanning service.
73
74 /// The function invoked to create each worker's VFS. This function and the
75 /// VFS itself must be thread-safe whenever using multiple workers
76 /// concurrently or whenever \c AsyncScanModules is true.
78 MakeVFS; // = [] { return llvm::vfs::createPhysicalFileSystem(); }
79 /// Whether to use optimized dependency directive scan or full preprocessing.
81 /// How to optimize resulting explicit module command lines.
83 /// Whether the scanner should emit warnings.
84 bool EmitWarnings = true;
85 /// Whether to make reported file paths absolute.
87 /// Whether to report modules visible from modules that are imported directly.
89 /// Whether the resulting command lines should load explicit PCMs eagerly.
90 bool EagerLoadModules = false;
91 /// Whether to trace VFS accesses during the scan.
92 bool TraceVFS = false;
93 /// Whether to scan modules asynchronously.
94 bool AsyncScanModules = false;
95 /// The build session timestamp for validate-once-per-build-session logic.
96 std::time_t BuildSessionTimestamp; // = std::chrono::system_clock::now();
97 /// Whether to automatically flush the module cache from memory to disk at the
98 /// end of the service lifetime.
99 bool FlushModuleCache = true;
100 /// Whether the caching VFS should cache missing filesystem entries.
102 /// Whether scanning modules validate their directory deps against paths
103 /// reported via \c DependencyScanningService::addInvalidatedPath instead of
104 /// the filesystem.
106 /// The path to a log file, which logs timing of actions performed by
107 /// the dependency scanner.
108 std::string LogPath;
109};
110
111/// The dependency scanning service contains shared configuration and state that
112/// is used by the individual dependency scanning workers.
114public:
116 : Opts(std::move(Opts)), Logger(this->Opts.LogPath) {
117 ModCacheEntries.ValidateAgainstInvalidatedPaths =
119 }
120
122 if (Opts.FlushModuleCache)
123 ModCacheEntries.flush();
124 }
125
126 const DependencyScanningServiceOptions &getOpts() const { return Opts; }
127
129 return SharedCache;
130 }
131
132 ModuleCacheEntries &getModuleCacheEntries() { return ModCacheEntries; }
133
134 /// Add a path that changed since the previous scan, so that cached scanning
135 /// modules depending on it are rebuilt. Requires
136 /// \c ValidateAgainstInvalidatedPaths.
137 ///
138 /// Only directories are currently checked. \p Path is compared textually
139 /// against \c ModuleDeps::DirectoryDeps, so it must be spelled the same way:
140 /// absolute, with dots removed, and without resolving symlinks. It is never
141 /// accessed on disk. Modules built since \c BuildSessionTimestamp are
142 /// considered up to date with it.
143 void addInvalidatedPath(StringRef Path) {
144 assert(Opts.ValidateAgainstInvalidatedPaths &&
145 "invalidated paths are only checked when validating against them");
146 ModCacheEntries.addInvalidatedPath(Path);
147 }
148
149 AtomicLineLogger &getLogger() { return Logger; }
150
151private:
152 /// The options customizing dependency scanning behavior.
154 /// The global file system cache.
156 /// The global module cache entries.
157 ModuleCacheEntries ModCacheEntries;
158 /// The logger of dependency scanning actions.
159 AtomicLineLogger Logger;
160};
161
162} // end namespace dependencies
163} // end namespace clang
164
165#endif // LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYSCANNINGSERVICE_H
Defines a logger where each line is written atomically to the file.
This class is a shared cache, that caches the 'stat' and 'open' calls to the underlying real file sys...
const DependencyScanningServiceOptions & getOpts() const
void addInvalidatedPath(StringRef Path)
Add a path that changed since the previous scan, so that cached scanning modules depending on it are ...
DependencyScanningService(DependencyScanningServiceOptions Opts)
DependencyScanningFilesystemSharedCache & getSharedCache()
@ VFS
Remove unused -ivfsoverlay arguments.
@ IgnoreCWD
Ignore the compiler's working directory if it is safe.
@ SystemWarnings
Remove warnings from system modules.
@ HeaderSearch
Remove unused header search paths including header maps.
bool shouldCacheNegativeStatsForPath(StringRef Path)
ScanningMode
The mode in which the dependency scanner will operate to find the dependencies.
@ DependencyDirectivesScan
This mode is used to compute the dependencies by running the preprocessor with special kind of lexing...
@ CanonicalPreprocessing
This mode is used to compute the dependencies by running the preprocessor over the source files.
Top level wrappers for InstallAPI frontend operations.
int const char * function
Definition c++config.h:31
The configuration knobs for the dependency scanning service.
bool FlushModuleCache
Whether to automatically flush the module cache from memory to disk at the end of the service lifetim...
std::function< IntrusiveRefCntPtr< llvm::vfs::FileSystem >()> MakeVFS
The function invoked to create each worker's VFS.
bool AsyncScanModules
Whether to scan modules asynchronously.
ScanningMode Mode
Whether to use optimized dependency directive scan or full preprocessing.
bool ReportVisibleModules
Whether to report modules visible from modules that are imported directly.
bool ValidateAgainstInvalidatedPaths
Whether scanning modules validate their directory deps against paths reported via DependencyScanningS...
bool EmitWarnings
Whether the scanner should emit warnings.
bool CacheNegativeStats
Whether the caching VFS should cache missing filesystem entries.
bool TraceVFS
Whether to trace VFS accesses during the scan.
std::string LogPath
The path to a log file, which logs timing of actions performed by the dependency scanner.
bool EagerLoadModules
Whether the resulting command lines should load explicit PCMs eagerly.
bool ReportAbsolutePaths
Whether to make reported file paths absolute.
std::time_t BuildSessionTimestamp
The build session timestamp for validate-once-per-build-session logic.
ScanningOptimizations OptimizeArgs
How to optimize resulting explicit module command lines.