浏览代码

ENH: Simplify CMAKE_INSTALL_ALWAYS implementation

This simplifies cmFileInstaller internally by storing the 'always' mark
as an instance variable instead of passing it through all method
signatures.
Brad King 16 年之前
父节点
当前提交
dc0621ba5a
共有 1 个文件被更改,包括 20 次插入27 次删除
  1. 20 27
      Source/cmFileCommand.cxx

+ 20 - 27
Source/cmFileCommand.cxx

@@ -904,15 +904,17 @@ cmFileCommand::HandleDifferentCommand(std::vector<std::string> const& args)
 struct cmFileInstaller
 struct cmFileInstaller
 {
 {
   // Methods to actually install files.
   // Methods to actually install files.
-  bool InstallFile(const char* fromFile, const char* toFile, bool always);
-  bool InstallDirectory(const char* source, const char* destination,
-                        bool always);
+  bool InstallFile(const char* fromFile, const char* toFile);
+  bool InstallDirectory(const char* source, const char* destination);
 
 
   // All instances need the file command and makefile using them.
   // All instances need the file command and makefile using them.
   cmFileInstaller(cmFileCommand* command):
   cmFileInstaller(cmFileCommand* command):
     FileCommand(command), Makefile(command->GetMakefile()),
     FileCommand(command), Makefile(command->GetMakefile()),
-    DestDirLength(0), MatchlessFiles(true)
+    Always(false), DestDirLength(0), MatchlessFiles(true)
     {
     {
+    // Check whether to copy files always or only if they have changed.
+    this->Always =
+      cmSystemTools::IsOn(cmSystemTools::GetEnv("CMAKE_INSTALL_ALWAYS"));
     // Get the current manifest.
     // Get the current manifest.
     this->Manifest =
     this->Manifest =
       this->Makefile->GetSafeDefinition("CMAKE_INSTALL_MANIFEST_FILES");
       this->Makefile->GetSafeDefinition("CMAKE_INSTALL_MANIFEST_FILES");
@@ -927,6 +929,7 @@ struct cmFileInstaller
 private:
 private:
   cmFileCommand* FileCommand;
   cmFileCommand* FileCommand;
   cmMakefile* Makefile;
   cmMakefile* Makefile;
+  bool Always;
   cmFileTimeComparison FileTimes;
   cmFileTimeComparison FileTimes;
 public:
 public:
 
 
@@ -1022,12 +1025,11 @@ public:
     }
     }
 
 
 private:
 private:
-  bool InstallSymlink(const char* fromFile, const char* toFile, bool always);
+  bool InstallSymlink(const char* fromFile, const char* toFile);
 };
 };
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-bool cmFileInstaller::InstallSymlink(const char* fromFile, const char* toFile,
-                                     bool always)
+bool cmFileInstaller::InstallSymlink(const char* fromFile, const char* toFile)
 {
 {
   // Read the original symlink.
   // Read the original symlink.
   std::string symlinkTarget;
   std::string symlinkTarget;
@@ -1043,7 +1045,7 @@ bool cmFileInstaller::InstallSymlink(const char* fromFile, const char* toFile,
   // Compare the symlink value to that at the destination if not
   // Compare the symlink value to that at the destination if not
   // always installing.
   // always installing.
   bool copy = true;
   bool copy = true;
-  if(!always)
+  if(!this->Always)
     {
     {
     std::string oldSymlinkTarget;
     std::string oldSymlinkTarget;
     if(cmSystemTools::ReadSymlink(toFile, oldSymlinkTarget))
     if(cmSystemTools::ReadSymlink(toFile, oldSymlinkTarget))
@@ -1083,8 +1085,7 @@ bool cmFileInstaller::InstallSymlink(const char* fromFile, const char* toFile,
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-bool cmFileInstaller::InstallFile(const char* fromFile, const char* toFile,
-                                  bool always)
+bool cmFileInstaller::InstallFile(const char* fromFile, const char* toFile)
 {
 {
   // Collect any properties matching this file name.
   // Collect any properties matching this file name.
   MatchProperties match_properties =
   MatchProperties match_properties =
@@ -1099,12 +1100,12 @@ bool cmFileInstaller::InstallFile(const char* fromFile, const char* toFile,
   // Short-circuit for symbolic links.
   // Short-circuit for symbolic links.
   if(cmSystemTools::FileIsSymlink(fromFile))
   if(cmSystemTools::FileIsSymlink(fromFile))
     {
     {
-    return this->InstallSymlink(fromFile, toFile, always);
+    return this->InstallSymlink(fromFile, toFile);
     }
     }
 
 
   // Determine whether we will copy the file.
   // Determine whether we will copy the file.
   bool copy = true;
   bool copy = true;
-  if(!always)
+  if(!this->Always)
     {
     {
     // If both files exist with the same time do not copy.
     // If both files exist with the same time do not copy.
     if(!this->FileTimes.FileTimesDiffer(fromFile, toFile))
     if(!this->FileTimes.FileTimesDiffer(fromFile, toFile))
@@ -1132,7 +1133,7 @@ bool cmFileInstaller::InstallFile(const char* fromFile, const char* toFile,
   this->ManifestAppend(toFile);
   this->ManifestAppend(toFile);
 
 
   // Set the file modification time of the destination file.
   // Set the file modification time of the destination file.
-  if(copy && !always)
+  if(copy && !this->Always)
     {
     {
     if (!cmSystemTools::CopyFileTime(fromFile, toFile))
     if (!cmSystemTools::CopyFileTime(fromFile, toFile))
       {
       {
@@ -1165,8 +1166,7 @@ bool cmFileInstaller::InstallFile(const char* fromFile, const char* toFile,
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 bool cmFileInstaller::InstallDirectory(const char* source,
 bool cmFileInstaller::InstallDirectory(const char* source,
-                                       const char* destination,
-                                       bool always)
+                                       const char* destination)
 {
 {
   // Collect any properties matching this directory name.
   // Collect any properties matching this directory name.
   MatchProperties match_properties =
   MatchProperties match_properties =
@@ -1181,7 +1181,7 @@ bool cmFileInstaller::InstallDirectory(const char* source,
   // Short-circuit for symbolic links.
   // Short-circuit for symbolic links.
   if(cmSystemTools::FileIsSymlink(source))
   if(cmSystemTools::FileIsSymlink(source))
     {
     {
-    return this->InstallSymlink(source, destination, always);
+    return this->InstallSymlink(source, destination);
     }
     }
 
 
   // Inform the user about this directory installation.
   // Inform the user about this directory installation.
@@ -1256,7 +1256,7 @@ bool cmFileInstaller::InstallDirectory(const char* source,
         cmsys_stl::string toDir = destination;
         cmsys_stl::string toDir = destination;
         toDir += "/";
         toDir += "/";
         toDir += dir.GetFile(fileNum);
         toDir += dir.GetFile(fileNum);
-        if(!this->InstallDirectory(fromPath.c_str(), toDir.c_str(), always))
+        if(!this->InstallDirectory(fromPath.c_str(), toDir.c_str()))
           {
           {
           return false;
           return false;
           }
           }
@@ -1267,7 +1267,7 @@ bool cmFileInstaller::InstallDirectory(const char* source,
         std::string toFile = destination;
         std::string toFile = destination;
         toFile += "/";
         toFile += "/";
         toFile += dir.GetFile(fileNum);
         toFile += dir.GetFile(fileNum);
-        if(!this->InstallFile(fromPath.c_str(), toFile.c_str(), always))
+        if(!this->InstallFile(fromPath.c_str(), toFile.c_str()))
           {
           {
           return false;
           return false;
           }
           }
@@ -2041,11 +2041,6 @@ bool cmFileCommand::DoInstall( cmFileInstaller& installer,
 {
 {
   typedef std::set<cmStdString>::const_iterator iter_type;
   typedef std::set<cmStdString>::const_iterator iter_type;
 
 
-  // Check whether files should be copied always or only if they have
-  // changed.
-  bool copy_always =
-    cmSystemTools::IsOn(cmSystemTools::GetEnv("CMAKE_INSTALL_ALWAYS"));
-
   // Handle each file listed.
   // Handle each file listed.
   for (std::vector<std::string>::size_type i = 0; i < files.size(); i ++ )
   for (std::vector<std::string>::size_type i = 0; i < files.size(); i ++ )
     {
     {
@@ -2082,8 +2077,7 @@ bool cmFileCommand::DoInstall( cmFileInstaller& installer,
           cmSystemTools::FileIsDirectory(fromFile.c_str())))
           cmSystemTools::FileIsDirectory(fromFile.c_str())))
         {
         {
         // Try installing this directory.
         // Try installing this directory.
-        if(!installer.InstallDirectory(fromFile.c_str(), toFile.c_str(),
-                                       copy_always))
+        if(!installer.InstallDirectory(fromFile.c_str(), toFile.c_str()))
           {
           {
           return false;
           return false;
           }
           }
@@ -2091,8 +2085,7 @@ bool cmFileCommand::DoInstall( cmFileInstaller& installer,
       else if(cmSystemTools::FileExists(fromFile.c_str()))
       else if(cmSystemTools::FileExists(fromFile.c_str()))
         {
         {
         // Install this file.
         // Install this file.
-        if(!installer.InstallFile(fromFile.c_str(), toFile.c_str(),
-                                  copy_always))
+        if(!installer.InstallFile(fromFile.c_str(), toFile.c_str()))
           {
           {
           return false;
           return false;
           }
           }