diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2018-02-19 17:49:52 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2018-02-21 09:17:15 +0000 |
commit | 9379e0eae0f05614313083c8b46b8dae6da8b230 (patch) | |
tree | 84726ab0e84b54f7eac73e4e3f84e2eb554e0864 /src | |
parent | 32c82062f91cc77bbb2b502e50d72fa5978a281e (diff) |
RunEnvironment: Add safety check for API mis-use
It makes no sense to try to run a disabled product.
Task-number: QBS-1306
Change-Id: I07e36bc8f787d702ed9caa21972537e588db57e8
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/corelib/api/runenvironment.cpp | 14 | ||||
-rw-r--r-- | src/lib/corelib/api/runenvironment.h | 1 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/lib/corelib/api/runenvironment.cpp b/src/lib/corelib/api/runenvironment.cpp index 9ca798e17..d803639a8 100644 --- a/src/lib/corelib/api/runenvironment.cpp +++ b/src/lib/corelib/api/runenvironment.cpp @@ -85,6 +85,16 @@ public: { } + void checkProduct() + { + if (!resolvedProduct) + throw ErrorInfo(Tr::tr("Cannot run: No such product.")); + if (!resolvedProduct->enabled) { + throw ErrorInfo(Tr::tr("Cannot run disabled product '%1'.") + .arg(resolvedProduct->fullDisplayName())); + } + } + const ResolvedProductPtr resolvedProduct; const TopLevelProjectConstPtr project; InstallOptions installOptions; @@ -274,6 +284,7 @@ void RunEnvironment::printStartInfo(const QProcess &proc, bool dryRun) int RunEnvironment::doRunTarget(const QString &targetBin, const QStringList &arguments, bool dryRun) { + d->checkProduct(); const QStringList targetOS = d->resolvedProduct->moduleProperties->qbsPropertyValue( QLatin1String("targetOS")).toStringList(); const QStringList toolchain = d->resolvedProduct->moduleProperties->qbsPropertyValue( @@ -462,8 +473,7 @@ int RunEnvironment::doRunTarget(const QString &targetBin, const QStringList &arg const QProcessEnvironment RunEnvironment::getRunEnvironment() const { - if (!d->resolvedProduct) - return d->environment; + d->checkProduct(); EnvironmentScriptRunner(d->resolvedProduct.get(), &d->evalContext, d->environment) .setupForRun(d->setupRunEnvConfig); return d->resolvedProduct->runEnvironment; diff --git a/src/lib/corelib/api/runenvironment.h b/src/lib/corelib/api/runenvironment.h index 658ec810b..69603bf76 100644 --- a/src/lib/corelib/api/runenvironment.h +++ b/src/lib/corelib/api/runenvironment.h @@ -66,6 +66,7 @@ class QBS_EXPORT RunEnvironment { friend class CommandLineFrontend; friend class Project; + friend class TestApi; public: ~RunEnvironment(); |