[Cmake-commits] [cmake-commits] king committed cmFileCommand.cxx 1.126 1.127 cmFileCommand.h 1.44 1.45

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Apr 29 08:47:15 EDT 2009


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv30877/Source

Modified Files:
	cmFileCommand.cxx cmFileCommand.h 
Log Message:
ENH: Send all file installations through one path

This creates a single cmFileInstaller method to dispatch installation of
symlinks, directories, and files.  The change removes duplicate tests of
input file type and makes the decision more consistent.


Index: cmFileCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFileCommand.h,v
retrieving revision 1.44
retrieving revision 1.45
diff -C 2 -d -r1.44 -r1.45
*** cmFileCommand.h	27 Apr 2009 17:20:54 -0000	1.44
--- cmFileCommand.h	29 Apr 2009 12:47:13 -0000	1.45
***************
*** 187,192 ****
                          std::string& destination,
                          std::string& rename,
!                         std::vector<std::string>& files,
!                         bool& optional
                         );
    bool DoInstall(cmFileInstaller& installer,
--- 187,191 ----
                          std::string& destination,
                          std::string& rename,
!                         std::vector<std::string>& files
                         );
    bool DoInstall(cmFileInstaller& installer,
***************
*** 194,199 ****
                   const std::string& rename,
                   const std::string& destination,
!                  const std::vector<std::string>& files,
!                  const bool optional
                  );
    bool HandleDownloadCommand(std::vector<std::string> const& args);
--- 193,197 ----
                   const std::string& rename,
                   const std::string& destination,
!                  const std::vector<std::string>& files
                  );
    bool HandleDownloadCommand(std::vector<std::string> const& args);

Index: cmFileCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFileCommand.cxx,v
retrieving revision 1.126
retrieving revision 1.127
diff -C 2 -d -r1.126 -r1.127
*** cmFileCommand.cxx	29 Apr 2009 12:47:04 -0000	1.126
--- cmFileCommand.cxx	29 Apr 2009 12:47:13 -0000	1.127
***************
*** 904,915 ****
  struct cmFileInstaller
  {
-   // Methods to actually install files.
-   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.
    cmFileInstaller(cmFileCommand* command):
      FileCommand(command), Makefile(command->GetMakefile()),
!     Always(false), DestDirLength(0), MatchlessFiles(true)
      {
      // Check whether to copy files always or only if they have changed.
--- 904,911 ----
  struct cmFileInstaller
  {
    // All instances need the file command and makefile using them.
    cmFileInstaller(cmFileCommand* command):
      FileCommand(command), Makefile(command->GetMakefile()),
!     Always(false), Optional(false), DestDirLength(0), MatchlessFiles(true)
      {
      // Check whether to copy files always or only if they have changed.
***************
*** 933,936 ****
--- 929,933 ----
    cmFileTimeComparison FileTimes;
  public:
+   bool Optional;
  
    // The length of the destdir setting.
***************
*** 965,970 ****
  
    // Get the properties from rules matching this input file.
!   MatchProperties CollectMatchProperties(const char* file,
!                                          bool isDirectory)
      {
      // Match rules are case-insensitive on some platforms.
--- 962,966 ----
  
    // Get the properties from rules matching this input file.
!   MatchProperties CollectMatchProperties(const char* file)
      {
      // Match rules are case-insensitive on some platforms.
***************
*** 987,993 ****
          }
        }
!     if(!matched && !this->MatchlessFiles && !isDirectory)
        {
!       result.Exclude = true;
        }
      return result;
--- 983,989 ----
          }
        }
!     if(!matched && !this->MatchlessFiles)
        {
!       result.Exclude = !cmSystemTools::FileIsDirectory(file);
        }
      return result;
***************
*** 1039,1045 ****
--- 1035,1094 ----
  private:
    bool InstallSymlink(const char* fromFile, const char* toFile);
+ public:
+   bool InstallFile(const char* fromFile, const char* toFile,
+                    MatchProperties const& match_properties);
+   bool InstallDirectory(const char* source, const char* destination,
+                         MatchProperties const& match_properties);
+   bool Install(const char* fromFile, const char* toFile);
  };
  
  //----------------------------------------------------------------------------
+ bool cmFileInstaller::Install(const char* fromFile, const char* toFile)
+ {
+   if(!*fromFile)
+     {
+     cmOStringStream e;
+     e << "INSTALL encountered an empty string input file name.";
+     this->FileCommand->SetError(e.str().c_str());
+     return false;
+     }
+ 
+   // Collect any properties matching this file name.
+   MatchProperties match_properties = this->CollectMatchProperties(fromFile);
+ 
+   // Skip the file if it is excluded.
+   if(match_properties.Exclude)
+     {
+     return true;
+     }
+ 
+   if(cmSystemTools::SameFile(fromFile, toFile))
+     {
+     return true;
+     }
+   else if(cmSystemTools::FileIsSymlink(fromFile))
+     {
+     return this->InstallSymlink(fromFile, toFile);
+     }
+   else if(cmSystemTools::FileIsDirectory(fromFile))
+     {
+     return this->InstallDirectory(fromFile, toFile, match_properties);
+     }
+   else if(cmSystemTools::FileExists(fromFile))
+     {
+     return this->InstallFile(fromFile, toFile, match_properties);
+     }
+   else if(!this->Optional)
+     {
+     // The input file does not exist and installation is not optional.
+     cmOStringStream e;
+     e << "INSTALL cannot find file \"" << fromFile << "\" to install.";
+     this->FileCommand->SetError(e.str().c_str());
+     return false;
+     }
+   return true;
+ }
+ 
+ //----------------------------------------------------------------------------
  bool cmFileInstaller::InstallSymlink(const char* fromFile, const char* toFile)
  {
***************
*** 1098,1119 ****
  
  //----------------------------------------------------------------------------
! bool cmFileInstaller::InstallFile(const char* fromFile, const char* toFile)
  {
-   // Collect any properties matching this file name.
-   MatchProperties match_properties =
-     this->CollectMatchProperties(fromFile, false);
- 
-   // Skip the file if it is excluded.
-   if(match_properties.Exclude)
-     {
-     return true;
-     }
- 
-   // Short-circuit for symbolic links.
-   if(cmSystemTools::FileIsSymlink(fromFile))
-     {
-     return this->InstallSymlink(fromFile, toFile);
-     }
- 
    // Determine whether we will copy the file.
    bool copy = true;
--- 1147,1153 ----
  
  //----------------------------------------------------------------------------
! bool cmFileInstaller::InstallFile(const char* fromFile, const char* toFile,
!                                   MatchProperties const& match_properties)
  {
    // Determine whether we will copy the file.
    bool copy = true;
***************
*** 1171,1192 ****
  //----------------------------------------------------------------------------
  bool cmFileInstaller::InstallDirectory(const char* source,
!                                        const char* destination)
  {
-   // Collect any properties matching this directory name.
-   MatchProperties match_properties =
-     this->CollectMatchProperties(source, true);
- 
-   // Skip the directory if it is excluded.
-   if(match_properties.Exclude)
-     {
-     return true;
-     }
- 
-   // Short-circuit for symbolic links.
-   if(cmSystemTools::FileIsSymlink(source))
-     {
-     return this->InstallSymlink(source, destination);
-     }
- 
    // Inform the user about this directory installation.
    std::string message = "Installing: ";
--- 1205,1211 ----
  //----------------------------------------------------------------------------
  bool cmFileInstaller::InstallDirectory(const char* source,
!                                        const char* destination,
!                                       MatchProperties const& match_properties)
  {
    // Inform the user about this directory installation.
    std::string message = "Installing: ";
***************
*** 1255,1278 ****
        fromPath += "/";
        fromPath += dir.GetFile(fileNum);
!       if(cmSystemTools::FileIsDirectory(fromPath.c_str()))
!         {
!         cmsys_stl::string toDir = destination;
!         toDir += "/";
!         toDir += dir.GetFile(fileNum);
!         if(!this->InstallDirectory(fromPath.c_str(), toDir.c_str()))
!           {
!           return false;
!           }
!         }
!       else
          {
!         // Install this file.
!         std::string toFile = destination;
!         toFile += "/";
!         toFile += dir.GetFile(fileNum);
!         if(!this->InstallFile(fromPath.c_str(), toFile.c_str()))
!           {
!           return false;
!           }
          }
        }
--- 1274,1283 ----
        fromPath += "/";
        fromPath += dir.GetFile(fileNum);
!       std::string toPath = destination;
!       toPath += "/";
!       toPath += dir.GetFile(fileNum);
!       if(!this->Install(fromPath.c_str(), toPath.c_str()))
          {
!         return false;
          }
        }
***************
*** 1729,1740 ****
    int itype = cmTarget::INSTALL_FILES;
  
-   bool optional = false;
    bool result = this->ParseInstallArgs(args, installer,
!                                        itype, rename, destination, files,
!                                        optional);
    if (result == true)
      {
      result = this->DoInstall(installer,
!                              itype, rename, destination, files, optional);
      }
    return result;
--- 1734,1743 ----
    int itype = cmTarget::INSTALL_FILES;
  
    bool result = this->ParseInstallArgs(args, installer,
!                                        itype, rename, destination, files);
    if (result == true)
      {
      result = this->DoInstall(installer,
!                              itype, rename, destination, files);
      }
    return result;
***************
*** 1747,1752 ****
                                  std::string& rename,
                                  std::string& destination,
!                                 std::vector<std::string>& files,
!                                 bool& optional)
  {
      std::string stype = "FILES";
--- 1750,1754 ----
                                  std::string& rename,
                                  std::string& destination,
!                                 std::vector<std::string>& files)
  {
      std::string stype = "FILES";
***************
*** 1796,1800 ****
            {
            i++;
!           optional = true;
            }
          doing = DoingNone;
--- 1798,1802 ----
            {
            i++;
!           installer.Optional = true;
            }
          doing = DoingNone;
***************
*** 2031,2036 ****
                                const std::string& rename,
                                const std::string& destination,
!                               const std::vector<std::string>& files,
!                               const bool optional)
  {
    typedef std::set<cmStdString>::const_iterator iter_type;
--- 2033,2037 ----
                                const std::string& rename,
                                const std::string& destination,
!                               const std::vector<std::string>& files)
  {
    typedef std::set<cmStdString>::const_iterator iter_type;
***************
*** 2064,2097 ****
        }
  
!     std::string message;
!     if(!cmSystemTools::SameFile(fromFile.c_str(), toFile.c_str()))
        {
!       if(itype == cmTarget::INSTALL_DIRECTORY &&
!          (fromFile.empty() ||
!           cmSystemTools::FileIsDirectory(fromFile.c_str())))
!         {
!         // Try installing this directory.
!         if(!installer.InstallDirectory(fromFile.c_str(), toFile.c_str()))
!           {
!           return false;
!           }
!         }
!       else if(cmSystemTools::FileExists(fromFile.c_str()))
!         {
!         // Install this file.
!         if(!installer.InstallFile(fromFile.c_str(), toFile.c_str()))
!           {
!           return false;
!           }
!         }
!       else if(!optional)
          {
-         // The input file does not exist and installation is not optional.
-         cmOStringStream e;
-         e << "INSTALL cannot find file \"" << fromFile << "\" to install.";
-         this->SetError(e.str().c_str());
          return false;
          }
        }
      }
  
--- 2065,2080 ----
        }
  
!     if(itype == cmTarget::INSTALL_DIRECTORY && fromFile.empty())
        {
!       if(!installer.InstallDirectory(fromFile.c_str(), toFile.c_str(),
!                                      cmFileInstaller::MatchProperties()))
          {
          return false;
          }
        }
+     else if(!installer.Install(fromFile.c_str(), toFile.c_str()))
+       {
+       return false;
+       }
      }
  



More information about the Cmake-commits mailing list