summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/.gitignore1
-rwxr-xr-xpkg/default.aar.do6
-rwxr-xr-xpkg/default.flat.zip.do12
-rwxr-xr-xpkg/default.jar.do13
-rwxr-xr-xpkg/default.java.do32
-rw-r--r--pkg/get35
6 files changed, 99 insertions, 0 deletions
diff --git a/pkg/.gitignore b/pkg/.gitignore
new file mode 100644
index 0000000..27d1535
--- /dev/null
+++ b/pkg/.gitignore
@@ -0,0 +1 @@
+*.java
diff --git a/pkg/default.aar.do b/pkg/default.aar.do
new file mode 100755
index 0000000..034d507
--- /dev/null
+++ b/pkg/default.aar.do
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+set -e
+pkg=${1%.aar}
+redo-ifchange get
+. ./get "$pkg" "$3"
+# vim:ft=bash
diff --git a/pkg/default.flat.zip.do b/pkg/default.flat.zip.do
new file mode 100755
index 0000000..8373faf
--- /dev/null
+++ b/pkg/default.flat.zip.do
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+set -e
+src=${1%.flat.zip}.aar
+redo-ifchange ../.vars.rc "$src"
+. ../.vars.rc
+redo-ifchange "$BUILD_TOOLS/aapt2"
+tmp=$(mktemp -d)
+trap 'rm -rf "$tmp"' EXIT
+mkdir -p "$tmp/res"
+7z x -tzip -o"$tmp" "$src" res >/dev/null
+"$BUILD_TOOLS/aapt2" compile --dir "$tmp/res" -o "$3"
+# vim:ft=bash
diff --git a/pkg/default.jar.do b/pkg/default.jar.do
new file mode 100755
index 0000000..6fa7d4e
--- /dev/null
+++ b/pkg/default.jar.do
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+set -e
+redo-ifchange ../packages.rc
+. ../packages.rc
+pkg=${1%.jar}
+if [[ $(package_ext "$pkg") == "aar" ]]; then
+ redo-ifchange "$pkg.aar"
+ 7z e -tzip -so "$pkg.aar" classes.jar >"$3"
+else
+ redo-ifchange get
+ . ./get "$pkg" "$3"
+fi
+# vim:ft=bash
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
diff --git a/pkg/get b/pkg/get
new file mode 100644
index 0000000..a26bec6
--- /dev/null
+++ b/pkg/get
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+set -e
+redo-ifchange ../packages.rc ../.vars.rc
+. ../.vars.rc
+. ../packages.rc
+
+set -f
+IFS=:; p=($1); d=(${packages[$1]})
+set +f
+group=${p[0]}
+artifact=${p[1]}
+version=${p[2]}
+packaging=${d[0]}
+repo=${d[1]}
+valid_sum=${d[2]}
+
+hash_file() { sha256sum "$1" 2>/dev/null | cut -d ' ' -f 1; }
+
+if [[ $valid_sum ]] && [[ $(hash_file "$1.$packaging") == "$valid_sum" ]]; then
+ cp "$1.$packaging" "$2"
+ exit
+fi
+
+url=${MAVEN_REPO[$repo]}/${group//.//}/$artifact/$version/$artifact-$version.$packaging
+curl --silent --show-error --fail --output "$2" "$url"
+sum=$(hash_file "$2")
+if [[ $valid_sum ]] && [[ $sum != "$valid_sum" ]]; then
+ printf '%s: checksum mismatch (got: %s)\n' "$pkg" "$sum" >&2
+ rm "$2"
+ exit 1
+fi
+if [[ ! $valid_sum ]]; then
+ printf "sed -i 's/^packages(_[a-z]*){0,1}\\[%s:%s:%s\\]=%s:%s:$/&%s/' packages.rc\n" "$group" "$artifact" "$version" "$packaging" "$repo" "$sum" >&2
+fi
+# vim:ft=bash