From 3ccee65c5e2c22dae34f2a25a14601bbf795fbff Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 19 Jun 2023 21:28:12 -0400 Subject: [PATCH] build: gen-version-i.sh: use errexit option Use `set -o errexit` in gen-version-i.sh, so that any unexpected command failures stops the script. The first `git describe` command can unexpectedly fail when the script is ran by a user other than the owner of the git repository (and sudo wasn't used, so SUDO_UID & co are not set): # git describe --tags --dirty fatal: detected dubious ownership in repository at '/home/smarchi/src/babeltrace' To add an exception for this directory, call: git config --global --add safe.directory /home/smarchi/src/babeltrace For instance, this happens if the git repository is owned by a regular user, and `make install` is ran in a root shell started with `su`. Add `|| true` to that command, to keep the existing behavior (even if it's not ideal). Change-Id: Idfbcb3a86158bcddff11a34a18a5d004def37742 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/10103 Reviewed-by: Michael Jeanson --- src/common/gen-version-i.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/gen-version-i.sh b/src/common/gen-version-i.sh index 860ac18a..bbdee5e6 100755 --- a/src/common/gen-version-i.sh +++ b/src/common/gen-version-i.sh @@ -12,6 +12,7 @@ # release version and set an empty git version. set -o nounset +set -o errexit if test "${TOP_SRCDIR:-}" = ""; then echo "$0: TOP_SRCDIR is not set" >&2 @@ -38,7 +39,7 @@ fi # overwrite the git version with an empty string in "version.i.tmp". if test -r "$TOP_SRCDIR/bootstrap" && test -r "$TOP_SRCDIR/.git" && (command -v git > /dev/null 2>&1); then - GIT_VERSION_STR="$(cd "$TOP_SRCDIR" && git describe --tags --dirty)" + GIT_VERSION_STR="$(cd "$TOP_SRCDIR" && (git describe --tags --dirty || true))" GIT_CURRENT_TAG="$(cd "$TOP_SRCDIR" && (git describe --tags --exact-match --match="v[0-9]*" HEAD || true) 2> /dev/null)" echo "#define BT_VERSION_GIT \"$GIT_VERSION_STR\"" > version.i.tmp -- 2.34.1