Parcourir la source

cmFileTimeComparison: use std::string arguments

Vitaly Stakhovsky il y a 6 ans
Parent
commit
2fc69ba0b3

+ 1 - 2
Source/CTest/cmCTestBuildHandler.cxx

@@ -513,8 +513,7 @@ public:
     // Order files by modification time.  Use lexicographic order
     // among files with the same time.
     int result;
-    if (this->FTC->FileTimeCompare(l.c_str(), r.c_str(), &result) &&
-        result != 0) {
+    if (this->FTC->FileTimeCompare(l, r, &result) && result != 0) {
       return result < 0;
     }
     return l < r;

+ 4 - 4
Source/cmDepends.cxx

@@ -156,8 +156,8 @@ bool cmDepends::CheckDependencies(
     // * if the depender does not exist, but the dependee is newer than the
     //   depends file
     bool regenerate = false;
-    const char* dependee = this->Dependee + 1;
-    const char* depender = this->Depender;
+    const std::string dependee(this->Dependee + 1);
+    const std::string depender(this->Depender);
     if (currentDependencies != nullptr) {
       currentDependencies->push_back(dependee);
     }
@@ -195,8 +195,8 @@ bool cmDepends::CheckDependencies(
         // The dependee exists, but the depender doesn't. Regenerate if the
         // internalDepends file is older than the dependee.
         int result = 0;
-        if ((!this->FileComparison->FileTimeCompare(
-               internalDependsFileName.c_str(), dependee, &result) ||
+        if ((!this->FileComparison->FileTimeCompare(internalDependsFileName,
+                                                    dependee, &result) ||
              result < 0)) {
           // The depends-file is older than the dependee.
           regenerate = true;

+ 1 - 2
Source/cmDependsC.cxx

@@ -268,8 +268,7 @@ void cmDependsC::ReadCacheFile()
       haveFileName = true;
       int newer = 0;
       cmFileTimeComparison comp;
-      bool res = comp.FileTimeCompare(this->CacheFileName.c_str(),
-                                      line.c_str(), &newer);
+      bool res = comp.FileTimeCompare(this->CacheFileName, line, &newer);
 
       if (res && newer == 1) // cache is newer than the parsed file
       {

+ 15 - 12
Source/cmFileTimeComparison.cxx

@@ -21,9 +21,10 @@ class cmFileTimeComparisonInternal
 {
 public:
   // Internal comparison method.
-  inline bool FileTimeCompare(const char* f1, const char* f2, int* result);
+  inline bool FileTimeCompare(const std::string& f1, const std::string& f2,
+                              int* result);
 
-  bool FileTimesDiffer(const char* f1, const char* f2);
+  bool FileTimesDiffer(const std::string& f1, const std::string& f2);
 
 private:
   typedef std::unordered_map<std::string, cmFileTimeComparison_Type>
@@ -31,14 +32,14 @@ private:
   FileStatsMap Files;
 
   // Internal methods to lookup and compare modification times.
-  inline bool Stat(const char* fname, cmFileTimeComparison_Type* st);
+  inline bool Stat(const std::string& fname, cmFileTimeComparison_Type* st);
   inline int Compare(cmFileTimeComparison_Type* st1,
                      cmFileTimeComparison_Type* st2);
   inline bool TimesDiffer(cmFileTimeComparison_Type* st1,
                           cmFileTimeComparison_Type* st2);
 };
 
-bool cmFileTimeComparisonInternal::Stat(const char* fname,
+bool cmFileTimeComparisonInternal::Stat(const std::string& fname,
                                         cmFileTimeComparison_Type* st)
 {
   // Use the stored time if available.
@@ -51,7 +52,7 @@ bool cmFileTimeComparisonInternal::Stat(const char* fname,
 
 #if !defined(_WIN32) || defined(__CYGWIN__)
   // POSIX version.  Use the stat function.
-  int res = ::stat(fname, st);
+  int res = ::stat(fname.c_str(), st);
   if (res != 0) {
     return false;
   }
@@ -83,13 +84,14 @@ cmFileTimeComparison::~cmFileTimeComparison()
   delete this->Internals;
 }
 
-bool cmFileTimeComparison::FileTimeCompare(const char* f1, const char* f2,
-                                           int* result)
+bool cmFileTimeComparison::FileTimeCompare(const std::string& f1,
+                                           const std::string& f2, int* result)
 {
   return this->Internals->FileTimeCompare(f1, f2, result);
 }
 
-bool cmFileTimeComparison::FileTimesDiffer(const char* f1, const char* f2)
+bool cmFileTimeComparison::FileTimesDiffer(const std::string& f1,
+                                           const std::string& f2)
 {
   return this->Internals->FileTimesDiffer(f1, f2);
 }
@@ -199,8 +201,9 @@ bool cmFileTimeComparisonInternal::TimesDiffer(cmFileTimeComparison_Type* s1,
 #endif
 }
 
-bool cmFileTimeComparisonInternal::FileTimeCompare(const char* f1,
-                                                   const char* f2, int* result)
+bool cmFileTimeComparisonInternal::FileTimeCompare(const std::string& f1,
+                                                   const std::string& f2,
+                                                   int* result)
 {
   // Get the modification time for each file.
   cmFileTimeComparison_Type s1;
@@ -215,8 +218,8 @@ bool cmFileTimeComparisonInternal::FileTimeCompare(const char* f1,
   return false;
 }
 
-bool cmFileTimeComparisonInternal::FileTimesDiffer(const char* f1,
-                                                   const char* f2)
+bool cmFileTimeComparisonInternal::FileTimesDiffer(const std::string& f1,
+                                                   const std::string& f2)
 {
   // Get the modification time for each file.
   cmFileTimeComparison_Type s1;

+ 5 - 2
Source/cmFileTimeComparison.h

@@ -5,6 +5,8 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
+#include <string>
+
 class cmFileTimeComparisonInternal;
 
 /** \class cmFileTimeComparison
@@ -24,13 +26,14 @@ public:
    *  When true is returned, result has -1, 0, +1 for
    *  f1 older, same, or newer than f2.
    */
-  bool FileTimeCompare(const char* f1, const char* f2, int* result);
+  bool FileTimeCompare(const std::string& f1, const std::string& f2,
+                       int* result);
 
   /**
    *  Compare file modification times.  Return true unless both files
    *  exist and have modification times less than 1 second apart.
    */
-  bool FileTimesDiffer(const char* f1, const char* f2);
+  bool FileTimesDiffer(const std::string& f1, const std::string& f2);
 
 protected:
   cmFileTimeComparisonInternal* Internals;

+ 2 - 4
Source/cmLocalUnixMakefileGenerator3.cxx

@@ -1278,8 +1278,7 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(
     this->GlobalGenerator->GetCMakeInstance()->GetFileComparison();
   {
     int result;
-    if (!ftc->FileTimeCompare(internalDependFile.c_str(), tgtInfo.c_str(),
-                              &result) ||
+    if (!ftc->FileTimeCompare(internalDependFile, tgtInfo, &result) ||
         result < 0) {
       if (verbose) {
         std::ostringstream msg;
@@ -1299,8 +1298,7 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(
   dirInfoFile += "/CMakeDirectoryInformation.cmake";
   {
     int result;
-    if (!ftc->FileTimeCompare(internalDependFile.c_str(), dirInfoFile.c_str(),
-                              &result) ||
+    if (!ftc->FileTimeCompare(internalDependFile, dirInfoFile, &result) ||
         result < 0) {
       if (verbose) {
         std::ostringstream msg;

+ 5 - 8
Source/cmake.cxx

@@ -2146,8 +2146,7 @@ int cmake::CheckBuildSystem()
   std::string dep_newest = *dep++;
   for (; dep != depends.end(); ++dep) {
     int result = 0;
-    if (this->FileComparison->FileTimeCompare(dep_newest.c_str(), dep->c_str(),
-                                              &result)) {
+    if (this->FileComparison->FileTimeCompare(dep_newest, *dep, &result)) {
       if (result < 0) {
         dep_newest = *dep;
       }
@@ -2166,8 +2165,7 @@ int cmake::CheckBuildSystem()
   std::string out_oldest = *out++;
   for (; out != outputs.end(); ++out) {
     int result = 0;
-    if (this->FileComparison->FileTimeCompare(out_oldest.c_str(), out->c_str(),
-                                              &result)) {
+    if (this->FileComparison->FileTimeCompare(out_oldest, *out, &result)) {
       if (result > 0) {
         out_oldest = *out;
       }
@@ -2184,8 +2182,8 @@ int cmake::CheckBuildSystem()
   // If any output is older than any dependency then rerun.
   {
     int result = 0;
-    if (!this->FileComparison->FileTimeCompare(out_oldest.c_str(),
-                                               dep_newest.c_str(), &result) ||
+    if (!this->FileComparison->FileTimeCompare(out_oldest, dep_newest,
+                                               &result) ||
         result < 0) {
       if (verbose) {
         std::ostringstream msg;
@@ -2446,8 +2444,7 @@ static bool cmakeCheckStampFile(const std::string& stampName, bool verbose)
   while (cmSystemTools::GetLineFromStream(fin, dep)) {
     int result;
     if (!dep.empty() && dep[0] != '#' &&
-        (!ftc.FileTimeCompare(stampDepends.c_str(), dep.c_str(), &result) ||
-         result < 0)) {
+        (!ftc.FileTimeCompare(stampDepends, dep, &result) || result < 0)) {
       // The stamp depends file is older than this dependency.  The
       // build system is really out of date.
       std::cout << "CMake is re-running because " << stampName