[Cmake-commits] [cmake-commits] king committed cmDependsC.cxx 1.34 1.35 cmDependsC.h 1.21 1.22

cmake-commits at cmake.org cmake-commits at cmake.org
Wed May 14 11:54:34 EDT 2008


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

Modified Files:
	cmDependsC.cxx cmDependsC.h 
Log Message:
ENH: Teach cmDependsC about user-configured macro transformations.

  - Syntax is SOME_MACRO(%)=value-with-%
  - Later we will configure these with target and directory properties.
  - See issue #6648.


Index: cmDependsC.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmDependsC.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -C 2 -d -r1.21 -r1.22
*** cmDependsC.h	8 May 2008 14:09:14 -0000	1.21
--- cmDependsC.h	14 May 2008 15:54:32 -0000	1.22
***************
*** 60,63 ****
--- 60,72 ----
    std::string IncludeRegexComplainString;
  
+   // Regex to transform #include lines.
+   std::string IncludeRegexTransformString;
+   cmsys::RegularExpression IncludeRegexTransform;
+   typedef std::map<cmStdString, cmStdString> TransformRulesType;
+   TransformRulesType TransformRules;
+   void SetupTransforms();
+   void ParseTransform(std::string const& xform);
+   void TransformLine(std::string& line);
+ 
  public:
    // Data structures for dependency graph walk.

Index: cmDependsC.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmDependsC.cxx,v
retrieving revision 1.34
retrieving revision 1.35
diff -C 2 -d -r1.34 -r1.35
*** cmDependsC.cxx	8 May 2008 14:09:14 -0000	1.34
--- cmDependsC.cxx	14 May 2008 15:54:32 -0000	1.35
***************
*** 31,34 ****
--- 31,35 ----
  #define INCLUDE_REGEX_SCAN_MARKER "#IncludeRegexScan: "
  #define INCLUDE_REGEX_COMPLAIN_MARKER "#IncludeRegexComplain: "
+ #define INCLUDE_REGEX_TRANSFORM_MARKER "#IncludeRegexTransform: "
  
  //----------------------------------------------------------------------------
***************
*** 75,78 ****
--- 76,81 ----
    this->IncludeRegexComplainString += complainRegex;
  
+   this->SetupTransforms();
+ 
    this->CacheFileName = this->TargetDirectory;
    this->CacheFileName += "/";
***************
*** 342,345 ****
--- 345,355 ----
              }
            }
+         else if (line.find(INCLUDE_REGEX_TRANSFORM_MARKER) == 0)
+           {
+           if (line != this->IncludeRegexTransformString)
+             {
+             return;
+             }
+           }
          }
        }
***************
*** 376,379 ****
--- 386,390 ----
    cacheOut << this->IncludeRegexScanString << "\n\n";
    cacheOut << this->IncludeRegexComplainString << "\n\n";
+   cacheOut << this->IncludeRegexTransformString << "\n\n";
  
    for (std::map<cmStdString, cmIncludeLines*>::const_iterator fileIt=
***************
*** 416,419 ****
--- 427,436 ----
    while(cmSystemTools::GetLineFromStream(is, line))
      {
+     // Transform the line content first.
+     if(!this->TransformRules.empty())
+       {
+       this->TransformLine(line);
+       }
+ 
      // Match include directives.
      if(this->IncludeRegexLine.find(line.c_str()))
***************
*** 452,453 ****
--- 469,567 ----
      }
  }
+ 
+ //----------------------------------------------------------------------------
+ void cmDependsC::SetupTransforms()
+ {
+   // Get the transformation rules.
+   std::vector<std::string> transformRules;
+   cmMakefile* mf = this->LocalGenerator->GetMakefile();
+   if(const char* xform =
+      mf->GetDefinition("CMAKE_INCLUDE_TRANSFORMS"))
+     {
+     cmSystemTools::ExpandListArgument(xform, transformRules, true);
+     }
+   for(std::vector<std::string>::const_iterator tri = transformRules.begin();
+       tri != transformRules.end(); ++tri)
+     {
+     this->ParseTransform(*tri);
+     }
+ 
+   this->IncludeRegexTransformString = INCLUDE_REGEX_TRANSFORM_MARKER;
+   if(!this->TransformRules.empty())
+     {
+     // Construct the regular expression to match lines to be
+     // transformed.
+     std::string xform = "^([ \t]*#[ \t]*(include|import)[ \t]*)(";
+     const char* sep = "";
+     for(TransformRulesType::const_iterator tri = this->TransformRules.begin();
+         tri != this->TransformRules.end(); ++tri)
+       {
+       xform += sep;
+       xform += tri->first;
+       sep = "|";
+       }
+     xform += ")[ \t]*\\(([^),]*)\\)";
+     this->IncludeRegexTransform.compile(xform.c_str());
+ 
+     // Build a string that encodes all transformation rules and will
+     // change when rules are changed.
+     this->IncludeRegexTransformString += xform;
+     for(TransformRulesType::const_iterator tri = this->TransformRules.begin();
+         tri != this->TransformRules.end(); ++tri)
+       {
+       this->IncludeRegexTransformString += " ";
+       this->IncludeRegexTransformString += tri->first;
+       this->IncludeRegexTransformString += "(%)=";
+       this->IncludeRegexTransformString += tri->second;
+       }
+     }
+ }
+ 
+ //----------------------------------------------------------------------------
+ void cmDependsC::ParseTransform(std::string const& xform)
+ {
+   // A transform rule is of the form SOME_MACRO(%)=value-with-%
+   // We can simply separate with "(%)=".
+   std::string::size_type pos = xform.find("(%)=");
+   if(pos == xform.npos || pos == 0)
+     {
+     return;
+     }
+   std::string name = xform.substr(0, pos);
+   std::string value = xform.substr(pos+4, xform.npos);
+   this->TransformRules[name] = value;
+ }
+ 
+ //----------------------------------------------------------------------------
+ void cmDependsC::TransformLine(std::string& line)
+ {
+   // Check for a transform rule match.  Return if none.
+   if(!this->IncludeRegexTransform.find(line.c_str()))
+     {
+     return;
+     }
+   TransformRulesType::const_iterator tri =
+     this->TransformRules.find(this->IncludeRegexTransform.match(3));
+   if(tri == this->TransformRules.end())
+     {
+     return;
+     }
+ 
+   // Construct the transformed line.
+   std::string newline = this->IncludeRegexTransform.match(1);
+   std::string arg = this->IncludeRegexTransform.match(4);
+   for(const char* c = tri->second.c_str(); *c; ++c)
+     {
+     if(*c == '%')
+       {
+       newline += arg;
+       }
+     else
+       {
+       newline += *c;
+       }
+     }
+ 
+   // Return the transformed line.
+   line = newline;
+ }



More information about the Cmake-commits mailing list