36 lines
No EOL
1.5 KiB
Python
36 lines
No EOL
1.5 KiB
Python
"""Change only generated temperate leaf persistence in a pinned retained Terrain JAR."""
|
|
import argparse
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
from tempfile import TemporaryDirectory
|
|
from plugin_wild_update import digest, read_archive, write_archive
|
|
|
|
ENTRY = "com/example/duneterrain/TemperateLandscape.class"
|
|
|
|
def assemble(baseline, baseline_sha, output, classpath):
|
|
original = baseline.read_bytes()
|
|
if digest(original) != baseline_sha:
|
|
raise ValueError("Unexpected retained Terrain archive")
|
|
entries = read_archive(original)
|
|
helper = Path(__file__).with_name("GeneratedLeavesMerge.java")
|
|
with TemporaryDirectory() as work:
|
|
root = Path(work)
|
|
source = root / "temperate.class"
|
|
changed = root / "generated-leaves.class"
|
|
source.write_bytes(entries[ENTRY])
|
|
subprocess.run(["javac", "-cp", classpath, "-d", work, str(helper)], check=True)
|
|
subprocess.run(["java", "-cp", f"{work}{os.pathsep}{classpath}", "GeneratedLeavesMerge",
|
|
str(source), str(changed)], check=True)
|
|
entries[ENTRY] = changed.read_bytes()
|
|
with output.open("xb") as stream:
|
|
stream.write(write_archive(entries))
|
|
print(digest(output.read_bytes()))
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("baseline", type=Path)
|
|
parser.add_argument("baseline_sha")
|
|
parser.add_argument("output", type=Path)
|
|
parser.add_argument("classpath")
|
|
assemble(**vars(parser.parse_args())) |

Staff