blob: cb5a062f1a8633c18991e20a064bc3bf1d044a29 [file] [log] [blame] [edit]
#!/bin/bash
# Copyright 2022 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Builds the cros-im Debian package for listed architectures and Debian
# releases. Currently supports bullseye only.
# Usage: ./build-packages or ./build-packages <arch>
set -ex
ALL_ARCHES="arm64 armhf amd64 i386"
RELEASES="bullseye"
ARTIFACTS="artifacts"
usage() {
cat<<END
Usage: $(basename "$0") [ARCH]
Builds cros_im for ARCH. ARCH should be one or more of: ${ALL_ARCHES}.
If ARCH is omitted, builds for all architectures.
END
}
create_changelog() {
# Set version number to number of commits in main.
local version
version="$(git rev-list --count HEAD)"
# Use the timestamp of the last commit so the build is reproducible.
local timestamp
timestamp="$(git show -s --format=%cD HEAD)"
cat > debian/changelog <<END
cros-im (${version}) UNRELEASED; urgency=medium
* Please view commit history at
https://chromium.googlesource.com/chromiumos/platform2/+log/main/vm_tools/cros_im
-- The ChromiumOS Authors <chromium-os-dev@chromium.org> ${timestamp}
END
}
setup_deps() {
apt-get update
apt-get install -y debian-archive-keyring pbuilder debootstrap devscripts \
qemu-user-static debhelper
cp .pbuilderrc /root/
# Copy the .xml dependencies to protocols/ for the pbuilder chroot
mkdir -p protocols
cp ../sommelier/protocol/text-input-extension-unstable-v1.xml protocols
cp ../sommelier/protocol/text-input-unstable-v1.xml protocols
cp ../sommelier/protocol/text-input-x11-unstable-v1.xml protocols
}
cleanup() {
# Remove the temporary .xml files
rm -rf protocols
}
make_chroot() {
local dist="$1"
local arch="$2"
export DIST="${dist}"
export ARCH="${arch}"
pbuilder create \
--mirror http://deb.debian.org/debian \
--distribution "${dist}" \
--architecture "${arch}" \
--debootstrapopts \
--keyring="/usr/share/keyrings/debian-archive-keyring.gpg"
}
build_package() {
local dist="$1"
local arch="$2"
local basetgz="$3"
pdebuild --buildresult "${ARTIFACTS}" \
-- \
--architecture "${arch}" \
--basetgz "${basetgz}"
}
main() {
cd "$(dirname "$0")"
local arches_to_build="${ALL_ARCHES}"
if [[ -z "$1" ]]; then
echo "No architecture specified, compiling for all architectures."
elif [[ " ${ALL_ARCHES} " == *" $1 "* ]]; then
echo "Building cros-im for $1 only"
arches_to_build="$1"
else
usage >&2
return
fi
setup_deps
create_changelog
local arch
for dist in ${RELEASES}; do
for arch in ${arches_to_build}; do
mkdir -p "/var/cache/pbuilder/aptcache/debian-${dist}-${arch}"
basetgz="/var/cache/pbuilder/base-${arch}.tgz"
if [ -f "${basetgz}" ]; then
pbuilder update --basetgz "${basetgz}"
else
make_chroot "${dist}" "${arch}"
fi
build_package "${dist}" "${arch}" "${basetgz}"
done
local deb_dir="${dist}_cros_im_debs"
mkdir -p "${deb_dir}"
mv "${ARTIFACTS}"/cros-im_*.deb "${deb_dir}"
done
cleanup
}
main "$@"