Files
logos-basecamp/app/utils/BuildInfo.h
T
Dario Gabriel Lipicar 9b8cf6e47e feat(shell): ship main_ui as a plugin that links no logos runtime
Measured on the built artefact: main_ui.dylib DEFINES zero and IMPORTS zero of
TokenManager, StoreRegistry, LogosAPI, LogosAPIClient and logos_core_*, out of
3410 symbols read. It links Qt and nothing else from this workspace, which
nix/symbol-gate.nix enforces across the in-process image set.

Getting there needed the last non-Qt types off the boundary: the model
properties cross as QAbstractItemModel*, catalogInstallStageChanged carries an
int rather than InstallStage::Value, and the two prebuilt AppsFilterProxy
instances are declared in QML instead of owned by MainUIBackend. That last one
removes a real inversion -- PackageCoordinator called setRequiredPackages() on
a proxy the host held a pointer to; it now emits requiredPackagesResolved() and
QML binds to the republished property.

Window resolves the plugin, qobject_casts it to IShellView, checks
hostAbiVersion() against IShellHost_abi, and calls createShell(IShellHost*).
No error-label fallback widget: that degraded to something that looked like a
working app with an empty window.

Filter proxies read role constants off host-side models and InstallEnums is
used by nine host files, so app/interfaces/ gains the contract headers both
sides compile against -- the models inherit the role structs, leaving every
AppsModel::NameRole call site unchanged. The plugin's include path is
app/interfaces only, so including a host header does not compile.

Four things only running it finds:
  * Logos::DesignSystem may be linked by exactly ONE image -- both linked it
    and the app aborted with "Cannot add multiple registrations for
    Logos.Icons"; QML module registration is process-global
  * qmltyperegistrar emits no #include for a SOURCES header given as an
    absolute path outside the project
  * each qt_add_qml_module is its own target and inherits no include dirs
  * AUTOMOC pairs header<->cpp by same-basename-same-DIRECTORY, which the
    split breaks

tst_AppManagerView.qml grows five tests for the QML binding, checked with a
negative control: breaking one assertion fails qml-tests, so they run.
2026-08-22 16:42:13 -03:00

101 lines
3.3 KiB
C++

#pragma once
// Pulls the nix-generated logos_build_info.h for its two consumers:
// * app/main.cpp — startup banner in the per-session log.
// * app/MainUIBackend — Q_PROPERTYs for the Dashboard view.
//
// Non-nix builds see no logos_build_info.h; accessors return empty values
// so callers can still render / log something sane.
#include <QByteArray>
#include <QDebug>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QString>
#include <QVariant>
#include <QVariantList>
#include <QVariantMap>
#if __has_include("logos_build_info.h")
# include "logos_build_info.h"
# define LOGOS_BASECAMP_HAS_BUILD_INFO 1
#else
# define LOGOS_BASECAMP_HAS_BUILD_INFO 0
#endif
namespace LogosBasecampBuildInfo {
// VERSION file contents, baked in at build time. Empty on dev branches
// (VERSION is only checked in on release branches) and in non-nix builds.
inline QString version() {
#if LOGOS_BASECAMP_HAS_BUILD_INFO
return QStringLiteral(LOGOS_BASECAMP_VERSION);
#else
return {};
#endif
}
// True for distributed / portable builds (AppImage, DMG) — driven by the
// LOGOS_PORTABLE_BUILD compile define set by nix/app.nix.
inline bool isPortableBuild() {
#ifdef LOGOS_PORTABLE_BUILD
return true;
#else
return false;
#endif
}
// List of {name, commit} entries for logos-basecamp + each flake input,
// populated from the nix-generated JSON blob. Empty in non-nix builds.
inline QVariantList commits() {
QVariantList out;
#if LOGOS_BASECAMP_HAS_BUILD_INFO
const auto doc = QJsonDocument::fromJson(
QByteArray::fromRawData(logos_basecamp_build_info::kCommitsJson,
qstrlen(logos_basecamp_build_info::kCommitsJson)));
if (doc.isArray()) {
for (const QJsonValue& v : doc.array()) {
const QJsonObject obj = v.toObject();
QVariantMap entry;
entry["name"] = obj.value("name").toString();
entry["commit"] = obj.value("commit").toString();
out.append(entry);
}
}
#endif
return out;
}
// Prints version + dev/portable marker + commit hashes at startup so the
// per-session log captures exactly which sources produced this binary.
inline void logStartupBanner() {
const char* buildType = isPortableBuild() ? "portable" : "dev";
#if LOGOS_BASECAMP_HAS_BUILD_INFO
const QString v = version();
if (!v.isEmpty()) {
qInfo().noquote() << QString("LogosBasecamp version %1 (%2 build)")
.arg(v, QString::fromUtf8(buildType));
} else {
qInfo().noquote() << QString("LogosBasecamp (%1 build, unreleased)")
.arg(QString::fromUtf8(buildType));
}
const QVariantList cs = commits();
if (!cs.isEmpty()) {
qInfo().noquote() << "Build commits:";
for (const QVariant& c : cs) {
const QVariantMap m = c.toMap();
qInfo().noquote() << QString(" - %1 %2")
.arg(m.value("name").toString(),
m.value("commit").toString());
}
}
#else
qInfo().noquote() << QString("LogosBasecamp (%1 build, no build info)")
.arg(QString::fromUtf8(buildType));
#endif
}
} // namespace LogosBasecampBuildInfo