QtSupport: Consolidate Qt version macro expander setup a bit

Change-Id: Id8f08d335beb3f6aef682b84f62cd9bdb50dd057
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2023-01-05 12:24:55 +01:00
parent 4e0b4fcc92
commit c022f53b88

View File

@@ -1387,26 +1387,31 @@ QtVersion::createMacroExpander(const std::function<const QtVersion *()> &qtVersi
{ {
const auto versionProperty = const auto versionProperty =
[qtVersion](const std::function<QString(const QtVersion *)> &property) { [qtVersion](const std::function<QString(const QtVersion *)> &property) {
return [property, qtVersion]() -> QString { return [property, qtVersion] {
const QtVersion *version = qtVersion(); const QtVersion *version = qtVersion();
return version ? property(version) : QString(); return version ? property(version) : QString();
}; };
}; };
const auto pathProperty =
[qtVersion](const std::function<FilePath(const QtVersion *)> &property) {
return [property, qtVersion] {
const QtVersion *version = qtVersion();
return version ? property(version).path() : QString();
};
};
std::unique_ptr<MacroExpander> expander(new MacroExpander); std::unique_ptr<MacroExpander> expander(new MacroExpander);
expander->setDisplayName(Tr::tr("Qt version")); expander->setDisplayName(Tr::tr("Qt version"));
expander->registerVariable("Qt:Version", expander->registerVariable(
"Qt:Version",
Tr::tr("The version string of the current Qt version."), Tr::tr("The version string of the current Qt version."),
versionProperty([](const QtVersion *version) { versionProperty(&QtVersion::qtVersionString));
return version->qtVersionString();
}));
expander->registerVariable( expander->registerVariable(
"Qt:Type", "Qt:Type",
Tr::tr("The type of the current Qt version."), Tr::tr("The type of the current Qt version."),
versionProperty([](const QtVersion *version) { versionProperty(&QtVersion::type));
return version->type();
}));
expander->registerVariable( expander->registerVariable(
"Qt:Mkspec", "Qt:Mkspec",
@@ -1415,130 +1420,109 @@ QtVersion::createMacroExpander(const std::function<const QtVersion *()> &qtVersi
return QDir::toNativeSeparators(version->mkspec()); return QDir::toNativeSeparators(version->mkspec());
})); }));
expander->registerVariable("Qt:QT_INSTALL_PREFIX", expander->registerVariable(
"Qt:QT_INSTALL_PREFIX",
Tr::tr("The installation prefix of the current Qt version."), Tr::tr("The installation prefix of the current Qt version."),
versionProperty([](const QtVersion *version) { pathProperty(&QtVersion::prefix));
return version->prefix().path();
}));
expander->registerVariable("Qt:QT_INSTALL_DATA", expander->registerVariable(
Tr::tr( "Qt:QT_INSTALL_DATA",
"The installation location of the current Qt version's data."), Tr::tr("The installation location of the current Qt version's data."),
versionProperty([](const QtVersion *version) { pathProperty(&QtVersion::dataPath));
return version->dataPath().path();
}));
expander->registerVariable("Qt:QT_HOST_PREFIX", expander->registerVariable(
"Qt:QT_HOST_PREFIX",
Tr::tr("The host location of the current Qt version."), Tr::tr("The host location of the current Qt version."),
versionProperty([](const QtVersion *version) { pathProperty(&QtVersion::hostPrefixPath));
return version->hostPrefixPath().path();
}));
expander->registerVariable("Qt:QT_HOST_LIBEXECS", expander->registerVariable("Qt:QT_HOST_LIBEXECS",
Tr::tr("The installation location of the current Qt " Tr::tr("The installation location of the current Qt "
"version's internal host executable files."), "version's internal host executable files."),
versionProperty([](const QtVersion *version) { pathProperty(&QtVersion::hostLibexecPath));
return version->hostLibexecPath().path();
}));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_HEADERS", "Qt:QT_INSTALL_HEADERS",
Tr::tr("The installation location of the current Qt version's header files."), Tr::tr("The installation location of the current Qt version's header files."),
versionProperty( pathProperty(&QtVersion::headerPath));
[](const QtVersion *version) { return version->headerPath().path(); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_LIBS", "Qt:QT_INSTALL_LIBS",
Tr::tr("The installation location of the current Qt version's library files."), Tr::tr("The installation location of the current Qt version's library files."),
versionProperty( pathProperty(&QtVersion::libraryPath));
[](const QtVersion *version) { return version->libraryPath().path(); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_DOCS", "Qt:QT_INSTALL_DOCS",
Tr::tr("The installation location of the current Qt version's documentation files."), Tr::tr("The installation location of the current Qt version's documentation files."),
versionProperty( pathProperty(&QtVersion::docsPath));
[](const QtVersion *version) { return version->docsPath().path(); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_BINS", "Qt:QT_INSTALL_BINS",
Tr::tr("The installation location of the current Qt version's executable files."), Tr::tr("The installation location of the current Qt version's executable files."),
versionProperty([](const QtVersion *version) { return version->binPath().path(); })); pathProperty(&QtVersion::binPath));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_LIBEXECS", "Qt:QT_INSTALL_LIBEXECS",
Tr::tr("The installation location of the current Qt version's internal executable files."), Tr::tr("The installation location of the current Qt version's internal executable files."),
versionProperty( pathProperty(&QtVersion::libExecPath));
[](const QtVersion *version) { return version->libExecPath().path(); }));
expander expander->registerVariable(
->registerVariable("Qt:QT_INSTALL_PLUGINS", "Qt:QT_INSTALL_PLUGINS",
Tr::tr("The installation location of the current Qt version's plugins."), Tr::tr("The installation location of the current Qt version's plugins."),
versionProperty([](const QtVersion *version) { pathProperty(&QtVersion::pluginPath));
return version->pluginPath().path();
}));
expander expander->registerVariable(
->registerVariable("Qt:QT_INSTALL_QML", "Qt:QT_INSTALL_QML",
Tr::tr("The installation location of the current Qt version's QML files."), Tr::tr("The installation location of the current Qt version's QML files."),
versionProperty([](const QtVersion *version) { pathProperty(&QtVersion::qmlPath));
return version->qmlPath().path();
}));
expander expander->registerVariable(
->registerVariable("Qt:QT_INSTALL_IMPORTS", "Qt:QT_INSTALL_IMPORTS",
Tr::tr("The installation location of the current Qt version's imports."), Tr::tr("The installation location of the current Qt version's imports."),
versionProperty([](const QtVersion *version) { pathProperty(&QtVersion::importsPath));
return version->importsPath().path();
}));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_TRANSLATIONS", "Qt:QT_INSTALL_TRANSLATIONS",
Tr::tr("The installation location of the current Qt version's translation files."), Tr::tr("The installation location of the current Qt version's translation files."),
versionProperty( pathProperty(&QtVersion::translationsPath));
[](const QtVersion *version) { return version->translationsPath().path(); }));
expander->registerVariable( expander->registerVariable(
"Qt:QT_INSTALL_CONFIGURATION", "Qt:QT_INSTALL_CONFIGURATION",
Tr::tr("The installation location of the current Qt version's translation files."), Tr::tr("The installation location of the current Qt version's translation files."),
versionProperty( pathProperty(&QtVersion::configurationPath));
[](const QtVersion *version) { return version->configurationPath().path(); }));
expander expander->registerVariable(
->registerVariable("Qt:QT_INSTALL_EXAMPLES", "Qt:QT_INSTALL_EXAMPLES",
Tr::tr( Tr::tr("The installation location of the current Qt version's examples."),
"The installation location of the current Qt version's examples."), pathProperty(&QtVersion::examplesPath));
versionProperty([](const QtVersion *version) {
return version->examplesPath().path();
}));
expander->registerVariable("Qt:QT_INSTALL_DEMOS", expander->registerVariable(
Tr::tr( "Qt:QT_INSTALL_DEMOS",
"The installation location of the current Qt version's demos."), Tr::tr("The installation location of the current Qt version's demos."),
versionProperty([](const QtVersion *version) { pathProperty(&QtVersion::demosPath));
return version->demosPath().path();
}));
expander->registerVariable("Qt:QMAKE_MKSPECS", expander->registerVariable(
"Qt:QMAKE_MKSPECS",
Tr::tr("The current Qt version's default mkspecs (Qt 4)."), Tr::tr("The current Qt version's default mkspecs (Qt 4)."),
versionProperty([](const QtVersion *version) { versionProperty([](const QtVersion *version) {
return version->d->qmakeProperty("QMAKE_MKSPECS"); return version->d->qmakeProperty("QMAKE_MKSPECS");
})); }));
expander->registerVariable("Qt:QMAKE_SPEC", expander->registerVariable(
Tr::tr( "Qt:QMAKE_SPEC",
"The current Qt version's default mkspec (Qt 5; host system)."), Tr::tr("The current Qt version's default mkspec (Qt 5; host system)."),
versionProperty([](const QtVersion *version) { versionProperty([](const QtVersion *version) {
return version->d->qmakeProperty("QMAKE_SPEC"); return version->d->qmakeProperty("QMAKE_SPEC");
})); }));
expander expander->registerVariable(
->registerVariable("Qt:QMAKE_XSPEC", "Qt:QMAKE_XSPEC",
Tr::tr("The current Qt version's default mkspec (Qt 5; target system)."), Tr::tr("The current Qt version's default mkspec (Qt 5; target system)."),
versionProperty([](const QtVersion *version) { versionProperty([](const QtVersion *version) {
return version->d->qmakeProperty("QMAKE_XSPEC"); return version->d->qmakeProperty("QMAKE_XSPEC");
})); }));
expander->registerVariable("Qt:QMAKE_VERSION", expander->registerVariable(
"Qt:QMAKE_VERSION",
Tr::tr("The current Qt's qmake version."), Tr::tr("The current Qt's qmake version."),
versionProperty([](const QtVersion *version) { versionProperty([](const QtVersion *version) {
return version->d->qmakeProperty("QMAKE_VERSION"); return version->d->qmakeProperty("QMAKE_VERSION");
@@ -1547,9 +1531,7 @@ QtVersion::createMacroExpander(const std::function<const QtVersion *()> &qtVersi
// FIXME: Re-enable once we can detect expansion loops. // FIXME: Re-enable once we can detect expansion loops.
// expander->registerVariable("Qt:Name", // expander->registerVariable("Qt:Name",
// Tr::tr("The display name of the current Qt version."), // Tr::tr("The display name of the current Qt version."),
// versionProperty([](QtVersion *version) { // versionProperty(&QtVersion::displayName));
// return version->displayName();
// }));
return expander; return expander;
} }