1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-07-27 13:25:40 +08:00

Autogen: Single point of return in RccGenerateFile

This commit is contained in:
Sebastian Holtermann 2017-02-14 21:59:36 +01:00
parent c29950cc1f
commit 2fed7bcc1f
2 changed files with 79 additions and 72 deletions

View File

@ -672,7 +672,7 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile)
if (!this->UicGenerateAll(includedUis)) { if (!this->UicGenerateAll(includedUis)) {
return false; return false;
} }
if (!this->QrcGenerateAll()) { if (!this->RccGenerateAll()) {
return false; return false;
} }
@ -1408,7 +1408,7 @@ bool cmQtAutoGenerators::UicGenerateFile(const std::string& realName,
return uicGenerated; return uicGenerated;
} }
bool cmQtAutoGenerators::QrcGenerateAll() bool cmQtAutoGenerators::RccGenerateAll()
{ {
if (!this->RccEnabled()) { if (!this->RccEnabled()) {
return true; return true;
@ -1445,7 +1445,7 @@ bool cmQtAutoGenerators::QrcGenerateAll()
qrcGenMap.begin(); qrcGenMap.begin();
si != qrcGenMap.end(); ++si) { si != qrcGenMap.end(); ++si) {
bool unique = FileNameIsUnique(si->first, qrcGenMap); bool unique = FileNameIsUnique(si->first, qrcGenMap);
if (!this->QrcGenerateFile(si->first, si->second, unique)) { if (!this->RccGenerateFile(si->first, si->second, unique)) {
if (this->RunRccFailed) { if (this->RunRccFailed) {
return false; return false;
} }
@ -1457,88 +1457,95 @@ bool cmQtAutoGenerators::QrcGenerateAll()
/** /**
* @return True if a rcc file was created. False may indicate an error. * @return True if a rcc file was created. False may indicate an error.
*/ */
bool cmQtAutoGenerators::QrcGenerateFile(const std::string& qrcInputFile, bool cmQtAutoGenerators::RccGenerateFile(const std::string& rccInputFile,
const std::string& qrcOutputFile, const std::string& rccOutputFile,
bool unique_n) bool unique_n)
{ {
bool rccGenerated = false;
bool generateRcc = this->GenerateAllRcc;
const std::string rccBuildFile = this->CurrentBinaryDir + rccOutputFile;
if (!generateRcc) {
// Test if the resources list file is newer than build file
generateRcc = FileAbsentOrOlder(rccBuildFile, rccInputFile);
if (!generateRcc) {
// Test if any resource file is newer than the build file
const std::vector<std::string>& files = this->RccInputs[rccInputFile];
for (std::vector<std::string>::const_iterator it = files.begin();
it != files.end(); ++it) {
if (FileAbsentOrOlder(rccBuildFile, *it)) {
generateRcc = true;
break;
}
}
}
}
if (generateRcc) {
// Log
this->LogBold("Generating RCC source " + rccOutputFile);
// Make sure the parent directory exists
if (this->MakeParentDirectory(rccBuildFile)) {
// Compose symbol name
std::string symbolName = std::string symbolName =
cmsys::SystemTools::GetFilenameWithoutLastExtension(qrcInputFile); cmsys::SystemTools::GetFilenameWithoutLastExtension(rccInputFile);
if (!unique_n) { if (!unique_n) {
symbolName += "_"; symbolName += "_";
symbolName += fpathCheckSum.getPart(qrcInputFile); symbolName += fpathCheckSum.getPart(rccInputFile);
} }
// Replace '-' with '_'. The former is valid for // Replace '-' with '_'. The former is valid for
// file names but not for symbol names. // file names but not for symbol names.
std::replace(symbolName.begin(), symbolName.end(), '-', '_'); std::replace(symbolName.begin(), symbolName.end(), '-', '_');
const std::string qrcBuildFile = this->CurrentBinaryDir + qrcOutputFile; // Compose rcc command
std::vector<std::string> cmd;
bool generateQrc = this->GenerateAllRcc; cmd.push_back(this->RccExecutable);
// Test if the resources list file is newer than build file
if (!generateQrc) {
generateQrc = FileAbsentOrOlder(qrcBuildFile, qrcInputFile);
}
// Test if any resource file is newer than the build file
if (!generateQrc) {
const std::vector<std::string>& files = this->RccInputs[qrcInputFile];
for (std::vector<std::string>::const_iterator it = files.begin();
it != files.end(); ++it) {
if (FileAbsentOrOlder(qrcBuildFile, *it)) {
generateQrc = true;
break;
}
}
}
if (generateQrc) {
{
std::string msg = "Generating RCC source ";
msg += qrcOutputFile;
this->LogBold(msg);
}
// Make sure the parent directory exists
if (!this->MakeParentDirectory(qrcOutputFile)) {
this->RunRccFailed = true;
return false;
}
std::vector<std::string> command;
command.push_back(this->RccExecutable);
{ {
std::map<std::string, std::string>::const_iterator optionIt = std::map<std::string, std::string>::const_iterator optionIt =
this->RccOptions.find(qrcInputFile); this->RccOptions.find(rccInputFile);
if (optionIt != this->RccOptions.end()) { if (optionIt != this->RccOptions.end()) {
cmSystemTools::ExpandListArgument(optionIt->second, command); cmSystemTools::ExpandListArgument(optionIt->second, cmd);
} }
} }
command.push_back("-name"); cmd.push_back("-name");
command.push_back(symbolName); cmd.push_back(symbolName);
command.push_back("-o"); cmd.push_back("-o");
command.push_back(qrcBuildFile); cmd.push_back(rccBuildFile);
command.push_back(qrcInputFile); cmd.push_back(rccInputFile);
// Log command
if (this->Verbose) { if (this->Verbose) {
this->LogCommand(command); this->LogCommand(cmd);
} }
std::string output;
// Execute command
bool res = false;
int retVal = 0; int retVal = 0;
bool result = std::string output;
cmSystemTools::RunSingleCommand(command, &output, &output, &retVal); res = cmSystemTools::RunSingleCommand(cmd, &output, &output, &retVal);
if (!result || retVal) { if (!res || (retVal != 0)) {
// Command failed
{ {
std::ostringstream err; std::ostringstream err;
err << "AutoRcc: Error: rcc process for " << qrcOutputFile err << "AutoRcc: Error: rcc process failed for\n";
<< " failed:\n" err << "\"" << rccOutputFile << "\"\n";
<< output << std::endl; err << "AutoRcc: Command:\n" << cmJoin(cmd, " ") << "\n";
err << "AutoRcc: Command output:\n" << output << "\n";
this->LogError(err.str()); this->LogError(err.str());
} }
cmSystemTools::RemoveFile(qrcBuildFile); cmSystemTools::RemoveFile(rccBuildFile);
this->RunRccFailed = true; this->RunRccFailed = true;
return false; } else {
// Success
rccGenerated = true;
} }
return true; } else {
// Parent directory creation failed
this->RunRccFailed = true;
} }
return false; }
return rccGenerated;
} }
void cmQtAutoGenerators::LogErrorNameCollision( void cmQtAutoGenerators::LogErrorNameCollision(

View File

@ -89,9 +89,9 @@ private:
const std::string& uiInputFile, const std::string& uiInputFile,
const std::string& uiOutputFile); const std::string& uiOutputFile);
// - Qrc file generation // - Rcc file generation
bool QrcGenerateAll(); bool RccGenerateAll();
bool QrcGenerateFile(const std::string& qrcInputFile, bool RccGenerateFile(const std::string& qrcInputFile,
const std::string& qrcOutputFile, bool unique_n); const std::string& qrcOutputFile, bool unique_n);
// - Logging // - Logging