diff options
author | Nick Little <nicklaus.little@us.af.mil> | 2022-01-27 22:47:32 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-01-28 16:12:59 (GMT) |
commit | 5f8c5657a9a41b6f6138bbc1f35901e4007c477a (patch) | |
tree | c94fe4a785e63aacd3c917cdb90766cd3492ed61 /Source/cmLocalGenerator.cxx | |
parent | d282ca55b8219b04dd03ff1d7125ce65a671ec07 (diff) | |
download | CMake-5f8c5657a9a41b6f6138bbc1f35901e4007c477a.zip CMake-5f8c5657a9a41b6f6138bbc1f35901e4007c477a.tar.gz CMake-5f8c5657a9a41b6f6138bbc1f35901e4007c477a.tar.bz2 |
Shorten object name even if still longer than CMAKE_OBJECT_PATH_MAX
In some cases the shortened path may end up working in practice, even if
it is over CMAKE_OBJECT_PATH_MAX, where the original path does not.
If the original path is too long, do the MD5 substitution whenever it
makes the path shorter. Retain the warning if it is still too long.
Diffstat (limited to 'Source/cmLocalGenerator.cxx')
-rw-r--r-- | Source/cmLocalGenerator.cxx | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 5b3aad3..50e6cdc 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -3430,21 +3430,27 @@ void cmLocalGenerator::GenerateTargetInstallRules( static bool cmLocalGeneratorShortenObjectName(std::string& objName, std::string::size_type max_len) { + // Check if the path can be shortened using an md5 sum replacement for + // a portion of the path. + std::string::size_type md5Len = 32; + std::string::size_type numExtraChars = objName.size() - max_len + md5Len; + std::string::size_type pos = objName.find('/', numExtraChars); + if (pos == std::string::npos) { + pos = objName.rfind('/', numExtraChars); + if (pos == std::string::npos || pos <= md5Len) { + return false; + } + } + // Replace the beginning of the path portion of the object name with // its own md5 sum. - std::string::size_type pos = - objName.find('/', objName.size() - max_len + 32); - if (pos != std::string::npos) { - cmCryptoHash md5(cmCryptoHash::AlgoMD5); - std::string md5name = cmStrCat(md5.HashString(objName.substr(0, pos)), - cm::string_view(objName).substr(pos)); - objName = md5name; + cmCryptoHash md5(cmCryptoHash::AlgoMD5); + std::string md5name = cmStrCat(md5.HashString(objName.substr(0, pos)), + cm::string_view(objName).substr(pos)); + objName = md5name; - // The object name is now short enough. - return true; - } - // The object name could not be shortened enough. - return false; + // The object name is now shorter, check if it is short enough. + return pos >= numExtraChars; } bool cmLocalGeneratorCheckObjectName(std::string& objName, |