https://github.com/Bigcheese updated https://github.com/llvm/llvm-project/pull/167964
>From 5dd550243cfda0035ebf9c19a3c8e78c6bdb9caf Mon Sep 17 00:00:00 2001 From: Michael Spencer <[email protected]> Date: Wed, 12 Nov 2025 16:23:42 -0800 Subject: [PATCH] [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. --- .../DependencyScanningService.h | 50 +++++++++++-------- .../DependencyScanningService.cpp | 8 +-- clang/tools/clang-scan-deps/ClangScanDeps.cpp | 7 ++- .../DependencyScanningWorkerTest.cpp | 4 +- .../Tooling/DependencyScannerTest.cpp | 8 +-- 5 files changed, 41 insertions(+), 36 deletions(-) diff --git a/clang/include/clang/DependencyScanning/DependencyScanningService.h b/clang/include/clang/DependencyScanning/DependencyScanningService.h index 371b862996706..0bdfee289f10c 100644 --- a/clang/include/clang/DependencyScanning/DependencyScanningService.h +++ b/clang/include/clang/DependencyScanning/DependencyScanningService.h @@ -77,26 +77,38 @@ enum class ScanningOptimizations { #undef DSS_LAST_BITMASK_ENUM +struct DependencyScanningServiceOptions { + DependencyScanningServiceOptions(ScanningMode Mode, + ScanningOutputFormat Format) + : Mode(Mode), Format(Format) {} + + ScanningMode Mode; + ScanningOutputFormat Format; + /// How to optimize the modules' command-line arguments. + ScanningOptimizations OptimizeArgs = ScanningOptimizations::Default; + /// Whether to set up command-lines to load PCM files eagerly. + bool EagerLoadModules = false; + /// Whether to trace VFS accesses. + bool TraceVFS = false; + std::time_t BuildSessionTimestamp = + llvm::sys::toTimeT(std::chrono::system_clock::now()); +}; + /// The dependency scanning service contains shared configuration and state that /// is used by the individual dependency scanning workers. class DependencyScanningService { public: - DependencyScanningService( - ScanningMode Mode, ScanningOutputFormat Format, - ScanningOptimizations OptimizeArgs = ScanningOptimizations::Default, - bool EagerLoadModules = false, bool TraceVFS = false, - std::time_t BuildSessionTimestamp = - llvm::sys::toTimeT(std::chrono::system_clock::now())); + DependencyScanningService(const DependencyScanningServiceOptions &Options); - ScanningMode getMode() const { return Mode; } + ScanningMode getMode() const { return Options.Mode; } - ScanningOutputFormat getFormat() const { return Format; } + ScanningOutputFormat getFormat() const { return Options.Format; } - ScanningOptimizations getOptimizeArgs() const { return OptimizeArgs; } + ScanningOptimizations getOptimizeArgs() const { return Options.OptimizeArgs; } - bool shouldEagerLoadModules() const { return EagerLoadModules; } + bool shouldEagerLoadModules() const { return Options.EagerLoadModules; } - bool shouldTraceVFS() const { return TraceVFS; } + bool shouldTraceVFS() const { return Options.TraceVFS; } DependencyScanningFilesystemSharedCache &getSharedCache() { return SharedCache; @@ -104,23 +116,17 @@ class DependencyScanningService { ModuleCacheEntries &getModuleCacheEntries() { return ModCacheEntries; } - std::time_t getBuildSessionTimestamp() const { return BuildSessionTimestamp; } + std::time_t getBuildSessionTimestamp() const { + return Options.BuildSessionTimestamp; + } private: - const ScanningMode Mode; - const ScanningOutputFormat Format; - /// Whether to optimize the modules' command-line arguments. - const ScanningOptimizations OptimizeArgs; - /// Whether to set up command-lines to load PCM files eagerly. - const bool EagerLoadModules; - /// Whether to trace VFS accesses. - const bool TraceVFS; + const DependencyScanningServiceOptions Options; + /// The global file system cache. DependencyScanningFilesystemSharedCache SharedCache; /// The global module cache entries. ModuleCacheEntries ModCacheEntries; - /// The build session timestamp. - std::time_t BuildSessionTimestamp; }; } // end namespace dependencies diff --git a/clang/lib/DependencyScanning/DependencyScanningService.cpp b/clang/lib/DependencyScanning/DependencyScanningService.cpp index 72f359e56d116..f08e612b7aff9 100644 --- a/clang/lib/DependencyScanning/DependencyScanningService.cpp +++ b/clang/lib/DependencyScanning/DependencyScanningService.cpp @@ -12,9 +12,5 @@ using namespace clang; using namespace dependencies; DependencyScanningService::DependencyScanningService( - ScanningMode Mode, ScanningOutputFormat Format, - ScanningOptimizations OptimizeArgs, bool EagerLoadModules, bool TraceVFS, - std::time_t BuildSessionTimestamp) - : Mode(Mode), Format(Format), OptimizeArgs(OptimizeArgs), - EagerLoadModules(EagerLoadModules), TraceVFS(TraceVFS), - BuildSessionTimestamp(BuildSessionTimestamp) {} + const DependencyScanningServiceOptions &Options) + : Options(Options) {} diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp index 256a70568a3bf..7bc540c4cea57 100644 --- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp +++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp @@ -1136,8 +1136,11 @@ int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) { }); }; - DependencyScanningService Service(ScanMode, Format, OptimizeArgs, - EagerLoadModules, /*TraceVFS=*/Verbose); + DependencyScanningServiceOptions Options{ScanMode, Format}; + Options.OptimizeArgs = OptimizeArgs; + Options.EagerLoadModules = EagerLoadModules; + Options.TraceVFS = Verbose; + DependencyScanningService Service(Options); llvm::Timer T; T.startTimer(); diff --git a/clang/unittests/DependencyScanning/DependencyScanningWorkerTest.cpp b/clang/unittests/DependencyScanning/DependencyScanningWorkerTest.cpp index 872c7effde3d3..2c268315c2176 100644 --- a/clang/unittests/DependencyScanning/DependencyScanningWorkerTest.cpp +++ b/clang/unittests/DependencyScanning/DependencyScanningWorkerTest.cpp @@ -31,8 +31,8 @@ TEST(DependencyScanner, ScanDepsWithDiagConsumer) { llvm::MemoryBuffer::getMemBuffer("#include \"header.h\"\n")); VFS->addFile(AsmPath, 0, llvm::MemoryBuffer::getMemBuffer("")); - DependencyScanningService Service(ScanningMode::DependencyDirectivesScan, - ScanningOutputFormat::Make); + DependencyScanningService Service({ScanningMode::DependencyDirectivesScan, + ScanningOutputFormat::Make}); DependencyScanningWorker Worker(Service, VFS); llvm::DenseSet<ModuleID> AlreadySeen; diff --git a/clang/unittests/Tooling/DependencyScannerTest.cpp b/clang/unittests/Tooling/DependencyScannerTest.cpp index 42d1a7b242aa9..04fcc5e91fd9b 100644 --- a/clang/unittests/Tooling/DependencyScannerTest.cpp +++ b/clang/unittests/Tooling/DependencyScannerTest.cpp @@ -228,8 +228,8 @@ TEST(DependencyScanner, ScanDepsWithFS) { VFS->addFile(TestPath, 0, llvm::MemoryBuffer::getMemBuffer("#include \"header.h\"\n")); - DependencyScanningService Service(ScanningMode::DependencyDirectivesScan, - ScanningOutputFormat::Make); + DependencyScanningService Service( + {ScanningMode::DependencyDirectivesScan, ScanningOutputFormat::Make}); DependencyScanningTool ScanTool(Service, VFS); TextDiagnosticBuffer DiagConsumer; @@ -285,8 +285,8 @@ TEST(DependencyScanner, ScanDepsWithModuleLookup) { auto InterceptFS = llvm::makeIntrusiveRefCnt<InterceptorFS>(VFS); - DependencyScanningService Service(ScanningMode::DependencyDirectivesScan, - ScanningOutputFormat::Make); + DependencyScanningService Service( + {ScanningMode::DependencyDirectivesScan, ScanningOutputFormat::Make}); DependencyScanningTool ScanTool(Service, InterceptFS); // This will fail with "fatal error: module 'Foo' not found" but it doesn't _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
