@@ -2,15 +2,26 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# Generate a version string using git describe
+#
+# An optional sha string can be passed as the second command line argument
+# if the caller wishes to override the SHA value picked up by git. This may be
+# useful when distribution packages are build outside of the upstream repo.
build_dir="$1"
+sha_override="$2"
-# Bail out if the directory isn't under git control
-src_dir=$(git rev-parse --git-dir 2>&1) || exit 1
-src_dir=$(readlink -f "$src_dir/..")
-
-# Get a short description from the tree.
-version=$(git describe --abbrev=8 --match "v[0-9]*" 2>/dev/null)
+if [ -n "$sha_override" ]
+then
+ # Use the sha provided on the command line.
+ version="v0.0.0-g$sha_override"
+else
+ # Bail out if the directory isn't under git control
+ src_dir=$(git rev-parse --git-dir 2>&1) || exit 1
+ src_dir=$(readlink -f "$src_dir/..")
+
+ # Get a short description from the tree.
+ version=$(git describe --abbrev=8 --match "v[0-9]*" 2>/dev/null)
+fi
if [ -z "$version" ]
then
@@ -26,7 +37,7 @@ if [ -z "$build_dir" ] || (echo "$build_dir" | grep -q "$src_dir")
then
git update-index --refresh > /dev/null 2>&1
fi
-git diff-index --quiet HEAD || version="$version-dirty ($(date --iso-8601=seconds))"
+[ -n "$sha_override" ] || git diff-index --quiet HEAD || version="$version-dirty ($(date --iso-8601=seconds))"
# Replace first '-' with a '+' to denote build metadata, strip the 'g' in from
# of the git SHA1 and remove the initial 'v'.
Add an optional second command line argument to the gen-version.sh shell script that would be used as the SHA value in the version string. An override is needed if distributions make libcamera builds outside of the upstream git tree. In these cases, the user can then use the correct SHA value of the upstream tree instead of the local downstream build tree. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> --- utils/gen-version.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-)