From 5e780903063a1059725217bc9e44e230fbc4f15f Mon Sep 17 00:00:00 2001 From: Reka Norman Date: Thu, 15 Dec 2022 15:04:11 +1100 Subject: [PATCH] util/genbuild_h: Only use version tags in expected format With commit 0110e1abe0ba ("util/genbuild_h: Update printf %d to %s for sh compatability"), the ChromeOS coreboot build is failing with: In file included from src/lib/version.c:4: /build/nissa/tmp/portage/sys-boot/coreboot-0.0.1-r5473/work/build/nivviks/build.h:10:32: error: 'v1' undeclared here (not in a function) 10 | #define COREBOOT_MAJOR_VERSION v1 | ^~ src/lib/version.c:35:46: note: in expansion of macro 'COREBOOT_MAJOR_VERSION' 35 | const unsigned int coreboot_major_revision = COREBOOT_MAJOR_VERSION; | ^~~~~~~~~~~~~~~~~~~~~~ /build/nissa/tmp/portage/sys-boot/coreboot-0.0.1-r5473/work/build/nivviks/build.h:11:32: error: 'v9308' undeclared here (not in a function) 11 | #define COREBOOT_MINOR_VERSION v9308 | ^~~~~ src/lib/version.c:36:46: note: in expansion of macro 'COREBOOT_MINOR_VERSION' 36 | const unsigned int coreboot_minor_revision = COREBOOT_MINOR_VERSION; | ^~~~~~~~~~~~~~~~~~~~~~ This is because the ChromeOS coreboot repo has a tag which is not in the expected . format: $ git tag v1.9308_26_0.0.22 Change genbuild_h.sh to only use the version from `git describe` if it's in the expected . format. TEST=ChromeOS coreboot build now succeeds, with versions set to 0: #define COREBOOT_MAJOR_VERSION 0 #define COREBOOT_MINOR_VERSION 0 Building upstream coreboot, the versions are still set correctly: #define COREBOOT_MAJOR_VERSION 4 #define COREBOOT_MINOR_VERSION 18 Change-Id: I81b2317a83cdec4cc2aad60af2990e5e3f4ad694 Signed-off-by: Reka Norman Reviewed-on: https://review.coreboot.org/c/coreboot/+/70770 Tested-by: build bot (Jenkins) Reviewed-by: Angel Pons Reviewed-by: Usha P --- util/genbuild_h/genbuild_h.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/util/genbuild_h/genbuild_h.sh b/util/genbuild_h/genbuild_h.sh index ae21d6c478..b4878c6407 100755 --- a/util/genbuild_h/genbuild_h.sh +++ b/util/genbuild_h/genbuild_h.sh @@ -36,8 +36,12 @@ elif [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then 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/')" + # Only use the `git describe` output if the tag is in the expected . + # format, e.g. 4.18. Forks of coreboot may have other tags in different formats. + if echo "${VERSION}" | grep -q "^[0-9]\.[0-9][0-9]*"; then + 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/')" + fi else GITREV=Unknown TIMESOURCE="date"