AppMan: Inline AppManInferiorRunner

Change-Id: I3e67d39de10f88b6b98fbf8ea0856bd0562de687
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-11-20 16:14:54 +01:00
parent c6ff6d8a8f
commit 490a859ee9

View File

@@ -92,79 +92,72 @@ public:
} }
}; };
static RunWorker *createInferiorRunner(RunControl *runControl, QmlDebugServicesPreset qmlServices)
// AppManInferiorRunner
class AppManInferiorRunner : public SimpleTargetRunner
{ {
public: auto worker = new SimpleTargetRunner(runControl);
AppManInferiorRunner(RunControl *runControl, QmlDebugServicesPreset qmlServices) worker->setId(AppManager::Constants::DEBUG_LAUNCHER_ID);
: SimpleTargetRunner(runControl) worker->setEssential(true);
{
setId(AppManager::Constants::DEBUG_LAUNCHER_ID);
setEssential(true);
if (usesPerfChannel()) { if (worker->usesPerfChannel()) {
suppressDefaultStdOutHandling(); worker->suppressDefaultStdOutHandling();
runControl->setProperty("PerfProcess", QVariant::fromValue(process())); runControl->setProperty("PerfProcess", QVariant::fromValue(worker->process()));
}
worker->setStartModifier([worker, runControl, qmlServices] {
FilePath controller = runControl->aspectData<AppManagerControllerAspect>()->filePath;
QString appId = runControl->aspectData<AppManagerIdAspect>()->value;
QString instanceId = runControl->aspectData<AppManagerInstanceIdAspect>()->value;
QString documentUrl = runControl->aspectData<AppManagerDocumentUrlAspect>()->value;
bool restartIfRunning = runControl->aspectData<AppManagerRestartIfRunningAspect>()->value;
QStringList envVars;
if (auto envAspect = runControl->aspectData<EnvironmentAspect>())
envVars = envAspect->environment.toStringList();
envVars.replaceInStrings(" ", "\\ ");
CommandLine cmd{controller};
if (!instanceId.isEmpty())
cmd.addArgs({"--instance-id", instanceId});
cmd.addArg("debug-application");
if (worker->usesDebugChannel() || worker->usesQmlChannel()) {
QStringList debugArgs;
debugArgs.append(envVars.join(' '));
if (worker->usesDebugChannel())
debugArgs.append(QString("gdbserver :%1").arg(worker->debugChannel().port()));
if (worker->usesQmlChannel()) {
const QString qmlArgs = qmlDebugCommandLineArguments(qmlServices,
QString("port:%1").arg(worker->qmlChannel().port()), true);
debugArgs.append(QString("%program% %1 %arguments%") .arg(qmlArgs));
}
cmd.addArg(debugArgs.join(' '));
}
if (worker->usesPerfChannel()) {
const Store perfArgs = runControl->settingsData(PerfProfiler::Constants::PerfSettingsId);
const QString recordArgs = perfArgs[PerfProfiler::Constants::PerfRecordArgsId].toString();
cmd.addArg(QString("perf record %1 -o - --").arg(recordArgs));
} }
setStartModifier([this, runControl, qmlServices] { cmd.addArg("-eio");
FilePath controller = runControl->aspectData<AppManagerControllerAspect>()->filePath; if (restartIfRunning)
QString appId = runControl->aspectData<AppManagerIdAspect>()->value; cmd.addArg("--restart");
QString instanceId = runControl->aspectData<AppManagerInstanceIdAspect>()->value; cmd.addArg(appId);
QString documentUrl = runControl->aspectData<AppManagerDocumentUrlAspect>()->value;
bool restartIfRunning = runControl->aspectData<AppManagerRestartIfRunningAspect>()->value;
QStringList envVars;
if (auto envAspect = runControl->aspectData<EnvironmentAspect>())
envVars = envAspect->environment.toStringList();
envVars.replaceInStrings(" ", "\\ ");
CommandLine cmd{controller}; if (!documentUrl.isEmpty())
if (!instanceId.isEmpty()) cmd.addArg(documentUrl);
cmd.addArgs({"--instance-id", instanceId});
cmd.addArg("debug-application"); // Always use the default environment to start the appman-controller in
// The env variables from the EnvironmentAspect are set through the controller
if (usesDebugChannel() || usesQmlChannel()) { worker->setEnvironment({});
QStringList debugArgs; // Prevent the write channel to be closed, otherwise the appman-controller will exit
debugArgs.append(envVars.join(' ')); worker->setProcessMode(ProcessMode::Writer);
if (usesDebugChannel()) worker->setCommandLine(cmd);
debugArgs.append(QString("gdbserver :%1").arg(debugChannel().port()));
if (usesQmlChannel()) {
const QString qmlArgs = qmlDebugCommandLineArguments(qmlServices,
QString("port:%1").arg(qmlChannel().port()), true);
debugArgs.append(QString("%program% %1 %arguments%") .arg(qmlArgs));
}
cmd.addArg(debugArgs.join(' '));
}
if (usesPerfChannel()) {
const Store perfArgs = runControl->settingsData(PerfProfiler::Constants::PerfSettingsId);
const QString recordArgs = perfArgs[PerfProfiler::Constants::PerfRecordArgsId].toString();
cmd.addArg(QString("perf record %1 -o - --").arg(recordArgs));
}
cmd.addArg("-eio");
if (restartIfRunning)
cmd.addArg("--restart");
cmd.addArg(appId);
if (!documentUrl.isEmpty())
cmd.addArg(documentUrl);
// Always use the default environment to start the appman-controller in
// The env variables from the EnvironmentAspect are set through the controller
setEnvironment({});
// Prevent the write channel to be closed, otherwise the appman-controller will exit
setProcessMode(ProcessMode::Writer);
setCommandLine(cmd);
appendMessage(Tr::tr("Starting Application Manager debugging..."), NormalMessageFormat);
appendMessage(Tr::tr("Using: %1.").arg(cmd.toUserOutput()), NormalMessageFormat);
});
}
};
worker->appendMessage(Tr::tr("Starting Application Manager debugging..."), NormalMessageFormat);
worker->appendMessage(Tr::tr("Using: %1.").arg(cmd.toUserOutput()), NormalMessageFormat);
});
return worker;
}
// AppManagerDebugSupport // AppManagerDebugSupport
@@ -181,7 +174,7 @@ public:
if (isQmlDebugging()) if (isQmlDebugging())
runControl->requestQmlChannel(); runControl->requestQmlChannel();
auto debuggee = new AppManInferiorRunner(runControl, QmlDebuggerServices); auto debuggee = createInferiorRunner(runControl, QmlDebuggerServices);
addStartDependency(debuggee); addStartDependency(debuggee);
addStopDependency(debuggee); addStopDependency(debuggee);
@@ -260,7 +253,7 @@ public:
runControl->requestQmlChannel(); runControl->requestQmlChannel();
QmlDebugServicesPreset services = servicesForRunMode(runControl->runMode()); QmlDebugServicesPreset services = servicesForRunMode(runControl->runMode());
auto runner = new AppManInferiorRunner(runControl, services); auto runner = createInferiorRunner(runControl, services);
addStartDependency(runner); addStartDependency(runner);
addStopDependency(runner); addStopDependency(runner);
@@ -284,7 +277,7 @@ public:
setId("AppManagerPerfProfilerSupport"); setId("AppManagerPerfProfilerSupport");
runControl->requestPerfChannel(); runControl->requestPerfChannel();
auto profilee = new AppManInferiorRunner(runControl, NoQmlDebugServices); auto profilee = createInferiorRunner(runControl, NoQmlDebugServices);
addStartDependency(profilee); addStartDependency(profilee);
addStopDependency(profilee); addStopDependency(profilee);
} }