summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@digia.com>2013-04-03 11:24:27 +0200
committerJoerg Bornemann <joerg.bornemann@digia.com>2013-04-03 12:13:05 +0200
commitbce64216ceea9c1cb9baa8a6a744fbbc62dd72c9 (patch)
tree82ee753d780f3ba73db41adfb6dcfffefb55af8a
parent3059ab7aeb2695d32c1a03455e376265e3af4c1c (diff)
downloadqbs-bce64216ceea9c1cb9baa8a6a744fbbc62dd72c9.tar.gz
Make a process' environment configurable in a prepare script.
This is needed for applications that are configured via environment variables rather than command-line arguments. Change-Id: I114f2bcd65d8551175b35ffbd4912bd37699dc89 Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
-rw-r--r--src/lib/buildgraph/command.cpp22
-rw-r--r--src/lib/buildgraph/command.h6
-rw-r--r--src/lib/buildgraph/processcommandexecutor.cpp11
-rw-r--r--src/lib/buildgraph/processcommandexecutor.h6
-rw-r--r--src/lib/tools/persistence.cpp2
5 files changed, 39 insertions, 8 deletions
diff --git a/src/lib/buildgraph/command.cpp b/src/lib/buildgraph/command.cpp
index 9e5d0889e..372d4b469 100644
--- a/src/lib/buildgraph/command.cpp
+++ b/src/lib/buildgraph/command.cpp
@@ -112,6 +112,7 @@ static QScriptValue js_Command(QScriptContext *context, QScriptEngine *engine)
cmd.setProperty("stderrFilterFunction", engine->toScriptValue(commandPrototype.stderrFilterFunction()));
cmd.setProperty("responseFileThreshold", engine->toScriptValue(commandPrototype.responseFileThreshold()));
cmd.setProperty("responseFileUsagePrefix", engine->toScriptValue(commandPrototype.responseFileUsagePrefix()));
+ cmd.setProperty("environment", engine->toScriptValue(commandPrototype.environment().toStringList()));
return cmd;
}
@@ -129,9 +130,21 @@ ProcessCommand::ProcessCommand()
{
}
+void ProcessCommand::getEnvironmentFromList(const QStringList &envList)
+{
+ m_environment.clear();
+ foreach (const QString &env, envList) {
+ const int equalsIndex = env.indexOf(QLatin1Char('='));
+ if (equalsIndex <= 0 || equalsIndex == env.count() - 1)
+ continue;
+ const QString &var = env.left(equalsIndex);
+ const QString &value = env.mid(equalsIndex + 1);
+ m_environment.insert(var, value);
+ }
+}
+
void ProcessCommand::fillFromScriptValue(const QScriptValue *scriptValue, const CodeLocation &codeLocation)
{
- Q_UNUSED(codeLocation);
AbstractCommand::fillFromScriptValue(scriptValue, codeLocation);
m_program = scriptValue->property("program").toString();
m_arguments = scriptValue->property("arguments").toVariant().toStringList();
@@ -141,19 +154,25 @@ void ProcessCommand::fillFromScriptValue(const QScriptValue *scriptValue, const
m_stderrFilterFunction = scriptValue->property("stderrFilterFunction").toString();
m_responseFileThreshold = scriptValue->property("responseFileThreshold").toInt32();
m_responseFileUsagePrefix = scriptValue->property("responseFileUsagePrefix").toString();
+ QStringList envList = scriptValue->property(QLatin1String("environment")).toVariant()
+ .toStringList();
+ getEnvironmentFromList(envList);
}
void ProcessCommand::load(QDataStream &s)
{
AbstractCommand::load(s);
+ QStringList envList;
s >> m_program
>> m_arguments
+ >> envList
>> m_workingDir
>> m_maxExitCode
>> m_stdoutFilterFunction
>> m_stderrFilterFunction
>> m_responseFileThreshold
>> m_responseFileUsagePrefix;
+ getEnvironmentFromList(envList);
}
void ProcessCommand::store(QDataStream &s)
@@ -161,6 +180,7 @@ void ProcessCommand::store(QDataStream &s)
AbstractCommand::store(s);
s << m_program
<< m_arguments
+ << m_environment.toStringList()
<< m_workingDir
<< m_maxExitCode
<< m_stdoutFilterFunction
diff --git a/src/lib/buildgraph/command.h b/src/lib/buildgraph/command.h
index fbd011ac7..d59783f0f 100644
--- a/src/lib/buildgraph/command.h
+++ b/src/lib/buildgraph/command.h
@@ -32,6 +32,7 @@
#include <tools/codelocation.h>
+#include <QProcessEnvironment>
#include <QStringList>
#include <QVariantMap>
#include <QScriptValue>
@@ -113,7 +114,11 @@ public:
QString responseFileUsagePrefix() const { return m_responseFileUsagePrefix; }
void setResponseFileUsagePrefix(const QString &function) { m_responseFileUsagePrefix = function; }
+ QProcessEnvironment environment() const { return m_environment; }
+
private:
+ void getEnvironmentFromList(const QStringList &envList);
+
QString m_program;
QStringList m_arguments;
QString m_workingDir;
@@ -122,6 +127,7 @@ private:
QString m_stderrFilterFunction;
int m_responseFileThreshold; // When to use response files? In bytes of (program name + arguments).
QString m_responseFileUsagePrefix;
+ QProcessEnvironment m_environment;
};
class JavaScriptCommand : public AbstractCommand
diff --git a/src/lib/buildgraph/processcommandexecutor.cpp b/src/lib/buildgraph/processcommandexecutor.cpp
index c61a8f700..122e1e993 100644
--- a/src/lib/buildgraph/processcommandexecutor.cpp
+++ b/src/lib/buildgraph/processcommandexecutor.cpp
@@ -72,11 +72,6 @@ ProcessCommandExecutor::ProcessCommandExecutor(const Logger &logger, QObject *pa
connect(&m_process, SIGNAL(finished(int)), SLOT(onProcessFinished(int)));
}
-void ProcessCommandExecutor::setProcessEnvironment(const QProcessEnvironment &processEnvironment)
-{
- m_process.setProcessEnvironment(processEnvironment);
-}
-
// returns an empty string or one that starts with a space!
static QString commandArgsToString(const QStringList &args)
{
@@ -106,6 +101,12 @@ void ProcessCommandExecutor::doStart()
program = findProcessCommandInPath();
}
+ 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);
+
QStringList arguments = cmd->arguments();
QString argString = commandArgsToString(arguments);
diff --git a/src/lib/buildgraph/processcommandexecutor.h b/src/lib/buildgraph/processcommandexecutor.h
index 27ef56855..d1f55c4b3 100644
--- a/src/lib/buildgraph/processcommandexecutor.h
+++ b/src/lib/buildgraph/processcommandexecutor.h
@@ -33,6 +33,7 @@
#include "abstractcommandexecutor.h"
#include <QProcess>
+#include <QProcessEnvironment>
#include <QString>
namespace qbs {
@@ -47,7 +48,9 @@ class ProcessCommandExecutor : public AbstractCommandExecutor
public:
explicit ProcessCommandExecutor(const Internal::Logger &logger, QObject *parent = 0);
- void setProcessEnvironment(const QProcessEnvironment &processEnvironment);
+ void setProcessEnvironment(const QProcessEnvironment &processEnvironment) {
+ m_buildEnvironment = processEnvironment;
+ }
signals:
void reportProcessResult(const qbs::ProcessResult &result);
@@ -76,6 +79,7 @@ private:
QStringList m_arguments;
QProcess m_process;
+ QProcessEnvironment m_buildEnvironment;
QString m_responseFileName;
};
diff --git a/src/lib/tools/persistence.cpp b/src/lib/tools/persistence.cpp
index c04c8a75e..ee65f64e3 100644
--- a/src/lib/tools/persistence.cpp
+++ b/src/lib/tools/persistence.cpp
@@ -39,7 +39,7 @@
namespace qbs {
namespace Internal {
-static const char QBS_PERSISTENCE_MAGIC[] = "QBSPERSISTENCE0_0_1__34";
+static const char QBS_PERSISTENCE_MAGIC[] = "QBSPERSISTENCE0_0_1__35";
PersistentPool::PersistentPool(const Logger &logger) : m_logger(logger)
{