aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Labatut <plabatut@google.com>2023-11-20 15:24:09 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-11-20 15:24:09 +0000
commit7f200de810734256065d02da1d66c43f613615bf (patch)
tree4938275507c8385f53db76bf3c3bbaf8e27ff0cb
parent150d6788321b4ca13168757e29ce141288e716f7 (diff)
parentce74166af0ecc0d01318473d6f4f5f34f0890af0 (diff)
downloadcuttlefish_vmm-7f200de810734256065d02da1d66c43f613615bf.tar.gz
Automate build in a container. am: 406cc9401c am: a9fb76666e am: ce74166af0
Original change: https://android-review.googlesource.com/c/device/google/cuttlefish_vmm/+/2836856 Change-Id: I55531a9f99a8f71c2c1de0d065e8cc7b0823a9b6 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rwxr-xr-xqemu/scripts/rebuild_in_container.sh70
1 files changed, 70 insertions, 0 deletions
diff --git a/qemu/scripts/rebuild_in_container.sh b/qemu/scripts/rebuild_in_container.sh
new file mode 100755
index 0000000..0643a11
--- /dev/null
+++ b/qemu/scripts/rebuild_in_container.sh
@@ -0,0 +1,70 @@
+#!/bin/sh
+# Starts an isolated build in a container
+set -e
+
+FROM_EXISTING_SOURCES=0
+
+while [[ $# -gt 0 ]]; do
+ case $1 in
+ --from_existing_sources)
+ FROM_EXISTING_SOURCES=1
+ shift
+ ;;
+ *)
+ echo "Build QEMU from sources in a container."
+ echo
+ echo "usage: $0 [--from_existing_sources]"
+ echo
+ echo "Options:"
+ echo " --from_existing_sources: Do not checkout sources with repo,"
+ echo " and do not copy the prebuild back to the source directory."
+ shift
+ exit 1
+ ;;
+ esac
+done
+
+readonly SCRIPT_DIR="$(realpath "$(dirname "$0")")"
+readonly GIT_ROOT="$(realpath "${SCRIPT_DIR}/../..")"
+readonly WORK_DIR="/tmp/qemu-build-output"
+
+echo "Clear the working directory: ${WORK_DIR}"
+rm -rf "${WORK_DIR}"
+mkdir -p "${WORK_DIR}"
+
+if [ "$FROM_EXISTING_SOURCES" -eq 0 ]; then
+ readonly SRC_DIR="${HOME}/qemu-build-checkout"
+ echo "Check out sources with repo at: ${SRC_DIR}"
+ rm -rf "${SRC_DIR}"
+ mkdir -p "${SRC_DIR}"
+ repo init --manifest-url "${GIT_ROOT}" \
+ --manifest-name=qemu/manifest.xml
+
+ repo sync
+else
+ echo "Reuse existing source checkout at: ${SRC_DIR}"
+ readonly SRC_DIR="$GIT_ROOT"
+fi
+
+readonly COMMAND="apt-get update && \
+apt-get -qy install autoconf libtool texinfo libgbm-dev && \
+/src/qemu/third_party/python/bin/python3 /src/qemu/scripts/rebuild.py --build-dir /out"
+
+podman run --name qemu-build \
+ --replace \
+ --pids-limit=-1 \
+ --volume "${SRC_DIR}:/src:O" \
+ --volume "${WORK_DIR}:/out" \
+ docker.io/debian:10-slim \
+ bash -c "${COMMAND}"
+
+if [ "$FROM_EXISTING_SOURCES" -eq 0 ]; then
+ readonly DEST="${GIT_ROOT}/qemu/x86_64-linux-gnu"
+ echo "Overwrite prebuild at: ${DEST}"
+ rm -rf "${DEST}/*"
+ tar -xvf "${WORK_DIR}/qemu-portable.tar.gz" -C "${DEST}"
+
+fi
+
+echo "Binary available at: ${WORK_DIR}/qemu-portable/bin"
+echo "Done." \ No newline at end of file