[Cmake-commits] [cmake-commits] king committed cmSystemTools.cxx 1.370 1.371

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Apr 8 13:42:32 EDT 2008


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

Modified Files:
	cmSystemTools.cxx 
Log Message:
ENH: Update cmSystemTools::ChangeRPath to support replacing rpath values from the middle of the string.


Index: cmSystemTools.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSystemTools.cxx,v
retrieving revision 1.370
retrieving revision 1.371
diff -C 2 -d -r1.370 -r1.371
*** cmSystemTools.cxx	7 Apr 2008 14:55:52 -0000	1.370
--- cmSystemTools.cxx	8 Apr 2008 17:42:30 -0000	1.371
***************
*** 2200,2203 ****
--- 2200,2249 ----
  
  //----------------------------------------------------------------------------
+ #if defined(CMAKE_USE_ELF_PARSER)
+ std::string::size_type cmSystemToolsFindRPath(std::string const& have,
+                                               std::string const& want)
+ {
+   // Search for the desired rpath.
+   std::string::size_type pos = have.find(want);
+ 
+   // If the path is not present we are done.
+   if(pos == std::string::npos)
+     {
+     return pos;
+     }
+ 
+   // Build a regex to match a properly separated path instance.
+   std::string regex_str = "(^|:)(";
+   for(std::string::const_iterator i = want.begin(); i != want.end(); ++i)
+     {
+     int ch = *i;
+     if(!(('a' <= ch && ch <= 'z') ||
+          ('A' <= ch && ch <= 'Z') ||
+          ('0' <= ch && ch <= '9')))
+       {
+       // Escape the non-alphanumeric character.
+       regex_str += "\\";
+       }
+     // Store the character.
+     regex_str.append(1, static_cast<char>(ch));
+     }
+   regex_str += ")(:|$)";
+ 
+   // Look for the separated path.
+   cmsys::RegularExpression regex(regex_str.c_str());
+   if(regex.find(have))
+     {
+     // Return the position of the path portion.
+     return regex.start(2);
+     }
+   else
+     {
+     // The desired rpath was not found.
+     return std::string::npos;
+     }
+ }
+ #endif
+ 
+ //----------------------------------------------------------------------------
  bool cmSystemTools::ChangeRPath(std::string const& file,
                                  std::string const& oldRPath,
***************
*** 2208,2214 ****
--- 2254,2264 ----
    unsigned long rpathPosition = 0;
    unsigned long rpathSize = 0;
+   std::string rpathPrefix;
    std::string rpathSuffix;
    {
+   // Parse the ELF binary.
    cmELF elf(file.c_str());
+ 
+   // Get the RPATH or RUNPATH entry from it.
    cmELF::StringEntry const* se = elf.GetRPath();
    if(!se)
***************
*** 2216,2228 ****
      se = elf.GetRunPath();
      }
    if(se)
      {
!     // Make sure the current rpath begins with the old rpath.
!     if(se->Value.length() < oldRPath.length() ||
!        se->Value.substr(0, oldRPath.length()) != oldRPath)
        {
!       // If it begins with the new rpath instead then it is okay.
!       if(se->Value.length() >= newRPath.length() &&
!          se->Value.substr(0, newRPath.length()) == newRPath)
          {
          return true;
--- 2266,2278 ----
      se = elf.GetRunPath();
      }
+ 
    if(se)
      {
!     // Make sure the current rpath contains the old rpath.
!     std::string::size_type pos = cmSystemToolsFindRPath(se->Value, oldRPath);
!     if(pos == std::string::npos)
        {
!       // If it contains the new rpath instead then it is okay.
!       if(cmSystemToolsFindRPath(se->Value, newRPath) != std::string::npos)
          {
          return true;
***************
*** 2233,2237 ****
          e << "The current RPATH is:\n"
            << "  " << se->Value << "\n"
!           << "which does not begin with:\n"
            << "  " << oldRPath << "\n"
            << "as was expected.";
--- 2283,2287 ----
          e << "The current RPATH is:\n"
            << "  " << se->Value << "\n"
!           << "which does not contain:\n"
            << "  " << oldRPath << "\n"
            << "as was expected.";
***************
*** 2246,2250 ****
  
      // Store the part of the path we must preserve.
!     rpathSuffix = se->Value.substr(oldRPath.length(), oldRPath.npos);
      }
    else if(newRPath.empty())
--- 2296,2301 ----
  
      // Store the part of the path we must preserve.
!     rpathPrefix = se->Value.substr(0, pos);
!     rpathSuffix = se->Value.substr(pos+oldRPath.length(), oldRPath.npos);
      }
    else if(newRPath.empty())
***************
*** 2265,2269 ****
    }
    // Compute the full new rpath.
!   std::string rpath = newRPath;
    rpath += rpathSuffix;
  
--- 2316,2321 ----
    }
    // Compute the full new rpath.
!   std::string rpath = rpathPrefix;
!   rpath += newRPath;
    rpath += rpathSuffix;
  



More information about the Cmake-commits mailing list