forked from qt-creator/qt-creator
de-duplicate qmake property parsing code
Change-Id: I7555de5c72a9250b31e20fc60e39680d19882fcb Reviewed-by: Tobias Hunger <tobias.hunger@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -1447,33 +1447,8 @@ bool BaseQtVersion::queryQMakeVariables(const FileName &binary, const Environmen
|
|||||||
if (output.isNull())
|
if (output.isNull())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QTextStream stream(&output);
|
QMakeGlobals::parseProperties(output, *versionInfo);
|
||||||
while (!stream.atEnd()) {
|
|
||||||
const QString line = stream.readLine();
|
|
||||||
const int index = line.indexOf(QLatin1Char(':'));
|
|
||||||
if (index != -1) {
|
|
||||||
QString name = line.left(index);
|
|
||||||
ProString value(QDir::fromNativeSeparators(line.mid(index+1)));
|
|
||||||
if (value.isNull())
|
|
||||||
value = ProString(""); // Make sure it is not null, to discern from missing keys
|
|
||||||
versionInfo->insert(ProKey(name), value);
|
|
||||||
if (name.startsWith(QLatin1String("QT_")) && !name.contains(QLatin1Char('/'))) {
|
|
||||||
if (name.startsWith(QLatin1String("QT_INSTALL_"))) {
|
|
||||||
versionInfo->insert(ProKey(name + QLatin1String("/raw")), value);
|
|
||||||
versionInfo->insert(ProKey(name + QLatin1String("/get")), value);
|
|
||||||
if (name == QLatin1String("QT_INSTALL_PREFIX")
|
|
||||||
|| name == QLatin1String("QT_INSTALL_DATA")
|
|
||||||
|| name == QLatin1String("QT_INSTALL_BINS")) {
|
|
||||||
name.replace(3, 7, QLatin1String("HOST"));
|
|
||||||
versionInfo->insert(ProKey(name), value);
|
|
||||||
versionInfo->insert(ProKey(name + QLatin1String("/get")), value);
|
|
||||||
}
|
|
||||||
} else if (name.startsWith(QLatin1String("QT_HOST_"))) {
|
|
||||||
versionInfo->insert(ProKey(name + QLatin1String("/get")), value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -324,6 +324,13 @@ bool QMakeGlobals::initProperties()
|
|||||||
QT_PCLOSE(proc);
|
QT_PCLOSE(proc);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
parseProperties(data, properties);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void QMakeGlobals::parseProperties(const QByteArray &data, QHash<ProKey, ProString> &properties)
|
||||||
|
{
|
||||||
const auto lines = data.split('\n');
|
const auto lines = data.split('\n');
|
||||||
for (QByteArray line : lines) {
|
for (QByteArray line : lines) {
|
||||||
int off = line.indexOf(':');
|
int off = line.indexOf(':');
|
||||||
@@ -334,6 +341,8 @@ bool QMakeGlobals::initProperties()
|
|||||||
QString name = QString::fromLatin1(line.left(off));
|
QString name = QString::fromLatin1(line.left(off));
|
||||||
ProString value = ProString(QDir::fromNativeSeparators(
|
ProString value = ProString(QDir::fromNativeSeparators(
|
||||||
QString::fromLocal8Bit(line.mid(off + 1))));
|
QString::fromLocal8Bit(line.mid(off + 1))));
|
||||||
|
if (value.isNull())
|
||||||
|
value = ProString(""); // Make sure it is not null, to discern from missing keys
|
||||||
properties.insert(ProKey(name), value);
|
properties.insert(ProKey(name), value);
|
||||||
if (name.startsWith(QLatin1String("QT_"))) {
|
if (name.startsWith(QLatin1String("QT_"))) {
|
||||||
bool plain = !name.contains(QLatin1Char('/'));
|
bool plain = !name.contains(QLatin1Char('/'));
|
||||||
@@ -365,9 +374,7 @@ bool QMakeGlobals::initProperties()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#endif // QT_BUILD_QMAKE
|
#endif // QT_BUILD_QMAKE
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ public:
|
|||||||
void setQMakeProperty(QMakeProperty *prop) { property = prop; }
|
void setQMakeProperty(QMakeProperty *prop) { property = prop; }
|
||||||
ProString propertyValue(const ProKey &name) const { return property->value(name); }
|
ProString propertyValue(const ProKey &name) const { return property->value(name); }
|
||||||
#else
|
#else
|
||||||
|
static void parseProperties(const QByteArray &data, QHash<ProKey, ProString> &props);
|
||||||
# ifdef PROEVALUATOR_INIT_PROPS
|
# ifdef PROEVALUATOR_INIT_PROPS
|
||||||
bool initProperties();
|
bool initProperties();
|
||||||
# else
|
# else
|
||||||
|
|||||||
Reference in New Issue
Block a user