plugins/tools/plugin_guild_cookbook.py
unimatrixgit 5bb36a4eb2
Some checks failed
Guild and Cookbook Overlay / guild-cookbook (push) Successful in 2m27s
DuneRealms Resourcepack CI / resourcepack (push) Has been cancelled
DuneRealms Plugin CI / plugins (push) Has been cancelled
Package a scoped Guild and Cookbook overlay for each retained variant
2026-12-04 20:35:31 +01:00

53 lines
2.2 KiB
Python

"""Assemble reviewed Guild and Cookbook methods onto the installed plugin variants."""
import argparse
import os
from pathlib import Path
import subprocess
from tempfile import TemporaryDirectory
from plugin_wild_update import digest, read_archive, write_archive
CLASSES = {
"gui": (
"com/dunerealms/gui/DuneGUI.class",
"com/dunerealms/gui/OrganisationMenus.class",
"com/dunerealms/gui/CookbookCatalog$Recipe.class",
),
"npc": ("com/example/dunenpc/DuneNPC.class",),
"lobby": ("com/example/dunelobby/DuneLobby.class",),
}
def assemble(module, baseline, baseline_sha, donor, donor_sha, output, classpath):
baseline_bytes = baseline.read_bytes()
donor_bytes = donor.read_bytes()
if digest(baseline_bytes) != baseline_sha or digest(donor_bytes) != donor_sha:
raise ValueError("Unexpected baseline or donor checksum")
retained = read_archive(baseline_bytes)
compiled = read_archive(donor_bytes)
java_home = os.environ.get("JAVA_HOME")
executable = "java.exe" if os.name == "nt" else "java"
java = str(Path(java_home) / "bin" / executable) if java_home else executable
helper = Path(__file__).with_name("GuildCookbookMerge.java")
with TemporaryDirectory() as temporary:
temp = Path(temporary)
for index, entry in enumerate(CLASSES[module]):
old, new, merged = (temp / f"{index}-{name}.class" for name in ("retained", "donor", "merged"))
old.write_bytes(retained[entry])
new.write_bytes(compiled[entry])
subprocess.run([java, "--class-path", classpath, str(helper), str(old), str(new), str(merged)], check=True)
retained[entry] = merged.read_bytes()
with output.open("xb") as candidate:
candidate.write(write_archive(retained))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("module", choices=CLASSES)
parser.add_argument("baseline", type=Path)
parser.add_argument("baseline_sha")
parser.add_argument("donor", type=Path)
parser.add_argument("donor_sha")
parser.add_argument("output", type=Path)
parser.add_argument("classpath", help="ASM core and tree JARs")
assemble(**vars(parser.parse_args()))