Преглед изворни кода

ENH: Remove cmGlob and use glob from kwsys

Andy Cedilnik пре 19 година
родитељ
комит
15d7dd9937

+ 0 - 1
Source/CMakeLists.txt

@@ -110,7 +110,6 @@ SET(SRCS
   cmExprParser.cxx
   cmExprParserHelper.cxx
   cmGeneratedFileStream.cxx
-  cmGlob.cxx
   cmGlobalGenerator.cxx
   cmGlobalGenerator.h
   cmGlobalUnixMakefileGenerator3.cxx

+ 3 - 2
Source/CTest/cmCTestCoverageHandler.cxx

@@ -21,9 +21,10 @@
 #include "cmake.h"
 #include "cmSystemTools.h"
 #include "cmGeneratedFileStream.h"
-#include "cmGlob.h"
+
 #include <cmsys/Process.h>
 #include <cmsys/RegularExpression.hxx>
+#include <cmsys/Glob.hxx>
 
 #include <stdlib.h>
 #include <math.h>
@@ -237,7 +238,7 @@ int cmCTestCoverageHandler::ProcessHandler()
   cmSystemTools::MakeDirectory(tempDir.c_str());
   cmSystemTools::ChangeDirectory(tempDir.c_str());
 
-  cmGlob gl;
+  cmsys::Glob gl;
   gl.RecurseOn();
   std::string daGlob = binaryDir + "/*.da";
   gl.FindFiles(daGlob);

+ 2 - 2
Source/cmCTest.cxx

@@ -22,7 +22,6 @@
 #include "cmLocalGenerator.h"
 #include "cmGlobalGenerator.h"
 #include <cmsys/Directory.hxx>
-#include "cmGlob.h"
 #include "cmDynamicLoader.h"
 #include "cmGeneratedFileStream.h"
 #include "cmCTestCommand.h"
@@ -41,6 +40,7 @@
 
 #include <cmsys/RegularExpression.hxx>
 #include <cmsys/Process.h>
+#include <cmsys/Glob.hxx>
 
 #include <stdlib.h>
 #include <math.h>
@@ -1876,7 +1876,7 @@ int cmCTest::ReadCustomConfigurationFileTree(const char* dir)
 
   std::string rexpr = dir;
   rexpr += "/CTestCustom.ctest";
-  cmGlob gl;
+  cmsys::Glob gl;
   gl.RecurseOn();
   gl.FindFiles(rexpr);
   std::vector<std::string>& files = gl.GetFiles();

+ 3 - 2
Source/cmCacheManager.cxx

@@ -19,8 +19,9 @@
 #include "cmSystemTools.h"
 #include "cmCacheManager.h"
 #include "cmMakefile.h"
-#include "cmGlob.h"
+
 #include <cmsys/Directory.hxx>
+#include <cmsys/Glob.hxx>
 
 #include <cmsys/RegularExpression.hxx>
 
@@ -163,7 +164,7 @@ void cmCacheManager::CleanCMakeFiles(const char* path)
 {
   std::string glob = path;
   glob += "/CMakeFiles/*.cmake";
-  cmGlob globIt;
+  cmsys::Glob globIt;
   globIt.FindFiles(glob);
   std::vector<std::string> files = globIt.GetFiles();
   for(std::vector<std::string>::iterator i = files.begin();

+ 13 - 13
Source/cmFileCommand.cxx

@@ -9,18 +9,17 @@
   Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
   See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
 
-     This software is distributed WITHOUT ANY WARRANTY; without even 
-     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
      PURPOSE.  See the above copyright notices for more information.
 
 =========================================================================*/
 #include "cmFileCommand.h"
 
-#include "cmGlob.h"
-
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <cmsys/Directory.hxx>
+#include <cmsys/Glob.hxx>
 
 // cmLibraryCommand
 bool cmFileCommand::InitialPass(std::vector<std::string> const& args)
@@ -82,7 +81,7 @@ bool cmFileCommand::InitialPass(std::vector<std::string> const& args)
 }
 
 //----------------------------------------------------------------------------
-bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args, 
+bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
   bool append)
 {
   std::string message;
@@ -205,7 +204,7 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
 
   std::string variable = *i;
   i++;
-  cmGlob g;
+  cmsys::Glob g;
   g.SetRecurse(recurse);
   std::string output = "";
   bool first = true;
@@ -509,7 +508,7 @@ bool cmFileCommand::HandleInstallCommand(
       {
       if ( ch2 == '/' )
         {
-        // looks like a network path. 
+        // looks like a network path.
         this->SetError("called with network path DESTINATION. This "
           "does not make sense when using DESTDIR. Specify local "
           "absolute path or remove DESTDIR environment variable.");
@@ -530,11 +529,11 @@ bool cmFileCommand::HandleInstallCommand(
     {
     itype = cmTarget::EXECUTABLE;
     }
-  else if ( stype == "PROGRAM" ) 
+  else if ( stype == "PROGRAM" )
     {
     itype = cmTarget::INSTALL_PROGRAMS;
     }
-  else if ( stype == "STATIC_LIBRARY" ) 
+  else if ( stype == "STATIC_LIBRARY" )
     {
     itype = cmTarget::STATIC_LIBRARY;
     }
@@ -620,7 +619,7 @@ bool cmFileCommand::HandleInstallCommand(
     }
 
   // Get the current manifest.
-  const char* manifest_files = 
+  const char* manifest_files =
     this->Makefile->GetDefinition("CMAKE_INSTALL_MANIFEST_FILES");
   std::string smanifest_files;
   if ( manifest_files )
@@ -871,7 +870,7 @@ bool cmFileCommand::HandleRelativePathCommand(
 
 
 //----------------------------------------------------------------------------
-bool cmFileCommand::HandleRemove(std::vector<std::string> const& args, 
+bool cmFileCommand::HandleRemove(std::vector<std::string> const& args,
                                  bool recurse)
 {
 
@@ -893,9 +892,10 @@ bool cmFileCommand::HandleRemove(std::vector<std::string> const& args,
   return true;
 }
 
-bool cmFileCommand::HandleSystemPathCommand(std::vector<std::string> 
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleSystemPathCommand(std::vector<std::string>
                                             const& args)
-{ 
+{
   std::vector<std::string>::const_iterator i = args.begin();
   if(args.size() != 3)
     {

+ 2 - 1
Source/cmFindPathCommand.cxx

@@ -17,6 +17,7 @@
 #include "cmFindPathCommand.h"
 #include "cmCacheManager.h"
 
+#include <cmsys/Glob.hxx>
 
 cmFindPathCommand::cmFindPathCommand()
 {
@@ -170,7 +171,7 @@ std::string cmFindPathCommand::FindHeaderInFramework(std::string& file,
   cmStdString glob = dir;
   glob += "/*/Headers/";
   glob += file;
-  cmGlob globIt;
+  cmsys::Glob globIt;
   globIt.FindFiles(glob);
   std::vector<std::string> files = globIt.GetFiles();
   if(files.size())

+ 0 - 401
Source/cmGlob.cxx

@@ -1,401 +0,0 @@
-/*=========================================================================
-
-  Program:   CMake - Cross-Platform Makefile Generator
-  Module:    $RCSfile$
-  Language:  C++
-  Date:      $Date$
-  Version:   $Revision$
-
-  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
-  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
-
-     This software is distributed WITHOUT ANY WARRANTY; without even 
-     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
-     PURPOSE.  See the above copyright notices for more information.
-
-=========================================================================*/
-#include "cmGlob.h"
-
-#include <cmsys/Directory.hxx>
-#include <cmsys/RegularExpression.hxx>
-#include <cmsys/SystemTools.hxx>
-
-#include <ctype.h>
-
-#if defined( _WIN32 ) || defined( APPLE ) || defined( __CYGWIN__ )
-  // On Windows and apple, no difference between lower and upper case
-  #define CM_GLOB_CASE_INDEPENDENT
-#endif
-
-#if defined( _WIN32 ) || defined( __CYGWIN__ )
-  // Handle network paths
-  #define CM_GLOB_SUPPORT_NETWORK_PATHS
-#endif
-
-class cmGlobInternal
-{
-public:
-  std::vector<std::string> Files;
-  std::vector<cmsys::RegularExpression> Expressions;
-  std::vector<std::string> TextExpressions;
-};
-
-cmGlob::cmGlob()
-{
-  this->Internals = new cmGlobInternal;
-  this->Recurse = false;
-}
-
-cmGlob::~cmGlob()
-{
-  delete this->Internals;
-}
-
-void cmGlob::Escape(int ch, char* buffer)
-{
-  if (! (
-      'a' <= ch && ch <= 'z' || 
-      'A' <= ch && ch <= 'Z' || 
-      '0' <= ch && ch <= '9') )
-    {
-    sprintf(buffer, "\\%c", ch);
-    }
-  else
-    {
-#if defined( CM_GLOB_CASE_INDEPENDENT )
-    // On Windows and apple, no difference between lower and upper case
-    sprintf(buffer, "%c", tolower(ch));
-#else
-    sprintf(buffer, "%c", ch);
-#endif
-    }
-}
-
-std::vector<std::string>& cmGlob::GetFiles()
-{
-  return this->Internals->Files;
-}
-
-std::string cmGlob::ConvertExpression(const std::string& expr)
-{
-  
-  std::string::size_type i = 0;
-  std::string::size_type n = expr.size();
-
-  std::string res = "^";
-  std::string stuff = "";
-
-  while ( i < n )
-    {
-    int c = expr[i];
-    i = i+1;
-    if ( c == '*' )
-      {
-      res = res + ".*";
-      }
-    else if ( c == '?' )
-      {
-      res = res + ".";
-      }
-    else if ( c == '[' )
-      {
-      std::string::size_type j = i;
-      if ( j < n && ( expr[j] == '!' || expr[j] == '^' ) )
-        {
-        j = j+1;
-        }
-      if ( j < n && expr[j] == ']' )
-        {
-        j = j+1;
-        } 
-      while ( j < n && expr[j] != ']' )
-        {
-        j = j+1;
-        }
-      if ( j >= n )
-        {
-        res = res + "\\[";
-        }
-      else
-        {
-        stuff = "";
-        std::string::size_type cc;
-        for ( cc = i; cc < j; cc ++ )
-          {
-          if ( expr[cc] == '\\' )
-            {
-            stuff += "\\\\";
-            }
-          else
-            {
-            stuff += expr[cc];
-            }
-          }
-        i = j+1;
-        if ( stuff[0] == '!' || stuff[0] == '^' )
-          {
-          stuff = '^' + stuff.substr(1);
-          }
-        else if ( stuff[0] == '^' )
-          {
-          stuff = '\\' + stuff;
-          }
-        res = res + "[" + stuff + "]";
-        }
-      }
-    else
-      {
-      char buffer[100];
-      buffer[0] = 0;
-      this->Escape(c, buffer);
-      res = res + buffer;
-      }
-    }
-  return res + "$";
-}
-
-void cmGlob::RecurseDirectory(std::string::size_type start,
-  const std::string& dir, bool dir_only)
-{
-  cmsys::Directory d;
-  if ( !d.Load(dir.c_str()) )
-    {
-    return;
-    }
-  unsigned long cc;
-  std::string fullname;
-  std::string realname;
-  std::string fname;
-  for ( cc = 0; cc < d.GetNumberOfFiles(); cc ++ )
-    {
-    fname = d.GetFile(cc);
-    if ( strcmp(fname.c_str(), ".") == 0 ||
-      strcmp(fname.c_str(), "..") == 0  )
-      {
-      continue;
-      }
-
-    if ( start == 0 )
-      {
-      realname = dir + fname;
-      }
-    else
-      {
-      realname = dir + "/" + fname;
-      }
-
-#if defined( CM_GLOB_CASE_INDEPENDENT )
-    // On Windows and apple, no difference between lower and upper case
-    fname = cmsys::SystemTools::LowerCase(fname);
-#endif
-
-    if ( start == 0 )
-      {
-      fullname = dir + fname;
-      }
-    else
-      {
-      fullname = dir + "/" + fname;
-      }
-
-    if ( !dir_only || !cmsys::SystemTools::FileIsDirectory(realname.c_str()) )
-      {
-      if ( this->Internals->Expressions[this->Internals->Expressions.size()-1].find(fname.c_str()) )
-        {
-        this->Internals->Files.push_back(realname);
-        }
-      }
-    if ( cmsys::SystemTools::FileIsDirectory(realname.c_str()) )
-      {
-      this->RecurseDirectory(start+1, realname, dir_only);
-      }
-    }
-}
-
-void cmGlob::ProcessDirectory(std::string::size_type start, 
-  const std::string& dir, bool dir_only)
-{
-  //std::cout << "ProcessDirectory: " << dir << std::endl;
-  bool last = ( start == this->Internals->Expressions.size()-1 );
-  if ( last && this->Recurse )
-    {
-    this->RecurseDirectory(start, dir, dir_only);
-    return;
-    }
-  cmsys::Directory d;
-  if ( !d.Load(dir.c_str()) )
-    {
-    return;
-    }
-  unsigned long cc;
-  std::string fullname;
-  std::string realname;
-  std::string fname;
-  for ( cc = 0; cc < d.GetNumberOfFiles(); cc ++ )
-    {
-    fname = d.GetFile(cc);
-    if ( strcmp(fname.c_str(), ".") == 0 ||
-      strcmp(fname.c_str(), "..") == 0  )
-      {
-      continue;
-      }
-
-    if ( start == 0 )
-      {
-      realname = dir + fname;
-      }
-    else
-      {
-      realname = dir + "/" + fname;
-      }
-
-#if defined( CM_GLOB_CASE_INDEPENDENT )
-    // On Windows and apple, no difference between lower and upper case
-    fname = cmsys::SystemTools::LowerCase(fname);
-#endif
-
-    if ( start == 0 )
-      {
-      fullname = dir + fname;
-      }
-    else
-      {
-      fullname = dir + "/" + fname;
-      }
-
-    //std::cout << "Look at file: " << fname << std::endl;
-    //std::cout << "Match: " << this->Internals->TextExpressions[start].c_str() << std::endl;
-    //std::cout << "Full name: " << fullname << std::endl;
-
-    if ( (!dir_only || !last) && !cmsys::SystemTools::FileIsDirectory(realname.c_str()) )
-      {
-      continue;
-      }
-
-    if ( this->Internals->Expressions[start].find(fname.c_str()) )
-      {
-      if ( last )
-        {
-        this->Internals->Files.push_back(realname);
-        }
-      else
-        {
-        this->ProcessDirectory(start+1, realname + "/", dir_only);
-        }
-      }
-    }
-}
-
-bool cmGlob::FindFiles(const std::string& inexpr)
-{
-  std::string cexpr;
-  std::string::size_type cc;
-  std::string expr = inexpr;
-
-  this->Internals->Expressions.clear();
-  this->Internals->Files.clear();
-
-  if ( !cmsys::SystemTools::FileIsFullPath(expr.c_str()) )
-    {
-    expr = cmsys::SystemTools::GetCurrentWorkingDirectory();
-    expr += "/" + inexpr;
-    }
-  std::string fexpr = expr;
-
-  int skip = 0;
-  int last_slash = 0;
-  for ( cc = 0; cc < expr.size(); cc ++ )
-    {
-    if ( cc > 0 && expr[cc] == '/' && expr[cc-1] != '\\' )
-      {
-      last_slash = cc;
-      }
-    if ( cc > 0 && 
-      (expr[cc] == '[' || expr[cc] == '?' || expr[cc] == '*') &&
-      expr[cc-1] != '\\' )
-      {
-      break;
-      }
-    }
-  if ( last_slash > 0 )
-    {
-    //std::cout << "I can skip: " << fexpr.substr(0, last_slash) << std::endl;
-    skip = last_slash;
-    }
-  if ( skip == 0 )
-    {
-#if defined( CM_GLOB_SUPPORT_NETWORK_PATHS )
-    // Handle network paths
-    if ( expr[0] == '/' && expr[1] == '/' )
-      {
-      int cnt = 0;
-      for ( cc = 2; cc < expr.size(); cc ++ )
-        {
-        if ( expr[cc] == '/' )
-          {
-          cnt ++;
-          if ( cnt == 2 )
-            {
-            break;
-            }
-          }
-        }
-      skip = cc + 1;
-      }
-    else
-#endif
-      // Handle drive letters on Windows
-      if ( expr[1] == ':' && expr[0] != '/' )
-        {
-        skip = 2;
-        }
-    }
-
-  if ( skip > 0 )
-    {
-    expr = expr.substr(skip);
-    }
-
-  cexpr = "";
-  for ( cc = 0; cc < expr.size(); cc ++ )
-    {
-    int ch = expr[cc];
-    if ( ch == '/' )
-      {
-      if ( cexpr.size() > 0 )
-        {
-        this->AddExpression(cexpr.c_str());
-        }
-      cexpr = "";
-      }
-    else
-      {
-      cexpr.append(1, (char)ch);
-      }
-    }
-  if ( cexpr.size() > 0 )
-    {
-    this->AddExpression(cexpr.c_str());
-    }
-
-  // Handle network paths
-  if ( skip > 0 )
-    {
-    this->ProcessDirectory(0, fexpr.substr(0, skip) + "/",
-      true);     
-    }
-  else
-    {
-    this->ProcessDirectory(0, "/", true);
-    }
-  return true;
-}
-
-void cmGlob::AddExpression(const char* expr)
-{
-  this->Internals->Expressions.push_back(
-    cmsys::RegularExpression(
-      this->ConvertExpression(expr).c_str()));
-  this->Internals->TextExpressions.push_back(this->ConvertExpression(expr));
-}
-

+ 0 - 73
Source/cmGlob.h

@@ -1,73 +0,0 @@
-/*=========================================================================
-
-  Program:   CMake - Cross-Platform Makefile Generator
-  Module:    $RCSfile$
-  Language:  C++
-  Date:      $Date$
-  Version:   $Revision$
-
-  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
-  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
-
-     This software is distributed WITHOUT ANY WARRANTY; without even 
-     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
-     PURPOSE.  See the above copyright notices for more information.
-
-=========================================================================*/
-#ifndef cmGlob_h
-#define cmGlob_h
-
-#include "cmStandardIncludes.h"
-
-class cmGlobInternal;
-
-/** \class cmGlob
- * \brief Helper class for performing globbing searches.
- *
- * Finds all files that match a given globbing expression.
- */
-class cmGlob
-{
-public:
-  cmGlob();
-  ~cmGlob();
-
-  //! Find all files that match the pattern.
-  bool FindFiles(const std::string& inexpr);
-
-  //! Return the list of files that matched.
-  std::vector<std::string>& GetFiles();
-
-  //! Set recurse to true to match subdirectories.
-  void RecurseOn() { this->SetRecurse(true); }
-  void RecurseOff() { this->SetRecurse(false); }
-  void SetRecurse(bool i) { this->Recurse = i; }
-  bool GetRecurse() { return this->Recurse; }
-
-protected:
-  //! Process directory
-  void ProcessDirectory(std::string::size_type start, 
-    const std::string& dir, bool dir_only);
-
-  //! Process last directory, but only when recurse flags is on. That is
-  // effectively like saying: /path/to/file/**/file
-  void RecurseDirectory(std::string::size_type start,
-    const std::string& dir, bool dir_only);
-
-  //! Escape all non-alphanumeric characters in pattern.
-  void Escape(int ch, char* buffer);
-
-  //!
-  // Translate a shell PATTERN to a regular expression.
-  // There is no way to quote meta-characters.
-  std::string ConvertExpression(const std::string& expr);
-
-  //! Add regular expression
-  void AddExpression(const char* expr);
-
-  cmGlobInternal* Internals;
-  bool Recurse;
-};
-
-
-#endif

+ 0 - 1
bootstrap

@@ -95,7 +95,6 @@ CMAKE_CXX_SOURCES="\
   cmMakefile \
   cmGeneratedFileStream \
   cmGlobalGenerator \
-  cmGlob \
   cmLocalGenerator \
   cmInstallGenerator \
   cmInstallFilesGenerator \