diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-04-21 23:50:38 +0100 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-04-21 23:50:38 +0100 |
commit | 16a36c812fabda812ecf3aaa7f12fa6f44c66b2e (patch) | |
tree | ccae60abf8301ae451cfa1f21c33b8a62d5306cf /default.packages.jar.do | |
parent | db091bfd1db36ab66340ccad2eb7b6393a0aa3da (diff) | |
download | android-jetpack-compose-redo-master.tar.gz android-jetpack-compose-redo-master.tar.xz android-jetpack-compose-redo-master.zip |
Diffstat (limited to 'default.packages.jar.do')
-rwxr-xr-x | default.packages.jar.do | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/default.packages.jar.do b/default.packages.jar.do new file mode 100755 index 0000000..27dedf9 --- /dev/null +++ b/default.packages.jar.do @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import re +from subprocess import run +from sys import argv +from tempfile import TemporaryDirectory +from zipfile import ZipFile, ZipInfo + +variant = argv[1].removesuffix(".packages.jar") +run(["redo-ifchange", "packages.rc"], close_fds=False).check_returncode() +jars = [] +expr = re.compile(r"^packages_" + variant + r"\[([^]]*)\]=") +with open("packages.rc") as f: + for line in f: + if match := expr.match(line): + jars.append(f"pkg/{match.group(1)}.jar") +run(["redo-ifchange", *jars], close_fds=False).check_returncode() +already_written = set() +with TemporaryDirectory() as d, ZipFile(argv[3], "w") as out: + for jar in reversed(jars): + with ZipFile(jar) as z: + for inf in z.infolist(): + if inf.is_dir(): + continue + path = inf.filename.split("/") + if ( + not path + or path[0] == "" + or ".." in path + or path == ["META-INF", "MANIFEST.MF"] + or inf.filename in already_written + ): + continue + already_written.add(inf.filename) + with z.open(inf.filename) as src: + out.writestr(inf, src.read()) + out.writestr( + ZipInfo("META-INF/MANIFEST.MF"), + b"Manifest-Version: 1.0\nCreated-By: python-program\n", + ) +# vim:ft=python |