[Cmake-commits] [cmake-commits] king committed cmListFileCache.cxx 1.40 1.41 cmListFileCache.h 1.20 1.21 cmMakefile.cxx 1.461 1.462 cmMakefile.h 1.229 1.230 cmTarget.cxx 1.206 1.207 cmTarget.h 1.108 1.109 cmake.cxx 1.372 1.373 cmake.h 1.108 1.109

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Mar 13 13:49:00 EDT 2008


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

Modified Files:
	cmListFileCache.cxx cmListFileCache.h cmMakefile.cxx 
	cmMakefile.h cmTarget.cxx cmTarget.h cmake.cxx cmake.h 
Log Message:
ENH: Improve new error/warning message generation

  - Add cmListFileBacktrace to record stack traces
  - Move main IssueMessage method to the cmake class instance
    (make the backtrace an explicit argument)
  - Change cmMakefile::IssueMessage to construct a backtrace
    and call the cmake instance version
  - Record a backtrace at the point a target is created
    (useful later for messages issued by generators)


Index: cmListFileCache.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmListFileCache.cxx,v
retrieving revision 1.40
retrieving revision 1.41
diff -C 2 -d -r1.40 -r1.41
*** cmListFileCache.cxx	13 Mar 2008 15:38:46 -0000	1.40
--- cmListFileCache.cxx	13 Mar 2008 17:48:57 -0000	1.41
***************
*** 269,270 ****
--- 269,285 ----
    return false;
  }
+ 
+ //----------------------------------------------------------------------------
+ std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc)
+ {
+   os << lfc.FilePath;
+   if(lfc.Line)
+     {
+     os << ":" << lfc.Line;
+     if(!lfc.Name.empty())
+       {
+       os << " (" << lfc.Name << ")";
+       }
+     }
+   return os;
+ }

Index: cmake.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmake.h,v
retrieving revision 1.108
retrieving revision 1.109
diff -C 2 -d -r1.108 -r1.109
*** cmake.h	13 Mar 2008 01:06:32 -0000	1.108
--- cmake.h	13 Mar 2008 17:48:57 -0000	1.109
***************
*** 55,58 ****
--- 55,59 ----
  class cmDocumentationSection;
  class cmPolicies;
+ class cmListFileBacktrace;
  
  class cmake
***************
*** 350,353 ****
--- 351,358 ----
        this->SuppressDevWarnings = v;
      }
+ 
+   /** Display a message to the user.  */
+   void IssueMessage(cmake::MessageType t, std::string const& text,
+                     cmListFileBacktrace const& backtrace);
  protected:
    void InitializeProperties();

Index: cmake.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmake.cxx,v
retrieving revision 1.372
retrieving revision 1.373
diff -C 2 -d -r1.372 -r1.373
*** cmake.cxx	13 Mar 2008 15:38:46 -0000	1.372
--- cmake.cxx	13 Mar 2008 17:48:57 -0000	1.373
***************
*** 29,32 ****
--- 29,33 ----
  #include "cmVersion.h"
  #include "cmTest.h"
+ #include "cmDocumentationFormatterText.h"
  
  #if defined(CMAKE_BUILD_WITH_CMAKE)
***************
*** 4109,4110 ****
--- 4110,4188 ----
    return 0;
  }
+ 
+ //----------------------------------------------------------------------------
+ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
+                          cmListFileBacktrace const& backtrace)
+ {
+   cmOStringStream msg;
+   bool isError = false;
+   // Construct the message header.
+   if(t == cmake::FATAL_ERROR)
+     {
+     isError = true;
+     msg << "CMake Error";
+     }
+   else if(t == cmake::INTERNAL_ERROR)
+     {
+     isError = true;
+     msg << "CMake Internal Error (please report a bug)";
+     }
+   else
+     {
+     msg << "CMake Warning";
+     if(t == cmake::AUTHOR_WARNING)
+       {
+       // Allow suppression of these warnings.
+       cmCacheManager::CacheIterator it = this->CacheManager
+         ->GetCacheIterator("CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
+       if(!it.IsAtEnd() && it.GetValueAsBool())
+         {
+         return;
+         }
+       msg << " (dev)";
+       }
+     }
+ 
+   // Add the immediate context.
+   cmListFileBacktrace::const_iterator i = backtrace.begin();
+   if(i != backtrace.end())
+     {
+     cmListFileContext const& lfc = *i;
+     msg << (lfc.Line? " at ": " in ") << lfc;
+     ++i;
+     }
+ 
+   // Add the message text.
+   {
+   msg << ":\n";
+   cmDocumentationFormatterText formatter;
+   formatter.SetIndent("  ");
+   formatter.PrintFormatted(msg, text.c_str());
+   }
+ 
+   // Add the rest of the context.
+   if(i != backtrace.end())
+     {
+     msg << "Call Stack (most recent call first):\n";
+     while(i != backtrace.end())
+       {
+       cmListFileContext const& lfc = *i;
+       msg << "  " << lfc << "\n";
+       ++i;
+       }
+     }
+ 
+   // Add a terminating blank line.
+   msg << "\n";
+ 
+   // Output the message.
+   if(isError)
+     {
+     cmSystemTools::SetErrorOccured();
+     cmSystemTools::Message(msg.str().c_str(), "Error");
+     }
+   else
+     {
+     cmSystemTools::Message(msg.str().c_str(), "Warning");
+     }
+ }

Index: cmMakefile.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.h,v
retrieving revision 1.229
retrieving revision 1.230
diff -C 2 -d -r1.229 -r1.230
*** cmMakefile.h	11 Mar 2008 14:29:55 -0000	1.229
--- cmMakefile.h	13 Mar 2008 17:48:57 -0000	1.230
***************
*** 608,611 ****
--- 608,616 ----
  
    /**
+    * Get the current context backtrace.
+    */
+   bool GetBacktrace(cmListFileBacktrace& backtrace) const;
+ 
+   /**
     * Get the vector of  files created by this makefile
     */

Index: cmTarget.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTarget.h,v
retrieving revision 1.108
retrieving revision 1.109
diff -C 2 -d -r1.108 -r1.109
*** cmTarget.h	1 Mar 2008 17:51:07 -0000	1.108
--- cmTarget.h	13 Mar 2008 17:48:57 -0000	1.109
***************
*** 26,29 ****
--- 26,30 ----
  class cmGlobalGenerator;
  class cmComputeLinkInformation;
+ class cmListFileBacktrace;
  
  struct cmTargetLinkInformationMap:
***************
*** 375,378 ****
--- 376,382 ----
    bool IsAppBundleOnApple();
  
+   /** Get a backtrace from the creation of the target.  */
+   cmListFileBacktrace const& GetBacktrace() const;
+ 
  private:
    /**

Index: cmListFileCache.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmListFileCache.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -C 2 -d -r1.20 -r1.21
*** cmListFileCache.h	7 Mar 2008 13:40:36 -0000	1.20
--- cmListFileCache.h	13 Mar 2008 17:48:57 -0000	1.21
***************
*** 58,61 ****
--- 58,63 ----
  };
  
+ std::ostream& operator<<(std::ostream&, cmListFileContext const&);
+ 
  struct cmListFileFunction: public cmListFileContext
  {
***************
*** 63,66 ****
--- 65,70 ----
  };
  
+ class cmListFileBacktrace: public std::vector<cmListFileContext> {};
+ 
  struct cmListFile
  {

Index: cmTarget.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTarget.cxx,v
retrieving revision 1.206
retrieving revision 1.207
diff -C 2 -d -r1.206 -r1.207
*** cmTarget.cxx	13 Mar 2008 01:06:32 -0000	1.206
--- cmTarget.cxx	13 Mar 2008 17:48:57 -0000	1.207
***************
*** 22,25 ****
--- 22,26 ----
  #include "cmGlobalGenerator.h"
  #include "cmComputeLinkInformation.h"
+ #include "cmListFileCache.h"
  #include <map>
  #include <set>
***************
*** 44,47 ****
--- 45,51 ----
    std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
    bool SourceFileFlagsConstructed;
+ 
+   // The backtrace when the target was created.
+   cmListFileBacktrace Backtrace;
  };
  
***************
*** 720,723 ****
--- 724,736 ----
        }
      }
+ 
+   // Save the backtrace of target construction.
+   this->Makefile->GetBacktrace(this->Internal->Backtrace);
+ }
+ 
+ //----------------------------------------------------------------------------
+ cmListFileBacktrace const& cmTarget::GetBacktrace() const
+ {
+   return this->Internal->Backtrace;
  }
  

Index: cmMakefile.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.cxx,v
retrieving revision 1.461
retrieving revision 1.462
diff -C 2 -d -r1.461 -r1.462
*** cmMakefile.cxx	13 Mar 2008 15:38:46 -0000	1.461
--- cmMakefile.cxx	13 Mar 2008 17:48:57 -0000	1.462
***************
*** 36,41 ****
  #include <stdlib.h> // required for atoi
  
- #include "cmDocumentationFormatterText.h"
- 
  #include <cmsys/RegularExpression.hxx>
  
--- 36,39 ----
***************
*** 288,333 ****
                                std::string const& text) const
  {
!   cmOStringStream msg;
!   bool isError = false;
!   // Construct the message header.
!   if(t == cmake::FATAL_ERROR)
!     {
!     isError = true;
!     msg << "CMake Error:";
!     }
!   else if(t == cmake::INTERNAL_ERROR)
!     {
!     isError = true;
!     msg << "CMake Internal Error, please report a bug: ";
!     }
!   else
!     {
!     msg << "CMake Warning";
!     if(t == cmake::AUTHOR_WARNING)
!       {
!       if(this->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS"))
!         {
!         return;
!         }
!       msg << "(dev)";
!       }
!     msg << ":";
!     }
! 
!   // 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;
      }
    else if(!this->ListFileStack.empty())
--- 286,298 ----
                                std::string const& text) const
  {
!   // Collect context information.
!   cmListFileBacktrace backtrace;
!   if(!this->CallStack.empty())
      {
!     if((t == cmake::FATAL_ERROR) || (t == cmake::INTERNAL_ERROR))
        {
!       this->CallStack.back().Status->SetNestedError(true);
        }
!     this->GetBacktrace(backtrace);
      }
    else if(!this->ListFileStack.empty())
***************
*** 335,393 ****
      // We are processing the project but are not currently executing a
      // command.  Add whatever context information we have.
!     if(this->LocalGenerator->GetParent())
!       {
!       msg << " in directory "
!           << this->LocalGenerator->Convert(this->GetCurrentDirectory(),
!                                            cmLocalGenerator::HOME);
!       }
!     else if(this->GetCMakeInstance()->GetIsInTryCompile())
!       {
!       msg << " in directory " << this->GetCurrentDirectory();
!       }
!     else
        {
!       msg << " in top-level directory";
        }
      }
  
!   // Add the message text.
!   {
!   msg << " {\n";
!   cmDocumentationFormatterText formatter;
!   formatter.SetIndent("  ");
!   formatter.PrintFormatted(msg, text.c_str());
!   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");
      }
  }
  
--- 300,334 ----
      // We are processing the project but are not currently executing a
      // command.  Add whatever context information we have.
!     cmListFileContext lfc;
!     lfc.FilePath = this->ListFileStack.back();
!     lfc.Line = 0;
!     if(!this->GetCMakeInstance()->GetIsInTryCompile())
        {
!       lfc.FilePath = this->LocalGenerator->Convert(lfc.FilePath.c_str(),
!                                                    cmLocalGenerator::HOME);
        }
+     backtrace.push_back(lfc);
      }
  
!   // Issue the message.
!   this->GetCMakeInstance()->IssueMessage(t, text, backtrace);
! }
  
! //----------------------------------------------------------------------------
! bool cmMakefile::GetBacktrace(cmListFileBacktrace& backtrace) const
! {
!   if(this->CallStack.empty())
      {
!     return false;
      }
!   for(CallStackType::const_reverse_iterator i = this->CallStack.rbegin();
!       i != this->CallStack.rend(); ++i)
      {
!     cmListFileContext lfc = *(*i).Context;
!     lfc.FilePath = this->LocalGenerator->Convert(lfc.FilePath.c_str(),
!                                                  cmLocalGenerator::HOME);
!     backtrace.push_back(lfc);
      }
+   return true;
  }
  
***************
*** 1648,1657 ****
  cmMakefile::AddNewTarget(cmTarget::TargetType type, const char* name)
  {
!   cmTargets::iterator it;
!   cmTarget target;
    target.SetType(type, name);
    target.SetMakefile(this);
-   it=this->Targets.insert(
-       cmTargets::value_type(target.GetName(), target)).first;
    this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it);
    return &it->second;
--- 1589,1597 ----
  cmMakefile::AddNewTarget(cmTarget::TargetType type, const char* name)
  {
!   cmTargets::iterator it =
!     this->Targets.insert(cmTargets::value_type(name, cmTarget())).first;
!   cmTarget& target = it->second;
    target.SetType(type, name);
    target.SetMakefile(this);
    this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it);
    return &it->second;



More information about the Cmake-commits mailing list