From 429fb28f25752352db876f634d3b317962cfeb7d Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Tue, 6 Jul 2021 16:11:42 +0200 Subject: cmLocalGenerator: Factor out repeated condition into local variable --- Source/cmLocalGenerator.cxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index a14f085..f58f142 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1247,9 +1247,11 @@ std::vector> cmLocalGenerator::GetIncludeDirectoriesImplicit( } } + bool const isCorCxx = (lang == "C" || lang == "CXX"); + // Checks if this is not an excluded (implicit) include directory. auto notExcluded = [this, &implicitSet, &implicitExclude, - &lang](std::string const& dir) { + isCorCxx](std::string const& dir) { return ( // Do not exclude directories that are not in an excluded set. ((!cm::contains(implicitSet, this->GlobalGenerator->GetRealPath(dir))) && @@ -1258,8 +1260,7 @@ std::vector> cmLocalGenerator::GetIncludeDirectoriesImplicit( // they are implicitly searched by the compiler. They are meant to be // user-specified directories that can be re-ordered or converted to // -isystem without breaking real compiler builtin headers. - || - ((lang == "C" || lang == "CXX") && cm::contains(this->EnvCPATH, dir))); + || (isCorCxx && cm::contains(this->EnvCPATH, dir))); }; // Get the target-specific include directories. -- cgit v0.12 From 3fd56472c6b6a78ba47cea0905a1694a7e6cec38 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Tue, 6 Jul 2021 16:11:42 +0200 Subject: cmLocalGenerator: Store realpath lookup result in a variable --- Source/cmLocalGenerator.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index f58f142..051b15a 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1251,10 +1251,11 @@ std::vector> cmLocalGenerator::GetIncludeDirectoriesImplicit( // Checks if this is not an excluded (implicit) include directory. auto notExcluded = [this, &implicitSet, &implicitExclude, - isCorCxx](std::string const& dir) { + isCorCxx](std::string const& dir) -> bool { + std::string const& real_dir = this->GlobalGenerator->GetRealPath(dir); return ( // Do not exclude directories that are not in an excluded set. - ((!cm::contains(implicitSet, this->GlobalGenerator->GetRealPath(dir))) && + ((!cm::contains(implicitSet, real_dir)) && (!cm::contains(implicitExclude, dir))) // Do not exclude entries of the CPATH environment variable even though // they are implicitly searched by the compiler. They are meant to be -- cgit v0.12 From 10969fd003919ba32072ead5d134e024bd37f228 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Tue, 6 Jul 2021 16:11:42 +0200 Subject: cmLocalGenerator: Remove unnecessary parentheses in a condition --- Source/cmLocalGenerator.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 051b15a..5fbff6c 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1253,15 +1253,15 @@ std::vector> cmLocalGenerator::GetIncludeDirectoriesImplicit( auto notExcluded = [this, &implicitSet, &implicitExclude, isCorCxx](std::string const& dir) -> bool { std::string const& real_dir = this->GlobalGenerator->GetRealPath(dir); - return ( + return // Do not exclude directories that are not in an excluded set. - ((!cm::contains(implicitSet, real_dir)) && - (!cm::contains(implicitExclude, dir))) + (!cm::contains(implicitSet, real_dir) && + !cm::contains(implicitExclude, dir)) // Do not exclude entries of the CPATH environment variable even though // they are implicitly searched by the compiler. They are meant to be // user-specified directories that can be re-ordered or converted to // -isystem without breaking real compiler builtin headers. - || (isCorCxx && cm::contains(this->EnvCPATH, dir))); + || (isCorCxx && cm::contains(this->EnvCPATH, dir)); }; // Get the target-specific include directories. -- cgit v0.12 From 86595b300297c9572eea5710837f5bb12251c62f Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Tue, 6 Jul 2021 16:11:42 +0200 Subject: cmLocalGenerator: Clarify check for membership in multiple sets --- Source/cmLocalGenerator.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 5fbff6c..cfda21f 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1254,9 +1254,9 @@ std::vector> cmLocalGenerator::GetIncludeDirectoriesImplicit( isCorCxx](std::string const& dir) -> bool { std::string const& real_dir = this->GlobalGenerator->GetRealPath(dir); return - // Do not exclude directories that are not in an excluded set. - (!cm::contains(implicitSet, real_dir) && - !cm::contains(implicitExclude, dir)) + // Do not exclude directories that are not in any excluded set. + !(cm::contains(implicitSet, real_dir) || + cm::contains(implicitExclude, dir)) // Do not exclude entries of the CPATH environment variable even though // they are implicitly searched by the compiler. They are meant to be // user-specified directories that can be re-ordered or converted to -- cgit v0.12 From 5c02964aff0e126980fe327ad1601665d9fcabfe Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Tue, 6 Jul 2021 16:11:42 +0200 Subject: cmLocalGenerator: Simplify CPATH lookup loop --- Source/cmLocalGenerator.cxx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index cfda21f..30df4c4 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -107,10 +107,9 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile) { std::vector cpath; cmSystemTools::GetPath(cpath, "CPATH"); - for (std::string& cp : cpath) { + for (std::string const& cp : cpath) { if (cmSystemTools::FileIsFullPath(cp)) { - cp = cmSystemTools::CollapseFullPath(cp); - this->EnvCPATH.emplace(std::move(cp)); + this->EnvCPATH.emplace(cmSystemTools::CollapseFullPath(cp)); } } } -- cgit v0.12 From c00f928ce1aba90c0b3fe8d6112eacd0f5494ec3 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Tue, 6 Jul 2021 16:11:42 +0200 Subject: Do not exclude include directory symlinks to entries of CPATH Extend the fix from commit 2d0b0e2b9d (Do not exclude include directories made implicit by CPATH, 2019-05-29, v3.14.5~2^2) to cover include directories that are symlinks to paths listed in `CPATH`. Compare resolved paths against resolved entries of `CPATH`. Resolve the entries as late as possible in case symlinks change. Fixes: #22383 --- Source/cmLocalGenerator.cxx | 16 +++++++++++++--- Source/cmLocalGenerator.h | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 30df4c4..3d36acd 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -109,7 +109,7 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile) cmSystemTools::GetPath(cpath, "CPATH"); for (std::string const& cp : cpath) { if (cmSystemTools::FileIsFullPath(cp)) { - this->EnvCPATH.emplace(cmSystemTools::CollapseFullPath(cp)); + this->EnvCPATH.emplace_back(cmSystemTools::CollapseFullPath(cp)); } } } @@ -1248,8 +1248,18 @@ std::vector> cmLocalGenerator::GetIncludeDirectoriesImplicit( bool const isCorCxx = (lang == "C" || lang == "CXX"); + // Resolve symlinks in CPATH for comparison with resolved include paths. + // We do this here instead of when EnvCPATH is populated in case symlinks + // on disk have changed in the meantime. + std::set resolvedEnvCPATH; + if (isCorCxx) { + for (std::string const& i : this->EnvCPATH) { + resolvedEnvCPATH.emplace(this->GlobalGenerator->GetRealPath(i)); + } + } + // Checks if this is not an excluded (implicit) include directory. - auto notExcluded = [this, &implicitSet, &implicitExclude, + auto notExcluded = [this, &implicitSet, &implicitExclude, &resolvedEnvCPATH, isCorCxx](std::string const& dir) -> bool { std::string const& real_dir = this->GlobalGenerator->GetRealPath(dir); return @@ -1260,7 +1270,7 @@ std::vector> cmLocalGenerator::GetIncludeDirectoriesImplicit( // they are implicitly searched by the compiler. They are meant to be // user-specified directories that can be re-ordered or converted to // -isystem without breaking real compiler builtin headers. - || (isCorCxx && cm::contains(this->EnvCPATH, dir)); + || (isCorCxx && cm::contains(resolvedEnvCPATH, real_dir)); }; // Get the target-specific include directories. diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 993280a..cafb34d 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -587,7 +587,7 @@ protected: std::string::size_type ObjectPathMax; std::set ObjectMaxPathViolations; - std::set EnvCPATH; + std::vector EnvCPATH; using GeneratorTargetMap = std::unordered_map; -- cgit v0.12