From a383917b23932200f7bc598ec9becd19a0e73a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 19 May 2023 17:52:52 +0200 Subject: [PATCH] ci: Use improved version of install-meson-project Copied from https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/.gitlab-ci/install-meson-project.sh Part-of: --- .gitlab-ci/install-meson-project.sh | 95 +++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 26 deletions(-) diff --git a/.gitlab-ci/install-meson-project.sh b/.gitlab-ci/install-meson-project.sh index bf0f9e2b7..8ecf8a300 100755 --- a/.gitlab-ci/install-meson-project.sh +++ b/.gitlab-ci/install-meson-project.sh @@ -2,38 +2,81 @@ set -e -if [[ $# -lt 3 ]]; then - echo Usage: $0 [options] [repo-url] [commit] [subdir] - echo Options: - echo -Dkey=val +usage() { + cat <<-EOF + Usage: $(basename $0) [OPTION…] REPO_URL COMMIT + + Check out and install a meson project + + Options: + -Dkey=val Option to pass on to meson + --subdir Build subdirectory instead of whole project + --prepare Script to run before build + + -h, --help Display this help + + EOF +} + +TEMP=$(getopt \ + --name=$(basename $0) \ + --options='D:h' \ + --longoptions='subdir:' \ + --longoptions='prepare:' \ + --longoptions='help' \ + -- "$@") + +eval set -- "$TEMP" +unset TEMP + +MESON_OPTIONS=() +SUBDIR=. +PREPARE=: + +while true; do + case "$1" in + -D) + MESON_OPTIONS+=( -D$2 ) + shift 2 + ;; + + --subdir) + SUBDIR=$2 + shift 2 + ;; + + --prepare) + PREPARE=$2 + shift 2 + ;; + + -h|--help) + usage + exit 0 + ;; + + --) + shift + break + ;; + esac +done + +if [[ $# -lt 2 ]]; then + usage exit 1 fi -MESON_OPTIONS=() - -while [[ $1 =~ ^-D ]]; do - MESON_OPTIONS+=( "$1" ) - shift -done - REPO_URL="$1" -TAG_OR_BRANCH="$2" -SUBDIR="$3" -COMMIT="$4" +COMMIT="$2" -REPO_DIR="$(basename ${REPO_URL%.git})" +CHECKOUT_DIR=$(mktemp --directory) +trap "rm -rf $CHECKOUT_DIR" EXIT -git clone --depth 1 "$REPO_URL" -b "$TAG_OR_BRANCH" -pushd "$REPO_DIR" -pushd "$SUBDIR" +git clone --depth 1 "$REPO_URL" -b "$COMMIT" "$CHECKOUT_DIR" -if [ ! -z "$COMMIT" ]; then - git fetch origin "$COMMIT" - git checkout "$COMMIT" -fi - -meson --prefix=/usr _build "${MESON_OPTIONS[@]}" +pushd "$CHECKOUT_DIR/$SUBDIR" +sh -c "$PREPARE" +meson setup --prefix=/usr _build "${MESON_OPTIONS[@]}" meson install -C _build popd -popd -rm -rf "$REPO_DIR"