mirror of
https://github.com/Kitware/CMake.git
synced 2025-07-26 02:16:47 +08:00
Autogen: Single point of return in RccGenerateFile
This commit is contained in:
parent
c29950cc1f
commit
2fed7bcc1f
@ -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)
|
||||||
{
|
{
|
||||||
std::string symbolName =
|
bool rccGenerated = false;
|
||||||
cmsys::SystemTools::GetFilenameWithoutLastExtension(qrcInputFile);
|
bool generateRcc = this->GenerateAllRcc;
|
||||||
if (!unique_n) {
|
|
||||||
symbolName += "_";
|
|
||||||
symbolName += fpathCheckSum.getPart(qrcInputFile);
|
|
||||||
}
|
|
||||||
// Replace '-' with '_'. The former is valid for
|
|
||||||
// file names but not for symbol names.
|
|
||||||
std::replace(symbolName.begin(), symbolName.end(), '-', '_');
|
|
||||||
|
|
||||||
const std::string qrcBuildFile = this->CurrentBinaryDir + qrcOutputFile;
|
const std::string rccBuildFile = this->CurrentBinaryDir + rccOutputFile;
|
||||||
|
|
||||||
bool generateQrc = this->GenerateAllRcc;
|
if (!generateRcc) {
|
||||||
// Test if the resources list file is newer than build file
|
// Test if the resources list file is newer than build file
|
||||||
if (!generateQrc) {
|
generateRcc = FileAbsentOrOlder(rccBuildFile, rccInputFile);
|
||||||
generateQrc = FileAbsentOrOlder(qrcBuildFile, qrcInputFile);
|
if (!generateRcc) {
|
||||||
}
|
// Test if any resource file is newer than the build file
|
||||||
// Test if any resource file is newer than the build file
|
const std::vector<std::string>& files = this->RccInputs[rccInputFile];
|
||||||
if (!generateQrc) {
|
for (std::vector<std::string>::const_iterator it = files.begin();
|
||||||
const std::vector<std::string>& files = this->RccInputs[qrcInputFile];
|
it != files.end(); ++it) {
|
||||||
for (std::vector<std::string>::const_iterator it = files.begin();
|
if (FileAbsentOrOlder(rccBuildFile, *it)) {
|
||||||
it != files.end(); ++it) {
|
generateRcc = true;
|
||||||
if (FileAbsentOrOlder(qrcBuildFile, *it)) {
|
break;
|
||||||
generateQrc = true;
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (generateQrc) {
|
if (generateRcc) {
|
||||||
{
|
// Log
|
||||||
std::string msg = "Generating RCC source ";
|
this->LogBold("Generating RCC source " + rccOutputFile);
|
||||||
msg += qrcOutputFile;
|
|
||||||
this->LogBold(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure the parent directory exists
|
// Make sure the parent directory exists
|
||||||
if (!this->MakeParentDirectory(qrcOutputFile)) {
|
if (this->MakeParentDirectory(rccBuildFile)) {
|
||||||
this->RunRccFailed = true;
|
// Compose symbol name
|
||||||
return false;
|
std::string symbolName =
|
||||||
}
|
cmsys::SystemTools::GetFilenameWithoutLastExtension(rccInputFile);
|
||||||
|
if (!unique_n) {
|
||||||
std::vector<std::string> command;
|
symbolName += "_";
|
||||||
command.push_back(this->RccExecutable);
|
symbolName += fpathCheckSum.getPart(rccInputFile);
|
||||||
{
|
|
||||||
std::map<std::string, std::string>::const_iterator optionIt =
|
|
||||||
this->RccOptions.find(qrcInputFile);
|
|
||||||
if (optionIt != this->RccOptions.end()) {
|
|
||||||
cmSystemTools::ExpandListArgument(optionIt->second, command);
|
|
||||||
}
|
}
|
||||||
}
|
// Replace '-' with '_'. The former is valid for
|
||||||
command.push_back("-name");
|
// file names but not for symbol names.
|
||||||
command.push_back(symbolName);
|
std::replace(symbolName.begin(), symbolName.end(), '-', '_');
|
||||||
command.push_back("-o");
|
|
||||||
command.push_back(qrcBuildFile);
|
|
||||||
command.push_back(qrcInputFile);
|
|
||||||
|
|
||||||
if (this->Verbose) {
|
// Compose rcc command
|
||||||
this->LogCommand(command);
|
std::vector<std::string> cmd;
|
||||||
}
|
cmd.push_back(this->RccExecutable);
|
||||||
std::string output;
|
|
||||||
int retVal = 0;
|
|
||||||
bool result =
|
|
||||||
cmSystemTools::RunSingleCommand(command, &output, &output, &retVal);
|
|
||||||
if (!result || retVal) {
|
|
||||||
{
|
{
|
||||||
std::ostringstream err;
|
std::map<std::string, std::string>::const_iterator optionIt =
|
||||||
err << "AutoRcc: Error: rcc process for " << qrcOutputFile
|
this->RccOptions.find(rccInputFile);
|
||||||
<< " failed:\n"
|
if (optionIt != this->RccOptions.end()) {
|
||||||
<< output << std::endl;
|
cmSystemTools::ExpandListArgument(optionIt->second, cmd);
|
||||||
this->LogError(err.str());
|
}
|
||||||
}
|
}
|
||||||
cmSystemTools::RemoveFile(qrcBuildFile);
|
cmd.push_back("-name");
|
||||||
|
cmd.push_back(symbolName);
|
||||||
|
cmd.push_back("-o");
|
||||||
|
cmd.push_back(rccBuildFile);
|
||||||
|
cmd.push_back(rccInputFile);
|
||||||
|
|
||||||
|
// Log command
|
||||||
|
if (this->Verbose) {
|
||||||
|
this->LogCommand(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute command
|
||||||
|
bool res = false;
|
||||||
|
int retVal = 0;
|
||||||
|
std::string output;
|
||||||
|
res = cmSystemTools::RunSingleCommand(cmd, &output, &output, &retVal);
|
||||||
|
if (!res || (retVal != 0)) {
|
||||||
|
// Command failed
|
||||||
|
{
|
||||||
|
std::ostringstream err;
|
||||||
|
err << "AutoRcc: Error: rcc process failed for\n";
|
||||||
|
err << "\"" << rccOutputFile << "\"\n";
|
||||||
|
err << "AutoRcc: Command:\n" << cmJoin(cmd, " ") << "\n";
|
||||||
|
err << "AutoRcc: Command output:\n" << output << "\n";
|
||||||
|
this->LogError(err.str());
|
||||||
|
}
|
||||||
|
cmSystemTools::RemoveFile(rccBuildFile);
|
||||||
|
this->RunRccFailed = true;
|
||||||
|
} else {
|
||||||
|
// Success
|
||||||
|
rccGenerated = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Parent directory creation failed
|
||||||
this->RunRccFailed = true;
|
this->RunRccFailed = true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return rccGenerated;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmQtAutoGenerators::LogErrorNameCollision(
|
void cmQtAutoGenerators::LogErrorNameCollision(
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user