diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp index 8e064aaf989..2d60f326450 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp @@ -52,7 +52,6 @@ #include #include #include -#include #include #include @@ -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) diff --git a/src/plugins/mesonprojectmanager/project/mesonbuildconfiguration.cpp b/src/plugins/mesonprojectmanager/project/mesonbuildconfiguration.cpp index 518726cb548..b603f856b35 100644 --- a/src/plugins/mesonprojectmanager/project/mesonbuildconfiguration.cpp +++ b/src/plugins/mesonprojectmanager/project/mesonbuildconfiguration.cpp @@ -39,13 +39,15 @@ #include #include #include -#include #include #include #include +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 diff --git a/src/plugins/nim/project/nimblebuildconfiguration.cpp b/src/plugins/nim/project/nimblebuildconfiguration.cpp index 8bc91193025..13756bc72a4 100644 --- a/src/plugins/nim/project/nimblebuildconfiguration.cpp +++ b/src/plugins/nim/project/nimblebuildconfiguration.cpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include diff --git a/src/plugins/nim/project/nimbuildconfiguration.cpp b/src/plugins/nim/project/nimbuildconfiguration.cpp index ae421b738da..e27b1374f24 100644 --- a/src/plugins/nim/project/nimbuildconfiguration.cpp +++ b/src/plugins/nim/project/nimbuildconfiguration.cpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include @@ -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) diff --git a/src/plugins/projectexplorer/CMakeLists.txt b/src/plugins/projectexplorer/CMakeLists.txt index 2bae7add9ca..6e2970af9ab 100644 --- a/src/plugins/projectexplorer/CMakeLists.txt +++ b/src/plugins/projectexplorer/CMakeLists.txt @@ -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 diff --git a/src/plugins/projectexplorer/buildconfiguration.cpp b/src/plugins/projectexplorer/buildconfiguration.cpp index 9610dacd333..e66d5ac0768 100644 --- a/src/plugins/projectexplorer/buildconfiguration.cpp +++ b/src/plugins/projectexplorer/buildconfiguration.cpp @@ -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 /// diff --git a/src/plugins/projectexplorer/buildconfiguration.h b/src/plugins/projectexplorer/buildconfiguration.h index 7bf743367f7..d3df3e21ea4 100644 --- a/src/plugins/projectexplorer/buildconfiguration.h +++ b/src/plugins/projectexplorer/buildconfiguration.h @@ -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(); diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp index 07c78e61155..26bb877d12d 100644 --- a/src/plugins/projectexplorer/project.cpp +++ b/src/plugins/projectexplorer/project.cpp @@ -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); diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro index 07ecca97b8b..c2ff07180d0 100644 --- a/src/plugins/projectexplorer/projectexplorer.pro +++ b/src/plugins/projectexplorer/projectexplorer.pro @@ -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 \ diff --git a/src/plugins/projectexplorer/projectexplorer.qbs b/src/plugins/projectexplorer/projectexplorer.qbs index e6e64c98fa9..7967b2a3546 100644 --- a/src/plugins/projectexplorer/projectexplorer.qbs +++ b/src/plugins/projectexplorer/projectexplorer.qbs @@ -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", diff --git a/src/plugins/projectexplorer/projectmacroexpander.cpp b/src/plugins/projectexplorer/projectmacroexpander.cpp deleted file mode 100644 index 93d63ce89ce..00000000000 --- a/src/plugins/projectexplorer/projectmacroexpander.cpp +++ /dev/null @@ -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 diff --git a/src/plugins/projectexplorer/projectmacroexpander.h b/src/plugins/projectexplorer/projectmacroexpander.h deleted file mode 100644 index 59028ddd9cd..00000000000 --- a/src/plugins/projectexplorer/projectmacroexpander.h +++ /dev/null @@ -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 - -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 diff --git a/src/plugins/qbsprojectmanager/qbsbuildconfiguration.cpp b/src/plugins/qbsprojectmanager/qbsbuildconfiguration.cpp index 7760b9dbb0d..c4f087b9ee4 100644 --- a/src/plugins/qbsprojectmanager/qbsbuildconfiguration.cpp +++ b/src/plugins/qbsprojectmanager/qbsbuildconfiguration.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include #include @@ -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); } // --------------------------------------------------------------------------- diff --git a/src/plugins/qbsprojectmanager/qbsprojectimporter.cpp b/src/plugins/qbsprojectmanager/qbsprojectimporter.cpp index eded9e977bb..db2b48d6489 100644 --- a/src/plugins/qbsprojectmanager/qbsprojectimporter.cpp +++ b/src/plugins/qbsprojectmanager/qbsprojectimporter.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include @@ -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) diff --git a/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.cpp b/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.cpp index 8fffcc56b88..beef0a160d9 100644 --- a/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.cpp +++ b/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.cpp @@ -49,7 +49,6 @@ #include #include #include -#include #include #include @@ -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";