1
0
Эх сурвалжийг харах

ENH: Extended INCLUDE_REGULAR_EXPRESSION to allow selective complaints about missing dependencies.

Brad King 24 жил өмнө
parent
commit
cf82992964

+ 6 - 1
Source/cmIncludeRegularExpressionCommand.cxx

@@ -43,13 +43,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 // cmIncludeRegularExpressionCommand
 bool cmIncludeRegularExpressionCommand::InitialPass(std::vector<std::string>& args)
 {
-  if(args.size() != 1)
+  if((args.size() < 1) || (args.size() > 2))
     {
     this->SetError("called with incorrect number of arguments");
     return false;
     }
   m_Makefile->SetIncludeRegularExpression(args[0].c_str());
   
+  if(args.size() > 1)
+    {
+    m_Makefile->SetComplainRegularExpression(args[1].c_str());
+    }
+  
   return true;
 }
 

+ 7 - 3
Source/cmIncludeRegularExpressionCommand.h

@@ -96,9 +96,13 @@ public:
   virtual const char* GetFullDocumentation()
     {
     return
-      "INCLUDE_REGULAR_EXPRESSION(regex)\n"
-      "Sets the regular expression used in dependency checking.  Only\n"
-      "include files matching this regular expression will be traced.";
+      "INCLUDE_REGULAR_EXPRESSION(regex_match [regex_complain])\n"
+      "Set the regular expressions used in dependency checking.  Only files\n"
+      "matching regex_match will be traced as dependencies.  Only files\n"
+      "matching regex_complain will generate warnings if they cannot be found\n"
+      "(standard header paths are not searched).  The defaults are:\n"
+      "    regex_match    = \"^.*$\" (match everything)\n"
+      "    regex_complain = \"^$\" (match empty string only)\n";
     }
   
   cmTypeMacro(cmIncludeRegularExpressionCommand, cmCommand);

+ 19 - 30
Source/cmMakeDepend.cxx

@@ -45,7 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 cmMakeDepend::cmMakeDepend()
 {
   m_Verbose = false;
-  m_IncludeFileRegularExpression.compile("");
+  m_IncludeFileRegularExpression.compile("^.*$");
+  m_ComplainFileRegularExpression.compile("^$");
 }
 
 
@@ -71,6 +72,8 @@ void cmMakeDepend::SetMakefile(const cmMakefile* makefile)
   // Now extract the include file regular expression from the makefile.
   m_IncludeFileRegularExpression.compile(
     m_Makefile->m_IncludeFileRegularExpression.c_str());
+  m_ComplainFileRegularExpression.compile(
+    m_Makefile->m_ComplainFileRegularExpression.c_str());
   
   // Now extract any include paths from the makefile flags
   const std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
@@ -200,7 +203,16 @@ void cmMakeDepend::Depend(cmDependInformation* info)
     }
   
   // Couldn't find any dependency information.
-  cmSystemTools::Error("error cannot find dependencies for ", path);
+  if(m_ComplainFileRegularExpression.find(info->m_IncludeName.c_str()))
+    {
+    cmSystemTools::Error("error cannot find dependencies for ", path);
+    }
+  else
+    {
+    // Destroy the name of the file so that it won't be output as a
+    // dependency.
+    info->m_FullPath = "";
+    }
 }
 
 
@@ -208,6 +220,7 @@ void cmMakeDepend::Depend(cmDependInformation* info)
 // #include directives
 void cmMakeDepend::DependWalk(cmDependInformation* info, const char* file)
 {
+  cmRegularExpression includeLine("^[ \t]*#[ \t]*include[ \t]*[<\"]([^\">]+)[\">]");
   std::ifstream fin(file);
   if(!fin)
     {
@@ -216,37 +229,12 @@ void cmMakeDepend::DependWalk(cmDependInformation* info, const char* file)
     }
   
   char line[255];
-  while(!fin.eof() && !fin.fail())
+  for(fin.getline(line, 255); !fin.eof()&&!fin.fail(); fin.getline(line, 255))
     {
-    fin.getline(line, 255);
-    if(!strncmp(line, "#include", 8))
+    if(includeLine.find(line))
       {
-      // if it is an include line then create a string class
-      std::string currentline = line;
-      size_t qstart = currentline.find('\"', 8);
-      size_t qend;
-      // if a quote is not found look for a <
-      if(qstart == std::string::npos)
-	{
-	qstart = currentline.find('<', 8);
-	// if a < is not found then move on
-	if(qstart == std::string::npos)
-	  {
-	  cmSystemTools::Error("unknown include directive ", 
-                               currentline.c_str() );
-	  continue;
-	  }
-	else
-	  {
-	  qend = currentline.find('>', qstart+1);
-	  }
-	}
-      else
-	{
-	qend = currentline.find('\"', qstart+1);
-	}
       // extract the file being included
-      std::string includeFile = currentline.substr(qstart+1, qend - qstart-1);
+      std::string includeFile = includeLine.match(1);
       // see if the include matches the regular expression
       if(!m_IncludeFileRegularExpression.find(includeFile))
 	{
@@ -352,6 +340,7 @@ std::string cmMakeDepend::FullPath(const char* fname)
       }
     }
 
+  // Couldn't find the file.
   return std::string(fname);
 }
 

+ 1 - 0
Source/cmMakeDepend.h

@@ -180,6 +180,7 @@ protected:
   const cmMakefile* m_Makefile;
   bool m_Verbose;
   cmRegularExpression m_IncludeFileRegularExpression;
+  cmRegularExpression m_ComplainFileRegularExpression;
   DependArray m_DependInformation;
   std::vector<std::string> m_IncludeDirectories;
 };

+ 4 - 3
Source/cmMakefile.cxx

@@ -53,9 +53,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 // default is not to be building executables
 cmMakefile::cmMakefile()
 {
-  // Setup the default include file regular expression.
-  // Should be changed to something like "\\.(h|hh|hpp|hxx)$" or "^.*$"
-  m_IncludeFileRegularExpression = "^itk|^vtk|^vnl|^vcl|^f2c";
+  // Setup the default include file regular expression (match everything).
+  m_IncludeFileRegularExpression = "^.*$";
+  // Setup the default include complaint regular expression (match nothing).
+  m_ComplainFileRegularExpression = "^$";
   
   m_DefineFlags = " ";
   m_MakefileGenerator = 0;

+ 10 - 0
Source/cmMakefile.h

@@ -346,6 +346,15 @@ public:
       m_IncludeFileRegularExpression = regex;
     }
 
+  /** 
+   * Set a regular expression that include files that are not found
+   * must match in order to be considered a problem.
+   */
+  void SetComplainRegularExpression(const char* regex)
+    {
+      m_ComplainFileRegularExpression = regex;
+    }
+
   /**
    * Get the list of targets
    */
@@ -493,6 +502,7 @@ protected:
   cmTarget::LinkLibraries m_LinkLibraries;
 
   std::string m_IncludeFileRegularExpression;
+  std::string m_ComplainFileRegularExpression;
   std::string m_DefineFlags;
   std::vector<cmSourceGroup> m_SourceGroups;
   typedef std::map<std::string, cmCommand*> RegisteredCommandsMap;

+ 6 - 1
Source/cmUnixMakefileGenerator.cxx

@@ -128,7 +128,12 @@ void cmUnixMakefileGenerator::ProcessDepends(const cmMakeDepend &md)
                  info->m_IndexSet.begin();
                indx != info->m_IndexSet.end(); ++indx)
             {
-            i->GetDepends().push_back(md.GetDependInformation()[*indx]->m_FullPath);
+            // Make sure the full path is given.  If not, the dependency was
+            // not found.
+            if(md.GetDependInformation()[*indx]->m_FullPath != "")
+              {
+              i->GetDepends().push_back(md.GetDependInformation()[*indx]->m_FullPath);
+              }
             }
           }
         }