cmCustomCommandGenerator: Add option to transform depfile

This commit is contained in:
Kyle Edwards 2020-10-05 12:15:17 -04:00
parent b2c14bc774
commit 596439b1bb
4 changed files with 113 additions and 37 deletions

View File

@ -6,18 +6,22 @@
#include <memory>
#include <utility>
#include <cm/optional>
#include <cmext/algorithm>
#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<std::string>& inputs,
@ -42,7 +46,8 @@ void AppendPaths(const std::vector<std::string>& 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<unsigned int>(this->CC.GetCommandLines().size());
return static_cast<unsigned int>(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();

View File

@ -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<std::string> const& GetByproducts() const;
std::vector<std::string> const& GetDepends() const;
bool HasOnlyEmptyCommandLines() const;
std::string GetFullDepfile() const;
std::string GetInternalDepfile() const;
};

View File

@ -14,6 +14,7 @@
#include <utility>
#include <vector>
#include <cm/optional>
#include <cmext/algorithm>
#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 <cm3p/json/value.h>
@ -452,6 +454,10 @@ public:
virtual bool ShouldStripResourcePath(cmMakefile*) const;
virtual bool SupportsCustomCommandDepfile() const { return false; }
virtual cm::optional<cmDepfileFormat> DepfileFormat() const
{
return cm::nullopt;
}
std::string GetSharedLibFlagsForLanguage(std::string const& lang) const;

View File

@ -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 "