A gift for Alessandro

Add an info to the start process log about whether it was
started by a call to QtcProcess::runBlocking() or not.
In case it was, specify the event loop mode.

Change-Id: Ie1adf0526b341eedcd0d84505075a942b057ff99
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Jarek Kobus
2022-02-16 23:55:44 +01:00
parent e0d6568751
commit 0b08b24682

View File

@@ -69,6 +69,8 @@ using namespace Utils::Internal;
namespace Utils { namespace Utils {
namespace Internal { namespace Internal {
const char QTC_PROCESS_BLOCKING_TYPE[] = "__BLOCKING_TYPE__";
class MeasureAndRun class MeasureAndRun
{ {
public: public:
@@ -568,8 +570,24 @@ QtcProcess::Result QtcProcessPrivate::interpretExitCode(int exitCode)
} // Internal } // Internal
static QString blockingMessage(const QVariant &variant)
{
if (!variant.isValid())
return "(non blocking):";
if (variant.toInt() == int(QtcProcess::WithEventLoop))
return "(blocking with event loop):";
return "(blocking without event loop):";
}
void ProcessInterface::defaultStart() void ProcessInterface::defaultStart()
{ {
if (processLog().isDebugEnabled()) {
static std::atomic_int n = 0;
qCDebug(processLog) << "Starting process no." << ++n
<< qPrintable(blockingMessage(property(QTC_PROCESS_BLOCKING_TYPE)))
<< m_setup.m_commandLine.toUserOutput();
}
QString program; QString program;
QStringList arguments; QStringList arguments;
if (!dissolveCommand(&program, &arguments)) if (!dissolveCommand(&program, &arguments))
@@ -582,11 +600,6 @@ void ProcessInterface::defaultStart()
bool ProcessInterface::dissolveCommand(QString *program, QStringList *arguments) bool ProcessInterface::dissolveCommand(QString *program, QStringList *arguments)
{ {
const CommandLine &commandLine = m_setup.m_commandLine; const CommandLine &commandLine = m_setup.m_commandLine;
if (processLog().isDebugEnabled()) {
static std::atomic_int n = 0;
qCDebug(processLog) << "STARTING PROCESS: " << ++n << " " << commandLine.toUserOutput();
}
QString commandString; QString commandString;
ProcessArgs processArgs; ProcessArgs processArgs;
const bool success = ProcessArgs::prepareCommand(commandLine, &commandString, &processArgs, const bool success = ProcessArgs::prepareCommand(commandLine, &commandString, &processArgs,
@@ -772,6 +785,10 @@ void QtcProcess::start()
d->clearForRun(); d->clearForRun();
d->m_process->m_setup.m_commandLine = d->fullCommandLine(); d->m_process->m_setup.m_commandLine = d->fullCommandLine();
d->m_process->m_setup.m_environment = d->fullEnvironment(); d->m_process->m_setup.m_environment = d->fullEnvironment();
if (processLog().isDebugEnabled()) {
// Pass a dynamic property with info about blocking type
d->m_process->setProperty(QTC_PROCESS_BLOCKING_TYPE, property(QTC_PROCESS_BLOCKING_TYPE));
}
d->m_process->start(); d->m_process->start();
} }
@@ -1482,11 +1499,18 @@ void QtcProcess::runBlocking(QtcProcess::EventLoopMode eventLoopMode)
return; return;
}; };
qCDebug(processLog).noquote() << "Starting blocking:" << d->m_setup.m_commandLine.toUserOutput() if (processLog().isDebugEnabled()) {
<< " process user events: " << (eventLoopMode == QtcProcess::WithEventLoop); // Attach a dynamic property with info about blocking type
setProperty(QTC_PROCESS_BLOCKING_TYPE, int(eventLoopMode));
}
ExecuteOnDestruction logResult([this] { qCDebug(processLog) << *this; }); ExecuteOnDestruction logResult([this] { qCDebug(processLog) << *this; });
QtcProcess::start(); QtcProcess::start();
if (processLog().isDebugEnabled()) {
// Remove the dynamic property so that it's not reused in subseqent start()
setProperty(QTC_PROCESS_BLOCKING_TYPE, QVariant());
}
if (eventLoopMode == QtcProcess::WithEventLoop) { if (eventLoopMode == QtcProcess::WithEventLoop) {
// On Windows, start failure is triggered immediately if the // On Windows, start failure is triggered immediately if the
// executable cannot be found in the path. Do not start the // executable cannot be found in the path. Do not start the