From efc6c23a47e456b066089ed6f8fd11a1ca4396d3 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 27 Oct 2021 12:58:02 -0400 Subject: bootstrap: Do not declare cmSystemTools functions that are not implemented Convert runtime error messages into compile-time errors. --- Source/cmInstallExportGenerator.cxx | 2 ++ Source/cmLocalGenerator.cxx | 5 ++++- Source/cmSystemTools.cxx | 24 ++++-------------------- Source/cmSystemTools.h | 4 ++++ Source/cmcmd.cxx | 6 +++++- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Source/cmInstallExportGenerator.cxx b/Source/cmInstallExportGenerator.cxx index d932fd9..820f24a 100644 --- a/Source/cmInstallExportGenerator.cxx +++ b/Source/cmInstallExportGenerator.cxx @@ -85,7 +85,9 @@ void cmInstallExportGenerator::ComputeTempDir() } if (useMD5) { // Replace the destination path with a hash to keep it short. +#ifndef CMAKE_BOOTSTRAP this->TempDir += cmSystemTools::ComputeStringMD5(this->Destination); +#endif } else { std::string dest = this->Destination; // Avoid unix full paths. diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 95c9eea..3a4c386 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2831,7 +2831,10 @@ void cmLocalGenerator::IncludeFileInUnitySources( unity_file << "/* " << pathToHash << " */\n" << "#undef " << *uniqueIdName << "\n" << "#define " << *uniqueIdName << " unity_" - << cmSystemTools::ComputeStringMD5(pathToHash) << "\n"; +#ifndef CMAKE_BOOTSTRAP + << cmSystemTools::ComputeStringMD5(pathToHash) << "\n" +#endif + ; } if (beforeInclude) { diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 7d878b2..1b07358 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1158,39 +1158,26 @@ void cmSystemTools::MoveFileIfDifferent(const std::string& source, RemoveFile(source); } +#ifndef CMAKE_BOOTSTRAP std::string cmSystemTools::ComputeFileHash(const std::string& source, cmCryptoHash::Algo algo) { -#if !defined(CMAKE_BOOTSTRAP) cmCryptoHash hash(algo); return hash.HashFile(source); -#else - (void)source; - cmSystemTools::Message("hashsum not supported in bootstrapping mode", - "Error"); - return std::string(); -#endif } std::string cmSystemTools::ComputeStringMD5(const std::string& input) { -#if !defined(CMAKE_BOOTSTRAP) cmCryptoHash md5(cmCryptoHash::AlgoMD5); return md5.HashString(input); -#else - (void)input; - cmSystemTools::Message("md5sum not supported in bootstrapping mode", - "Error"); - return ""; -#endif } +# ifdef _WIN32 std::string cmSystemTools::ComputeCertificateThumbprint( const std::string& source) { std::string thumbprint; -#if !defined(CMAKE_BOOTSTRAP) && defined(_WIN32) CRYPT_INTEGER_BLOB cryptBlob; HCERTSTORE certStore = NULL; PCCERT_CONTEXT certContext = NULL; @@ -1247,14 +1234,11 @@ std::string cmSystemTools::ComputeCertificateThumbprint( } CloseHandle(certFile); } -#else - (void)source; - cmSystemTools::Message("ComputeCertificateThumbprint is not implemented", - "Error"); -#endif return thumbprint; } +# endif +#endif void cmSystemTools::Glob(const std::string& directory, const std::string& regexp, diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 715724c..19dabe8 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -179,6 +179,7 @@ public: static void MoveFileIfDifferent(const std::string& source, const std::string& destination); +#ifndef CMAKE_BOOTSTRAP //! Compute the hash of a file static std::string ComputeFileHash(const std::string& source, cmCryptoHash::Algo algo); @@ -186,8 +187,11 @@ public: /** Compute the md5sum of a string. */ static std::string ComputeStringMD5(const std::string& input); +# ifdef _WIN32 //! Get the SHA thumbprint for a certificate file static std::string ComputeCertificateThumbprint(const std::string& source); +# endif +#endif /** * Run a single executable command diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index f742ace..265c1fd 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1588,7 +1588,11 @@ int cmcmd::HashSumFile(std::vector const& args, std::cerr << "Error: " << filename << " is a directory" << std::endl; retval++; } else { - std::string value = cmSystemTools::ComputeFileHash(filename, algo); + std::string value +#ifndef CMAKE_BOOTSTRAP + = cmSystemTools::ComputeFileHash(filename, algo) +#endif + ; if (value.empty()) { // To mimic "md5sum/shasum" behavior in a shell: std::cerr << filename << ": No such file or directory" << std::endl; -- cgit v0.12 From 4862f3b2c88e37187c9a5e323f8881b24dbdabef Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 27 Oct 2021 12:58:29 -0400 Subject: cmcmd: Write progress and tar errors directly to stderr In these code paths, `cmSystemTools::Message` never has a callback set. Inline the non-callback implementation at call sites. --- Source/cmcmd.cxx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 265c1fd..8376d4d 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1112,7 +1112,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector const& args, int count; if (countFile) { if (1 != fscanf(countFile, "%i", &count)) { - cmSystemTools::Message("Could not read from count file."); + std::cerr << "Could not read from count file.\n"; } fclose(countFile); } else { @@ -1426,8 +1426,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector const& args, action = cmSystemTools::TarActionExtract; } break; default: { - cmSystemTools::Message( - std::string("tar: Unknown argument: ") + flag, "Warning"); + std::cerr << "tar: Unknown argument: " << flag << "\n"; } } } @@ -1448,8 +1447,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector const& args, } } else if (action == cmSystemTools::TarActionCreate) { if (files.empty()) { - cmSystemTools::Message("tar: No files or directories specified", - "Warning"); + std::cerr << "tar: No files or directories specified\n"; } if (!cmSystemTools::CreateTar(outFile, files, compress, verbose, mtime, format)) { @@ -1688,7 +1686,7 @@ static void cmcmdProgressReport(std::string const& dir, std::string const& num) return; } if (1 != fscanf(progFile, "%i", &count)) { - cmSystemTools::Message("Could not read from progress file."); + std::cerr << "Could not read from progress file.\n"; } fclose(progFile); -- cgit v0.12 From 1a25f057da00f79d9e81c64db87a27061d2ed311 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 27 Oct 2021 12:58:46 -0400 Subject: cmComputeLinkInformation: Add context to warning about linking a directory --- Source/cmComputeLinkInformation.cxx | 17 +++++++++-------- Source/cmComputeLinkInformation.h | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 831a81f..2ff91fe 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -722,7 +722,7 @@ void cmComputeLinkInformation::AddItem(BT const& item, this->AddFrameworkItem(item.Value); } else if (cmSystemTools::FileIsDirectory(item.Value)) { // This is a directory. - this->DropDirectoryItem(item.Value); + this->DropDirectoryItem(item); } else { // Use the full path given to the library file. this->Depends.push_back(item.Value); @@ -1349,16 +1349,17 @@ void cmComputeLinkInformation::AddFrameworkItem(std::string const& item) } } -void cmComputeLinkInformation::DropDirectoryItem(std::string const& item) +void cmComputeLinkInformation::DropDirectoryItem(BT const& item) { // A full path to a directory was found as a link item. Warn the // user. - std::ostringstream e; - e << "WARNING: Target \"" << this->Target->GetName() - << "\" requests linking to directory \"" << item << "\". " - << "Targets may link only to libraries. " - << "CMake is dropping the item."; - cmSystemTools::Message(e.str()); + this->CMakeInstance->IssueMessage( + MessageType::WARNING, + cmStrCat( + "Target \"", this->Target->GetName(), + "\" requests linking to directory \"", item.Value, + "\". Targets may link only to libraries. CMake is dropping the item."), + item.Backtrace); } void cmComputeLinkInformation::ComputeFrameworkInfo() diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h index 90a699e..0315540 100644 --- a/Source/cmComputeLinkInformation.h +++ b/Source/cmComputeLinkInformation.h @@ -187,7 +187,7 @@ private: bool CheckImplicitDirItem(std::string const& item); void AddUserItem(BT const& item, bool pathNotKnown); void AddFrameworkItem(std::string const& item); - void DropDirectoryItem(std::string const& item); + void DropDirectoryItem(BT const& item); bool CheckSharedLibNoSOName(std::string const& item); void AddSharedLibNoSOName(std::string const& item); void HandleBadFullItem(std::string const& item, std::string const& file); -- cgit v0.12 From dbe33b20bde8fd9a2196409a0df91245c082f653 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 27 Oct 2021 12:59:16 -0400 Subject: install: Add context to {PUBLIC,PRIVATE}_HEADER/RESOURCE DESTINATION warnings --- Source/cmInstallCommand.cxx | 16 ++++++++-------- Tests/RunCMake/install/TARGETS-Defaults-Cache-stderr.txt | 13 +++++++++++-- Tests/RunCMake/install/TARGETS-Defaults-stderr.txt | 13 +++++++++++-- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index eaf88f6..193b9be 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -942,9 +942,9 @@ bool HandleTargetsMode(std::vector const& args, helper.GetIncludeDestination(&privateHeaderArgs)); } else { std::ostringstream e; - e << "INSTALL TARGETS - target " << target.GetName() << " has " + e << "Target " << target.GetName() << " has " << "PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION."; - cmSystemTools::Message(e.str(), "Warning"); + helper.Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); } } @@ -964,9 +964,9 @@ bool HandleTargetsMode(std::vector const& args, helper.GetIncludeDestination(&publicHeaderArgs)); } else { std::ostringstream e; - e << "INSTALL TARGETS - target " << target.GetName() << " has " + e << "Target " << target.GetName() << " has " << "PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION."; - cmSystemTools::Message(e.str(), "Warning"); + helper.Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); } } @@ -983,10 +983,10 @@ bool HandleTargetsMode(std::vector const& args, resourceGenerator = CreateInstallFilesGenerator( helper.Makefile, absFiles, resourceArgs, false); } else if (!target.IsAppBundleOnApple()) { - cmSystemTools::Message( - cmStrCat("INSTALL TARGETS - target ", target.GetName(), - " has RESOURCE files but no RESOURCE DESTINATION."), - "Warning"); + helper.Makefile->IssueMessage( + MessageType::AUTHOR_WARNING, + cmStrCat("Target ", target.GetName(), + " has RESOURCE files but no RESOURCE DESTINATION.")); } } } diff --git a/Tests/RunCMake/install/TARGETS-Defaults-Cache-stderr.txt b/Tests/RunCMake/install/TARGETS-Defaults-Cache-stderr.txt index 1939097..138a69d 100644 --- a/Tests/RunCMake/install/TARGETS-Defaults-Cache-stderr.txt +++ b/Tests/RunCMake/install/TARGETS-Defaults-Cache-stderr.txt @@ -1,2 +1,11 @@ -^INSTALL TARGETS - target lib3 has PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION\. -INSTALL TARGETS - target lib4 has PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION\.$ +^CMake Warning \(dev\) at TARGETS-Defaults-Cache.cmake:[0-9]+ \(install\): + Target lib3 has PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. + +CMake Warning \(dev\) at TARGETS-Defaults-Cache.cmake:[0-9]+ \(install\): + Target lib4 has PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it.$ diff --git a/Tests/RunCMake/install/TARGETS-Defaults-stderr.txt b/Tests/RunCMake/install/TARGETS-Defaults-stderr.txt index 1939097..5f56986 100644 --- a/Tests/RunCMake/install/TARGETS-Defaults-stderr.txt +++ b/Tests/RunCMake/install/TARGETS-Defaults-stderr.txt @@ -1,2 +1,11 @@ -^INSTALL TARGETS - target lib3 has PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION\. -INSTALL TARGETS - target lib4 has PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION\.$ +^CMake Warning \(dev\) at TARGETS-Defaults.cmake:[0-9]+ \(install\): + Target lib3 has PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. ++ +CMake Warning \(dev\) at TARGETS-Defaults.cmake:[0-9]+ \(install\): + Target lib4 has PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it.$ -- cgit v0.12