summaryrefslogtreecommitdiffstats
path: root/qmake/generators
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-04-03 17:11:36 +0200
committerLars Knoll <lars.knoll@qt.io>2020-05-05 18:41:27 +0200
commita1947aeffe158a0ea7de3ced1bf8d6a4719a27ef (patch)
treec1b249b7d8bd9b3079df3ad5fe468f7ff4df861b /qmake/generators
parent412dd857b81471277e1014b6329f46a389a42cb3 (diff)
Port qmake over to user QRegularExpression
Use the DotMatchesEverythingOption for all places where we interpret .pro files, to increase compatibility with QRegExp. Change-Id: I347d6b17858069f3c9cedcedd04df58358d83f27 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'qmake/generators')
-rw-r--r--qmake/generators/mac/pbuilder_pbx.cpp15
-rw-r--r--qmake/generators/makefile.cpp42
-rw-r--r--qmake/generators/projectgenerator.cpp4
-rw-r--r--qmake/generators/unix/unixmake2.cpp14
-rw-r--r--qmake/generators/win32/mingw_make.cpp4
-rw-r--r--qmake/generators/win32/msbuild_objectmodel.cpp9
-rw-r--r--qmake/generators/win32/msvc_nmake.cpp8
-rw-r--r--qmake/generators/win32/msvc_objectmodel.cpp4
-rw-r--r--qmake/generators/win32/winmakefile.cpp8
9 files changed, 57 insertions, 51 deletions
diff --git a/qmake/generators/mac/pbuilder_pbx.cpp b/qmake/generators/mac/pbuilder_pbx.cpp
index ec0a044361..c6aab40d85 100644
--- a/qmake/generators/mac/pbuilder_pbx.cpp
+++ b/qmake/generators/mac/pbuilder_pbx.cpp
@@ -30,7 +30,7 @@
#include "option.h"
#include "meta.h"
#include <qdir.h>
-#include <qregexp.h>
+#include <qregularexpression.h>
#include <qcryptographichash.h>
#include <qdebug.h>
#include <qsettings.h>
@@ -1865,11 +1865,12 @@ QString
ProjectBuilderMakefileGenerator::fixForOutput(const QString &values)
{
//get the environment variables references
- QRegExp reg_var("\\$\\((.*)\\)");
- for(int rep = 0; (rep = reg_var.indexIn(values, rep)) != -1;) {
- if(project->values("QMAKE_PBX_VARS").indexOf(reg_var.cap(1)) == -1)
- project->values("QMAKE_PBX_VARS").append(reg_var.cap(1));
- rep += reg_var.matchedLength();
+ QRegularExpression reg_var("\\$\\((.*)\\)");
+ QRegularExpressionMatch match;
+ for (int rep = 0; (match = reg_var.match(values, rep)).hasMatch();) {
+ if (project->values("QMAKE_PBX_VARS").indexOf(match.captured(1)) == -1)
+ project->values("QMAKE_PBX_VARS").append(match.captured(1));
+ rep = match.capturedEnd();
}
return values;
@@ -2019,7 +2020,7 @@ ProjectBuilderMakefileGenerator::writeSettings(const QString &var, const ProStri
for(int i = 0; i < indent_level; ++i)
newline += "\t";
- static QRegExp allowedVariableCharacters("^[a-zA-Z0-9_]*$");
+ static QRegularExpression allowedVariableCharacters("^[a-zA-Z0-9_]*$");
ret += var.contains(allowedVariableCharacters) ? var : quotedStringLiteral(var);
ret += " = ";
diff --git a/qmake/generators/makefile.cpp b/qmake/generators/makefile.cpp
index 9d2d240bc2..3ccd53f0a2 100644
--- a/qmake/generators/makefile.cpp
+++ b/qmake/generators/makefile.cpp
@@ -36,7 +36,7 @@
#include <qdir.h>
#include <qfile.h>
#include <qtextstream.h>
-#include <qregexp.h>
+#include <qregularexpression.h>
#include <qhash.h>
#include <qdebug.h>
#include <qbuffer.h>
@@ -1575,11 +1575,12 @@ MakefileGenerator::replaceExtraCompilerVariables(
//do the work
QString ret = orig_var;
- QRegExp reg_var("\\$\\{.*\\}");
- reg_var.setMinimal(true);
- for(int rep = 0; (rep = reg_var.indexIn(ret, rep)) != -1; ) {
+ QRegularExpression reg_var("\\$\\{.*\\}", QRegularExpression::InvertedGreedinessOption);
+ QRegularExpressionMatch match;
+ for (int rep = 0; (match = reg_var.match(ret, rep)).hasMatch(); ) {
+ rep = match.capturedStart();
QStringList val;
- const ProString var(ret.mid(rep + 2, reg_var.matchedLength() - 3));
+ const ProString var(ret.mid(rep + 2, match.capturedLength() - 3));
bool filePath = false;
if(val.isEmpty() && var.startsWith(QLatin1String("QMAKE_VAR_"))) {
const ProKey varname = var.mid(10).toKey();
@@ -1675,10 +1676,10 @@ MakefileGenerator::replaceExtraCompilerVariables(
} else {
fullVal = val.join(' ');
}
- ret.replace(rep, reg_var.matchedLength(), fullVal);
- rep += fullVal.length();
+ ret.replace(match.capturedStart(), match.capturedLength(), fullVal);
+ rep = match.capturedStart(), fullVal.length();
} else {
- rep += reg_var.matchedLength();
+ rep = match.capturedEnd();
}
}
@@ -2018,7 +2019,7 @@ MakefileGenerator::writeExtraCompilerTargets(QTextStream &t)
const bool existingDepsOnly = config.contains("dep_existing_only");
QStringList tmp_dep = project->values(ProKey(*it + ".depends")).toQStringList();
if (config.indexOf("combine") != -1) {
- if (tmp_out.contains(QRegExp("(^|[^$])\\$\\{QMAKE_(?!VAR_)"))) {
+ if (tmp_out.contains(QRegularExpression("(^|[^$])\\$\\{QMAKE_(?!VAR_)"))) {
warn_msg(WarnLogic, "QMAKE_EXTRA_COMPILERS(%s) with combine has variable output.",
(*it).toLatin1().constData());
continue;
@@ -2167,9 +2168,10 @@ MakefileGenerator::writeExtraVariables(QTextStream &t)
const ProValueMap &vars = project->variables();
const ProStringList &exports = project->values("QMAKE_EXTRA_VARIABLES");
for (ProStringList::ConstIterator exp_it = exports.begin(); exp_it != exports.end(); ++exp_it) {
- QRegExp rx((*exp_it).toQString(), Qt::CaseInsensitive, QRegExp::Wildcard);
+ auto pattern = QRegularExpression::wildcardToRegularExpression((*exp_it).toQString());
+ QRegularExpression rx(pattern, QRegularExpression::CaseInsensitiveOption);
for (ProValueMap::ConstIterator it = vars.begin(); it != vars.end(); ++it) {
- if (rx.exactMatch(it.key().toQString()))
+ if (rx.match(it.key().toQString()).hasMatch())
outlist << ("EXPORT_" + it.key() + " = " + it.value().join(' '));
}
}
@@ -2314,7 +2316,7 @@ MakefileGenerator::findSubDirsSubTargets() const
ProString ofile = subdirs[subdir];
QString oname = ofile.toQString();
QString fixedSubdir = oname;
- fixedSubdir.replace(QRegExp("[^a-zA-Z0-9_]"),"-");
+ fixedSubdir.replace(QRegularExpression("[^a-zA-Z0-9_]"),"-");
SubTarget *st = new SubTarget;
st->name = oname;
@@ -2386,7 +2388,7 @@ MakefileGenerator::findSubDirsSubTargets() const
if(subdirs[subDep] == depends.at(depend)) {
QString subName = subdirs[subDep].toQString();
QString fixedSubDep = subName;
- fixedSubDep.replace(QRegExp("[^a-zA-Z0-9_]"),"-");
+ fixedSubDep.replace(QRegularExpression("[^a-zA-Z0-9_]"),"-");
const ProKey dtkey(fixedSubDep + ".target");
if (!project->isEmpty(dtkey)) {
st->depends += project->first(dtkey);
@@ -2400,7 +2402,7 @@ MakefileGenerator::findSubDirsSubTargets() const
if (!project->isEmpty(dskey))
d = project->first(dskey).toQString();
}
- st->depends += "sub-" + d.replace(QRegExp("[^a-zA-Z0-9_]"),"-");
+ st->depends += "sub-" + d.replace(QRegularExpression("[^a-zA-Z0-9_]"),"-");
}
found = true;
break;
@@ -2408,7 +2410,7 @@ MakefileGenerator::findSubDirsSubTargets() const
}
if(!found) {
QString depend_str = depends.at(depend).toQString();
- st->depends += depend_str.replace(QRegExp("[^a-zA-Z0-9_]"),"-");
+ st->depends += depend_str.replace(QRegularExpression("[^a-zA-Z0-9_]"),"-");
}
}
}
@@ -2417,7 +2419,7 @@ MakefileGenerator::findSubDirsSubTargets() const
st->target = project->first(tkey).toQString();
} else {
st->target = "sub-" + file;
- st->target.replace(QRegExp("[^a-zA-Z0-9_]"), "-");
+ st->target.replace(QRegularExpression("[^a-zA-Z0-9_]"), "-");
}
}
}
@@ -2882,12 +2884,12 @@ MakefileGenerator::escapeDependencyPath(const QString &path) const
#ifdef Q_OS_UNIX
// When running on Unix, we need to escape colons (which may appear
// anywhere in a path, and would be mis-parsed as dependency separators).
- static const QRegExp criticalChars(QStringLiteral("([\t :#])"));
+ static const QRegularExpression criticalChars(QStringLiteral("([\t :#])"));
#else
// MinGW make has a hack for colons which denote drive letters, and no
// other colons may appear in paths. And escaping colons actually breaks
// the make from the Android SDK.
- static const QRegExp criticalChars(QStringLiteral("([\t #])"));
+ static const QRegularExpression criticalChars(QStringLiteral("([\t #])"));
#endif
ret.replace(criticalChars, QStringLiteral("\\\\1"));
ret.replace(QLatin1Char('='), QStringLiteral("$(EQ)"));
@@ -3070,8 +3072,8 @@ MakefileGenerator::findFileForDep(const QMakeLocalFileName &dep, const QMakeLoca
const ProStringList &nodeplist = project->values("SKIP_DEPENDS");
for (ProStringList::ConstIterator it = nodeplist.begin();
it != nodeplist.end(); ++it) {
- QRegExp regx((*it).toQString());
- if(regx.indexIn(dep.local()) != -1) {
+ QRegularExpression regx((*it).toQString());
+ if (regx.match(dep.local()).hasMatch()) {
found = true;
break;
}
diff --git a/qmake/generators/projectgenerator.cpp b/qmake/generators/projectgenerator.cpp
index 613c97fb85..ac6793cbf3 100644
--- a/qmake/generators/projectgenerator.cpp
+++ b/qmake/generators/projectgenerator.cpp
@@ -32,7 +32,7 @@
#include <qdir.h>
#include <qfile.h>
#include <qfileinfo.h>
-#include <qregexp.h>
+#include <qregularexpression.h>
QT_BEGIN_NAMESPACE
@@ -245,7 +245,7 @@ ProjectGenerator::init()
v["INCLUDEPATH"] += inc.real();
}
}
- if(no_qt_files && file_no_path.indexOf(QRegExp("^q[a-z_0-9].h$")) != -1)
+ if (no_qt_files && file_no_path.contains(QRegularExpression("^q[a-z_0-9].h$")))
no_qt_files = false;
QString h_ext;
for(int hit = 0; hit < Option::h_ext.size(); ++hit) {
diff --git a/qmake/generators/unix/unixmake2.cpp b/qmake/generators/unix/unixmake2.cpp
index 19975bc8bb..09af15130f 100644
--- a/qmake/generators/unix/unixmake2.cpp
+++ b/qmake/generators/unix/unixmake2.cpp
@@ -30,7 +30,7 @@
#include "unixmake.h"
#include "option.h"
#include "meta.h"
-#include <qregexp.h>
+#include <qregularexpression.h>
#include <qbytearray.h>
#include <qfile.h>
#include <qdir.h>
@@ -290,7 +290,7 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
if (project->isActiveConfig("gcc_MD_depends")) {
ProStringList objects = project->values("OBJECTS");
for (ProStringList::Iterator it = objects.begin(); it != objects.end(); ++it) {
- QString d_file = (*it).toQString().replace(QRegExp(Option::obj_ext + "$"), ".d");
+ QString d_file = (*it).toQString().replace(QRegularExpression(Option::obj_ext + "$"), ".d");
t << "-include " << escapeDependencyPath(d_file) << Qt::endl;
project->values("QMAKE_DISTCLEAN") << d_file;
}
@@ -346,7 +346,7 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
if(!d_file.isEmpty()) {
d_file = odir + ".deps/" + fileFixify(d_file, FileFixifyBackwards) + ".d";
QString d_file_d = escapeDependencyPath(d_file);
- QStringList deps = findDependencies((*it).toQString()).filter(QRegExp(
+ QStringList deps = findDependencies((*it).toQString()).filter(QRegularExpression(
"((^|/)" + Option::h_moc_mod + "|" + Option::cpp_moc_ext + "$)"));
if(!deps.isEmpty())
t << d_file_d << ": " << finalizeDependencyPaths(deps).join(' ') << Qt::endl;
@@ -507,7 +507,7 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
if(do_incremental) {
ProString s_ext = project->first("QMAKE_EXTENSION_SHLIB");
QString incr_target = var("QMAKE_ORIG_TARGET").replace(
- QRegExp("\\." + s_ext), "").replace(QRegExp("^lib"), "") + "_incremental";
+ QRegularExpression("\\." + s_ext), "").replace(QRegularExpression("^lib"), "") + "_incremental";
if(incr_target.indexOf(Option::dir_sep) != -1)
incr_target = incr_target.right(incr_target.length() -
(incr_target.lastIndexOf(Option::dir_sep) + 1));
@@ -1533,8 +1533,10 @@ std::pair<bool, QString> UnixMakefileGenerator::writeObjectsPart(QTextStream &t,
for (ProStringList::ConstIterator objit = objs.begin(); objit != objs.end(); ++objit) {
bool increment = false;
for (ProStringList::ConstIterator incrit = incrs.begin(); incrit != incrs.end(); ++incrit) {
- if ((*objit).toQString().indexOf(QRegExp((*incrit).toQString(), Qt::CaseSensitive,
- QRegExp::Wildcard)) != -1) {
+ auto pattern =
+ QRegularExpression::wildcardToRegularExpression((*incrit).toQString(),
+ QRegularExpression::UnanchoredWildcardConversion);
+ if ((*objit).toQString().contains(QRegularExpression(pattern))) {
increment = true;
incrs_out.append((*objit));
break;
diff --git a/qmake/generators/win32/mingw_make.cpp b/qmake/generators/win32/mingw_make.cpp
index 096b041056..7a717a80a9 100644
--- a/qmake/generators/win32/mingw_make.cpp
+++ b/qmake/generators/win32/mingw_make.cpp
@@ -31,7 +31,7 @@
#include <proitems.h>
-#include <qregexp.h>
+#include <qregularexpression.h>
#include <qdir.h>
#include <stdlib.h>
#include <time.h>
@@ -209,7 +209,7 @@ void MingwMakefileGenerator::writeIncPart(QTextStream &t)
const ProStringList &incs = project->values("INCLUDEPATH");
for (ProStringList::ConstIterator incit = incs.begin(); incit != incs.end(); ++incit) {
QString inc = (*incit).toQString();
- inc.replace(QRegExp("\\\\$"), "");
+ inc.replace(QRegularExpression("\\\\$"), "");
if (!isystem.isEmpty() && isSystemInclude(inc))
t << isystem << ' ';
diff --git a/qmake/generators/win32/msbuild_objectmodel.cpp b/qmake/generators/win32/msbuild_objectmodel.cpp
index 355260c974..82c0983272 100644
--- a/qmake/generators/win32/msbuild_objectmodel.cpp
+++ b/qmake/generators/win32/msbuild_objectmodel.cpp
@@ -34,7 +34,7 @@
#include <qscopedpointer.h>
#include <qstringlist.h>
#include <qfileinfo.h>
-#include <qregexp.h>
+#include <qregularexpression.h>
QT_BEGIN_NAMESPACE
@@ -834,12 +834,13 @@ void VCXProjectWriter::write(XmlOutput &xml, VCProject &tool)
QFile manifestFile(Option::output_dir + QLatin1Char('/') + manifest);
if (manifestFile.open(QFile::ReadOnly)) {
const QString contents = manifestFile.readAll();
- QRegExp regexp("[\\\\/a-zA-Z0-9_\\-\\!]*\\.(png|jpg|jpeg)");
+ QRegularExpression regexp("[\\\\/a-zA-Z0-9_\\-\\!]*\\.(png|jpg|jpeg)");
int pos = 0;
while (pos > -1) {
- pos = regexp.indexIn(contents, pos);
+ QRegularExpressionMatch m;
+ pos = contents.indexOf(regexp, pos, &m);
if (pos >= 0) {
- const QString match = regexp.cap(0);
+ const QString match = m.captured(0);
icons.insert(match);
pos += match.length();
}
diff --git a/qmake/generators/win32/msvc_nmake.cpp b/qmake/generators/win32/msvc_nmake.cpp
index 73e84a3269..cf58ead2e9 100644
--- a/qmake/generators/win32/msvc_nmake.cpp
+++ b/qmake/generators/win32/msvc_nmake.cpp
@@ -29,7 +29,7 @@
#include "msvc_nmake.h"
#include "option.h"
-#include <qregexp.h>
+#include <qregularexpression.h>
#include <qdir.h>
#include <qdiriterator.h>
#include <qset.h>
@@ -370,12 +370,12 @@ void NmakeMakefileGenerator::writeImplicitRulesPart(QTextStream &t)
for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
t << '{' << escapeDependencyPath(sourceDir) << '}' << (*cppit)
<< '{' << escapeDependencyPath(objDir) << '}' << Option::obj_ext << "::\n\t"
- << var("QMAKE_RUN_CXX_IMP_BATCH").replace(QRegExp("\\$@"), fileVar("OBJECTS_DIR"))
+ << var("QMAKE_RUN_CXX_IMP_BATCH").replace(QRegularExpression("\\$@"), fileVar("OBJECTS_DIR"))
<< "\n\t$<\n<<\n\n";
for(QStringList::Iterator cit = Option::c_ext.begin(); cit != Option::c_ext.end(); ++cit)
t << '{' << escapeDependencyPath(sourceDir) << '}' << (*cit)
<< '{' << escapeDependencyPath(objDir) << '}' << Option::obj_ext << "::\n\t"
- << var("QMAKE_RUN_CC_IMP_BATCH").replace(QRegExp("\\$@"), fileVar("OBJECTS_DIR"))
+ << var("QMAKE_RUN_CC_IMP_BATCH").replace(QRegularExpression("\\$@"), fileVar("OBJECTS_DIR"))
<< "\n\t$<\n<<\n\n";
}
} else {
@@ -434,7 +434,7 @@ void NmakeMakefileGenerator::writeBuildRulesPart(QTextStream &t)
}
const QString resourceId = (templateName == "app") ? "1" : "2";
- const bool incrementalLinking = project->values("QMAKE_LFLAGS").toQStringList().filter(QRegExp("(/|-)INCREMENTAL:NO")).isEmpty();
+ const bool incrementalLinking = project->values("QMAKE_LFLAGS").toQStringList().filter(QRegularExpression("(/|-)INCREMENTAL:NO")).isEmpty();
if (incrementalLinking && !linkerSupportsEmbedding) {
// Link a resource that contains the manifest without modifying the exe/dll after linking.
diff --git a/qmake/generators/win32/msvc_objectmodel.cpp b/qmake/generators/win32/msvc_objectmodel.cpp
index 3002ce889c..9e93fe51f3 100644
--- a/qmake/generators/win32/msvc_objectmodel.cpp
+++ b/qmake/generators/win32/msvc_objectmodel.cpp
@@ -34,7 +34,7 @@
#include <qscopedpointer.h>
#include <qfileinfo.h>
-#include <qregexp.h>
+#include <qregularexpression.h>
using namespace QMakeInternal;
@@ -321,7 +321,7 @@ triState operator!(const triState &rhs)
QStringList VCToolBase::fixCommandLine(const QString &input)
{
// The splitting regexp is a bit bizarre for backwards compat reasons (why else ...).
- return input.split(QRegExp(QLatin1String("(\n\t|\r\\\\h|\r\n)\\s*")));
+ return input.split(QRegularExpression(QLatin1String("(\n\t|\r\\\\h|\r\n)\\s*")));
}
static QString vcCommandSeparator()
diff --git a/qmake/generators/win32/winmakefile.cpp b/qmake/generators/win32/winmakefile.cpp
index 112ad1f739..57f02c13d0 100644
--- a/qmake/generators/win32/winmakefile.cpp
+++ b/qmake/generators/win32/winmakefile.cpp
@@ -33,7 +33,7 @@
#include <qtextstream.h>
#include <qstring.h>
#include <qhash.h>
-#include <qregexp.h>
+#include <qregularexpression.h>
#include <qstringlist.h>
#include <qdir.h>
#include <stdlib.h>
@@ -561,7 +561,7 @@ void Win32MakefileGenerator::writeIncPart(QTextStream &t)
const ProStringList &incs = project->values("INCLUDEPATH");
for(int i = 0; i < incs.size(); ++i) {
QString inc = incs.at(i).toQString();
- inc.replace(QRegExp("\\\\$"), "");
+ inc.replace(QRegularExpression("\\\\$"), "");
if(!inc.isEmpty())
t << "-I" << escapeFilePath(inc) << ' ';
}
@@ -588,7 +588,7 @@ void Win32MakefileGenerator::writeStandardParts(QTextStream &t)
t << "####### Output directory\n\n";
if(!project->values("OBJECTS_DIR").isEmpty())
- t << "OBJECTS_DIR = " << escapeFilePath(var("OBJECTS_DIR").remove(QRegExp("\\\\$"))) << Qt::endl;
+ t << "OBJECTS_DIR = " << escapeFilePath(var("OBJECTS_DIR").remove(QRegularExpression("\\\\$"))) << Qt::endl;
else
t << "OBJECTS_DIR = . \n";
t << Qt::endl;
@@ -860,7 +860,7 @@ QString Win32MakefileGenerator::escapeDependencyPath(const QString &path) const
{
QString ret = path;
if (!ret.isEmpty()) {
- static const QRegExp criticalChars(QStringLiteral("([\t #])"));
+ static const QRegularExpression criticalChars(QStringLiteral("([\t #])"));
if (ret.contains(criticalChars))
ret = "\"" + ret + "\"";
debug_msg(2, "EscapeDependencyPath: %s -> %s", path.toLatin1().constData(), ret.toLatin1().constData());