forked from qt-creator/qt-creator
ProjectExplorer: Streamline access to buildDirectoryTemplate data
There's only one kind of use, in the context of BuildConfiguration. Change-Id: I09628ff443ef08e28738125a614c17d5d979189b Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -52,7 +52,6 @@
|
||||
#include <projectexplorer/namedwidget.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectmacroexpander.h>
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
#include <qtsupport/baseqtversion.h>
|
||||
@@ -1067,15 +1066,17 @@ FilePath CMakeBuildConfiguration::shadowBuildDirectory(const FilePath &projectFi
|
||||
return FilePath();
|
||||
|
||||
const QString projectName = projectFilePath.parentDir().fileName();
|
||||
ProjectMacroExpander expander(projectFilePath, projectName, k, bcName, buildType);
|
||||
const FilePath projectDir = Project::projectDirectory(projectFilePath);
|
||||
QString buildPath = expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate());
|
||||
buildPath.replace(" ", "-");
|
||||
FilePath buildPath = BuildConfiguration::buildDirectoryFromTemplate(projectDir,
|
||||
projectFilePath, projectName, k, bcName, buildType, BuildConfiguration::ReplaceSpaces);
|
||||
|
||||
if (CMakeGeneratorKitAspect::isMultiConfigGenerator(k))
|
||||
buildPath = buildPath.left(buildPath.lastIndexOf(QString("-%1").arg(bcName)));
|
||||
if (CMakeGeneratorKitAspect::isMultiConfigGenerator(k)) {
|
||||
QString path = buildPath.path();
|
||||
path = path.left(path.lastIndexOf(QString("-%1").arg(bcName)));
|
||||
buildPath.setPath(path);
|
||||
}
|
||||
|
||||
return projectDir.resolvePath(buildPath);
|
||||
return buildPath;
|
||||
}
|
||||
|
||||
void CMakeBuildConfiguration::buildTarget(const QString &buildTarget)
|
||||
|
@@ -39,13 +39,15 @@
|
||||
#include <projectexplorer/kit.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/projectmacroexpander.h>
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
#include <QDir>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace MesonProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
@@ -72,26 +74,18 @@ MesonBuildConfiguration::~MesonBuildConfiguration()
|
||||
delete m_buildSystem;
|
||||
}
|
||||
|
||||
Utils::FilePath MesonBuildConfiguration::shadowBuildDirectory(
|
||||
const Utils::FilePath &projectFilePath,
|
||||
const ProjectExplorer::Kit *k,
|
||||
const QString &bcName,
|
||||
ProjectExplorer::BuildConfiguration::BuildType buildType)
|
||||
FilePath MesonBuildConfiguration::shadowBuildDirectory(const FilePath &projectFilePath,
|
||||
const Kit *k,
|
||||
const QString &bcName,
|
||||
BuildConfiguration::BuildType buildType)
|
||||
{
|
||||
if (projectFilePath.isEmpty())
|
||||
return Utils::FilePath();
|
||||
return {};
|
||||
|
||||
const QString projectName = projectFilePath.parentDir().fileName();
|
||||
ProjectExplorer::ProjectMacroExpander expander(projectFilePath,
|
||||
projectName,
|
||||
k,
|
||||
bcName,
|
||||
buildType);
|
||||
QDir projectDir = QDir(ProjectExplorer::Project::projectDirectory(projectFilePath).toString());
|
||||
QString buildPath = expander.expand(
|
||||
ProjectExplorer::ProjectExplorerPlugin::buildDirectoryTemplate());
|
||||
buildPath.replace(" ", "-");
|
||||
return Utils::FilePath::fromUserInput(projectDir.absoluteFilePath(buildPath));
|
||||
return BuildConfiguration::buildDirectoryFromTemplate(
|
||||
Project::projectDirectory(projectFilePath),
|
||||
projectFilePath, projectName, k, bcName, buildType, BuildConfiguration::ReplaceSpaces);
|
||||
}
|
||||
|
||||
ProjectExplorer::BuildSystem *MesonBuildConfiguration::buildSystem() const
|
||||
|
@@ -36,7 +36,6 @@
|
||||
#include <projectexplorer/kit.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/projectmacroexpander.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/osspecificaspects.h>
|
||||
|
||||
|
@@ -36,7 +36,6 @@
|
||||
#include <projectexplorer/kit.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectmacroexpander.h>
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
#include <utils/aspects.h>
|
||||
@@ -53,17 +52,9 @@ static FilePath defaultBuildDirectory(const Kit *k,
|
||||
const QString &bc,
|
||||
BuildConfiguration::BuildType buildType)
|
||||
{
|
||||
QFileInfo projectFileInfo = projectFilePath.toFileInfo();
|
||||
|
||||
ProjectMacroExpander expander(projectFilePath,
|
||||
projectFileInfo.baseName(), k, bc, buildType);
|
||||
QString buildDirectory = expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate());
|
||||
|
||||
if (FileUtils::isAbsolutePath(buildDirectory))
|
||||
return FilePath::fromString(buildDirectory);
|
||||
|
||||
auto projectDir = FilePath::fromString(projectFileInfo.absoluteDir().absolutePath());
|
||||
return projectDir.pathAppended(buildDirectory);
|
||||
return BuildConfiguration::buildDirectoryFromTemplate(
|
||||
projectFilePath.parentDir(), projectFilePath, projectFilePath.baseName(),
|
||||
k, bc, buildType);
|
||||
}
|
||||
|
||||
NimBuildConfiguration::NimBuildConfiguration(Target *target, Utils::Id id)
|
||||
|
@@ -139,7 +139,6 @@ add_qtc_plugin(ProjectExplorer
|
||||
projectfilewizardextension.cpp projectfilewizardextension.h
|
||||
projectimporter.cpp projectimporter.h
|
||||
projectmacro.cpp projectmacro.h
|
||||
projectmacroexpander.cpp projectmacroexpander.h
|
||||
projectmanager.h
|
||||
projectmodels.cpp projectmodels.h
|
||||
projectnodes.cpp projectnodes.h
|
||||
|
@@ -39,7 +39,6 @@
|
||||
#include "projectexplorerconstants.h"
|
||||
#include "projectexplorer.h"
|
||||
#include "project.h"
|
||||
#include "projectmacroexpander.h"
|
||||
#include "projecttree.h"
|
||||
#include "session.h"
|
||||
#include "target.h"
|
||||
@@ -599,6 +598,52 @@ bool BuildConfiguration::isActive() const
|
||||
return target()->isActive() && target()->activeBuildConfiguration() == this;
|
||||
}
|
||||
|
||||
FilePath BuildConfiguration::buildDirectoryFromTemplate(const FilePath &projectDir,
|
||||
const FilePath &mainFilePath,
|
||||
const QString &projectName,
|
||||
const Kit *kit,
|
||||
const QString &bcName,
|
||||
BuildType buildType,
|
||||
SpaceHandling spaceHandling)
|
||||
{
|
||||
MacroExpander exp;
|
||||
|
||||
// TODO: Remove "Current" variants in ~4.16
|
||||
exp.registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX,
|
||||
QCoreApplication::translate("ProjectExplorer", "Main file of current project"),
|
||||
[mainFilePath] { return mainFilePath; }, false);
|
||||
exp.registerFileVariables("Project",
|
||||
QCoreApplication::translate("ProjectExplorer", "Main file of the project"),
|
||||
[mainFilePath] { return mainFilePath; });
|
||||
exp.registerVariable(Constants::VAR_CURRENTPROJECT_NAME,
|
||||
QCoreApplication::translate("ProjectExplorer", "Name of current project"),
|
||||
[projectName] { return projectName; }, false);
|
||||
exp.registerVariable("Project:Name",
|
||||
QCoreApplication::translate("ProjectExplorer", "Name of the project"),
|
||||
[projectName] { return projectName; });
|
||||
exp.registerVariable(Constants::VAR_CURRENTBUILD_NAME,
|
||||
QCoreApplication::translate("ProjectExplorer", "Name of current build"),
|
||||
[bcName] { return bcName; }, false);
|
||||
exp.registerVariable("BuildConfig:Name",
|
||||
QCoreApplication::translate(
|
||||
"ProjectExplorer", "Name of the project's active build configuration"),
|
||||
[bcName] { return bcName; });
|
||||
exp.registerVariable("CurrentBuild:Type",
|
||||
QCoreApplication::translate("ProjectExplorer", "Type of current build"),
|
||||
[buildType] { return buildTypeName(buildType); }, false);
|
||||
exp.registerVariable("BuildConfig:Type",
|
||||
QCoreApplication::translate(
|
||||
"ProjectExplorer", "Type of the project's active build configuration"),
|
||||
[buildType] { return buildTypeName(buildType); });
|
||||
exp.registerSubProvider([kit] { return kit->macroExpander(); });
|
||||
|
||||
QString buildDir = ProjectExplorerPlugin::buildDirectoryTemplate();
|
||||
buildDir = exp.expand(buildDir);
|
||||
if (spaceHandling == ReplaceSpaces)
|
||||
buildDir.replace(" ", "-");
|
||||
|
||||
return projectDir.resolvePath(buildDir);
|
||||
}
|
||||
///
|
||||
// IBuildConfigurationFactory
|
||||
///
|
||||
|
@@ -110,6 +110,15 @@ public:
|
||||
|
||||
static QString buildTypeName(BuildType type);
|
||||
|
||||
enum SpaceHandling { KeepSpace, ReplaceSpaces };
|
||||
static Utils::FilePath buildDirectoryFromTemplate(const Utils::FilePath &projectDir,
|
||||
const Utils::FilePath &mainFilePath,
|
||||
const QString &projectName,
|
||||
const Kit *kit,
|
||||
const QString &bcName,
|
||||
BuildType buildType,
|
||||
SpaceHandling spaceHandling = ReplaceSpaces);
|
||||
|
||||
bool isActive() const;
|
||||
|
||||
void updateCacheAndEmitEnvironmentChanged();
|
||||
|
@@ -34,7 +34,6 @@
|
||||
#include "kitinformation.h"
|
||||
#include "makestep.h"
|
||||
#include "projectexplorer.h"
|
||||
#include "projectmacroexpander.h"
|
||||
#include "projectnodes.h"
|
||||
#include "runconfiguration.h"
|
||||
#include "runcontrol.h"
|
||||
@@ -450,17 +449,16 @@ bool Project::copySteps(Target *sourceTarget, Target *newTarget)
|
||||
|
||||
const Project * const project = newTarget->project();
|
||||
for (BuildConfiguration *sourceBc : sourceTarget->buildConfigurations()) {
|
||||
ProjectMacroExpander expander(project->projectFilePath(), project->displayName(),
|
||||
newTarget->kit(), sourceBc->displayName(),
|
||||
sourceBc->buildType());
|
||||
BuildConfiguration *newBc = BuildConfigurationFactory::clone(newTarget, sourceBc);
|
||||
if (!newBc) {
|
||||
buildconfigurationError << sourceBc->displayName();
|
||||
continue;
|
||||
}
|
||||
newBc->setDisplayName(sourceBc->displayName());
|
||||
newBc->setBuildDirectory(project->projectDirectory()
|
||||
.resolvePath(expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate())));
|
||||
newBc->setBuildDirectory(BuildConfiguration::buildDirectoryFromTemplate(
|
||||
project->projectDirectory(), project->projectFilePath(),
|
||||
project->displayName(), newTarget->kit(),
|
||||
sourceBc->displayName(), sourceBc->buildType()));
|
||||
newTarget->addBuildConfiguration(newBc);
|
||||
if (sourceTarget->activeBuildConfiguration() == sourceBc)
|
||||
SessionManager::setActiveBuildConfiguration(newTarget, newBc, SetActive::NoCascade);
|
||||
|
@@ -142,7 +142,6 @@ HEADERS += projectexplorer.h \
|
||||
deploymentdataview.h \
|
||||
buildtargetinfo.h \
|
||||
customtoolchain.h \
|
||||
projectmacroexpander.h \
|
||||
customparser.h \
|
||||
customparserconfigdialog.h \
|
||||
ipotentialkit.h \
|
||||
@@ -290,7 +289,6 @@ SOURCES += projectexplorer.cpp \
|
||||
deploymentdata.cpp \
|
||||
deploymentdataview.cpp \
|
||||
customtoolchain.cpp \
|
||||
projectmacroexpander.cpp \
|
||||
customparser.cpp \
|
||||
customparserconfigdialog.cpp \
|
||||
msvcparser.cpp \
|
||||
|
@@ -118,7 +118,6 @@ Project {
|
||||
"projectfilewizardextension.cpp", "projectfilewizardextension.h",
|
||||
"projectimporter.cpp", "projectimporter.h",
|
||||
"projectmacro.cpp", "projectmacro.h",
|
||||
"projectmacroexpander.cpp", "projectmacroexpander.h",
|
||||
"projectmanager.h",
|
||||
"projectmodels.cpp", "projectmodels.h",
|
||||
"projectnodes.cpp", "projectnodes.h",
|
||||
|
@@ -1,66 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "projectmacroexpander.h"
|
||||
#include "kit.h"
|
||||
#include "projectexplorerconstants.h"
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
ProjectMacroExpander::ProjectMacroExpander(const Utils::FilePath &mainFilePath, const QString &projectName,
|
||||
const Kit *kit, const QString &bcName,
|
||||
BuildConfiguration::BuildType buildType)
|
||||
{
|
||||
// TODO: Remove "Current" variants in ~4.16
|
||||
registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX,
|
||||
QCoreApplication::translate("ProjectExplorer", "Main file of current project"),
|
||||
[mainFilePath] { return mainFilePath; }, false);
|
||||
registerFileVariables("Project",
|
||||
QCoreApplication::translate("ProjectExplorer", "Main file of the project"),
|
||||
[mainFilePath] { return mainFilePath; });
|
||||
registerVariable(Constants::VAR_CURRENTPROJECT_NAME,
|
||||
QCoreApplication::translate("ProjectExplorer", "Name of current project"),
|
||||
[projectName] { return projectName; }, false);
|
||||
registerVariable("Project:Name",
|
||||
QCoreApplication::translate("ProjectExplorer", "Name of the project"),
|
||||
[projectName] { return projectName; });
|
||||
registerVariable(Constants::VAR_CURRENTBUILD_NAME,
|
||||
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; });
|
||||
registerVariable("CurrentBuild:Type",
|
||||
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); });
|
||||
registerSubProvider([kit] { return kit->macroExpander(); });
|
||||
}
|
||||
|
||||
} // namespace ProjectExplorer
|
@@ -1,47 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "projectexplorer_export.h"
|
||||
|
||||
#include "buildconfiguration.h"
|
||||
|
||||
#include <utils/macroexpander.h>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class Kit;
|
||||
|
||||
class PROJECTEXPLORER_EXPORT ProjectMacroExpander : public Utils::MacroExpander
|
||||
{
|
||||
public:
|
||||
ProjectMacroExpander(const Utils::FilePath &mainFilePath,
|
||||
const QString &projectName,
|
||||
const Kit *kit,
|
||||
const QString &bcName,
|
||||
BuildConfiguration::BuildType buildType);
|
||||
};
|
||||
|
||||
} // namespace ProjectExplorer
|
@@ -41,7 +41,6 @@
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectmacroexpander.h>
|
||||
#include <projectexplorer/target.h>
|
||||
#include <projectexplorer/toolchain.h>
|
||||
|
||||
@@ -65,10 +64,9 @@ static FilePath defaultBuildDirectory(const FilePath &projectFilePath, const Kit
|
||||
BuildConfiguration::BuildType buildType)
|
||||
{
|
||||
const QString projectName = projectFilePath.completeBaseName();
|
||||
ProjectMacroExpander expander(projectFilePath, projectName, k, bcName, buildType);
|
||||
FilePath projectDir = Project::projectDirectory(projectFilePath);
|
||||
QString buildPath = expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate());
|
||||
return projectDir.resolvePath(buildPath);
|
||||
return BuildConfiguration::buildDirectoryFromTemplate(
|
||||
Project::projectDirectory(projectFilePath),
|
||||
projectFilePath, projectName, k, bcName, buildType);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
@@ -37,7 +37,6 @@
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectmacroexpander.h>
|
||||
#include <projectexplorer/toolchain.h>
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
#include <utils/fileutils.h>
|
||||
@@ -89,11 +88,9 @@ QbsProjectImporter::QbsProjectImporter(const FilePath &path) : QtProjectImporter
|
||||
static FilePath buildDir(const FilePath &projectFilePath, const Kit *k)
|
||||
{
|
||||
const QString projectName = projectFilePath.completeBaseName();
|
||||
ProjectMacroExpander expander(projectFilePath, projectName, k, QString(),
|
||||
BuildConfiguration::Unknown);
|
||||
const FilePath projectDir = Project::projectDirectory(projectFilePath);
|
||||
const QString buildPath = expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate());
|
||||
return projectDir.resolvePath(buildPath);
|
||||
return BuildConfiguration::buildDirectoryFromTemplate(
|
||||
Project::projectDirectory(projectFilePath),
|
||||
projectFilePath, projectName, k, QString(), BuildConfiguration::Unknown);
|
||||
}
|
||||
|
||||
static bool hasBuildGraph(const QString &dir)
|
||||
|
@@ -49,7 +49,6 @@
|
||||
#include <projectexplorer/makestep.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectmacroexpander.h>
|
||||
#include <projectexplorer/target.h>
|
||||
#include <projectexplorer/toolchain.h>
|
||||
|
||||
@@ -106,10 +105,8 @@ FilePath QmakeBuildConfiguration::shadowBuildDirectory(const FilePath &proFilePa
|
||||
return {};
|
||||
|
||||
const QString projectName = proFilePath.completeBaseName();
|
||||
ProjectMacroExpander expander(proFilePath, projectName, k, suffix, buildType);
|
||||
FilePath projectDir = Project::projectDirectory(proFilePath);
|
||||
QString buildPath = expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate());
|
||||
return projectDir.resolvePath(buildPath);
|
||||
return BuildConfiguration::buildDirectoryFromTemplate(
|
||||
Project::projectDirectory(proFilePath), proFilePath, projectName, k, suffix, buildType);
|
||||
}
|
||||
|
||||
const char BUILD_CONFIGURATION_KEY[] = "Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration";
|
||||
|
Reference in New Issue
Block a user