build: Define build id and version in one place

Before this change, setting `GIT_VERSION` in `make`'s environment was
intended to allow the user to specify a custom build id.  As it turns
out, `test/test.mk` had duplicated the logic from
`board/common/post-build.sh` to unconditionally override any value set
in it.  Because of the way `make` handles variables, where assignments
to variables inherited from the environment are exported back to
it[^1], this would mean that `test.mk` would always clobber any value
set by the user.  Furthermore, there is also this file called
`buildroot/package/git/git.mk`, which also (reasonably) has opinions
about what the proper value of `GIT_VERSION` should be.  In summary,
this was a bit of a mess.

Therefore: Make sure that there is one single place where we determine
the build id and version, and make sure that those variables are
scoped under the `INFIX_` prefix to avoid clashing with any other
component.

[^1]: https://www.gnu.org/software/make/manual/html_node/Environment.html
This commit is contained in:
Tobias Waldekranz
2024-12-05 10:29:21 +01:00
parent e635e3e720
commit d16ad7eedc
5 changed files with 18 additions and 29 deletions
+1 -3
View File
@@ -2,8 +2,6 @@
set -e
GIT_VERSION=$(git -C "$BR2_EXTERNAL_INFIX_PATH" describe --always --dirty --tags)
name=$1
compat=$2
sign=$3
@@ -26,7 +24,7 @@ cp -f "$BINARIES_DIR/rootfs.itbh" "$work/rootfs.itbh"
cat >"$work/manifest.raucm" <<EOF
[update]
compatible=${compat}
version=${GIT_VERSION}
version=${INFIX_VERSION}
[bundle]
format=verity
+5 -21
View File
@@ -39,22 +39,6 @@ if [ -n "${ID_LIKE}" ]; then
ID="${ID} ${ID_LIKE}"
fi
if [ -z "$GIT_VERSION" ]; then
infix_path="$BR2_EXTERNAL_INFIX_PATH"
if [ -n "$INFIX_OEM_PATH" ]; then
# Use version from br2-external OEM:ing Infix
infix_path="$INFIX_OEM_PATH"
fi
GIT_VERSION=$(git -C "$infix_path" describe --always --dirty --tags)
fi
# Override VERSION in /etc/os-release and filenames for release builds
if [ -n "$INFIX_RELEASE" ]; then
VERSION="$INFIX_RELEASE"
else
VERSION=$GIT_VERSION
fi
if [ -n "$INFIX_IMAGE_ID" ]; then
NAME="$INFIX_IMAGE_ID"
else
@@ -71,12 +55,12 @@ rm -f "$TARGET_DIR/etc/os-release"
{
echo "NAME=\"$INFIX_NAME\""
echo "ID=$INFIX_ID"
echo "PRETTY_NAME=\"$INFIX_TAGLINE $VERSION\""
echo "PRETTY_NAME=\"$INFIX_TAGLINE $INFIX_VERSION\""
echo "ID_LIKE=\"${ID}\""
echo "DEFAULT_HOSTNAME=$BR2_TARGET_GENERIC_HOSTNAME"
echo "VERSION=\"${VERSION}\""
echo "VERSION_ID=${VERSION}"
echo "BUILD_ID=\"${GIT_VERSION}\""
echo "VERSION=\"${INFIX_VERSION}\""
echo "VERSION_ID=${INFIX_VERSION}"
echo "BUILD_ID=\"${INFIX_BUILD_ID}\""
if [ -n "$INFIX_IMAGE_ID" ]; then
echo "IMAGE_ID=\"$INFIX_IMAGE_ID\""
fi
@@ -102,7 +86,7 @@ rm -f "$TARGET_DIR/etc/os-release"
fi
} > "$TARGET_DIR/etc/os-release"
echo "$INFIX_TAGLINE $VERSION -- $(date +"%b %e %H:%M %Z %Y")" > "$TARGET_DIR/etc/version"
echo "$INFIX_TAGLINE $INFIX_VERSION -- $(date +"%b %e %H:%M %Z %Y")" > "$TARGET_DIR/etc/version"
# In case of ambguities, this is what the image was built from
cp "$BR2_CONFIG" "$TARGET_DIR/usr/share/infix/config"
+1 -3
View File
@@ -1,9 +1,7 @@
IXMSG = printf "\e[37;44m>>> $(call qstrip,$(1))\e[0m\n"
include $(BR2_EXTERNAL_INFIX_PATH)/infix.mk
include $(sort $(wildcard $(BR2_EXTERNAL_INFIX_PATH)/package/*/*.mk))
include $(BR2_EXTERNAL_INFIX_PATH)/board/common/common.mk
-include $(BR2_EXTERNAL_INFIX_PATH)/board/$(patsubst "%",%,$(BR2_ARCH))/board.mk
include $(BR2_EXTERNAL_INFIX_PATH)/infix.mk
include $(BR2_EXTERNAL_INFIX_PATH)/test/test.mk
.PHONY: local.mk
+10
View File
@@ -1 +1,11 @@
IXMSG = printf "\e[37;44m>>> $(call qstrip,$(1))\e[0m\n"
INFIX_TOPDIR = $(if $(INFIX_OEM_PATH),$(INFIX_OEM_PATH),$(BR2_EXTERNAL_INFIX_PATH))
# Unless the user specifies an explicit build id, source it from git.
# The build id also becomes the image version, unless an official
# release is being built.
export INFIX_BUILD_ID ?= $(shell git -C $(INFIX_TOPDIR) describe --dirty --always --tags)
export INFIX_VERSION = $(if $(INFIX_RELEASE),$(INFIX_RELEASE),$(INFIX_BUILD_ID))
INFIX_CFLAGS:=-Wall -Werror -Wextra -Wno-unused-parameter -Wformat=2 -Wformat-overflow=2 -Winit-self -Wstrict-overflow=4 -Wno-format-truncation -Wno-format-nonliteral
+1 -2
View File
@@ -6,7 +6,6 @@ test-specification := $(O)/images/test-specification.pdf
UNIT_TESTS ?= $(test-dir)/case/all-repo.yaml $(test-dir)/case/all-unit.yaml
TESTS ?= $(test-dir)/case/all.yaml
GIT_VERSION = $(shell git -C $(GIT_PATH) describe --dirty --always --tags)
base := -b $(base-dir)
@@ -34,7 +33,7 @@ test-sh:
test-spec:
@esc_infix_name="$(echo $(INFIX_NAME) | sed 's/\//\\\//g')"; \
sed 's/{REPLACE}/$(subst ",,$(esc_infix_name)) $(GIT_VERSION)/' $(spec-dir)/Readme.adoc.in > $(spec-dir)/Readme.adoc
sed 's/{REPLACE}/$(subst ",,$(esc_infix_name)) $(INFIX_VERSION)/' $(spec-dir)/Readme.adoc.in > $(spec-dir)/Readme.adoc
@$(spec-dir)/generate_spec.py -d $(test-dir)/case -r $(BR2_EXTERNAL_INFIX_PATH)
@asciidoctor-pdf --failure-level INFO --theme $(spec-dir)/theme.yml -a pdf-fontsdir=$(spec-dir)/fonts -o $(test-specification) $(spec-dir)/Readme.adoc