From: Simon McVittie <smcv@collabora.com>
Date: Mon, 12 Nov 2018 17:29:03 +0000
Subject: Log the version number during startup

When testing OBS behaviour changes, it's useful to be able to look
at a build log and see which code was running.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Forwarded: https://github.com/openSUSE/obs-build/pull/497
---
 Makefile         | 12 +++++++++++-
 build            |  2 ++
 common_functions |  2 ++
 init_buildsystem |  2 ++
 4 files changed, 17 insertions(+), 1 deletion(-)

Index: obs-build/Makefile
===================================================================
--- obs-build.orig/Makefile
+++ obs-build/Makefile
@@ -20,13 +20,22 @@ sysconfdir=/etc
 DESTDIR=
 
 all:
+ifeq ($(SCM),svn)
+	echo $(VERSION)$(SVNVER) > version
+else
+ifeq ($(SCM),git)
+	echo $(VERSION)_git$(DATE) > version
+else
+	echo $(VERSION) > version
+endif
+endif
 
 .PHONY:	test
 
 test:
 	PERL5LIB=. prove -v
 
-install:
+install: all
 	install -m755 -d \
 	    $(DESTDIR)$(pkglibdir)/configs \
 	    $(DESTDIR)$(pkglibdir)/baselibs_configs \
@@ -88,6 +97,7 @@ install:
 	install -m644 build-recipe build-recipe-* $(DESTDIR)$(pkglibdir)
 	install -m644 build-pkg build-pkg-* $(DESTDIR)$(pkglibdir)
 	install -m644 *.pm $(DESTDIR)$(pkglibdir)
+	install -m644 version $(DESTDIR)$(pkglibdir)
 	install -m644 configs/* $(DESTDIR)$(pkglibdir)/configs
 	install -m644 baselibs_configs/* $(DESTDIR)$(pkglibdir)/baselibs_configs
 	install -d $(DESTDIR)$(man1dir)
Index: obs-build/build
===================================================================
--- obs-build.orig/build
+++ obs-build/build
@@ -122,6 +122,7 @@ umask 022
 
 echo_help () {
     cat << EOT
+build version: $BUILD_VERSION
 
 Some comments for build
 -----------------------
@@ -1210,6 +1211,7 @@ for RECIPEFILE in "${RECIPEFILES[@]}" ;
     if test -z "$RUNNING_IN_VM" ; then
 	echo
 	echo "$HOST started \"build $RECIPEFILE\" at `date --utc`."
+	echo "build version: $BUILD_VERSION"
 	echo
 	test -n "$REASON" && echo "$REASON"
 	echo
Index: obs-build/common_functions
===================================================================
--- obs-build.orig/common_functions
+++ obs-build/common_functions
@@ -20,6 +20,8 @@
 #
 ################################################################
 
+BUILD_VERSION="$(cat "$BUILD_DIR/version")"
+
 build_host_arch() {
     : ${BUILD_HOST_ARCH:=`uname -m`}
     # the linux kernel only knows armv7l, armv7hl is a userland definition
Index: obs-build/init_buildsystem
===================================================================
--- obs-build.orig/init_buildsystem
+++ obs-build/init_buildsystem
@@ -461,6 +461,8 @@ getcachedir() {
     done
 }
 
+echo "init_buildsystem version: $BUILD_VERSION"
+
 set_build_arch
 
 trap fail_exit EXIT
