2017-11-16 09:59:03 +01: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 12:42:56 +02:00
|
|
|
#include "cmQtAutoRcc.h"
|
2019-05-11 21:39:41 +02:00
|
|
|
|
2017-11-16 09:59:03 +01:00
|
|
|
#include "cmAlgorithms.h"
|
|
|
|
#include "cmCryptoHash.h"
|
2019-04-05 21:54:53 +02:00
|
|
|
#include "cmDuration.h"
|
2018-05-30 16:34:09 +02:00
|
|
|
#include "cmFileLockResult.h"
|
2017-11-16 09:59:03 +01:00
|
|
|
#include "cmMakefile.h"
|
2019-04-05 21:54:53 +02:00
|
|
|
#include "cmProcessOutput.h"
|
2019-08-26 17:16:54 +02:00
|
|
|
#include "cmQtAutoGen.h"
|
2019-07-29 12:16:40 +02:00
|
|
|
#include "cmStringAlgorithms.h"
|
2017-11-16 09:59:03 +01:00
|
|
|
#include "cmSystemTools.h"
|
2019-08-26 17:16:54 +02:00
|
|
|
#include "cm_string_view.hxx"
|
2017-11-16 09:59:03 +01:00
|
|
|
|
2019-04-06 12:42:56 +02:00
|
|
|
cmQtAutoRcc::cmQtAutoRcc() = default;
|
2017-11-16 09:59:03 +01:00
|
|
|
|
2019-04-06 12:42:56 +02:00
|
|
|
cmQtAutoRcc::~cmQtAutoRcc() = default;
|
2018-01-03 16:59:40 +01:00
|
|
|
|
2019-04-06 12:42:56 +02:00
|
|
|
bool cmQtAutoRcc::Init(cmMakefile* makefile)
|
2017-11-16 09:59:03 +01:00
|
|
|
{
|
2018-01-31 13:54:37 +01:00
|
|
|
// -- Utility lambdas
|
2019-08-26 17:16:54 +02:00
|
|
|
auto InfoGet = [makefile](cm::string_view key) {
|
|
|
|
return makefile->GetSafeDefinition(std::string(key));
|
2017-11-16 09:59:03 +01:00
|
|
|
};
|
2018-01-31 13:54:37 +01:00
|
|
|
auto InfoGetList =
|
2019-08-26 17:16:54 +02:00
|
|
|
[makefile](cm::string_view key) -> std::vector<std::string> {
|
|
|
|
return cmExpandedList(makefile->GetSafeDefinition(std::string(key)));
|
2017-11-16 09:59:03 +01:00
|
|
|
};
|
2019-08-26 17:16:54 +02:00
|
|
|
auto InfoGetConfig = [makefile, this](cm::string_view key) -> std::string {
|
|
|
|
if (const char* valueConf =
|
|
|
|
makefile->GetDefinition(cmStrCat(key, '_', InfoConfig()))) {
|
|
|
|
return std::string(valueConf);
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
2019-08-26 17:16:54 +02:00
|
|
|
return makefile->GetSafeDefinition(std::string(key));
|
2017-11-16 09:59:03 +01:00
|
|
|
};
|
|
|
|
auto InfoGetConfigList =
|
2019-08-26 17:16:54 +02:00
|
|
|
[&InfoGetConfig](cm::string_view key) -> std::vector<std::string> {
|
|
|
|
return cmExpandedList(InfoGetConfig(key));
|
2017-11-16 09:59:03 +01:00
|
|
|
};
|
2019-08-26 17:16:54 +02:00
|
|
|
auto LogInfoError = [this](cm::string_view msg) -> bool {
|
|
|
|
this->Log().Error(GenT::RCC,
|
|
|
|
cmStrCat("In ", Quoted(this->InfoFile()), ":\n", msg));
|
2019-05-11 21:39:41 +02:00
|
|
|
return false;
|
|
|
|
};
|
2017-11-16 09:59:03 +01:00
|
|
|
|
|
|
|
// -- Read info file
|
2019-01-17 12:36:07 -05:00
|
|
|
if (!makefile->ReadListFile(InfoFile())) {
|
2019-05-11 21:39:41 +02:00
|
|
|
return LogInfoError("File processing failed.");
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
|
|
|
|
2018-01-31 13:54:37 +01:00
|
|
|
// - Configurations
|
2019-05-02 11:03:13 +02:00
|
|
|
Logger_.RaiseVerbosity(InfoGet("ARCC_VERBOSITY"));
|
2018-01-31 13:54:37 +01:00
|
|
|
MultiConfig_ = makefile->IsOn("ARCC_MULTI_CONFIG");
|
2017-11-16 09:59:03 +01:00
|
|
|
|
2018-01-31 13:54:37 +01:00
|
|
|
// - Directories
|
2018-01-03 16:59:40 +01:00
|
|
|
AutogenBuildDir_ = InfoGet("ARCC_BUILD_DIR");
|
2018-01-31 13:54:37 +01:00
|
|
|
if (AutogenBuildDir_.empty()) {
|
2019-05-11 21:39:41 +02:00
|
|
|
return LogInfoError("Build directory empty.");
|
2018-01-31 13:54:37 +01:00
|
|
|
}
|
2017-11-16 09:59:03 +01:00
|
|
|
|
2018-01-31 13:54:37 +01:00
|
|
|
IncludeDir_ = InfoGetConfig("ARCC_INCLUDE_DIR");
|
|
|
|
if (IncludeDir_.empty()) {
|
2019-05-11 21:39:41 +02:00
|
|
|
return LogInfoError("Include directory empty.");
|
2018-01-31 13:54:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// - Rcc executable
|
2018-01-03 16:59:40 +01:00
|
|
|
RccExecutable_ = InfoGet("ARCC_RCC_EXECUTABLE");
|
2019-05-11 21:30:20 +02:00
|
|
|
if (!RccExecutableTime_.Load(RccExecutable_)) {
|
2019-08-26 17:16:54 +02:00
|
|
|
return LogInfoError(cmStrCat("The rcc executable ", Quoted(RccExecutable_),
|
|
|
|
" does not exist."));
|
2019-05-11 21:30:20 +02:00
|
|
|
}
|
2018-01-03 16:59:40 +01:00
|
|
|
RccListOptions_ = InfoGetList("ARCC_RCC_LIST_OPTIONS");
|
2017-11-16 09:59:03 +01:00
|
|
|
|
|
|
|
// - Job
|
2018-05-30 16:34:09 +02:00
|
|
|
LockFile_ = InfoGet("ARCC_LOCK_FILE");
|
2018-01-03 16:59:40 +01:00
|
|
|
QrcFile_ = InfoGet("ARCC_SOURCE");
|
|
|
|
QrcFileName_ = cmSystemTools::GetFilenameName(QrcFile_);
|
|
|
|
QrcFileDir_ = cmSystemTools::GetFilenamePath(QrcFile_);
|
2018-01-31 13:54:37 +01:00
|
|
|
RccPathChecksum_ = InfoGet("ARCC_OUTPUT_CHECKSUM");
|
|
|
|
RccFileName_ = InfoGet("ARCC_OUTPUT_NAME");
|
2018-01-03 16:59:40 +01:00
|
|
|
Options_ = InfoGetConfigList("ARCC_OPTIONS");
|
|
|
|
Inputs_ = InfoGetList("ARCC_INPUTS");
|
2017-11-16 09:59:03 +01:00
|
|
|
|
2018-01-31 13:54:37 +01:00
|
|
|
// - Settings file
|
|
|
|
SettingsFile_ = InfoGetConfig("ARCC_SETTINGS_FILE");
|
|
|
|
|
2017-11-16 09:59:03 +01:00
|
|
|
// - Validity checks
|
2018-05-30 16:34:09 +02:00
|
|
|
if (LockFile_.empty()) {
|
2019-05-11 21:39:41 +02:00
|
|
|
return LogInfoError("Lock file name missing.");
|
2018-05-30 16:34:09 +02:00
|
|
|
}
|
2018-01-03 16:59:40 +01:00
|
|
|
if (SettingsFile_.empty()) {
|
2019-05-11 21:39:41 +02:00
|
|
|
return LogInfoError("Settings file name missing.");
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
2018-01-03 16:59:40 +01:00
|
|
|
if (AutogenBuildDir_.empty()) {
|
2019-05-11 21:39:41 +02:00
|
|
|
return LogInfoError("Autogen build directory missing.");
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
2018-01-03 16:59:40 +01:00
|
|
|
if (RccExecutable_.empty()) {
|
2019-05-11 21:39:41 +02:00
|
|
|
return LogInfoError("rcc executable missing.");
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
2018-01-03 16:59:40 +01:00
|
|
|
if (QrcFile_.empty()) {
|
2019-05-11 21:39:41 +02:00
|
|
|
return LogInfoError("rcc input file missing.");
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
2018-01-31 13:54:37 +01:00
|
|
|
if (RccFileName_.empty()) {
|
2019-05-11 21:39:41 +02:00
|
|
|
return LogInfoError("rcc output file missing.");
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Init derived information
|
|
|
|
// ------------------------
|
|
|
|
|
2019-08-22 16:34:40 +02:00
|
|
|
RccFilePublic_ =
|
|
|
|
cmStrCat(AutogenBuildDir_, '/', RccPathChecksum_, '/', RccFileName_);
|
2018-01-31 13:54:37 +01:00
|
|
|
|
2018-01-03 16:59:40 +01:00
|
|
|
// Compute rcc output file name
|
2018-01-31 13:54:37 +01:00
|
|
|
if (IsMultiConfig()) {
|
2019-08-22 16:34:40 +02:00
|
|
|
RccFileOutput_ = cmStrCat(IncludeDir_, '/', MultiConfigOutput());
|
2018-01-31 13:54:37 +01:00
|
|
|
} else {
|
|
|
|
RccFileOutput_ = RccFilePublic_;
|
2018-01-03 16:59:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-11-16 09:59:03 +01:00
|
|
|
|
2019-04-06 12:42:56 +02:00
|
|
|
bool cmQtAutoRcc::Process()
|
2018-01-03 16:59:40 +01:00
|
|
|
{
|
2019-04-05 21:54:53 +02: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 16:59:40 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
2019-04-05 21:54:53 +02:00
|
|
|
// Test if the info file is newer than the output file
|
|
|
|
if (!TestInfoFile()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-03 16:59:40 +01:00
|
|
|
}
|
|
|
|
|
2019-04-05 21:54:53 +02:00
|
|
|
if (!GenerateWrapper()) {
|
|
|
|
return false;
|
2018-01-03 16:59:40 +01:00
|
|
|
}
|
|
|
|
|
2019-04-05 21:54:53 +02:00
|
|
|
return SettingsFileWrite();
|
2018-01-03 16:59:40 +01:00
|
|
|
}
|
|
|
|
|
2019-04-06 12:42:56 +02:00
|
|
|
std::string cmQtAutoRcc::MultiConfigOutput() const
|
2018-01-31 13:54:37 +01:00
|
|
|
{
|
2019-08-26 17:16:54 +02:00
|
|
|
return cmStrCat(RccPathChecksum_, '/',
|
|
|
|
AppendFilenameSuffix(RccFileName_, "_CMAKE_"));
|
2018-01-31 13:54:37 +01:00
|
|
|
}
|
|
|
|
|
2019-04-06 12:42:56 +02:00
|
|
|
bool cmQtAutoRcc::SettingsFileRead()
|
2017-11-16 09:59:03 +01:00
|
|
|
{
|
|
|
|
// Compose current settings strings
|
|
|
|
{
|
|
|
|
cmCryptoHash crypt(cmCryptoHash::AlgoSHA256);
|
|
|
|
std::string const sep(" ~~~ ");
|
|
|
|
{
|
2019-08-22 16:34:40 +02:00
|
|
|
std::string str =
|
|
|
|
cmStrCat(RccExecutable_, sep, cmJoin(RccListOptions_, ";"), sep,
|
|
|
|
QrcFile_, sep, RccPathChecksum_, sep, RccFileName_, sep,
|
|
|
|
cmJoin(Options_, ";"), sep, cmJoin(Inputs_, ";"), sep);
|
2018-01-03 16:59:40 +01:00
|
|
|
SettingsString_ = crypt.HashString(str);
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-30 16:34:09 +02:00
|
|
|
// Make sure the settings file exists
|
2019-04-05 23:43:19 +02:00
|
|
|
if (!cmSystemTools::FileExists(SettingsFile_, true)) {
|
2018-05-30 16:34:09 +02:00
|
|
|
// Touch the settings file to make sure it exists
|
2019-04-05 23:43:19 +02:00
|
|
|
if (!cmSystemTools::Touch(SettingsFile_, true)) {
|
|
|
|
Log().ErrorFile(GenT::RCC, SettingsFile_,
|
|
|
|
"Settings file creation failed.");
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-30 16:34:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Lock the lock file
|
|
|
|
{
|
|
|
|
// Make sure the lock file exists
|
2019-04-05 23:43:19 +02:00
|
|
|
if (!cmSystemTools::FileExists(LockFile_, true)) {
|
|
|
|
if (!cmSystemTools::Touch(LockFile_, true)) {
|
|
|
|
Log().ErrorFile(GenT::RCC, LockFile_, "Lock file creation failed.");
|
2018-05-30 16:34:09 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Lock the lock file
|
|
|
|
cmFileLockResult lockResult =
|
|
|
|
LockFileLock_.Lock(LockFile_, static_cast<unsigned long>(-1));
|
|
|
|
if (!lockResult.IsOk()) {
|
2019-02-21 10:17:52 +01:00
|
|
|
Log().ErrorFile(GenT::RCC, LockFile_,
|
2018-05-30 16:34:09 +02:00
|
|
|
"File lock failed: " + lockResult.GetOutputMessage());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-16 09:59:03 +01:00
|
|
|
// Read old settings
|
2018-01-03 16:59:40 +01:00
|
|
|
{
|
|
|
|
std::string content;
|
2019-04-05 23:43:19 +02:00
|
|
|
if (FileRead(content, SettingsFile_)) {
|
2018-01-03 16:59:40 +01:00
|
|
|
SettingsChanged_ = (SettingsString_ != SettingsFind(content, "rcc"));
|
2018-05-30 16:34:09 +02:00
|
|
|
// In case any setting changed clear the old settings file.
|
2018-01-03 16:59:40 +01: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 23:43:19 +02:00
|
|
|
std::string error;
|
|
|
|
if (!FileWrite(SettingsFile_, "", &error)) {
|
|
|
|
Log().ErrorFile(GenT::RCC, SettingsFile_,
|
|
|
|
"Settings file clearing failed. " + error);
|
|
|
|
return false;
|
|
|
|
}
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
2018-01-03 16:59:40 +01:00
|
|
|
} else {
|
|
|
|
SettingsChanged_ = true;
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
|
|
|
}
|
2018-05-30 16:34:09 +02:00
|
|
|
|
|
|
|
return true;
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
|
|
|
|
2019-04-06 12:42:56 +02:00
|
|
|
bool cmQtAutoRcc::SettingsFileWrite()
|
2017-11-16 09:59:03 +01:00
|
|
|
{
|
|
|
|
// Only write if any setting changed
|
2018-01-03 16:59:40 +01:00
|
|
|
if (SettingsChanged_) {
|
|
|
|
if (Log().Verbose()) {
|
2019-02-21 10:17:52 +01:00
|
|
|
Log().Info(GenT::RCC, "Writing settings file " + Quoted(SettingsFile_));
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
|
|
|
// Write settings file
|
2019-08-06 10:40:49 +02:00
|
|
|
std::string content = cmStrCat("rcc:", SettingsString_, '\n');
|
2019-04-05 23:43:19 +02:00
|
|
|
std::string error;
|
|
|
|
if (!FileWrite(SettingsFile_, content, &error)) {
|
2019-02-21 10:17:52 +01:00
|
|
|
Log().ErrorFile(GenT::RCC, SettingsFile_,
|
2019-04-05 23:43:19 +02:00
|
|
|
"Settings file writing failed. " + error);
|
2017-11-16 09:59:03 +01:00
|
|
|
// Remove old settings file to trigger a full rebuild on the next run
|
2019-04-05 23:43:19 +02:00
|
|
|
cmSystemTools::RemoveFile(SettingsFile_);
|
2019-04-05 21:54:53 +02:00
|
|
|
return false;
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
|
|
|
}
|
2018-05-30 16:34:09 +02:00
|
|
|
|
|
|
|
// Unlock the lock file
|
|
|
|
LockFileLock_.Release();
|
2019-04-05 21:54:53 +02:00
|
|
|
return true;
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
|
|
|
|
2019-04-05 21:54:53 +02:00
|
|
|
/// Do basic checks if rcc generation is required
|
2019-04-06 12:42:56 +02:00
|
|
|
bool cmQtAutoRcc::TestQrcRccFiles(bool& generate)
|
2017-11-16 09:59:03 +01:00
|
|
|
{
|
2019-04-05 21:54:53 +02:00
|
|
|
// Test if the rcc input file exists
|
|
|
|
if (!QrcFileTime_.Load(QrcFile_)) {
|
2019-08-26 17:16:54 +02:00
|
|
|
Log().ErrorFile(
|
|
|
|
GenT::RCC, QrcFile_,
|
|
|
|
cmStrCat("The resources file ", Quoted(QrcFile_), " does not exist"));
|
2019-04-05 21:54:53 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-01-03 16:59:40 +01:00
|
|
|
|
|
|
|
// Test if the rcc output file exists
|
2019-04-05 21:54:53 +02:00
|
|
|
if (!RccFileTime_.Load(RccFileOutput_)) {
|
2018-01-03 16:59:40 +01:00
|
|
|
if (Log().Verbose()) {
|
2019-08-22 16:34:40 +02:00
|
|
|
Reason = cmStrCat("Generating ", Quoted(RccFileOutput_),
|
|
|
|
", because it doesn't exist, from ", Quoted(QrcFile_));
|
2018-01-03 16:59:40 +01:00
|
|
|
}
|
2019-04-05 21:54:53 +02:00
|
|
|
generate = true;
|
|
|
|
return true;
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
2018-01-03 16:59:40 +01:00
|
|
|
|
|
|
|
// Test if the settings changed
|
|
|
|
if (SettingsChanged_) {
|
|
|
|
if (Log().Verbose()) {
|
2019-08-22 16:34:40 +02:00
|
|
|
Reason = cmStrCat("Generating ", Quoted(RccFileOutput_),
|
|
|
|
", because the rcc settings changed, from ",
|
|
|
|
Quoted(QrcFile_));
|
2018-01-03 16:59:40 +01:00
|
|
|
}
|
2019-04-05 21:54:53 +02:00
|
|
|
generate = true;
|
|
|
|
return true;
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
2018-01-03 16:59:40 +01:00
|
|
|
|
|
|
|
// Test if the rcc output file is older than the .qrc file
|
2019-04-05 21:54:53 +02:00
|
|
|
if (RccFileTime_.Older(QrcFileTime_)) {
|
|
|
|
if (Log().Verbose()) {
|
2019-08-22 16:34:40 +02:00
|
|
|
Reason = cmStrCat("Generating ", Quoted(RccFileOutput_),
|
|
|
|
", because it is older than ", Quoted(QrcFile_),
|
|
|
|
", from ", Quoted(QrcFile_));
|
2018-01-03 16:59:40 +01:00
|
|
|
}
|
2019-04-05 21:54:53 +02:00
|
|
|
generate = true;
|
2018-01-03 16:59:40 +01:00
|
|
|
return true;
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
|
|
|
|
2019-05-11 21:30:20 +02:00
|
|
|
// Test if the rcc output file is older than the rcc executable
|
|
|
|
if (RccFileTime_.Older(RccExecutableTime_)) {
|
|
|
|
if (Log().Verbose()) {
|
2019-08-22 16:34:40 +02:00
|
|
|
Reason = cmStrCat("Generating ", Quoted(RccFileOutput_),
|
|
|
|
", because it is older than the rcc executable, from ",
|
|
|
|
Quoted(QrcFile_));
|
2019-05-11 21:30:20 +02:00
|
|
|
}
|
|
|
|
generate = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-03 16:59:40 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-06 12:42:56 +02:00
|
|
|
bool cmQtAutoRcc::TestResources(bool& generate)
|
2018-01-03 16:59:40 +01:00
|
|
|
{
|
2019-04-05 21:54:53 +02:00
|
|
|
// Read resource files list
|
2018-01-03 16:59:40 +01:00
|
|
|
if (Inputs_.empty()) {
|
2017-11-16 09:59:03 +01:00
|
|
|
std::string error;
|
2019-04-05 21:54:53 +02:00
|
|
|
RccLister const lister(RccExecutable_, RccListOptions_);
|
|
|
|
if (!lister.list(QrcFile_, Inputs_, error, Log().Verbose())) {
|
|
|
|
Log().ErrorFile(GenT::RCC, QrcFile_, error);
|
|
|
|
return false;
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-03 16:59:40 +01:00
|
|
|
|
2019-05-11 21:23:29 +02:00
|
|
|
// Check if any resource file is newer than the rcc output file
|
2019-04-05 21:54:53 +02:00
|
|
|
for (std::string const& resFile : Inputs_) {
|
|
|
|
// Check if the resource file exists
|
|
|
|
cmFileTime fileTime;
|
|
|
|
if (!fileTime.Load(resFile)) {
|
2019-08-26 17:16:54 +02:00
|
|
|
Log().ErrorFile(GenT::RCC, QrcFile_,
|
|
|
|
cmStrCat("Could not find the resource file\n ",
|
|
|
|
Quoted(resFile), '\n'));
|
2019-04-05 21:54:53 +02:00
|
|
|
return false;
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
2019-05-11 21:23:29 +02:00
|
|
|
// Check if the resource file is newer than the rcc output file
|
2019-04-05 21:54:53 +02:00
|
|
|
if (RccFileTime_.Older(fileTime)) {
|
2018-01-03 16:59:40 +01:00
|
|
|
if (Log().Verbose()) {
|
2019-08-22 16:34:40 +02:00
|
|
|
Reason = cmStrCat("Generating ", Quoted(RccFileOutput_),
|
|
|
|
", because it is older than ", Quoted(resFile),
|
|
|
|
", from ", Quoted(QrcFile_));
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
2019-04-05 21:54:53 +02:00
|
|
|
generate = true;
|
|
|
|
break;
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
|
|
|
}
|
2019-04-05 21:54:53 +02:00
|
|
|
return true;
|
2018-01-03 16:59:40 +01:00
|
|
|
}
|
2017-11-16 09:59:03 +01:00
|
|
|
|
2019-04-06 12:42:56 +02:00
|
|
|
bool cmQtAutoRcc::TestInfoFile()
|
2018-01-03 16:59:40 +01:00
|
|
|
{
|
2019-04-05 21:54:53 +02:00
|
|
|
// Test if the rcc output file is older than the info file
|
2019-05-11 22:13:39 +02:00
|
|
|
if (RccFileTime_.Older(InfoFileTime())) {
|
2019-04-05 21:54:53 +02:00
|
|
|
if (Log().Verbose()) {
|
2019-08-26 17:16:54 +02:00
|
|
|
Log().Info(GenT::RCC,
|
|
|
|
cmStrCat("Touching ", Quoted(RccFileOutput_),
|
|
|
|
" because it is older than ", Quoted(InfoFile())));
|
2019-04-05 21:54:53 +02:00
|
|
|
}
|
|
|
|
// Touch build file
|
2019-04-05 23:43:19 +02:00
|
|
|
if (!cmSystemTools::Touch(RccFileOutput_, false)) {
|
|
|
|
Log().ErrorFile(GenT::RCC, RccFileOutput_, "Build file touch failed");
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-05 21:54:53 +02:00
|
|
|
BuildFileChanged_ = true;
|
2018-01-03 16:59:40 +01:00
|
|
|
}
|
2019-04-05 21:54:53 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-06 12:42:56 +02:00
|
|
|
bool cmQtAutoRcc::GenerateRcc()
|
2018-01-03 16:59:40 +01:00
|
|
|
{
|
2019-04-05 23:43:19 +02:00
|
|
|
// Make parent directory
|
|
|
|
if (!MakeParentDirectory(RccFileOutput_)) {
|
|
|
|
Log().ErrorFile(GenT::RCC, RccFileOutput_,
|
|
|
|
"Could not create parent directory");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-11 21:23:29 +02:00
|
|
|
// Compose rcc command
|
2019-04-05 21:54:53 +02:00
|
|
|
std::vector<std::string> cmd;
|
|
|
|
cmd.push_back(RccExecutable_);
|
2019-05-23 14:49:54 +02:00
|
|
|
cmAppend(cmd, Options_);
|
2019-04-05 21:54:53 +02:00
|
|
|
cmd.emplace_back("-o");
|
|
|
|
cmd.push_back(RccFileOutput_);
|
|
|
|
cmd.push_back(QrcFile_);
|
|
|
|
|
2019-05-11 21:23:29 +02:00
|
|
|
// Log reason and command
|
2019-04-05 21:54:53 +02:00
|
|
|
if (Log().Verbose()) {
|
2019-08-26 17:16:54 +02:00
|
|
|
Log().Info(GenT::RCC,
|
|
|
|
cmStrCat(Reason, cmHasSuffix(Reason, '\n') ? "" : "\n",
|
|
|
|
QuotedCommand(cmd), '\n'));
|
2018-01-03 16:59:40 +01:00
|
|
|
}
|
|
|
|
|
2019-04-05 21:54:53 +02: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 17:16:54 +02:00
|
|
|
Log().ErrorCommand(GenT::RCC,
|
|
|
|
cmStrCat("The rcc process failed to compile\n ",
|
|
|
|
Quoted(QrcFile_), "\ninto\n ",
|
|
|
|
Quoted(RccFileOutput_)),
|
|
|
|
cmd, rccStdOut + rccStdErr);
|
2019-04-05 23:43:19 +02:00
|
|
|
cmSystemTools::RemoveFile(RccFileOutput_);
|
2019-04-05 21:54:53 +02:00
|
|
|
return false;
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
|
|
|
|
2019-04-05 21:54:53 +02:00
|
|
|
// rcc process success
|
|
|
|
// Print rcc output
|
|
|
|
if (!rccStdOut.empty()) {
|
|
|
|
Log().Info(GenT::RCC, rccStdOut);
|
|
|
|
}
|
|
|
|
BuildFileChanged_ = true;
|
|
|
|
|
2018-01-03 16:59:40 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-06 12:42:56 +02:00
|
|
|
bool cmQtAutoRcc::GenerateWrapper()
|
2018-01-03 16:59:40 +01:00
|
|
|
{
|
2017-11-16 09:59:03 +01:00
|
|
|
// Generate a wrapper source file on demand
|
2018-01-31 13:54:37 +01:00
|
|
|
if (IsMultiConfig()) {
|
2017-11-16 09:59:03 +01:00
|
|
|
// Wrapper file content
|
2019-08-06 10:40:49 +02:00
|
|
|
std::string content =
|
|
|
|
cmStrCat("// This is an autogenerated configuration wrapper file.\n",
|
|
|
|
"// Changes will be overwritten.\n", "#include <",
|
|
|
|
MultiConfigOutput(), ">\n");
|
2018-01-31 13:54:37 +01:00
|
|
|
|
2019-04-05 23:43:19 +02:00
|
|
|
// Compare with existing file content
|
|
|
|
bool fileDiffers = true;
|
|
|
|
{
|
|
|
|
std::string oldContents;
|
|
|
|
if (FileRead(oldContents, RccFilePublic_)) {
|
|
|
|
fileDiffers = (oldContents != content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fileDiffers) {
|
2017-11-16 09:59:03 +01:00
|
|
|
// Write new wrapper file
|
2018-01-03 16:59:40 +01:00
|
|
|
if (Log().Verbose()) {
|
2019-02-21 10:17:52 +01:00
|
|
|
Log().Info(GenT::RCC, "Generating RCC wrapper file " + RccFilePublic_);
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
2019-04-05 23:43:19 +02:00
|
|
|
std::string error;
|
|
|
|
if (!FileWrite(RccFilePublic_, content, &error)) {
|
2019-02-21 10:17:52 +01:00
|
|
|
Log().ErrorFile(GenT::RCC, RccFilePublic_,
|
2019-04-05 23:43:19 +02:00
|
|
|
"RCC wrapper file writing failed. " + error);
|
2019-04-05 21:54:53 +02:00
|
|
|
return false;
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
2018-01-03 16:59:40 +01:00
|
|
|
} else if (BuildFileChanged_) {
|
2017-11-16 09:59:03 +01:00
|
|
|
// Just touch the wrapper file
|
2018-01-03 16:59:40 +01:00
|
|
|
if (Log().Verbose()) {
|
2019-02-21 10:17:52 +01:00
|
|
|
Log().Info(GenT::RCC, "Touching RCC wrapper file " + RccFilePublic_);
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
2019-04-05 23:43:19 +02:00
|
|
|
if (!cmSystemTools::Touch(RccFilePublic_, false)) {
|
|
|
|
Log().ErrorFile(GenT::RCC, RccFilePublic_,
|
|
|
|
"RCC wrapper file touch failed.");
|
|
|
|
return false;
|
|
|
|
}
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-03 16:59:40 +01:00
|
|
|
return true;
|
2017-11-16 09:59:03 +01:00
|
|
|
}
|