1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 10:47:59 +08:00

PkgC: Only remove system paths which are exact matches

This commit is contained in:
Vito Gamberini
2025-08-13 12:59:00 -04:00
parent 93f77d8183
commit d5f6cf5ba8
5 changed files with 41 additions and 40 deletions

View File

@@ -56,6 +56,15 @@ std::string AppendAndTrim(std::string& str, cm::string_view sv)
return { &*begin, static_cast<std::size_t>(cur - begin) + 1 };
}
cm::string_view TrimFlag(cm::string_view flag)
{
std::size_t trim_size = 2;
for (auto c = flag.rbegin(); c != flag.rend() && std::isspace(*c); ++c) {
++trim_size;
}
return { flag.data() + 2, flag.size() - trim_size };
}
} // namespace
std::string cmPkgConfigVersionReq::string() const
@@ -460,12 +469,10 @@ cmPkgConfigCflagsResult cmPkgConfigResolver::MangleCflags(
for (auto flag : flags) {
if (flag.rfind("-I", 0) == 0) {
cm::string_view noprefix{ flag.data() + 2, flag.size() - 2 };
if (std::all_of(syspaths.begin(), syspaths.end(),
[&](std::string const& path) {
return noprefix.rfind(path, 0) == noprefix.npos;
})) {
cm::string_view trimmed = TrimFlag(flag);
if (std::all_of(
syspaths.begin(), syspaths.end(),
[&](std::string const& path) { return path != trimmed; })) {
result.Includes.emplace_back(AppendAndTrim(result.Flagline, flag));
}
@@ -486,12 +493,10 @@ cmPkgConfigCflagsResult cmPkgConfigResolver::MangleCflags(
for (auto flag : flags) {
if (flag.rfind("-I", 0) == 0) {
std::string reroot = Reroot(flag, "-I", sysroot);
cm::string_view noprefix{ reroot.data() + 2, reroot.size() - 2 };
if (std::all_of(syspaths.begin(), syspaths.end(),
[&](std::string const& path) {
return noprefix.rfind(path, 0) == noprefix.npos;
})) {
cm::string_view trimmed = TrimFlag(reroot);
if (std::all_of(
syspaths.begin(), syspaths.end(),
[&](std::string const& path) { return path != trimmed; })) {
result.Includes.emplace_back(AppendAndTrim(result.Flagline, reroot));
}
@@ -548,12 +553,10 @@ cmPkgConfigLibsResult cmPkgConfigResolver::MangleLibs(
for (auto flag : flags) {
if (flag.rfind("-L", 0) == 0) {
cm::string_view noprefix{ flag.data() + 2, flag.size() - 2 };
if (std::all_of(syspaths.begin(), syspaths.end(),
[&](std::string const& path) {
return noprefix.rfind(path, 0) == noprefix.npos;
})) {
cm::string_view trimmed = TrimFlag(flag);
if (std::all_of(
syspaths.begin(), syspaths.end(),
[&](std::string const& path) { return path != trimmed; })) {
result.LibDirs.emplace_back(AppendAndTrim(result.Flagline, flag));
}
@@ -576,12 +579,10 @@ cmPkgConfigLibsResult cmPkgConfigResolver::MangleLibs(
for (auto flag : flags) {
if (flag.rfind("-L", 0) == 0) {
std::string reroot = Reroot(flag, "-L", sysroot);
cm::string_view noprefix{ reroot.data() + 2, reroot.size() - 2 };
if (std::all_of(syspaths.begin(), syspaths.end(),
[&](std::string const& path) {
return noprefix.rfind(path, 0) == noprefix.npos;
})) {
cm::string_view trimmed = TrimFlag(reroot);
if (std::all_of(
syspaths.begin(), syspaths.end(),
[&](std::string const& path) { return path != trimmed; })) {
result.LibDirs.emplace_back(AppendAndTrim(result.Flagline, reroot));
}

View File

@@ -1,5 +1,5 @@
Includes: -I/Alpha;-I/Gamma
LibDirs: -L/Delta;-L/Zeta
Includes: -I/Alpha;-I/Alpha/sub;-I/Gamma
LibDirs: -L/Delta;-L/Delta/sub;-L/Zeta
Cflags: QuxInstalled
PC_LIB_DIRS: Alpha;Beta
PC_PATH: [^

View File

@@ -1,8 +1,8 @@
Cflags: Beta -I/Gamma
Includes: -I/Gamma
Libs: Epsilon -L/Zeta
LibDirs: -L/Zeta
Cflags: -I/Alpha Beta -I/Gamma
Includes: -I/Alpha;-I/Gamma
Libs: -L/Delta Epsilon -L/Zeta
LibDirs: -L/Delta;-L/Zeta
Cflags: -I/Alpha/sub Beta -I/Gamma
Includes: -I/Alpha/sub;-I/Gamma
Libs: -L/Delta/sub Epsilon -L/Zeta
LibDirs: -L/Delta/sub;-L/Zeta
Cflags: -I/Alpha -I/Alpha/sub Beta -I/Gamma
Includes: -I/Alpha;-I/Alpha/sub;-I/Gamma
Libs: -L/Delta -L/Delta/sub Epsilon -L/Zeta
LibDirs: -L/Delta;-L/Delta/sub;-L/Zeta

View File

@@ -1,4 +1,4 @@
Cflags: -I/NewRoot/Alpha Beta -I/NewRoot/Gamma
Includes: -I/NewRoot/Alpha;-I/NewRoot/Gamma
Libs: -L/NewRoot/Delta Epsilon -L/NewRoot/Zeta
LibDirs: -L/NewRoot/Delta;-L/NewRoot/Zeta
Cflags: -I/NewRoot/Alpha -I/NewRoot/Alpha/sub Beta -I/NewRoot/Gamma
Includes: -I/NewRoot/Alpha;-I/NewRoot/Alpha/sub;-I/NewRoot/Gamma
Libs: -L/NewRoot/Delta -L/NewRoot/Delta/sub Epsilon -L/NewRoot/Zeta
LibDirs: -L/NewRoot/Delta;-L/NewRoot/Delta/sub;-L/NewRoot/Zeta

View File

@@ -2,5 +2,5 @@ Name: Relocate
Description: For testing relocation and flag mangling
Version: 1.0.0
Cflags: -I/Alpha Beta -I/Gamma
Libs: -L/Delta Epsilon -L/Zeta
Cflags: -I/Alpha -I/Alpha/sub Beta -I/Gamma
Libs: -L/Delta -L/Delta/sub Epsilon -L/Zeta