build: gen-version-i.sh: use a fixed abbrev length
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 26 May 2023 16:17:01 +0000 (12:17 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 31 Aug 2023 14:38:42 +0000 (10:38 -0400)
When doing:

 - make
 - sudo make install

... it is possible for the `sudo make install` command to generate a new
src/common/version.i file, if the regular user has a custom value for
the `core.abbrev` git configuration variable.

The version.i file generated by `make` contains a version number with a
hash of a certain length.  Then `sudo make install` generates an
equivalent version number, but with a hash of a different length.  This
then causes some object files that depended on it to be rebuilt, which
is not expected for the install target.

To avoid this, add --abbrev=12 to the git describe command that
genenerates the version string, so that the same hash representation is
generated during both "make" and "sudo make install".

Change-Id: I979d6a9d627f133909dc026e0d2820b52f409d98
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Fixes: https://bugs.lttng.org/issues/1376
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10098
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/common/gen-version-i.sh

index bbdee5e6104d57d2eacdeb911a67825c9b852fa8..aa7d5b3ec2b079574e1a5c6061cf7f1ddc34d040 100755 (executable)
@@ -37,9 +37,12 @@ fi
 # And store it in "version.i.tmp", if the current commit is tagged, the tag
 # starts with "v" and the tree is clean, consider this a release version and
 # overwrite the git version with an empty string in "version.i.tmp".
+#
+# Use an explicit hash abbreviation length, to avoid local `core.abbrev`
+# configurations leading to different results.
 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 || true))"
+       GIT_VERSION_STR="$(cd "$TOP_SRCDIR" && (git describe --tags --dirty --abbrev=12 || 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
 
This page took 0.031624 seconds and 4 git commands to generate.