Commit ea476ffc authored by Tobias Hunger's avatar Tobias Hunger
Browse files

ShellCommand: Store workingdirectory in the jobs



Not all jobs of one command can run in the same directory, so
prepare for having individual working directories per job.

Change-Id: Ice43361fe54f2b7153ccd38435f6108d83570082
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent 2221636c
......@@ -73,21 +73,23 @@ class ShellCommandPrivate
{
public:
struct Job {
explicit Job(const Utils::FileName &b, const QStringList &a, int t,
explicit Job(const QString &wd, const Utils::FileName &b, const QStringList &a, int t,
Utils::ExitCodeInterpreter *interpreter = 0);
QString workingDirectory;
Utils::FileName binary;
QStringList arguments;
int timeoutS;
Utils::ExitCodeInterpreter *exitCodeInterpreter;
};
ShellCommandPrivate(const QString &workingDirectory, const QProcessEnvironment &environment);
ShellCommandPrivate(const QString &defaultWorkingDirectory,
const QProcessEnvironment &environment);
~ShellCommandPrivate();
std::function<OutputProxy *()> m_proxyFactory = []() { return new OutputProxy; };
QString m_displayName;
const QString m_workingDirectory;
const QString m_defaultWorkingDirectory;
const QProcessEnvironment m_environment;
QVariant m_cookie;
int m_defaultTimeoutS;
......@@ -105,9 +107,9 @@ public:
int m_lastExecExitCode;
};
ShellCommandPrivate::ShellCommandPrivate(const QString &workingDirectory,
ShellCommandPrivate::ShellCommandPrivate(const QString &defaultWorkingDirectory,
const QProcessEnvironment &environment) :
m_workingDirectory(workingDirectory),
m_defaultWorkingDirectory(defaultWorkingDirectory),
m_environment(environment),
m_defaultTimeoutS(10),
m_flags(0),
......@@ -125,8 +127,9 @@ ShellCommandPrivate::~ShellCommandPrivate()
delete m_progressParser;
}
ShellCommandPrivate::Job::Job(const Utils::FileName &b, const QStringList &a,
ShellCommandPrivate::Job::Job(const QString &wd, const Utils::FileName &b, const QStringList &a,
int t, Utils::ExitCodeInterpreter *interpreter) :
workingDirectory(wd),
binary(b),
arguments(a),
timeoutS(t),
......@@ -171,9 +174,9 @@ void ShellCommand::setDisplayName(const QString &name)
d->m_displayName = name;
}
const QString &ShellCommand::workingDirectory() const
const QString &ShellCommand::defaultWorkingDirectory() const
{
return d->m_workingDirectory;
return d->m_defaultWorkingDirectory;
}
const QProcessEnvironment ShellCommand::processEnvironment() const
......@@ -210,7 +213,8 @@ void ShellCommand::addJob(const Utils::FileName &binary, const QStringList &argu
void ShellCommand::addJob(const Utils::FileName &binary, const QStringList &arguments, int timeoutS,
Utils::ExitCodeInterpreter *interpreter)
{
d->m_jobs.push_back(Internal::ShellCommandPrivate::Job(binary, arguments, timeoutS, interpreter));
d->m_jobs.push_back(Internal::ShellCommandPrivate::Job(d->m_defaultWorkingDirectory, binary,
arguments, timeoutS, interpreter));
}
void ShellCommand::execute()
......@@ -320,7 +324,7 @@ Utils::SynchronousProcessResponse ShellCommand::runCommand(const Utils::FileName
QSharedPointer<OutputProxy> proxy(d->m_proxyFactory());
if (!(d->m_flags & SuppressCommandLogging))
proxy->appendCommand(d->m_workingDirectory, binary, arguments);
proxy->appendCommand(d->m_defaultWorkingDirectory, binary, arguments);
if (d->m_flags & FullySynchronously) {
response = runSynchronous(binary, arguments, timeoutS, interpreter);
......@@ -328,8 +332,8 @@ Utils::SynchronousProcessResponse ShellCommand::runCommand(const Utils::FileName
Utils::SynchronousProcess process;
process.setExitCodeInterpreter(interpreter);
connect(this, &ShellCommand::terminate, &process, &Utils::SynchronousProcess::terminate);
if (!d->m_workingDirectory.isEmpty())
process.setWorkingDirectory(d->m_workingDirectory);
if (!d->m_defaultWorkingDirectory.isEmpty())
process.setWorkingDirectory(d->m_defaultWorkingDirectory);
process.setProcessEnvironment(processEnvironment());
process.setTimeoutS(timeoutS);
......@@ -402,8 +406,8 @@ Utils::SynchronousProcessResponse ShellCommand::runSynchronous(const Utils::File
// Set up process
QSharedPointer<QProcess> process = Utils::SynchronousProcess::createProcess(processFlags());
if (!d->m_workingDirectory.isEmpty())
process->setWorkingDirectory(d->m_workingDirectory);
if (!d->m_defaultWorkingDirectory.isEmpty())
process->setWorkingDirectory(d->m_defaultWorkingDirectory);
process->setProcessEnvironment(processEnvironment());
if (d->m_flags & MergeOutputChannels)
process->setProcessChannelMode(QProcess::MergedChannels);
......@@ -463,10 +467,10 @@ bool ShellCommand::runFullySynchronous(const Utils::FileName &binary, const QStr
QScopedPointer<OutputProxy> proxy(d->m_proxyFactory());
if (!(d->m_flags & SuppressCommandLogging))
proxy->appendCommand(d->m_workingDirectory, binary, arguments);
proxy->appendCommand(d->m_defaultWorkingDirectory, binary, arguments);
QProcess process;
process.setWorkingDirectory(d->m_workingDirectory);
process.setWorkingDirectory(d->m_defaultWorkingDirectory);
process.setProcessEnvironment(d->m_environment);
process.start(binary.toString(), arguments);
......
......@@ -128,7 +128,7 @@ public:
bool lastExecutionSuccess() const;
int lastExecutionExitCode() const;
const QString &workingDirectory() const;
const QString &defaultWorkingDirectory() const;
virtual const QProcessEnvironment processEnvironment() const;
int defaultTimeoutS() const;
......
......@@ -472,7 +472,7 @@ class ConflictHandler : public QObject
Q_OBJECT
public:
static void attachToCommand(VcsCommand *command, const QString &abortCommand = QString()) {
ConflictHandler *handler = new ConflictHandler(command->workingDirectory(), abortCommand);
ConflictHandler *handler = new ConflictHandler(command->defaultWorkingDirectory(), abortCommand);
handler->setParent(command); // delete when command goes out of scope
command->addFlags(VcsCommand::ExpectRepoChanges);
......
......@@ -116,7 +116,7 @@ void VcsCommand::emitRepositoryChanged()
return;
// TODO tell the document manager that the directory now received all expected changes
// Core::DocumentManager::unexpectDirectoryChange(d->m_workingDirectory);
Core::VcsManager::emitRepositoryChanged(workingDirectory());
Core::VcsManager::emitRepositoryChanged(defaultWorkingDirectory());
}
unsigned VcsCommand::processFlags() const
......
......@@ -47,7 +47,7 @@ public:
ExpectRepoChanges = 0x2000, // Expect changes in repository by the command
};
VcsCommand(const QString &workingDirectory, const QProcessEnvironment &environment);
VcsCommand(const QString &defaultWorkingDirectory, const QProcessEnvironment &environment);
const QProcessEnvironment processEnvironment() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment