genbuild_h: Fix and harden major/minor version parsing
Our major version is suddenly two digits long to represent the year. This can't be parsed with the current sed scripts. To make sure that no unparsed data ends up in our major/minor versions, we'll run sed with `-n' and only print the extracted numbers if anything. Also, to allow us to use the version numbers in C code, we strip leading zeros (a leading 0 identifies octal numbers, so for instance 08 for August is not a valid number). This can result in empty major/minor version strings, so we move the default `0' to the final variable expansion. As a bonus, this makes an explicit check if the numbers can be parsed unnecessary. Change-Id: Ie39381a8ef4b971556168b6996efeefe6adf2b14 Reported-by: Christoph Zechner <christophz@vrvis.at> Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/c/coreboot/+/81290 Reviewed-by: Maximilian Brune <maximilian.brune@9elements.com> Reviewed-by: Martin L Roth <gaumless@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
committed by
Martin L Roth
parent
5c769ab711
commit
3e4b517265
@ -6,8 +6,8 @@ DATE=""
|
|||||||
GITREV=""
|
GITREV=""
|
||||||
TIMESOURCE=""
|
TIMESOURCE=""
|
||||||
XGCCPATH="${XGCCPATH:-util/crossgcc/xgcc/bin/}"
|
XGCCPATH="${XGCCPATH:-util/crossgcc/xgcc/bin/}"
|
||||||
MAJOR_VER="0"
|
MAJOR_VER=""
|
||||||
MINOR_VER="0"
|
MINOR_VER=""
|
||||||
COREBOOT_VERSION_FILE=".coreboot-version"
|
COREBOOT_VERSION_FILE=".coreboot-version"
|
||||||
|
|
||||||
export LANG=C
|
export LANG=C
|
||||||
@ -36,19 +36,15 @@ elif [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
|
|||||||
TIMESOURCE=git
|
TIMESOURCE=git
|
||||||
DATE="$(get_git_head_data %ct)"
|
DATE="$(get_git_head_data %ct)"
|
||||||
VERSION="$(git describe)"
|
VERSION="$(git describe)"
|
||||||
# Only use the `git describe` output if the tag is in the expected <major>.<minor>
|
MAJOR_VER="$(echo "${VERSION}" | sed -n 's/^0*\([0-9]*\)\.0*\([0-9]*\).*/\1/p')"
|
||||||
# format, e.g. 4.18. Forks of coreboot may have other tags in different formats.
|
MINOR_VER="$(echo "${VERSION}" | sed -n 's/^0*\([0-9]*\)\.0*\([0-9]*\).*/\2/p')"
|
||||||
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
|
else
|
||||||
GITREV=Unknown
|
GITREV=Unknown
|
||||||
TIMESOURCE="date"
|
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
|
if [ -f "${COREBOOT_VERSION_FILE}" ]; then
|
||||||
MAJOR_VER="$(sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\1/' "${COREBOOT_VERSION_FILE}")"
|
MAJOR_VER="$(sed -n 's/^0*\([0-9]*\)\.0*\([0-9]*\).*/\1/p' "${COREBOOT_VERSION_FILE}")"
|
||||||
MINOR_VER="$(sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\2/' "${COREBOOT_VERSION_FILE}")"
|
MINOR_VER="$(sed -n 's/^0*\([0-9]*\)\.0*\([0-9]*\).*/\2/p' "${COREBOOT_VERSION_FILE}")"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -84,8 +80,8 @@ printf "#define COREBOOT_VERSION_TIMESTAMP %s\n" "${DATE}"
|
|||||||
printf "#define COREBOOT_ORIGIN_GIT_REVISION \"%s\"\n" "${GITREV}"
|
printf "#define COREBOOT_ORIGIN_GIT_REVISION \"%s\"\n" "${GITREV}"
|
||||||
|
|
||||||
printf "#define COREBOOT_EXTRA_VERSION \"%s\"\n" "${COREBOOT_EXTRA_VERSION}"
|
printf "#define COREBOOT_EXTRA_VERSION \"%s\"\n" "${COREBOOT_EXTRA_VERSION}"
|
||||||
printf "#define COREBOOT_MAJOR_VERSION %s\n" "${MAJOR_VER}"
|
printf "#define COREBOOT_MAJOR_VERSION %s\n" "${MAJOR_VER:-0}"
|
||||||
printf "#define COREBOOT_MINOR_VERSION %s\n" "${MINOR_VER}"
|
printf "#define COREBOOT_MINOR_VERSION %s\n" "${MINOR_VER:-0}"
|
||||||
printf "#define COREBOOT_BUILD \"%s\"\n" "$(our_date "${DATE}" "+%a %b %d %H:%M:%S %Z %Y")"
|
printf "#define COREBOOT_BUILD \"%s\"\n" "$(our_date "${DATE}" "+%a %b %d %H:%M:%S %Z %Y")"
|
||||||
printf "#define COREBOOT_BUILD_YEAR_BCD 0x%s\n" "$(our_date "${DATE}" "+%y")"
|
printf "#define COREBOOT_BUILD_YEAR_BCD 0x%s\n" "$(our_date "${DATE}" "+%y")"
|
||||||
printf "#define COREBOOT_BUILD_MONTH_BCD 0x%s\n" "$(our_date "${DATE}" "+%m")"
|
printf "#define COREBOOT_BUILD_MONTH_BCD 0x%s\n" "$(our_date "${DATE}" "+%m")"
|
||||||
|
Reference in New Issue
Block a user