aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@qt.io>2016-05-22 17:19:38 -0700
committerJake Petroules <jake.petroules@qt.io>2016-05-23 08:06:08 +0000
commitbf1667e8e1aae74ff85583452afc06caa4a01d22 (patch)
tree3a6981fb778486c906ddcccc085677bc21cef541 /src
parent12c2eaee9f27ddfa1ac8232fdf04577223927cf6 (diff)
Add a new command line echo mode that also prints environment variables.
Change-Id: I88213103519ae4f69fedb4fe535c9c44e3b61d03 Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/lib/corelib/buildgraph/jscommandexecutor.cpp4
-rw-r--r--src/lib/corelib/buildgraph/processcommandexecutor.cpp36
-rw-r--r--src/lib/corelib/buildgraph/processcommandexecutor.h1
-rw-r--r--src/lib/corelib/tools/commandechomode.cpp4
-rw-r--r--src/lib/corelib/tools/commandechomode.h3
5 files changed, 39 insertions, 9 deletions
diff --git a/src/lib/corelib/buildgraph/jscommandexecutor.cpp b/src/lib/corelib/buildgraph/jscommandexecutor.cpp
index 4d1af8943..17cca78f0 100644
--- a/src/lib/corelib/buildgraph/jscommandexecutor.cpp
+++ b/src/lib/corelib/buildgraph/jscommandexecutor.cpp
@@ -168,7 +168,9 @@ JsCommandExecutor::~JsCommandExecutor()
void JsCommandExecutor::doReportCommandDescription()
{
- if (m_echoMode == CommandEchoModeCommandLine && !command()->extendedDescription().isEmpty()) {
+ if ((m_echoMode == CommandEchoModeCommandLine
+ || m_echoMode == CommandEchoModeCommandLineWithEnvironment)
+ && !command()->extendedDescription().isEmpty()) {
emit reportCommandDescription(command()->highlight(), command()->extendedDescription());
return;
}
diff --git a/src/lib/corelib/buildgraph/processcommandexecutor.cpp b/src/lib/corelib/buildgraph/processcommandexecutor.cpp
index e64812a2a..bf526f6f8 100644
--- a/src/lib/corelib/buildgraph/processcommandexecutor.cpp
+++ b/src/lib/corelib/buildgraph/processcommandexecutor.cpp
@@ -72,6 +72,12 @@ void ProcessCommandExecutor::doSetup()
transformer()->product()->buildEnvironment, logger())
.findExecutable(cmd->program(), cmd->workingDir());
+ QProcessEnvironment env = m_buildEnvironment;
+ const QProcessEnvironment &additionalVariables = cmd->environment();
+ foreach (const QString &key, additionalVariables.keys())
+ env.insert(key, additionalVariables.value(key));
+ m_commandEnvironment = env;
+
m_program = program;
m_arguments = cmd->arguments();
m_shellInvocation = shellQuote(QDir::toNativeSeparators(m_program), m_arguments);
@@ -83,11 +89,7 @@ void ProcessCommandExecutor::doStart()
const ProcessCommand * const cmd = processCommand();
- QProcessEnvironment env = m_buildEnvironment;
- const QProcessEnvironment &additionalVariables = cmd->environment();
- foreach (const QString &key, additionalVariables.keys())
- env.insert(key, additionalVariables.value(key));
- m_process.setProcessEnvironment(env);
+ m_process.setProcessEnvironment(m_commandEnvironment);
QStringList arguments = m_arguments;
@@ -144,6 +146,7 @@ void ProcessCommandExecutor::doStart()
logger().qbsDebug() << "[EXEC] Running external process; full command line is: "
<< m_shellInvocation;
+ const QProcessEnvironment &additionalVariables = cmd->environment();
logger().qbsTrace() << "[EXEC] Additional environment:" << additionalVariables.toStringList();
m_process.setWorkingDirectory(workingDir);
m_process.start(m_program, arguments);
@@ -303,13 +306,32 @@ void ProcessCommandExecutor::onProcessFinished()
sendProcessOutput();
}
+static QString environmentVariableString(const QString &key, const QString &value)
+{
+ QString str;
+ if (HostOsInfo::isAnyUnixHost())
+ str += QStringLiteral("export ");
+ if (HostOsInfo::isWindowsHost())
+ str += QStringLiteral("set ");
+ return str + shellQuote(key + QLatin1Char('=') + value) + QLatin1Char('\n');
+}
+
void ProcessCommandExecutor::doReportCommandDescription()
{
- if (m_echoMode == CommandEchoModeCommandLine) {
+ if (m_echoMode == CommandEchoModeCommandLine ||
+ m_echoMode == CommandEchoModeCommandLineWithEnvironment) {
+ QString fullInvocation;
+ if (m_echoMode == CommandEchoModeCommandLineWithEnvironment) {
+ QStringList keys = m_commandEnvironment.keys();
+ keys.sort();
+ for (const QString &key : keys)
+ fullInvocation += environmentVariableString(key, m_commandEnvironment.value(key));
+ }
+ fullInvocation += m_shellInvocation;
emit reportCommandDescription(command()->highlight(),
!command()->extendedDescription().isEmpty()
? command()->extendedDescription()
- : m_shellInvocation);
+ : fullInvocation);
return;
}
diff --git a/src/lib/corelib/buildgraph/processcommandexecutor.h b/src/lib/corelib/buildgraph/processcommandexecutor.h
index 38dc1ee36..1b7a35575 100644
--- a/src/lib/corelib/buildgraph/processcommandexecutor.h
+++ b/src/lib/corelib/buildgraph/processcommandexecutor.h
@@ -81,6 +81,7 @@ private:
QProcess m_process;
QProcessEnvironment m_buildEnvironment;
+ QProcessEnvironment m_commandEnvironment;
QString m_responseFileName;
};
diff --git a/src/lib/corelib/tools/commandechomode.cpp b/src/lib/corelib/tools/commandechomode.cpp
index 87f1aa6bc..e3814fd4e 100644
--- a/src/lib/corelib/tools/commandechomode.cpp
+++ b/src/lib/corelib/tools/commandechomode.cpp
@@ -36,6 +36,8 @@
* \value CommandEchoModeSilent Indicates that no output will be printed.
* \value CommandEchoModeSummary Indicates that descriptions will be printed.
* \value CommandEchoModeCommandLine Indidcates that full command line invocations will be printed.
+ * \value CommandEchoModeCommandLineWithEnvironment Indidcates that full command line invocations,
+ * including environment variables, will be printed.
*/
namespace qbs {
@@ -54,6 +56,8 @@ QString commandEchoModeName(CommandEchoMode mode)
return QLatin1String("summary");
case CommandEchoModeCommandLine:
return QLatin1String("command-line");
+ case CommandEchoModeCommandLineWithEnvironment:
+ return QLatin1String("command-line-with-environment");
default:
break;
}
diff --git a/src/lib/corelib/tools/commandechomode.h b/src/lib/corelib/tools/commandechomode.h
index e59f3bf14..f6fe517e1 100644
--- a/src/lib/corelib/tools/commandechomode.h
+++ b/src/lib/corelib/tools/commandechomode.h
@@ -41,7 +41,8 @@ enum CommandEchoMode {
CommandEchoModeSilent,
CommandEchoModeSummary,
CommandEchoModeCommandLine,
- CommandEchoModeLast = CommandEchoModeCommandLine
+ CommandEchoModeCommandLineWithEnvironment,
+ CommandEchoModeLast = CommandEchoModeCommandLineWithEnvironment
};
QBS_EXPORT CommandEchoMode defaultCommandEchoMode();