[Cmake-commits] [cmake-commits] king committed cmCommandArgumentParserHelper.cxx 1.20 1.21 cmCommandArgumentParserHelper.h 1.11 1.12 cmMakefile.cxx 1.481 1.482 cmPolicies.cxx 1.33 1.34 cmPolicies.h 1.18 1.19

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Sep 24 08:51:21 EDT 2008


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

Modified Files:
	cmCommandArgumentParserHelper.cxx 
	cmCommandArgumentParserHelper.h cmMakefile.cxx cmPolicies.cxx 
	cmPolicies.h 
Log Message:
ENH: Improve argument parsing error messages

Previously error messages produced by parsing of command argument
variable references, such as bad $KEY{VAR} syntax or a bad escape
sequence, did not provide good context information.  Errors parsing
arguments inside macro invocations gave no context at all.  Furthermore,
some errors such as a missing close curly "${VAR" would be reported but
build files would still be generated.

These changes teach CMake to report errors with good context information
for all command argument parsing problems.  Policy CMP0010 is introduced
so that existing projects that built despite such errors will continue
to work.


Index: cmCommandArgumentParserHelper.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCommandArgumentParserHelper.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -C 2 -d -r1.11 -r1.12
*** cmCommandArgumentParserHelper.h	6 Jun 2007 20:20:02 -0000	1.11
--- cmCommandArgumentParserHelper.h	24 Sep 2008 12:51:19 -0000	1.12
***************
*** 96,99 ****
--- 96,100 ----
  
    void CleanupParser();
+   void SetError(std::string const& msg);
  
    std::vector<char*> Variables;

Index: cmCommandArgumentParserHelper.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCommandArgumentParserHelper.cxx,v
retrieving revision 1.20
retrieving revision 1.21
diff -C 2 -d -r1.20 -r1.21
*** cmCommandArgumentParserHelper.cxx	6 Jun 2007 20:20:02 -0000	1.20
--- cmCommandArgumentParserHelper.cxx	24 Sep 2008 12:51:19 -0000	1.21
***************
*** 88,93 ****
      return this->EmptyVariable;
      }
!   cmSystemTools::Error("Key ", key, 
!                        " is not used yet. For now only $ENV{..} is allowed");
    return 0;
  }
--- 88,95 ----
      return this->EmptyVariable;
      }
!   cmOStringStream e;
!   e << "Syntax $" << key << "{} is not supported.  "
!     << "Only ${} and ENV{} are allowed.";
!   this->SetError(e.str());
    return 0;
  }
***************
*** 217,224 ****
      break;
    default:
!     char buffer[2];
!     buffer[0] = symbol;
!     buffer[1] = 0;
!     cmSystemTools::Error("Invalid escape sequence \\", buffer);
      return false;
      }
--- 219,227 ----
      break;
    default:
!     {
!     cmOStringStream e;
!     e << "Invalid escape sequence \\" << symbol;
!     this->SetError(e.str());
!     }
      return false;
      }
***************
*** 301,305 ****
    cmOStringStream ostr;
    ostr << str << " (" << pos << ")";
!   this->ErrorString = ostr.str();
  }
  
--- 304,308 ----
    cmOStringStream ostr;
    ostr << str << " (" << pos << ")";
!   this->SetError(ostr.str());
  }
  
***************
*** 319,320 ****
--- 322,331 ----
  }
  
+ void cmCommandArgumentParserHelper::SetError(std::string const& msg)
+ {
+   // Keep only the first error.
+   if(this->ErrorString.empty())
+     {
+     this->ErrorString = msg;
+     }
+ }

Index: cmPolicies.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmPolicies.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -C 2 -d -r1.18 -r1.19
*** cmPolicies.h	11 Sep 2008 18:34:04 -0000	1.18
--- cmPolicies.h	24 Sep 2008 12:51:19 -0000	1.19
***************
*** 51,54 ****
--- 51,55 ----
      CMP0008, // Full-path libraries must be a valid library file name
      CMP0009, // GLOB_RECURSE should not follow symlinks by default
+     CMP0010, // Bad variable reference syntax is an error
  
      // 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.33
retrieving revision 1.34
diff -C 2 -d -r1.33 -r1.34
*** cmPolicies.cxx	11 Sep 2008 18:34:04 -0000	1.33
--- cmPolicies.cxx	24 Sep 2008 12:51:19 -0000	1.34
***************
*** 324,327 ****
--- 324,339 ----
      "argument to the FILE command.",
      2,6,2, cmPolicies::WARN);
+ 
+   this->DefinePolicy(
+     CMP0010, "CMP0010",
+     "Bad variable reference syntax is an error.",
+     "In CMake 2.6.2 and below, incorrect variable reference syntax such as "
+     "a missing close-brace (\"${FOO\") was reported but did not stop "
+     "processing of CMake code.  "
+     "This policy determines whether a bad variable reference is an error.  "
+     "The OLD behavior for this policy is to warn about the error, leave "
+     "the string untouched, and continue. "
+     "The NEW behavior for this policy is to report an error.",
+     2,6,3, cmPolicies::WARN);
  }
  

Index: cmMakefile.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.cxx,v
retrieving revision 1.481
retrieving revision 1.482
diff -C 2 -d -r1.481 -r1.482
*** cmMakefile.cxx	25 Aug 2008 14:31:28 -0000	1.481
--- cmMakefile.cxx	24 Sep 2008 12:51:19 -0000	1.482
***************
*** 2169,2173 ****
    parser.SetRemoveEmpty(removeEmpty);
    int res = parser.ParseString(source.c_str(), 0);
!   if ( res )
      {
      source = parser.GetResult();
--- 2169,2174 ----
    parser.SetRemoveEmpty(removeEmpty);
    int res = parser.ParseString(source.c_str(), 0);
!   const char* emsg = parser.GetError();
!   if ( res && !emsg[0] )
      {
      source = parser.GetResult();
***************
*** 2175,2194 ****
    else
      {
      cmOStringStream error;
!     error << "Syntax error in cmake code at\n"
!           << (filename?filename:"(no filename given)")
!           << ":" << line << ":\n"
!           << parser.GetError() << ", when parsing string \""
!           << source.c_str() << "\"";
!     if(this->NeedBackwardsCompatibility(2,0))
        {
!       cmSystemTools::Error(error.str().c_str());
!       cmSystemTools::SetFatalErrorOccured();
!       return source.c_str();
        }
!     else
        {
!       cmSystemTools::Message(error.str().c_str());
        }
      }
    return source.c_str();
--- 2176,2226 ----
    else
      {
+     // Construct the main error message.
      cmOStringStream error;
!     error << "Syntax error in cmake code ";
!     if(filename && line > 0)
        {
!       // This filename and line number may be more specific than the
!       // command context because one command invocation can have
!       // arguments on multiple lines.
!       error << "at\n"
!             << "  " << filename << ":" << line << "\n";
        }
!     error << "when parsing string\n"
!           << "  " << source.c_str() << "\n";
!     error << emsg;
! 
!     // If the parser failed ("res" is false) then this is a real
!     // argument parsing error, so the policy applies.  Otherwise the
!     // parser reported an error message without failing because the
!     // helper implementation is unhappy, which has always reported an
!     // error.
!     cmake::MessageType mtype = cmake::FATAL_ERROR;
!     if(!res)
        {
!       // This is a real argument parsing error.  Use policy CMP0010 to
!       // decide whether it is an error.
!       switch(this->GetPolicyStatus(cmPolicies::CMP0010))
!         {
!         case cmPolicies::WARN:
!           error << "\n"
!                 << (this->GetPolicies()
!                     ->GetPolicyWarning(cmPolicies::CMP0010));
!         case cmPolicies::OLD:
!           // OLD behavior is to just warn and continue.
!           mtype = cmake::AUTHOR_WARNING;
!           break;
!         case cmPolicies::REQUIRED_IF_USED:
!         case cmPolicies::REQUIRED_ALWAYS:
!           error << "\n"
!                 << (this->GetPolicies()
!                     ->GetRequiredPolicyError(cmPolicies::CMP0010));
!         case cmPolicies::NEW:
!           // NEW behavior is to report the error.
!           cmSystemTools::SetFatalErrorOccured();
!           break;
!         }
        }
+     this->IssueMessage(mtype, error.str());
      }
    return source.c_str();



More information about the Cmake-commits mailing list