mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-21 14:40:26 -06:00
AutoRcc: Use cmQtAutoGen::RccLister in initializer and generator
Both classes `cmQtAutoGenInitializer` and `cmQtAutoGeneratorRcc` had different implementations for reading the files list from a `.qrc` resources file. This patch replaces both implementations with the common simple `cmQtAutoGen::RccLister` implementation.
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
#include "cmAlgorithms.h"
|
||||
#include "cmCustomCommand.h"
|
||||
#include "cmCustomCommandLines.h"
|
||||
#include "cmDuration.h"
|
||||
#include "cmFilePathChecksum.h"
|
||||
#include "cmGeneratorExpression.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
@@ -19,7 +18,6 @@
|
||||
#include "cmMessageType.h"
|
||||
#include "cmOutputConverter.h"
|
||||
#include "cmPolicies.h"
|
||||
#include "cmProcessOutput.h"
|
||||
#include "cmSourceFile.h"
|
||||
#include "cmSourceFileLocationKind.h"
|
||||
#include "cmSourceGroup.h"
|
||||
@@ -28,7 +26,6 @@
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmTarget.h"
|
||||
#include "cmake.h"
|
||||
#include "cmsys/FStream.hxx"
|
||||
#include "cmsys/SystemInformation.hxx"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -36,7 +33,6 @@
|
||||
#include <deque>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -935,7 +931,8 @@ bool cmQtAutoGenInitializer::InitScanFiles()
|
||||
for (Qrc& qrc : this->Rcc.Qrcs) {
|
||||
if (!qrc.Generated) {
|
||||
std::string error;
|
||||
if (!RccListInputs(qrc.QrcFile, qrc.Resources, error)) {
|
||||
RccLister const lister(this->Rcc.Executable, this->Rcc.ListOptions);
|
||||
if (!lister.list(qrc.QrcFile, qrc.Resources, error)) {
|
||||
cmSystemTools::Error(error);
|
||||
return false;
|
||||
}
|
||||
@@ -1630,86 +1627,3 @@ bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @brief Reads the resource files list from from a .qrc file
|
||||
/// @arg fileName Must be the absolute path of the .qrc file
|
||||
/// @return True if the rcc file was successfully read
|
||||
bool cmQtAutoGenInitializer::RccListInputs(std::string const& fileName,
|
||||
std::vector<std::string>& files,
|
||||
std::string& error)
|
||||
{
|
||||
if (!cmSystemTools::FileExists(fileName)) {
|
||||
error = "rcc resource file does not exist:\n ";
|
||||
error += Quoted(fileName);
|
||||
error += "\n";
|
||||
return false;
|
||||
}
|
||||
if (this->Rcc.ExecutableExists && !this->Rcc.ListOptions.empty()) {
|
||||
// Use rcc for file listing
|
||||
if (this->Rcc.Executable.empty()) {
|
||||
error = "rcc executable not available";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Run rcc list command in the directory of the qrc file with the
|
||||
// pathless
|
||||
// qrc file name argument. This way rcc prints relative paths.
|
||||
// This avoids issues on Windows when the qrc file is in a path that
|
||||
// contains non-ASCII characters.
|
||||
std::string const fileDir = cmSystemTools::GetFilenamePath(fileName);
|
||||
std::string const fileNameName = cmSystemTools::GetFilenameName(fileName);
|
||||
|
||||
bool result = false;
|
||||
int retVal = 0;
|
||||
std::string rccStdOut;
|
||||
std::string rccStdErr;
|
||||
{
|
||||
std::vector<std::string> cmd;
|
||||
cmd.push_back(this->Rcc.Executable);
|
||||
cmd.insert(cmd.end(), this->Rcc.ListOptions.begin(),
|
||||
this->Rcc.ListOptions.end());
|
||||
cmd.push_back(fileNameName);
|
||||
result = cmSystemTools::RunSingleCommand(
|
||||
cmd, &rccStdOut, &rccStdErr, &retVal, fileDir.c_str(),
|
||||
cmSystemTools::OUTPUT_NONE, cmDuration::zero(), cmProcessOutput::Auto);
|
||||
}
|
||||
if (!result || retVal) {
|
||||
error = "rcc list process failed for:\n ";
|
||||
error += Quoted(fileName);
|
||||
error += "\n";
|
||||
error += rccStdOut;
|
||||
error += "\n";
|
||||
error += rccStdErr;
|
||||
error += "\n";
|
||||
return false;
|
||||
}
|
||||
if (!RccListParseOutput(rccStdOut, rccStdErr, files, error)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// We can't use rcc for the file listing.
|
||||
// Read the qrc file content into string and parse it.
|
||||
{
|
||||
std::string qrcContents;
|
||||
{
|
||||
cmsys::ifstream ifs(fileName.c_str());
|
||||
if (ifs) {
|
||||
std::ostringstream osst;
|
||||
osst << ifs.rdbuf();
|
||||
qrcContents = osst.str();
|
||||
} else {
|
||||
error = "rcc file not readable:\n ";
|
||||
error += Quoted(fileName);
|
||||
error += "\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Parse string content
|
||||
RccListParseContent(qrcContents, files);
|
||||
}
|
||||
}
|
||||
|
||||
// Convert relative paths to absolute paths
|
||||
RccListConvertFullPath(cmSystemTools::GetFilenamePath(fileName), files);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -149,10 +149,6 @@ private:
|
||||
bool GetQtExecutable(GenVarsT& genVars, const std::string& executable,
|
||||
bool ignoreMissingTarget, std::string* output) const;
|
||||
|
||||
bool RccListInputs(std::string const& fileName,
|
||||
std::vector<std::string>& files,
|
||||
std::string& errorMessage);
|
||||
|
||||
private:
|
||||
cmQtAutoGenGlobalInitializer* GlobalInitializer;
|
||||
cmGeneratorTarget* Target;
|
||||
|
||||
@@ -410,59 +410,12 @@ bool cmQtAutoGeneratorRcc::TestResourcesRead()
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!RccListOptions_.empty()) {
|
||||
// Start a rcc list process and parse the output
|
||||
if (Process_) {
|
||||
// Process is running already
|
||||
if (Process_->IsFinished()) {
|
||||
// Process is finished
|
||||
if (!ProcessResult_.error()) {
|
||||
// Process success
|
||||
std::string parseError;
|
||||
if (!RccListParseOutput(ProcessResult_.StdOut, ProcessResult_.StdErr,
|
||||
Inputs_, parseError)) {
|
||||
Log().ErrorFile(GenT::RCC, QrcFile_, parseError);
|
||||
Error_ = true;
|
||||
}
|
||||
} else {
|
||||
Log().ErrorFile(GenT::RCC, QrcFile_, ProcessResult_.ErrorMessage);
|
||||
Error_ = true;
|
||||
}
|
||||
// Clean up
|
||||
Process_.reset();
|
||||
ProcessResult_.reset();
|
||||
} else {
|
||||
// Process is not finished, yet.
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Start a new process
|
||||
// rcc prints relative entry paths when started in the directory of the
|
||||
// qrc file with a pathless qrc file name argument.
|
||||
// This is important because on Windows absolute paths returned by rcc
|
||||
// might contain bad multibyte characters when the qrc file path
|
||||
// contains non-ASCII pcharacters.
|
||||
std::vector<std::string> cmd;
|
||||
cmd.push_back(RccExecutable_);
|
||||
cmd.insert(cmd.end(), RccListOptions_.begin(), RccListOptions_.end());
|
||||
cmd.push_back(QrcFileName_);
|
||||
// We're done here if the process fails to start
|
||||
return !StartProcess(QrcFileDir_, cmd, false);
|
||||
}
|
||||
} else {
|
||||
// rcc does not support the --list command.
|
||||
// Read the qrc file content and parse it.
|
||||
std::string qrcContent;
|
||||
if (FileSys().FileRead(GenT::RCC, qrcContent, QrcFile_)) {
|
||||
RccListParseContent(qrcContent, Inputs_);
|
||||
}
|
||||
std::string error;
|
||||
RccLister lister(RccExecutable_, RccListOptions_);
|
||||
if (!lister.list(QrcFile_, Inputs_, error)) {
|
||||
Log().ErrorFile(GenT::RCC, QrcFile_, error);
|
||||
Error_ = true;
|
||||
}
|
||||
|
||||
if (!Inputs_.empty()) {
|
||||
// Convert relative paths to absolute paths
|
||||
RccListConvertFullPath(QrcFileDir_, Inputs_);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user