10#define SRC_EXECUTOR_H_
14#include <QProcessEnvironment>
100 static void startProcess(QProcess &process,
const QString &app,
101 const QStringList &args);
111 -> std::pair<QString, QString>;
134 static auto runBlocking(QProcess &process,
const QString &app,
135 const QStringList &args,
const QString &input,
136 QString *process_out, QString *process_err,
137 const std::atomic_bool *cancel =
nullptr,
138 int timeoutMs = -1) -> int;
145 explicit Executor(QObject *parent =
nullptr);
155 void execute(
int id,
const QString &app,
const QStringList &args,
156 bool readStdout,
bool readStderr =
true);
167 void execute(
int id,
const QString &workDir,
const QString &app,
168 const QStringList &args,
bool readStdout,
169 bool readStderr =
true);
180 void execute(
int id,
const QString &app,
const QStringList &args,
181 QString input = QString(),
bool readStdout =
false,
182 bool readStderr =
true);
194 void execute(
int id,
const QString &workDir,
const QString &app,
195 const QStringList &args, QString input = QString(),
196 bool readStdout =
false,
bool readStderr =
true);
208 const QStringList &args,
209 const QString &input = QString(),
210 QString *process_out =
nullptr,
211 QString *process_err =
nullptr)
247 QProcess &process,
const QString &app,
const QStringList &args,
248 const QString &input = QString(), QString *process_out =
nullptr,
249 QString *process_err =
nullptr,
const std::atomic_bool *cancel =
nullptr,
250 int timeoutMs = -1) -> int;
260 [[nodiscard]]
static auto
262 QString *process_out, QString *process_err =
nullptr) -> int;
273 [[nodiscard]]
static auto
275 const QStringList &args, QString *process_out =
nullptr,
276 QString *process_err =
nullptr) -> int;
321 [[nodiscard]]
static auto childUmask() -> int;
356 auto argv(
const QStringList &args)
const -> QStringList;
380 static auto parseWslCommand(
const QString &app) -> std::optional<WslCommand>;
389 static auto wslExecArgs(
const QString &command,
const QStringList &args)
473 void finished(
int id,
int exitCode,
const QString &output,
474 const QString &errout);
505 void error(
int id,
int exitCode,
const QString &output,
506 const QString &errout);
void dequeuing(int id, bool completes)
Emitted, synchronously, when the queue's head leaves it: just before it is started,...
QQueue< ExecQueueItem > m_execQueue
Commands waiting to run, head first. The head stays queued while it runs and is dequeued in onProcess...
auto isIdle() const -> bool
Whether no command is running and nothing is queued.
static auto childUmask() -> int
The umask setChildUmask() set.
static auto executeBlocking(const QString &app, const QStringList &args, const QString &input=QString(), QString *process_out=nullptr, QString *process_err=nullptr) -> int
Run a command synchronously and return its exit code.
static auto translatePathForWsl(const QString &path, const QString &exe) -> QString
Translate a native path for a WSL-routed executable.
auto environment() const -> QProcessEnvironment
Return the environment passed to child processes.
void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
Finish the running item when its process exits.
int m_pendingErrors
error()s of failed starts posted but not delivered yet.
auto collectOutput(const ExecQueueItem &item, int exitCode) -> std::pair< QString, QString >
Read what a finished process produced, according to the queue item's readStdout/readStderr flags; std...
bool m_drainCheckPosted
A drained() check is posted and not run yet.
auto hasQueued(int id) const -> bool
Whether a command with process id id is queued or running.
static void startProcess(QProcess &process, const QString &app, const QStringList &args)
Start process running app, handling the "wsl " prefix once for both the queued and the blocking path.
void execute(int id, const QString &app, const QStringList &args, bool readStdout, bool readStderr=true)
Queue a command without stdin input.
static auto resolveExecutable(const QString &app) -> QString
The one rule for turning a configured executable into what runs.
void drained()
Emitted once the last queued item is done and nothing runs or waits any more (isIdle()),...
void error(int id, int exitCode, const QString &output, const QString &errout)
Emitted instead of finished() when a queued process could not be started, had no executable configure...
static auto wslExecArgs(const QString &command, const QStringList &args) -> QStringList
Build the wsl.exe argument list that runs command directly.
static void setChildUmask(int mask)
The umask every child QtPass starts gets, as pass sets its own.
Executor(QObject *parent=nullptr)
Construct an Executor with an optional parent QObject.
bool running
Whether the head of the queue has been started (or is being dequeued, see dequeuing()) and has not fi...
void finished(int id, int exitCode, const QString &output, const QString &errout)
Emitted when a queued process exits normally, whatever its exit code; a non-zero code is the receiver...
void starting()
Emitted just before a queued process is started; the main window shows the busy indicator on it.
void setEnvironment(const QProcessEnvironment &env)
Set the environment passed to all child processes.
static auto runBlocking(QProcess &process, const QString &app, const QStringList &args, const QString &input, QString *process_out, QString *process_err, const std::atomic_bool *cancel=nullptr, int timeoutMs=-1) -> int
Shared blocking run: start process, optionally feed input on stdin, wait, and capture stdout/stderr....
static void detachFromTerminal(QProcess &process)
Make process start its child without a controlling terminal.
void executeNext()
Start the head of the queue unless something runs or the queue is empty.
static auto parseWslCommand(const QString &app) -> std::optional< WslCommand >
Parse a configured executable as a WSL command.
auto cancelNext() -> int
Cancel the next queued command without executing it.
QProcess m_process
The one process object; every queued command reuses it.
Execution queue item for non-interactive ordered execution.
bool readStdout
Whether stdout is captured for finished().
QString workingDir
Working directory to start in; empty for the current one.
QString input
Data written to the process's stdin, then closed.
int id
Identifier the caller gave; echoed in finished()/error().
bool readStderr
Whether stderr is captured; it is read regardless when the process exits non-zero.
QStringList args
Arguments for the executable.
QString app
Executable as configured; resolved when started.
A configured executable that runs a Linux program through WSL.
auto argv(const QStringList &args) const -> QStringList
Arguments for launcher that run command with args.
QString command
The Linux program to run, looked up on the WSL PATH.
QString launcher
What to start.
QStringList options
wsl.exe options that go before the program (-d Debian, -u me), without any -e/--exec: argv() always a...
auto with(const QString &program) const -> WslCommand
The same launcher and options running another program.