Commit c356a276 authored by Christian Kandeler's avatar Christian Kandeler

QbsProjectManager: Fix command-line representations.

- All except the one for "qbs build" were incomplete, which is fixed
  now.
- The new implementation is centralized, so maintenance will be simpler.
- The command lines are also completely self-contained now, so they can
  be pasted as-is into a shell with no assumptions about the working
  directory etc.

Change-Id: I2c684141bcdc5c6da0e1af60ce60278fc4dcd088
Reviewed-by: default avatarJake Petroules <jake.petroules@petroules.com>
parent aa39916c
......@@ -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,
......
......@@ -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();
......
......@@ -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) {
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment