Commit edc08ba2 authored by hjk's avatar hjk
Browse files

Move uses of ProjectMacroExpander closer to build configuration



All static functions, can live closer to related code.

Change-Id: I54c5680256c78f1d09b4bee3e8843b2f4350b75a
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 5003bc60
......@@ -35,31 +35,48 @@
#include "cmakeproject.h"
#include "cmakeprojectconstants.h"
#include <coreplugin/documentmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectmacroexpander.h>
#include <projectexplorer/target.h>
#include <utils/qtcassert.h>
#include <QInputDialog>
using namespace CMakeProjectManager;
using namespace Internal;
using namespace ProjectExplorer;
using namespace Utils;
namespace CMakeProjectManager {
namespace Internal {
namespace {
const char USE_NINJA_KEY[] = "CMakeProjectManager.CMakeBuildConfiguration.UseNinja";
} // namespace
static QString shadowBuildDirectory(const QString &projectFilePath, const Kit *k, const QString &bcName)
{
if (projectFilePath.isEmpty())
return QString();
QFileInfo info(projectFilePath);
const QString projectName = QFileInfo(info.absolutePath()).fileName();
ProjectMacroExpander expander(projectName, k, bcName);
QDir projectDir = QDir(Project::projectDirectory(FileName::fromString(projectFilePath)).toString());
QString buildPath = expander.expand(Core::DocumentManager::buildDirectory());
return QDir::cleanPath(projectDir.absoluteFilePath(buildPath));
}
CMakeBuildConfiguration::CMakeBuildConfiguration(ProjectExplorer::Target *parent) :
BuildConfiguration(parent, Core::Id(Constants::CMAKE_BC_ID)), m_useNinja(false)
{
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
setBuildDirectory(Utils::FileName::fromString(project->shadowBuildDirectory(project->projectFilePath().toString(),
parent->kit(),
displayName())));
setBuildDirectory(Utils::FileName::fromString(shadowBuildDirectory(project->projectFilePath().toString(),
parent->kit(),
displayName())));
}
CMakeBuildConfiguration::CMakeBuildConfiguration(ProjectExplorer::Target *parent,
......@@ -156,9 +173,7 @@ QList<ProjectExplorer::BuildInfo *> CMakeBuildConfigurationFactory::availableSet
CMakeBuildInfo *info = createBuildInfo(k, ProjectExplorer::Project::projectDirectory(Utils::FileName::fromString(projectPath)).toString());
//: The name of the build configuration created by default for a cmake project.
info->displayName = tr("Default");
info->buildDirectory
= Utils::FileName::fromString(CMakeProject::shadowBuildDirectory(projectPath, k,
info->displayName));
info->buildDirectory = FileName::fromString(shadowBuildDirectory(projectPath, k, info->displayName));
result << info;
return result;
}
......@@ -174,10 +189,9 @@ ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::create(Proj
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
if (copy.buildDirectory.isEmpty())
copy.buildDirectory
= Utils::FileName::fromString(project->shadowBuildDirectory(project->projectFilePath().toString(),
parent->kit(),
copy.displayName));
copy.buildDirectory = FileName::fromString(shadowBuildDirectory(project->projectFilePath().toString(),
parent->kit(),
copy.displayName));
CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), project->projectManager(), CMakeOpenProjectWizard::ChangeDirectory, &copy);
if (copw.exec() != QDialog::Accepted)
......@@ -295,3 +309,5 @@ ProjectExplorer::BuildConfiguration::BuildType CMakeBuildConfiguration::buildTyp
return Unknown;
}
} // namespace Internal
} // namespace CMakeProjectManager
......@@ -49,7 +49,6 @@
#include <projectexplorer/target.h>
#include <projectexplorer/deployconfiguration.h>
#include <projectexplorer/deploymentdata.h>
#include <projectexplorer/projectmacroexpander.h>
#include <qtsupport/customexecutablerunconfiguration.h>
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitinformation.h>
......@@ -62,7 +61,6 @@
#include <utils/hostosinfo.h>
#include <coreplugin/icore.h>
#include <coreplugin/infobar.h>
#include <coreplugin/documentmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <QDebug>
......@@ -177,19 +175,6 @@ void CMakeProject::changeBuildDirectory(CMakeBuildConfiguration *bc, const QStri
parseCMakeLists();
}
QString CMakeProject::shadowBuildDirectory(const QString &projectFilePath, const Kit *k, const QString &bcName)
{
if (projectFilePath.isEmpty())
return QString();
QFileInfo info(projectFilePath);
const QString projectName = QFileInfo(info.absolutePath()).fileName();
ProjectExplorer::ProjectMacroExpander expander(projectFilePath, projectName, k, bcName);
QDir projectDir = QDir(projectDirectory(Utils::FileName::fromString(projectFilePath)).toString());
QString buildPath = expander.expand(Core::DocumentManager::buildDirectory());
return QDir::cleanPath(projectDir.absoluteFilePath(buildPath));
}
QStringList CMakeProject::getCXXFlagsFor(const CMakeBuildTarget &buildTarget)
{
QString makeCommand = QDir::fromNativeSeparators(buildTarget.makeCommand);
......
......@@ -102,9 +102,6 @@ public:
CMakeBuildTarget buildTargetForTitle(const QString &title);
static QString shadowBuildDirectory(const QString &projectFilePath, const ProjectExplorer::Kit *k,
const QString &bcName);
bool isProjectFile(const QString &fileName);
bool parseCMakeLists();
......
......@@ -36,9 +36,9 @@
#include "target.h"
#include "project.h"
#include "kit.h"
#include "projectmacroexpander.h"
#include <projectexplorer/buildenvironmentwidget.h>
#include <projectexplorer/projectmacroexpander.h>
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/idocument.h>
......@@ -55,38 +55,6 @@ static const char USER_ENVIRONMENT_CHANGES_KEY[] = "ProjectExplorer.BuildConfigu
static const char BUILDDIRECTORY_KEY[] = "ProjectExplorer.BuildConfiguration.BuildDirectory";
namespace ProjectExplorer {
namespace Internal {
class BuildConfigMacroExpander : public ProjectMacroExpander
{
public:
explicit BuildConfigMacroExpander(const BuildConfiguration *bc)
: ProjectMacroExpander(bc->target()->project()->document()->filePath(),
bc->target()->project()->displayName(),
bc->target()->kit(),
bc->displayName()),
m_bc(bc)
{}
virtual bool resolveMacro(const QString &name, QString *ret) const;
private:
const BuildConfiguration *m_bc;
};
bool BuildConfigMacroExpander::resolveMacro(const QString &name, QString *ret) const
{
// legacy variables
if (name == QLatin1String("sourceDir")) {
*ret = m_bc->target()->project()->projectDirectory().toUserOutput();
return true;
}
if (name == QLatin1String("buildDir")) {
*ret = m_bc->buildDirectory().toUserOutput();
return true;
}
return ProjectMacroExpander::resolveMacro(name, ret);
}
} // namespace Internal
BuildConfiguration::BuildConfiguration(Target *target, Core::Id id) :
ProjectConfiguration(target, id),
......@@ -157,8 +125,21 @@ QList<NamedWidget *> BuildConfiguration::createSubConfigWidgets()
Utils::MacroExpander *BuildConfiguration::macroExpander()
{
if (!m_macroExpander)
m_macroExpander = new Internal::BuildConfigMacroExpander(this);
if (!m_macroExpander) {
m_macroExpander = new ProjectMacroExpander(target()->project()->displayName(),
target()->kit(), displayName());
m_macroExpander->registerSubProvider(
[this]() { return target()->kit()->macroExpander(); });
// Legacy support.
m_macroExpander->registerVariable("sourceDir", tr("Source directory"),
[this]() { return target()->project()->projectDirectory().toUserOutput(); });
m_macroExpander->registerVariable("buildDir", tr("Build directory"),
[this]() { return buildDirectory().toUserOutput(); });
}
return m_macroExpander;
}
......
......@@ -41,7 +41,6 @@
#include "jsonwizard/jsonwizardpagefactory_p.h"
#include "project.h"
#include "projectexplorersettings.h"
#include "projectmacroexpander.h"
#include "removetaskhandler.h"
#include "unconfiguredprojectpanel.h"
#include "kitfeatureprovider.h"
......
......@@ -38,9 +38,9 @@
using namespace ProjectExplorer;
ProjectMacroExpander::ProjectMacroExpander(const QString &projectFilePath, const QString &projectName,
const Kit *k, const QString &bcName)
: m_projectFile(projectFilePath), m_projectName(projectName), m_kit(k), m_bcName(bcName)
ProjectMacroExpander::ProjectMacroExpander(const QString &projectName,
const Kit *k, const QString &bcName)
: m_projectName(projectName), m_kit(k), m_bcName(bcName)
{ }
bool ProjectMacroExpander::resolveMacro(const QString &name, QString *ret) const
......
......@@ -41,7 +41,7 @@ class Kit;
class PROJECTEXPLORER_EXPORT ProjectMacroExpander : public Utils::MacroExpander
{
public:
ProjectMacroExpander(const QString &projectFilePath, const QString &projectName, const Kit *k, const QString &bcName);
ProjectMacroExpander(const QString &projectName, const Kit *k, const QString &bcName);
bool resolveMacro(const QString &name, QString *ret) const;
private:
......
......@@ -37,6 +37,7 @@
#include "qbsproject.h"
#include "qbsprojectmanagerconstants.h"
#include <coreplugin/documentmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
#include <utils/qtcassert.h>
......@@ -44,6 +45,7 @@
#include <projectexplorer/kit.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectmacroexpander.h>
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
......@@ -275,6 +277,16 @@ int QbsBuildConfigurationFactory::priority(const Kit *k, const QString &projectP
.matchesType(QLatin1String(Constants::MIME_TYPE))) ? 0 : -1;
}
static Utils::FileName defaultBuildDirectory(const QString &projectFilePath, const Kit *k,
const QString &bcName)
{
const QString projectName = QFileInfo(projectFilePath).completeBaseName();
ProjectMacroExpander expander(projectName, k, bcName);
QString projectDir = Project::projectDirectory(Utils::FileName::fromString(projectFilePath)).toString();
QString buildPath = expander.expand(Core::DocumentManager::buildDirectory());
return Utils::FileName::fromString(Utils::FileUtils::resolvePath(projectDir, buildPath));
}
QList<BuildInfo *> QbsBuildConfigurationFactory::availableSetups(const Kit *k, const QString &projectPath) const
{
QList<BuildInfo *> result;
......@@ -282,13 +294,13 @@ QList<BuildInfo *> QbsBuildConfigurationFactory::availableSetups(const Kit *k, c
BuildInfo *info = createBuildInfo(k, BuildConfiguration::Debug);
//: The name of the debug build configuration created by default for a qbs project.
info->displayName = tr("Debug");
info->buildDirectory = QbsProject::defaultBuildDirectory(projectPath, k, info->displayName);
info->buildDirectory = defaultBuildDirectory(projectPath, k, info->displayName);
result << info;
info = createBuildInfo(k, BuildConfiguration::Release);
//: The name of the release build configuration created by default for a qbs project.
info->displayName = tr("Release");
info->buildDirectory = QbsProject::defaultBuildDirectory(projectPath, k, info->displayName);
info->buildDirectory = defaultBuildDirectory(projectPath, k, info->displayName);
result << info;
return result;
......@@ -310,8 +322,8 @@ BuildConfiguration *QbsBuildConfigurationFactory::create(Target *parent, const B
Utils::FileName buildDir = info->buildDirectory;
if (buildDir.isEmpty())
buildDir = QbsProject::defaultBuildDirectory(parent->project()->projectDirectory().toString(),
parent->kit(), info->displayName);
buildDir = defaultBuildDirectory(parent->project()->projectDirectory().toString(),
parent->kit(), info->displayName);
BuildConfiguration *bc
= QbsBuildConfiguration::setup(parent, info->displayName, info->displayName,
......
......@@ -55,7 +55,6 @@
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectmacroexpander.h>
#include <projectexplorer/target.h>
#include <projectexplorer/taskhub.h>
#include <projectexplorer/toolchain.h>
......@@ -397,16 +396,6 @@ bool QbsProject::hasParseResult() const
return qbsProject().isValid();
}
Utils::FileName QbsProject::defaultBuildDirectory(const QString &projectFilePath, const Kit *k,
const QString &bcName)
{
const QString projectName = QFileInfo(projectFilePath).completeBaseName();
ProjectExplorer::ProjectMacroExpander expander(projectFilePath, projectName, k, bcName);
QString projectDir = projectDirectory(Utils::FileName::fromString(projectFilePath)).toString();
QString buildPath = expander.expand(Core::DocumentManager::buildDirectory());
return Utils::FileName::fromString(Utils::FileUtils::resolvePath(projectDir, buildPath));
}
qbs::Project QbsProject::qbsProject() const
{
return m_qbsProject;
......
......@@ -99,10 +99,6 @@ public:
void registerQbsProjectParser(QbsProjectParser *p);
static Utils::FileName defaultBuildDirectory(const QString &projectFilePath,
const ProjectExplorer::Kit *k,
const QString &bcName);
qbs::Project qbsProject() const;
qbs::ProjectData qbsProjectData() const;
......
......@@ -39,45 +39,67 @@
#include "qmakestep.h"
#include "makestep.h"
#include <utils/qtcprocess.h>
#include <utils/qtcassert.h>
#include <limits>
#include <coreplugin/documentmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectmacroexpander.h>
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/toolchainmanager.h>
#include <qtsupport/qtkitinformation.h>
#include <qtsupport/qtversionmanager.h>
#include <utils/qtcassert.h>
#include <QDebug>
#include <utils/qtcprocess.h>
#include <utils/qtcassert.h>
#include <android/androidmanager.h>
#include <QDebug>
#include <QInputDialog>
#include <limits>
using namespace ProjectExplorer;
using namespace QtSupport;
using namespace Utils;
using namespace QmakeProjectManager::Internal;
namespace QmakeProjectManager {
// --------------------------------------------------------------------
// Helpers:
// --------------------------------------------------------------------
QString QmakeBuildConfiguration::shadowBuildDirectory(const QString &proFilePath, const Kit *k, const QString &suffix)
{
if (proFilePath.isEmpty())
return QString();
QFileInfo info(proFilePath);
BaseQtVersion *version = QtKitInformation::qtVersion(k);
if (version && !version->supportsShadowBuilds())
return info.absolutePath();
const QString projectName = QFileInfo(proFilePath).completeBaseName();
ProjectMacroExpander expander(projectName, k, suffix);
QString projectDir = Project::projectDirectory(FileName::fromString(proFilePath)).toString();
QString buildPath = expander.expand(Core::DocumentManager::buildDirectory());
return FileUtils::resolvePath(projectDir, buildPath);
}
static Utils::FileName defaultBuildDirectory(bool supportsShadowBuild,
const QString &projectPath,
const ProjectExplorer::Kit *k,
const QString &suffix)
{
if (supportsShadowBuild)
return Utils::FileName::fromString(QmakeProject::shadowBuildDirectory(projectPath, k, suffix));
return Utils::FileName::fromString(QmakeBuildConfiguration::shadowBuildDirectory(projectPath, k, suffix));
return ProjectExplorer::Project::projectDirectory(Utils::FileName::fromString(projectPath));
}
using namespace Internal;
using namespace ProjectExplorer;
using namespace QtSupport;
using namespace Utils;
const char QMAKE_BC_ID[] = "Qt4ProjectManager.Qt4BuildConfiguration";
const char USE_SHADOW_BUILD_KEY[] = "Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild";
const char BUILD_CONFIGURATION_KEY[] = "Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration";
......@@ -201,8 +223,8 @@ NamedWidget *QmakeBuildConfiguration::createConfigWidget()
QString QmakeBuildConfiguration::defaultShadowBuildDirectory() const
{
// todo displayName isn't ideal
return QmakeProject::shadowBuildDirectory(target()->project()->projectFilePath().toString(),
target()->kit(), displayName());
return shadowBuildDirectory(target()->project()->projectFilePath().toString(),
target()->kit(), displayName());
}
bool QmakeBuildConfiguration::supportsShadowBuilds()
......
......@@ -68,6 +68,10 @@ public:
QtSupport::BaseQtVersion::QmakeBuildConfigs qmakeBuildConfiguration() const;
void setQMakeBuildConfiguration(QtSupport::BaseQtVersion::QmakeBuildConfigs config);
/// suffix should be unique
static QString shadowBuildDirectory(const QString &profilePath, const ProjectExplorer::Kit *k,
const QString &suffix);
/// \internal for qmakestep
// used by qmake step to notify that the qmake args have changed
// not really nice, the build configuration should save the arguments
......
......@@ -45,7 +45,6 @@
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/documentmanager.h>
#include <cpptools/cppmodelmanager.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <projectexplorer/buildmanager.h>
......@@ -55,7 +54,6 @@
#include <projectexplorer/headerpath.h>
#include <projectexplorer/target.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectmacroexpander.h>
#include <proparser/qmakevfs.h>
#include <qtsupport/profilereader.h>
#include <qtsupport/qtkitinformation.h>
......@@ -1442,23 +1440,6 @@ QString QmakeProject::disabledReasonForRunConfiguration(const QString &proFilePa
.arg(QFileInfo(proFilePath).fileName());
}
QString QmakeProject::shadowBuildDirectory(const QString &proFilePath, const Kit *k, const QString &suffix)
{
if (proFilePath.isEmpty())
return QString();
QFileInfo info(proFilePath);
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(k);
if (version && !version->supportsShadowBuilds())
return info.absolutePath();
const QString projectName = QFileInfo(proFilePath).completeBaseName();
ProjectExplorer::ProjectMacroExpander expander(proFilePath, projectName, k, suffix);
QString projectDir = projectDirectory(Utils::FileName::fromString(proFilePath)).toString();
QString buildPath = expander.expand(Core::DocumentManager::buildDirectory());
return Utils::FileUtils::resolvePath(projectDir, buildPath);
}
QString QmakeProject::buildNameFor(const Kit *k)
{
if (!k)
......
......@@ -132,9 +132,6 @@ public:
/// \internal
QString disabledReasonForRunConfiguration(const QString &proFilePath);
/// suffix should be unique
static QString shadowBuildDirectory(const QString &profilePath, const ProjectExplorer::Kit *k,
const QString &suffix);
/// used by the default implementation of shadowBuildDirectory
static QString buildNameFor(const ProjectExplorer::Kit *k);
......
......@@ -51,9 +51,9 @@ QmakeProjectConfigWidget::QmakeProjectConfigWidget(QmakeBuildConfiguration *bc)
m_ignoreChange(false)
{
m_defaultShadowBuildDir
= QmakeProject::shadowBuildDirectory(bc->target()->project()->projectFilePath().toString(),
bc->target()->kit(),
Utils::FileUtils::qmakeFriendlyName(bc->displayName()));
= QmakeBuildConfiguration::shadowBuildDirectory(bc->target()->project()->projectFilePath().toString(),
bc->target()->kit(),
Utils::FileUtils::qmakeFriendlyName(bc->displayName()));
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->setMargin(0);
......
......@@ -213,7 +213,7 @@ QStringList QmakeProjectImporter::importCandidates(const Utils::FileName &projec
QList<ProjectExplorer::Kit *> kitList = ProjectExplorer::KitManager::kits();
foreach (ProjectExplorer::Kit *k, kitList) {
QFileInfo fi(QmakeProject::shadowBuildDirectory(projectPath.toString(), k, QString()));
QFileInfo fi(QmakeBuildConfiguration::shadowBuildDirectory(projectPath.toString(), k, QString()));
const QString baseDir = fi.absolutePath();
foreach (const QString &dir, QDir(baseDir).entryList()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment