Skip to content

Commit acf3193

Browse files
committed
[clang][ScanDeps] Use an options struct for the scanning service
Upcoming patches will be adding more options to this constructor which will end up requiring lots of test changes to handle new default arguments. This uses a struct instead so that only the settings relevant to the test can be set. This also avoids the problem of the meaning of a bool argument changing.
1 parent 6a89439 commit acf3193

File tree

4 files changed

+41
-36
lines changed

4 files changed

+41
-36
lines changed

clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,50 +78,56 @@ enum class ScanningOptimizations {
7878

7979
#undef DSS_LAST_BITMASK_ENUM
8080

81+
struct DependencyScanningServiceOptions {
82+
DependencyScanningServiceOptions(ScanningMode Mode,
83+
ScanningOutputFormat Format)
84+
: Mode(Mode), Format(Format) {}
85+
86+
ScanningMode Mode;
87+
ScanningOutputFormat Format;
88+
/// How to optimize the modules' command-line arguments.
89+
ScanningOptimizations OptimizeArgs = ScanningOptimizations::Default;
90+
/// Whether to set up command-lines to load PCM files eagerly.
91+
bool EagerLoadModules = false;
92+
/// Whether to trace VFS accesses.
93+
bool TraceVFS = false;
94+
std::time_t BuildSessionTimestamp =
95+
llvm::sys::toTimeT(std::chrono::system_clock::now());
96+
};
97+
8198
/// The dependency scanning service contains shared configuration and state that
8299
/// is used by the individual dependency scanning workers.
83100
class DependencyScanningService {
84101
public:
85-
DependencyScanningService(
86-
ScanningMode Mode, ScanningOutputFormat Format,
87-
ScanningOptimizations OptimizeArgs = ScanningOptimizations::Default,
88-
bool EagerLoadModules = false, bool TraceVFS = false,
89-
std::time_t BuildSessionTimestamp =
90-
llvm::sys::toTimeT(std::chrono::system_clock::now()));
102+
DependencyScanningService(const DependencyScanningServiceOptions &Options);
91103

92-
ScanningMode getMode() const { return Mode; }
104+
ScanningMode getMode() const { return Options.Mode; }
93105

94-
ScanningOutputFormat getFormat() const { return Format; }
106+
ScanningOutputFormat getFormat() const { return Options.Format; }
95107

96-
ScanningOptimizations getOptimizeArgs() const { return OptimizeArgs; }
108+
ScanningOptimizations getOptimizeArgs() const { return Options.OptimizeArgs; }
97109

98-
bool shouldEagerLoadModules() const { return EagerLoadModules; }
110+
bool shouldEagerLoadModules() const { return Options.EagerLoadModules; }
99111

100-
bool shouldTraceVFS() const { return TraceVFS; }
112+
bool shouldTraceVFS() const { return Options.TraceVFS; }
101113

102114
DependencyScanningFilesystemSharedCache &getSharedCache() {
103115
return SharedCache;
104116
}
105117

106118
ModuleCacheEntries &getModuleCacheEntries() { return ModCacheEntries; }
107119

108-
std::time_t getBuildSessionTimestamp() const { return BuildSessionTimestamp; }
120+
std::time_t getBuildSessionTimestamp() const {
121+
return Options.BuildSessionTimestamp;
122+
}
109123

110124
private:
111-
const ScanningMode Mode;
112-
const ScanningOutputFormat Format;
113-
/// Whether to optimize the modules' command-line arguments.
114-
const ScanningOptimizations OptimizeArgs;
115-
/// Whether to set up command-lines to load PCM files eagerly.
116-
const bool EagerLoadModules;
117-
/// Whether to trace VFS accesses.
118-
const bool TraceVFS;
125+
const DependencyScanningServiceOptions Options;
126+
119127
/// The global file system cache.
120128
DependencyScanningFilesystemSharedCache SharedCache;
121129
/// The global module cache entries.
122130
ModuleCacheEntries ModCacheEntries;
123-
/// The build session timestamp.
124-
std::time_t BuildSessionTimestamp;
125131
};
126132

127133
} // end namespace dependencies

clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,5 @@ using namespace tooling;
1313
using namespace dependencies;
1414

1515
DependencyScanningService::DependencyScanningService(
16-
ScanningMode Mode, ScanningOutputFormat Format,
17-
ScanningOptimizations OptimizeArgs, bool EagerLoadModules, bool TraceVFS,
18-
std::time_t BuildSessionTimestamp)
19-
: Mode(Mode), Format(Format), OptimizeArgs(OptimizeArgs),
20-
EagerLoadModules(EagerLoadModules), TraceVFS(TraceVFS),
21-
BuildSessionTimestamp(BuildSessionTimestamp) {}
16+
const DependencyScanningServiceOptions &Options)
17+
: Options(Options) {}

clang/tools/clang-scan-deps/ClangScanDeps.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,11 @@ int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) {
11711171
});
11721172
};
11731173

1174-
DependencyScanningService Service(ScanMode, Format, OptimizeArgs,
1175-
EagerLoadModules, /*TraceVFS=*/Verbose);
1174+
DependencyScanningServiceOptions Options{ScanMode, Format};
1175+
Options.OptimizeArgs = OptimizeArgs;
1176+
Options.EagerLoadModules = EagerLoadModules;
1177+
Options.TraceVFS = Verbose;
1178+
DependencyScanningService Service(Options);
11761179

11771180
llvm::Timer T;
11781181
T.startTimer();

clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ TEST(DependencyScanner, ScanDepsWithFS) {
231231
VFS->addFile(TestPath, 0,
232232
llvm::MemoryBuffer::getMemBuffer("#include \"header.h\"\n"));
233233

234-
DependencyScanningService Service(ScanningMode::DependencyDirectivesScan,
235-
ScanningOutputFormat::Make);
234+
DependencyScanningService Service(
235+
{ScanningMode::DependencyDirectivesScan, ScanningOutputFormat::Make});
236236
DependencyScanningTool ScanTool(Service, VFS);
237237

238238
std::string DepFile;
@@ -289,8 +289,8 @@ TEST(DependencyScanner, ScanDepsWithModuleLookup) {
289289

290290
auto InterceptFS = llvm::makeIntrusiveRefCnt<InterceptorFS>(VFS);
291291

292-
DependencyScanningService Service(ScanningMode::DependencyDirectivesScan,
293-
ScanningOutputFormat::Make);
292+
DependencyScanningService Service(
293+
{ScanningMode::DependencyDirectivesScan, ScanningOutputFormat::Make});
294294
DependencyScanningTool ScanTool(Service, InterceptFS);
295295

296296
// This will fail with "fatal error: module 'Foo' not found" but it doesn't
@@ -321,8 +321,8 @@ TEST(DependencyScanner, ScanDepsWithDiagConsumer) {
321321
llvm::MemoryBuffer::getMemBuffer("#include \"header.h\"\n"));
322322
VFS->addFile(AsmPath, 0, llvm::MemoryBuffer::getMemBuffer(""));
323323

324-
DependencyScanningService Service(ScanningMode::DependencyDirectivesScan,
325-
ScanningOutputFormat::Make);
324+
DependencyScanningService Service(
325+
{ScanningMode::DependencyDirectivesScan, ScanningOutputFormat::Make});
326326
DependencyScanningWorker Worker(Service, VFS);
327327

328328
llvm::DenseSet<ModuleID> AlreadySeen;

0 commit comments

Comments
 (0)