#!/usr/bin/env python3 """Generate a third-party notices file from the Flatpak manifest. A .deb lists only what it actually ships, because its dependencies are separate packages carrying their own copyright files. A Flatpak or AppImage distributes those libraries itself, so the notices have to travel with the artifact -- and for the LGPL ones (libconfig, argtable2, libserialport, orcania, yder) that includes saying where the corresponding source can be obtained. The manifest already pins every dependency by URL and sha256, which is exactly that information, so this is generated from it rather than maintained by hand where it would drift. """ import re import sys from pathlib import Path manifest = Path(sys.argv[1] if len(sys.argv) > 1 else "flatpak/io.github.spacefreak18.monocoque.yml") text = manifest.read_text() entries, name = [], None for line in text.splitlines(): m = re.match(r"^ - name: (\S+)", line) if m: name = m.group(1) entries.append({"name": name, "url": None, "sha256": None, "commit": None, "tag": None}) elif entries: for key in ("url", "sha256", "commit", "tag"): k = re.match(rf"^\s+{key}: (\S+)", line) if k and entries[-1][key] is None: entries[-1][key] = k.group(1) out = [ "# Third-party notices", "", "This package bundles the libraries below. Each one's own licence text is", "installed alongside it under `/app/share/licenses//`.", "", "Where a bundled library is under the LGPL, the corresponding source is the", "exact archive listed here, identified by URL and SHA-256; the same version", "can be rebuilt from it, and the Flatpak links these libraries dynamically.", "", "| Component | Source | Checksum / revision |", "|---|---|---|", ] for e in entries: if not e["url"]: continue rev = e["sha256"] or e["commit"] or e["tag"] or "" out.append(f"| {e['name']} | {e['url']} | `{rev[:16]}{'…' if len(rev) > 16 else ''}` |") out += [ "", "Generated by tools/generate-third-party-notices.py from the Flatpak", "manifest -- do not edit by hand.", "", ] print("\n".join(out))