aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/api
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2017-12-22 17:53:39 +0100
committerChristian Kandeler <christian.kandeler@qt.io>2018-01-12 09:13:59 +0000
commita673f4f2591772eaa959fb9a24d66874e376a368 (patch)
tree465b13aff2901989461adf4b530d4920f2069491 /src/lib/corelib/api
parent72793c7278c81cf0d557c962d35475cdac0d6300 (diff)
Properly take the --dry-run option into account in the "run" command
Do not try to execute the virtual binary. Change-Id: I19b0a9e7600b33cb42c4ab60f689dd4c3329930b Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Diffstat (limited to 'src/lib/corelib/api')
-rw-r--r--src/lib/corelib/api/runenvironment.cpp117
-rw-r--r--src/lib/corelib/api/runenvironment.h6
2 files changed, 71 insertions, 52 deletions
diff --git a/src/lib/corelib/api/runenvironment.cpp b/src/lib/corelib/api/runenvironment.cpp
index 36d953572..9ca798e17 100644
--- a/src/lib/corelib/api/runenvironment.cpp
+++ b/src/lib/corelib/api/runenvironment.cpp
@@ -120,11 +120,11 @@ int RunEnvironment::runShell(ErrorInfo *error)
}
}
-int RunEnvironment::runTarget(const QString &targetBin, const QStringList &arguments,
+int RunEnvironment::runTarget(const QString &targetBin, const QStringList &arguments, bool dryRun,
ErrorInfo *error)
{
try {
- return doRunTarget(targetBin, arguments);
+ return doRunTarget(targetBin, arguments, dryRun);
} catch (const ErrorInfo &e) {
if (error)
*error = e;
@@ -263,7 +263,16 @@ static QString findMainIntent(const QString &aapt, const QString &apkFilePath)
return QString();
}
-int RunEnvironment::doRunTarget(const QString &targetBin, const QStringList &arguments)
+void RunEnvironment::printStartInfo(const QProcess &proc, bool dryRun)
+{
+ QString message = dryRun ? Tr::tr("Would start target.") : Tr::tr("Starting target.");
+ message.append(QLatin1Char(' ')).append(Tr::tr("Full command line: %1")
+ .arg(shellQuote(QStringList(QDir::toNativeSeparators(proc.program()))
+ << proc.arguments())));
+ d->logger.qbsInfo() << message;
+}
+
+int RunEnvironment::doRunTarget(const QString &targetBin, const QStringList &arguments, bool dryRun)
{
const QStringList targetOS = d->resolvedProduct->moduleProperties->qbsPropertyValue(
QLatin1String("targetOS")).toStringList();
@@ -282,34 +291,36 @@ int RunEnvironment::doRunTarget(const QString &targetBin, const QStringList &arg
QStringLiteral("Android.sdk"), QStringLiteral("sdkDir")).toString();
targetExecutable = sdkDir + QStringLiteral("/platform-tools/adb");
- QProcess process;
- process.setProcessChannelMode(QProcess::ForwardedChannels);
- process.start(targetExecutable, QStringList()
- << StringConstants::androidInstallCommand()
- << QStringLiteral("-r") // replace existing application
- << QStringLiteral("-t") // allow test packages
- << QStringLiteral("-d") // allow version code downgrade
- << targetBin);
- if (!process.waitForFinished()) {
- if (process.error() == QProcess::FailedToStart) {
- throw ErrorInfo(Tr::tr("The process '%1' could not be started: %2")
- .arg(targetExecutable)
- .arg(process.errorString()));
- } else {
- d->logger.qbsWarning()
- << "QProcess error: " << process.errorString();
+ if (!dryRun) {
+ QProcess process;
+ process.setProcessChannelMode(QProcess::ForwardedChannels);
+ process.start(targetExecutable, QStringList()
+ << StringConstants::androidInstallCommand()
+ << QStringLiteral("-r") // replace existing application
+ << QStringLiteral("-t") // allow test packages
+ << QStringLiteral("-d") // allow version code downgrade
+ << targetBin);
+ if (!process.waitForFinished()) {
+ if (process.error() == QProcess::FailedToStart) {
+ throw ErrorInfo(Tr::tr("The process '%1' could not be started: %2")
+ .arg(targetExecutable)
+ .arg(process.errorString()));
+ } else {
+ d->logger.qbsWarning()
+ << "QProcess error: " << process.errorString();
+ }
+
+ return EXIT_FAILURE;
}
- return EXIT_FAILURE;
+ targetArguments << QStringList()
+ << QStringLiteral("shell")
+ << QStringLiteral("am")
+ << QStringLiteral("start")
+ << QStringLiteral("-W") // wait for launch to complete
+ << QStringLiteral("-n")
+ << intent;
}
-
- targetArguments << QStringList()
- << QStringLiteral("shell")
- << QStringLiteral("am")
- << QStringLiteral("start")
- << QStringLiteral("-W") // wait for launch to complete
- << QStringLiteral("-n")
- << intent;
} else if (targetOS.contains(QLatin1String("ios")) || targetOS.contains(QLatin1String("tvos"))) {
const QString bundlePath = targetBin + StringConstants::slashDotDot();
@@ -322,28 +333,30 @@ int RunEnvironment::doRunTarget(const QString &targetBin, const QStringList &arg
const auto bundleId = d->resolvedProduct->moduleProperties->moduleProperty(
QStringLiteral("bundle"), QStringLiteral("identifier")).toString();
- QProcess process;
- process.setProcessChannelMode(QProcess::ForwardedChannels);
- process.start(targetExecutable, QStringList()
- << StringConstants::simctlInstallCommand()
- << simulatorId
- << QDir::cleanPath(bundlePath));
- if (!process.waitForFinished()) {
- if (process.error() == QProcess::FailedToStart) {
- throw ErrorInfo(Tr::tr("The process '%1' could not be started: %2")
- .arg(targetExecutable)
- .arg(process.errorString()));
+ if (!dryRun) {
+ QProcess process;
+ process.setProcessChannelMode(QProcess::ForwardedChannels);
+ process.start(targetExecutable, QStringList()
+ << StringConstants::simctlInstallCommand()
+ << simulatorId
+ << QDir::cleanPath(bundlePath));
+ if (!process.waitForFinished()) {
+ if (process.error() == QProcess::FailedToStart) {
+ throw ErrorInfo(Tr::tr("The process '%1' could not be started: %2")
+ .arg(targetExecutable)
+ .arg(process.errorString()));
+ }
+
+ return EXIT_FAILURE;
}
- return EXIT_FAILURE;
+ targetArguments << QStringList()
+ << QStringLiteral("launch")
+ << QStringLiteral("--console")
+ << simulatorId
+ << bundleId
+ << arguments;
}
-
- targetArguments << QStringList()
- << QStringLiteral("launch")
- << QStringLiteral("--console")
- << simulatorId
- << bundleId
- << arguments;
} else {
if (QFileInfo(targetExecutable = findExecutable(QStringList()
<< QStringLiteral("iostool"))).isExecutable()) {
@@ -403,7 +416,7 @@ int RunEnvironment::doRunTarget(const QString &targetBin, const QStringList &arg
// Only check if the target is executable if we're not running it through another
// known application such as msiexec or wine, as we can't check in this case anyways
QFileInfo fi(targetExecutable);
- if (targetBin == targetExecutable && (!fi.isFile() || !fi.isExecutable())) {
+ if (!dryRun && targetBin == targetExecutable && (!fi.isFile() || !fi.isExecutable())) {
d->logger.qbsLog(LoggerError) << Tr::tr("File '%1' is not an executable.")
.arg(QDir::toNativeSeparators(targetExecutable));
return EXIT_FAILURE;
@@ -414,11 +427,15 @@ int RunEnvironment::doRunTarget(const QString &targetBin, const QStringList &arg
EnvironmentScriptRunner(d->resolvedProduct.get(), &d->evalContext, env)
.setupForRun(d->setupRunEnvConfig);
- d->logger.qbsInfo() << Tr::tr("Starting target '%1'.").arg(QDir::toNativeSeparators(targetBin));
QProcess process;
process.setProcessEnvironment(d->resolvedProduct->runEnvironment);
process.setProcessChannelMode(QProcess::ForwardedChannels);
- process.start(targetExecutable, targetArguments);
+ process.setProgram(targetExecutable);
+ process.setArguments(targetArguments);
+ printStartInfo(process, dryRun);
+ if (dryRun)
+ return EXIT_SUCCESS;
+ process.start();
if (!process.waitForFinished(-1)) {
if (process.error() == QProcess::FailedToStart) {
QString errorPrefixString;
diff --git a/src/lib/corelib/api/runenvironment.h b/src/lib/corelib/api/runenvironment.h
index 5c380d48c..658ec810b 100644
--- a/src/lib/corelib/api/runenvironment.h
+++ b/src/lib/corelib/api/runenvironment.h
@@ -46,6 +46,7 @@
#include <QtCore/qglobal.h>
QT_BEGIN_NAMESPACE
+class QProcess;
class QProcessEnvironment;
class QString;
class QStringList;
@@ -69,7 +70,7 @@ public:
~RunEnvironment();
int runShell(ErrorInfo *error = nullptr);
- int runTarget(const QString &targetBin, const QStringList &arguments,
+ int runTarget(const QString &targetBin, const QStringList &arguments, bool dryRun,
ErrorInfo *error = nullptr);
const QProcessEnvironment runEnvironment(ErrorInfo *error = nullptr) const;
@@ -85,7 +86,8 @@ private:
const Internal::Logger &logger);
int doRunShell();
- int doRunTarget(const QString &targetBin, const QStringList &arguments);
+ int doRunTarget(const QString &targetBin, const QStringList &arguments, bool dryRun);
+ void printStartInfo(const QProcess &proc, bool dryRun);
const QProcessEnvironment getRunEnvironment() const;
const QProcessEnvironment getBuildEnvironment() const;