diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h --- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h +++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h @@ -50,7 +50,8 @@ public: DependencyScanningService(ScanningMode Mode, ScanningOutputFormat Format, bool OptimizeArgs = false, - bool EagerLoadModules = false); + bool EagerLoadModules = false, + uint64_t BuildSessionTimestamp = 0); ScanningMode getMode() const { return Mode; } @@ -60,6 +61,8 @@ bool shouldEagerLoadModules() const { return EagerLoadModules; } + uint64_t getBuildSessionTimestamp() const { return BuildSessionTimestamp; } + DependencyScanningFilesystemSharedCache &getSharedCache() { return SharedCache; } @@ -73,6 +76,8 @@ bool OptimizeArgs; /// Whether to set up command-lines to load PCM files eagerly. bool EagerLoadModules; + /// The build session timestamp. + uint64_t BuildSessionTimestamp; /// The global file system cache. DependencyScanningFilesystemSharedCache SharedCache; }; diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp @@ -9,15 +9,21 @@ #include "clang/Tooling/DependencyScanning/DependencyScanningService.h" #include "llvm/Support/TargetSelect.h" +#include + using namespace clang; using namespace tooling; using namespace dependencies; DependencyScanningService::DependencyScanningService( ScanningMode Mode, ScanningOutputFormat Format, bool OptimizeArgs, - bool EagerLoadModules) + bool EagerLoadModules, uint64_t BuildSessionTimestamp) : Mode(Mode), Format(Format), OptimizeArgs(OptimizeArgs), - EagerLoadModules(EagerLoadModules) { + EagerLoadModules(EagerLoadModules), + BuildSessionTimestamp( + BuildSessionTimestamp != 0 + ? BuildSessionTimestamp + : std::chrono::system_clock::now().time_since_epoch().count()) { // Initialize targets for object file support. llvm::InitializeAllTargets(); llvm::InitializeAllTargetMCs(); diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp @@ -182,6 +182,12 @@ ScanInstance.getFrontendOpts().ModulesShareFileManager = false; ScanInstance.getHeaderSearchOpts().ModuleFormat = "raw"; + ScanInstance.getHeaderSearchOpts().ModulesValidateOncePerBuildSession = + true; + // FIXME: Consider diagnosing when this overwrites existing timestamp. + ScanInstance.getHeaderSearchOpts().BuildSessionTimestamp = + Service.getBuildSessionTimestamp(); + ScanInstance.setFileManager(FileMgr); // Support for virtual file system overlays. FileMgr->setVirtualFileSystem(createVFSFromCompilerInvocation(