2013-01-30 18:19:31 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-01-30 18:19:31 +01:00
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2013-01-30 18:19:31 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2013-01-30 18:19:31 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "qbsbuildconfiguration.h"
|
|
|
|
|
|
|
|
|
|
#include "qbsbuildconfigurationwidget.h"
|
|
|
|
|
#include "qbsbuildstep.h"
|
|
|
|
|
#include "qbscleanstep.h"
|
|
|
|
|
#include "qbsproject.h"
|
|
|
|
|
#include "qbsprojectmanagerconstants.h"
|
2016-02-22 17:49:02 +01:00
|
|
|
#include "qbsprojectmanagersettings.h"
|
2013-01-30 18:19:31 +01:00
|
|
|
|
2014-10-22 09:16:55 +02:00
|
|
|
#include <coreplugin/documentmanager.h>
|
2013-07-22 15:53:57 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2013-01-30 18:19:31 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2015-10-22 16:55:17 +02:00
|
|
|
#include <projectexplorer/buildinfo.h>
|
2013-01-30 18:19:31 +01:00
|
|
|
#include <projectexplorer/buildsteplist.h>
|
|
|
|
|
#include <projectexplorer/kit.h>
|
|
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2014-10-22 09:16:55 +02:00
|
|
|
#include <projectexplorer/projectmacroexpander.h>
|
2013-01-30 18:19:31 +01:00
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
#include <projectexplorer/toolchain.h>
|
2015-02-04 09:32:46 +01:00
|
|
|
#include <utils/mimetypes/mimedatabase.h>
|
2015-01-30 13:52:46 +01:00
|
|
|
#include <utils/qtcprocess.h>
|
2013-01-30 18:19:31 +01:00
|
|
|
|
2015-01-30 13:52:46 +01:00
|
|
|
#include <QCoreApplication>
|
2013-01-30 18:19:31 +01:00
|
|
|
#include <QInputDialog>
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
using namespace ProjectExplorer;
|
2013-01-30 18:19:31 +01:00
|
|
|
|
|
|
|
|
namespace QbsProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
const char QBS_BC_ID[] = "Qbs.QbsBuildConfiguration";
|
|
|
|
|
|
2013-01-30 18:19:31 +01:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// QbsBuildConfiguration:
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
QbsBuildConfiguration::QbsBuildConfiguration(Target *target) :
|
2013-01-30 18:19:31 +01:00
|
|
|
BuildConfiguration(target, Core::Id(QBS_BC_ID)),
|
|
|
|
|
m_isParsing(true),
|
|
|
|
|
m_parsingError(false)
|
|
|
|
|
{
|
2014-10-21 18:10:39 +02:00
|
|
|
connect(project(), &QbsProject::projectParsingStarted, this, &BuildConfiguration::enabledChanged);
|
|
|
|
|
connect(project(), &QbsProject::projectParsingDone, this, &BuildConfiguration::enabledChanged);
|
2013-01-30 18:19:31 +01:00
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
BuildStepList *bsl = stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
|
|
|
|
|
connect(bsl, &BuildStepList::stepInserted, this, &QbsBuildConfiguration::buildStepInserted);
|
2013-01-30 18:19:31 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
QbsBuildConfiguration::QbsBuildConfiguration(Target *target, Core::Id id) :
|
2013-01-30 18:19:31 +01:00
|
|
|
BuildConfiguration(target, id)
|
|
|
|
|
{ }
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
QbsBuildConfiguration::QbsBuildConfiguration(Target *target, QbsBuildConfiguration *source) :
|
2013-08-16 17:45:16 +02:00
|
|
|
BuildConfiguration(target, source)
|
2013-01-30 18:19:31 +01:00
|
|
|
{
|
|
|
|
|
cloneSteps(source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QbsBuildConfiguration::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
if (!BuildConfiguration::fromMap(map))
|
|
|
|
|
return false;
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
BuildStepList *bsl = stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
|
2013-01-30 18:19:31 +01:00
|
|
|
// Fix up the existing build steps:
|
|
|
|
|
for (int i = 0; i < bsl->count(); ++i) {
|
|
|
|
|
QbsBuildStep *bs = qobject_cast<QbsBuildStep *>(bsl->at(i));
|
|
|
|
|
if (bs)
|
2014-10-21 18:10:39 +02:00
|
|
|
connect(bs, &QbsBuildStep::qbsConfigurationChanged, this, &QbsBuildConfiguration::qbsConfigurationChanged);
|
2013-01-30 18:19:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QbsBuildConfiguration::buildStepInserted(int pos)
|
|
|
|
|
{
|
|
|
|
|
QbsBuildStep *step = qobject_cast<QbsBuildStep *>(stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD)->at(pos));
|
|
|
|
|
if (step) {
|
2014-10-21 18:10:39 +02:00
|
|
|
connect(step, &QbsBuildStep::qbsConfigurationChanged, this, &QbsBuildConfiguration::qbsConfigurationChanged);
|
2013-01-30 18:19:31 +01:00
|
|
|
emit qbsConfigurationChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
NamedWidget *QbsBuildConfiguration::createConfigWidget()
|
2013-01-30 18:19:31 +01:00
|
|
|
{
|
|
|
|
|
return new QbsBuildConfigurationWidget(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QbsBuildStep *QbsBuildConfiguration::qbsStep() const
|
|
|
|
|
{
|
2016-04-19 12:36:11 +02:00
|
|
|
return stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD)->firstOfType<QbsBuildStep>();
|
2013-01-30 18:19:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap QbsBuildConfiguration::qbsConfiguration() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap config;
|
|
|
|
|
QbsBuildStep *qbsBs = qbsStep();
|
|
|
|
|
if (qbsBs)
|
2016-10-23 06:01:41 +03:00
|
|
|
config = qbsBs->qbsConfiguration(QbsBuildStep::ExpandVariables);
|
2013-01-30 18:19:31 +01:00
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Internal::QbsProject *QbsBuildConfiguration::project() const
|
|
|
|
|
{
|
|
|
|
|
return qobject_cast<Internal::QbsProject *>(target()->project());
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
IOutputParser *QbsBuildConfiguration::createOutputParser() const
|
2013-01-30 18:19:31 +01:00
|
|
|
{
|
2016-12-16 00:43:14 +01:00
|
|
|
ToolChain *tc = ToolChainKitInformation::toolChain(target()->kit(), ProjectExplorer::Constants::CXX_LANGUAGE_ID);
|
2013-01-30 18:19:31 +01:00
|
|
|
return tc ? tc->outputParser() : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QbsBuildConfiguration::isEnabled() const
|
|
|
|
|
{
|
|
|
|
|
return !project()->isParsing() && project()->hasParseResult();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString QbsBuildConfiguration::disabledReason() const
|
|
|
|
|
{
|
|
|
|
|
if (project()->isParsing())
|
|
|
|
|
return tr("Parsing the Qbs project.");
|
|
|
|
|
if (!project()->hasParseResult())
|
|
|
|
|
return tr("Parsing of Qbs project has failed.");
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
BuildConfiguration::BuildType QbsBuildConfiguration::buildType() const
|
2013-01-30 18:19:31 +01:00
|
|
|
{
|
|
|
|
|
QString variant;
|
|
|
|
|
if (qbsStep())
|
|
|
|
|
variant = qbsStep()->buildVariant();
|
|
|
|
|
|
|
|
|
|
if (variant == QLatin1String(Constants::QBS_VARIANT_DEBUG))
|
|
|
|
|
return Debug;
|
|
|
|
|
if (variant == QLatin1String(Constants::QBS_VARIANT_RELEASE))
|
|
|
|
|
return Release;
|
|
|
|
|
return Unknown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QbsBuildConfiguration::setChangedFiles(const QStringList &files)
|
|
|
|
|
{
|
|
|
|
|
m_changedFiles = files;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList QbsBuildConfiguration::changedFiles() const
|
|
|
|
|
{
|
|
|
|
|
return m_changedFiles;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-24 16:47:02 +02:00
|
|
|
void QbsBuildConfiguration::setActiveFileTags(const QStringList &fileTags)
|
|
|
|
|
{
|
|
|
|
|
m_activeFileTags = fileTags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList QbsBuildConfiguration::activeFileTags() const
|
|
|
|
|
{
|
|
|
|
|
return m_activeFileTags;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 15:40:18 +02:00
|
|
|
void QbsBuildConfiguration::setProducts(const QStringList &products)
|
|
|
|
|
{
|
|
|
|
|
m_products = products;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList QbsBuildConfiguration::products() const
|
|
|
|
|
{
|
|
|
|
|
return m_products;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-19 15:29:11 +02:00
|
|
|
void QbsBuildConfiguration::emitBuildTypeChanged()
|
|
|
|
|
{
|
|
|
|
|
emit buildTypeChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 15:40:59 +01:00
|
|
|
QString QbsBuildConfiguration::configurationName() const
|
|
|
|
|
{
|
|
|
|
|
const QString profileName = QbsManager::instance()->profileForKit(target()->kit());
|
|
|
|
|
const QString buildVariant = qbsConfiguration()
|
|
|
|
|
.value(QLatin1String(Constants::QBS_CONFIG_VARIANT_KEY)).toString();
|
|
|
|
|
return profileName + QLatin1Char('-') + buildVariant;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-30 13:52:46 +01:00
|
|
|
class StepProxy
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
StepProxy(const BuildStep *buildStep)
|
|
|
|
|
: m_qbsBuildStep(qobject_cast<const QbsBuildStep *>(buildStep))
|
|
|
|
|
, m_qbsCleanStep(qobject_cast<const QbsCleanStep *>(buildStep))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString command() const {
|
|
|
|
|
if (m_qbsBuildStep)
|
|
|
|
|
return QLatin1String("build");
|
2017-02-13 15:40:59 +01:00
|
|
|
return QLatin1String("clean");
|
2015-01-30 13:52:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool dryRun() const {
|
|
|
|
|
if (m_qbsBuildStep)
|
2016-01-22 11:56:23 +01:00
|
|
|
return false;
|
2017-02-13 15:40:59 +01:00
|
|
|
return m_qbsCleanStep->dryRun();
|
2015-01-30 13:52:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool keepGoing() const {
|
|
|
|
|
if (m_qbsBuildStep)
|
|
|
|
|
return m_qbsBuildStep->keepGoing();
|
2017-02-13 15:40:59 +01:00
|
|
|
return m_qbsCleanStep->keepGoing();
|
2015-01-30 13:52:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool showCommandLines() const {
|
|
|
|
|
return m_qbsBuildStep ? m_qbsBuildStep->showCommandLines() : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool noInstall() const {
|
|
|
|
|
return m_qbsBuildStep ? !m_qbsBuildStep->install() : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool cleanInstallRoot() const {
|
|
|
|
|
if (m_qbsBuildStep)
|
|
|
|
|
return m_qbsBuildStep->cleanInstallRoot();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int jobCount() const {
|
|
|
|
|
return m_qbsBuildStep ? m_qbsBuildStep->maxJobs() : 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 15:40:59 +01:00
|
|
|
Utils::FileName installRoot() const {
|
|
|
|
|
if (m_qbsBuildStep && m_qbsBuildStep->hasCustomInstallRoot())
|
|
|
|
|
return m_qbsBuildStep->installRoot();
|
|
|
|
|
return Utils::FileName();
|
2015-01-30 13:52:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const QbsBuildStep * const m_qbsBuildStep;
|
|
|
|
|
const QbsCleanStep * const m_qbsCleanStep;
|
|
|
|
|
};
|
|
|
|
|
|
2017-02-13 15:40:59 +01:00
|
|
|
QString QbsBuildConfiguration::equivalentCommandLine(const BuildStep *buildStep) const
|
2015-01-30 13:52:46 +01:00
|
|
|
{
|
|
|
|
|
QString commandLine;
|
|
|
|
|
const QString qbsInstallDir = QString::fromLocal8Bit(qgetenv("QBS_INSTALL_DIR"));
|
|
|
|
|
const QString qbsFilePath = Utils::HostOsInfo::withExecutableSuffix(!qbsInstallDir.isEmpty()
|
|
|
|
|
? qbsInstallDir + QLatin1String("/bin/qbs")
|
|
|
|
|
: QCoreApplication::applicationDirPath() + QLatin1String("/qbs"));
|
2015-04-28 20:27:19 -07:00
|
|
|
Utils::QtcProcess::addArg(&commandLine, QDir::toNativeSeparators(qbsFilePath));
|
2015-01-30 13:52:46 +01:00
|
|
|
const StepProxy stepProxy(buildStep);
|
|
|
|
|
Utils::QtcProcess::addArg(&commandLine, stepProxy.command());
|
2017-02-13 15:40:59 +01:00
|
|
|
const QString buildDir = buildDirectory().toUserOutput();
|
|
|
|
|
Utils::QtcProcess::addArgs(&commandLine, QStringList({ "-d", buildDir }));
|
2017-02-09 14:00:07 +01:00
|
|
|
Utils::QtcProcess::addArgs(&commandLine, QStringList("-f")
|
2015-01-30 13:52:46 +01:00
|
|
|
<< buildStep->project()->projectFilePath().toUserOutput());
|
2016-02-22 17:49:02 +01:00
|
|
|
if (QbsProjectManagerSettings::useCreatorSettingsDirForQbs()) {
|
2017-02-09 14:00:07 +01:00
|
|
|
Utils::QtcProcess::addArgs(&commandLine, QStringList({ "--settings-dir",
|
|
|
|
|
QDir::toNativeSeparators(QbsProjectManagerSettings::qbsSettingsBaseDir()) }));
|
2016-02-22 17:49:02 +01:00
|
|
|
}
|
2015-01-30 13:52:46 +01:00
|
|
|
if (stepProxy.dryRun())
|
|
|
|
|
Utils::QtcProcess::addArg(&commandLine, QLatin1String("--dry-run"));
|
|
|
|
|
if (stepProxy.keepGoing())
|
|
|
|
|
Utils::QtcProcess::addArg(&commandLine, QLatin1String("--keep-going"));
|
|
|
|
|
if (stepProxy.showCommandLines())
|
2017-02-09 14:00:07 +01:00
|
|
|
Utils::QtcProcess::addArgs(&commandLine, QStringList({ "--command-echo-mode",
|
|
|
|
|
"command-line" }));
|
2015-01-30 13:52:46 +01:00
|
|
|
if (stepProxy.noInstall())
|
|
|
|
|
Utils::QtcProcess::addArg(&commandLine, QLatin1String("--no-install"));
|
|
|
|
|
if (stepProxy.cleanInstallRoot())
|
|
|
|
|
Utils::QtcProcess::addArg(&commandLine, QLatin1String("--clean-install-root"));
|
|
|
|
|
const int jobCount = stepProxy.jobCount();
|
|
|
|
|
if (jobCount > 0) {
|
2017-02-09 14:00:07 +01:00
|
|
|
Utils::QtcProcess::addArgs(&commandLine, QStringList({ "--jobs",
|
|
|
|
|
QString::number(jobCount) }));
|
2015-01-30 13:52:46 +01:00
|
|
|
}
|
2016-06-27 16:16:47 +02:00
|
|
|
const QString profileName = QbsManager::instance()->profileForKit(buildStep->target()->kit());
|
2017-02-13 15:40:59 +01:00
|
|
|
const QString buildVariant = qbsConfiguration()
|
|
|
|
|
.value(QLatin1String(Constants::QBS_CONFIG_VARIANT_KEY)).toString();
|
|
|
|
|
Utils::QtcProcess::addArg(&commandLine, configurationName());
|
|
|
|
|
Utils::QtcProcess::addArg(&commandLine, QLatin1String(Constants::QBS_CONFIG_VARIANT_KEY)
|
2016-06-27 16:16:47 +02:00
|
|
|
+ QLatin1Char(':') + buildVariant);
|
2017-02-13 15:40:59 +01:00
|
|
|
const Utils::FileName installRoot = stepProxy.installRoot();
|
|
|
|
|
if (!installRoot.isEmpty()) {
|
|
|
|
|
Utils::QtcProcess::addArg(&commandLine, QLatin1String(Constants::QBS_INSTALL_ROOT_KEY)
|
|
|
|
|
+ QLatin1Char(':') + installRoot.toUserOutput());
|
2015-01-30 13:52:46 +01:00
|
|
|
}
|
2016-06-27 16:16:47 +02:00
|
|
|
Utils::QtcProcess::addArg(&commandLine, QLatin1String("profile:") + profileName);
|
2015-01-30 13:52:46 +01:00
|
|
|
|
|
|
|
|
return commandLine;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
QbsBuildConfiguration *QbsBuildConfiguration::setup(Target *t,
|
2013-01-30 18:19:31 +01:00
|
|
|
const QString &defaultDisplayName,
|
|
|
|
|
const QString &displayName,
|
|
|
|
|
const QVariantMap &buildData,
|
|
|
|
|
const Utils::FileName &directory)
|
|
|
|
|
{
|
|
|
|
|
// Add the build configuration.
|
|
|
|
|
QbsBuildConfiguration *bc = new QbsBuildConfiguration(t);
|
|
|
|
|
bc->setDefaultDisplayName(defaultDisplayName);
|
|
|
|
|
bc->setDisplayName(displayName);
|
|
|
|
|
bc->setBuildDirectory(directory);
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
BuildStepList *buildSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
|
2013-01-30 18:19:31 +01:00
|
|
|
QbsBuildStep *bs = new QbsBuildStep(buildSteps);
|
|
|
|
|
bs->setQbsConfiguration(buildData);
|
|
|
|
|
buildSteps->insertStep(0, bs);
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
BuildStepList *cleanSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
|
2013-01-30 18:19:31 +01:00
|
|
|
QbsCleanStep *cs = new QbsCleanStep(cleanSteps);
|
|
|
|
|
cleanSteps->insertStep(0, cs);
|
|
|
|
|
|
|
|
|
|
return bc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// QbsBuildConfigurationFactory:
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
QbsBuildConfigurationFactory::QbsBuildConfigurationFactory(QObject *parent) :
|
|
|
|
|
IBuildConfigurationFactory(parent)
|
|
|
|
|
{ }
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
bool QbsBuildConfigurationFactory::canHandle(const Target *t) const
|
2013-01-30 18:19:31 +01:00
|
|
|
{
|
|
|
|
|
return qobject_cast<Internal::QbsProject *>(t->project());
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
BuildInfo *QbsBuildConfigurationFactory::createBuildInfo(const Kit *k,
|
|
|
|
|
BuildConfiguration::BuildType type) const
|
2013-01-30 18:19:31 +01:00
|
|
|
{
|
2015-10-22 16:55:17 +02:00
|
|
|
auto info = new ProjectExplorer::BuildInfo(this);
|
2013-07-22 15:53:57 +02:00
|
|
|
info->typeName = tr("Build");
|
|
|
|
|
info->kitId = k->id();
|
2015-10-22 16:55:17 +02:00
|
|
|
info->buildType = type;
|
2013-07-22 15:53:57 +02:00
|
|
|
return info;
|
2013-01-30 18:19:31 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
int QbsBuildConfigurationFactory::priority(const Target *parent) const
|
2013-01-30 18:19:31 +01:00
|
|
|
{
|
2013-07-24 12:42:24 +02:00
|
|
|
return canHandle(parent) ? 0 : -1;
|
2013-01-30 18:19:31 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
QList<BuildInfo *> QbsBuildConfigurationFactory::availableBuilds(const Target *parent) const
|
2013-01-30 18:19:31 +01:00
|
|
|
{
|
2014-10-21 18:10:39 +02:00
|
|
|
QList<BuildInfo *> result;
|
2013-01-30 18:19:31 +01:00
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
BuildInfo *info = createBuildInfo(parent->kit(), BuildConfiguration::Debug);
|
2013-07-22 15:53:57 +02:00
|
|
|
result << info;
|
2013-01-30 18:19:31 +01:00
|
|
|
|
2013-07-22 15:53:57 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
2013-01-30 18:19:31 +01:00
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
int QbsBuildConfigurationFactory::priority(const Kit *k, const QString &projectPath) const
|
2013-08-13 10:52:57 +02:00
|
|
|
{
|
2015-02-04 09:32:46 +01:00
|
|
|
Utils::MimeDatabase mdb;
|
|
|
|
|
if (k && mdb.mimeTypeForFile(projectPath).matchesName(QLatin1String(Constants::MIME_TYPE)))
|
|
|
|
|
return 0;
|
|
|
|
|
return -1;
|
2013-08-13 10:52:57 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-22 09:16:55 +02:00
|
|
|
static Utils::FileName defaultBuildDirectory(const QString &projectFilePath, const Kit *k,
|
2015-10-22 17:26:33 +02:00
|
|
|
const QString &bcName,
|
|
|
|
|
BuildConfiguration::BuildType buildType)
|
2014-10-22 09:16:55 +02:00
|
|
|
{
|
|
|
|
|
const QString projectName = QFileInfo(projectFilePath).completeBaseName();
|
2016-08-08 18:35:32 +02:00
|
|
|
ProjectMacroExpander expander(projectFilePath, projectName, k, bcName, buildType);
|
2014-10-22 09:16:55 +02:00
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
QList<BuildInfo *> QbsBuildConfigurationFactory::availableSetups(const Kit *k, const QString &projectPath) const
|
2013-08-13 10:52:57 +02:00
|
|
|
{
|
2014-10-21 18:10:39 +02:00
|
|
|
QList<BuildInfo *> result;
|
2013-08-13 10:52:57 +02:00
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
BuildInfo *info = createBuildInfo(k, BuildConfiguration::Debug);
|
2013-08-13 10:52:57 +02:00
|
|
|
//: The name of the debug build configuration created by default for a qbs project.
|
|
|
|
|
info->displayName = tr("Debug");
|
2015-04-15 22:50:32 +03:00
|
|
|
//: Non-ASCII characters in directory suffix may cause build issues.
|
2015-10-22 17:26:33 +02:00
|
|
|
info->buildDirectory
|
|
|
|
|
= defaultBuildDirectory(projectPath, k, tr("Debug", "Shadow build directory suffix"),
|
|
|
|
|
info->buildType);
|
2013-08-13 10:52:57 +02:00
|
|
|
result << info;
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
info = createBuildInfo(k, BuildConfiguration::Release);
|
2013-08-13 10:52:57 +02:00
|
|
|
//: The name of the release build configuration created by default for a qbs project.
|
|
|
|
|
info->displayName = tr("Release");
|
2015-04-15 22:50:32 +03:00
|
|
|
//: Non-ASCII characters in directory suffix may cause build issues.
|
2015-10-22 17:26:33 +02:00
|
|
|
info->buildDirectory
|
|
|
|
|
= defaultBuildDirectory(projectPath, k, tr("Release", "Shadow build directory suffix"),
|
|
|
|
|
info->buildType);
|
2013-08-13 10:52:57 +02:00
|
|
|
result << info;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
BuildConfiguration *QbsBuildConfigurationFactory::create(Target *parent, const BuildInfo *info) const
|
2013-07-22 15:53:57 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(info->factory() == this, return 0);
|
|
|
|
|
QTC_ASSERT(info->kitId == parent->kit()->id(), return 0);
|
|
|
|
|
QTC_ASSERT(!info->displayName.isEmpty(), return 0);
|
2013-01-30 18:19:31 +01:00
|
|
|
|
|
|
|
|
QVariantMap configData;
|
|
|
|
|
configData.insert(QLatin1String(Constants::QBS_CONFIG_VARIANT_KEY),
|
2015-10-22 16:55:17 +02:00
|
|
|
(info->buildType == BuildConfiguration::Debug)
|
|
|
|
|
? QLatin1String(Constants::QBS_VARIANT_DEBUG)
|
|
|
|
|
: QLatin1String(Constants::QBS_VARIANT_RELEASE));
|
2013-01-30 18:19:31 +01:00
|
|
|
|
2014-05-02 11:36:15 +02:00
|
|
|
Utils::FileName buildDir = info->buildDirectory;
|
|
|
|
|
if (buildDir.isEmpty())
|
2014-10-22 09:16:55 +02:00
|
|
|
buildDir = defaultBuildDirectory(parent->project()->projectDirectory().toString(),
|
2015-10-22 17:26:33 +02:00
|
|
|
parent->kit(), info->displayName, info->buildType);
|
2014-05-02 11:36:15 +02:00
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
BuildConfiguration *bc
|
2013-07-22 15:53:57 +02:00
|
|
|
= QbsBuildConfiguration::setup(parent, info->displayName, info->displayName,
|
2014-05-02 11:36:15 +02:00
|
|
|
configData, buildDir);
|
2013-07-22 15:53:57 +02:00
|
|
|
|
2013-01-30 18:19:31 +01:00
|
|
|
return bc;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
bool QbsBuildConfigurationFactory::canClone(const Target *parent, BuildConfiguration *source) const
|
2013-01-30 18:19:31 +01:00
|
|
|
{
|
|
|
|
|
return canHandle(parent) && qobject_cast<QbsBuildConfiguration *>(source);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
BuildConfiguration *QbsBuildConfigurationFactory::clone(Target *parent, BuildConfiguration *source)
|
2013-01-30 18:19:31 +01:00
|
|
|
{
|
|
|
|
|
if (!canClone(parent, source))
|
|
|
|
|
return 0;
|
|
|
|
|
QbsBuildConfiguration *oldbc(static_cast<QbsBuildConfiguration *>(source));
|
|
|
|
|
return new QbsBuildConfiguration(parent, oldbc);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
bool QbsBuildConfigurationFactory::canRestore(const Target *parent, const QVariantMap &map) const
|
2013-01-30 18:19:31 +01:00
|
|
|
{
|
|
|
|
|
if (!canHandle(parent))
|
|
|
|
|
return false;
|
|
|
|
|
return ProjectExplorer::idFromMap(map) == Core::Id(QBS_BC_ID);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 18:10:39 +02:00
|
|
|
BuildConfiguration *QbsBuildConfigurationFactory::restore(Target *parent, const QVariantMap &map)
|
2013-01-30 18:19:31 +01:00
|
|
|
{
|
|
|
|
|
if (!canRestore(parent, map))
|
|
|
|
|
return 0;
|
|
|
|
|
QbsBuildConfiguration *bc = new QbsBuildConfiguration(parent);
|
|
|
|
|
if (bc->fromMap(map))
|
|
|
|
|
return bc;
|
|
|
|
|
delete bc;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QbsProjectManager
|