plugins/tools/plugin_woodcutting_origin.py
unimatrixgit f9484ff164
Some checks failed
DuneRealms Plugin CI / plugins (push) Has been cancelled
Stamp sawmill outputs at their WoodCutting producer
2026-12-04 20:32:18 +01:00

49 lines
1.9 KiB
Python

"""Build the scoped provenance overlay for the reviewed WoodCutting runtime."""
import argparse
import os
from pathlib import Path
import subprocess
from tempfile import TemporaryDirectory
from plugin_wild_update import digest, read_archive, write_archive
BASELINE = "de19fff89bd43c00a8dad8013dc8898ef56cf811825ba424b811cd8bffd78169"
ENTRY = "io/gitlab/jumperdenfer/features/WoodCuttingFeature.class"
def assemble(baseline, output, classpath):
baseline_bytes = baseline.read_bytes()
if digest(baseline_bytes) != BASELINE:
raise ValueError("Unreviewed WoodCutting runtime")
entries = read_archive(baseline_bytes)
root = Path(__file__).resolve().parent
java_home = os.environ.get("JAVA_HOME")
def executable(name):
name += ".exe" if os.name == "nt" else ""
return str(Path(java_home) / "bin" / name) if java_home else name
with TemporaryDirectory() as temporary:
temp = Path(temporary)
current, merged = temp / "retained.class", temp / "merged.class"
current.write_bytes(entries[ENTRY])
subprocess.run([
executable("javac"), "--release", "21", "-classpath", classpath, "-d", str(temp),
str(root.parent / "vendor/woodcutting/WoodCuttingFeature.java"),
], check=True)
subprocess.run([
executable("java"), "--class-path", classpath,
str(root / "WoodcuttingOriginMerge.java"),
str(current), str(temp / ENTRY), str(merged),
], check=True)
entries[ENTRY] = merged.read_bytes()
with output.open("xb") as candidate:
candidate.write(write_archive(entries))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("baseline", type=Path)
parser.add_argument("output", type=Path)
parser.add_argument("classpath", help="Paper API, its dependencies, and ASM core and tree JARs")
assemble(**vars(parser.parse_args()))