[Cmake-commits] [cmake-commits] david.cole committed cmFileCommand.cxx 1.112 1.113 cmFileCommand.h 1.39 1.40 cmPolicies.cxx 1.32 1.33 cmPolicies.h 1.17 1.18

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Sep 11 14:34:06 EDT 2008


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

Modified Files:
	cmFileCommand.cxx cmFileCommand.h cmPolicies.cxx cmPolicies.h 
Log Message:
ENH: Improve FILE GLOB_RECURSE handling of symlinks with a new CMake policy. CMP0009 establishes NEW default behavior of not recursing through symlinks. OLD default behavior or explicit FOLLOW_SYMLINKS argument to FILE GLOB_RECURSE will still recurse through symlinks.


Index: cmFileCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFileCommand.h,v
retrieving revision 1.39
retrieving revision 1.40
diff -C 2 -d -r1.39 -r1.40
*** cmFileCommand.h	23 Aug 2008 17:47:24 -0000	1.39
--- cmFileCommand.h	11 Sep 2008 18:34:04 -0000	1.40
***************
*** 78,82 ****
        "  file(GLOB variable [RELATIVE path] [globbing expressions]...)\n"
        "  file(GLOB_RECURSE variable [RELATIVE path] \n"
!       "       [RECURSE_SYMLINKS_OFF] [globbing expressions]...)\n"
        "  file(REMOVE [file1 ...])\n"
        "  file(REMOVE_RECURSE [file1 ...])\n"
--- 78,82 ----
        "  file(GLOB variable [RELATIVE path] [globbing expressions]...)\n"
        "  file(GLOB_RECURSE variable [RELATIVE path] \n"
!       "       [FOLLOW_SYMLINKS] [globbing expressions]...)\n"
        "  file(REMOVE [file1 ...])\n"
        "  file(REMOVE_RECURSE [file1 ...])\n"
***************
*** 125,133 ****
        "   *.vt?      - match all files with extension vta,...,vtz\n"
        "   f[3-5].txt - match files f3.txt, f4.txt, f5.txt\n"
!       "GLOB_RECURSE will generate similar list as the regular GLOB, except "
        "it will traverse all the subdirectories of the matched directory and "
!       "match the files. Subdirectories that are symlinks are traversed by "
!       "default to match the behavior of older CMake releases. Use "
!       "RECURSE_SYMLINKS_OFF to prevent recursion through symlinks.\n"
        "Examples of recursive globbing include:\n"
        "   /dir/*.py  - match all python files in /dir and subdirectories\n"
--- 125,133 ----
        "   *.vt?      - match all files with extension vta,...,vtz\n"
        "   f[3-5].txt - match files f3.txt, f4.txt, f5.txt\n"
!       "GLOB_RECURSE will generate a list similar to the regular GLOB, except "
        "it will traverse all the subdirectories of the matched directory and "
!       "match the files. Subdirectories that are symlinks are only traversed "
!       "if FOLLOW_SYMLINKS is given or cmake policy CMP0009 is not set to NEW. "
!       "See cmake --help-policy CMP0009 for more information.\n"
        "Examples of recursive globbing include:\n"
        "   /dir/*.py  - match all python files in /dir and subdirectories\n"

Index: cmPolicies.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmPolicies.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -C 2 -d -r1.17 -r1.18
*** cmPolicies.h	18 Aug 2008 20:29:00 -0000	1.17
--- cmPolicies.h	11 Sep 2008 18:34:04 -0000	1.18
***************
*** 50,53 ****
--- 50,54 ----
      CMP0007, // list command handling of empty elements
      CMP0008, // Full-path libraries must be a valid library file name
+     CMP0009, // GLOB_RECURSE should not follow symlinks by default
  
      // Always the last entry.  Useful mostly to avoid adding a comma

Index: cmPolicies.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmPolicies.cxx,v
retrieving revision 1.32
retrieving revision 1.33
diff -C 2 -d -r1.32 -r1.33
*** cmPolicies.cxx	18 Aug 2008 20:29:00 -0000	1.32
--- cmPolicies.cxx	11 Sep 2008 18:34:04 -0000	1.33
***************
*** 308,311 ****
--- 308,327 ----
      "pass it directly to the native build tool unchanged.",
      2,6,1, cmPolicies::WARN);
+ 
+   this->DefinePolicy(
+     CMP0009, "CMP0009",
+     "FILE GLOB_RECURSE calls should not follow symlinks by default.",
+     "In CMake 2.6.1 and below, FILE GLOB_RECURSE calls would follow "
+     "through symlinks, sometimes coming up with unexpectedly large "
+     "result sets because of symlinks to top level directories that "
+     "contain hundreds of thousands of files."
+     "\n"
+     "This policy determines whether or not to follow symlinks "
+     "encountered during a FILE GLOB_RECURSE call. "
+     "The OLD behavior for this policy is to follow the symlinks. "
+     "The NEW behavior for this policy is not to follow the symlinks "
+     "by default, but only if FOLLOW_SYMLINKS is given as an additional "
+     "argument to the FILE command.",
+     2,6,2, cmPolicies::WARN);
  }
  
***************
*** 385,389 ****
        "than 2.4 set policy CMP0001 to OLD to tell CMake to check the "
        "CMAKE_BACKWARDS_COMPATIBILITY variable.  "
!       "One way to so this is to set the policy version to 2.4 exactly."
        );
      return false;
--- 401,405 ----
        "than 2.4 set policy CMP0001 to OLD to tell CMake to check the "
        "CMAKE_BACKWARDS_COMPATIBILITY variable.  "
!       "One way to do this is to set the policy version to 2.4 exactly."
        );
      return false;

Index: cmFileCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFileCommand.cxx,v
retrieving revision 1.112
retrieving revision 1.113
diff -C 2 -d -r1.112 -r1.113
*** cmFileCommand.cxx	23 Aug 2008 17:33:13 -0000	1.112
--- cmFileCommand.cxx	11 Sep 2008 18:34:04 -0000	1.113
***************
*** 669,684 ****
    cmsys::Glob g;
    g.SetRecurse(recurse);
    std::string output = "";
    bool first = true;
    for ( ; i != args.end(); ++i )
      {
!     if ( *i == "RECURSE_SYMLINKS_OFF" )
        {
!       g.RecurseThroughSymlinksOff();
        ++i;
        if ( i == args.end() )
          {
          this->SetError(
!           "GLOB requires a glob expression after RECURSE_SYMLINKS_OFF");
          return false;
          }
--- 669,705 ----
    cmsys::Glob g;
    g.SetRecurse(recurse);
+ 
+   bool explicitFollowSymlinks = false;
+   cmPolicies::PolicyStatus status =
+     this->Makefile->GetPolicyStatus(cmPolicies::CMP0009);
+   if(recurse)
+     {
+     switch(status)
+       {
+       case cmPolicies::NEW:
+         g.RecurseThroughSymlinksOff();
+         break;
+       case cmPolicies::OLD:
+       case cmPolicies::WARN:
+       case cmPolicies::REQUIRED_IF_USED:
+       case cmPolicies::REQUIRED_ALWAYS:
+         g.RecurseThroughSymlinksOn();
+         break;
+       }
+     }
+ 
    std::string output = "";
    bool first = true;
    for ( ; i != args.end(); ++i )
      {
!     if ( recurse && (*i == "FOLLOW_SYMLINKS") )
        {
!       explicitFollowSymlinks = true;
!       g.RecurseThroughSymlinksOn();
        ++i;
        if ( i == args.end() )
          {
          this->SetError(
!           "GLOB_RECURSE requires a glob expression after FOLLOW_SYMLINKS");
          return false;
          }
***************
*** 733,736 ****
--- 754,788 ----
        }
      }
+ 
+   if(recurse && !explicitFollowSymlinks)
+     {
+     switch (status)
+       {
+       case cmPolicies::NEW:
+         // Correct behavior, yay!
+         break;
+       case cmPolicies::OLD:
+         // Probably not really the expected behavior, but the author explicitly
+         // asked for the old behavior... no warning.
+       case cmPolicies::WARN:
+         // Possibly unexpected old behavior *and* we actually traversed
+         // symlinks without being explicitly asked to: warn the author.
+         if(g.GetFollowedSymlinkCount() != 0)
+           {
+           this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
+             this->Makefile->GetPolicies()->
+               GetPolicyWarning(cmPolicies::CMP0009));
+           }
+         break;
+       case cmPolicies::REQUIRED_IF_USED:
+       case cmPolicies::REQUIRED_ALWAYS:
+         this->SetError("policy CMP0009 error");
+         this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+           this->Makefile->GetPolicies()->
+             GetRequiredPolicyError(cmPolicies::CMP0009));
+         return false;
+       }
+     }
+ 
    this->Makefile->AddDefinition(variable.c_str(), output.c_str());
    return true;



More information about the Cmake-commits mailing list