aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@petroules.com>2015-07-11 22:42:55 -0700
committerJake Petroules <jake.petroules@petroules.com>2015-07-13 11:52:31 +0000
commitbe6d0e2486487e84839871c324d0cccc5067284d (patch)
treece87bb4ca98fa52174fe4659bd3b14ac43726049
parentf05c8c1b9d6205086bf6c0ce6fe226f627d9c86e (diff)
Print the command that was actually executed in command echo mode.
Previously, it would display the command that was entered ("cmd") vs the command that was actually used ("C:\Windows\System32\cmd.exe"). Change-Id: Ia3487f2a0fee4c439d82598f3e2e81650efafa80 Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
-rw-r--r--src/lib/corelib/buildgraph/abstractcommandexecutor.cpp1
-rw-r--r--src/lib/corelib/buildgraph/abstractcommandexecutor.h1
-rw-r--r--src/lib/corelib/buildgraph/processcommandexecutor.cpp35
-rw-r--r--src/lib/corelib/buildgraph/processcommandexecutor.h2
4 files changed, 23 insertions, 16 deletions
diff --git a/src/lib/corelib/buildgraph/abstractcommandexecutor.cpp b/src/lib/corelib/buildgraph/abstractcommandexecutor.cpp
index 30d9704c9..b8c6033f0 100644
--- a/src/lib/corelib/buildgraph/abstractcommandexecutor.cpp
+++ b/src/lib/corelib/buildgraph/abstractcommandexecutor.cpp
@@ -53,6 +53,7 @@ void AbstractCommandExecutor::start(Transformer *transformer, const AbstractComm
{
m_transformer = transformer;
m_command = cmd;
+ doSetup();
doReportCommandDescription();
doStart();
}
diff --git a/src/lib/corelib/buildgraph/abstractcommandexecutor.h b/src/lib/corelib/buildgraph/abstractcommandexecutor.h
index 8d746641f..5c60886a6 100644
--- a/src/lib/corelib/buildgraph/abstractcommandexecutor.h
+++ b/src/lib/corelib/buildgraph/abstractcommandexecutor.h
@@ -74,6 +74,7 @@ protected:
CommandEchoMode m_echoMode;
private:
+ virtual void doSetup() { };
virtual void doStart() = 0;
private:
diff --git a/src/lib/corelib/buildgraph/processcommandexecutor.cpp b/src/lib/corelib/buildgraph/processcommandexecutor.cpp
index b15879bf7..c714181a9 100644
--- a/src/lib/corelib/buildgraph/processcommandexecutor.cpp
+++ b/src/lib/corelib/buildgraph/processcommandexecutor.cpp
@@ -65,17 +65,23 @@ ProcessCommandExecutor::ProcessCommandExecutor(const Logger &logger, QObject *pa
connect(&m_process, SIGNAL(finished(int)), SLOT(onProcessFinished(int)));
}
-void ProcessCommandExecutor::doStart()
+void ProcessCommandExecutor::doSetup()
{
- QBS_ASSERT(m_process.state() == QProcess::NotRunning, return);
-
const ProcessCommand * const cmd = processCommand();
const QString program = ExecutableFinder(transformer()->product(),
transformer()->product()->buildEnvironment, logger())
.findExecutable(cmd->program(), cmd->workingDir());
- // Use native separators for debug output, so people can copy-paste it to a command line.
- const QString programNative = QDir::toNativeSeparators(program);
+ m_program = program;
+ m_arguments = cmd->arguments();
+ m_shellInvocation = shellQuote(QDir::toNativeSeparators(m_program), m_arguments);
+}
+
+void ProcessCommandExecutor::doStart()
+{
+ QBS_ASSERT(m_process.state() == QProcess::NotRunning, return);
+
+ const ProcessCommand * const cmd = processCommand();
QProcessEnvironment env = m_buildEnvironment;
const QProcessEnvironment &additionalVariables = cmd->environment();
@@ -83,8 +89,7 @@ void ProcessCommandExecutor::doStart()
env.insert(key, additionalVariables.value(key));
m_process.setProcessEnvironment(env);
- QStringList arguments = cmd->arguments();
- const QString argString = shellQuote(programNative, arguments);
+ QStringList arguments = m_arguments;
if (dryRun()) {
QTimer::singleShot(0, this, SIGNAL(finished())); // Don't call back on the caller.
@@ -96,7 +101,8 @@ void ProcessCommandExecutor::doStart()
FileInfo fi(workingDir);
if (!fi.exists() || !fi.isDir()) {
emit finished(ErrorInfo(Tr::tr("The working directory '%1' for process '%2' "
- "is invalid.").arg(QDir::toNativeSeparators(workingDir), programNative),
+ "is invalid.").arg(QDir::toNativeSeparators(workingDir),
+ QDir::toNativeSeparators(m_program)),
cmd->codeLocation()));
return;
}
@@ -104,7 +110,7 @@ void ProcessCommandExecutor::doStart()
// Automatically use response files, if the command line gets to long.
if (!cmd->responseFileUsagePrefix().isEmpty()) {
- const int commandLineLength = argString.length();
+ const int commandLineLength = m_shellInvocation.length();
if (cmd->responseFileThreshold() >= 0 && commandLineLength > cmd->responseFileThreshold()) {
if (logger().debugEnabled()) {
logger().qbsDebug() << QString::fromLocal8Bit("[EXEC] Using response file. "
@@ -135,13 +141,11 @@ void ProcessCommandExecutor::doStart()
}
}
- logger().qbsDebug() << "[EXEC] Running external process; full command line is: " << argString;
+ logger().qbsDebug() << "[EXEC] Running external process; full command line is: "
+ << m_shellInvocation;
logger().qbsTrace() << "[EXEC] Additional environment:" << additionalVariables.toStringList();
m_process.setWorkingDirectory(workingDir);
- m_process.start(program, arguments);
-
- m_program = program;
- m_arguments = arguments;
+ m_process.start(m_program, arguments);
}
void ProcessCommandExecutor::cancel()
@@ -266,8 +270,7 @@ void ProcessCommandExecutor::onProcessFinished(int exitCode)
void ProcessCommandExecutor::doReportCommandDescription()
{
if (m_echoMode == CommandEchoModeCommandLine) {
- const ProcessCommand * const cmd = processCommand();
- emit reportCommandDescription(QString(), shellQuote(cmd->program(), cmd->arguments()));
+ emit reportCommandDescription(command()->highlight(), m_shellInvocation);
return;
}
diff --git a/src/lib/corelib/buildgraph/processcommandexecutor.h b/src/lib/corelib/buildgraph/processcommandexecutor.h
index bae8a7e50..d0b4bb82b 100644
--- a/src/lib/corelib/buildgraph/processcommandexecutor.h
+++ b/src/lib/corelib/buildgraph/processcommandexecutor.h
@@ -61,6 +61,7 @@ private slots:
void onProcessFinished(int exitCode);
private:
+ void doSetup();
void doReportCommandDescription();
void doStart();
void cancel();
@@ -74,6 +75,7 @@ private:
private:
QString m_program;
QStringList m_arguments;
+ QString m_shellInvocation;
QProcess m_process;
QProcessEnvironment m_buildEnvironment;