2017-11-16 08:59:03 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2019-04-06 10:42:56 +00:00
|
|
|
#include "cmQtAutoRcc.h"
|
2019-05-11 19:39:41 +00:00
|
|
|
|
2017-11-16 08:59:03 +00:00
|
|
|
#include "cmAlgorithms.h"
|
|
|
|
#include "cmCryptoHash.h"
|
2019-04-05 19:54:53 +00:00
|
|
|
#include "cmDuration.h"
|
2018-05-30 14:34:09 +00:00
|
|
|
#include "cmFileLockResult.h"
|
2019-04-05 19:54:53 +00:00
|
|
|
#include "cmProcessOutput.h"
|
2019-08-26 15:16:54 +00:00
|
|
|
#include "cmQtAutoGen.h"
|
2019-07-29 10:16:40 +00:00
|
|
|
#include "cmStringAlgorithms.h"
|
2017-11-16 08:59:03 +00:00
|
|
|
#include "cmSystemTools.h"
|
2019-08-04 08:49:16 +00:00
|
|
|
|
|
|
|
#include <cm/string_view>
|
2017-11-16 08:59:03 +00:00
|
|
|
|
2019-08-26 15:25:44 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2019-09-20 20:39:13 +00:00
|
|
|
cmQtAutoRcc::cmQtAutoRcc()
|
|
|
|
: cmQtAutoGenerator(GenT::RCC)
|
|
|
|
{
|
|
|
|
}
|
2019-04-06 10:42:56 +00:00
|
|
|
cmQtAutoRcc::~cmQtAutoRcc() = default;
|
2018-01-03 15:59:40 +00:00
|
|
|
|
2019-09-20 20:39:13 +00:00
|
|
|
bool cmQtAutoRcc::InitFromInfo()
|
2017-11-16 08:59:03 +00:00
|
|
|
{
|
2019-09-20 20:39:13 +00:00
|
|
|
// -- Required settings
|
|
|
|
if (!InfoBool("MULTI_CONFIG", MultiConfig_, true) ||
|
|
|
|
!InfoString("BUILD_DIR", AutogenBuildDir_, true) ||
|
|
|
|
!InfoStringConfig("INCLUDE_DIR", IncludeDir_, true) ||
|
|
|
|
!InfoString("RCC_EXECUTABLE", RccExecutable_, true) ||
|
|
|
|
!InfoArray("RCC_LIST_OPTIONS", RccListOptions_, false) ||
|
|
|
|
!InfoString("LOCK_FILE", LockFile_, true) ||
|
|
|
|
!InfoStringConfig("SETTINGS_FILE", SettingsFile_, true) ||
|
|
|
|
!InfoString("SOURCE", QrcFile_, true) ||
|
|
|
|
!InfoString("OUTPUT_CHECKSUM", RccPathChecksum_, true) ||
|
|
|
|
!InfoString("OUTPUT_NAME", RccFileName_, true) ||
|
|
|
|
!InfoArray("OPTIONS", Options_, false) ||
|
|
|
|
!InfoArray("INPUTS", Inputs_, false)) {
|
2019-05-11 19:39:41 +00:00
|
|
|
return false;
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
|
|
|
|
2019-09-20 20:39:13 +00:00
|
|
|
// -- Derive information
|
2018-01-03 15:59:40 +00:00
|
|
|
QrcFileName_ = cmSystemTools::GetFilenameName(QrcFile_);
|
|
|
|
QrcFileDir_ = cmSystemTools::GetFilenamePath(QrcFile_);
|
2019-08-22 14:34:40 +00:00
|
|
|
RccFilePublic_ =
|
|
|
|
cmStrCat(AutogenBuildDir_, '/', RccPathChecksum_, '/', RccFileName_);
|
2018-01-31 12:54:37 +00:00
|
|
|
|
2019-09-20 20:39:13 +00:00
|
|
|
// rcc output file name
|
2018-01-31 12:54:37 +00:00
|
|
|
if (IsMultiConfig()) {
|
2019-08-22 14:34:40 +00:00
|
|
|
RccFileOutput_ = cmStrCat(IncludeDir_, '/', MultiConfigOutput());
|
2018-01-31 12:54:37 +00:00
|
|
|
} else {
|
|
|
|
RccFileOutput_ = RccFilePublic_;
|
2018-01-03 15:59:40 +00:00
|
|
|
}
|
|
|
|
|
2019-09-20 20:39:13 +00:00
|
|
|
// -- Checks
|
|
|
|
if (!RccExecutableTime_.Load(RccExecutable_)) {
|
|
|
|
return LogInfoError(cmStrCat(
|
|
|
|
"The rcc executable ", MessagePath(RccExecutable_), " does not exist."));
|
|
|
|
}
|
|
|
|
|
2018-01-03 15:59:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-11-16 08:59:03 +00:00
|
|
|
|
2019-04-06 10:42:56 +00:00
|
|
|
bool cmQtAutoRcc::Process()
|
2018-01-03 15:59:40 +00:00
|
|
|
{
|
2019-04-05 19:54:53 +00:00
|
|
|
if (!SettingsFileRead()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test if the rcc output needs to be regenerated
|
|
|
|
bool generate = false;
|
|
|
|
if (!TestQrcRccFiles(generate)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!generate && !TestResources(generate)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Generate on demand
|
|
|
|
if (generate) {
|
|
|
|
if (!GenerateRcc()) {
|
2018-01-03 15:59:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
2019-04-05 19:54:53 +00:00
|
|
|
// Test if the info file is newer than the output file
|
|
|
|
if (!TestInfoFile()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-03 15:59:40 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 19:54:53 +00:00
|
|
|
if (!GenerateWrapper()) {
|
|
|
|
return false;
|
2018-01-03 15:59:40 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 19:54:53 +00:00
|
|
|
return SettingsFileWrite();
|
2018-01-03 15:59:40 +00:00
|
|
|
}
|
|
|
|
|
2019-04-06 10:42:56 +00:00
|
|
|
std::string cmQtAutoRcc::MultiConfigOutput() const
|
2018-01-31 12:54:37 +00:00
|
|
|
{
|
2019-08-26 15:16:54 +00:00
|
|
|
return cmStrCat(RccPathChecksum_, '/',
|
|
|
|
AppendFilenameSuffix(RccFileName_, "_CMAKE_"));
|
2018-01-31 12:54:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-06 10:42:56 +00:00
|
|
|
bool cmQtAutoRcc::SettingsFileRead()
|
2017-11-16 08:59:03 +00:00
|
|
|
{
|
|
|
|
// Compose current settings strings
|
|
|
|
{
|
2019-08-26 15:25:44 +00:00
|
|
|
cmCryptoHash cryptoHash(cmCryptoHash::AlgoSHA256);
|
|
|
|
auto cha = [&cryptoHash](cm::string_view value) {
|
|
|
|
cryptoHash.Append(value);
|
|
|
|
cryptoHash.Append(";");
|
|
|
|
};
|
|
|
|
cha(RccExecutable_);
|
|
|
|
std::for_each(RccListOptions_.begin(), RccListOptions_.end(), cha);
|
|
|
|
cha(QrcFile_);
|
|
|
|
cha(RccPathChecksum_);
|
|
|
|
cha(RccFileName_);
|
|
|
|
std::for_each(Options_.begin(), Options_.end(), cha);
|
|
|
|
std::for_each(Inputs_.begin(), Inputs_.end(), cha);
|
|
|
|
SettingsString_ = cryptoHash.FinalizeHex();
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
|
|
|
|
2018-05-30 14:34:09 +00:00
|
|
|
// Make sure the settings file exists
|
2019-04-05 21:43:19 +00:00
|
|
|
if (!cmSystemTools::FileExists(SettingsFile_, true)) {
|
2018-05-30 14:34:09 +00:00
|
|
|
// Touch the settings file to make sure it exists
|
2019-04-05 21:43:19 +00:00
|
|
|
if (!cmSystemTools::Touch(SettingsFile_, true)) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Log().Error(GenT::RCC,
|
|
|
|
cmStrCat("Touching the settings file ",
|
|
|
|
MessagePath(SettingsFile_), " failed."));
|
2019-04-05 21:43:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-05-30 14:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Lock the lock file
|
|
|
|
{
|
|
|
|
// Make sure the lock file exists
|
2019-04-05 21:43:19 +00:00
|
|
|
if (!cmSystemTools::FileExists(LockFile_, true)) {
|
|
|
|
if (!cmSystemTools::Touch(LockFile_, true)) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Log().Error(GenT::RCC,
|
|
|
|
cmStrCat("Touching the lock file ", MessagePath(LockFile_),
|
|
|
|
" failed."));
|
2018-05-30 14:34:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Lock the lock file
|
|
|
|
cmFileLockResult lockResult =
|
|
|
|
LockFileLock_.Lock(LockFile_, static_cast<unsigned long>(-1));
|
|
|
|
if (!lockResult.IsOk()) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Log().Error(GenT::RCC,
|
|
|
|
cmStrCat("Locking of the lock file ", MessagePath(LockFile_),
|
|
|
|
" failed.\n", lockResult.GetOutputMessage()));
|
2018-05-30 14:34:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-16 08:59:03 +00:00
|
|
|
// Read old settings
|
2018-01-03 15:59:40 +00:00
|
|
|
{
|
|
|
|
std::string content;
|
2019-04-05 21:43:19 +00:00
|
|
|
if (FileRead(content, SettingsFile_)) {
|
2018-01-03 15:59:40 +00:00
|
|
|
SettingsChanged_ = (SettingsString_ != SettingsFind(content, "rcc"));
|
2018-05-30 14:34:09 +00:00
|
|
|
// In case any setting changed clear the old settings file.
|
2018-01-03 15:59:40 +00:00
|
|
|
// This triggers a full rebuild on the next run if the current
|
|
|
|
// build is aborted before writing the current settings in the end.
|
|
|
|
if (SettingsChanged_) {
|
2019-04-05 21:43:19 +00:00
|
|
|
std::string error;
|
|
|
|
if (!FileWrite(SettingsFile_, "", &error)) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Log().Error(GenT::RCC,
|
|
|
|
cmStrCat("Clearing of the settings file ",
|
|
|
|
MessagePath(SettingsFile_), " failed.\n",
|
|
|
|
error));
|
2019-04-05 21:43:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
2018-01-03 15:59:40 +00:00
|
|
|
} else {
|
|
|
|
SettingsChanged_ = true;
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-30 14:34:09 +00:00
|
|
|
|
|
|
|
return true;
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
|
|
|
|
2019-04-06 10:42:56 +00:00
|
|
|
bool cmQtAutoRcc::SettingsFileWrite()
|
2017-11-16 08:59:03 +00:00
|
|
|
{
|
|
|
|
// Only write if any setting changed
|
2018-01-03 15:59:40 +00:00
|
|
|
if (SettingsChanged_) {
|
|
|
|
if (Log().Verbose()) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Log().Info(GenT::RCC,
|
|
|
|
"Writing settings file " + MessagePath(SettingsFile_));
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
|
|
|
// Write settings file
|
2019-08-06 08:40:49 +00:00
|
|
|
std::string content = cmStrCat("rcc:", SettingsString_, '\n');
|
2019-04-05 21:43:19 +00:00
|
|
|
std::string error;
|
|
|
|
if (!FileWrite(SettingsFile_, content, &error)) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Log().Error(GenT::RCC,
|
|
|
|
cmStrCat("Writing of the settings file ",
|
|
|
|
MessagePath(SettingsFile_), " failed.\n", error));
|
2017-11-16 08:59:03 +00:00
|
|
|
// Remove old settings file to trigger a full rebuild on the next run
|
2019-04-05 21:43:19 +00:00
|
|
|
cmSystemTools::RemoveFile(SettingsFile_);
|
2019-04-05 19:54:53 +00:00
|
|
|
return false;
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-30 14:34:09 +00:00
|
|
|
|
|
|
|
// Unlock the lock file
|
|
|
|
LockFileLock_.Release();
|
2019-04-05 19:54:53 +00:00
|
|
|
return true;
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 19:54:53 +00:00
|
|
|
/// Do basic checks if rcc generation is required
|
2019-04-06 10:42:56 +00:00
|
|
|
bool cmQtAutoRcc::TestQrcRccFiles(bool& generate)
|
2017-11-16 08:59:03 +00:00
|
|
|
{
|
2019-04-05 19:54:53 +00:00
|
|
|
// Test if the rcc input file exists
|
|
|
|
if (!QrcFileTime_.Load(QrcFile_)) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Log().Error(GenT::RCC,
|
|
|
|
cmStrCat("The resources file ", MessagePath(QrcFile_),
|
|
|
|
" does not exist"));
|
2019-04-05 19:54:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-01-03 15:59:40 +00:00
|
|
|
|
|
|
|
// Test if the rcc output file exists
|
2019-04-05 19:54:53 +00:00
|
|
|
if (!RccFileTime_.Load(RccFileOutput_)) {
|
2018-01-03 15:59:40 +00:00
|
|
|
if (Log().Verbose()) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Reason =
|
|
|
|
cmStrCat("Generating ", MessagePath(RccFileOutput_),
|
|
|
|
", because it doesn't exist, from ", MessagePath(QrcFile_));
|
2018-01-03 15:59:40 +00:00
|
|
|
}
|
2019-04-05 19:54:53 +00:00
|
|
|
generate = true;
|
|
|
|
return true;
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
2018-01-03 15:59:40 +00:00
|
|
|
|
|
|
|
// Test if the settings changed
|
|
|
|
if (SettingsChanged_) {
|
|
|
|
if (Log().Verbose()) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Reason = cmStrCat("Generating ", MessagePath(RccFileOutput_),
|
2019-08-22 14:34:40 +00:00
|
|
|
", because the rcc settings changed, from ",
|
2019-09-09 15:04:51 +00:00
|
|
|
MessagePath(QrcFile_));
|
2018-01-03 15:59:40 +00:00
|
|
|
}
|
2019-04-05 19:54:53 +00:00
|
|
|
generate = true;
|
|
|
|
return true;
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
2018-01-03 15:59:40 +00:00
|
|
|
|
|
|
|
// Test if the rcc output file is older than the .qrc file
|
2019-04-05 19:54:53 +00:00
|
|
|
if (RccFileTime_.Older(QrcFileTime_)) {
|
|
|
|
if (Log().Verbose()) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Reason = cmStrCat("Generating ", MessagePath(RccFileOutput_),
|
|
|
|
", because it is older than ", MessagePath(QrcFile_),
|
|
|
|
", from ", MessagePath(QrcFile_));
|
2018-01-03 15:59:40 +00:00
|
|
|
}
|
2019-04-05 19:54:53 +00:00
|
|
|
generate = true;
|
2018-01-03 15:59:40 +00:00
|
|
|
return true;
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
|
|
|
|
2019-05-11 19:30:20 +00:00
|
|
|
// Test if the rcc output file is older than the rcc executable
|
|
|
|
if (RccFileTime_.Older(RccExecutableTime_)) {
|
|
|
|
if (Log().Verbose()) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Reason = cmStrCat("Generating ", MessagePath(RccFileOutput_),
|
2019-08-22 14:34:40 +00:00
|
|
|
", because it is older than the rcc executable, from ",
|
2019-09-09 15:04:51 +00:00
|
|
|
MessagePath(QrcFile_));
|
2019-05-11 19:30:20 +00:00
|
|
|
}
|
|
|
|
generate = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-03 15:59:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-06 10:42:56 +00:00
|
|
|
bool cmQtAutoRcc::TestResources(bool& generate)
|
2018-01-03 15:59:40 +00:00
|
|
|
{
|
2019-04-05 19:54:53 +00:00
|
|
|
// Read resource files list
|
2018-01-03 15:59:40 +00:00
|
|
|
if (Inputs_.empty()) {
|
2017-11-16 08:59:03 +00:00
|
|
|
std::string error;
|
2019-04-05 19:54:53 +00:00
|
|
|
RccLister const lister(RccExecutable_, RccListOptions_);
|
|
|
|
if (!lister.list(QrcFile_, Inputs_, error, Log().Verbose())) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Log().Error(
|
|
|
|
GenT::RCC,
|
|
|
|
cmStrCat("Listing of ", MessagePath(QrcFile_), " failed.\n", error));
|
2019-04-05 19:54:53 +00:00
|
|
|
return false;
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-03 15:59:40 +00:00
|
|
|
|
2019-05-11 19:23:29 +00:00
|
|
|
// Check if any resource file is newer than the rcc output file
|
2019-04-05 19:54:53 +00:00
|
|
|
for (std::string const& resFile : Inputs_) {
|
|
|
|
// Check if the resource file exists
|
|
|
|
cmFileTime fileTime;
|
|
|
|
if (!fileTime.Load(resFile)) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Log().Error(GenT::RCC,
|
|
|
|
cmStrCat("The resource file ", MessagePath(resFile),
|
|
|
|
" listed in ", MessagePath(QrcFile_),
|
|
|
|
" does not exist."));
|
2019-04-05 19:54:53 +00:00
|
|
|
return false;
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
2019-05-11 19:23:29 +00:00
|
|
|
// Check if the resource file is newer than the rcc output file
|
2019-04-05 19:54:53 +00:00
|
|
|
if (RccFileTime_.Older(fileTime)) {
|
2018-01-03 15:59:40 +00:00
|
|
|
if (Log().Verbose()) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Reason = cmStrCat("Generating ", MessagePath(RccFileOutput_),
|
|
|
|
", because it is older than ", MessagePath(resFile),
|
|
|
|
", from ", MessagePath(QrcFile_));
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
2019-04-05 19:54:53 +00:00
|
|
|
generate = true;
|
|
|
|
break;
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-05 19:54:53 +00:00
|
|
|
return true;
|
2018-01-03 15:59:40 +00:00
|
|
|
}
|
2017-11-16 08:59:03 +00:00
|
|
|
|
2019-04-06 10:42:56 +00:00
|
|
|
bool cmQtAutoRcc::TestInfoFile()
|
2018-01-03 15:59:40 +00:00
|
|
|
{
|
2019-04-05 19:54:53 +00:00
|
|
|
// Test if the rcc output file is older than the info file
|
2019-05-11 20:13:39 +00:00
|
|
|
if (RccFileTime_.Older(InfoFileTime())) {
|
2019-04-05 19:54:53 +00:00
|
|
|
if (Log().Verbose()) {
|
2019-08-26 15:16:54 +00:00
|
|
|
Log().Info(GenT::RCC,
|
2019-09-09 15:04:51 +00:00
|
|
|
cmStrCat("Touching ", MessagePath(RccFileOutput_),
|
|
|
|
" because it is older than ",
|
|
|
|
MessagePath(InfoFile())));
|
2019-04-05 19:54:53 +00:00
|
|
|
}
|
|
|
|
// Touch build file
|
2019-04-05 21:43:19 +00:00
|
|
|
if (!cmSystemTools::Touch(RccFileOutput_, false)) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Log().Error(
|
|
|
|
GenT::RCC,
|
|
|
|
cmStrCat("Touching ", MessagePath(RccFileOutput_), " failed."));
|
2019-04-05 21:43:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-04-05 19:54:53 +00:00
|
|
|
BuildFileChanged_ = true;
|
2018-01-03 15:59:40 +00:00
|
|
|
}
|
2019-04-05 19:54:53 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-06 10:42:56 +00:00
|
|
|
bool cmQtAutoRcc::GenerateRcc()
|
2018-01-03 15:59:40 +00:00
|
|
|
{
|
2019-04-05 21:43:19 +00:00
|
|
|
// Make parent directory
|
|
|
|
if (!MakeParentDirectory(RccFileOutput_)) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Log().Error(GenT::RCC,
|
|
|
|
cmStrCat("Could not create parent directory of ",
|
|
|
|
MessagePath(RccFileOutput_)));
|
2019-04-05 21:43:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-11 19:23:29 +00:00
|
|
|
// Compose rcc command
|
2019-04-05 19:54:53 +00:00
|
|
|
std::vector<std::string> cmd;
|
|
|
|
cmd.push_back(RccExecutable_);
|
2019-05-23 12:49:54 +00:00
|
|
|
cmAppend(cmd, Options_);
|
2019-04-05 19:54:53 +00:00
|
|
|
cmd.emplace_back("-o");
|
|
|
|
cmd.push_back(RccFileOutput_);
|
|
|
|
cmd.push_back(QrcFile_);
|
|
|
|
|
2019-05-11 19:23:29 +00:00
|
|
|
// Log reason and command
|
2019-04-05 19:54:53 +00:00
|
|
|
if (Log().Verbose()) {
|
2019-08-26 15:16:54 +00:00
|
|
|
Log().Info(GenT::RCC,
|
|
|
|
cmStrCat(Reason, cmHasSuffix(Reason, '\n') ? "" : "\n",
|
|
|
|
QuotedCommand(cmd), '\n'));
|
2018-01-03 15:59:40 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 19:54:53 +00:00
|
|
|
std::string rccStdOut;
|
|
|
|
std::string rccStdErr;
|
|
|
|
int retVal = 0;
|
|
|
|
bool result = cmSystemTools::RunSingleCommand(
|
|
|
|
cmd, &rccStdOut, &rccStdErr, &retVal, AutogenBuildDir_.c_str(),
|
|
|
|
cmSystemTools::OUTPUT_NONE, cmDuration::zero(), cmProcessOutput::Auto);
|
|
|
|
if (!result || (retVal != 0)) {
|
|
|
|
// rcc process failed
|
2019-08-26 15:16:54 +00:00
|
|
|
Log().ErrorCommand(GenT::RCC,
|
|
|
|
cmStrCat("The rcc process failed to compile\n ",
|
2019-09-09 15:04:51 +00:00
|
|
|
MessagePath(QrcFile_), "\ninto\n ",
|
|
|
|
MessagePath(RccFileOutput_)),
|
2019-08-26 15:16:54 +00:00
|
|
|
cmd, rccStdOut + rccStdErr);
|
2019-04-05 21:43:19 +00:00
|
|
|
cmSystemTools::RemoveFile(RccFileOutput_);
|
2019-04-05 19:54:53 +00:00
|
|
|
return false;
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 19:54:53 +00:00
|
|
|
// rcc process success
|
|
|
|
// Print rcc output
|
|
|
|
if (!rccStdOut.empty()) {
|
|
|
|
Log().Info(GenT::RCC, rccStdOut);
|
|
|
|
}
|
|
|
|
BuildFileChanged_ = true;
|
|
|
|
|
2018-01-03 15:59:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-06 10:42:56 +00:00
|
|
|
bool cmQtAutoRcc::GenerateWrapper()
|
2018-01-03 15:59:40 +00:00
|
|
|
{
|
2017-11-16 08:59:03 +00:00
|
|
|
// Generate a wrapper source file on demand
|
2018-01-31 12:54:37 +00:00
|
|
|
if (IsMultiConfig()) {
|
2017-11-16 08:59:03 +00:00
|
|
|
// Wrapper file content
|
2019-08-06 08:40:49 +00:00
|
|
|
std::string content =
|
|
|
|
cmStrCat("// This is an autogenerated configuration wrapper file.\n",
|
|
|
|
"// Changes will be overwritten.\n", "#include <",
|
|
|
|
MultiConfigOutput(), ">\n");
|
2018-01-31 12:54:37 +00:00
|
|
|
|
2019-04-05 21:43:19 +00:00
|
|
|
// Compare with existing file content
|
|
|
|
bool fileDiffers = true;
|
|
|
|
{
|
|
|
|
std::string oldContents;
|
|
|
|
if (FileRead(oldContents, RccFilePublic_)) {
|
|
|
|
fileDiffers = (oldContents != content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fileDiffers) {
|
2017-11-16 08:59:03 +00:00
|
|
|
// Write new wrapper file
|
2018-01-03 15:59:40 +00:00
|
|
|
if (Log().Verbose()) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Log().Info(GenT::RCC,
|
|
|
|
cmStrCat("Generating RCC wrapper file ",
|
|
|
|
MessagePath(RccFilePublic_)));
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
2019-04-05 21:43:19 +00:00
|
|
|
std::string error;
|
|
|
|
if (!FileWrite(RccFilePublic_, content, &error)) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Log().Error(GenT::RCC,
|
|
|
|
cmStrCat("Generating RCC wrapper file ",
|
|
|
|
MessagePath(RccFilePublic_), " failed.\n",
|
|
|
|
error));
|
2019-04-05 19:54:53 +00:00
|
|
|
return false;
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
2018-01-03 15:59:40 +00:00
|
|
|
} else if (BuildFileChanged_) {
|
2017-11-16 08:59:03 +00:00
|
|
|
// Just touch the wrapper file
|
2018-01-03 15:59:40 +00:00
|
|
|
if (Log().Verbose()) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Log().Info(
|
|
|
|
GenT::RCC,
|
|
|
|
cmStrCat("Touching RCC wrapper file ", MessagePath(RccFilePublic_)));
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
2019-04-05 21:43:19 +00:00
|
|
|
if (!cmSystemTools::Touch(RccFilePublic_, false)) {
|
2019-09-09 15:04:51 +00:00
|
|
|
Log().Error(GenT::RCC,
|
|
|
|
cmStrCat("Touching RCC wrapper file ",
|
|
|
|
MessagePath(RccFilePublic_), " failed."));
|
2019-04-05 21:43:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-03 15:59:40 +00:00
|
|
|
return true;
|
2017-11-16 08:59:03 +00:00
|
|
|
}
|