1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
qTox/appimage/build.sh
Mick Sayson 8abe8320d2 chore(CI): Use docker for CI scripts
Motiviation:
* Reproducing issues in CI is currently difficult
* Predicting issues in CI is currently difficult if you are not on
  ubuntu 18.04
* Reproducing issues submitted from other distros is currently done by
  creating a VM of that distro and building qtox for it locally
* Documentation for how to build on different distros is out of date
* Issues on non-ubuntu distributions are not caught by CI
* Cross compiling for windows locally is not trivial
* Iterating when working with custom build scripts is slow, scripts
  don't necessarily support re-running without re-starting the docker
  container and re-building qtox again
* Updating dependencies is a pain

Changes:
* docker-compose file has been added to the root of our repo.
  After `docker compose run --rm ubuntu` (or other supported distros),
  you are ready to compile and run qtox
* Dependencies are owned by dependency install scripts in buildscripts/.
  This allows us to use the same exact dependencies in our
  OSX/windows/linux scripts
* New docker images have been added for a variety of distributions.
  These are now run in CI in a variety of configurations
  * Docker images are cached in CI so rebuild time for the majority of
    jobs is quite quick
* Build scripts have been trimmed to leverage state of docker
  containers.
  * Windows build script no longer installs anything, dependencies are
    now managed by the windows_builder docker images
  * Build scripts should now be easily re-runnable. Usage is now `docker
    compose run --rm <image>` and then run the scripts
* All artifacts are now uploaded to github after build, this means we
  can take an appimage/flatpak/exe/dmg for any given PR and try it out
  without having to build it ourselves

Notes:
* Docker image size is quite important. We have a maximum of 5GB cache
  space on github actions. The majority of the linux distro docker
  images cache at ~300-400MB, which gives us room to test ~6 distros
  after accounting for the sizes of flatpak/windows docker images
* Docker layer ordering is relatively intentional. Approximate order
  should be that large dependencies that change infrequently should be
  farther up. This lowers the amount of rebuilding we have to do when
  dependencies are updated
* download_xxx.sh scripts are the cleanest way I could find to implement
  a shared dependency map between osx scripts and docker containers.
  Although it would be nice to have a single dependency mapping file,
  splitting it into individual scripts allows us to only rebuild some
  docker layers when dependencies are updated.
* Github actions are split between docker image building and docker
  image use. This allows us to re-use the same docker images for
  multiple jobs, but only build it once
  * Unfortunately I could not find a way to de-duplicate the stitching
    between jobs, so we have a lot of copy pasta in that area
2021-12-19 14:56:05 -08:00

121 lines
4.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# MIT License
#
# Copyright © 2019 by The qTox Project Contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# Fail out on error
set -exuo pipefail
usage() {
echo "$0 --src-dir SRC_DIR"
echo "Builds an app image in the CWD based off qtox installation at SRC_DIR"
}
while (( $# > 0 )); do
case $1 in
--src-dir) QTOX_SRC_DIR=$2; shift 2 ;;
--help|-h) usage; exit 1 ;;
*) echo "Unexpected argument $1"; usage; exit 1;;
esac
done
if [ -z "${QTOX_SRC_DIR+x}" ]; then
echo "--src-dir is a required argument"
usage
exit 1
fi
# directory paths
BUILD_DIR=$(realpath .)
readonly BUILD_DIR
QTOX_APP_DIR="$BUILD_DIR"/appdir
readonly QTOX_APP_DIR
readonly LOCAL_LIB_DIR="$QTOX_APP_DIR"/local/lib
# ldqt binary
readonly LDQT_BIN="/usr/lib/qt5/bin/linuxdeployqt"
# update information to be embeded in AppImage
if [ "cron" == "${TRAVIS_EVENT_TYPE:-}" ]
then
# update information for nightly version
readonly NIGHTLY_REPO_SLUG=$(echo "$CIRP_GITHUB_REPO_SLUG" | tr "/" "|")
readonly UPDATE_INFO="gh-releases-zsync|$NIGHTLY_REPO_SLUG|ci-master-latest|qTox-*-x86_64.AppImage.zsync"
else
# update information for stable version
readonly UPDATE_INFO="gh-releases-zsync|qTox|qTox|latest|qTox-*.x86_64.AppImage.zsync"
fi
export VERSION=$(git -C "${QTOX_SRC_DIR}" rev-parse --short HEAD)
echo $QTOX_APP_DIR
cmake "${QTOX_SRC_DIR}" -DDESKTOP_NOTIFICATIONS=ON -DUPDATE_CHECK=ON -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
rm -fr appdir
make DESTDIR=appdir install
unset QTDIR; unset QT_PLUGIN_PATH; unset LD_LIBRARY_PATH;
readonly QTOX_DESKTOP_FILE="$QTOX_APP_DIR"/usr/local/share/applications/*.desktop
export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib/x86_64-linux-gnu/
eval "$LDQT_BIN $QTOX_DESKTOP_FILE -bundle-non-qt-libs -extra-plugins=libsnore-qt5"
# Move the required files to the correct directory
mv "$QTOX_APP_DIR"/usr/* "$QTOX_APP_DIR/"
rm -rf "$QTOX_APP_DIR/usr"
# Warning: This is hard coded to debain:stretch.
libs=(
# copy OpenSSL libs to AppImage
/usr/lib/x86_64-linux-gnu/libssl.so
/usr/lib/x86_64-linux-gnu/libcrypt.so
/usr/lib/x86_64-linux-gnu/libcrypto.so
# Also bundle libjack.so* without which the AppImage does not work in Fedora Workstation
/usr/lib/x86_64-linux-gnu/libjack.so.0
# And libglib needed by Red Hat and derivatives to work with our old gnutls
/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
/usr/lib/x86_64-linux-gnu/libgio-2.0.so.0
/usr/lib/x86_64-linux-gnu/libpango-1.0.so.0
/usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0
)
for lib in "${libs[@]}"; do
lib_file_name=$(basename "$lib")
cp -P $(echo "$lib"*) "$LOCAL_LIB_DIR"
patchelf --set-rpath '$ORIGIN' "$LOCAL_LIB_DIR/$lib_file_name"
done
# this is important, aitool automatically uses the same filename in .zsync meta file.
# if this name does not match with the one we upload, the update always fails.
if [ -n "${TRAVIS_TAG-}" ]
then
VERSION_NAME="${TRAVIS_TAG}"
elif [ -n "${TRAVIS_COMMIT-}" ]
then
VERSION_NAME="${TRAVIS_COMMIT}"
else
VERSION_NAME="${VERSION}"
fi
appimagetool -u "$UPDATE_INFO" $QTOX_APP_DIR qTox-$VERSION_NAME.x86_64.AppImage