build/debian: Several improvements to build scripts
- Consistently `exit 1` in place of `exit` at errors
- Default to host machine arch, instead of aarch64
- Identical Kokoro build scripts for aarch64 and x86_64 due to the above
- Better error message¹ for ANDROID_BUILD_TOP in containerized build
- `-s` flag for build_in_container.sh to unconditionally leave a shell open for further testing
¹ ANDROID_BUILD_TOP is not set by only running `source build/envsetup.sh`. Additionally, a target must be `lunch`ed to set this variable.
Bug: None
Test: ./build_in_container.sh -s -w
Change-Id: Iec28c7f0d582fc5fdbbe9700cb759b1f3278a514
diff --git a/build/debian/build_in_container.sh b/build/debian/build_in_container.sh
index 7fd4c00..5028b74 100755
--- a/build/debian/build_in_container.sh
+++ b/build/debian/build_in_container.sh
@@ -1,35 +1,56 @@
#!/bin/bash
-if [ -z "$ANDROID_BUILD_TOP" ]; then echo "forgot to source build/envsetup.sh?" && exit 1; fi
+show_help() {
+ echo "Usage: sudo $0 [OPTION]..."
+ echo "Builds a debian image and save it to image.raw."
+ echo "Options:"
+ echo "-h Print usage and this help message and exit."
+ echo "-a ARCH Architecture of the image [default is host arch: $(uname -m)]"
+ echo "-r Release mode build"
+ echo "-s Leave a shell open [default: only if the build fails]"
+ echo "-w Save temp work directory in the container [for debugging]"
+}
-arch=aarch64
+arch="$(uname -m)"
release_flag=
save_workdir_flag=
+shell_condition="||"
-while getopts "a:rw" option; do
+while getopts "a:rsw" option; do
case ${option} in
a)
- if [[ "$OPTARG" != "aarch64" && "$OPTARG" != "x86_64" ]]; then
- echo "Invalid architecture: $OPTARG"
- exit
- fi
arch="$OPTARG"
;;
+ h)
+ show_help ; exit
+ ;;
r)
release_flag="-r"
;;
+ s)
+ shell_condition=";"
+ ;;
w)
save_workdir_flag="-w"
;;
*)
- echo "Invalid option: $OPTARG"
- exit
+ echo "Invalid option: $OPTARG" ; exit 1
;;
esac
done
+if [[ "$arch" != "aarch64" && "$arch" != "x86_64" ]]; then
+ echo "Invalid architecture: $arch" ; exit 1
+fi
+
+if [ -z "$ANDROID_BUILD_TOP" ] ; then
+ echo '`ANDROID_BUILD_TOP` is undefined.'
+ echo 'Please `lunch` an Android target, or manually set the variable.'
+ exit 1
+fi
+
docker run --privileged -it -v /dev:/dev \
-v "$ANDROID_BUILD_TOP/packages/modules/Virtualization:/root/Virtualization" \
--workdir /root/Virtualization/build/debian \
ubuntu:22.04 \
- bash -c "/root/Virtualization/build/debian/build.sh -a $arch $release_flag $save_workdir_flag || bash"
+ bash -c "/root/Virtualization/build/debian/build.sh -a $arch $release_flag $save_workdir_flag $shell_condition bash"