2017-02-28 11:08:26 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2017-08-26 11:59:57 +00:00
|
|
|
#include "cmQtAutoGen.h"
|
2017-02-28 11:08:26 +00:00
|
|
|
#include "cmAlgorithms.h"
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
2017-04-11 20:00:21 +00:00
|
|
|
#include "cmsys/RegularExpression.hxx"
|
2017-02-28 11:08:26 +00:00
|
|
|
|
2017-08-30 21:13:10 +00:00
|
|
|
#include <algorithm>
|
2017-10-05 10:43:06 +00:00
|
|
|
#include <iterator>
|
2017-02-28 11:08:26 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2017-08-26 11:59:57 +00:00
|
|
|
// - Static variables
|
|
|
|
|
2017-09-12 08:08:10 +00:00
|
|
|
std::string const genNameGen = "AutoGen";
|
|
|
|
std::string const genNameMoc = "AutoMoc";
|
|
|
|
std::string const genNameUic = "AutoUic";
|
|
|
|
std::string const genNameRcc = "AutoRcc";
|
|
|
|
|
|
|
|
std::string const mcNameSingle = "SINGLE";
|
2018-01-03 15:59:40 +00:00
|
|
|
std::string const mcNameWrapper = "WRAPPER";
|
|
|
|
std::string const mcNameMulti = "MULTI";
|
2017-08-26 11:59:57 +00:00
|
|
|
|
2017-02-28 11:08:26 +00:00
|
|
|
// - Static functions
|
|
|
|
|
2017-08-30 21:13:10 +00:00
|
|
|
/// @brief Merges newOpts into baseOpts
|
|
|
|
/// @arg valueOpts list of options that accept a value
|
|
|
|
void MergeOptions(std::vector<std::string>& baseOpts,
|
2017-09-12 08:08:10 +00:00
|
|
|
std::vector<std::string> const& newOpts,
|
|
|
|
std::vector<std::string> const& valueOpts, bool isQt5)
|
2017-08-30 21:13:10 +00:00
|
|
|
{
|
|
|
|
typedef std::vector<std::string>::iterator Iter;
|
|
|
|
typedef std::vector<std::string>::const_iterator CIter;
|
|
|
|
if (newOpts.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (baseOpts.empty()) {
|
|
|
|
baseOpts = newOpts;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> extraOpts;
|
|
|
|
for (CIter fit = newOpts.begin(), fitEnd = newOpts.end(); fit != fitEnd;
|
|
|
|
++fit) {
|
2017-09-12 08:08:10 +00:00
|
|
|
std::string const& newOpt = *fit;
|
2017-08-30 21:13:10 +00:00
|
|
|
Iter existIt = std::find(baseOpts.begin(), baseOpts.end(), newOpt);
|
|
|
|
if (existIt != baseOpts.end()) {
|
|
|
|
if (newOpt.size() >= 2) {
|
|
|
|
// Acquire the option name
|
|
|
|
std::string optName;
|
|
|
|
{
|
|
|
|
auto oit = newOpt.begin();
|
|
|
|
if (*oit == '-') {
|
|
|
|
++oit;
|
|
|
|
if (isQt5 && (*oit == '-')) {
|
|
|
|
++oit;
|
|
|
|
}
|
|
|
|
optName.assign(oit, newOpt.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Test if this is a value option and change the existing value
|
|
|
|
if (!optName.empty() && (std::find(valueOpts.begin(), valueOpts.end(),
|
|
|
|
optName) != valueOpts.end())) {
|
|
|
|
const Iter existItNext(existIt + 1);
|
|
|
|
const CIter fitNext(fit + 1);
|
|
|
|
if ((existItNext != baseOpts.end()) && (fitNext != fitEnd)) {
|
|
|
|
*existItNext = *fitNext;
|
|
|
|
++fit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
extraOpts.push_back(newOpt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Append options
|
|
|
|
baseOpts.insert(baseOpts.end(), extraOpts.begin(), extraOpts.end());
|
|
|
|
}
|
|
|
|
|
2017-02-28 11:08:26 +00:00
|
|
|
// - Class definitions
|
|
|
|
|
2018-01-03 15:59:40 +00:00
|
|
|
std::string const cmQtAutoGen::ListSep = "<<<S>>>";
|
|
|
|
unsigned int const cmQtAutoGen::ParallelMax = 64;
|
2017-08-26 11:59:57 +00:00
|
|
|
|
2018-01-03 15:59:40 +00:00
|
|
|
std::string const& cmQtAutoGen::GeneratorName(GeneratorT type)
|
2017-08-26 11:59:57 +00:00
|
|
|
{
|
|
|
|
switch (type) {
|
2018-01-03 15:59:40 +00:00
|
|
|
case GeneratorT::GEN:
|
2017-08-26 11:59:57 +00:00
|
|
|
return genNameGen;
|
2018-01-03 15:59:40 +00:00
|
|
|
case GeneratorT::MOC:
|
2017-08-26 11:59:57 +00:00
|
|
|
return genNameMoc;
|
2018-01-03 15:59:40 +00:00
|
|
|
case GeneratorT::UIC:
|
2017-08-26 11:59:57 +00:00
|
|
|
return genNameUic;
|
2018-01-03 15:59:40 +00:00
|
|
|
case GeneratorT::RCC:
|
2017-08-26 11:59:57 +00:00
|
|
|
return genNameRcc;
|
|
|
|
}
|
|
|
|
return genNameGen;
|
|
|
|
}
|
|
|
|
|
2018-01-03 15:59:40 +00:00
|
|
|
std::string cmQtAutoGen::GeneratorNameUpper(GeneratorT genType)
|
2017-08-26 11:59:57 +00:00
|
|
|
{
|
|
|
|
return cmSystemTools::UpperCase(cmQtAutoGen::GeneratorName(genType));
|
|
|
|
}
|
2017-02-28 11:08:26 +00:00
|
|
|
|
2018-01-03 15:59:40 +00:00
|
|
|
std::string const& cmQtAutoGen::MultiConfigName(MultiConfigT config)
|
2017-09-12 08:08:10 +00:00
|
|
|
{
|
|
|
|
switch (config) {
|
2018-01-03 15:59:40 +00:00
|
|
|
case MultiConfigT::SINGLE:
|
2017-09-12 08:08:10 +00:00
|
|
|
return mcNameSingle;
|
2018-01-03 15:59:40 +00:00
|
|
|
case MultiConfigT::WRAPPER:
|
|
|
|
return mcNameWrapper;
|
|
|
|
case MultiConfigT::MULTI:
|
|
|
|
return mcNameMulti;
|
2017-09-12 08:08:10 +00:00
|
|
|
}
|
2018-01-03 15:59:40 +00:00
|
|
|
return mcNameWrapper;
|
2017-09-12 08:08:10 +00:00
|
|
|
}
|
|
|
|
|
2018-01-03 15:59:40 +00:00
|
|
|
cmQtAutoGen::MultiConfigT cmQtAutoGen::MultiConfigType(std::string const& name)
|
2017-09-12 08:08:10 +00:00
|
|
|
{
|
|
|
|
if (name == mcNameSingle) {
|
2018-01-03 15:59:40 +00:00
|
|
|
return MultiConfigT::SINGLE;
|
2017-09-12 08:08:10 +00:00
|
|
|
}
|
2018-01-03 15:59:40 +00:00
|
|
|
if (name == mcNameMulti) {
|
|
|
|
return MultiConfigT::MULTI;
|
2017-09-12 08:08:10 +00:00
|
|
|
}
|
2018-01-03 15:59:40 +00:00
|
|
|
return MultiConfigT::WRAPPER;
|
2017-09-12 08:08:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmQtAutoGen::Quoted(std::string const& text)
|
2017-03-02 13:06:02 +00:00
|
|
|
{
|
|
|
|
static const char* rep[18] = { "\\", "\\\\", "\"", "\\\"", "\a", "\\a",
|
|
|
|
"\b", "\\b", "\f", "\\f", "\n", "\\n",
|
|
|
|
"\r", "\\r", "\t", "\\t", "\v", "\\v" };
|
|
|
|
|
|
|
|
std::string res = text;
|
2017-10-05 10:43:06 +00:00
|
|
|
for (const char* const* it = cm::cbegin(rep); it != cm::cend(rep); it += 2) {
|
2017-03-02 13:06:02 +00:00
|
|
|
cmSystemTools::ReplaceString(res, *it, *(it + 1));
|
|
|
|
}
|
|
|
|
res = '"' + res;
|
|
|
|
res += '"';
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2018-01-03 15:59:40 +00:00
|
|
|
std::string cmQtAutoGen::QuotedCommand(std::vector<std::string> const& command)
|
|
|
|
{
|
|
|
|
std::string res;
|
|
|
|
for (std::string const& item : command) {
|
|
|
|
if (!res.empty()) {
|
|
|
|
res.push_back(' ');
|
|
|
|
}
|
|
|
|
std::string const cesc = cmQtAutoGen::Quoted(item);
|
|
|
|
if (item.empty() || (cesc.size() > (item.size() + 2)) ||
|
|
|
|
(cesc.find(' ') != std::string::npos)) {
|
|
|
|
res += cesc;
|
|
|
|
} else {
|
|
|
|
res += item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmQtAutoGen::SubDirPrefix(std::string const& filename)
|
|
|
|
{
|
|
|
|
std::string res(cmSystemTools::GetFilenamePath(filename));
|
|
|
|
if (!res.empty()) {
|
|
|
|
res += '/';
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-09-12 08:08:10 +00:00
|
|
|
std::string cmQtAutoGen::AppendFilenameSuffix(std::string const& filename,
|
|
|
|
std::string const& suffix)
|
|
|
|
{
|
|
|
|
std::string res;
|
|
|
|
auto pos = filename.rfind('.');
|
|
|
|
if (pos != std::string::npos) {
|
|
|
|
const auto it_dot = filename.begin() + pos;
|
|
|
|
res.assign(filename.begin(), it_dot);
|
|
|
|
res.append(suffix);
|
|
|
|
res.append(it_dot, filename.end());
|
|
|
|
} else {
|
|
|
|
res = filename;
|
|
|
|
res.append(suffix);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-08-30 21:13:10 +00:00
|
|
|
void cmQtAutoGen::UicMergeOptions(std::vector<std::string>& baseOpts,
|
2017-09-12 08:08:10 +00:00
|
|
|
std::vector<std::string> const& newOpts,
|
2017-08-30 21:13:10 +00:00
|
|
|
bool isQt5)
|
|
|
|
{
|
2017-09-12 08:08:10 +00:00
|
|
|
static std::vector<std::string> const valueOpts = {
|
2017-08-30 21:13:10 +00:00
|
|
|
"tr", "translate", "postfix", "generator",
|
|
|
|
"include", // Since Qt 5.3
|
|
|
|
"g"
|
|
|
|
};
|
|
|
|
MergeOptions(baseOpts, newOpts, valueOpts, isQt5);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmQtAutoGen::RccMergeOptions(std::vector<std::string>& baseOpts,
|
2017-09-12 08:08:10 +00:00
|
|
|
std::vector<std::string> const& newOpts,
|
2017-08-30 21:13:10 +00:00
|
|
|
bool isQt5)
|
|
|
|
{
|
2017-09-12 08:08:10 +00:00
|
|
|
static std::vector<std::string> const valueOpts = { "name", "root",
|
2017-08-30 21:13:10 +00:00
|
|
|
"compress",
|
|
|
|
"threshold" };
|
|
|
|
MergeOptions(baseOpts, newOpts, valueOpts, isQt5);
|
|
|
|
}
|
|
|
|
|
2018-01-03 15:59:40 +00:00
|
|
|
void cmQtAutoGen::RccListParseContent(std::string const& content,
|
|
|
|
std::vector<std::string>& files)
|
2017-02-28 11:08:26 +00:00
|
|
|
{
|
2018-01-03 15:59:40 +00:00
|
|
|
cmsys::RegularExpression fileMatchRegex("(<file[^<]+)");
|
|
|
|
cmsys::RegularExpression fileReplaceRegex("(^<file[^>]*>)");
|
|
|
|
|
|
|
|
const char* contentChars = content.c_str();
|
|
|
|
while (fileMatchRegex.find(contentChars)) {
|
|
|
|
std::string const qrcEntry = fileMatchRegex.match(1);
|
|
|
|
contentChars += qrcEntry.size();
|
|
|
|
{
|
|
|
|
fileReplaceRegex.find(qrcEntry);
|
|
|
|
std::string const tag = fileReplaceRegex.match(1);
|
|
|
|
files.push_back(qrcEntry.substr(tag.size()));
|
2017-03-02 13:06:02 +00:00
|
|
|
}
|
2018-01-03 15:59:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmQtAutoGen::RccListParseOutput(std::string const& rccStdOut,
|
|
|
|
std::string const& rccStdErr,
|
|
|
|
std::vector<std::string>& files,
|
|
|
|
std::string& error)
|
|
|
|
{
|
|
|
|
// Lambda to strip CR characters
|
|
|
|
auto StripCR = [](std::string& line) {
|
|
|
|
std::string::size_type cr = line.find('\r');
|
|
|
|
if (cr != std::string::npos) {
|
|
|
|
line = line.substr(0, cr);
|
2017-03-02 13:06:02 +00:00
|
|
|
}
|
2018-01-03 15:59:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Parse rcc std output
|
|
|
|
{
|
|
|
|
std::istringstream ostr(rccStdOut);
|
|
|
|
std::string oline;
|
|
|
|
while (std::getline(ostr, oline)) {
|
|
|
|
StripCR(oline);
|
|
|
|
if (!oline.empty()) {
|
|
|
|
files.push_back(oline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Parse rcc error output
|
|
|
|
{
|
|
|
|
std::istringstream estr(rccStdErr);
|
|
|
|
std::string eline;
|
|
|
|
while (std::getline(estr, eline)) {
|
|
|
|
StripCR(eline);
|
|
|
|
if (cmHasLiteralPrefix(eline, "RCC: Error in")) {
|
|
|
|
static std::string const searchString = "Cannot find file '";
|
|
|
|
|
|
|
|
std::string::size_type pos = eline.find(searchString);
|
|
|
|
if (pos == std::string::npos) {
|
|
|
|
error = "rcc lists unparsable output:\n";
|
|
|
|
error += cmQtAutoGen::Quoted(eline);
|
|
|
|
error += "\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
pos += searchString.length();
|
|
|
|
std::string::size_type sz = eline.size() - pos - 1;
|
|
|
|
files.push_back(eline.substr(pos, sz));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmQtAutoGen::RccListConvertFullPath(std::string const& qrcFileDir,
|
|
|
|
std::vector<std::string>& files)
|
|
|
|
{
|
|
|
|
for (std::string& entry : files) {
|
|
|
|
std::string tmp = cmSystemTools::CollapseCombinedPath(qrcFileDir, entry);
|
|
|
|
entry = std::move(tmp);
|
2017-02-28 11:08:26 +00:00
|
|
|
}
|
|
|
|
}
|