Răsfoiți Sursa

cmState: Store execution context.

Extend snapshot creation API to store the file being executed and the
entry point to get to that context.
Stephen Kelly 10 ani în urmă
părinte
comite
6361f68056
6 a modificat fișierele cu 133 adăugiri și 25 ștergeri
  1. 1 0
      Source/cmFunctionCommand.cxx
  2. 1 0
      Source/cmMacroCommand.cxx
  3. 31 10
      Source/cmMakefile.cxx
  4. 7 5
      Source/cmMakefile.h
  5. 66 5
      Source/cmState.cxx
  6. 27 5
      Source/cmState.h

+ 1 - 0
Source/cmFunctionCommand.cxx

@@ -95,6 +95,7 @@ bool cmFunctionHelperCommand::InvokeInitialPass
     }
     }
 
 
   cmMakefile::FunctionPushPop functionScope(this->Makefile,
   cmMakefile::FunctionPushPop functionScope(this->Makefile,
+                                            this->FilePath,
                                             this->Policies);
                                             this->Policies);
 
 
   // set the value of argc
   // set the value of argc

+ 1 - 0
Source/cmMacroCommand.cxx

@@ -97,6 +97,7 @@ bool cmMacroHelperCommand::InvokeInitialPass
     }
     }
 
 
   cmMakefile::MacroPushPop macroScope(this->Makefile,
   cmMakefile::MacroPushPop macroScope(this->Makefile,
+                                      this->FilePath,
                                       this->Policies);
                                       this->Policies);
 
 
   // set the value of argc
   // set the value of argc

+ 31 - 10
Source/cmMakefile.cxx

@@ -465,8 +465,11 @@ cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf,
   this->Makefile->PushFunctionBlockerBarrier();
   this->Makefile->PushFunctionBlockerBarrier();
 
 
   this->Makefile->StateSnapshot =
   this->Makefile->StateSnapshot =
-        this->Makefile->GetState()->CreateCallStackSnapshot(
-            this->Makefile->StateSnapshot);
+      this->Makefile->GetState()->CreateCallStackSnapshot(
+        this->Makefile->StateSnapshot,
+        this->Makefile->ContextStack.back()->Name,
+        this->Makefile->ContextStack.back()->Line,
+        filenametoread);
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
@@ -576,9 +579,16 @@ public:
     this->Makefile->ListFileStack.push_back(filenametoread);
     this->Makefile->ListFileStack.push_back(filenametoread);
     this->Makefile->PushPolicyBarrier();
     this->Makefile->PushPolicyBarrier();
 
 
+    long line = 0;
+    std::string name;
+    if (!this->Makefile->ContextStack.empty())
+      {
+      line = this->Makefile->ContextStack.back()->Line;
+      name = this->Makefile->ContextStack.back()->Name;
+      }
     this->Makefile->StateSnapshot =
     this->Makefile->StateSnapshot =
         this->Makefile->GetState()->CreateInlineListFileSnapshot(
         this->Makefile->GetState()->CreateInlineListFileSnapshot(
-          this->Makefile->StateSnapshot);
+          this->Makefile->StateSnapshot, name, line, filenametoread);
     assert(this->Makefile->StateSnapshot.IsValid());
     assert(this->Makefile->StateSnapshot.IsValid());
     this->Makefile->PushFunctionBlockerBarrier();
     this->Makefile->PushFunctionBlockerBarrier();
   }
   }
@@ -1590,11 +1600,14 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent)
   this->ImportedTargets = parent->ImportedTargets;
   this->ImportedTargets = parent->ImportedTargets;
 }
 }
 
 
-void cmMakefile::PushFunctionScope(const cmPolicies::PolicyMap& pm)
+void cmMakefile::PushFunctionScope(std::string const& fileName,
+                                   const cmPolicies::PolicyMap& pm)
 {
 {
   this->StateSnapshot =
   this->StateSnapshot =
       this->GetState()->CreateFunctionCallSnapshot(
       this->GetState()->CreateFunctionCallSnapshot(
-        this->StateSnapshot);
+        this->StateSnapshot,
+        this->ContextStack.back()->Name, this->ContextStack.back()->Line,
+        fileName);
   assert(this->StateSnapshot.IsValid());
   assert(this->StateSnapshot.IsValid());
 
 
   this->Internal->PushDefinitions();
   this->Internal->PushDefinitions();
@@ -1632,11 +1645,14 @@ void cmMakefile::PopFunctionScope(bool reportError)
   this->Internal->PopDefinitions();
   this->Internal->PopDefinitions();
 }
 }
 
 
-void cmMakefile::PushMacroScope(const cmPolicies::PolicyMap& pm)
+void cmMakefile::PushMacroScope(std::string const& fileName,
+                                const cmPolicies::PolicyMap& pm)
 {
 {
   this->StateSnapshot =
   this->StateSnapshot =
       this->GetState()->CreateMacroCallSnapshot(
       this->GetState()->CreateMacroCallSnapshot(
-        this->StateSnapshot);
+        this->StateSnapshot,
+        this->ContextStack.back()->Name, this->ContextStack.back()->Line,
+        fileName);
   assert(this->StateSnapshot.IsValid());
   assert(this->StateSnapshot.IsValid());
 
 
   this->PushFunctionBlockerBarrier();
   this->PushFunctionBlockerBarrier();
@@ -1670,6 +1686,7 @@ public:
     std::string currentStart =
     std::string currentStart =
         this->Makefile->StateSnapshot.GetCurrentSourceDirectory();
         this->Makefile->StateSnapshot.GetCurrentSourceDirectory();
     currentStart += "/CMakeLists.txt";
     currentStart += "/CMakeLists.txt";
+    this->Makefile->StateSnapshot.SetListFile(currentStart);
     this->Makefile->ListFileStack.push_back(currentStart);
     this->Makefile->ListFileStack.push_back(currentStart);
     this->Makefile->PushPolicyBarrier();
     this->Makefile->PushPolicyBarrier();
     this->Makefile->PushFunctionBlockerBarrier();
     this->Makefile->PushFunctionBlockerBarrier();
@@ -1813,7 +1830,9 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath,
     }
     }
 
 
   cmState::Snapshot newSnapshot = this->GetState()
   cmState::Snapshot newSnapshot = this->GetState()
-      ->CreateBuildsystemDirectorySnapshot(this->StateSnapshot);
+      ->CreateBuildsystemDirectorySnapshot(this->StateSnapshot,
+                                           this->ContextStack.back()->Name,
+                                           this->ContextStack.back()->Line);
 
 
   // create a new local generator and set its parent
   // create a new local generator and set its parent
   cmLocalGenerator *lg2 = this->GetGlobalGenerator()
   cmLocalGenerator *lg2 = this->GetGlobalGenerator()
@@ -5511,10 +5530,11 @@ AddRequiredTargetCFeature(cmTarget *target, const std::string& feature) const
 
 
 
 
 cmMakefile::FunctionPushPop::FunctionPushPop(cmMakefile* mf,
 cmMakefile::FunctionPushPop::FunctionPushPop(cmMakefile* mf,
+                                             const std::string& fileName,
                                              cmPolicies::PolicyMap const& pm)
                                              cmPolicies::PolicyMap const& pm)
   : Makefile(mf), ReportError(true)
   : Makefile(mf), ReportError(true)
 {
 {
-  this->Makefile->PushFunctionScope(pm);
+  this->Makefile->PushFunctionScope(fileName, pm);
 }
 }
 
 
 cmMakefile::FunctionPushPop::~FunctionPushPop()
 cmMakefile::FunctionPushPop::~FunctionPushPop()
@@ -5524,10 +5544,11 @@ cmMakefile::FunctionPushPop::~FunctionPushPop()
 
 
 
 
 cmMakefile::MacroPushPop::MacroPushPop(cmMakefile* mf,
 cmMakefile::MacroPushPop::MacroPushPop(cmMakefile* mf,
+                                       const std::string& fileName,
                                        const cmPolicies::PolicyMap& pm)
                                        const cmPolicies::PolicyMap& pm)
   : Makefile(mf), ReportError(true)
   : Makefile(mf), ReportError(true)
 {
 {
-  this->Makefile->PushMacroScope(pm);
+  this->Makefile->PushMacroScope(fileName, pm);
 }
 }
 
 
 cmMakefile::MacroPushPop::~MacroPushPop()
 cmMakefile::MacroPushPop::~MacroPushPop()

+ 7 - 5
Source/cmMakefile.h

@@ -720,7 +720,7 @@ public:
   class FunctionPushPop
   class FunctionPushPop
   {
   {
   public:
   public:
-    FunctionPushPop(cmMakefile* mf,
+    FunctionPushPop(cmMakefile* mf, std::string const& fileName,
                     cmPolicies::PolicyMap const& pm);
                     cmPolicies::PolicyMap const& pm);
     ~FunctionPushPop();
     ~FunctionPushPop();
 
 
@@ -733,8 +733,8 @@ public:
   class MacroPushPop
   class MacroPushPop
   {
   {
   public:
   public:
-    MacroPushPop(cmMakefile* mf,
-                    cmPolicies::PolicyMap const& pm);
+    MacroPushPop(cmMakefile* mf, std::string const& fileName,
+                 cmPolicies::PolicyMap const& pm);
     ~MacroPushPop();
     ~MacroPushPop();
 
 
     void Quiet() { this->ReportError = false; }
     void Quiet() { this->ReportError = false; }
@@ -743,9 +743,11 @@ public:
     bool ReportError;
     bool ReportError;
   };
   };
 
 
-  void PushFunctionScope(cmPolicies::PolicyMap const& pm);
+  void PushFunctionScope(std::string const& fileName,
+                         cmPolicies::PolicyMap const& pm);
   void PopFunctionScope(bool reportError);
   void PopFunctionScope(bool reportError);
-  void PushMacroScope(cmPolicies::PolicyMap const& pm);
+  void PushMacroScope(std::string const& fileName,
+                      cmPolicies::PolicyMap const& pm);
   void PopMacroScope(bool reportError);
   void PopMacroScope(bool reportError);
   void PushScope();
   void PushScope();
   void PopScope();
   void PopScope();

+ 66 - 5
Source/cmState.cxx

@@ -23,8 +23,11 @@ struct cmState::SnapshotDataType
   cmState::PositionType CallStackParent;
   cmState::PositionType CallStackParent;
   cmState::PositionType DirectoryParent;
   cmState::PositionType DirectoryParent;
   cmState::SnapshotType SnapshotType;
   cmState::SnapshotType SnapshotType;
+  cmLinkedTree<std::string>::iterator ExecutionListFile;
   cmLinkedTree<cmState::BuildsystemDirectoryStateType>::iterator
   cmLinkedTree<cmState::BuildsystemDirectoryStateType>::iterator
                                                           BuildSystemDirectory;
                                                           BuildSystemDirectory;
+  std::string EntryPointCommand;
+  long EntryPointLine;
 };
 };
 
 
 struct cmState::BuildsystemDirectoryStateType
 struct cmState::BuildsystemDirectoryStateType
@@ -227,6 +230,7 @@ cmState::Snapshot cmState::Reset()
 
 
   this->BuildsystemDirectory.Truncate();
   this->BuildsystemDirectory.Truncate();
   PositionType pos = this->SnapshotData.Truncate();
   PositionType pos = this->SnapshotData.Truncate();
+  this->ExecutionListFiles.Truncate();
 
 
   this->DefineProperty
   this->DefineProperty
     ("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY,
     ("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY,
@@ -683,61 +687,98 @@ cmState::Snapshot cmState::CreateBaseSnapshot()
   pos->SnapshotType = BuildsystemDirectoryType;
   pos->SnapshotType = BuildsystemDirectoryType;
   pos->BuildSystemDirectory =
   pos->BuildSystemDirectory =
       this->BuildsystemDirectory.Extend(this->BuildsystemDirectory.Root());
       this->BuildsystemDirectory.Extend(this->BuildsystemDirectory.Root());
+  pos->ExecutionListFile =
+      this->ExecutionListFiles.Extend(this->ExecutionListFiles.Root());
   return cmState::Snapshot(this, pos);
   return cmState::Snapshot(this, pos);
 }
 }
 
 
 cmState::Snapshot
 cmState::Snapshot
-cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot)
+cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot,
+                                    std::string const& entryPointCommand,
+                                    long entryPointLine)
 {
 {
   assert(originSnapshot.IsValid());
   assert(originSnapshot.IsValid());
   PositionType pos = this->SnapshotData.Extend(originSnapshot.Position);
   PositionType pos = this->SnapshotData.Extend(originSnapshot.Position);
   pos->CallStackParent = originSnapshot.Position;
   pos->CallStackParent = originSnapshot.Position;
+  pos->EntryPointLine = entryPointLine;
+  pos->EntryPointCommand = entryPointCommand;
   pos->DirectoryParent = originSnapshot.Position;
   pos->DirectoryParent = originSnapshot.Position;
   pos->SnapshotType = BuildsystemDirectoryType;
   pos->SnapshotType = BuildsystemDirectoryType;
   pos->BuildSystemDirectory =
   pos->BuildSystemDirectory =
       this->BuildsystemDirectory.Extend(
       this->BuildsystemDirectory.Extend(
         originSnapshot.Position->BuildSystemDirectory);
         originSnapshot.Position->BuildSystemDirectory);
+  pos->ExecutionListFile =
+      this->ExecutionListFiles.Extend(
+        originSnapshot.Position->ExecutionListFile);
   return cmState::Snapshot(this, pos);
   return cmState::Snapshot(this, pos);
 }
 }
 
 
 cmState::Snapshot
 cmState::Snapshot
-cmState::CreateFunctionCallSnapshot(cmState::Snapshot originSnapshot)
+cmState::CreateFunctionCallSnapshot(cmState::Snapshot originSnapshot,
+                                    std::string const& entryPointCommand,
+                                    long entryPointLine,
+                                    std::string const& fileName)
 {
 {
   PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
   PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
                                                *originSnapshot.Position);
                                                *originSnapshot.Position);
   pos->CallStackParent = originSnapshot.Position;
   pos->CallStackParent = originSnapshot.Position;
+  pos->EntryPointLine = entryPointLine;
+  pos->EntryPointCommand = entryPointCommand;
   pos->SnapshotType = FunctionCallType;
   pos->SnapshotType = FunctionCallType;
+  pos->ExecutionListFile = this->ExecutionListFiles.Extend(
+        originSnapshot.Position->ExecutionListFile, fileName);
   return cmState::Snapshot(this, pos);
   return cmState::Snapshot(this, pos);
 }
 }
 
 
 
 
 cmState::Snapshot
 cmState::Snapshot
-cmState::CreateMacroCallSnapshot(cmState::Snapshot originSnapshot)
+cmState::CreateMacroCallSnapshot(cmState::Snapshot originSnapshot,
+                                    std::string const& entryPointCommand,
+                                    long entryPointLine,
+                                    std::string const& fileName)
 {
 {
   PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
   PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
                                                *originSnapshot.Position);
                                                *originSnapshot.Position);
   pos->CallStackParent = originSnapshot.Position;
   pos->CallStackParent = originSnapshot.Position;
+  pos->EntryPointLine = entryPointLine;
+  pos->EntryPointCommand = entryPointCommand;
   pos->SnapshotType = MacroCallType;
   pos->SnapshotType = MacroCallType;
+  pos->ExecutionListFile = this->ExecutionListFiles.Extend(
+        originSnapshot.Position->ExecutionListFile, fileName);
   return cmState::Snapshot(this, pos);
   return cmState::Snapshot(this, pos);
 }
 }
 
 
 cmState::Snapshot
 cmState::Snapshot
-cmState::CreateCallStackSnapshot(cmState::Snapshot originSnapshot)
+cmState::CreateCallStackSnapshot(cmState::Snapshot originSnapshot,
+                                 const std::string& entryPointCommand,
+                                 long entryPointLine,
+                                 const std::string& fileName)
 {
 {
   PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
   PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
                                                *originSnapshot.Position);
                                                *originSnapshot.Position);
   pos->CallStackParent = originSnapshot.Position;
   pos->CallStackParent = originSnapshot.Position;
+  pos->EntryPointLine = entryPointLine;
+  pos->EntryPointCommand = entryPointCommand;
   pos->SnapshotType = CallStackType;
   pos->SnapshotType = CallStackType;
+  pos->ExecutionListFile = this->ExecutionListFiles.Extend(
+        originSnapshot.Position->ExecutionListFile, fileName);
   return cmState::Snapshot(this, pos);
   return cmState::Snapshot(this, pos);
 }
 }
 
 
 cmState::Snapshot
 cmState::Snapshot
-cmState::CreateInlineListFileSnapshot(cmState::Snapshot originSnapshot)
+cmState::CreateInlineListFileSnapshot(cmState::Snapshot originSnapshot,
+                                      const std::string& entryPointCommand,
+                                      long entryPointLine,
+                                      const std::string& fileName)
 {
 {
   PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
   PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
                                                *originSnapshot.Position);
                                                *originSnapshot.Position);
   pos->CallStackParent = originSnapshot.Position;
   pos->CallStackParent = originSnapshot.Position;
+  pos->EntryPointLine = entryPointLine;
+  pos->EntryPointCommand = entryPointCommand;
   pos->SnapshotType = InlineListFileType;
   pos->SnapshotType = InlineListFileType;
+  pos->ExecutionListFile = this->ExecutionListFiles.Extend(
+        originSnapshot.Position->ExecutionListFile, fileName);
   return cmState::Snapshot(this, pos);
   return cmState::Snapshot(this, pos);
 }
 }
 
 
@@ -797,6 +838,11 @@ void cmState::Snapshot::SetCurrentBinaryDirectory(std::string const& dir)
   this->ComputeRelativePathTopBinary();
   this->ComputeRelativePathTopBinary();
 }
 }
 
 
+void cmState::Snapshot::SetListFile(const std::string& listfile)
+{
+  *this->Position->ExecutionListFile = listfile;
+}
+
 std::vector<std::string> const&
 std::vector<std::string> const&
 cmState::Snapshot::GetCurrentSourceDirectoryComponents() const
 cmState::Snapshot::GetCurrentSourceDirectoryComponents() const
 {
 {
@@ -831,6 +877,21 @@ void cmState::Snapshot::SetRelativePathTopBinary(const char* dir)
   this->Position->BuildSystemDirectory->RelativePathTopBinary = dir;
   this->Position->BuildSystemDirectory->RelativePathTopBinary = dir;
 }
 }
 
 
+std::string cmState::Snapshot::GetExecutionListFile() const
+{
+  return *this->Position->ExecutionListFile;
+}
+
+std::string cmState::Snapshot::GetEntryPointCommand() const
+{
+  return this->Position->EntryPointCommand;
+}
+
+long cmState::Snapshot::GetEntryPointLine() const
+{
+  return this->Position->EntryPointLine;
+}
+
 bool cmState::Snapshot::IsValid() const
 bool cmState::Snapshot::IsValid() const
 {
 {
   return this->State && this->Position.IsValid()
   return this->State && this->Position.IsValid()

+ 27 - 5
Source/cmState.h

@@ -47,6 +47,8 @@ public:
     const char* GetCurrentBinaryDirectory() const;
     const char* GetCurrentBinaryDirectory() const;
     void SetCurrentBinaryDirectory(std::string const& dir);
     void SetCurrentBinaryDirectory(std::string const& dir);
 
 
+    void SetListFile(std::string const& listfile);
+
     std::vector<std::string> const&
     std::vector<std::string> const&
     GetCurrentSourceDirectoryComponents() const;
     GetCurrentSourceDirectoryComponents() const;
     std::vector<std::string> const&
     std::vector<std::string> const&
@@ -57,6 +59,10 @@ public:
     void SetRelativePathTopSource(const char* dir);
     void SetRelativePathTopSource(const char* dir);
     void SetRelativePathTopBinary(const char* dir);
     void SetRelativePathTopBinary(const char* dir);
 
 
+    std::string GetExecutionListFile() const;
+    std::string GetEntryPointCommand() const;
+    long GetEntryPointLine() const;
+
     bool IsValid() const;
     bool IsValid() const;
     Snapshot GetBuildsystemDirectoryParent() const;
     Snapshot GetBuildsystemDirectoryParent() const;
     Snapshot GetCallStackParent() const;
     Snapshot GetCallStackParent() const;
@@ -75,11 +81,25 @@ public:
 
 
   Snapshot CreateBaseSnapshot();
   Snapshot CreateBaseSnapshot();
   Snapshot
   Snapshot
-  CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot);
-  Snapshot CreateFunctionCallSnapshot(Snapshot originSnapshot);
-  Snapshot CreateMacroCallSnapshot(Snapshot originSnapshot);
-  Snapshot CreateCallStackSnapshot(Snapshot originSnapshot);
-  Snapshot CreateInlineListFileSnapshot(Snapshot originSnapshot);
+  CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot,
+                                     std::string const& entryPointCommand,
+                                     long entryPointLine);
+  Snapshot CreateFunctionCallSnapshot(Snapshot originSnapshot,
+                                      std::string const& entryPointCommand,
+                                      long entryPointLine,
+                                      std::string const& fileName);
+  Snapshot CreateMacroCallSnapshot(Snapshot originSnapshot,
+                                   std::string const& entryPointCommand,
+                                   long entryPointLine,
+                                   std::string const& fileName);
+  Snapshot CreateCallStackSnapshot(Snapshot originSnapshot,
+                                   std::string const& entryPointCommand,
+                                   long entryPointLine,
+                                   std::string const& fileName);
+  Snapshot CreateInlineListFileSnapshot(Snapshot originSnapshot,
+                                        const std::string& entryPointCommand,
+                                        long entryPointLine,
+                                        std::string const& fileName);
   Snapshot Pop(Snapshot originSnapshot);
   Snapshot Pop(Snapshot originSnapshot);
 
 
   enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC,
   enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC,
@@ -186,6 +206,8 @@ private:
   struct BuildsystemDirectoryStateType;
   struct BuildsystemDirectoryStateType;
   cmLinkedTree<BuildsystemDirectoryStateType> BuildsystemDirectory;
   cmLinkedTree<BuildsystemDirectoryStateType> BuildsystemDirectory;
 
 
+  cmLinkedTree<std::string> ExecutionListFiles;
+
   cmLinkedTree<SnapshotDataType> SnapshotData;
   cmLinkedTree<SnapshotDataType> SnapshotData;
 
 
   std::vector<std::string> SourceDirectoryComponents;
   std::vector<std::string> SourceDirectoryComponents;