From 596439b1bbac44b4218f65615d93e9fe9bd43922 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Mon, 5 Oct 2020 12:15:17 -0400 Subject: cmCustomCommandGenerator: Add option to transform depfile --- Source/cmCustomCommandGenerator.cxx | 73 ++++++++++++++++++++++++++++++++++++- Source/cmCustomCommandGenerator.h | 4 +- Source/cmGlobalGenerator.h | 6 +++ bootstrap | 67 +++++++++++++++++----------------- 4 files changed, 113 insertions(+), 37 deletions(-) diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index 60504ba..d8307f6 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -6,18 +6,22 @@ #include #include +#include #include +#include "cmCryptoHash.h" #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" +#include "cmGlobalGenerator.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmProperty.h" #include "cmStateTypes.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" +#include "cmTransformDepfile.h" namespace { void AppendPaths(const std::vector& inputs, @@ -42,7 +46,8 @@ void AppendPaths(const std::vector& inputs, cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, std::string config, - cmLocalGenerator* lg) + cmLocalGenerator* lg, + bool transformDepfile) : CC(cc) , Config(std::move(config)) , LG(lg) @@ -75,6 +80,36 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, this->CommandLines.push_back(std::move(argv)); } + if (transformDepfile && !this->CommandLines.empty() && + !cc.GetDepfile().empty() && + this->LG->GetGlobalGenerator()->DepfileFormat()) { + cmCustomCommandLine argv; + argv.push_back(cmSystemTools::GetCMakeCommand()); + argv.emplace_back("-E"); + argv.emplace_back("cmake_transform_depfile"); + switch (*this->LG->GetGlobalGenerator()->DepfileFormat()) { + case cmDepfileFormat::GccDepfile: + argv.emplace_back("gccdepfile"); + break; + case cmDepfileFormat::VsTlog: + argv.emplace_back("vstlog"); + break; + } + if (this->LG->GetCurrentBinaryDirectory() == + this->LG->GetBinaryDirectory()) { + argv.emplace_back("./"); + } else { + argv.push_back(cmStrCat(this->LG->MaybeConvertToRelativePath( + this->LG->GetBinaryDirectory(), + this->LG->GetCurrentBinaryDirectory()), + '/')); + } + argv.push_back(this->GetFullDepfile()); + argv.push_back(this->GetInternalDepfile()); + + this->CommandLines.push_back(std::move(argv)); + } + AppendPaths(cc.GetByproducts(), ge, this->LG, this->Config, this->Byproducts); AppendPaths(cc.GetDepends(), ge, this->LG, this->Config, this->Depends); @@ -97,7 +132,7 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, unsigned int cmCustomCommandGenerator::GetNumberOfCommands() const { - return static_cast(this->CC.GetCommandLines().size()); + return static_cast(this->CommandLines.size()); } void cmCustomCommandGenerator::FillEmulatorsWithArguments() @@ -234,6 +269,40 @@ void cmCustomCommandGenerator::AppendArguments(unsigned int c, } } +std::string cmCustomCommandGenerator::GetFullDepfile() const +{ + std::string depfile = this->CC.GetDepfile(); + if (depfile.empty()) { + return ""; + } + + if (!cmSystemTools::FileIsFullPath(depfile)) { + depfile = cmStrCat(this->LG->GetCurrentBinaryDirectory(), '/', depfile); + } + return cmSystemTools::CollapseFullPath(depfile); +} + +std::string cmCustomCommandGenerator::GetInternalDepfile() const +{ + std::string depfile = this->GetFullDepfile(); + if (depfile.empty()) { + return ""; + } + + cmCryptoHash hash(cmCryptoHash::AlgoSHA256); + std::string extension; + switch (*this->LG->GetGlobalGenerator()->DepfileFormat()) { + case cmDepfileFormat::GccDepfile: + extension = ".d"; + break; + case cmDepfileFormat::VsTlog: + extension = ".tlog"; + break; + } + return cmStrCat(this->LG->GetBinaryDirectory(), "/CMakeFiles/d/", + hash.HashString(depfile), extension); +} + const char* cmCustomCommandGenerator::GetComment() const { return this->CC.GetComment(); diff --git a/Source/cmCustomCommandGenerator.h b/Source/cmCustomCommandGenerator.h index 412eba8..8b5259d 100644 --- a/Source/cmCustomCommandGenerator.h +++ b/Source/cmCustomCommandGenerator.h @@ -31,7 +31,7 @@ class cmCustomCommandGenerator public: cmCustomCommandGenerator(cmCustomCommand const& cc, std::string config, - cmLocalGenerator* lg); + cmLocalGenerator* lg, bool transformDepfile = true); cmCustomCommandGenerator(const cmCustomCommandGenerator&) = delete; cmCustomCommandGenerator& operator=(const cmCustomCommandGenerator&) = delete; @@ -45,4 +45,6 @@ public: std::vector const& GetByproducts() const; std::vector const& GetDepends() const; bool HasOnlyEmptyCommandLines() const; + std::string GetFullDepfile() const; + std::string GetInternalDepfile() const; }; diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index b532a43..de5eba7 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -14,6 +14,7 @@ #include #include +#include #include #include "cm_codecvt.hxx" @@ -26,6 +27,7 @@ #include "cmSystemTools.h" #include "cmTarget.h" #include "cmTargetDepend.h" +#include "cmTransformDepfile.h" #if !defined(CMAKE_BOOTSTRAP) # include @@ -452,6 +454,10 @@ public: virtual bool ShouldStripResourcePath(cmMakefile*) const; virtual bool SupportsCustomCommandDepfile() const { return false; } + virtual cm::optional DepfileFormat() const + { + return cm::nullopt; + } std::string GetSharedLibFlagsForLanguage(std::string const& lang) const; diff --git a/bootstrap b/bootstrap index 9126ae6..b36c162 100755 --- a/bootstrap +++ b/bootstrap @@ -307,6 +307,7 @@ CMAKE_CXX_SOURCES="\ cmContinueCommand \ cmCoreTryCompile \ cmCreateTestSourceList \ + cmCryptoHash \ cmCustomCommand \ cmCustomCommandGenerator \ cmCustomCommandLines \ @@ -539,6 +540,18 @@ KWSYS_FILES="\ SystemTools.hxx \ Terminal.h" +LIBRHASH_C_SOURCES="\ + librhash/algorithms.c \ + librhash/byte_order.c \ + librhash/hex.c \ + librhash/md5.c \ + librhash/rhash.c \ + librhash/sha1.c \ + librhash/sha256.c \ + librhash/sha3.c \ + librhash/sha512.c \ + " + if ${cmake_system_mingw}; then LIBUV_C_SOURCES="\ src/fs-poll.c \ @@ -1016,7 +1029,6 @@ cmake_ld_flags=${LDFLAGS} # Add generator-specific files if test "${cmake_bootstrap_generator}" = "Ninja"; then CMAKE_CXX_SOURCES="${CMAKE_CXX_SOURCES} \ - cmCryptoHash \ cmFortranParserImpl \ cmGlobalNinjaGenerator \ cmLocalNinjaGenerator \ @@ -1037,18 +1049,6 @@ if test "${cmake_bootstrap_generator}" = "Ninja"; then src/lib_json/json_value.cpp \ src/lib_json/json_writer.cpp \ " - - LIBRHASH_C_SOURCES="\ - librhash/algorithms.c \ - librhash/byte_order.c \ - librhash/hex.c \ - librhash/md5.c \ - librhash/rhash.c \ - librhash/sha1.c \ - librhash/sha256.c \ - librhash/sha3.c \ - librhash/sha512.c \ - " else CMAKE_CXX_SOURCES="${CMAKE_CXX_SOURCES} \ cmDepends \ @@ -1062,7 +1062,6 @@ else " JSONCPP_CXX_SOURCES= - LIBRHASH_C_SOURCES= fi # Add Cygwin-specific flags @@ -1632,17 +1631,17 @@ if test "x${bootstrap_system_libuv}" = "x"; then objs="${objs} uv-`cmake_obj ${a}`" done fi +if test "x${bootstrap_system_librhash}" = "x"; then + for a in ${LIBRHASH_C_SOURCES}; do + objs="${objs} rhash-`cmake_obj ${a}`" + done +fi if test "${cmake_bootstrap_generator}" = "Ninja"; then if test "x${bootstrap_system_jsoncpp}" = "x"; then for a in ${JSONCPP_CXX_SOURCES}; do objs="${objs} jsoncpp-`cmake_obj ${a}`" done fi - if test "x${bootstrap_system_librhash}" = "x"; then - for a in ${LIBRHASH_C_SOURCES}; do - objs="${objs} rhash-`cmake_obj ${a}`" - done - fi fi libs="" @@ -1702,6 +1701,15 @@ else libs="${libs} -luv" fi +if test "x${bootstrap_system_librhash}" != "x"; then + if test `which pkg-config`; then + use_librhash_flags="`pkg-config --cflags librhash`" + cmake_c_flags="${cmake_c_flags} ${use_librhash_flags}" + cmake_cxx_flags="${cmake_cxx_flags} ${use_librhash_flags}" + fi + libs="${libs} -lrhash" +fi + if test "${cmake_bootstrap_generator}" = "Ninja"; then jsoncpp_cxx_flags= if test "x${bootstrap_system_jsoncpp}" = "x"; then @@ -1713,15 +1721,6 @@ if test "${cmake_bootstrap_generator}" = "Ninja"; then fi libs="${libs} -ljsoncpp" fi - - if test "x${bootstrap_system_librhash}" != "x"; then - if test `which pkg-config`; then - use_librhash_flags="`pkg-config --cflags librhash`" - cmake_c_flags="${cmake_c_flags} ${use_librhash_flags}" - cmake_cxx_flags="${cmake_cxx_flags} ${use_librhash_flags}" - fi - libs="${libs} -lrhash" - fi fi if test "x${cmake_ansi_cxx_flags}" != "x"; then @@ -1845,6 +1844,12 @@ if test "x${bootstrap_system_libuv}" = "x"; then write_source_rule "c" "uv-`cmake_obj ${a}`" "${src}" "${uv_c_flags}" done fi +if test "x${bootstrap_system_librhash}" = "x"; then + for a in ${LIBRHASH_C_SOURCES}; do + src=`cmake_escape_artifact "${cmake_source_dir}/Utilities/cmlibrhash/${a}"` + write_source_rule "c" "rhash-`cmake_obj ${a}`" "${src}" "" + done +fi if test "${cmake_bootstrap_generator}" = "Ninja"; then if test "x${bootstrap_system_jsoncpp}" = "x"; then for a in ${JSONCPP_CXX_SOURCES}; do @@ -1852,12 +1857,6 @@ if test "${cmake_bootstrap_generator}" = "Ninja"; then write_source_rule "cxx" "jsoncpp-`cmake_obj ${a}`" "${src}" "${jsoncpp_cxx_flags}" done fi - if test "x${bootstrap_system_librhash}" = "x"; then - for a in ${LIBRHASH_C_SOURCES}; do - src=`cmake_escape_artifact "${cmake_source_dir}/Utilities/cmlibrhash/${a}"` - write_source_rule "c" "rhash-`cmake_obj ${a}`" "${src}" "" - done - fi fi if test "${cmake_bootstrap_generator}" = "Ninja"; then echo " -- cgit v0.12