gnome-shell/.gitlab-ci/install-meson-project.sh
Florian Müllner 919812a851 ci: Fix meson-install usage check
The script has four mandatory arguments, and also accepts optional
build options that are passed on to meson. Checking for the number
of arguments *before* filtering out the optional ones means that

`./install-meson-project.sh -Done=1 -Dtwo=2 -Dthree=3 -Dfour=4`

is considered valid, even though not a single required argument
is passed.

Fix this by filtering out the arguments before doing the usage
check. As it is a nice touch to have usage information at the
top of the script, move the message into a usage() function at
the top.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2712>
2023-04-20 15:59:56 +00:00

45 lines
641 B
Bash
Executable File

#!/bin/bash
set -e
usage() {
cat <<-EOF
Usage: $(basename $0) [OPTION…] REPO_URL COMMIT SUBDIR PREPARE
Check out and install a meson project
Options:
-Dkey=val Option to pass on to meson
EOF
}
MESON_OPTIONS=()
while [[ $1 =~ ^-D ]]; do
MESON_OPTIONS+=( "$1" )
shift
done
if [[ $# -lt 4 ]]; then
usage
exit 1
fi
REPO_URL="$1"
COMMIT="$2"
SUBDIR="$3"
PREPARE="$4"
REPO_DIR="$(basename ${REPO_URL%.git})"
git clone --depth 1 "$REPO_URL" -b "$COMMIT"
pushd "$REPO_DIR"
pushd "$SUBDIR"
sh -c "$PREPARE"
meson setup --prefix=/usr _build "${MESON_OPTIONS[@]}"
meson install -C _build
popd
popd
rm -rf "$REPO_DIR"