[Cmake-commits] [cmake-commits] king committed cmSourceFileLocation.cxx 1.7 1.8 cmSourceFileLocation.h 1.2 1.3

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Aug 5 13:27:03 EDT 2008


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

Modified Files:
	cmSourceFileLocation.cxx cmSourceFileLocation.h 
Log Message:
BUG: Fix matching of ambiguous sf extensions.

A name with an ambiguous extension may only match an unambiguous name
that is extended by one of the fixed set of extensions tried when
finding the source file on disk.  This rule makes matching of source
files with ambiguous extensions much less aggressive but still
sufficient.


Index: cmSourceFileLocation.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSourceFileLocation.cxx,v
retrieving revision 1.7
retrieving revision 1.8
diff -C 2 -d -r1.7 -r1.8
*** cmSourceFileLocation.cxx	30 Jul 2008 15:06:11 -0000	1.7
--- cmSourceFileLocation.cxx	5 Aug 2008 17:27:01 -0000	1.8
***************
*** 153,180 ****
  
  //----------------------------------------------------------------------------
  bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc)
  {
!   if(this->AmbiguousExtension || loc.AmbiguousExtension)
      {
!     // Need to compare without the file extension.
!     std::string thisName;
!     if(this->AmbiguousExtension)
!       {
!       thisName = this->Name;
!       }
!     else
!       {
!       thisName = cmSystemTools::GetFilenameWithoutLastExtension(this->Name);
!       }
!     std::string locName;
!     if(loc.AmbiguousExtension)
        {
!       locName = loc.Name;
        }
!     else
        {
!       locName = cmSystemTools::GetFilenameWithoutLastExtension(loc.Name);
        }
!     if(thisName != locName)
        {
        return false;
--- 153,218 ----
  
  //----------------------------------------------------------------------------
+ bool
+ cmSourceFileLocation
+ ::MatchesAmbiguousExtension(cmSourceFileLocation const& loc) const
+ {
+   // This location's extension is not ambiguous but loc's extension
+   // is.  See if the names match as-is.
+   if(this->Name == loc.Name)
+     {
+     return true;
+     }
+ 
+   // Check if loc's name could possibly be extended to our name by
+   // adding an extension.
+   if(!(this->Name.size() > loc.Name.size() &&
+        this->Name.substr(0, loc.Name.size()) == loc.Name &&
+        this->Name[loc.Name.size()] == '.'))
+     {
+     return false;
+     }
+ 
+   // Only a fixed set of extensions will be tried to match a file on
+   // disk.  One of these must match if loc refers to this source file.
+   std::string ext = this->Name.substr(loc.Name.size()+1);
+   cmMakefile* mf = this->Makefile;
+   const std::vector<std::string>& srcExts = mf->GetSourceExtensions();
+   if(std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end())
+     {
+     return true;
+     }
+   const std::vector<std::string>& hdrExts = mf->GetHeaderExtensions();
+   if(std::find(hdrExts.begin(), hdrExts.end(), ext) != hdrExts.end())
+     {
+     return true;
+     }
+   return false;
+ }
+ 
+ //----------------------------------------------------------------------------
  bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc)
  {
!   if(this->AmbiguousExtension && loc.AmbiguousExtension)
      {
!     // Both extensions are ambiguous.  Since only the old fixed set of
!     // extensions will be tried, the names must match at this point to
!     // be the same file.
!     if(this->Name != loc.Name)
        {
!       return false;
        }
!     }
!   else if(this->AmbiguousExtension)
!     {
!     // Only "this" extension is ambiguous.
!     if(!loc.MatchesAmbiguousExtension(*this))
        {
!       return false;
        }
!     }
!   else if(loc.AmbiguousExtension)
!     {
!     // Only "loc" extension is ambiguous.
!     if(!this->MatchesAmbiguousExtension(loc))
        {
        return false;
***************
*** 183,187 ****
    else
      {
!     // Compare with extension.
      if(this->Name != loc.Name)
        {
--- 221,225 ----
    else
      {
!     // Neither extension is ambiguous.
      if(this->Name != loc.Name)
        {

Index: cmSourceFileLocation.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSourceFileLocation.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C 2 -d -r1.2 -r1.3
*** cmSourceFileLocation.h	18 Jun 2007 15:59:23 -0000	1.2
--- cmSourceFileLocation.h	5 Aug 2008 17:27:01 -0000	1.3
***************
*** 95,98 ****
--- 95,100 ----
    std::string Name;
  
+   bool MatchesAmbiguousExtension(cmSourceFileLocation const& loc) const;
+ 
    // Update the location with additional knowledge.
    void Update(cmSourceFileLocation const& loc);



More information about the Cmake-commits mailing list