util/genbuild_h: Only use version tags in expected format

With commit 0110e1abe0 ("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 <major>.<minor> 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 <major>.<minor> 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 <rekanorman@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/70770
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Usha P <usha.p@intel.com>
This commit is contained in:
Reka Norman 2022-12-15 15:04:11 +11:00 committed by Martin L Roth
parent f7bb72333a
commit 5e78090306
1 changed files with 6 additions and 2 deletions

View File

@ -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)"
# Only use the `git describe` output if the tag is in the expected <major>.<minor>
# 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"