[Cmake-commits] [cmake-commits] king committed cmAddCustomTargetCommand.cxx 1.34 1.35 cmExecutionStatus.h 1.1 1.2 cmFunctionCommand.cxx 1.5 1.6 cmListFileCache.cxx 1.34 1.35 cmListFileCache.h 1.19 1.20 cmMacroCommand.cxx 1.35 1.36 cmMakefile.cxx 1.446 1.447 cmMakefile.h 1.227 1.228 cmPolicies.cxx 1.12 1.13

cmake-commits at cmake.org cmake-commits at cmake.org
Fri Mar 7 08:40:39 EST 2008


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

Modified Files:
	cmAddCustomTargetCommand.cxx cmExecutionStatus.h 
	cmFunctionCommand.cxx cmListFileCache.cxx cmListFileCache.h 
	cmMacroCommand.cxx cmMakefile.cxx cmMakefile.h cmPolicies.cxx 
Log Message:
ENH: New format for warning and error messages

  - Add cmMakefile methods IssueError and IssueWarning
  - Maintain an explicit call stack in cmMakefile
  - Include context/call-stack info in messages
  - Nested errors now unwind the call stack
  - Use new mechanism for policy warnings and errors
  - Improve policy error message
  - Include cmExecutionStatus pointer in call stack
    so that errors deeper in the C++ stack under
    a command invocation will become errors for the
    command


Index: cmListFileCache.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmListFileCache.cxx,v
retrieving revision 1.34
retrieving revision 1.35
diff -C 2 -d -r1.34 -r1.35
*** cmListFileCache.cxx	6 Mar 2008 21:03:48 -0000	1.34
--- cmListFileCache.cxx	7 Mar 2008 13:40:36 -0000	1.35
***************
*** 153,165 ****
        {
          case cmPolicies::WARN:
!           cmSystemTools::Message(
!             mf->GetPolicies()->GetPolicyWarning
!               (cmPolicies::CMP_0000).c_str(),"Warning");
          case cmPolicies::OLD:
            break; 
          default:
!           cmSystemTools::Error(
!             mf->GetPolicies()->GetRequiredPolicyError
!               (cmPolicies::CMP_0000).c_str());
            return false;
        }
--- 153,165 ----
        {
          case cmPolicies::WARN:
!           mf->IssueWarning(
!             mf->GetPolicies()->GetPolicyWarning(cmPolicies::CMP_0000)
!             );
          case cmPolicies::OLD:
            break; 
          default:
!           mf->IssueError(
!             mf->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP_0000)
!             );
            return false;
        }

Index: cmPolicies.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmPolicies.cxx,v
retrieving revision 1.12
retrieving revision 1.13
diff -C 2 -d -r1.12 -r1.13
*** cmPolicies.cxx	6 Mar 2008 20:08:03 -0000	1.12
--- cmPolicies.cxx	7 Mar 2008 13:40:36 -0000	1.13
***************
*** 87,91 ****
    this->DefinePolicy(CMP_0000, "CMP_0000",
      "Missing a CMake version specification. You must have a cmake_policy "
!     "or cmake_minimum_required call.",
      "CMake requires that projects specify what version of CMake they have "
      "been written to. The easiest way to do this is by placing a call to "
--- 87,91 ----
    this->DefinePolicy(CMP_0000, "CMP_0000",
      "Missing a CMake version specification. You must have a cmake_policy "
!     "call.",
      "CMake requires that projects specify what version of CMake they have "
      "been written to. The easiest way to do this is by placing a call to "
***************
*** 349,356 ****
    cmOStringStream msg;
    msg <<
!     "WARNING: Policy " << pos->second->IDString << " is not set: "
!     "" << pos->second->ShortDescription << " "
      "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
!     "policy details.  Use the cmake_policy command to set the policy "
      "and suppress this warning.";
    return msg.str();
--- 349,357 ----
    cmOStringStream msg;
    msg <<
!     "Policy " << pos->second->IDString << " is not set: "
!     "" << pos->second->ShortDescription << "\n"
      "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
!     "policy details.\n"
!     "Use the cmake_policy command to set the policy "
      "and suppress this warning.";
    return msg.str();
***************
*** 371,389 ****
  
    cmOStringStream error;
!   error << 
!     "Error " <<
!     pos->second->IDString << ": " <<
!     pos->second->ShortDescription <<
!     " This behavior is required now. You can suppress this message by "
!     "specifying that your listfile is written to handle this new "
!     "behavior by adding either\n" <<
!     "cmake_policy (NEW " <<
!     pos->second->IDString << ")\n or \n. " <<
!     "cmake_policy (VERSION " << 
!     pos->second->GetVersionString() << " ) or later."
!     "Run cmake --help-policy " <<
!     pos->second->IDString << " for more information.";
    return error.str();
-   
  }
  
--- 372,388 ----
  
    cmOStringStream error;
!   error <<
!     "Policy " << pos->second->IDString << " is not set to NEW: "
!     "" << pos->second->ShortDescription << "\n"
!     "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
!     "policy details.\n"
!     "CMake now requires this policy to be set to NEW by the project.  "
!     "The policy may be set explicitly using the code\n"
!     "  cmake_policy(SET " << pos->second->IDString << " NEW)\n"
!     "or by upgrading all policies with the code\n"
!     "  cmake_policy(VERSION " << pos->second->GetVersionString() <<
!     ") # or later\n"
!     "Run \"cmake --help-command cmake_policy\" for more information.";
    return error.str();
  }
  

Index: cmAddCustomTargetCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmAddCustomTargetCommand.cxx,v
retrieving revision 1.34
retrieving revision 1.35
diff -C 2 -d -r1.34 -r1.35
*** cmAddCustomTargetCommand.cxx	3 Mar 2008 16:28:16 -0000	1.34
--- cmAddCustomTargetCommand.cxx	7 Mar 2008 13:40:36 -0000	1.35
***************
*** 19,23 ****
  // cmAddCustomTargetCommand
  bool cmAddCustomTargetCommand
! ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  {
    // This enum must be before an enum is used in a switch statment. 
--- 19,24 ----
  // cmAddCustomTargetCommand
  bool cmAddCustomTargetCommand
! ::InitialPass(std::vector<std::string> const& args,
!               cmExecutionStatus& status)
  {
    // This enum must be before an enum is used in a switch statment. 
***************
*** 46,52 ****
      {
        case cmPolicies::WARN:
!         cmSystemTools::Message(
            this->Makefile->GetPolicies()->GetPolicyWarning
!             (cmPolicies::CMP_0001).c_str(),"Warning");
        case cmPolicies::OLD:
  //        if (this->Makefile->IsBWCompatibilityLessThan(2,2))
--- 47,53 ----
      {
        case cmPolicies::WARN:
!         this->Makefile->IssueWarning(
            this->Makefile->GetPolicies()->GetPolicyWarning
!             (cmPolicies::CMP_0001));
        case cmPolicies::OLD:
  //        if (this->Makefile->IsBWCompatibilityLessThan(2,2))
***************
*** 61,68 ****
        case cmPolicies::REQUIRED_IF_USED:
        case cmPolicies::REQUIRED_ALWAYS:
!         this->SetError(
            this->Makefile->GetPolicies()->GetRequiredPolicyError
!             (cmPolicies::CMP_0001).c_str());
!         return false;      
      }
    }
--- 62,70 ----
        case cmPolicies::REQUIRED_IF_USED:
        case cmPolicies::REQUIRED_ALWAYS:
!         this->Makefile->IssueError(
            this->Makefile->GetPolicies()->GetRequiredPolicyError
!             (cmPolicies::CMP_0001).c_str()
!           );
!         return false;
      }
    }

Index: cmMacroCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMacroCommand.cxx,v
retrieving revision 1.35
retrieving revision 1.36
diff -C 2 -d -r1.35 -r1.36
*** cmMacroCommand.cxx	29 Feb 2008 17:18:11 -0000	1.35
--- cmMacroCommand.cxx	7 Mar 2008 13:40:36 -0000	1.36
***************
*** 238,259 ****
        }
      cmExecutionStatus status;
!     if(!this->Makefile->ExecuteCommand(newLFF,status))
        {
!       if(args.size())
!         {
!         arg.FilePath = args[0].FilePath;
!         arg.Line = args[0].Line;
!         }
!       else
!         {
!         arg.FilePath =  "Unknown";
!         arg.Line = 0;
!         }
!       cmOStringStream error;
!       error << "Error in cmake code at\n"
!             << arg.FilePath << ":" << arg.Line << ":\n"
!             << "A command failed during the invocation of macro \""
!             << this->Args[0].c_str() << "\".";
!       cmSystemTools::Error(error.str().c_str());
        return false;
        }
--- 238,247 ----
        }
      cmExecutionStatus status;
!     if(!this->Makefile->ExecuteCommand(newLFF, status) ||
!        status.GetNestedError())
        {
!       // The error message should have already included the call stack
!       // so we do not need to report an error here.
!       inStatus.SetNestedError(true);
        return false;
        }

Index: cmMakefile.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.h,v
retrieving revision 1.227
retrieving revision 1.228
diff -C 2 -d -r1.227 -r1.228
*** cmMakefile.h	5 Mar 2008 23:21:10 -0000	1.227
--- cmMakefile.h	7 Mar 2008 13:40:36 -0000	1.228
***************
*** 42,45 ****
--- 42,46 ----
  class cmVariableWatch;
  class cmake;
+ class cmMakefileCall;
  
  /** \class cmMakefile
***************
*** 784,787 ****
--- 785,792 ----
    void RaiseScope(const char *var, const char *value);
  
+   /** Issue messages with the given text plus context information.  */
+   void IssueWarning(std::string const& msg) const;
+   void IssueError(std::string const& msg) const;
+ 
  protected:
    // add link libraries and directories to the target
***************
*** 877,880 ****
--- 882,897 ----
    std::deque<cmStdString> ListFileStack;
  
+   // stack of commands being invoked.
+   struct CallStackEntry
+   {
+     cmListFileContext const* Context;
+     cmExecutionStatus* Status;
+   };
+   typedef std::deque<CallStackEntry> CallStackType;
+   CallStackType CallStack;
+   friend class cmMakefileCall;
+ 
+   void IssueMessage(std::string const& text, bool isError) const;
+ 
    cmTarget* FindBasicTarget(const char* name);
    std::vector<cmTarget*> ImportedTargetsOwned;

Index: cmFunctionCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFunctionCommand.cxx,v
retrieving revision 1.5
retrieving revision 1.6
diff -C 2 -d -r1.5 -r1.6
*** cmFunctionCommand.cxx	29 Feb 2008 17:18:11 -0000	1.5
--- cmFunctionCommand.cxx	7 Mar 2008 13:40:36 -0000	1.6
***************
*** 87,91 ****
  bool cmFunctionHelperCommand::InvokeInitialPass
  (const std::vector<cmListFileArgument>& args,
!  cmExecutionStatus &)
  {
    // Expand the argument list to the function.
--- 87,91 ----
  bool cmFunctionHelperCommand::InvokeInitialPass
  (const std::vector<cmListFileArgument>& args,
!  cmExecutionStatus & inStatus)
  {
    // Expand the argument list to the function.
***************
*** 158,173 ****
      {
      cmExecutionStatus status;
!     if (!this->Makefile->ExecuteCommand(this->Functions[c],status))
        {
!       cmOStringStream error;
!       error << "Error in cmake code at\n"
!             << this->Functions[c].FilePath << ":" 
!             << this->Functions[c].Line << ":\n"
!             << "A command failed during the invocation of function \""
!             << this->Args[0].c_str() << "\".";
!       cmSystemTools::Error(error.str().c_str());
! 
!       // pop scope on the makefile and return
!       this->Makefile->PopScope();
        return false;
        }
--- 158,167 ----
      {
      cmExecutionStatus status;
!     if (!this->Makefile->ExecuteCommand(this->Functions[c],status) ||
!         status.GetNestedError())
        {
!       // The error message should have already included the call stack
!       // so we do not need to report an error here.
!       inStatus.SetNestedError(true);
        return false;
        }

Index: cmListFileCache.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmListFileCache.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -C 2 -d -r1.19 -r1.20
*** cmListFileCache.h	6 Mar 2008 15:57:39 -0000	1.19
--- cmListFileCache.h	7 Mar 2008 13:40:36 -0000	1.20
***************
*** 51,62 ****
  };
  
! struct cmListFileFunction
  {
    std::string Name;
-   std::vector<cmListFileArgument> Arguments;
    std::string FilePath;
    long Line;
  };
  
  struct cmListFile
  {
--- 51,66 ----
  };
  
! struct cmListFileContext
  {
    std::string Name;
    std::string FilePath;
    long Line;
  };
  
+ struct cmListFileFunction: public cmListFileContext
+ {
+   std::vector<cmListFileArgument> Arguments;
+ };
+ 
  struct cmListFile
  {

Index: cmExecutionStatus.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmExecutionStatus.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C 2 -d -r1.1 -r1.2
*** cmExecutionStatus.h	23 Jan 2008 15:28:26 -0000	1.1
--- cmExecutionStatus.h	7 Mar 2008 13:40:36 -0000	1.2
***************
*** 43,47 ****
              
    virtual void Clear()
!   { this->ReturnInvoked = false; this->BreakInvoked = false; }
  
                                          
--- 43,53 ----
              
    virtual void Clear()
!     {
!     this->ReturnInvoked = false;
!     this->BreakInvoked = false;
!     this->NestedError = false;
!     }
!   virtual void SetNestedError(bool val) { this->NestedError = val; }
!   virtual bool GetNestedError() { return this->NestedError; }
  
                                          
***************
*** 49,52 ****
--- 55,59 ----
    bool ReturnInvoked;
    bool BreakInvoked;
+   bool NestedError;
  };
  

Index: cmMakefile.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.cxx,v
retrieving revision 1.446
retrieving revision 1.447
diff -C 2 -d -r1.446 -r1.447
*** cmMakefile.cxx	6 Mar 2008 15:57:41 -0000	1.446
--- cmMakefile.cxx	7 Mar 2008 13:40:36 -0000	1.447
***************
*** 281,284 ****
--- 281,412 ----
  }
  
+ //----------------------------------------------------------------------------
+ // Helper function to print a block of text with every line following
+ // a given prefix.
+ void cmMakefilePrintPrefixed(std::ostream& os,  const char* prefix,
+                              std::string const& msg)
+ {
+   bool newline = true;
+   for(const char* c = msg.c_str(); *c; ++c)
+     {
+     if(newline)
+       {
+       os << prefix;
+       newline = false;
+       }
+     os << *c;
+     if(*c == '\n')
+       {
+       newline = true;
+       }
+     }
+   if(!newline)
+     {
+     os << "\n";
+     }
+ }
+ 
+ //----------------------------------------------------------------------------
+ void cmMakefile::IssueError(std::string const& msg) const
+ {
+   this->IssueMessage(msg, true);
+ }
+ 
+ //----------------------------------------------------------------------------
+ void cmMakefile::IssueWarning(std::string const& msg) const
+ {
+   this->IssueMessage(msg, false);
+ }
+ 
+ //----------------------------------------------------------------------------
+ void cmMakefile::IssueMessage(std::string const& text, bool isError) const
+ {
+   cmOStringStream msg;
+ 
+   // Construct the message header.
+   if(isError)
+     {
+     msg << "CMake Error:";
+     }
+   else
+     {
+     msg << "CMake Warning:";
+     }
+ 
+   // Add the immediate context.
+   CallStackType::const_reverse_iterator i = this->CallStack.rbegin();
+   if(i != this->CallStack.rend())
+     {
+     if(isError)
+       {
+       i->Status->SetNestedError(true);
+       }
+     cmListFileContext const& lfc = *i->Context;
+     msg
+       << " at "
+       << this->LocalGenerator->Convert(lfc.FilePath.c_str(),
+                                        cmLocalGenerator::HOME)
+       << ":" << lfc.Line << " " << lfc.Name;
+     ++i;
+     }
+ 
+   // Add the message text.
+   msg << " {\n";
+   cmMakefilePrintPrefixed(msg, "  ", text);
+   msg << "}";
+ 
+   // Add the rest of the context.
+   if(i != this->CallStack.rend())
+     {
+     msg << " with call stack {\n";
+     while(i != this->CallStack.rend())
+       {
+       cmListFileContext const& lfc = *i->Context;
+       msg << "  "
+           << this->LocalGenerator->Convert(lfc.FilePath.c_str(),
+                                            cmLocalGenerator::HOME)
+           << ":" << lfc.Line << " " << lfc.Name << "\n";
+       ++i;
+       }
+     msg << "}\n";
+     }
+   else
+     {
+     msg << "\n";
+     }
+ 
+   // Output the message.
+   if(isError)
+     {
+     cmSystemTools::SetErrorOccured();
+     cmSystemTools::Message(msg.str().c_str(), "Error");
+     }
+   else
+     {
+     cmSystemTools::Message(msg.str().c_str(), "Warning");
+     }
+ }
+ 
+ //----------------------------------------------------------------------------
+ // Helper class to make sure the call stack is valid.
+ class cmMakefileCall
+ {
+ public:
+   cmMakefileCall(cmMakefile* mf,
+                  cmListFileContext const& lfc,
+                  cmExecutionStatus& status): Makefile(mf)
+     {
+     cmMakefile::CallStackEntry entry = {&lfc, &status};
+     this->Makefile->CallStack.push_back(entry);
+     }
+   ~cmMakefileCall()
+     {
+     this->Makefile->CallStack.pop_back();
+     }
+ private:
+   cmMakefile* Makefile;
+ };
+ 
+ //----------------------------------------------------------------------------
  bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
                                  cmExecutionStatus &status)
***************
*** 295,326 ****
    std::string name = lff.Name;
  
!   // execute the command
!   cmCommand *rm =
!     this->GetCMakeInstance()->GetCommand(name.c_str());
!   if(rm)
      {
!     // const char* versionValue
!       // = this->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
!     // int major = 0;
!     // int minor = 0;
!     // if ( versionValue )
!       // {
!       // sscanf(versionValue, "%d.%d", &major, &minor);
!       // }
!     cmCommand* usedCommand = rm->Clone();
!     usedCommand->SetMakefile(this);
!     bool keepCommand = false;
!     if(usedCommand->GetEnabled() && !cmSystemTools::GetFatalErrorOccured()  &&
!        (!this->GetCMakeInstance()->GetScriptMode() ||
!         usedCommand->IsScriptable()))
        {
!       if(!usedCommand->InvokeInitialPass(lff.Arguments,status))
          {
!         cmOStringStream error;
!         error << "Error in cmake code at\n"
!               << lff.FilePath << ":" << lff.Line << ":\n"
!               << usedCommand->GetError() << std::endl
!               << "   Called from: " << this->GetListFileStack().c_str();
!         cmSystemTools::Error(error.str().c_str());
          result = false;
          if ( this->GetCMakeInstance()->GetScriptMode() )
--- 423,450 ----
    std::string name = lff.Name;
  
!   // Place this call on the call stack.
!   cmMakefileCall stack_manager(this, lff, status);
!   static_cast<void>(stack_manager);
! 
!   // Lookup the command prototype.
!   if(cmCommand* proto = this->GetCMakeInstance()->GetCommand(name.c_str()))
      {
!     // Clone the prototype.
!     cmsys::auto_ptr<cmCommand> pcmd(proto->Clone());
!     pcmd->SetMakefile(this);
! 
!     // Decide whether to invoke the command.
!     if(pcmd->GetEnabled() && !cmSystemTools::GetFatalErrorOccured()  &&
!        (!this->GetCMakeInstance()->GetScriptMode() || pcmd->IsScriptable()))
        {
!       // Try invoking the command.
!       if(!pcmd->InvokeInitialPass(lff.Arguments,status) ||
!          status.GetNestedError())
          {
!         if(!status.GetNestedError())
!           {
!           // The command invocation requested that we report an error.
!           this->IssueError(pcmd->GetError());
!           }
          result = false;
          if ( this->GetCMakeInstance()->GetScriptMode() )
***************
*** 332,357 ****
          {
          // use the command
!         keepCommand = true;
!         this->UsedCommands.push_back(usedCommand);
          }
        }
      else if ( this->GetCMakeInstance()->GetScriptMode()
!               && !usedCommand->IsScriptable() )
        {
!       cmOStringStream error;
!       error << "Error in cmake code at\n"
!             << lff.FilePath << ":" << lff.Line << ":\n"
!             << "Command " << usedCommand->GetName()
!             << "() is not scriptable" << std::endl;
!       cmSystemTools::Error(error.str().c_str());
        result = false;
        cmSystemTools::SetFatalErrorOccured();
        }
-     // if the Cloned command was not used
-     // then delete it
-     if(!keepCommand)
-       {
-       delete usedCommand;
-       }
      }
    else
--- 456,472 ----
          {
          // use the command
!         this->UsedCommands.push_back(pcmd.release());
          }
        }
      else if ( this->GetCMakeInstance()->GetScriptMode()
!               && !pcmd->IsScriptable() )
        {
!       std::string error = "Command ";
!       error += pcmd->GetName();
!       error += "() is not scriptable";
!       this->IssueError(error);
        result = false;
        cmSystemTools::SetFatalErrorOccured();
        }
      }
    else
***************
*** 359,367 ****
      if(!cmSystemTools::GetFatalErrorOccured())
        {
!       cmOStringStream error;
!       error << "Error in cmake code at\n"
!             << lff.FilePath << ":" << lff.Line << ":\n"
!             << "Unknown CMake command \"" << lff.Name.c_str() << "\".";
!       cmSystemTools::Error(error.str().c_str());
        result = false;
        cmSystemTools::SetFatalErrorOccured();
--- 474,481 ----
      if(!cmSystemTools::GetFatalErrorOccured())
        {
!       std::string error = "Unknown CMake command \"";
!       error += lff.Name;
!       error += "\".";
!       this->IssueError(error);
        result = false;
        cmSystemTools::SetFatalErrorOccured();
***************
*** 3153,3158 ****
          {
          case cmPolicies::WARN:
!           msg = this->GetPolicies()->
!             GetPolicyWarning(cmPolicies::CMP_0002);
          case cmPolicies::OLD:
            return true;
--- 3267,3272 ----
          {
          case cmPolicies::WARN:
!           this->IssueWarning(this->GetPolicies()->
!                              GetPolicyWarning(cmPolicies::CMP_0002));
          case cmPolicies::OLD:
            return true;



More information about the Cmake-commits mailing list