diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2022-04-22 22:13:55 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2022-04-28 13:13:48 (GMT) |
commit | c5b56b35c264664e897a2895e2561a5fb8287703 (patch) | |
tree | 74a2c0c2524178f8b0e60832a595500be29762e6 /Source/cmInstallExportGenerator.cxx | |
parent | c107760417d5941202713fbaaa3e25e62d1dd12e (diff) | |
download | CMake-c5b56b35c264664e897a2895e2561a5fb8287703.zip CMake-c5b56b35c264664e897a2895e2561a5fb8287703.tar.gz CMake-c5b56b35c264664e897a2895e2561a5fb8287703.tar.bz2 |
cmInstallExportGenerator: expose the temporary directory
This needs to be known so that C++ module properties for the install can
be staged beside the other files.
Always perform the MD5 transformation (in non-bootstrap builds) so that
the path can be computed prior to generation (where it used the longest
configuration name to detect too-long paths). Update tests to expect the
always-present MD5 value. Note that this improves robustness of the test
suite as testing in a too-long path may have triggered the MD5
conversion anyways.
Diffstat (limited to 'Source/cmInstallExportGenerator.cxx')
-rw-r--r-- | Source/cmInstallExportGenerator.cxx | 76 |
1 files changed, 19 insertions, 57 deletions
diff --git a/Source/cmInstallExportGenerator.cxx b/Source/cmInstallExportGenerator.cxx index eb7537d..f1ac656 100644 --- a/Source/cmInstallExportGenerator.cxx +++ b/Source/cmInstallExportGenerator.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallExportGenerator.h" -#include <algorithm> #include <map> #include <sstream> #include <utility> @@ -54,73 +53,36 @@ bool cmInstallExportGenerator::Compute(cmLocalGenerator* lg) return true; } -void cmInstallExportGenerator::ComputeTempDir() +std::string cmInstallExportGenerator::TempDirCalculate() const { // Choose a temporary directory in which to generate the import // files to be installed. - this->TempDir = cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(), - "/CMakeFiles/Export"); + std::string path = cmStrCat( + this->LocalGenerator->GetCurrentBinaryDirectory(), "/CMakeFiles/Export"); if (this->Destination.empty()) { - return; - } - this->TempDir += "/"; - - // Enforce a maximum length. - bool useMD5 = false; -#if defined(_WIN32) || defined(__CYGWIN__) - std::string::size_type const max_total_len = 250; -#else - std::string::size_type const max_total_len = 1000; -#endif - // Will generate files of the form "<temp-dir>/<base>-<config>.<ext>". - std::string::size_type const len = this->TempDir.size() + 1 + - this->FileName.size() + 1 + this->GetMaxConfigLength(); - if (len < max_total_len) { - // Keep the total path length below the limit. - std::string::size_type const max_len = max_total_len - len; - if (this->Destination.size() > max_len) { - useMD5 = true; - } - } else { - useMD5 = true; + return path; } - if (useMD5) { - // Replace the destination path with a hash to keep it short. + #ifndef CMAKE_BOOTSTRAP - this->TempDir += cmSystemTools::ComputeStringMD5(this->Destination); + path += '/'; + // Replace the destination path with a hash to keep it short. + path += cmSystemTools::ComputeStringMD5(this->Destination); #endif - } else { - std::string dest = this->Destination; - // Avoid unix full paths. - if (dest[0] == '/') { - dest[0] = '_'; - } - // Avoid windows full paths by removing colons. - std::replace(dest.begin(), dest.end(), ':', '_'); - // Avoid relative paths that go up the tree. - cmSystemTools::ReplaceString(dest, "../", "__/"); - // Avoid spaces. - std::replace(dest.begin(), dest.end(), ' ', '_'); - this->TempDir += dest; - } + + return path; } -size_t cmInstallExportGenerator::GetMaxConfigLength() const +void cmInstallExportGenerator::ComputeTempDir() { - // Always use at least 8 for "noconfig". - size_t len = 8; - if (this->ConfigurationTypes->empty()) { - if (this->ConfigurationName.size() > 8) { - len = this->ConfigurationName.size(); - } - } else { - for (std::string const& c : *this->ConfigurationTypes) { - if (c.size() > len) { - len = c.size(); - } - } + this->TempDir = this->TempDirCalculate(); +} + +std::string cmInstallExportGenerator::GetTempDir() const +{ + if (this->TempDir.empty()) { + return this->TempDirCalculate(); } - return len; + return this->TempDir; } void cmInstallExportGenerator::GenerateScript(std::ostream& os) |