Files
qt-creator/src/plugins/cmakeprojectmanager/cmakerunconfiguration.cpp

122 lines
4.3 KiB
C++
Raw Normal View History

/****************************************************************************
**
** 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.
2010-12-17 16:01:08 +01:00
**
****************************************************************************/
#include "cmakerunconfiguration.h"
2008-12-09 15:25:01 +01:00
#include "cmakeprojectconstants.h"
#include <qtsupport/qtkitinformation.h>
#include <qtsupport/qtoutputformatter.h>
#include <projectexplorer/localenvironmentaspect.h>
#include <projectexplorer/project.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h>
2011-02-28 16:50:14 +01:00
using namespace ProjectExplorer;
namespace CMakeProjectManager {
namespace Internal {
CMakeRunConfiguration::CMakeRunConfiguration(Target *target, Core::Id id)
: RunConfiguration(target, id)
{
// Workaround for QTCREATORBUG-19354:
auto cmakeRunEnvironmentModifier = [target](Utils::Environment &env) {
if (!Utils::HostOsInfo::isWindowsHost())
return;
const Kit *k = target->kit();
const QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(k);
if (qt)
env.prependOrSetPath(qt->qmakeProperty("QT_INSTALL_BINS"));
};
auto envAspect = addAspect<LocalEnvironmentAspect>(target, cmakeRunEnvironmentModifier);
addAspect<ExecutableAspect>();
addAspect<ArgumentsAspect>();
addAspect<WorkingDirectoryAspect>(envAspect);
addAspect<TerminalAspect>();
connect(target->project(), &Project::parsingFinished,
this, &CMakeRunConfiguration::updateTargetInformation);
if (QtSupport::QtKitInformation::qtVersion(target->kit()))
setOutputFormatter<QtSupport::QtOutputFormatter>();
}
2009-11-26 14:43:27 +01:00
void CMakeRunConfiguration::doAdditionalSetup(const RunConfigurationCreationInfo &info)
{
Q_UNUSED(info);
updateTargetInformation();
}
bool CMakeRunConfiguration::isBuildTargetValid() const
{
return Utils::anyOf(target()->applicationTargets().list, [this](const BuildTargetInfo &bti) {
ProjectExplorer: Consolidate RunConfiguration identifications The previously per-Project/RunConfiguration changing meanings of BuildTargetInfo::buildTarget have by now been split into separate values in BuildTargetInfo: - buildKey a handle to one item in Target::applicationTargetList - displayName a user-visible string in the run settings page The buildKey was tweaked to coincide with the previous 'extraId', i.e. the non-RunConfiguration-type part of the project configuration id that (still) use id mangling. This allows replacing the cases of locally stored seven different versions of buildKey(-ish) data by one RunConfiguration::m_buildKey, and do all remaining extraId handling in RC::{from,to}Map only, i.e. remove the base ProjectConfiguration::extraId() virtual and remove the "re-try fromMap with mangled id" hack entirely. The id mangling is still used to temporarily maintain .user file compatibility in some cases for now, but should be replaced by storing the build key and the RunConfiguration type soon. Qbs already changes in here to only use the uniqueProductName as buildKey, without the previously added display name which is stored as part of the ProjectConfiguration already. It turns out that RunConfiguration::buildSystemTarget was intended and used to retrieve an item from the Target::applicationTargetList for some configurations, coinciding with what buildKey does always. So use that insteand and drop RunConfiguration::buildSystemTarget. There is clearly is further consolidation potential left. handling of (default)displayNames is still a per-runconfiguration mess and there is further consolidation potential left. Change-Id: I448ed30f1b562fb91b970e328a42fa5f6fb2e43e Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2018-04-09 12:33:10 +02:00
return bti.buildKey == buildKey();
});
}
void CMakeRunConfiguration::updateEnabledState()
{
if (!isBuildTargetValid())
setEnabled(false);
else
RunConfiguration::updateEnabledState();
}
QString CMakeRunConfiguration::disabledReason() const
{
if (!isBuildTargetValid())
return tr("The project no longer builds the target associated with this run configuration.");
return RunConfiguration::disabledReason();
}
void CMakeRunConfiguration::updateTargetInformation()
{
ProjectExplorer: Consolidate RunConfiguration identifications The previously per-Project/RunConfiguration changing meanings of BuildTargetInfo::buildTarget have by now been split into separate values in BuildTargetInfo: - buildKey a handle to one item in Target::applicationTargetList - displayName a user-visible string in the run settings page The buildKey was tweaked to coincide with the previous 'extraId', i.e. the non-RunConfiguration-type part of the project configuration id that (still) use id mangling. This allows replacing the cases of locally stored seven different versions of buildKey(-ish) data by one RunConfiguration::m_buildKey, and do all remaining extraId handling in RC::{from,to}Map only, i.e. remove the base ProjectConfiguration::extraId() virtual and remove the "re-try fromMap with mangled id" hack entirely. The id mangling is still used to temporarily maintain .user file compatibility in some cases for now, but should be replaced by storing the build key and the RunConfiguration type soon. Qbs already changes in here to only use the uniqueProductName as buildKey, without the previously added display name which is stored as part of the ProjectConfiguration already. It turns out that RunConfiguration::buildSystemTarget was intended and used to retrieve an item from the Target::applicationTargetList for some configurations, coinciding with what buildKey does always. So use that insteand and drop RunConfiguration::buildSystemTarget. There is clearly is further consolidation potential left. handling of (default)displayNames is still a per-runconfiguration mess and there is further consolidation potential left. Change-Id: I448ed30f1b562fb91b970e328a42fa5f6fb2e43e Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2018-04-09 12:33:10 +02:00
BuildTargetInfo bti = target()->applicationTargets().buildTargetInfo(buildKey());
extraAspect<ExecutableAspect>()->setExecutable(bti.targetFilePath);
extraAspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(bti.workingDirectory);
extraAspect<LocalEnvironmentAspect>()->buildEnvironmentHasChanged();
auto terminalAspect = extraAspect<TerminalAspect>();
if (!terminalAspect->isUserSet())
terminalAspect->setUseTerminal(bti.usesTerminal);
}
// Factory
CMakeRunConfigurationFactory::CMakeRunConfigurationFactory()
{
registerRunConfiguration<CMakeRunConfiguration>("CMakeProjectManager.CMakeRunConfiguration.");
addSupportedProjectType(CMakeProjectManager::Constants::CMAKEPROJECT_ID);
addSupportedTargetDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE);
addRunWorkerFactory<SimpleTargetRunner>(ProjectExplorer::Constants::NORMAL_RUN_MODE);
}
} // Internal
} // CMakeProjectManager