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 /pkg/default.java.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 'pkg/default.java.do')
-rwxr-xr-x | pkg/default.java.do | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/pkg/default.java.do b/pkg/default.java.do new file mode 100755 index 0000000..16bf440 --- /dev/null +++ b/pkg/default.java.do @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -e +src=${1%.java}.aar +redo-ifchange "$src" "../ids.rc" +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT +7z e -tzip -o"$tmp" "$src" AndroidManifest.xml R.txt >/dev/null +if [[ -r "$tmp/AndroidManifest.xml" ]]; then + package=$(xmllint --xpath 'string(/manifest/@package)' "$tmp/AndroidManifest.xml") +fi +if [[ ! $package ]] || [[ ! -r $tmp/R.txt ]]; then + printf '//\n' >"$3" + exit 0 +fi +. ../ids.rc +. <(sed -n 's/^int[^ ]* \([a-z]*\) \([A-Za-z0-9_]*\) .*$/names_\1+=(\2)/p' "$tmp/R.txt") +mapfile -t types < <(sed -n 's/^int[^ ]* \([a-z]*\) .*/\1/p' "$tmp/R.txt" | sort -u) +exec >"$3" +printf '// generated by %s\n' "$0" +printf 'package %s;\npublic final class R {\n' "$package" +for typ in "${types[@]}"; do + declare -n names="names_$typ" + printf 'public static final class %s {\n' "$typ" + for name in "${names[@]}"; do + if [[ ${ids[$typ:$name]} ]]; then + printf 'public static final %s;\n' "${ids[$typ:$name]}" + fi + done + printf '}\n' +done +printf '}\n' +# vim:ft=bash |