53 lines
2.3 KiB
Python
53 lines
2.3 KiB
Python
"""Build scoped native workstation overlays on the three reviewed live JARVIS 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
|
|
|
|
PKG = "com/dunerealms/jarvis/"
|
|
ENTRY = PKG + "ItemMetadataOverlay.class"
|
|
NEW = [PKG + "WorkstationOrigins.class", PKG + "WorkstationOrigins$NativeBatch.class"]
|
|
BASELINES = {
|
|
"5edc2595210d7b683e185a3442b0c762a6f62af645ad9702c28bf363ba3c2427",
|
|
"d914bf7ab726a596471154fb69f5d8e64998f3a7342b9580450e85dfc66709ac",
|
|
"33c95e514d3b42185d70511156c58bada28a05ff9ccc151f33ddc50bf6a60d76",
|
|
}
|
|
|
|
|
|
def assemble(baseline, donor, donor_sha, output, classpath):
|
|
existing = baseline.read_bytes()
|
|
compiled = donor.read_bytes()
|
|
if digest(existing) not in BASELINES or digest(compiled) != donor_sha:
|
|
raise ValueError("Unexpected baseline or donor checksum")
|
|
retained = read_archive(existing)
|
|
source = read_archive(compiled)
|
|
if any(entry in retained for entry in NEW):
|
|
raise ValueError("The reviewed baseline already contains native workstation output hooks")
|
|
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("NativeWorkstationMerge.java")
|
|
with TemporaryDirectory() as temporary:
|
|
temp = Path(temporary)
|
|
old, new, merged = (temp / f"{name}.class" for name in ("retained", "donor", "merged"))
|
|
old.write_bytes(retained[ENTRY])
|
|
new.write_bytes(source[ENTRY])
|
|
subprocess.run([java, "--class-path", classpath, str(helper), str(old), str(new), str(merged)], check=True)
|
|
retained[ENTRY] = merged.read_bytes()
|
|
for entry in NEW:
|
|
retained[entry] = source[entry]
|
|
with output.open("xb") as candidate:
|
|
candidate.write(write_archive(retained))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("baseline", type=Path)
|
|
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()))
|

Staff