[Cmake-commits] [cmake-commits] king committed cmIfCommand.cxx 1.100 1.101

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Oct 27 09:01:43 EDT 2009


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

Modified Files:
	cmIfCommand.cxx 
Log Message:
Report expanded arguments in if() command errors

The if() command reports its arguments at the beginning of some error
messages.  Originally it reported the un-expanded form of the arguments
because in ancient CMake versions no context information was available.
Now it is more useful to see the real arguments, which may be mentioned
in the main error message.  Since full context information is now
available, users can refer back to the source if they need to see the
unexpanded form of the arguments.

For example, the code

  set(regex "++")
  if("x" MATCHES "${regex}")
  endif()

now produces the message

  if given arguments:

    "x" "MATCHES" "++"

  Regular expression "++" cannot compile

instead of

  if given arguments

    "x" MATCHES "${regex}"

  Regular expression "++" cannot compile


Index: cmIfCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmIfCommand.cxx,v
retrieving revision 1.100
retrieving revision 1.101
diff -C 2 -d -r1.100 -r1.101
*** cmIfCommand.cxx	21 Oct 2009 17:11:16 -0000	1.100
--- cmIfCommand.cxx	27 Oct 2009 13:01:33 -0000	1.101
***************
*** 17,20 ****
--- 17,36 ----
  #include <cmsys/RegularExpression.hxx>
  
+ 
+ static std::string cmIfCommandError(
+   cmMakefile* mf, std::vector<std::string> const& args)
+ {
+   cmLocalGenerator* lg = mf->GetLocalGenerator();
+   std::string err = "given arguments:\n ";
+   for(std::vector<std::string>::const_iterator i = args.begin();
+       i != args.end(); ++i)
+     {
+     err += " ";
+     err += lg->EscapeForCMake(i->c_str());
+     }
+   err += "\n";
+   return err;
+ }
+ 
  //=========================================================================
  bool cmIfFunctionBlocker::
***************
*** 86,99 ****
              if (errorString.size())
                {
!               std::string err = "given arguments\n  ";
!               unsigned int i;
!               for(i =0; i < this->Functions[c].Arguments.size(); ++i)
!                 {
!                 err += (this->Functions[c].Arguments[i].Quoted?"\"":"");
!                 err += this->Functions[c].Arguments[i].Value;
!                 err += (this->Functions[c].Arguments[i].Quoted?"\"":"");
!                 err += " ";
!                 }
!               err += "\n";
                err += errorString;
                mf.IssueMessage(messType, err);
--- 102,106 ----
              if (errorString.size())
                {
!               std::string err = cmIfCommandError(&mf, expandedArguments);
                err += errorString;
                mf.IssueMessage(messType, err);
***************
*** 176,189 ****
    if (errorString.size())
      {
!     std::string err = "given arguments\n  ";
!     unsigned int i;
!     for(i =0; i < args.size(); ++i)
!       {
!       err += (args[i].Quoted?"\"":"");
!       err += args[i].Value;
!       err += (args[i].Quoted?"\"":"");
!       err += " ";
!       }
!     err += "\n";
      err += errorString;
      if (status == cmake::FATAL_ERROR)
--- 183,187 ----
    if (errorString.size())
      {
!     std::string err = cmIfCommandError(this->Makefile, expandedArguments);
      err += errorString;
      if (status == cmake::FATAL_ERROR)



More information about the Cmake-commits mailing list