From 8a79a89ec48ba171e8550b2ba2db60a3a2b65e8c Mon Sep 17 00:00:00 2001 From: Martin Roth Date: Sun, 27 Nov 2022 18:18:10 -0700 Subject: util/genbuild_h: Update version calculation - 'git describe --match [0-9].[0-9]*' was giving me an error, so use the basic 'git describe' command instead. - If a .coreboot-version file exists, use that to determine the version. This fixes the problem for coreboot releases. - Don't run git for the versions unless it's being built from a valid git repository. Use 0.0 as the default version for timeless or unknown. Signed-off-by: Martin Roth Change-Id: I5fae2f012cc9b9914d8803af8dd58a885358cb1a Reviewed-on: https://review.coreboot.org/c/coreboot/+/70055 Tested-by: build bot (Jenkins) Reviewed-by: Jakub Czapiga Reviewed-by: Angel Pons --- util/genbuild_h/genbuild_h.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'util/genbuild_h') diff --git a/util/genbuild_h/genbuild_h.sh b/util/genbuild_h/genbuild_h.sh index 8c72ddfb4a65..78b09a612af1 100755 --- a/util/genbuild_h/genbuild_h.sh +++ b/util/genbuild_h/genbuild_h.sh @@ -6,6 +6,9 @@ DATE="" GITREV="" TIMESOURCE="" XGCCPATH="${XGCCPATH:-util/crossgcc/xgcc/bin/}" +MAJOR_VER="0" +MINOR_VER="0" +COREBOOT_VERSION_FILE=".coreboot-version" export LANG=C export LC_ALL=C @@ -32,10 +35,17 @@ elif [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then GITREV=$(get_git_head_data %h) TIMESOURCE=git DATE=$(get_git_head_data %ct) + VERSION="$(git describe)" + MAJOR_VER="$(echo "${VERSION}" | sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\1/')" + MINOR_VER="$(echo "${VERSION}" | sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\2/')" else GITREV=Unknown TIMESOURCE="date" - DATE=$(LANG= LC_ALL=C TZ=UTC0 date +%s) + DATE=$(LANG="" LC_ALL=C TZ=UTC0 date +%s) + if [ -f "${COREBOOT_VERSION_FILE}" ]; then + MAJOR_VER="$(sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\1/' "${COREBOOT_VERSION_FILE}")" + MINOR_VER="$(sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\2/' "${COREBOOT_VERSION_FILE}")" + fi fi our_date() { @@ -70,7 +80,8 @@ printf "#define COREBOOT_VERSION_TIMESTAMP $DATE\n" printf "#define COREBOOT_ORIGIN_GIT_REVISION \"$GITREV\"\n" printf "#define COREBOOT_EXTRA_VERSION \"%s\"\n" "$COREBOOT_EXTRA_VERSION" -printf "#define COREBOOT_MAJOR_VERSION %d\n#define COREBOOT_MINOR_VERSION %d\n" `git describe --match [0-9].[0-9]* | sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\1 \2/'` +printf "#define COREBOOT_MAJOR_VERSION %d\n" "${MAJOR_VER}" +printf "#define COREBOOT_MINOR_VERSION %d\n" "${MINOR_VER}" printf "#define COREBOOT_BUILD \"$(our_date "$DATE")\"\n" printf "#define COREBOOT_BUILD_YEAR_BCD 0x$(our_date "$DATE" +%y)\n" printf "#define COREBOOT_BUILD_MONTH_BCD 0x$(our_date "$DATE" +%m)\n" -- cgit v1.2.3