Change qt.conf key Qml2Imports to QmlImports

[ChangeLog][qt.conf] The key Paths/Qml2Imports has been renamed to
Paths/QmlImports. For backwards-compatibility, Paths/Qml2Imports is
still accepted and acts as default value for when Paths/QmlImports is
not present.

Fixes: QTBUG-98335
Change-Id: If7ffedd281eb8a87e8ab1a2b69a823e615c33541
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
This commit is contained in:
Joerg Bornemann 2021-11-16 13:06:28 +01:00
parent a3303aceeb
commit 04ec14105e
3 changed files with 46 additions and 32 deletions

View File

@ -148,21 +148,14 @@ static QLibraryInfo::LibraryPath hostToTargetPathEnum(int loc)
Q_UNREACHABLE(); Q_UNREACHABLE();
} }
struct LocationInfo static QLibraryInfoPrivate::LocationInfo defaultLocationInfo(int loc)
{ {
QString key; QLibraryInfoPrivate::LocationInfo result;
QString defaultValue;
};
static LocationInfo defaultLocationInfo(int loc)
{
LocationInfo result;
if (loc < QMakeLibraryInfo::FirstHostPath) { if (loc < QMakeLibraryInfo::FirstHostPath) {
QLibraryInfoPrivate::keyAndDefault(static_cast<QLibraryInfo::LibraryPath>(loc), result = QLibraryInfoPrivate::locationInfo(static_cast<QLibraryInfo::LibraryPath>(loc));
&result.key, &result.defaultValue);
} else if (loc <= QMakeLibraryInfo::LastHostPath) { } else if (loc <= QMakeLibraryInfo::LastHostPath) {
QLibraryInfoPrivate::keyAndDefault(hostToTargetPathEnum(loc), &result.key, &result.defaultValue); result = QLibraryInfoPrivate::locationInfo(hostToTargetPathEnum(loc));
result.key.prepend(QStringLiteral("Host")); result.key.prepend(QStringLiteral("Host"));
} else if (loc == QMakeLibraryInfo::SysrootPath) { } else if (loc == QMakeLibraryInfo::SysrootPath) {
result.key = QStringLiteral("Sysroot"); result.key = QStringLiteral("Sysroot");
@ -219,7 +212,7 @@ QString QMakeLibraryInfo::rawLocation(int loc, QMakeLibraryInfo::PathGroup group
|| (group = orig_group, false)) { || (group = orig_group, false)) {
fromConf = true; fromConf = true;
LocationInfo locinfo = defaultLocationInfo(loc); QLibraryInfoPrivate::LocationInfo locinfo = defaultLocationInfo(loc);
if (!locinfo.key.isNull()) { if (!locinfo.key.isNull()) {
QSettings *config = QLibraryInfoPrivate::configuration(); QSettings *config = QLibraryInfoPrivate::configuration();
Q_ASSERT(config != nullptr); Q_ASSERT(config != nullptr);
@ -229,7 +222,15 @@ QString QMakeLibraryInfo::rawLocation(int loc, QMakeLibraryInfo::PathGroup group
: group == EffectivePaths ? "EffectivePaths" : group == EffectivePaths ? "EffectivePaths"
: "Paths")); : "Paths"));
ret = config->value(locinfo.key).toString(); if (locinfo.fallbackKey.isNull()) {
ret = config->value(locinfo.key, locinfo.defaultValue).toString();
} else {
QVariant v = config->value(locinfo.key);
if (!v.isValid())
v = config->value(locinfo.fallbackKey, locinfo.defaultValue);
ret = v.toString();
}
if (ret.isEmpty()) { if (ret.isEmpty()) {
if (loc == HostPrefixPath || loc == TargetSpecPath || loc == HostSpecPath if (loc == HostPrefixPath || loc == TargetSpecPath || loc == HostSpecPath
|| loc == SysrootifyPrefixPath || loc == QLibraryInfo::PrefixPath) { || loc == SysrootifyPrefixPath || loc == QLibraryInfo::PrefixPath) {

View File

@ -490,8 +490,7 @@ static QString getPrefix()
#endif #endif
} }
void QLibraryInfoPrivate::keyAndDefault(QLibraryInfo::LibraryPath loc, QString *key, QLibraryInfoPrivate::LocationInfo QLibraryInfoPrivate::locationInfo(QLibraryInfo::LibraryPath loc)
QString *value)
{ {
/* /*
* To add a new entry in QLibraryInfo::LibraryPath, add it to the enum * To add a new entry in QLibraryInfo::LibraryPath, add it to the enum
@ -512,9 +511,7 @@ void QLibraryInfoPrivate::keyAndDefault(QLibraryInfo::LibraryPath loc, QString *
"Binaries", "bin", "Binaries", "bin",
"Plugins", "plugins", // should be ${ArchData}/plugins "Plugins", "plugins", // should be ${ArchData}/plugins
// TODO: Find a way to rename this to QmlImports "QmlImports", "qml", // should be ${ArchData}/qml
// without breaking compatibility with old qt.conf files.
"Qml2Imports", "qml", // should be ${ArchData}/qml
"ArchData", ".", "ArchData", ".",
"Data", ".", "Data", ".",
@ -526,18 +523,21 @@ void QLibraryInfoPrivate::keyAndDefault(QLibraryInfo::LibraryPath loc, QString *
static_assert(dot.size() == 1); static_assert(dot.size() == 1);
static_assert(dot[0] == '.'); static_assert(dot[0] == '.');
LocationInfo result;
if (int(loc) < qtConfEntries.count()) { if (int(loc) < qtConfEntries.count()) {
*key = QLatin1String(qtConfEntries.viewAt(loc * 2)); result.key = QLatin1String(qtConfEntries.viewAt(loc * 2));
*value = QLatin1String(qtConfEntries.viewAt(loc * 2 + 1)); result.defaultValue = QLatin1String(qtConfEntries.viewAt(loc * 2 + 1));
if (result.key == u"QmlImports")
result.fallbackKey = u"Qml2Imports"_qs;
#ifndef Q_OS_WIN // On Windows we use the registry #ifndef Q_OS_WIN // On Windows we use the registry
} else if (loc == QLibraryInfo::SettingsPath) { } else if (loc == QLibraryInfo::SettingsPath) {
*key = QLatin1String("Settings"); result.key = QLatin1String("Settings");
*value = QLatin1String(dot); result.defaultValue = QLatin1String(dot);
#endif #endif
} else {
key->clear();
value->clear();
} }
return result;
} }
/*! \fn QString QLibraryInfo::location(LibraryLocation loc) /*! \fn QString QLibraryInfo::location(LibraryLocation loc)
@ -559,15 +559,21 @@ QString QLibraryInfo::path(LibraryPath p)
if (havePaths()) { if (havePaths()) {
fromConf = true; fromConf = true;
QString key; auto li = QLibraryInfoPrivate::locationInfo(loc);
QString defaultValue; if (!li.key.isNull()) {
QLibraryInfoPrivate::keyAndDefault(loc, &key, &defaultValue);
if (!key.isNull()) {
QSettings *config = QLibraryInfoPrivate::configuration(); QSettings *config = QLibraryInfoPrivate::configuration();
Q_ASSERT(config != nullptr); Q_ASSERT(config != nullptr);
config->beginGroup(QLatin1String("Paths")); config->beginGroup(QLatin1String("Paths"));
ret = config->value(key, defaultValue).toString(); if (li.fallbackKey.isNull()) {
ret = config->value(li.key, li.defaultValue).toString();
} else {
QVariant v = config->value(li.key);
if (!v.isValid())
v = config->value(li.fallbackKey, li.defaultValue);
ret = v.toString();
}
int startIndex = 0; int startIndex = 0;
forever { forever {
startIndex = ret.indexOf(QLatin1Char('$'), startIndex); startIndex = ret.indexOf(QLatin1Char('$'), startIndex);

View File

@ -69,8 +69,15 @@ public:
static void reload(); static void reload();
static QString qtconfManualPath; static QString qtconfManualPath;
#endif #endif
static void keyAndDefault(QLibraryInfo::LibraryPath loc, QString *key,
QString *value); struct LocationInfo
{
QString key;
QString defaultValue;
QString fallbackKey;
};
static LocationInfo locationInfo(QLibraryInfo::LibraryPath loc);
}; };
QT_END_NAMESPACE QT_END_NAMESPACE