From 216416219ae438ec5e93a1e125298fa0b5fd64d9 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 13 Mar 2019 19:10:19 +0100 Subject: Rename cmFileTimeComparison to cmFileTimeCache The name `cmFileTimeCache` reflects the functionality of the class more appropriately. --- Source/CMakeLists.txt | 4 +-- Source/CTest/cmCTestBuildHandler.cxx | 8 ++--- Source/cmDepends.cxx | 2 +- Source/cmDepends.h | 9 ++--- Source/cmFileCopier.h | 4 +-- Source/cmFileTimeCache.cxx | 58 +++++++++++++++++++++++++++++++ Source/cmFileTimeCache.h | 52 ++++++++++++++++++++++++++++ Source/cmFileTimeComparison.cxx | 59 -------------------------------- Source/cmFileTimeComparison.h | 52 ---------------------------- Source/cmLocalUnixMakefileGenerator3.cxx | 4 +-- Source/cmake.cxx | 6 ++-- Source/cmake.h | 6 ++-- bootstrap | 2 +- 13 files changed, 131 insertions(+), 135 deletions(-) create mode 100644 Source/cmFileTimeCache.cxx create mode 100644 Source/cmFileTimeCache.h delete mode 100644 Source/cmFileTimeComparison.cxx delete mode 100644 Source/cmFileTimeComparison.h diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index f615496..596c7f5 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -238,8 +238,8 @@ set(SRCS cmFilePathChecksum.h cmFileTime.cxx cmFileTime.h - cmFileTimeComparison.cxx - cmFileTimeComparison.h + cmFileTimeCache.cxx + cmFileTimeCache.h cmFortranParserImpl.cxx cmFSPermissions.cxx cmFSPermissions.h diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index 07bc7e7..54d7705 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -5,7 +5,7 @@ #include "cmAlgorithms.h" #include "cmCTest.h" #include "cmDuration.h" -#include "cmFileTimeComparison.h" +#include "cmFileTimeCache.h" #include "cmGeneratedFileStream.h" #include "cmMakefile.h" #include "cmProcessOutput.h" @@ -503,7 +503,7 @@ void cmCTestBuildHandler::GenerateXMLHeader(cmXMLWriter& xml) class cmCTestBuildHandler::FragmentCompare { public: - FragmentCompare(cmFileTimeComparison* ftc) + FragmentCompare(cmFileTimeCache* ftc) : FTC(ftc) { } @@ -520,7 +520,7 @@ public: } private: - cmFileTimeComparison* FTC = nullptr; + cmFileTimeCache* FTC = nullptr; }; void cmCTestBuildHandler::GenerateXMLLaunched(cmXMLWriter& xml) @@ -530,7 +530,7 @@ void cmCTestBuildHandler::GenerateXMLLaunched(cmXMLWriter& xml) } // Sort XML fragments in chronological order. - cmFileTimeComparison ftc; + cmFileTimeCache ftc; FragmentCompare fragmentCompare(&ftc); typedef std::set Fragments; Fragments fragments(fragmentCompare); diff --git a/Source/cmDepends.cxx b/Source/cmDepends.cxx index c128b02..4e97af2 100644 --- a/Source/cmDepends.cxx +++ b/Source/cmDepends.cxx @@ -2,7 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmDepends.h" -#include "cmFileTimeComparison.h" +#include "cmFileTimeCache.h" #include "cmGeneratedFileStream.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" diff --git a/Source/cmDepends.h b/Source/cmDepends.h index 20c91ca..bbc79be 100644 --- a/Source/cmDepends.h +++ b/Source/cmDepends.h @@ -12,7 +12,7 @@ #include #include -class cmFileTimeComparison; +class cmFileTimeCache; class cmLocalGenerator; /** \class cmDepends @@ -72,10 +72,7 @@ public: void Clear(const std::string& file); /** Set the file comparison object */ - void SetFileComparison(cmFileTimeComparison* fc) - { - this->FileComparison = fc; - } + void SetFileComparison(cmFileTimeCache* fc) { this->FileComparison = fc; } protected: // Write dependencies for the target file to the given stream. @@ -101,7 +98,7 @@ protected: // Flag for verbose output. bool Verbose = false; - cmFileTimeComparison* FileComparison = nullptr; + cmFileTimeCache* FileComparison = nullptr; std::string Language; diff --git a/Source/cmFileCopier.h b/Source/cmFileCopier.h index a11c371..003b8f6 100644 --- a/Source/cmFileCopier.h +++ b/Source/cmFileCopier.h @@ -5,7 +5,7 @@ #include "cmConfigure.h" // IWYU pragma: keep -#include "cmFileTimeComparison.h" +#include "cmFileTimeCache.h" #include "cm_sys_stat.h" #include "cmsys/RegularExpression.hxx" @@ -28,7 +28,7 @@ protected: cmMakefile* Makefile; const char* Name; bool Always; - cmFileTimeComparison FileTimes; + cmFileTimeCache FileTimes; // Whether to install a file not matching any expression. bool MatchlessFiles; diff --git a/Source/cmFileTimeCache.cxx b/Source/cmFileTimeCache.cxx new file mode 100644 index 0000000..ff205b7 --- /dev/null +++ b/Source/cmFileTimeCache.cxx @@ -0,0 +1,58 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmFileTimeCache.h" + +#include +#include +#include + +cmFileTimeCache::cmFileTimeCache() = default; + +cmFileTimeCache::~cmFileTimeCache() = default; + +bool cmFileTimeCache::Load(std::string const& fileName, cmFileTime& fileTime) +{ + // Use the stored time if available. + { + auto fit = this->FileTimes.find(fileName); + if (fit != this->FileTimes.end()) { + fileTime = fit->second; + return true; + } + } + // Read file time from OS + if (!fileTime.Load(fileName)) { + return false; + } + // Store file time in cache + this->FileTimes[fileName] = fileTime; + return true; +} + +bool cmFileTimeCache::FileTimeCompare(std::string const& f1, + std::string const& f2, int* result) +{ + // Get the modification time for each file. + cmFileTime ft1, ft2; + if (this->Load(f1, ft1) && this->Load(f2, ft2)) { + // Compare the two modification times. + *result = ft1.Compare(ft2); + return true; + } + // No comparison available. Default to the same time. + *result = 0; + return false; +} + +bool cmFileTimeCache::FileTimesDiffer(std::string const& f1, + std::string const& f2) +{ + // Get the modification time for each file. + cmFileTime ft1, ft2; + if (this->Load(f1, ft1) && this->Load(f2, ft2)) { + // Compare the two modification times. + return ft1.DifferS(ft2); + } + // No comparison available. Default to different times. + return true; +} diff --git a/Source/cmFileTimeCache.h b/Source/cmFileTimeCache.h new file mode 100644 index 0000000..d284fdb --- /dev/null +++ b/Source/cmFileTimeCache.h @@ -0,0 +1,52 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmFileTimeCache_h +#define cmFileTimeCache_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include "cmFileTime.h" +#include +#include + +/** \class cmFileTimeCache + * \brief Caches file modification times in an internal map for fast lookups. + */ +class cmFileTimeCache +{ +public: + cmFileTimeCache(); + ~cmFileTimeCache(); + + cmFileTimeCache(const cmFileTimeCache&) = delete; + cmFileTimeCache& operator=(const cmFileTimeCache&) = delete; + + /** + * @brief Loads the file time from the cache or the file system. + * @return true on success + */ + bool Load(std::string const& fileName, cmFileTime& fileTime); + + /** + * @brief Compare file modification times. + * @return true for successful comparison and false for error. + * + * When true is returned, result has -1, 0, +1 for + * f1 older, same, or newer than f2. + */ + bool FileTimeCompare(std::string const& f1, std::string const& f2, + int* result); + + /** + * @brief Compare file modification times. + * @return true unless both files exist and have modification times less + * than 1 second apart. + */ + bool FileTimesDiffer(std::string const& f1, std::string const& f2); + +private: + typedef std::unordered_map FileTimeMap; + FileTimeMap FileTimes; +}; + +#endif diff --git a/Source/cmFileTimeComparison.cxx b/Source/cmFileTimeComparison.cxx deleted file mode 100644 index 2115029..0000000 --- a/Source/cmFileTimeComparison.cxx +++ /dev/null @@ -1,59 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#include "cmFileTimeComparison.h" - -#include -#include -#include - -cmFileTimeComparison::cmFileTimeComparison() = default; - -cmFileTimeComparison::~cmFileTimeComparison() = default; - -bool cmFileTimeComparison::Load(std::string const& fileName, - cmFileTime& fileTime) -{ - // Use the stored time if available. - { - auto fit = this->FileTimes.find(fileName); - if (fit != this->FileTimes.end()) { - fileTime = fit->second; - return true; - } - } - // Read file time from OS - if (!fileTime.Load(fileName)) { - return false; - } - // Store file time in cache - this->FileTimes[fileName] = fileTime; - return true; -} - -bool cmFileTimeComparison::FileTimeCompare(std::string const& f1, - std::string const& f2, int* result) -{ - // Get the modification time for each file. - cmFileTime ft1, ft2; - if (this->Load(f1, ft1) && this->Load(f2, ft2)) { - // Compare the two modification times. - *result = ft1.Compare(ft2); - return true; - } - // No comparison available. Default to the same time. - *result = 0; - return false; -} - -bool cmFileTimeComparison::FileTimesDiffer(std::string const& f1, - std::string const& f2) -{ - // Get the modification time for each file. - cmFileTime ft1, ft2; - if (this->Load(f1, ft1) && this->Load(f2, ft2)) { - // Compare the two modification times. - return ft1.DifferS(ft2); - } - // No comparison available. Default to different times. - return true; -} diff --git a/Source/cmFileTimeComparison.h b/Source/cmFileTimeComparison.h deleted file mode 100644 index 80ea409..0000000 --- a/Source/cmFileTimeComparison.h +++ /dev/null @@ -1,52 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#ifndef cmFileTimeComparison_h -#define cmFileTimeComparison_h - -#include "cmConfigure.h" // IWYU pragma: keep - -#include "cmFileTime.h" -#include -#include - -/** \class cmFileTimeComparison - * \brief Caches file modification times in an internal map for fast lookups. - */ -class cmFileTimeComparison -{ -public: - cmFileTimeComparison(); - ~cmFileTimeComparison(); - - cmFileTimeComparison(const cmFileTimeComparison&) = delete; - cmFileTimeComparison& operator=(const cmFileTimeComparison&) = delete; - - /** - * @brief Loads the file time from the cache or the file system. - * @return true on success - */ - bool Load(std::string const& fileName, cmFileTime& fileTime); - - /** - * @brief Compare file modification times. - * @return true for successful comparison and false for error. - * - * When true is returned, result has -1, 0, +1 for - * f1 older, same, or newer than f2. - */ - bool FileTimeCompare(std::string const& f1, std::string const& f2, - int* result); - - /** - * @brief Compare file modification times. - * @return true unless both files exist and have modification times less - * than 1 second apart. - */ - bool FileTimesDiffer(std::string const& f1, std::string const& f2); - -private: - typedef std::unordered_map FileTimeMap; - FileTimeMap FileTimes; -}; - -#endif diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index d1093be..30b9790 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -12,7 +12,7 @@ #include "cmAlgorithms.h" #include "cmCustomCommandGenerator.h" -#include "cmFileTimeComparison.h" +#include "cmFileTimeCache.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" @@ -1273,7 +1273,7 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies( // happen when a new source file is added and CMake regenerates the // project but no other sources were touched. bool needRescanDependInfo = false; - cmFileTimeComparison* ftc = + cmFileTimeCache* ftc = this->GlobalGenerator->GetCMakeInstance()->GetFileComparison(); { int result; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 08e284e..84ac5b1 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -9,7 +9,7 @@ #include "cmDocumentationFormatter.h" #include "cmDuration.h" #include "cmExternalMakefileProjectGenerator.h" -#include "cmFileTimeComparison.h" +#include "cmFileTimeCache.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" #include "cmGlobalGeneratorFactory.h" @@ -138,7 +138,7 @@ cmake::cmake(Role role, cmState::Mode mode) this->DebugOutput = false; this->DebugTryCompile = false; this->ClearBuildSystem = false; - this->FileComparison = new cmFileTimeComparison; + this->FileComparison = new cmFileTimeCache; this->State = new cmState; this->State->SetMode(mode); @@ -2431,7 +2431,7 @@ static bool cmakeCheckStampFile(const std::string& stampName) } // Compare the stamp dependencies against the dependency file itself. - cmFileTimeComparison ftc; + cmFileTimeCache ftc; std::string dep; while (cmSystemTools::GetLineFromStream(fin, dep)) { int result; diff --git a/Source/cmake.h b/Source/cmake.h index 1ffeabc..a9aaaeb 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -26,7 +26,7 @@ class cmExternalMakefileProjectGeneratorFactory; class cmFileAPI; -class cmFileTimeComparison; +class cmFileTimeCache; class cmGlobalGenerator; class cmGlobalGeneratorFactory; class cmMakefile; @@ -329,7 +329,7 @@ public: /** * Get the file comparison class */ - cmFileTimeComparison* GetFileComparison() { return this->FileComparison; } + cmFileTimeCache* GetFileComparison() { return this->FileComparison; } // Do we want debug output during the cmake run. bool GetDebugOutput() { return this->DebugOutput; } @@ -509,7 +509,7 @@ private: std::unordered_set HeaderFileExtensionsSet; bool ClearBuildSystem; bool DebugTryCompile; - cmFileTimeComparison* FileComparison; + cmFileTimeCache* FileComparison; std::string GraphVizFile; InstalledFilesMap InstalledFiles; diff --git a/bootstrap b/bootstrap index 77293c8..537b43b 100755 --- a/bootstrap +++ b/bootstrap @@ -305,7 +305,7 @@ CMAKE_CXX_SOURCES="\ cmFileCopier \ cmFileInstaller \ cmFileTime \ - cmFileTimeComparison \ + cmFileTimeCache \ cmFindBase \ cmFindCommon \ cmFindFileCommand \ -- cgit v0.12