Răsfoiți Sursa

cmLinkItem: Add backtrace

Carry a backtrace on every link item, not just link implementation
items.  For now the non-impl items will still have empty backtraces at
runtime, but this will allow us to introduce values over time.
Brad King 7 ani în urmă
părinte
comite
a093b1a4f3

+ 2 - 1
Source/cmComputeLinkDepends.cxx

@@ -6,6 +6,7 @@
 #include "cmComputeComponentGraph.h"
 #include "cmGeneratorTarget.h"
 #include "cmGlobalGenerator.h"
+#include "cmListFileCache.h"
 #include "cmLocalGenerator.h"
 #include "cmMakefile.h"
 #include "cmStateTypes.h"
@@ -565,7 +566,7 @@ cmLinkItem cmComputeLinkDepends::ResolveLinkItem(int depender_index,
       from = depender;
     }
   }
-  return from->ResolveLinkItem(name);
+  return from->ResolveLinkItem(name, cmListFileBacktrace());
 }
 
 void cmComputeLinkDepends::InferDependencies()

+ 7 - 13
Source/cmComputeTargetDepends.cxx

@@ -6,6 +6,7 @@
 #include "cmGeneratorTarget.h"
 #include "cmGlobalGenerator.h"
 #include "cmLinkItem.h"
+#include "cmListFileCache.h"
 #include "cmLocalGenerator.h"
 #include "cmMakefile.h"
 #include "cmPolicies.h"
@@ -22,8 +23,6 @@
 #include <stdio.h>
 #include <utility>
 
-class cmListFileBacktrace;
-
 /*
 
 This class is meant to analyze inter-target dependencies globally
@@ -208,7 +207,8 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index)
       for (cmSourceFile const* o : objectFiles) {
         std::string const& objLib = o->GetObjectLibrary();
         if (!objLib.empty()) {
-          cmLinkItem const& objItem = depender->ResolveLinkItem(objLib);
+          cmLinkItem const& objItem =
+            depender->ResolveLinkItem(objLib, cmListFileBacktrace());
           if (emitted.insert(objItem).second) {
             if (depender->GetType() != cmStateEnums::EXECUTABLE &&
                 depender->GetType() != cmStateEnums::STATIC_LIBRARY &&
@@ -230,7 +230,7 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index)
       cmLinkImplementation const* impl = depender->GetLinkImplementation(it);
 
       // A target should not depend on itself.
-      emitted.insert(cmLinkItem(depender));
+      emitted.insert(cmLinkItem(depender, cmListFileBacktrace()));
       for (cmLinkImplItem const& lib : impl->Libraries) {
         // Don't emit the same library twice for this target.
         if (emitted.insert(lib).second) {
@@ -246,7 +246,7 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index)
     std::set<cmLinkItem> const& tutils = depender->GetUtilityItems();
     std::set<cmLinkItem> emitted;
     // A target should not depend on itself.
-    emitted.insert(cmLinkItem(depender));
+    emitted.insert(cmLinkItem(depender, cmListFileBacktrace()));
     for (cmLinkItem const& litem : tutils) {
       // Don't emit the same utility twice for this target.
       if (emitted.insert(litem).second) {
@@ -289,7 +289,7 @@ void cmComputeTargetDepends::AddInterfaceDepends(
 
   if (dependee) {
     // A target should not depend on itself.
-    emitted.insert(cmLinkItem(depender));
+    emitted.insert(cmLinkItem(depender, cmListFileBacktrace()));
     this->AddInterfaceDepends(depender_index, dependee, config, emitted);
   }
 }
@@ -327,13 +327,7 @@ void cmComputeTargetDepends::AddTargetDepend(int depender_index,
       e << "The dependency target \"" << dependee_name << "\" of target \""
         << depender->GetName() << "\" does not exist.";
 
-      cmListFileBacktrace const* backtrace =
-        depender->GetUtilityBacktrace(dependee_name.AsStr());
-      if (backtrace) {
-        cm->IssueMessage(messageType, e.str(), *backtrace);
-      } else {
-        cm->IssueMessage(messageType, e.str());
-      }
+      cm->IssueMessage(messageType, e.str(), dependee_name.Backtrace);
     }
   }
 

+ 17 - 11
Source/cmGeneratorTarget.cxx

@@ -676,11 +676,14 @@ std::set<cmLinkItem> const& cmGeneratorTarget::GetUtilityItems() const
     this->UtilityItemsDone = true;
     std::set<std::string> const& utilities = this->GetUtilities();
     for (std::string const& i : utilities) {
+      cmListFileBacktrace const* bt = this->GetUtilityBacktrace(i);
       if (cmGeneratorTarget* gt =
             this->LocalGenerator->FindGeneratorTargetToUse(i)) {
-        this->UtilityItems.insert(cmLinkItem(gt));
+        this->UtilityItems.insert(
+          cmLinkItem(gt, bt ? *bt : cmListFileBacktrace()));
       } else {
-        this->UtilityItems.insert(cmLinkItem(i));
+        this->UtilityItems.insert(
+          cmLinkItem(i, bt ? *bt : cmListFileBacktrace()));
       }
     }
   }
@@ -4618,6 +4621,7 @@ void cmGeneratorTarget::ReportPropertyOrigin(
 }
 
 void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
+                                        cmListFileBacktrace const& bt,
                                         std::vector<cmLinkItem>& items) const
 {
   for (std::string const& n : names) {
@@ -4625,7 +4629,7 @@ void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
     if (name == this->GetName() || name.empty()) {
       continue;
     }
-    items.push_back(this->ResolveLinkItem(name));
+    items.push_back(this->ResolveLinkItem(name, bt));
   }
 }
 
@@ -4647,7 +4651,7 @@ void cmGeneratorTarget::ExpandLinkItems(
                                                   false, headTarget, this,
                                                   &dagChecker),
                                     libs);
-  this->LookupLinkItems(libs, items);
+  this->LookupLinkItems(libs, cge->GetBacktrace(), items);
   hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
 }
 
@@ -5200,7 +5204,7 @@ const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface(
                           iface.HadHeadSensitiveCondition);
     std::vector<std::string> deps;
     cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
-    this->LookupLinkItems(deps, iface.SharedDeps);
+    this->LookupLinkItems(deps, cmListFileBacktrace(), iface.SharedDeps);
   }
 
   return &iface;
@@ -5736,7 +5740,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
       }
 
       // The entry is meant for this configuration.
-      impl.Libraries.emplace_back(this->ResolveLinkItem(name), *btIt,
+      impl.Libraries.emplace_back(this->ResolveLinkItem(name, *btIt),
                                   evaluated != *le);
     }
 
@@ -5764,7 +5768,8 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
         continue;
       }
       // Support OLD behavior for CMP0003.
-      impl.WrongConfigLibraries.push_back(this->ResolveLinkItem(name));
+      impl.WrongConfigLibraries.push_back(
+        this->ResolveLinkItem(name, cmListFileBacktrace()));
     }
   }
 }
@@ -5811,12 +5816,13 @@ cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference(
   return resolved;
 }
 
-cmLinkItem cmGeneratorTarget::ResolveLinkItem(std::string const& name) const
+cmLinkItem cmGeneratorTarget::ResolveLinkItem(
+  std::string const& name, cmListFileBacktrace const& bt) const
 {
   TargetOrString resolved = this->ResolveTargetReference(name);
 
   if (!resolved.Target) {
-    return cmLinkItem(resolved.String);
+    return cmLinkItem(resolved.String, bt);
   }
 
   // Skip targets that will not really be linked.  This is probably a
@@ -5824,10 +5830,10 @@ cmLinkItem cmGeneratorTarget::ResolveLinkItem(std::string const& name) const
   // within the project.
   if (resolved.Target->GetType() == cmStateEnums::EXECUTABLE &&
       !resolved.Target->IsExecutableWithExports()) {
-    return cmLinkItem(resolved.Target->GetName());
+    return cmLinkItem(resolved.Target->GetName(), bt);
   }
 
-  return cmLinkItem(resolved.Target);
+  return cmLinkItem(resolved.Target, bt);
 }
 
 std::string cmGeneratorTarget::GetPDBDirectory(const std::string& config) const

+ 3 - 1
Source/cmGeneratorTarget.h

@@ -362,7 +362,8 @@ public:
   };
   TargetOrString ResolveTargetReference(std::string const& name) const;
 
-  cmLinkItem ResolveLinkItem(std::string const& name) const;
+  cmLinkItem ResolveLinkItem(std::string const& name,
+                             cmListFileBacktrace const& bt) const;
 
   // Compute the set of languages compiled by the target.  This is
   // computed every time it is called because the languages can change
@@ -838,6 +839,7 @@ private:
                        std::vector<cmLinkItem>& items,
                        bool& hadHeadSensitiveCondition) const;
   void LookupLinkItems(std::vector<std::string> const& names,
+                       cmListFileBacktrace const& bt,
                        std::vector<cmLinkItem>& items) const;
 
   void GetSourceFiles(std::vector<std::string>& files,

+ 6 - 6
Source/cmLinkItem.cxx

@@ -12,15 +12,18 @@ cmLinkItem::cmLinkItem()
 {
 }
 
-cmLinkItem::cmLinkItem(std::string const& n)
+cmLinkItem::cmLinkItem(std::string const& n, cmListFileBacktrace const& bt)
   : String(n)
   , Target(nullptr)
+  , Backtrace(bt)
 {
 }
 
-cmLinkItem::cmLinkItem(cmGeneratorTarget const* t)
+cmLinkItem::cmLinkItem(cmGeneratorTarget const* t,
+                       cmListFileBacktrace const& bt)
   : String()
   , Target(t)
+  , Backtrace(bt)
 {
 }
 
@@ -58,15 +61,12 @@ std::ostream& operator<<(std::ostream& os, cmLinkItem const& item)
 
 cmLinkImplItem::cmLinkImplItem()
   : cmLinkItem()
-  , Backtrace()
   , FromGenex(false)
 {
 }
 
-cmLinkImplItem::cmLinkImplItem(cmLinkItem item, cmListFileBacktrace const& bt,
-                               bool fromGenex)
+cmLinkImplItem::cmLinkImplItem(cmLinkItem item, bool fromGenex)
   : cmLinkItem(std::move(item))
-  , Backtrace(bt)
   , FromGenex(fromGenex)
 {
 }

+ 4 - 5
Source/cmLinkItem.h

@@ -24,10 +24,11 @@ class cmLinkItem
 
 public:
   cmLinkItem();
-  explicit cmLinkItem(std::string const& s);
-  explicit cmLinkItem(cmGeneratorTarget const* t);
+  cmLinkItem(std::string const& s, cmListFileBacktrace const& bt);
+  cmLinkItem(cmGeneratorTarget const* t, cmListFileBacktrace const& bt);
   std::string const& AsStr() const;
   cmGeneratorTarget const* Target;
+  cmListFileBacktrace Backtrace;
   friend bool operator<(cmLinkItem const& l, cmLinkItem const& r);
   friend bool operator==(cmLinkItem const& l, cmLinkItem const& r);
   friend std::ostream& operator<<(std::ostream& os, cmLinkItem const& item);
@@ -37,9 +38,7 @@ class cmLinkImplItem : public cmLinkItem
 {
 public:
   cmLinkImplItem();
-  cmLinkImplItem(cmLinkItem item, cmListFileBacktrace const& bt,
-                 bool fromGenex);
-  cmListFileBacktrace Backtrace;
+  cmLinkImplItem(cmLinkItem item, bool fromGenex);
   bool FromGenex;
 };