forked from qt-creator/qt-creator
Utils: Add a synchronous property to QtcProcess interface
Use it to avoid IDevice interface clutter. Change-Id: I4a04f04e2c343593d937a402060e56ef94fcabf1 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -278,6 +278,8 @@ public:
|
||||
|
||||
~DockerDevicePrivate() { delete m_shell; }
|
||||
|
||||
int runSynchronously(const CommandLine &cmd) const;
|
||||
|
||||
DockerDeviceData m_data;
|
||||
|
||||
// For local file access
|
||||
@@ -542,7 +544,7 @@ bool DockerDevice::isExecutableFile(const FilePath &filePath) const
|
||||
}
|
||||
const QString path = filePath.toUrl().path();
|
||||
const CommandLine cmd("test", {"-x", path});
|
||||
const int exitCode = runSynchronously(cmd);
|
||||
const int exitCode = d->runSynchronously(cmd);
|
||||
return exitCode == 0;
|
||||
}
|
||||
|
||||
@@ -558,7 +560,7 @@ bool DockerDevice::isReadableFile(const FilePath &filePath) const
|
||||
}
|
||||
const QString path = filePath.toUrl().path();
|
||||
const CommandLine cmd("test", {"-r", path, "-a", "-f", path});
|
||||
const int exitCode = runSynchronously(cmd);
|
||||
const int exitCode = d->runSynchronously(cmd);
|
||||
return exitCode == 0;
|
||||
}
|
||||
|
||||
@@ -574,7 +576,7 @@ bool DockerDevice::isReadableDirectory(const FilePath &filePath) const
|
||||
}
|
||||
const QString path = filePath.toUrl().path();
|
||||
const CommandLine cmd("test", {"-x", path, "-a", "-d", path});
|
||||
const int exitCode = runSynchronously(cmd);
|
||||
const int exitCode = d->runSynchronously(cmd);
|
||||
return exitCode == 0;
|
||||
}
|
||||
|
||||
@@ -590,7 +592,7 @@ bool DockerDevice::isWritableDirectory(const FilePath &filePath) const
|
||||
}
|
||||
const QString path = filePath.toUrl().path();
|
||||
const CommandLine cmd("test", {"-x", path, "-a", "-d", path});
|
||||
const int exitCode = runSynchronously(cmd);
|
||||
const int exitCode = d->runSynchronously(cmd);
|
||||
return exitCode == 0;
|
||||
}
|
||||
|
||||
@@ -606,7 +608,7 @@ bool DockerDevice::createDirectory(const FilePath &filePath) const
|
||||
}
|
||||
const QString path = filePath.toUrl().path();
|
||||
const CommandLine cmd("mkdir", {"-p", path});
|
||||
const int exitCode = runSynchronously(cmd);
|
||||
const int exitCode = d->runSynchronously(cmd);
|
||||
return exitCode == 0;
|
||||
}
|
||||
|
||||
@@ -651,21 +653,16 @@ void DockerDevice::runProcess(QtcProcess &process) const
|
||||
process.start();
|
||||
}
|
||||
|
||||
int DockerDevice::runSynchronously(const CommandLine &cmd, QByteArray *out, QByteArray *err) const
|
||||
int DockerDevicePrivate::runSynchronously(const CommandLine &cmd) const
|
||||
{
|
||||
CommandLine dcmd{"docker", {"exec", d->m_container}};
|
||||
CommandLine dcmd{"docker", {"exec", m_container}};
|
||||
dcmd.addArgs(cmd);
|
||||
|
||||
QtcProcess proc;
|
||||
proc.setCommand(dcmd);
|
||||
proc.setWorkingDirectory("/tmp");
|
||||
proc.setSynchronous(true);
|
||||
proc.start();
|
||||
proc.waitForFinished();
|
||||
|
||||
if (out)
|
||||
*out = proc.readAllStandardOutput();
|
||||
if (err)
|
||||
*err = proc.readAllStandardError();
|
||||
|
||||
LOG("Run sync:" << dcmd.toUserOutput() << " result: " << proc.exitCode());
|
||||
return proc.exitCode();
|
||||
|
||||
@@ -84,10 +84,6 @@ public:
|
||||
QByteArray fileContents(const Utils::FilePath &filePath, int limit) const override;
|
||||
void runProcess(Utils::QtcProcess &process) const override;
|
||||
|
||||
int runSynchronously(const Utils::CommandLine &cmd,
|
||||
QByteArray *out = nullptr,
|
||||
QByteArray *err = nullptr) const override;
|
||||
|
||||
const DockerDeviceData &data() const;
|
||||
void autoDetectQtVersion() const;
|
||||
void autoDetectToolChains();
|
||||
|
||||
@@ -277,15 +277,6 @@ void IDevice::runProcess(QtcProcess &process) const
|
||||
QTC_CHECK(false);
|
||||
}
|
||||
|
||||
int IDevice::runSynchronously(const CommandLine &cmd, QByteArray *out, QByteArray *err) const
|
||||
{
|
||||
Q_UNUSED(cmd);
|
||||
Q_UNUSED(out);
|
||||
Q_UNUSED(err);
|
||||
QTC_CHECK(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Environment IDevice::systemEnvironment() const
|
||||
{
|
||||
QTC_CHECK(false);
|
||||
|
||||
@@ -246,9 +246,6 @@ public:
|
||||
QDir::Filters filters) const;
|
||||
virtual QByteArray fileContents(const Utils::FilePath &filePath, int limit) const;
|
||||
virtual void runProcess(Utils::QtcProcess &process) const;
|
||||
virtual int runSynchronously(const Utils::CommandLine &cmd,
|
||||
QByteArray *out = nullptr,
|
||||
QByteArray *err = nullptr) const;
|
||||
virtual Utils::Environment systemEnvironment() const;
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user