ProjectExplorer: Clean up variables

Global variables with names such as "CurrentProject*", "CurrentKit*" etc
are harmful, because the term "current project" as used in Qt Creator
does not refer to the "active project", but simply stands for the
project that contains the node that is currently selected in the project
tree, which in turn may or may not correspond to the current editor
document, depending on the "sync with editor" setting. In other words,
the "current project" is almost a random value with little meaning
outside the project tree itself.
Therefore, we remove "CurrentProject*" and friends, except the ones that
are currently intentionally in use. The latter get renamed to
"CurrentDocument:Project*", so their purpose becomes clear. Their old
names are kept around for backward compatibility, but are not suggested
by the variable chooser anymore, so new usages are unlikely and we can
remove them at some point.
We also add some ActiveProject* variants that have been requested in the
past.
Also remove the "CurrentSession" prefix that was deprecated six years
ago.

Fixes: QTCREATORBUG-12724
Fixes: QTCREATORBUG-24606
Change-Id: Ibba5d0e0ce3d2beb444a5eec01fbb9b745d90a1d
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Kandeler
2020-09-28 16:18:44 +02:00
parent da8db0f24d
commit b55825a420
19 changed files with 190 additions and 205 deletions

View File

@@ -230,8 +230,9 @@
%{variable} %{variable}
\endcode \endcode
For example, the following variable expands to the name of the current For example, the following variable expands to the name of the
project: \c {%{CurrentProject:Name}}. project containing the file that is currently open in the editor:
\c {%{CurrentDocument:Project:Name}}.
Use unique variable names within a snippet, because all instances of a Use unique variable names within a snippet, because all instances of a
variable are renamed when you specify a value for it. variable are renamed when you specify a value for it.

View File

@@ -59,8 +59,8 @@ public:
<snippet group="C++" trigger="lic" id="license-configured" complement="" removed="false" modified="false">%{Cpp:LicenseTemplate} <snippet group="C++" trigger="lic" id="license-configured" complement="" removed="false" modified="false">%{Cpp:LicenseTemplate}
$$</snippet> $$</snippet>
<snippet group="C++" trigger="licbsd" id="license-bsd" complement="" removed="false" modified="false">/** <snippet group="C++" trigger="licbsd" id="license-bsd" complement="" removed="false" modified="false">/**
@if ('%{CurrentProject:Name}' !== '') @if ('%{CurrentDocument:Project:Name}' !== '')
** This file is part of the %{CurrentProject:Name} project. ** This file is part of the %{CurrentDocument:Project:Name} project.
@endif @endif
@if ('%{Env:QTC_COPYRIGHT_USER}' === '' || '%{Env:QTC_COPYRIGHT_EMAIL}' === '') @if ('%{Env:QTC_COPYRIGHT_USER}' === '' || '%{Env:QTC_COPYRIGHT_EMAIL}' === '')
** Copyright %{CurrentDate:yyyy} $copyright_user$ &lt;$copyright_email$&gt;. ** Copyright %{CurrentDate:yyyy} $copyright_user$ &lt;$copyright_email$&gt;.
@@ -95,8 +95,8 @@ $$</snippet>
$$</snippet> $$</snippet>
<snippet group="C++" trigger="licgpl" id="license-gpl" complement="" removed="false" modified="false">/** <snippet group="C++" trigger="licgpl" id="license-gpl" complement="" removed="false" modified="false">/**
@if ('%{CurrentProject:Name}' !== '') @if ('%{CurrentDocument:Project:Name}' !== '')
** This file is part of the %{CurrentProject:Name} project. ** This file is part of the %{CurrentDocument:Project:Name} project.
@endif @endif
@if ('%{Env:QTC_COPYRIGHT_USER}' === '' || '%{Env:QTC_COPYRIGHT_EMAIL}' === '') @if ('%{Env:QTC_COPYRIGHT_USER}' === '' || '%{Env:QTC_COPYRIGHT_EMAIL}' === '')
** Copyright %{CurrentDate:yyyy} $copyright_user$ &lt;$copyright_email$&gt;. ** Copyright %{CurrentDate:yyyy} $copyright_user$ &lt;$copyright_email$&gt;.
@@ -120,8 +120,8 @@ $$</snippet>
$$</snippet> $$</snippet>
<snippet group="C++" trigger="liclgpl" id="license-lgpl" complement="" removed="false" modified="false">/** <snippet group="C++" trigger="liclgpl" id="license-lgpl" complement="" removed="false" modified="false">/**
@if ('%{CurrentProject:Name}' !== '') @if ('%{CurrentDocument:Project:Name}' !== '')
** This file is part of the %{CurrentProject:Name} project. ** This file is part of the %{CurrentDocument:Project:Name} project.
@endif @endif
@if ('%{Env:QTC_COPYRIGHT_USER}' === '' || '%{Env:QTC_COPYRIGHT_EMAIL}' === '') @if ('%{Env:QTC_COPYRIGHT_USER}' === '' || '%{Env:QTC_COPYRIGHT_EMAIL}' === '')
** Copyright %{CurrentDate:yyyy} $copyright_user$ &lt;$copyright_email$&gt;. ** Copyright %{CurrentDate:yyyy} $copyright_user$ &lt;$copyright_email$&gt;.
@@ -153,7 +153,7 @@ $$</snippet>
@endif @endif
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of %{CurrentProject:Name} ** This file is part of %{CurrentDocument:Project:Name}
** **
** Commercial License Usage ** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in ** Licensees holding valid commercial Qt licenses may use this file in

View File

@@ -343,10 +343,11 @@ static QByteArray fullPrefix(const QByteArray &prefix)
* \sa registerVariables(), registerIntVariable(), registerFileVariables() * \sa registerVariables(), registerIntVariable(), registerFileVariables()
*/ */
void MacroExpander::registerPrefix(const QByteArray &prefix, const QString &description, void MacroExpander::registerPrefix(const QByteArray &prefix, const QString &description,
const MacroExpander::PrefixFunction &value) const MacroExpander::PrefixFunction &value, bool visible)
{ {
QByteArray tmp = fullPrefix(prefix); QByteArray tmp = fullPrefix(prefix);
d->m_descriptions.insert(tmp + "<value>", description); if (visible)
d->m_descriptions.insert(tmp + "<value>", description);
d->m_prefixMap.insert(tmp, value); d->m_prefixMap.insert(tmp, value);
} }

View File

@@ -68,7 +68,7 @@ public:
using IntFunction = std::function<int()>; using IntFunction = std::function<int()>;
void registerPrefix(const QByteArray &prefix, void registerPrefix(const QByteArray &prefix,
const QString &description, const PrefixFunction &value); const QString &description, const PrefixFunction &value, bool visible = true);
void registerVariable(const QByteArray &variable, void registerVariable(const QByteArray &variable,
const QString &description, const StringFunction &value, const QString &description, const StringFunction &value,

View File

@@ -97,7 +97,7 @@ void ExecuteFilter::accept(LocatorFilterEntry selection,
bool found; bool found;
QString workingDirectory = Utils::globalMacroExpander()->value("CurrentDocument:Path", &found); QString workingDirectory = Utils::globalMacroExpander()->value("CurrentDocument:Path", &found);
if (!found || workingDirectory.isEmpty()) if (!found || workingDirectory.isEmpty())
workingDirectory = Utils::globalMacroExpander()->value("CurrentProject:Path", &found); workingDirectory = Utils::globalMacroExpander()->value("CurrentDocument:Project:Path", &found);
ExecuteData d; ExecuteData d;
d.workingDirectory = workingDirectory; d.workingDirectory = workingDirectory;

View File

@@ -172,11 +172,18 @@ BuildConfiguration::BuildConfiguration(Target *target, Utils::Id id)
expander->registerVariable("buildDir", tr("Build directory"), expander->registerVariable("buildDir", tr("Build directory"),
[this] { return buildDirectory().toUserOutput(); }); [this] { return buildDirectory().toUserOutput(); });
// TODO: Remove "Current" variants in ~4.16.
expander->registerVariable(Constants::VAR_CURRENTBUILD_NAME, tr("Name of current build"), expander->registerVariable(Constants::VAR_CURRENTBUILD_NAME, tr("Name of current build"),
[this] { return displayName(); }, false); [this] { return displayName(); }, false);
expander->registerVariable("BuildConfig:Name", tr("Name of the build configuration"),
[this] { return displayName(); });
expander->registerPrefix(Constants::VAR_CURRENTBUILD_ENV, expander->registerPrefix(Constants::VAR_CURRENTBUILD_ENV,
tr("Variables in the current build environment"), tr("Variables in the current build environment"),
[this](const QString &var) { return environment().expandedValueForKey(var); }, false);
expander->registerPrefix("BuildConfig:Env",
tr("Variables in the build configuration's environment"),
[this](const QString &var) { return environment().expandedValueForKey(var); }); [this](const QString &var) { return environment().expandedValueForKey(var); });
updateCacheAndEmitEnvironmentChanged(); updateCacheAndEmitEnvironmentChanged();

View File

@@ -98,20 +98,30 @@ public:
for (KitAspect *aspect : KitManager::kitAspects()) for (KitAspect *aspect : KitManager::kitAspects())
aspect->addToMacroExpander(kit, &m_macroExpander); aspect->addToMacroExpander(kit, &m_macroExpander);
// This provides the same global fall back as the global expander // TODO: Remove the "Current" variants in ~4.16
// without relying on the currentKit() discovery process there. m_macroExpander.registerVariable("CurrentKit:Name",
m_macroExpander.registerVariable(Constants::VAR_CURRENTKIT_NAME,
tr("The name of the currently active kit."), tr("The name of the currently active kit."),
[kit] { return kit->displayName(); }, [kit] { return kit->displayName(); },
false); false);
m_macroExpander.registerVariable(Constants::VAR_CURRENTKIT_FILESYSTEMNAME, m_macroExpander.registerVariable("Kit:Name",
tr("The name of the kit."),
[kit] { return kit->displayName(); });
m_macroExpander.registerVariable("CurrentKit:FileSystemName",
tr("The name of the currently active kit in a filesystem-friendly version."), tr("The name of the currently active kit in a filesystem-friendly version."),
[kit] { return kit->fileSystemFriendlyName(); }, [kit] { return kit->fileSystemFriendlyName(); },
false); false);
m_macroExpander.registerVariable(Constants::VAR_CURRENTKIT_ID, m_macroExpander.registerVariable("Kit:FileSystemName",
tr("The name of the kit in a filesystem-friendly version."),
[kit] { return kit->fileSystemFriendlyName(); });
m_macroExpander.registerVariable("CurrentKit:Id",
tr("The id of the currently active kit."), tr("The id of the currently active kit."),
[kit] { return kit->id().toString(); }, [kit] { return kit->id().toString(); },
false); false);
m_macroExpander.registerVariable("Kit:Id",
tr("The id of the kit."),
[kit] { return kit->id().toString(); });
} }
DisplayName m_unexpandedDisplayName; DisplayName m_unexpandedDisplayName;

View File

@@ -84,7 +84,7 @@ KitManagerConfigWidget::KitManagerConfigWidget(Kit *k) :
tr("<html><head/><body><p>The name of the kit suitable for generating " tr("<html><head/><body><p>The name of the kit suitable for generating "
"directory names. This value is used for the variable <i>%1</i>, " "directory names. This value is used for the variable <i>%1</i>, "
"which for example determines the name of the shadow build directory." "which for example determines the name of the shadow build directory."
"</p></body></html>").arg(QLatin1String(Constants::VAR_CURRENTKIT_FILESYSTEMNAME)); "</p></body></html>").arg(QLatin1String("Kit:FileSystemName"));
m_fileSystemFriendlyNameLineEdit->setToolTip(toolTip); m_fileSystemFriendlyNameLineEdit->setToolTip(toolTip);
QRegularExpression fileSystemFriendlyNameRegexp(QLatin1String("^[A-Za-z0-9_-]*$")); QRegularExpression fileSystemFriendlyNameRegexp(QLatin1String("^[A-Za-z0-9_-]*$"));
Q_ASSERT(fileSystemFriendlyNameRegexp.isValid()); Q_ASSERT(fileSystemFriendlyNameRegexp.isValid());

View File

@@ -258,7 +258,7 @@ const char FOLDER_OPEN_LOCATIONS_CONTEXT_MENU[] = "Project.F.OpenLocation.CtxMe
const char PROJECT_OPEN_LOCATIONS_CONTEXT_MENU[] = "Project.P.OpenLocation.CtxMenu"; const char PROJECT_OPEN_LOCATIONS_CONTEXT_MENU[] = "Project.P.OpenLocation.CtxMenu";
// Default directories: // Default directories:
const char DEFAULT_BUILD_DIRECTORY_TEMPLATE[] = "../%{JS: Util.asciify(\"build-%{CurrentProject:Name}-%{CurrentKit:FileSystemName}-%{CurrentBuild:Name}\")}"; const char DEFAULT_BUILD_DIRECTORY_TEMPLATE[] = "../%{JS: Util.asciify(\"build-%{Project:Name}-%{Kit:FileSystemName}-%{BuildConfig:Name}\")}";
const char DEFAULT_BUILD_DIRECTORY_TEMPLATE_KEY[] = "Directories/BuildDirectory.Template"; const char DEFAULT_BUILD_DIRECTORY_TEMPLATE_KEY[] = "Directories/BuildDirectory.Template";
const char BUILD_BEFORE_DEPLOY_SETTINGS_KEY[] = "ProjectExplorer/Settings/BuildBeforeDeploy"; const char BUILD_BEFORE_DEPLOY_SETTINGS_KEY[] = "ProjectExplorer/Settings/BuildBeforeDeploy";
@@ -332,18 +332,6 @@ static BuildConfiguration *activeBuildConfiguration()
return target ? target->activeBuildConfiguration() : nullptr; return target ? target->activeBuildConfiguration() : nullptr;
} }
static RunConfiguration *activeRunConfiguration()
{
Target *target = activeTarget();
return target ? target->activeRunConfiguration() : nullptr;
}
static Kit *currentKit()
{
Target *target = activeTarget();
return target ? target->kit() : nullptr;
}
static bool isTextFile(const QString &fileName) static bool isTextFile(const QString &fileName)
{ {
return Utils::mimeTypeForFile(fileName).inherits( return Utils::mimeTypeForFile(fileName).inherits(
@@ -1543,10 +1531,18 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
= s->value(Constants::ABORT_BUILD_ALL_ON_ERROR_SETTINGS_KEY, true).toBool(); = s->value(Constants::ABORT_BUILD_ALL_ON_ERROR_SETTINGS_KEY, true).toBool();
dd->m_projectExplorerSettings.lowBuildPriority dd->m_projectExplorerSettings.lowBuildPriority
= s->value(Constants::LOW_BUILD_PRIORITY_SETTINGS_KEY, false).toBool(); = s->value(Constants::LOW_BUILD_PRIORITY_SETTINGS_KEY, false).toBool();
dd->m_buildPropertiesSettings.buildDirectoryTemplate dd->m_buildPropertiesSettings.buildDirectoryTemplate
= s->value(Constants::DEFAULT_BUILD_DIRECTORY_TEMPLATE_KEY).toString(); = s->value(Constants::DEFAULT_BUILD_DIRECTORY_TEMPLATE_KEY).toString();
if (dd->m_buildPropertiesSettings.buildDirectoryTemplate.isEmpty()) if (dd->m_buildPropertiesSettings.buildDirectoryTemplate.isEmpty())
dd->m_buildPropertiesSettings.buildDirectoryTemplate = Constants::DEFAULT_BUILD_DIRECTORY_TEMPLATE; dd->m_buildPropertiesSettings.buildDirectoryTemplate = Constants::DEFAULT_BUILD_DIRECTORY_TEMPLATE;
// TODO: Remove in ~4.16
dd->m_buildPropertiesSettings.buildDirectoryTemplate.replace("%{CurrentProject:Name}",
"%{Project:Name}");
dd->m_buildPropertiesSettings.buildDirectoryTemplate.replace("%{CurrentKit:FileSystemName}",
"%{Kit:FileSystemName}");
dd->m_buildPropertiesSettings.buildDirectoryTemplate.replace("%{CurrentBuild:Name}",
"%{BuildConfig:Name}");
const auto loadTriStateValue = [&s](const QString &key) { const auto loadTriStateValue = [&s](const QString &key) {
return TriState::fromVariant(s->value(key, TriState::Default.toVariant())); return TriState::fromVariant(s->value(key, TriState::Default.toVariant()));
@@ -1745,6 +1741,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
// FIXME: These are mostly "legacy"/"convenience" entries, relying on // FIXME: These are mostly "legacy"/"convenience" entries, relying on
// the global entry point ProjectExplorer::currentProject(). They should // the global entry point ProjectExplorer::currentProject(). They should
// not be used in the Run/Build configuration pages. // not be used in the Run/Build configuration pages.
// TODO: Remove the CurrentProject versions in ~4.16
Utils::MacroExpander *expander = Utils::globalMacroExpander(); Utils::MacroExpander *expander = Utils::globalMacroExpander();
expander->registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX, expander->registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX,
tr("Current project's main file."), tr("Current project's main file."),
@@ -1753,115 +1750,39 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
if (Project *project = ProjectTree::currentProject()) if (Project *project = ProjectTree::currentProject())
projectFilePath = project->projectFilePath(); projectFilePath = project->projectFilePath();
return projectFilePath.toString(); return projectFilePath.toString();
}); }, false);
expander->registerFileVariables("CurrentDocument:Project",
expander->registerVariable("CurrentProject:BuildPath", tr("Main file of the project the current document belongs to."),
tr("Full build path of the current project's active build configuration."),
[]() -> QString { []() -> QString {
BuildConfiguration *bc = activeBuildConfiguration(); Utils::FilePath projectFilePath;
return bc ? bc->buildDirectory().toUserOutput() : QString(); if (Project *project = ProjectTree::currentProject())
}); projectFilePath = project->projectFilePath();
return projectFilePath.toString();
}, false);
expander->registerVariable(Constants::VAR_CURRENTPROJECT_NAME, expander->registerVariable(Constants::VAR_CURRENTPROJECT_NAME,
tr("The name of the current project."), tr("The name of the current project."),
[]() -> QString { []() -> QString {
Project *project = ProjectTree::currentProject(); Project *project = ProjectTree::currentProject();
return project ? project->displayName() : QString(); return project ? project->displayName() : QString();
}); }, false);
expander->registerVariable("CurrentDocument:Project:Name",
expander->registerVariable(Constants::VAR_CURRENTKIT_NAME, tr("The name of the project the current document belongs to."),
tr("The name of the currently active kit."),
[]() -> QString { []() -> QString {
Kit *kit = currentKit(); Project *project = ProjectTree::currentProject();
return kit ? kit->displayName() : QString(); return project ? project->displayName() : QString();
});
expander->registerVariable(Constants::VAR_CURRENTKIT_FILESYSTEMNAME,
tr("The name of the currently active kit as a filesystem-friendly version."),
[]() -> QString {
Kit *kit = currentKit();
return kit ? kit->fileSystemFriendlyName() : QString();
});
expander->registerVariable(Constants::VAR_CURRENTKIT_ID,
tr("The ID of the currently active kit."),
[]() -> QString {
Kit *kit = currentKit();
return kit ? kit->id().toString() : QString();
});
expander->registerVariable("CurrentDevice:HostAddress",
tr("The host address of the device in the currently active kit."),
[]() -> QString {
Kit *kit = currentKit();
const IDevice::ConstPtr device = DeviceKitAspect::device(kit);
return device ? device->sshParameters().host() : QString();
});
expander->registerVariable("CurrentDevice:SshPort",
tr("The SSH port of the device in the currently active kit."),
[]() -> QString {
Kit *kit = currentKit();
const IDevice::ConstPtr device = DeviceKitAspect::device(kit);
return device ? QString::number(device->sshParameters().port()) : QString();
});
expander->registerVariable("CurrentDevice:UserName",
tr("The username with which to log into the device in the currently active kit."),
[]() -> QString {
Kit *kit = currentKit();
const IDevice::ConstPtr device = DeviceKitAspect::device(kit);
return device ? device->sshParameters().userName() : QString();
});
expander->registerVariable("CurrentDevice:PrivateKeyFile",
tr("The private key file with which to authenticate when logging into the device "
"in the currently active kit."),
[]() -> QString {
Kit *kit = currentKit();
const IDevice::ConstPtr device = DeviceKitAspect::device(kit);
return device ? device->sshParameters().privateKeyFile : QString();
});
expander->registerVariable(Constants::VAR_CURRENTBUILD_NAME,
tr("The currently active build configuration's name."),
[&]() -> QString {
BuildConfiguration *bc = activeBuildConfiguration();
return bc ? bc->displayName() : QString();
});
expander->registerVariable(Constants::VAR_CURRENTRUN_NAME,
tr("The currently active run configuration's name."),
[]() -> QString {
if (Target *target = activeTarget()) {
if (RunConfiguration *rc = target->activeRunConfiguration())
return rc->displayName();
}
return QString();
});
expander->registerFileVariables("CurrentRun:Executable",
tr("The currently active run configuration's executable (if applicable)."),
[]() -> QString {
if (Target *target = activeTarget()) {
if (RunConfiguration *rc = target->activeRunConfiguration())
return rc->commandLine().executable().toString();
}
return QString();
});
expander->registerVariable(Constants::VAR_CURRENTBUILD_TYPE,
tr("The currently active build configuration's type."),
[&]() -> QString {
BuildConfiguration *bc = activeBuildConfiguration();
const BuildConfiguration::BuildType type
= bc ? bc->buildType() : BuildConfiguration::Unknown;
return BuildConfiguration::buildTypeName(type);
}); });
expander->registerPrefix(Constants::VAR_CURRENTBUILD_ENV, expander->registerPrefix(Constants::VAR_CURRENTBUILD_ENV,
BuildConfiguration::tr("Variables in the current build environment"), BuildConfiguration::tr("Variables in the current build environment"),
[](const QString &var) {
if (BuildConfiguration *bc = activeBuildConfiguration())
return bc->environment().expandedValueForKey(var);
return QString();
}, false);
expander->registerPrefix("CurrentDocument:Project:BuildConfig:Env",
BuildConfiguration::tr("Variables in the active build environment "
"of the project containing the currently open document"),
[](const QString &var) { [](const QString &var) {
if (BuildConfiguration *bc = activeBuildConfiguration()) if (BuildConfiguration *bc = activeBuildConfiguration())
return bc->environment().expandedValueForKey(var); return bc->environment().expandedValueForKey(var);
@@ -1874,24 +1795,21 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
return bc->environment(); return bc->environment();
return Utils::Environment::systemEnvironment(); return Utils::Environment::systemEnvironment();
}}); }});
Utils::EnvironmentProvider::addProvider( Utils::EnvironmentProvider::addProvider(
{"CurrentRun:Env", tr("Current Run Environment"), []() { {"CurrentDocument:Project:BuildConfig:Env", tr("Current Build Environment"), []() {
if (RunConfiguration *rc = activeRunConfiguration()) if (BuildConfiguration *bc = activeBuildConfiguration())
if (auto envAspect = rc->aspect<EnvironmentAspect>()) return bc->environment();
return envAspect->environment();
return Utils::Environment::systemEnvironment(); return Utils::Environment::systemEnvironment();
}}); }});
QString fileDescription = tr("File where current session is saved."); const auto fileHandler = [] {
auto fileHandler = [] { return SessionManager::sessionNameToFileName(SessionManager::activeSession()).toString(); }; return SessionManager::sessionNameToFileName(SessionManager::activeSession()).toString();
expander->registerFileVariables("Session", fileDescription, fileHandler); };
expander->registerFileVariables("CurrentSession", fileDescription, fileHandler, false); expander->registerFileVariables("Session", tr("File where current session is saved."),
fileHandler);
QString nameDescription = tr("Name of current session."); expander->registerVariable("Session:Name", tr("Name of current session."), [] {
auto nameHandler = [] { return SessionManager::activeSession(); }; return SessionManager::activeSession();
expander->registerVariable("Session:Name", nameDescription, nameHandler); });
expander->registerVariable("CurrentSession:Name", nameDescription, nameHandler, false);
return true; return true;
} }

View File

@@ -189,14 +189,8 @@ const char ANDROID_ABI_X86_64[] = "x86_64";
// Variable Names: // Variable Names:
const char VAR_CURRENTPROJECT_PREFIX[] = "CurrentProject"; const char VAR_CURRENTPROJECT_PREFIX[] = "CurrentProject";
const char VAR_CURRENTPROJECT_NAME[] = "CurrentProject:Name"; const char VAR_CURRENTPROJECT_NAME[] = "CurrentProject:Name";
const char VAR_CURRENTKIT_NAME[] = "CurrentKit:Name";
const char VAR_CURRENTKIT_FILESYSTEMNAME[] = "CurrentKit:FileSystemName";
const char VAR_CURRENTKIT_ID[] = "CurrentKit:Id";
const char VAR_CURRENTBUILD_NAME[] = "CurrentBuild:Name"; const char VAR_CURRENTBUILD_NAME[] = "CurrentBuild:Name";
const char VAR_CURRENTBUILD_TYPE[] = "CurrentBuild:Type";
const char VAR_CURRENTBUILD_ENV[] = "CurrentBuild:Env"; const char VAR_CURRENTBUILD_ENV[] = "CurrentBuild:Env";
const char VAR_CURRENTRUN_NAME[] = "CurrentRun:Name";
const char VAR_CURRENTRUN_WORKINGDIR[] = "CurrentRun:WorkingDir";
// JsonWizard: // JsonWizard:
const char PAGE_ID_PREFIX[] = "PE.Wizard.Page."; const char PAGE_ID_PREFIX[] = "PE.Wizard.Page.";

View File

@@ -33,22 +33,33 @@ ProjectMacroExpander::ProjectMacroExpander(const Utils::FilePath &mainFilePath,
const Kit *kit, const QString &bcName, const Kit *kit, const QString &bcName,
BuildConfiguration::BuildType buildType) BuildConfiguration::BuildType buildType)
{ {
// TODO: Remove "Current" variants in ~4.16
registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX, registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX,
QCoreApplication::translate("ProjectExplorer", "Main file of current project"), QCoreApplication::translate("ProjectExplorer", "Main file of current project"),
[mainFilePath] { return mainFilePath.toString(); }, false);
registerFileVariables("Project",
QCoreApplication::translate("ProjectExplorer", "Main file of the project"),
[mainFilePath] { return mainFilePath.toString(); }); [mainFilePath] { return mainFilePath.toString(); });
registerVariable(Constants::VAR_CURRENTPROJECT_NAME, registerVariable(Constants::VAR_CURRENTPROJECT_NAME,
QCoreApplication::translate("ProjectExplorer", "Name of current project"), QCoreApplication::translate("ProjectExplorer", "Name of current project"),
[projectName] { return projectName; }, false);
registerVariable("Project:Name",
QCoreApplication::translate("ProjectExplorer", "Name of the project"),
[projectName] { return projectName; }); [projectName] { return projectName; });
registerVariable(Constants::VAR_CURRENTBUILD_NAME, registerVariable(Constants::VAR_CURRENTBUILD_NAME,
QCoreApplication::translate("ProjectExplorer", "Name of current build"), QCoreApplication::translate("ProjectExplorer", "Name of current build"),
[bcName] { return bcName; }, false);
registerVariable("BuildConfig:Name",
QCoreApplication::translate(
"ProjectExplorer", "Name of the project's active build configuration"),
[bcName] { return bcName; }); [bcName] { return bcName; });
registerVariable("CurrentBuild:Type",
registerVariable(Constants::VAR_CURRENTBUILD_TYPE,
QCoreApplication::translate("ProjectExplorer", "Type of current build"), QCoreApplication::translate("ProjectExplorer", "Type of current build"),
[buildType] { return BuildConfiguration::buildTypeName(buildType); }, false);
registerVariable("BuildConfig:Type",
QCoreApplication::translate(
"ProjectExplorer", "Type of the project's active build configuration"),
[buildType] { return BuildConfiguration::buildTypeName(buildType); }); [buildType] { return BuildConfiguration::buildTypeName(buildType); });
registerSubProvider([kit] { return kit->macroExpander(); }); registerSubProvider([kit] { return kit->macroExpander(); });
} }

View File

@@ -177,23 +177,6 @@ RunConfiguration::RunConfiguration(Target *target, Utils::Id id)
BuildConfiguration *bc = target->activeBuildConfiguration(); BuildConfiguration *bc = target->activeBuildConfiguration();
return bc ? bc->macroExpander() : target->macroExpander(); return bc ? bc->macroExpander() : target->macroExpander();
}); });
m_expander.registerPrefix("CurrentRun:Env", tr("Variables in the current run environment"),
[this](const QString &var) {
const auto envAspect = aspect<EnvironmentAspect>();
return envAspect ? envAspect->environment().expandedValueForKey(var) : QString();
});
m_expander.registerVariable(Constants::VAR_CURRENTRUN_WORKINGDIR,
tr("The currently active run configuration's working directory"),
[this] {
const auto wdAspect = aspect<WorkingDirectoryAspect>();
return wdAspect ? wdAspect->workingDirectory(&m_expander).toString() : QString();
});
m_expander.registerVariable(Constants::VAR_CURRENTRUN_NAME,
QCoreApplication::translate("ProjectExplorer", "The currently active run configuration's name."),
[this] { return displayName(); }, false);
m_commandLineGetter = [this] { m_commandLineGetter = [this] {
FilePath executable; FilePath executable;
if (const auto executableAspect = aspect<ExecutableAspect>()) if (const auto executableAspect = aspect<ExecutableAspect>())

View File

@@ -34,6 +34,7 @@
#include "deployconfiguration.h" #include "deployconfiguration.h"
#include "deploymentdata.h" #include "deploymentdata.h"
#include "devicesupport/devicemanager.h" #include "devicesupport/devicemanager.h"
#include "environmentaspect.h"
#include "kit.h" #include "kit.h"
#include "kitinformation.h" #include "kitinformation.h"
#include "kitmanager.h" #include "kitmanager.h"
@@ -43,6 +44,7 @@
#include "projectexplorericons.h" #include "projectexplorericons.h"
#include "projectexplorersettings.h" #include "projectexplorersettings.h"
#include "runconfiguration.h" #include "runconfiguration.h"
#include "runconfigurationaspects.h"
#include "session.h" #include "session.h"
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
@@ -157,11 +159,46 @@ Target::Target(Project *project, Kit *k, _constructor_tag) :
d->m_macroExpander.registerVariable("sourceDir", tr("Source directory"), d->m_macroExpander.registerVariable("sourceDir", tr("Source directory"),
[project] { return project->projectDirectory().toUserOutput(); }); [project] { return project->projectDirectory().toUserOutput(); });
// Legacy support. // TODO: Remove in ~4.16.
d->m_macroExpander.registerVariable(Constants::VAR_CURRENTPROJECT_NAME, d->m_macroExpander.registerVariable(Constants::VAR_CURRENTPROJECT_NAME,
QCoreApplication::translate("ProjectExplorer", "Name of current project"), QCoreApplication::translate("ProjectExplorer", "Name of current project"),
[project] { return project->displayName(); }, [project] { return project->displayName(); },
false); false);
d->m_macroExpander.registerVariable("Project:Name",
QCoreApplication::translate("ProjectExplorer", "Name of current project"),
[project] { return project->displayName(); });
d->m_macroExpander.registerVariable("CurrentRun:Name",
tr("The currently active run configuration's name."),
[this]() -> QString {
if (RunConfiguration * const rc = activeRunConfiguration())
return rc->displayName();
return QString();
});
d->m_macroExpander.registerFileVariables("CurrentRun:Executable",
tr("The currently active run configuration's executable (if applicable)."),
[this]() -> QString {
if (RunConfiguration * const rc = activeRunConfiguration())
return rc->commandLine().executable().toString();
return QString();
});
d->m_macroExpander.registerPrefix("CurrentRun:Env", tr("Variables in the current run environment"),
[this](const QString &var) {
if (RunConfiguration * const rc = activeRunConfiguration()) {
if (const auto envAspect = rc->aspect<EnvironmentAspect>())
return envAspect->environment().expandedValueForKey(var);
}
return QString();
});
d->m_macroExpander.registerVariable("CurrentRun:WorkingDir",
tr("The currently active run configuration's working directory"),
[this] {
if (RunConfiguration * const rc = activeRunConfiguration()) {
if (const auto wdAspect = rc->aspect<WorkingDirectoryAspect>())
return wdAspect->workingDirectory(&d->m_macroExpander).toString();
}
return QString();
});
} }
Target::~Target() Target::~Target()

View File

@@ -47,14 +47,12 @@
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projecttree.h> #include <projectexplorer/projecttree.h>
#include <projectexplorer/runcontrol.h> #include <projectexplorer/runcontrol.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <utils/infobar.h> #include <utils/infobar.h>
#include <utils/macroexpander.h> #include <utils/macroexpander.h>
const char kHostBins[] = "CurrentProject:QT_HOST_BINS";
const char kInstallBins[] = "CurrentProject:QT_INSTALL_BINS";
using namespace Core; using namespace Core;
using namespace ProjectExplorer; using namespace ProjectExplorer;
@@ -107,15 +105,6 @@ bool QtSupportPlugin::initialize(const QStringList &arguments, QString *errorMes
return true; return true;
} }
static BaseQtVersion *qtVersion()
{
ProjectExplorer::Project *project = ProjectExplorer::ProjectTree::currentProject();
if (!project || !project->activeTarget())
return nullptr;
return QtKitAspect::qtVersion(project->activeTarget()->kit());
}
const char kLinkWithQtInstallationSetting[] = "LinkWithQtInstallation"; const char kLinkWithQtInstallationSetting[] = "LinkWithQtInstallation";
static void askAboutQtInstallation() static void askAboutQtInstallation()
@@ -144,21 +133,55 @@ void QtSupportPlugin::extensionsInitialized()
{ {
Utils::MacroExpander *expander = Utils::globalMacroExpander(); Utils::MacroExpander *expander = Utils::globalMacroExpander();
static const auto currentQtVersion = []() -> const BaseQtVersion * {
ProjectExplorer::Project *project = ProjectExplorer::ProjectTree::currentProject();
if (!project || !project->activeTarget())
return nullptr;
return QtKitAspect::qtVersion(project->activeTarget()->kit());
};
static const char kCurrentHostBins[] = "CurrentDocument:Project:QT_HOST_BINS";
expander->registerVariable( expander->registerVariable(
kHostBins, kCurrentHostBins,
tr("Full path to the host bin directory of the current project's Qt version."), tr("Full path to the host bin directory of the Qt version in the active kit "
"of the project containing the current document."),
[]() { []() {
BaseQtVersion *qt = qtVersion(); const BaseQtVersion * const qt = currentQtVersion();
return qt ? qt->hostBinPath().toUserOutput() : QString(); return qt ? qt->hostBinPath().toUserOutput() : QString();
}); });
expander->registerVariable( expander->registerVariable(
kInstallBins, "CurrentDocument:Project:QT_INSTALL_BINS",
tr("Full path to the target bin directory of the current project's Qt version.<br>" tr("Full path to the target bin directory of the Qt version in the active kit "
"You probably want %1 instead.") "of the project containing the current document.<br>You probably want %1 instead.")
.arg(QString::fromLatin1(kInstallBins)), .arg(QString::fromLatin1(kCurrentHostBins)),
[]() { []() {
BaseQtVersion *qt = qtVersion(); const BaseQtVersion * const qt = currentQtVersion();
return qt ? qt->binPath().toUserOutput() : QString();
});
static const auto activeQtVersion = []() -> const BaseQtVersion * {
ProjectExplorer::Project *project = SessionManager::startupProject();
if (!project || !project->activeTarget())
return nullptr;
return QtKitAspect::qtVersion(project->activeTarget()->kit());
};
static const char kActiveHostBins[] = "ActiveProject:QT_HOST_BINS";
expander->registerVariable(
kActiveHostBins,
tr("Full path to the host bin directory of the Qt version in the active kit "
"of the active project."),
[]() {
const BaseQtVersion * const qt = activeQtVersion();
return qt ? qt->hostBinPath().toUserOutput() : QString();
});
expander->registerVariable(
"ActiveProject:QT_INSTALL_BINS",
tr("Full path to the target bin directory of the Qt version in the active kit "
"of the active project.<br>You probably want %1 instead.")
.arg(QString::fromLatin1(kActiveHostBins)),
[]() {
const BaseQtVersion * const qt = activeQtVersion();
return qt ? qt->binPath().toUserOutput() : QString(); return qt ? qt->binPath().toUserOutput() : QString();
}); });

View File

@@ -42,9 +42,9 @@ const char VCS_ID_SUBVERSION[] = "J.Subversion";
const char VCS_ID_PERFORCE[] = "P.Perforce"; const char VCS_ID_PERFORCE[] = "P.Perforce";
const char VCS_ID_CVS[] = "Z.CVS"; const char VCS_ID_CVS[] = "Z.CVS";
const char VAR_VCS_NAME[] = "CurrentProject:VcsName"; const char VAR_VCS_NAME[] = "CurrentDocument:Project:VcsName";
const char VAR_VCS_TOPIC[] = "CurrentProject:VcsTopic"; const char VAR_VCS_TOPIC[] = "CurrentDocument:Project:VcsTopic";
const char VAR_VCS_TOPLEVELPATH[] = "CurrentProject:VcsTopLevelPath"; const char VAR_VCS_TOPLEVELPATH[] = "CurrentDocument:Project:VcsTopLevelPath";
} // namespace Constants } // namespace Constants
} // namespace VcsBase } // namespace VcsBase

View File

@@ -32,10 +32,10 @@
<category>Linguist</category> <category>Linguist</category>
<order>2</order> <order>2</order>
<executable> <executable>
<path>%{CurrentProject:QT_INSTALL_BINS}/lrelease</path> <path>%{CurrentDocument:Project:QT_INSTALL_BINS}/lrelease</path>
<path>lrelease</path> <path>lrelease</path>
<arguments>%{CurrentProject:FilePath}</arguments> <arguments>%{CurrentDocument:Project:FilePath}</arguments>
<workingdirectory>%{CurrentProject:Path}</workingdirectory> <workingdirectory>%{CurrentDocument:Project:Path}</workingdirectory>
<baseEnvironmentId>CurrentBuild:Env</baseEnvironmentId> <baseEnvironmentId>CurrentDocument:Project:BuildConfig:Env</baseEnvironmentId>
</executable> </executable>
</externaltool> </externaltool>

View File

@@ -32,10 +32,10 @@
<category>Linguist</category> <category>Linguist</category>
<order>1</order> <order>1</order>
<executable> <executable>
<path>%{CurrentProject:QT_INSTALL_BINS}/lupdate</path> <path>%{CurrentDocument:Project:QT_INSTALL_BINS}/lupdate</path>
<path>lupdate</path> <path>lupdate</path>
<arguments>%{CurrentProject:FilePath}</arguments> <arguments>%{CurrentDocument:Project:FilePath}</arguments>
<workingdirectory>%{CurrentProject:Path}</workingdirectory> <workingdirectory>%{CurrentDocument:Project:Path}</workingdirectory>
<baseEnvironmentId>CurrentBuild:Env</baseEnvironmentId> <baseEnvironmentId>CurrentDocument:Project:BuildConfig:Env</baseEnvironmentId>
</executable> </executable>
</externaltool> </externaltool>

View File

@@ -32,7 +32,7 @@
<category>Qt Quick</category> <category>Qt Quick</category>
<order>1</order> <order>1</order>
<executable> <executable>
<path>%{CurrentProject:QT_INSTALL_BINS}/qmlscene</path> <path>%{CurrentDocument:Project:QT_INSTALL_BINS}/qmlscene</path>
<path>qmlscene</path> <path>qmlscene</path>
<arguments>%{CurrentDocument:FilePath}</arguments> <arguments>%{CurrentDocument:FilePath}</arguments>
<workingdirectory>%{CurrentDocument:Path}</workingdirectory> <workingdirectory>%{CurrentDocument:Path}</workingdirectory>

View File

@@ -32,7 +32,7 @@
<category>Qt Quick</category> <category>Qt Quick</category>
<order>1</order> <order>1</order>
<executable> <executable>
<path>%{CurrentProject:QT_INSTALL_BINS}/qmlviewer</path> <path>%{CurrentDocument:Project:QT_INSTALL_BINS}/qmlviewer</path>
<path>qmlviewer</path> <path>qmlviewer</path>
<arguments>%{CurrentDocument:FilePath}</arguments> <arguments>%{CurrentDocument:FilePath}</arguments>
<workingdirectory>%{CurrentDocument:Path}</workingdirectory> <workingdirectory>%{CurrentDocument:Path}</workingdirectory>