From 1c89f616a92d09fa2eef6ec74c66d76fdd19b4b2 Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Tue, 21 Sep 2021 17:57:34 +0200
Subject: [PATCH] build: add support for .scmversion files for GLUON_VERSION
 and GLUON_SITE_VERSION

Sometimes it is useful to override the default version detection, for
example when local patches are applied to a repo. Allow providing a
version number using a file called .scmversion, which is the same that
the Linux kernel and U-Boot use.
---
 .gitignore            |  1 +
 docs/dev/build.rst    | 14 ++++++++++++++
 scripts/getversion.sh |  1 +
 3 files changed, 16 insertions(+)

diff --git a/.gitignore b/.gitignore
index a929851e8..c81272187 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@
 .bash_history
 .subversion
 .wget-hsts
+/.scmversion
diff --git a/docs/dev/build.rst b/docs/dev/build.rst
index 74b9aa11f..92fd672bd 100644
--- a/docs/dev/build.rst
+++ b/docs/dev/build.rst
@@ -88,3 +88,17 @@ update.sh
     source and installs it into *packages/* directory. It simply tries to set the *base*
     branch of the cloned repo to the correct commit. If this fails it fetches the
     upstream branch and tries again to set the local *base* branch.
+
+getversion.sh
+    Used to determine the version numbers of the repositories of Gluon and the
+    site configuraiton, to be included in the built firmware images as
+    */lib/gluon/gluon-version* and */lib/gluon/site-version*.
+
+    By default, this uses ``git describe`` to generate a version number based
+    on the last git tag. This can be overridden by putting a file called
+    *.scmversion* into the root of the respective repositories.
+
+    A command like ``rm -f .scmversion; echo "$(./scripts/getversion.sh .)" > .scmversion``
+    can be used before applying local patches to ensure that the reported
+    version numbers refer to an upstream commit ID rather than an arbitrary
+    local one after ``git am``.
diff --git a/scripts/getversion.sh b/scripts/getversion.sh
index cbb7cf602..8c437762a 100755
--- a/scripts/getversion.sh
+++ b/scripts/getversion.sh
@@ -7,6 +7,7 @@ fi
 
 cd "$1" || exit 1
 
+cat .scmversion 2>/dev/null && exit 0
 git --git-dir=.git describe --always --abbrev=7 --dirty=+ 2>/dev/null && exit 0
 
 echo unknown
-- 
GitLab