Minor refactor of installMetaFile

Move some lines into createSedArgs. This is used
in follow up patch.

Pick-to: 5.15
Task-number: QTBUG-87154
Change-Id: I226f4aad4aaf703a4726c42b40afb4bde3a9d878
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Michal Klocek 2020-09-18 09:06:01 +02:00
parent f9058a7534
commit 9bade12c2c
2 changed files with 27 additions and 20 deletions

View File

@ -3413,35 +3413,41 @@ static QString windowsifyPath(const QString &str)
return QString(str).replace('/', QLatin1String("\\\\\\\\")); return QString(str).replace('/', QLatin1String("\\\\\\\\"));
} }
QString MakefileGenerator::installMetaFile(const ProKey &replace_rule, const QString &src, const QString &dst) QString MakefileGenerator::createSedArgs(const ProKey &replace_rule) const
{ {
QString ret; QString sedargs;
if (project->isEmpty(replace_rule) if (!project->isEmpty(replace_rule) && !project->isActiveConfig("no_sed_meta_install")) {
|| project->isActiveConfig("no_sed_meta_install")) {
ret += "$(INSTALL_FILE) " + escapeFilePath(src) + ' ' + escapeFilePath(dst);
} else {
QString sedargs;
const ProStringList &replace_rules = project->values(replace_rule); const ProStringList &replace_rules = project->values(replace_rule);
for (int r = 0; r < replace_rules.size(); ++r) { for (int r = 0; r < replace_rules.size(); ++r) {
const ProString match = project->first(ProKey(replace_rules.at(r) + ".match")), const ProString match = project->first(ProKey(replace_rules.at(r) + ".match")),
replace = project->first(ProKey(replace_rules.at(r) + ".replace")); replace = project->first(ProKey(replace_rules.at(r) + ".replace"));
if (!match.isEmpty() /*&& match != replace*/) { if (!match.isEmpty() /*&& match != replace*/) {
sedargs += " -e " + shellQuote("s," + match + "," + replace + ",g"); sedargs += " -e " + shellQuote("s," + match + "," + replace + ",g");
if (isWindowsShell() && project->first(ProKey(replace_rules.at(r) + ".CONFIG")).contains("path")) if (isWindowsShell()
sedargs += " -e " + shellQuote("s," + windowsifyPath(match.toQString()) && project->first(ProKey(replace_rules.at(r) + ".CONFIG")).contains("path"))
+ "," + windowsifyPath(replace.toQString()) + ",gi"); sedargs += " -e "
+ shellQuote("s," + windowsifyPath(match.toQString()) + ","
+ windowsifyPath(replace.toQString()) + ",gi");
} }
} }
if (sedargs.isEmpty()) { }
ret += "$(INSTALL_FILE) " + escapeFilePath(src) + ' ' + escapeFilePath(dst); return sedargs;
} else { }
ret += "$(SED) " + sedargs + ' ' + escapeFilePath(src) + " > " + escapeFilePath(dst);
} QString MakefileGenerator::installMetaFile(const ProKey &replace_rule, const QString &src,
const QString &dst) const
{
QString ret;
QString sedargs = createSedArgs(replace_rule);
if (sedargs.isEmpty()) {
ret = "$(INSTALL_FILE) " + escapeFilePath(src) + ' ' + escapeFilePath(dst);
} else {
ret = "$(SED) " + sedargs + ' ' + escapeFilePath(src) + " > " + escapeFilePath(dst);
} }
return ret; return ret;
} }
QString MakefileGenerator::shellQuote(const QString &str) QString MakefileGenerator::shellQuote(const QString &str) const
{ {
return isWindowsShell() ? IoUtils::shellQuoteWin(str) : IoUtils::shellQuoteUnix(str); return isWindowsShell() ? IoUtils::shellQuoteWin(str) : IoUtils::shellQuoteUnix(str);
} }

View File

@ -258,8 +258,9 @@ public:
protected: protected:
QString fileFixify(const QString &file, FileFixifyTypes fix = FileFixifyDefault, bool canon = true) const; QString fileFixify(const QString &file, FileFixifyTypes fix = FileFixifyDefault, bool canon = true) const;
QStringList fileFixify(const QStringList &files, FileFixifyTypes fix = FileFixifyDefault, bool canon = true) const; QStringList fileFixify(const QStringList &files, FileFixifyTypes fix = FileFixifyDefault, bool canon = true) const;
QString createSedArgs(const ProKey &replace_rule) const;
QString installMetaFile(const ProKey &replace_rule, const QString &src, const QString &dst); QString installMetaFile(const ProKey &replace_rule, const QString &src,
const QString &dst) const;
virtual bool processPrlFileBase(QString &origFile, QStringView origName, virtual bool processPrlFileBase(QString &origFile, QStringView origName,
QStringView fixedBase, int slashOff); QStringView fixedBase, int slashOff);
@ -287,7 +288,7 @@ public:
virtual bool mergeBuildProject(MakefileGenerator * /*other*/) { return false; } virtual bool mergeBuildProject(MakefileGenerator * /*other*/) { return false; }
virtual bool openOutput(QFile &, const QString &build) const; virtual bool openOutput(QFile &, const QString &build) const;
bool isWindowsShell() const { return Option::dir_sep == QLatin1String("\\"); } bool isWindowsShell() const { return Option::dir_sep == QLatin1String("\\"); }
QString shellQuote(const QString &str); QString shellQuote(const QString &str) const;
virtual ProKey fullTargetVariable() const; virtual ProKey fullTargetVariable() const;
}; };
Q_DECLARE_TYPEINFO(MakefileGenerator::Compiler, Q_MOVABLE_TYPE); Q_DECLARE_TYPEINFO(MakefileGenerator::Compiler, Q_MOVABLE_TYPE);