forked from qt-creator/qt-creator
Avoid duplication of projectexplorer's variable handling.
Change-Id: I5a5c41448d521af5aa60b92b804c8fd965b90906 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
#include "gcctoolchainfactories.h"
|
#include "gcctoolchainfactories.h"
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
#include "projectexplorersettings.h"
|
#include "projectexplorersettings.h"
|
||||||
|
#include "projectmacroexpander.h"
|
||||||
#include "removetaskhandler.h"
|
#include "removetaskhandler.h"
|
||||||
#include "kitmanager.h"
|
#include "kitmanager.h"
|
||||||
#include "kitoptionspage.h"
|
#include "kitoptionspage.h"
|
||||||
@@ -1144,52 +1145,13 @@ void ProjectExplorerPlugin::loadCustomWizards()
|
|||||||
|
|
||||||
void ProjectExplorerPlugin::updateVariable(const QByteArray &variable)
|
void ProjectExplorerPlugin::updateVariable(const QByteArray &variable)
|
||||||
{
|
{
|
||||||
if (variable == Constants::VAR_CURRENTPROJECT_FILEPATH) {
|
if (variable == Constants::VAR_CURRENTPROJECT_BUILDPATH) {
|
||||||
if (currentProject() && currentProject()->document()) {
|
|
||||||
Core::VariableManager::instance()->insert(variable,
|
|
||||||
currentProject()->document()->fileName());
|
|
||||||
} else {
|
|
||||||
Core::VariableManager::instance()->remove(variable);
|
|
||||||
}
|
|
||||||
} else if (variable == Constants::VAR_CURRENTPROJECT_PATH) {
|
|
||||||
if (currentProject() && currentProject()->document()) {
|
|
||||||
Core::VariableManager::instance()->insert(variable,
|
|
||||||
QFileInfo(currentProject()->document()->fileName()).path());
|
|
||||||
} else {
|
|
||||||
Core::VariableManager::instance()->remove(variable);
|
|
||||||
}
|
|
||||||
} else if (variable == Constants::VAR_CURRENTPROJECT_BUILDPATH) {
|
|
||||||
if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->activeBuildConfiguration()) {
|
if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->activeBuildConfiguration()) {
|
||||||
Core::VariableManager::instance()->insert(variable,
|
Core::VariableManager::instance()->insert(variable,
|
||||||
currentProject()->activeTarget()->activeBuildConfiguration()->buildDirectory());
|
currentProject()->activeTarget()->activeBuildConfiguration()->buildDirectory());
|
||||||
} else {
|
} else {
|
||||||
Core::VariableManager::instance()->remove(variable);
|
Core::VariableManager::instance()->remove(variable);
|
||||||
}
|
}
|
||||||
} else if (variable == Constants::VAR_CURRENTPROJECT_NAME) {
|
|
||||||
if (currentProject())
|
|
||||||
Core::VariableManager::instance()->insert(variable, currentProject()->displayName());
|
|
||||||
else
|
|
||||||
Core::VariableManager::instance()->remove(variable);
|
|
||||||
} else if (variable == Constants::VAR_CURRENTKIT_NAME) {
|
|
||||||
if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->kit())
|
|
||||||
Core::VariableManager::instance()->insert(variable, currentProject()->activeTarget()->kit()->displayName());
|
|
||||||
else
|
|
||||||
Core::VariableManager::instance()->remove(variable);
|
|
||||||
} else if (variable == Constants::VAR_CURRENTKIT_FILESYSTEMNAME) {
|
|
||||||
if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->kit())
|
|
||||||
Core::VariableManager::instance()->insert(variable, currentProject()->activeTarget()->kit()->fileSystemFriendlyName());
|
|
||||||
else
|
|
||||||
Core::VariableManager::instance()->remove(variable);
|
|
||||||
} else if (variable == Constants::VAR_CURRENTKIT_ID) {
|
|
||||||
if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->kit())
|
|
||||||
Core::VariableManager::instance()->insert(variable, currentProject()->activeTarget()->kit()->id().toString());
|
|
||||||
else
|
|
||||||
Core::VariableManager::instance()->remove(variable);
|
|
||||||
} else if (variable == Constants::VAR_CURRENTBUILD_NAME) {
|
|
||||||
if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->activeBuildConfiguration())
|
|
||||||
Core::VariableManager::instance()->insert(variable, currentProject()->activeTarget()->activeBuildConfiguration()->displayName());
|
|
||||||
else
|
|
||||||
Core::VariableManager::instance()->remove(variable);
|
|
||||||
} else if (variable == Constants::VAR_CURRENTBUILD_TYPE) {
|
} else if (variable == Constants::VAR_CURRENTBUILD_TYPE) {
|
||||||
if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->activeBuildConfiguration()) {
|
if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->activeBuildConfiguration()) {
|
||||||
BuildConfiguration::BuildType type = currentProject()->activeTarget()->activeBuildConfiguration()->buildType();
|
BuildConfiguration::BuildType type = currentProject()->activeTarget()->activeBuildConfiguration()->buildType();
|
||||||
@@ -1204,6 +1166,28 @@ void ProjectExplorerPlugin::updateVariable(const QByteArray &variable)
|
|||||||
} else {
|
} else {
|
||||||
Core::VariableManager::instance()->remove(variable);
|
Core::VariableManager::instance()->remove(variable);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
QString projectName;
|
||||||
|
QString projectFilePath;
|
||||||
|
Kit *kit = 0;
|
||||||
|
QString buildConfigurationName;
|
||||||
|
if (Project *project = currentProject()) {
|
||||||
|
projectName = project->displayName();
|
||||||
|
if (Core::IDocument *doc = project->document())
|
||||||
|
projectFilePath = doc->fileName();
|
||||||
|
if (Target *target = project->activeTarget()) {
|
||||||
|
kit = target->kit();
|
||||||
|
if (BuildConfiguration *buildConfiguration = target->activeBuildConfiguration()) {
|
||||||
|
buildConfigurationName = buildConfiguration->displayName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ProjectExpander expander(projectFilePath, projectName, kit, buildConfigurationName);
|
||||||
|
QString result;
|
||||||
|
if (expander.resolveProjectMacro(QString::fromUtf8(variable), &result))
|
||||||
|
Core::VariableManager::instance()->insert(variable, result);
|
||||||
|
else
|
||||||
|
Core::VariableManager::instance()->remove(variable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,19 +40,25 @@ ProjectExpander::ProjectExpander(const QString &projectFilePath, const QString &
|
|||||||
: m_projectFile(projectFilePath), m_projectName(projectName), m_kit(k), m_bcName(bcName)
|
: m_projectFile(projectFilePath), m_projectName(projectName), m_kit(k), m_bcName(bcName)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool ProjectExpander::resolveMacro(const QString &name, QString *ret)
|
bool ProjectExpander::resolveProjectMacro(const QString &name, QString *ret)
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
if (name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTPROJECT_NAME)) {
|
if (name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTPROJECT_NAME)) {
|
||||||
|
if (!m_projectName.isEmpty()) {
|
||||||
result = m_projectName;
|
result = m_projectName;
|
||||||
found = true;
|
found = true;
|
||||||
|
}
|
||||||
} else if (name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTPROJECT_PATH)) {
|
} else if (name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTPROJECT_PATH)) {
|
||||||
|
if (!m_projectFile.filePath().isEmpty()) {
|
||||||
result = m_projectFile.absolutePath();
|
result = m_projectFile.absolutePath();
|
||||||
found = true;
|
found = true;
|
||||||
|
}
|
||||||
} else if (name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTPROJECT_FILEPATH)) {
|
} else if (name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTPROJECT_FILEPATH)) {
|
||||||
|
if (!m_projectFile.filePath().isEmpty()) {
|
||||||
result = m_projectFile.absoluteFilePath();
|
result = m_projectFile.absoluteFilePath();
|
||||||
found = true;
|
found = true;
|
||||||
|
}
|
||||||
} else if (m_kit && name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTKIT_NAME)) {
|
} else if (m_kit && name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTKIT_NAME)) {
|
||||||
result = m_kit->displayName();
|
result = m_kit->displayName();
|
||||||
found = true;
|
found = true;
|
||||||
@@ -65,10 +71,19 @@ bool ProjectExpander::resolveMacro(const QString &name, QString *ret)
|
|||||||
} else if (name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTBUILD_NAME)) {
|
} else if (name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTBUILD_NAME)) {
|
||||||
result = m_bcName;
|
result = m_bcName;
|
||||||
found = true;
|
found = true;
|
||||||
} else {
|
|
||||||
result = Core::VariableManager::instance()->value(name.toUtf8(), &found);
|
|
||||||
}
|
}
|
||||||
if (ret)
|
if (ret)
|
||||||
*ret = result;
|
*ret = result;
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ProjectExpander::resolveMacro(const QString &name, QString *ret)
|
||||||
|
{
|
||||||
|
bool found = resolveProjectMacro(name, ret);
|
||||||
|
if (!found) {
|
||||||
|
QString result = Core::VariableManager::instance()->value(name.toUtf8(), &found);
|
||||||
|
if (ret)
|
||||||
|
*ret = result;
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class PROJECTEXPLORER_EXPORT ProjectExpander : public Utils::AbstractQtcMacroExp
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ProjectExpander(const QString &projectFilePath, const QString &projectName, const Kit *k, const QString &bcName);
|
ProjectExpander(const QString &projectFilePath, const QString &projectName, const Kit *k, const QString &bcName);
|
||||||
|
bool resolveProjectMacro(const QString &name, QString *ret);
|
||||||
bool resolveMacro(const QString &name, QString *ret);
|
bool resolveMacro(const QString &name, QString *ret);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user