diff options
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 |