diff --git a/src/plugins/qbsprojectmanager/qbsbuildconfiguration.cpp b/src/plugins/qbsprojectmanager/qbsbuildconfiguration.cpp index b06731e3e9018b288abdf0a0dfd8c229197e523b..4030c60bf4e251f9b0c11937354d43fb8212e837 100644 --- a/src/plugins/qbsprojectmanager/qbsbuildconfiguration.cpp +++ b/src/plugins/qbsprojectmanager/qbsbuildconfiguration.cpp @@ -34,6 +34,7 @@ #include "qbsbuildinfo.h" #include "qbsbuildstep.h" #include "qbscleanstep.h" +#include "qbsinstallstep.h" #include "qbsproject.h" #include "qbsprojectmanagerconstants.h" @@ -48,7 +49,9 @@ #include <projectexplorer/projectmacroexpander.h> #include <projectexplorer/target.h> #include <projectexplorer/toolchain.h> +#include <utils/qtcprocess.h> +#include <QCoreApplication> #include <QInputDialog> using namespace ProjectExplorer; @@ -205,6 +208,127 @@ void QbsBuildConfiguration::emitBuildTypeChanged() emit buildTypeChanged(); } +class StepProxy +{ +public: + StepProxy(const BuildStep *buildStep) + : m_qbsBuildStep(qobject_cast<const QbsBuildStep *>(buildStep)) + , m_qbsCleanStep(qobject_cast<const QbsCleanStep *>(buildStep)) + , m_qbsInstallStep(qobject_cast<const QbsInstallStep *>(buildStep)) + { + } + + QString command() const { + if (m_qbsBuildStep) + return QLatin1String("build"); + if (m_qbsCleanStep) + return QLatin1String("clean"); + return QLatin1String("install"); + } + + bool dryRun() const { + if (m_qbsBuildStep) + return m_qbsBuildStep->dryRun(); + if (m_qbsCleanStep) + return m_qbsCleanStep->dryRun(); + return m_qbsInstallStep->dryRun(); + } + + bool keepGoing() const { + if (m_qbsBuildStep) + return m_qbsBuildStep->keepGoing(); + if (m_qbsCleanStep) + return m_qbsCleanStep->keepGoing(); + return m_qbsInstallStep->keepGoing(); + } + + 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(); + if (m_qbsInstallStep) + return m_qbsInstallStep->removeFirst(); + return false; + } + + int jobCount() const { + return m_qbsBuildStep ? m_qbsBuildStep->maxJobs() : 0; + } + + bool allArtifacts() const { + return m_qbsCleanStep ? m_qbsCleanStep->cleanAll() : false; + } + + QString installRoot() const { + return m_qbsInstallStep ? m_qbsInstallStep->absoluteInstallRoot() : QString(); + } + +private: + const QbsBuildStep * const m_qbsBuildStep; + const QbsCleanStep * const m_qbsCleanStep; + const QbsInstallStep * const m_qbsInstallStep; +}; + +QString QbsBuildConfiguration::equivalentCommandLine(const BuildStep *buildStep) +{ + 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")); + Utils::QtcProcess::addArg(&commandLine, qbsFilePath); + const StepProxy stepProxy(buildStep); + Utils::QtcProcess::addArg(&commandLine, stepProxy.command()); + const QbsBuildConfiguration * const buildConfig = qobject_cast<QbsBuildConfiguration *>( + buildStep->project()->activeTarget()->activeBuildConfiguration()); + if (buildConfig) { + const QString buildDir = buildConfig->buildDirectory().toUserOutput(); + Utils::QtcProcess::addArgs(&commandLine, QStringList() << QLatin1String("-d") << buildDir); + } + Utils::QtcProcess::addArgs(&commandLine, QStringList() << QLatin1String("-f") + << buildStep->project()->projectFilePath().toUserOutput()); + Utils::QtcProcess::addArgs(&commandLine, QStringList() << QLatin1String("--settings-dir") + << QDir::toNativeSeparators(Core::ICore::userResourcePath())); + if (stepProxy.dryRun()) + Utils::QtcProcess::addArg(&commandLine, QLatin1String("--dry-run")); + if (stepProxy.keepGoing()) + Utils::QtcProcess::addArg(&commandLine, QLatin1String("--keep-going")); + if (stepProxy.showCommandLines()) + Utils::QtcProcess::addArg(&commandLine, QLatin1String("--show-command-lines")); + 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) { + Utils::QtcProcess::addArgs(&commandLine, QStringList() << QLatin1String("--jobs") + << QString::number(jobCount)); + } + if (stepProxy.allArtifacts()) + Utils::QtcProcess::addArg(&commandLine, QLatin1String("--all-artifacts")); + const QString installRoot = stepProxy.installRoot(); + if (!installRoot.isEmpty()) { + Utils::QtcProcess::addArgs(&commandLine, QStringList() << QLatin1String("--install-root") + << installRoot); + } + + if (buildConfig) { + Utils::QtcProcess::addArg(&commandLine, buildConfig->qbsConfiguration() + .value(QLatin1String(Constants::QBS_CONFIG_VARIANT_KEY)).toString()); + } + Utils::QtcProcess::addArg(&commandLine, QLatin1String("profile:") + + QbsManager::instance()->profileForKit(buildStep->target()->kit())); + + return commandLine; +} + QbsBuildConfiguration *QbsBuildConfiguration::setup(Target *t, const QString &defaultDisplayName, const QString &displayName, diff --git a/src/plugins/qbsprojectmanager/qbsbuildconfiguration.h b/src/plugins/qbsprojectmanager/qbsbuildconfiguration.h index 8381588a705458c16c7c174513e6a3a1fdf0d4cb..5cfe314b799566639bbaea0e29c3d4efbd0f63b3 100644 --- a/src/plugins/qbsprojectmanager/qbsbuildconfiguration.h +++ b/src/plugins/qbsprojectmanager/qbsbuildconfiguration.h @@ -36,7 +36,10 @@ #include <projectexplorer/buildconfiguration.h> #include <qtsupport/baseqtversion.h> -namespace ProjectExplorer { class FileNode; } +namespace ProjectExplorer { +class BuildStep; +class FileNode; +} namespace QbsProjectManager { @@ -79,6 +82,8 @@ public: void emitBuildTypeChanged(); + static QString equivalentCommandLine(const ProjectExplorer::BuildStep *buildStep); + signals: void qbsConfigurationChanged(); diff --git a/src/plugins/qbsprojectmanager/qbsbuildstep.cpp b/src/plugins/qbsprojectmanager/qbsbuildstep.cpp index 87ef68822d6c207bd59e11bee46293065807e0b4..52f1610ed4015df8e72ecdf2a6c1aad4de64dbe3 100644 --- a/src/plugins/qbsprojectmanager/qbsbuildstep.cpp +++ b/src/plugins/qbsprojectmanager/qbsbuildstep.cpp @@ -525,22 +525,7 @@ void QbsBuildStepConfigWidget::updateState() const QString buildVariant = m_step->buildVariant(); const int idx = (buildVariant == QLatin1String(Constants::QBS_VARIANT_DEBUG)) ? 0 : 1; m_ui->buildVariantComboBox->setCurrentIndex(idx); - - QString command = QLatin1String("qbs build "); - command += QString::fromLatin1("--settings-dir ") - + QDir::toNativeSeparators(Core::ICore::userResourcePath()) + QLatin1Char(' '); - if (m_step->dryRun()) - command += QLatin1String("--dry-run "); - if (m_step->keepGoing()) - command += QLatin1String("--keep-going "); - if (m_step->showCommandLines()) - command += QLatin1String("--show-command-lines "); - if (!m_step->install()) - command += QLatin1String("--no-install "); - if (m_step->cleanInstallRoot()) - command += QLatin1String("--clean-install-root "); - command += QString::fromLatin1("--jobs %1 ").arg(m_step->maxJobs()); - command += QString::fromLatin1("%1 profile:%2").arg(buildVariant, m_step->profile()); + QString command = QbsBuildConfiguration::equivalentCommandLine(m_step); QList<QPair<QString, QString> > propertyList = m_ui->propertyEdit->properties(); for (int i = 0; i < propertyList.count(); ++i) { diff --git a/src/plugins/qbsprojectmanager/qbscleanstep.cpp b/src/plugins/qbsprojectmanager/qbscleanstep.cpp index 5cc015c395bcd37937e466b23a795dbab657fc38..5b5e0c03a8064218583fa974326ac7fad4ee3937 100644 --- a/src/plugins/qbsprojectmanager/qbscleanstep.cpp +++ b/src/plugins/qbsprojectmanager/qbscleanstep.cpp @@ -293,13 +293,7 @@ void QbsCleanStepConfigWidget::updateState() m_ui->dryRunCheckBox->setChecked(m_step->dryRun()); m_ui->keepGoingCheckBox->setChecked(m_step->keepGoing()); - QString command = QLatin1String("qbs clean "); - if (m_step->dryRun()) - command += QLatin1String("--dry-run "); - if (m_step->keepGoing()) - command += QLatin1String("--keep-going "); - if (m_step->cleanAll()) - command += QLatin1String(" --all-artifacts"); + QString command = QbsBuildConfiguration::equivalentCommandLine(m_step); m_ui->commandLineTextEdit->setPlainText(command); QString summary = tr("<b>Qbs:</b> %1").arg(command); diff --git a/src/plugins/qbsprojectmanager/qbsinstallstep.cpp b/src/plugins/qbsprojectmanager/qbsinstallstep.cpp index c1bf7ef6ad45f4564e8ba1454495defa5532757c..c0a124e0028348e74c7f5fb1c30726b449c34e6e 100644 --- a/src/plugins/qbsprojectmanager/qbsinstallstep.cpp +++ b/src/plugins/qbsprojectmanager/qbsinstallstep.cpp @@ -317,16 +317,7 @@ void QbsInstallStepConfigWidget::updateState() m_ui->installRootChooser->setBaseFileName(m_step->target()->activeBuildConfiguration()->buildDirectory()); - QString command = QLatin1String("qbs install "); - command += QString::fromLatin1("--settings-dir ") - + QDir::toNativeSeparators(Core::ICore::userResourcePath()) + QLatin1Char(' '); - if (m_step->dryRun()) - command += QLatin1String("--dry-run "); - if (m_step->keepGoing()) - command += QLatin1String("--keep-going "); - if (m_step->removeFirst()) - command += QLatin1String("--remove-first "); - command += QString::fromLatin1("--install-root \"%1\"").arg(m_step->absoluteInstallRoot()); + QString command = QbsBuildConfiguration::equivalentCommandLine(m_step); m_ui->commandLineTextEdit->setPlainText(command); QString summary = tr("<b>Qbs:</b> %1").arg(command);