Files
RedBear-OS/local/recipes/qt/qtdeclarative/source/tools/qmlpreview/qmlpreviewapplication.cpp
T
vasilito f31522130f fix: comprehensive boot warnings and exceptions — fixable silenced, unfixable diagnosed
Build system (5 gaps hardened):
- COOKBOOK_OFFLINE defaults to true (fork-mode)
- normalize_patch handles diff -ruN format
- New 'repo validate-patches' command (25/25 relibc patches)
- 14 patched Qt/Wayland/display recipes added to protected list
- relibc archive regenerated with current patch chain

Boot fixes (fixable):
- Full ISO EFI partition: 16 MiB → 1 MiB (matches mini, BIOS hardcoded 2 MiB offset)
- D-Bus system bus: absolute /usr/bin/dbus-daemon path (was skipped)
- redbear-sessiond: absolute /usr/bin/redbear-sessiond path (was skipped)
- daemon framework: silenced spurious INIT_NOTIFY warnings for oneshot_async services (P0-daemon-silence-init-notify.patch)
- udev-shim: demoted INIT_NOTIFY warning to INFO (expected for oneshot_async)
- relibc: comprehensive named semaphores (sem_open/close/unlink) replacing upstream todo!() stubs
- greeterd: Wayland socket timeout 15s → 30s (compositor DRM wait)
- greeter-ui: built and linked (header guard unification, sem_compat stubs removed)
- mc: un-ignored in both configs, fixed glib/libiconv/pcre2 transitive deps
- greeter config: removed stale keymapd dependency from display/greeter services
- prefix toolchain: relibc headers synced, _RELIBC_STDLIB_H guard unified

Unfixable (diagnosed, upstream):
- i2c-hidd: abort on no-I2C-hardware (QEMU) — process::exit → relibc abort
- kded6/greeter-ui: page fault 0x8 — Qt library null deref
- Thread panics fd != -1 — Rust std library on Redox
- DHCP timeout / eth0 MAC — QEMU user-mode networking
- hwrngd/thermald — no hardware RNG/thermal in VM
- live preload allocation — BIOS memory fragmentation, continues on demand
2026-05-05 20:20:37 +01:00

223 lines
7.3 KiB
C++

// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "qmlpreviewapplication.h"
#include <QtCore/QStringList>
#include <QtCore/QTextStream>
#include <QtCore/QProcess>
#include <QtCore/QTimer>
#include <QtCore/QDateTime>
#include <QtCore/QFileInfo>
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QCommandLineParser>
#include <QtCore/QTemporaryFile>
#include <QtCore/QUrl>
#include <QtCore/QLibraryInfo>
QmlPreviewApplication::QmlPreviewApplication(int &argc, char **argv) :
QCoreApplication(argc, argv),
m_verbose(false),
m_connectionAttempts(0)
{
m_connection.reset(new QQmlDebugConnection);
m_qmlPreviewClient.reset(new QQmlPreviewClient(m_connection.data()));
m_connectTimer.setInterval(1000);
m_loadTimer.setInterval(100);
m_loadTimer.setSingleShot(true);
connect(&m_loadTimer, &QTimer::timeout, this, [this]() {
m_qmlPreviewClient->triggerLoad(QUrl());
});
connect(&m_connectTimer, &QTimer::timeout, this, &QmlPreviewApplication::tryToConnect);
connect(m_connection.data(), &QQmlDebugConnection::connected, &m_connectTimer, &QTimer::stop);
connect(m_qmlPreviewClient.data(), &QQmlPreviewClient::error,
this, &QmlPreviewApplication::logError);
connect(m_qmlPreviewClient.data(), &QQmlPreviewClient::request,
this, &QmlPreviewApplication::serveRequest);
connect(&m_watcher, &QmlPreviewFileSystemWatcher::fileChanged,
this, &QmlPreviewApplication::sendFile);
connect(&m_watcher, &QmlPreviewFileSystemWatcher::directoryChanged,
this, &QmlPreviewApplication::sendDirectory);
}
QmlPreviewApplication::~QmlPreviewApplication()
{
if (m_process && m_process->state() != QProcess::NotRunning) {
logStatus("Terminating process ...");
m_process->disconnect();
m_process->terminate();
if (!m_process->waitForFinished(1000)) {
logStatus("Killing process ...");
m_process->kill();
}
}
}
void QmlPreviewApplication::parseArguments()
{
setApplicationName(QLatin1String("qmlpreview"));
setApplicationVersion(QLatin1String(qVersion()));
QCommandLineParser parser;
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
parser.setOptionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsPositionalArguments);
parser.setApplicationDescription(QChar::LineFeed + tr(
"The QML Preview tool watches QML and JavaScript files on disk and updates\n"
"the application live with any changes. The application to be previewed\n"
"has to enable QML debugging. See the Qt Creator documentation on how to do\n"
"this for different Qt versions."));
QCommandLineOption verbose(QStringList() << QLatin1String("verbose"),
tr("Print debugging output."));
parser.addOption(verbose);
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument(QLatin1String("executable"),
tr("The executable to be started and previewed."),
QLatin1String("[executable]"));
parser.addPositionalArgument(QLatin1String("parameters"),
tr("Parameters for the executable to be started."),
QLatin1String("[parameters...]"));
parser.process(*this);
QTemporaryFile file;
if (file.open())
m_socketFile = file.fileName();
if (parser.isSet(verbose))
m_verbose = true;
m_arguments = parser.positionalArguments();
if (!m_arguments.isEmpty())
m_executablePath = m_arguments.takeFirst();
if (m_executablePath.isEmpty()) {
logError(tr("You have to specify an executable to start."));
parser.showHelp(2);
}
}
int QmlPreviewApplication::exec()
{
QTimer::singleShot(0, this, &QmlPreviewApplication::run);
return QCoreApplication::exec();
}
void QmlPreviewApplication::run()
{
logStatus(QString("Listening on %1 ...").arg(m_socketFile));
m_connection->startLocalServer(m_socketFile);
m_process.reset(new QProcess(this));
QStringList arguments;
arguments << QString("-qmljsdebugger=file:%1,block,services:QmlPreview").arg(m_socketFile);
arguments << m_arguments;
m_process->setProcessChannelMode(QProcess::MergedChannels);
connect(m_process.data(), &QIODevice::readyRead,
this, &QmlPreviewApplication::processHasOutput);
connect(m_process.data(), QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, [this](int){ processFinished(); });
logStatus(QString("Starting '%1 %2' ...").arg(m_executablePath, arguments.join(QLatin1Char(' '))));
m_process->start(m_executablePath, arguments);
if (!m_process->waitForStarted()) {
logError(QString("Could not run '%1': %2").arg(m_executablePath, m_process->errorString()));
exit(1);
}
m_connectTimer.start();
}
void QmlPreviewApplication::tryToConnect()
{
Q_ASSERT(!m_connection->isConnected());
++m_connectionAttempts;
if (m_verbose && !(m_connectionAttempts % 5)) {// print every 5 seconds
logError(QString("No connection received on %1 for %2 seconds ...")
.arg(m_socketFile).arg(m_connectionAttempts));
}
}
void QmlPreviewApplication::processHasOutput()
{
Q_ASSERT(m_process);
while (m_process->bytesAvailable()) {
QTextStream out(stderr);
out << m_process->readAll();
}
}
void QmlPreviewApplication::processFinished()
{
Q_ASSERT(m_process);
int exitCode = 0;
if (m_process->exitStatus() == QProcess::NormalExit) {
logStatus(QString("Process exited (%1).").arg(m_process->exitCode()));
} else {
logError("Process crashed!");
exitCode = 3;
}
exit(exitCode);
}
void QmlPreviewApplication::logError(const QString &error)
{
QTextStream err(stderr);
err << "Error: " << error << Qt::endl;
}
void QmlPreviewApplication::logStatus(const QString &status)
{
if (!m_verbose)
return;
QTextStream err(stderr);
err << status << Qt::endl;
}
void QmlPreviewApplication::serveRequest(const QString &path)
{
QFileInfo info(path);
if (info.isDir()) {
m_qmlPreviewClient->sendDirectory(path, QDir(path).entryList());
m_watcher.addDirectory(path);
} else {
QFile file(path);
if (file.open(QIODevice::ReadOnly)) {
m_qmlPreviewClient->sendFile(path, file.readAll());
m_watcher.addFile(path);
} else {
logStatus(QString("Could not open file %1 for reading: %2").arg(path)
.arg(file.errorString()));
m_qmlPreviewClient->sendError(path);
}
}
}
bool QmlPreviewApplication::sendFile(const QString &path)
{
QFile file(path);
if (file.open(QIODevice::ReadOnly)) {
m_qmlPreviewClient->sendFile(path, file.readAll());
// Defer the Load, because files tend to change multiple times in a row.
m_loadTimer.start();
return true;
}
logStatus(QString("Could not open file %1 for reading: %2").arg(path).arg(file.errorString()));
return false;
}
void QmlPreviewApplication::sendDirectory(const QString &path)
{
m_qmlPreviewClient->sendDirectory(path, QDir(path).entryList());
m_loadTimer.start();
}