mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-29 04:09:35 +03:00
Refactor: Keep track of prefixes in cmSearchPath
This commit is contained in:
@@ -135,7 +135,7 @@ protected:
|
||||
std::map<PathLabel, cmSearchPath> LabeledPaths;
|
||||
|
||||
std::vector<std::string> SearchPaths;
|
||||
std::set<std::string> SearchPathsEmitted;
|
||||
std::set<cmSearchPath::PathWithPrefix> SearchPathsEmitted;
|
||||
|
||||
bool SearchFrameworkFirst;
|
||||
bool SearchFrameworkOnly;
|
||||
|
||||
@@ -1309,7 +1309,7 @@ inline std::size_t collectPathsForDebug(std::string& buffer,
|
||||
return 0;
|
||||
}
|
||||
for (std::size_t i = startIndex; i < paths.size(); i++) {
|
||||
buffer += " " + paths[i] + "\n";
|
||||
buffer += " " + paths[i].Path + "\n";
|
||||
}
|
||||
return paths.size();
|
||||
}
|
||||
|
||||
+37
-22
@@ -26,16 +26,16 @@ void cmSearchPath::ExtractWithout(const std::set<std::string>& ignore,
|
||||
if (clear) {
|
||||
outPaths.clear();
|
||||
}
|
||||
for (std::string const& path : this->Paths) {
|
||||
if (ignore.count(path) == 0) {
|
||||
outPaths.push_back(path);
|
||||
for (auto const& path : this->Paths) {
|
||||
if (ignore.count(path.Path) == 0) {
|
||||
outPaths.push_back(path.Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmSearchPath::AddPath(const std::string& path)
|
||||
{
|
||||
this->AddPathInternal(path);
|
||||
this->AddPathInternal(path, "");
|
||||
}
|
||||
|
||||
void cmSearchPath::AddUserPath(const std::string& path)
|
||||
@@ -69,7 +69,7 @@ void cmSearchPath::AddUserPath(const std::string& path)
|
||||
// Process them all from the current directory
|
||||
for (std::string const& p : outPaths) {
|
||||
this->AddPathInternal(
|
||||
p, this->FC->Makefile->GetCurrentSourceDirectory().c_str());
|
||||
p, "", this->FC->Makefile->GetCurrentSourceDirectory().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ void cmSearchPath::AddCMakePath(const std::string& variable)
|
||||
|
||||
for (std::string const& p : expanded) {
|
||||
this->AddPathInternal(
|
||||
p, this->FC->Makefile->GetCurrentSourceDirectory().c_str());
|
||||
p, "", this->FC->Makefile->GetCurrentSourceDirectory().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ void cmSearchPath::AddEnvPath(const std::string& variable)
|
||||
std::vector<std::string> expanded;
|
||||
cmSystemTools::GetPath(expanded, variable.c_str());
|
||||
for (std::string const& p : expanded) {
|
||||
this->AddPathInternal(p);
|
||||
this->AddPathInternal(p, "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,24 +132,25 @@ void cmSearchPath::AddEnvPrefixPath(const std::string& variable, bool stripBin)
|
||||
|
||||
void cmSearchPath::AddSuffixes(const std::vector<std::string>& suffixes)
|
||||
{
|
||||
std::vector<std::string> inPaths;
|
||||
std::vector<PathWithPrefix> inPaths;
|
||||
inPaths.swap(this->Paths);
|
||||
this->Paths.reserve(inPaths.size() * (suffixes.size() + 1));
|
||||
|
||||
for (std::string& inPath : inPaths) {
|
||||
cmSystemTools::ConvertToUnixSlashes(inPath);
|
||||
for (PathWithPrefix& inPath : inPaths) {
|
||||
cmSystemTools::ConvertToUnixSlashes(inPath.Path);
|
||||
cmSystemTools::ConvertToUnixSlashes(inPath.Prefix);
|
||||
|
||||
// if *i is only / then do not add a //
|
||||
// this will get incorrectly considered a network
|
||||
// path on windows and cause huge delays.
|
||||
std::string p = inPath;
|
||||
std::string p = inPath.Path;
|
||||
if (!p.empty() && p.back() != '/') {
|
||||
p += "/";
|
||||
}
|
||||
|
||||
// Combine with all the suffixes
|
||||
for (std::string const& suffix : suffixes) {
|
||||
this->Paths.push_back(p + suffix);
|
||||
this->Paths.push_back(PathWithPrefix{ p + suffix, inPath.Prefix });
|
||||
}
|
||||
|
||||
// And now the original w/o any suffix
|
||||
@@ -178,6 +179,10 @@ void cmSearchPath::AddPrefixPaths(const std::vector<std::string>& paths,
|
||||
if (!subdir.empty() && !dir.empty() && dir.back() != '/') {
|
||||
dir += "/";
|
||||
}
|
||||
std::string prefix = dir;
|
||||
if (!prefix.empty() && prefix != "/") {
|
||||
prefix.erase(prefix.size() - 1);
|
||||
}
|
||||
if (subdir == "include" || subdir == "lib") {
|
||||
cmValue arch =
|
||||
this->FC->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE");
|
||||
@@ -185,37 +190,47 @@ void cmSearchPath::AddPrefixPaths(const std::vector<std::string>& paths,
|
||||
if (this->FC->Makefile->IsDefinitionSet("CMAKE_SYSROOT") &&
|
||||
this->FC->Makefile->IsDefinitionSet(
|
||||
"CMAKE_PREFIX_LIBRARY_ARCHITECTURE")) {
|
||||
this->AddPathInternal(cmStrCat('/', *arch, dir, subdir), base);
|
||||
this->AddPathInternal(cmStrCat('/', *arch, dir, subdir),
|
||||
cmStrCat('/', *arch, prefix), base);
|
||||
} else {
|
||||
this->AddPathInternal(cmStrCat(dir, subdir, '/', *arch), base);
|
||||
this->AddPathInternal(cmStrCat(dir, subdir, '/', *arch), prefix,
|
||||
base);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string add = dir + subdir;
|
||||
if (add != "/") {
|
||||
this->AddPathInternal(add, base);
|
||||
this->AddPathInternal(add, prefix, base);
|
||||
}
|
||||
if (subdir == "bin") {
|
||||
this->AddPathInternal(dir + "sbin", base);
|
||||
this->AddPathInternal(dir + "sbin", prefix, base);
|
||||
}
|
||||
if (!subdir.empty() && path != "/") {
|
||||
this->AddPathInternal(path, base);
|
||||
this->AddPathInternal(path, prefix, base);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmSearchPath::AddPathInternal(const std::string& path, const char* base)
|
||||
void cmSearchPath::AddPathInternal(const std::string& path,
|
||||
const std::string& prefix, const char* base)
|
||||
{
|
||||
assert(this->FC != nullptr);
|
||||
|
||||
std::string collapsed = cmSystemTools::CollapseFullPath(path, base);
|
||||
std::string collapsedPath = cmSystemTools::CollapseFullPath(path, base);
|
||||
|
||||
if (collapsed.empty()) {
|
||||
if (collapsedPath.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string collapsedPrefix;
|
||||
if (!prefix.empty()) {
|
||||
collapsedPrefix = cmSystemTools::CollapseFullPath(prefix, base);
|
||||
}
|
||||
|
||||
// Insert the path if has not already been emitted.
|
||||
if (this->FC->SearchPathsEmitted.insert(collapsed).second) {
|
||||
this->Paths.push_back(std::move(collapsed));
|
||||
PathWithPrefix pathWithPrefix{ std::move(collapsedPath),
|
||||
std::move(collapsedPrefix) };
|
||||
if (this->FC->SearchPathsEmitted.insert(pathWithPrefix).second) {
|
||||
this->Paths.emplace_back(std::move(pathWithPrefix));
|
||||
}
|
||||
}
|
||||
|
||||
+15
-3
@@ -29,7 +29,18 @@ public:
|
||||
cmSearchPath(const cmSearchPath&) = default;
|
||||
cmSearchPath& operator=(const cmSearchPath&) = default;
|
||||
|
||||
const std::vector<std::string>& GetPaths() const { return this->Paths; }
|
||||
struct PathWithPrefix
|
||||
{
|
||||
std::string Path;
|
||||
std::string Prefix;
|
||||
|
||||
bool operator<(const PathWithPrefix& other) const
|
||||
{
|
||||
return this->Path < other.Path ||
|
||||
(this->Path == other.Path && this->Prefix < other.Prefix);
|
||||
}
|
||||
};
|
||||
const std::vector<PathWithPrefix>& GetPaths() const { return this->Paths; }
|
||||
std::size_t size() const { return this->Paths.size(); }
|
||||
|
||||
void ExtractWithout(const std::set<std::string>& ignore,
|
||||
@@ -47,8 +58,9 @@ public:
|
||||
const char* base = nullptr);
|
||||
|
||||
protected:
|
||||
void AddPathInternal(const std::string& path, const char* base = nullptr);
|
||||
void AddPathInternal(const std::string& path, const std::string& prefix,
|
||||
const char* base = nullptr);
|
||||
|
||||
cmFindCommon* FC;
|
||||
std::vector<std::string> Paths;
|
||||
std::vector<PathWithPrefix> Paths;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user