Add firmware and extension catalogues, configuration transactions, sample review and QML diagnostics. Preserve explicit authority, bounded retries and stop recovery in motor transport.
168 lines
6.2 KiB
Python
168 lines
6.2 KiB
Python
"""Private signed Ubuntu QML dependencies and offline renderer qualification."""
|
|
|
|
import hashlib
|
|
import json
|
|
import shutil
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
PACKAGES = (
|
|
"qml-module-qtquick2",
|
|
"qml-module-qtquick-controls2",
|
|
"qml-module-qtquick-templates2",
|
|
"qml-module-qtquick-controls",
|
|
"qml-module-qtquick-layouts",
|
|
"qml-module-qtquick-window2",
|
|
"qml-module-qtgraphicaleffects",
|
|
"qml-module-qtqml",
|
|
"qml-module-qtqml-models2",
|
|
"fonts-dejavu-core",
|
|
)
|
|
|
|
|
|
def dependencies(root, execute, cache=None):
|
|
target = root / "qml-deps"
|
|
target.mkdir()
|
|
downloads = target / "packages"
|
|
downloads.mkdir()
|
|
if cache is not None:
|
|
records = json.loads((cache / "packages.json").read_text())
|
|
if len(records) != len(PACKAGES) or {p["file"].split("_")[0] for p in records} != set(
|
|
PACKAGES
|
|
):
|
|
raise RuntimeError("Invalid QML dependency cache")
|
|
sysroot = target / "sysroot"
|
|
sysroot.mkdir()
|
|
for record in records:
|
|
name = record["file"]
|
|
if Path(name).name != name or not name.endswith(".deb"):
|
|
raise RuntimeError("Invalid cached package path")
|
|
path = cache / "packages" / name
|
|
if hashlib.sha256(path.read_bytes()).hexdigest() != record["sha256"]:
|
|
raise RuntimeError("Changed QML cache archive")
|
|
shutil.copyfile(path, downloads / name)
|
|
subprocess.run(
|
|
["/usr/bin/dpkg-deb", "--extract", str(downloads / name), str(sysroot)],
|
|
check=True,
|
|
timeout=30,
|
|
)
|
|
(target / "packages.json").write_text(json.dumps(records, indent=2) + "\n")
|
|
return sysroot
|
|
apt = target / "apt"
|
|
apt.mkdir()
|
|
for name in ("lists", "lists/partial", "archives", "archives/partial"):
|
|
(apt / name).mkdir()
|
|
sources = apt / "sources.list"
|
|
sources.write_text(
|
|
"".join(
|
|
"deb [signed-by=/usr/share/keyrings/ubuntu-archive-keyring.gpg] "
|
|
+ url
|
|
+ " "
|
|
+ suite
|
|
+ " main universe\n"
|
|
for url, suite in (
|
|
("https://archive.ubuntu.com/ubuntu", "noble"),
|
|
("https://archive.ubuntu.com/ubuntu", "noble-updates"),
|
|
("https://security.ubuntu.com/ubuntu", "noble-security"),
|
|
)
|
|
)
|
|
)
|
|
config = apt / "apt.conf"
|
|
config.write_text(
|
|
'Dir::Etc::Parts "-";\nDir::Etc::main "-";\nDir::Etc::sourceparts "-";\n'
|
|
f'Dir::Etc::sourcelist "{sources}";\n'
|
|
f'Dir::State::lists "{apt / "lists"}";\n'
|
|
f'Dir::Cache::archives "{apt / "archives"}";\n'
|
|
'Dir::Cache::pkgcache "";\nDir::Cache::srcpkgcache "";\n'
|
|
'Acquire::Languages "none";\nDebug::NoLocking "true";\n'
|
|
"#clear APT::Update::Post-Invoke;\n#clear APT::Update::Post-Invoke-Success;\n"
|
|
)
|
|
# Execute accepts an argv, never a shell. Only the task's private APT paths change.
|
|
execute(
|
|
"qml-private-indexes",
|
|
["/usr/bin/env", "APT_CONFIG=" + str(config), "/usr/bin/apt-get", "update"],
|
|
timeout=180,
|
|
)
|
|
for name in PACKAGES:
|
|
execute(
|
|
"qml-download-" + name,
|
|
[
|
|
"/usr/bin/env",
|
|
"-C",
|
|
str(downloads),
|
|
"APT_CONFIG=" + str(config),
|
|
"/usr/bin/apt-get",
|
|
"download",
|
|
name,
|
|
],
|
|
timeout=90,
|
|
)
|
|
sysroot = target / "sysroot"
|
|
sysroot.mkdir()
|
|
packages = []
|
|
for p in sorted(downloads.glob("*.deb")):
|
|
packages.append({"file": p.name, "sha256": hashlib.sha256(p.read_bytes()).hexdigest()})
|
|
subprocess.run(
|
|
["/usr/bin/dpkg-deb", "--extract", str(p), str(sysroot)], check=True, timeout=30
|
|
)
|
|
if len(packages) != len(PACKAGES):
|
|
raise RuntimeError("QML package inventory incomplete")
|
|
(target / "packages.json").write_text(json.dumps(packages, indent=2) + "\n")
|
|
return sysroot
|
|
|
|
|
|
def bright_pixels(png, rectangle):
|
|
"""Count visible light glyph pixels in a fixed native-render regression region."""
|
|
import struct
|
|
import zlib
|
|
|
|
if png[:8] != b"\x89PNG\r\n\x1a\n":
|
|
raise ValueError("Invalid QML test image")
|
|
cursor, data, shape = 8, bytearray(), None
|
|
while cursor < len(png):
|
|
length = struct.unpack_from(">I", png, cursor)[0]
|
|
tag, value = png[cursor + 4 : cursor + 8], png[cursor + 8 : cursor + 8 + length]
|
|
if tag == b"IHDR":
|
|
shape = struct.unpack(">IIBBBBB", value)
|
|
if tag == b"IDAT":
|
|
data.extend(value)
|
|
cursor += length + 12
|
|
width, height, depth, colour, compression, filtering, interlace = shape
|
|
if depth != 8 or colour not in (2, 6) or compression or filtering or interlace:
|
|
raise ValueError("Unsupported native QML test image encoding")
|
|
channels = 4 if colour == 6 else 3
|
|
stride = width * channels
|
|
raw = zlib.decompress(data)
|
|
if len(raw) != height * (stride + 1):
|
|
raise ValueError("Invalid native QML image size")
|
|
prior, count = bytearray(stride), 0
|
|
x0, y0, x1, y1 = rectangle
|
|
for y in range(height):
|
|
at = y * (stride + 1)
|
|
mode, row = raw[at], bytearray(raw[at + 1 : at + 1 + stride])
|
|
for i in range(stride):
|
|
left = row[i - channels] if i >= channels else 0
|
|
up = prior[i]
|
|
corner = prior[i - channels] if i >= channels else 0
|
|
if mode == 0:
|
|
prediction = 0
|
|
elif mode == 1:
|
|
prediction = left
|
|
elif mode == 2:
|
|
prediction = up
|
|
elif mode == 3:
|
|
prediction = (left + up) // 2
|
|
elif mode == 4:
|
|
p = left + up - corner
|
|
prediction = min((left, up, corner), key=lambda value: abs(p - value))
|
|
else:
|
|
raise ValueError("Invalid PNG filter")
|
|
row[i] = (row[i] + prediction) & 255
|
|
if y0 <= y < y1:
|
|
for x in range(x0, min(x1, width)):
|
|
pixel = row[x * channels : (x + 1) * channels]
|
|
if min(pixel[:3]) > 180 and (channels == 3 or pixel[3] > 200):
|
|
count += 1
|
|
prior = row
|
|
return count
|