From a9ad70de76b3d37a0686b4d6ee24cf365bd1f278 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 17 Jul 2023 13:53:31 -0400 Subject: [PATCH 1/3] Source: Avoid using CollapseFullPath just to get parent directory --- Source/CPack/cmCPackDebGenerator.cxx | 2 +- Source/CPack/cmCPackFreeBSDGenerator.cxx | 3 +-- Source/cmLocalGenerator.cxx | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx index 8d16428362..41ea32c70b 100644 --- a/Source/CPack/cmCPackDebGenerator.cxx +++ b/Source/CPack/cmCPackDebGenerator.cxx @@ -225,7 +225,7 @@ bool DebGenerator::generateDataTar() const // XXX/application/usr/bin/myprogram with GEN_WDIR=XXX/application // should not add XXX/application orderedFiles.insert(currentPath); - currentPath = cmSystemTools::CollapseFullPath("..", currentPath); + currentPath = cmSystemTools::GetFilenamePath(currentPath); } } diff --git a/Source/CPack/cmCPackFreeBSDGenerator.cxx b/Source/CPack/cmCPackFreeBSDGenerator.cxx index 0840e33cc8..6beb644c83 100644 --- a/Source/CPack/cmCPackFreeBSDGenerator.cxx +++ b/Source/CPack/cmCPackFreeBSDGenerator.cxx @@ -405,8 +405,7 @@ int cmCPackFreeBSDGenerator::PackageFiles() return 0; } - const std::string output_dir = - cmSystemTools::CollapseFullPath("../", toplevel); + const std::string output_dir = cmSystemTools::GetFilenamePath(toplevel); PkgCreate package(output_dir, toplevel, manifestname); if (package.isValid()) { if (!package.Create()) { diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 4afed4314f..7aeea4ddc4 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -909,8 +909,7 @@ std::string cmLocalGenerator::GetIncludeFlags( for (std::string const& i : includes) { if (cmNonempty(fwSearchFlag) && this->Makefile->IsOn("APPLE") && cmSystemTools::IsPathToFramework(i)) { - std::string const frameworkDir = - cmSystemTools::CollapseFullPath(cmStrCat(i, "/../")); + std::string const frameworkDir = cmSystemTools::GetFilenamePath(i); if (emitted.insert(frameworkDir).second) { if (sysFwSearchFlag && target && target->IsSystemIncludeDirectory(frameworkDir, config, lang)) { From cc3c603061ccef897e6f2a82585d011fb4f0e5f9 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 17 Jul 2023 14:28:01 -0400 Subject: [PATCH 2/3] cpack: Simplify package directory selection logic --- Source/CPack/cpack.cxx | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index 00c8fa2247..25c001f342 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -475,32 +475,26 @@ int main(int argc, char const* const* argv) if (!cpackProjectVendor.empty()) { globalMF.AddDefinition("CPACK_PACKAGE_VENDOR", cpackProjectVendor); } - // if this is not empty it has been set on the command line - // go for it. Command line override values set in config file. if (!cpackProjectDirectory.empty()) { - globalMF.AddDefinition("CPACK_PACKAGE_DIRECTORY", cpackProjectDirectory); - } - // The value has not been set on the command line - else { - // get a default value (current working directory) - cpackProjectDirectory = cmSystemTools::GetCurrentWorkingDirectory(); - // use default value if no value has been provided by the config file - if (!globalMF.IsSet("CPACK_PACKAGE_DIRECTORY")) { - globalMF.AddDefinition("CPACK_PACKAGE_DIRECTORY", - cpackProjectDirectory); + // The value has been set on the command line. Ensure it is absolute. + cpackProjectDirectory = + cmSystemTools::CollapseFullPath(cpackProjectDirectory); + } else { + // The value has not been set on the command line. Check config file. + if (cmValue pd = globalMF.GetDefinition("CPACK_PACKAGE_DIRECTORY")) { + // The value has been set in the config file. Ensure it is absolute. + cpackProjectDirectory = cmSystemTools::CollapseFullPath(*pd); + } else { + // Default to the current working directory. + cpackProjectDirectory = cmSystemTools::GetCurrentWorkingDirectory(); } } + globalMF.AddDefinition("CPACK_PACKAGE_DIRECTORY", cpackProjectDirectory); + for (auto const& cd : definitions) { globalMF.AddDefinition(cd.first, cd.second); } - // Force CPACK_PACKAGE_DIRECTORY as absolute path - cpackProjectDirectory = - globalMF.GetSafeDefinition("CPACK_PACKAGE_DIRECTORY"); - cpackProjectDirectory = - cmSystemTools::CollapseFullPath(cpackProjectDirectory); - globalMF.AddDefinition("CPACK_PACKAGE_DIRECTORY", cpackProjectDirectory); - cmValue cpackModulesPath = globalMF.GetDefinition("CPACK_MODULE_PATH"); if (cpackModulesPath) { globalMF.AddDefinition("CMAKE_MODULE_PATH", *cpackModulesPath); From 023720e10a66a3fbee98f49f88dc94b944a18545 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 17 Jul 2023 14:38:55 -0400 Subject: [PATCH 3/3] cpack: Simplify config file selection --- Source/CPack/cpack.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index 25c001f342..39a8e850cd 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -404,7 +404,9 @@ int main(int argc, char const* const* argv) "Read CPack config file: " << cpackConfigFile << '\n'); bool cpackConfigFileSpecified = true; - if (cpackConfigFile.empty()) { + if (!cpackConfigFile.empty()) { + cpackConfigFile = cmSystemTools::CollapseFullPath(cpackConfigFile); + } else { cpackConfigFile = cmStrCat(cmSystemTools::GetCurrentWorkingDirectory(), "/CPackConfig.cmake"); cpackConfigFileSpecified = false; @@ -446,7 +448,6 @@ int main(int argc, char const* const* argv) } if (cmSystemTools::FileExists(cpackConfigFile)) { - cpackConfigFile = cmSystemTools::CollapseFullPath(cpackConfigFile); cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Read CPack configuration file: " << cpackConfigFile << '\n');