🔒 Repository is read-only – file editing is disabled.

PaganLinux/tmp-fix-meson-install.py main

62 linii Raw ← Powrót
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
#!/usr/bin/env python3
"""Bulk fix: add missing `DESTDIR=${PKGDIR} meson install -C <dir>` to recipes
that run `meson compile -C <dir>` but never install the build output."""
import os, re, sys, yaml

R = "/var/lib/pagan-sync/recipes"
fixed, skipped, errors = [], [], []

for root, dirs, files in os.walk(R):
    if "PAGBUILD.yaml" not in files:
        continue
    fp = os.path.join(root, "PAGBUILD.yaml")
    try:
        s = open(fp, encoding="utf-8").read()
        d = yaml.safe_load(s) or {}
    except Exception as e:
        errors.append((fp, f"yaml: {e}"))
        continue
    build = d.get("build") or ""
    package = d.get("package") or ""
    if isinstance(build, list):
        build = "\n".join(str(x) for x in build)
    if isinstance(package, list):
        package = "\n".join(str(x) for x in package)
    whole = build + "\n" + package
    # only meson-compile recipes lacking any meson install
    if "meson install" in whole:
        continue
    m = re.search(r"(?m)^\s*meson compile -C (\S+)", build)
    if not m:
        continue
    bdir = m.group(1)
    install_line = f"DESTDIR=${{PKGDIR}} meson install -C {bdir}"
    if install_line in build:
        continue
    # insert right after the LAST meson compile line
    lines = s.split("\n")
    last = -1
    for i, ln in enumerate(lines):
        if re.match(r"^\s*meson compile -C ", ln):
            last = i
    if last < 0:
        skipped.append(fp)
        continue
    indent = re.match(r"^(\s*)", lines[last]).group(1)
    lines.insert(last + 1, indent + install_line)
    ns = "\n".join(lines)
    try:
        yaml.safe_load(ns)
    except Exception as e:
        errors.append((fp, f"yaml-after: {e}"))
        continue
    open(fp, "w", encoding="utf-8").write(ns)
    fixed.append(fp)

print(f"FIXED: {len(fixed)}")
print(f"SKIPPED: {len(skipped)}")
print(f"ERRORS: {len(errors)}")
for e in errors[:8]:
    print("  ERR:", e)
for f in fixed[:10]:
    print("  +", f.replace(R + "/", ""))