Merge branch 'backport-3.16-link-line-backtrace'

This commit is contained in:
Brad King 2020-02-10 16:16:56 -05:00
commit 8752c1bd64
9 changed files with 85 additions and 93 deletions

View File

@ -301,11 +301,11 @@ int cmComputeLinkDepends::AddLinkEntry(cmLinkItem const& item)
// Initialize the item entry.
int index = lei->second;
LinkEntry& entry = this->EntryList[index];
entry.Item = item.AsStr();
entry.Item = BT<std::string>(item.AsStr(), item.Backtrace);
entry.Target = item.Target;
entry.IsFlag =
(!entry.Target && entry.Item[0] == '-' && entry.Item[1] != 'l' &&
entry.Item.substr(0, 10) != "-framework");
entry.IsFlag = (!entry.Target && entry.Item.Value[0] == '-' &&
entry.Item.Value[1] != 'l' &&
entry.Item.Value.substr(0, 10) != "-framework");
// If the item has dependencies queue it to follow them.
if (entry.Target) {
@ -314,7 +314,7 @@ int cmComputeLinkDepends::AddLinkEntry(cmLinkItem const& item)
this->BFSQueue.push(qe);
} else {
// Look for an old-style <item>_LIB_DEPENDS variable.
std::string var = cmStrCat(entry.Item, "_LIB_DEPENDS");
std::string var = cmStrCat(entry.Item.Value, "_LIB_DEPENDS");
if (const char* val = this->Makefile->GetDefinition(var)) {
// The item dependencies are known. Follow them.
BFSEntry qe = { index, val };
@ -396,7 +396,7 @@ void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep)
// Initialize the item entry.
LinkEntry& entry = this->EntryList[lei->second];
entry.Item = dep.Item.AsStr();
entry.Item = BT<std::string>(dep.Item.AsStr(), dep.Item.Backtrace);
entry.Target = dep.Item.Target;
// This item was added specifically because it is a dependent
@ -671,7 +671,8 @@ void cmComputeLinkDepends::DisplayComponents()
fprintf(stderr, "Component (%u):\n", c);
NodeList const& nl = components[c];
for (int i : nl) {
fprintf(stderr, " item %d [%s]\n", i, this->EntryList[i].Item.c_str());
fprintf(stderr, " item %d [%s]\n", i,
this->EntryList[i].Item.Value.c_str());
}
EdgeList const& ol = this->CCG->GetComponentGraphEdges(c);
for (cmGraphEdge const& oi : ol) {
@ -819,7 +820,7 @@ void cmComputeLinkDepends::DisplayFinalEntries()
if (lei.Target) {
fprintf(stderr, " target [%s]\n", lei.Target->GetName().c_str());
} else {
fprintf(stderr, " item [%s]\n", lei.Item.c_str());
fprintf(stderr, " item [%s]\n", lei.Item.Value.c_str());
}
}
fprintf(stderr, "\n");

View File

@ -14,6 +14,7 @@
#include "cmGraphAdjacencyList.h"
#include "cmLinkItem.h"
#include "cmListFileCache.h"
#include "cmTargetLinkLibraryType.h"
class cmComputeComponentGraph;
@ -38,7 +39,7 @@ public:
// Basic information about each link item.
struct LinkEntry
{
std::string Item;
BT<std::string> Item;
cmGeneratorTarget const* Target = nullptr;
bool IsSharedDep = false;
bool IsFlag = false;

View File

@ -642,7 +642,7 @@ void cmComputeLinkInformation::AddImplicitLinkInfo(std::string const& lang)
}
}
void cmComputeLinkInformation::AddItem(std::string const& item,
void cmComputeLinkInformation::AddItem(BT<std::string> const& item,
cmGeneratorTarget const* tgt)
{
// Compute the proper name to use to link this library.
@ -668,7 +668,8 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
std::string exe = tgt->GetFullPath(config, artifact, true);
linkItem += exe;
this->Items.emplace_back(linkItem, true, tgt);
this->Items.emplace_back(BT<std::string>(linkItem, item.Backtrace), true,
tgt);
this->Depends.push_back(std::move(exe));
} else if (tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
// Add the interface library as an item so it can be considered as part
@ -679,7 +680,7 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
// Also add the item the interface specifies to be used in its place.
std::string const& libName = tgt->GetImportedLibName(config);
if (!libName.empty()) {
this->AddItem(libName, nullptr);
this->AddItem(BT<std::string>(libName, item.Backtrace), nullptr);
}
} else if (tgt->GetType() == cmStateEnums::OBJECT_LIBRARY) {
// Ignore object library!
@ -691,8 +692,9 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
: cmStateEnums::RuntimeBinaryArtifact;
// Pass the full path to the target file.
std::string lib = tgt->GetFullPath(config, artifact, true);
if (tgt->Target->IsAIX() && cmHasLiteralSuffix(lib, "-NOTFOUND") &&
BT<std::string> lib = BT<std::string>(
tgt->GetFullPath(config, artifact, true), item.Backtrace);
if (tgt->Target->IsAIX() && cmHasLiteralSuffix(lib.Value, "-NOTFOUND") &&
artifact == cmStateEnums::ImportLibraryArtifact) {
// This is an imported executable on AIX that has ENABLE_EXPORTS
// but not IMPORTED_IMPLIB. CMake used to produce and accept such
@ -703,23 +705,23 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
}
if (!this->LinkDependsNoShared ||
tgt->GetType() != cmStateEnums::SHARED_LIBRARY) {
this->Depends.push_back(lib);
this->Depends.push_back(lib.Value);
}
this->AddTargetItem(lib, tgt);
this->AddLibraryRuntimeInfo(lib, tgt);
this->AddLibraryRuntimeInfo(lib.Value, tgt);
}
} else {
// This is not a CMake target. Use the name given.
if (cmSystemTools::FileIsFullPath(item)) {
if (cmSystemTools::FileIsDirectory(item)) {
if (cmSystemTools::FileIsFullPath(item.Value)) {
if (cmSystemTools::FileIsDirectory(item.Value)) {
// This is a directory.
this->AddDirectoryItem(item);
this->AddDirectoryItem(item.Value);
} else {
// Use the full path given to the library file.
this->Depends.push_back(item);
this->Depends.push_back(item.Value);
this->AddFullItem(item);
this->AddLibraryRuntimeInfo(item);
this->AddLibraryRuntimeInfo(item.Value);
}
} else {
// This is a library or option specified by the user.
@ -728,7 +730,7 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
}
}
void cmComputeLinkInformation::AddSharedDepItem(std::string const& item,
void cmComputeLinkInformation::AddSharedDepItem(BT<std::string> const& item,
const cmGeneratorTarget* tgt)
{
// If dropping shared library dependencies, ignore them.
@ -747,12 +749,12 @@ void cmComputeLinkInformation::AddSharedDepItem(std::string const& item,
} else {
// Skip items that are not full paths. We will not be able to
// reliably specify them.
if (!cmSystemTools::FileIsFullPath(item)) {
if (!cmSystemTools::FileIsFullPath(item.Value)) {
return;
}
// Get the name of the library from the file name.
std::string file = cmSystemTools::GetFilenameName(item);
std::string file = cmSystemTools::GetFilenameName(item.Value);
if (!this->ExtractSharedLibraryName.find(file)) {
// This is not the name of a shared library.
return;
@ -776,7 +778,7 @@ void cmComputeLinkInformation::AddSharedDepItem(std::string const& item,
lib = tgt->GetFullPath(this->Config, artifact);
this->AddLibraryRuntimeInfo(lib, tgt);
} else {
lib = item;
lib = item.Value;
this->AddLibraryRuntimeInfo(lib);
}
@ -1033,7 +1035,7 @@ void cmComputeLinkInformation::SetCurrentLinkType(LinkType lt)
}
}
void cmComputeLinkInformation::AddTargetItem(std::string const& item,
void cmComputeLinkInformation::AddTargetItem(BT<std::string> const& item,
cmGeneratorTarget const* target)
{
// This is called to handle a link item that is a full path to a target.
@ -1054,7 +1056,7 @@ void cmComputeLinkInformation::AddTargetItem(std::string const& item,
// Handle case of an imported shared library with no soname.
if (this->NoSONameUsesPath &&
target->IsImportedSharedLibWithoutSOName(this->Config)) {
this->AddSharedLibNoSOName(item);
this->AddSharedLibNoSOName(item.Value);
return;
}
@ -1062,23 +1064,23 @@ void cmComputeLinkInformation::AddTargetItem(std::string const& item,
// the linker search path.
if (this->OldLinkDirMode && !target->IsFrameworkOnApple() &&
!cmContains(this->OldLinkDirMask,
cmSystemTools::GetFilenamePath(item))) {
this->OldLinkDirItems.push_back(item);
cmSystemTools::GetFilenamePath(item.Value))) {
this->OldLinkDirItems.push_back(item.Value);
}
// Now add the full path to the library.
this->Items.emplace_back(item, true, target);
}
void cmComputeLinkInformation::AddFullItem(std::string const& item)
void cmComputeLinkInformation::AddFullItem(BT<std::string> const& item)
{
// Check for the implicit link directory special case.
if (this->CheckImplicitDirItem(item)) {
if (this->CheckImplicitDirItem(item.Value)) {
return;
}
// Check for case of shared library with no builtin soname.
if (this->NoSONameUsesPath && this->CheckSharedLibNoSOName(item)) {
if (this->NoSONameUsesPath && this->CheckSharedLibNoSOName(item.Value)) {
return;
}
@ -1088,9 +1090,9 @@ void cmComputeLinkInformation::AddFullItem(std::string const& item)
if (this->Target->GetPolicyStatusCMP0008() != cmPolicies::NEW &&
(generator.find("Visual Studio") != std::string::npos ||
generator.find("Xcode") != std::string::npos)) {
std::string file = cmSystemTools::GetFilenameName(item);
std::string file = cmSystemTools::GetFilenameName(item.Value);
if (!this->ExtractAnyLibraryName.find(file)) {
this->HandleBadFullItem(item, file);
this->HandleBadFullItem(item.Value, file);
return;
}
}
@ -1102,10 +1104,10 @@ void cmComputeLinkInformation::AddFullItem(std::string const& item)
// static libraries. If a previous user item changed the link type
// to static we need to make sure it is back to shared.
if (this->LinkTypeEnabled) {
std::string name = cmSystemTools::GetFilenameName(item);
std::string name = cmSystemTools::GetFilenameName(item.Value);
if (this->ExtractSharedLibraryName.find(name)) {
this->SetCurrentLinkType(LinkShared);
} else if (!this->ExtractStaticLibraryName.find(item)) {
} else if (!this->ExtractStaticLibraryName.find(item.Value)) {
// We cannot determine the type. Assume it is the target's
// default type.
this->SetCurrentLinkType(this->StartLinkType);
@ -1116,8 +1118,8 @@ void cmComputeLinkInformation::AddFullItem(std::string const& item)
// the linker search path.
if (this->OldLinkDirMode &&
!cmContains(this->OldLinkDirMask,
cmSystemTools::GetFilenamePath(item))) {
this->OldLinkDirItems.push_back(item);
cmSystemTools::GetFilenamePath(item.Value))) {
this->OldLinkDirItems.push_back(item.Value);
}
// Now add the full path to the library.
@ -1181,7 +1183,7 @@ bool cmComputeLinkInformation::CheckImplicitDirItem(std::string const& item)
return true;
}
void cmComputeLinkInformation::AddUserItem(std::string const& item,
void cmComputeLinkInformation::AddUserItem(BT<std::string> const& item,
bool pathNotKnown)
{
// This is called to handle a link item that does not match a CMake
@ -1193,14 +1195,14 @@ void cmComputeLinkInformation::AddUserItem(std::string const& item,
// libfoo.a ==> -Wl,-Bstatic -lfoo
// Pass flags through untouched.
if (item[0] == '-' || item[0] == '$' || item[0] == '`') {
if (item.Value[0] == '-' || item.Value[0] == '$' || item.Value[0] == '`') {
// if this is a -l option then we might need to warn about
// CMP0003 so put it in OldUserFlagItems, if it is not a -l
// or -Wl,-l (-framework -pthread), then allow it without a
// CMP0003 as -L will not affect those other linker flags
if (item.find("-l") == 0 || item.find("-Wl,-l") == 0) {
if (item.Value.find("-l") == 0 || item.Value.find("-Wl,-l") == 0) {
// This is a linker option provided by the user.
this->OldUserFlagItems.push_back(item);
this->OldUserFlagItems.push_back(item.Value);
}
// Restore the target link type since this item does not specify
@ -1223,7 +1225,7 @@ void cmComputeLinkInformation::AddUserItem(std::string const& item,
// libraries. On AIX a library with the name libfoo.a can be
// shared!
std::string lib;
if (this->ExtractSharedLibraryName.find(item)) {
if (this->ExtractSharedLibraryName.find(item.Value)) {
// This matches a shared library file name.
#ifdef CM_COMPUTE_LINK_INFO_DEBUG
fprintf(stderr, "shared regex matched [%s] [%s] [%s]\n",
@ -1236,7 +1238,7 @@ void cmComputeLinkInformation::AddUserItem(std::string const& item,
// Use just the library name so the linker will search.
lib = this->ExtractSharedLibraryName.match(2);
} else if (this->ExtractStaticLibraryName.find(item)) {
} else if (this->ExtractStaticLibraryName.find(item.Value)) {
// This matches a static library file name.
#ifdef CM_COMPUTE_LINK_INFO_DEBUG
fprintf(stderr, "static regex matched [%s] [%s] [%s]\n",
@ -1249,7 +1251,7 @@ void cmComputeLinkInformation::AddUserItem(std::string const& item,
// Use just the library name so the linker will search.
lib = this->ExtractStaticLibraryName.match(2);
} else if (this->ExtractAnyLibraryName.find(item)) {
} else if (this->ExtractAnyLibraryName.find(item.Value)) {
// This matches a library file name.
#ifdef CM_COMPUTE_LINK_INFO_DEBUG
fprintf(stderr, "any regex matched [%s] [%s] [%s]\n",
@ -1266,19 +1268,19 @@ void cmComputeLinkInformation::AddUserItem(std::string const& item,
} else {
// This is a name specified by the user.
if (pathNotKnown) {
this->OldUserFlagItems.push_back(item);
this->OldUserFlagItems.push_back(item.Value);
}
// We must ask the linker to search for a library with this name.
// Restore the target link type since this item does not specify
// one.
this->SetCurrentLinkType(this->StartLinkType);
lib = item;
lib = item.Value;
}
// Create an option to ask the linker to search for the library.
std::string out = cmStrCat(this->LibLinkFlag, lib, this->LibLinkSuffix);
this->Items.emplace_back(out, false);
this->Items.emplace_back(BT<std::string>(out, item.Backtrace), false);
// Here we could try to find the library the linker will find and
// add a runtime information entry for it. It would probably not be
@ -1308,7 +1310,7 @@ void cmComputeLinkInformation::AddFrameworkItem(std::string const& item)
this->AddLibraryRuntimeInfo(full_fw);
// Add the item using the -framework option.
this->Items.emplace_back("-framework", false);
this->Items.emplace_back(std::string("-framework"), false);
cmOutputConverter converter(this->Makefile->GetStateSnapshot());
fw = converter.EscapeForShell(fw);
this->Items.emplace_back(fw, false);

View File

@ -14,13 +14,13 @@
#include "cmsys/RegularExpression.hxx"
#include "cmListFileCache.h"
class cmGeneratorTarget;
class cmGlobalGenerator;
class cmMakefile;
class cmOrderDirectories;
class cmake;
template <typename T>
class BT;
/** \class cmComputeLinkInformation
* \brief Compute link information for a target in one configuration.
@ -39,13 +39,13 @@ public:
struct Item
{
Item() = default;
Item(std::string v, bool p, cmGeneratorTarget const* target = nullptr)
Item(BT<std::string> v, bool p, cmGeneratorTarget const* target = nullptr)
: Value(std::move(v))
, IsPath(p)
, Target(target)
{
}
std::string Value;
BT<std::string> Value;
bool IsPath = true;
cmGeneratorTarget const* Target = nullptr;
};
@ -78,8 +78,9 @@ public:
const cmGeneratorTarget* GetTarget() { return this->Target; }
private:
void AddItem(std::string const& item, const cmGeneratorTarget* tgt);
void AddSharedDepItem(std::string const& item, cmGeneratorTarget const* tgt);
void AddItem(BT<std::string> const& item, const cmGeneratorTarget* tgt);
void AddSharedDepItem(BT<std::string> const& item,
cmGeneratorTarget const* tgt);
// Output information.
ItemVector Items;
@ -150,10 +151,11 @@ private:
std::string NoCaseExpression(const char* str);
// Handling of link items.
void AddTargetItem(std::string const& item, const cmGeneratorTarget* target);
void AddFullItem(std::string const& item);
void AddTargetItem(BT<std::string> const& item,
const cmGeneratorTarget* target);
void AddFullItem(BT<std::string> const& item);
bool CheckImplicitDirItem(std::string const& item);
void AddUserItem(std::string const& item, bool pathNotKnown);
void AddUserItem(BT<std::string> const& item, bool pathNotKnown);
void AddDirectoryItem(std::string const& item);
void AddFrameworkItem(std::string const& item);
void DropDirectoryItem(std::string const& item);

View File

@ -2817,11 +2817,11 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
linkLibs += sep;
sep = " ";
if (libName.IsPath) {
linkLibs += this->XCodeEscapePath(libName.Value);
linkLibs += this->XCodeEscapePath(libName.Value.Value);
} else if (!libName.Target ||
libName.Target->GetType() !=
cmStateEnums::INTERFACE_LIBRARY) {
linkLibs += libName.Value;
linkLibs += libName.Value.Value;
}
if (libName.Target && !libName.Target->IsImported()) {
target->AddDependTarget(configName, libName.Target->GetName());

View File

@ -9,7 +9,6 @@
#include "cmComputeLinkInformation.h"
#include "cmGeneratorTarget.h"
#include "cmLinkItem.h"
#include "cmListFileCache.h"
#include "cmOutputConverter.h"
#include "cmStateDirectory.h"
@ -85,27 +84,14 @@ void cmLinkLineComputer::ComputeLinkLibs(
BT<std::string> linkLib;
if (item.IsPath) {
linkLib.Value += cli.GetLibLinkFileFlag();
linkLib.Value +=
this->ConvertToOutputFormat(this->ConvertToLinkReference(item.Value));
linkLib.Value += this->ConvertToOutputFormat(
this->ConvertToLinkReference(item.Value.Value));
linkLib.Backtrace = item.Value.Backtrace;
} else {
linkLib.Value += item.Value;
linkLib = item.Value;
}
linkLib.Value += " ";
const cmLinkImplementation* linkImpl =
cli.GetTarget()->GetLinkImplementation(cli.GetConfig());
for (const cmLinkImplItem& iter : linkImpl->Libraries) {
if (iter.Target != nullptr &&
iter.Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
std::string libPath = iter.Target->GetLocation(cli.GetConfig());
if (item.Value == libPath) {
linkLib.Backtrace = iter.Backtrace;
break;
}
}
}
linkLibraries.emplace_back(linkLib);
}
}

View File

@ -115,18 +115,18 @@ void cmLinkLineDeviceComputer::ComputeLinkLibraries(
// These should be passed to nvlink. Other extensions need to be left
// out because nvlink may not understand or need them. Even though it
// can tolerate '.so' or '.dylib' it cannot tolerate '.so.1'.
if (cmHasLiteralSuffix(item.Value, ".a") ||
cmHasLiteralSuffix(item.Value, ".lib")) {
if (cmHasLiteralSuffix(item.Value.Value, ".a") ||
cmHasLiteralSuffix(item.Value.Value, ".lib")) {
linkLib.Value += this->ConvertToOutputFormat(
this->ConvertToLinkReference(item.Value));
this->ConvertToLinkReference(item.Value.Value));
}
} else if (item.Value == "-framework") {
// This is the first part of '-framework Name' where the framework
// name is specified as a following item. Ignore both.
skipItemAfterFramework = true;
continue;
} else if (cmLinkItemValidForDevice(item.Value)) {
linkLib.Value += item.Value;
} else if (cmLinkItemValidForDevice(item.Value.Value)) {
linkLib.Value += item.Value.Value;
}
if (emitted.insert(linkLib.Value).second) {

View File

@ -1254,11 +1254,11 @@ void cmLocalVisualStudio7GeneratorInternals::OutputLibraries(
for (auto const& lib : libs) {
if (lib.IsPath) {
std::string rel =
lg->MaybeConvertToRelativePath(currentBinDir, lib.Value);
lg->MaybeConvertToRelativePath(currentBinDir, lib.Value.Value);
fout << lg->ConvertToXMLOutputPath(rel) << " ";
} else if (!lib.Target ||
lib.Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
fout << lib.Value << " ";
fout << lib.Value.Value << " ";
}
}
}

View File

@ -3259,13 +3259,13 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions(
if (l.IsPath) {
std::string path = this->LocalGenerator->MaybeConvertToRelativePath(
currentBinDir, l.Value);
currentBinDir, l.Value.Value);
ConvertToWindowsSlash(path);
if (!cmVS10IsTargetsFile(l.Value)) {
if (!cmVS10IsTargetsFile(l.Value.Value)) {
libVec.push_back(path);
}
} else {
libVec.push_back(l.Value);
libVec.push_back(l.Value.Value);
}
}
@ -3819,9 +3819,9 @@ bool cmVisualStudio10TargetGenerator::ComputeLibOptions(
std::string currentBinDir =
this->LocalGenerator->GetCurrentBinaryDirectory();
for (cmComputeLinkInformation::Item const& l : libs) {
if (l.IsPath && cmVS10IsTargetsFile(l.Value)) {
if (l.IsPath && cmVS10IsTargetsFile(l.Value.Value)) {
std::string path = this->LocalGenerator->MaybeConvertToRelativePath(
currentBinDir, l.Value);
currentBinDir, l.Value.Value);
ConvertToWindowsSlash(path);
this->AddTargetsFileAndConfigPair(path, config);
}
@ -3905,16 +3905,16 @@ void cmVisualStudio10TargetGenerator::AddLibraries(
if (l.IsPath) {
std::string path = this->LocalGenerator->MaybeConvertToRelativePath(
currentBinDir, l.Value);
currentBinDir, l.Value.Value);
ConvertToWindowsSlash(path);
if (cmVS10IsTargetsFile(l.Value)) {
if (cmVS10IsTargetsFile(l.Value.Value)) {
vsTargetVec.push_back(path);
} else {
libVec.push_back(path);
}
} else if (!l.Target ||
l.Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
libVec.push_back(l.Value);
libVec.push_back(l.Value.Value);
}
}
}