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 <orgads@gmail.com>
This commit is contained in:
Tobias Hunger
2015-06-08 13:51:29 +02:00
parent 2221636cfb
commit ea476ffc39
5 changed files with 24 additions and 20 deletions

View File

@@ -73,21 +73,23 @@ class ShellCommandPrivate
{ {
public: public:
struct Job { 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); Utils::ExitCodeInterpreter *interpreter = 0);
QString workingDirectory;
Utils::FileName binary; Utils::FileName binary;
QStringList arguments; QStringList arguments;
int timeoutS; int timeoutS;
Utils::ExitCodeInterpreter *exitCodeInterpreter; Utils::ExitCodeInterpreter *exitCodeInterpreter;
}; };
ShellCommandPrivate(const QString &workingDirectory, const QProcessEnvironment &environment); ShellCommandPrivate(const QString &defaultWorkingDirectory,
const QProcessEnvironment &environment);
~ShellCommandPrivate(); ~ShellCommandPrivate();
std::function<OutputProxy *()> m_proxyFactory = []() { return new OutputProxy; }; std::function<OutputProxy *()> m_proxyFactory = []() { return new OutputProxy; };
QString m_displayName; QString m_displayName;
const QString m_workingDirectory; const QString m_defaultWorkingDirectory;
const QProcessEnvironment m_environment; const QProcessEnvironment m_environment;
QVariant m_cookie; QVariant m_cookie;
int m_defaultTimeoutS; int m_defaultTimeoutS;
@@ -105,9 +107,9 @@ public:
int m_lastExecExitCode; int m_lastExecExitCode;
}; };
ShellCommandPrivate::ShellCommandPrivate(const QString &workingDirectory, ShellCommandPrivate::ShellCommandPrivate(const QString &defaultWorkingDirectory,
const QProcessEnvironment &environment) : const QProcessEnvironment &environment) :
m_workingDirectory(workingDirectory), m_defaultWorkingDirectory(defaultWorkingDirectory),
m_environment(environment), m_environment(environment),
m_defaultTimeoutS(10), m_defaultTimeoutS(10),
m_flags(0), m_flags(0),
@@ -125,8 +127,9 @@ ShellCommandPrivate::~ShellCommandPrivate()
delete m_progressParser; 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) : int t, Utils::ExitCodeInterpreter *interpreter) :
workingDirectory(wd),
binary(b), binary(b),
arguments(a), arguments(a),
timeoutS(t), timeoutS(t),
@@ -171,9 +174,9 @@ void ShellCommand::setDisplayName(const QString &name)
d->m_displayName = 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 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, void ShellCommand::addJob(const Utils::FileName &binary, const QStringList &arguments, int timeoutS,
Utils::ExitCodeInterpreter *interpreter) 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() void ShellCommand::execute()
@@ -320,7 +324,7 @@ Utils::SynchronousProcessResponse ShellCommand::runCommand(const Utils::FileName
QSharedPointer<OutputProxy> proxy(d->m_proxyFactory()); QSharedPointer<OutputProxy> proxy(d->m_proxyFactory());
if (!(d->m_flags & SuppressCommandLogging)) if (!(d->m_flags & SuppressCommandLogging))
proxy->appendCommand(d->m_workingDirectory, binary, arguments); proxy->appendCommand(d->m_defaultWorkingDirectory, binary, arguments);
if (d->m_flags & FullySynchronously) { if (d->m_flags & FullySynchronously) {
response = runSynchronous(binary, arguments, timeoutS, interpreter); response = runSynchronous(binary, arguments, timeoutS, interpreter);
@@ -328,8 +332,8 @@ Utils::SynchronousProcessResponse ShellCommand::runCommand(const Utils::FileName
Utils::SynchronousProcess process; Utils::SynchronousProcess process;
process.setExitCodeInterpreter(interpreter); process.setExitCodeInterpreter(interpreter);
connect(this, &ShellCommand::terminate, &process, &Utils::SynchronousProcess::terminate); connect(this, &ShellCommand::terminate, &process, &Utils::SynchronousProcess::terminate);
if (!d->m_workingDirectory.isEmpty()) if (!d->m_defaultWorkingDirectory.isEmpty())
process.setWorkingDirectory(d->m_workingDirectory); process.setWorkingDirectory(d->m_defaultWorkingDirectory);
process.setProcessEnvironment(processEnvironment()); process.setProcessEnvironment(processEnvironment());
process.setTimeoutS(timeoutS); process.setTimeoutS(timeoutS);
@@ -402,8 +406,8 @@ Utils::SynchronousProcessResponse ShellCommand::runSynchronous(const Utils::File
// Set up process // Set up process
QSharedPointer<QProcess> process = Utils::SynchronousProcess::createProcess(processFlags()); QSharedPointer<QProcess> process = Utils::SynchronousProcess::createProcess(processFlags());
if (!d->m_workingDirectory.isEmpty()) if (!d->m_defaultWorkingDirectory.isEmpty())
process->setWorkingDirectory(d->m_workingDirectory); process->setWorkingDirectory(d->m_defaultWorkingDirectory);
process->setProcessEnvironment(processEnvironment()); process->setProcessEnvironment(processEnvironment());
if (d->m_flags & MergeOutputChannels) if (d->m_flags & MergeOutputChannels)
process->setProcessChannelMode(QProcess::MergedChannels); process->setProcessChannelMode(QProcess::MergedChannels);
@@ -463,10 +467,10 @@ bool ShellCommand::runFullySynchronous(const Utils::FileName &binary, const QStr
QScopedPointer<OutputProxy> proxy(d->m_proxyFactory()); QScopedPointer<OutputProxy> proxy(d->m_proxyFactory());
if (!(d->m_flags & SuppressCommandLogging)) if (!(d->m_flags & SuppressCommandLogging))
proxy->appendCommand(d->m_workingDirectory, binary, arguments); proxy->appendCommand(d->m_defaultWorkingDirectory, binary, arguments);
QProcess process; QProcess process;
process.setWorkingDirectory(d->m_workingDirectory); process.setWorkingDirectory(d->m_defaultWorkingDirectory);
process.setProcessEnvironment(d->m_environment); process.setProcessEnvironment(d->m_environment);
process.start(binary.toString(), arguments); process.start(binary.toString(), arguments);

View File

@@ -128,7 +128,7 @@ public:
bool lastExecutionSuccess() const; bool lastExecutionSuccess() const;
int lastExecutionExitCode() const; int lastExecutionExitCode() const;
const QString &workingDirectory() const; const QString &defaultWorkingDirectory() const;
virtual const QProcessEnvironment processEnvironment() const; virtual const QProcessEnvironment processEnvironment() const;
int defaultTimeoutS() const; int defaultTimeoutS() const;

View File

@@ -472,7 +472,7 @@ class ConflictHandler : public QObject
Q_OBJECT Q_OBJECT
public: public:
static void attachToCommand(VcsCommand *command, const QString &abortCommand = QString()) { 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 handler->setParent(command); // delete when command goes out of scope
command->addFlags(VcsCommand::ExpectRepoChanges); command->addFlags(VcsCommand::ExpectRepoChanges);

View File

@@ -116,7 +116,7 @@ void VcsCommand::emitRepositoryChanged()
return; return;
// TODO tell the document manager that the directory now received all expected changes // TODO tell the document manager that the directory now received all expected changes
// Core::DocumentManager::unexpectDirectoryChange(d->m_workingDirectory); // Core::DocumentManager::unexpectDirectoryChange(d->m_workingDirectory);
Core::VcsManager::emitRepositoryChanged(workingDirectory()); Core::VcsManager::emitRepositoryChanged(defaultWorkingDirectory());
} }
unsigned VcsCommand::processFlags() const unsigned VcsCommand::processFlags() const

View File

@@ -47,7 +47,7 @@ public:
ExpectRepoChanges = 0x2000, // Expect changes in repository by the command 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; const QProcessEnvironment processEnvironment() const;