build: allow rootfs builds w/o git or VERSION file deps

We set the VERSION variable consistently across Makefiles to
'unknown'  if the file is empty or not present.
We also use git commands consistently for calculating the COMMIT,
COMMIT_NO variables, not erroring out when building outside of
a git repository.
In create_summary_file we also account for a missing/empty VERSION
file.
This makes e.g. the UVM build process in an environment where we
build outside of git with a minimal/reduced set of files smoother.

Signed-off-by: Manuel Huber <mahuber@microsoft.com>
This commit is contained in:
Manuel Huber 2024-06-11 20:51:26 +00:00
parent 6f1062b5d6
commit 62fd84dfd8
6 changed files with 12 additions and 10 deletions

View File

@ -15,7 +15,7 @@ PROJECT_COMPONENT = kata-agent
TARGET = $(PROJECT_COMPONENT) TARGET = $(PROJECT_COMPONENT)
VERSION_FILE := ./VERSION VERSION_FILE := ./VERSION
VERSION := $(shell grep -v ^\# $(VERSION_FILE)) VERSION := $(shell grep -v ^\# $(VERSION_FILE) 2>/dev/null || echo "unknown")
COMMIT_NO := $(shell git rev-parse HEAD 2>/dev/null || true) COMMIT_NO := $(shell git rev-parse HEAD 2>/dev/null || true)
COMMIT := $(if $(shell git status --porcelain --untracked-files=no 2>/dev/null || true),${COMMIT_NO}-dirty,${COMMIT_NO}) COMMIT := $(if $(shell git status --porcelain --untracked-files=no 2>/dev/null || true),${COMMIT_NO}-dirty,${COMMIT_NO})
COMMIT_MSG = $(if $(COMMIT),$(COMMIT),unknown) COMMIT_MSG = $(if $(COMMIT),$(COMMIT),unknown)

View File

@ -358,7 +358,7 @@ SOURCES := \
Cargo.toml Cargo.toml
VERSION_FILE := ./VERSION VERSION_FILE := ./VERSION
VERSION := $(shell grep -v ^\# $(VERSION_FILE)) VERSION := $(shell grep -v ^\# $(VERSION_FILE) 2>/dev/null || echo "unknown")
COMMIT_NO := $(shell git rev-parse HEAD 2>/dev/null || true) COMMIT_NO := $(shell git rev-parse HEAD 2>/dev/null || true)
COMMIT := $(if $(shell git status --porcelain --untracked-files=no 2>/dev/null || true),${COMMIT_NO}-dirty,${COMMIT_NO}) COMMIT := $(if $(shell git status --porcelain --untracked-files=no 2>/dev/null || true),${COMMIT_NO}-dirty,${COMMIT_NO})
COMMIT_MSG = $(if $(COMMIT),$(COMMIT),unknown) COMMIT_MSG = $(if $(COMMIT),$(COMMIT),unknown)

View File

@ -13,7 +13,7 @@ TARGET = $(PROJECT_COMPONENT)
INSTALL_PATH = $(HOME)/.cargo INSTALL_PATH = $(HOME)/.cargo
VERSION_FILE := ./VERSION VERSION_FILE := ./VERSION
export VERSION := $(shell grep -v ^\# $(VERSION_FILE)) export VERSION := $(shell grep -v ^\# $(VERSION_FILE) 2>/dev/null || echo "unknown")
COMMIT_NO := $(shell git rev-parse HEAD 2>/dev/null || true) COMMIT_NO := $(shell git rev-parse HEAD 2>/dev/null || true)
COMMIT_NO_SHORT := $(shell git rev-parse --short HEAD 2>/dev/null || true) COMMIT_NO_SHORT := $(shell git rev-parse --short HEAD 2>/dev/null || true)
export COMMIT := $(if $(shell git status --porcelain --untracked-files=no 2>/dev/null || true),${COMMIT_NO}-dirty,${COMMIT_NO}) export COMMIT := $(if $(shell git status --porcelain --untracked-files=no 2>/dev/null || true),${COMMIT_NO}-dirty,${COMMIT_NO})

View File

@ -7,9 +7,10 @@
TARGET = kata-log-parser TARGET = kata-log-parser
SOURCES = $(shell find . 2>&1 | grep -E '.*\.go$$') SOURCES = $(shell find . 2>&1 | grep -E '.*\.go$$')
VERSION := ${shell cat ./VERSION} VERSION_FILE := ./VERSION
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true) VERSION := $(shell grep -v ^\# $(VERSION_FILE) 2>/dev/null || echo "unknown")
COMMIT := $(if $(shell git status --porcelain --untracked-files=no),"${COMMIT_NO}-dirty","${COMMIT_NO}") COMMIT_NO := $(shell git rev-parse HEAD 2>/dev/null || true)
COMMIT := $(if $(shell git status --porcelain --untracked-files=no 2>/dev/null || true),"${COMMIT_NO}-dirty","${COMMIT_NO}")
BINDIR := $(GOPATH)/bin BINDIR := $(GOPATH)/bin
DESTTARGET := $(abspath $(BINDIR)/$(TARGET)) DESTTARGET := $(abspath $(BINDIR)/$(TARGET))

View File

@ -23,9 +23,9 @@ TARGET_IMAGE := $(IMAGES_BUILD_DEST)/kata-containers.img
TARGET_INITRD := $(IMAGES_BUILD_DEST)/kata-containers-initrd.img TARGET_INITRD := $(IMAGES_BUILD_DEST)/kata-containers-initrd.img
VERSION_FILE := ./VERSION VERSION_FILE := ./VERSION
VERSION := $(shell grep -v ^\# $(VERSION_FILE)) VERSION := $(shell grep -v ^\# $(VERSION_FILE) 2>/dev/null || echo "unknown")
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true) COMMIT_NO := $(shell git rev-parse HEAD 2>/dev/null || true)
COMMIT := $(if $(shell git status --porcelain --untracked-files=no),${COMMIT_NO}-dirty,${COMMIT_NO}) COMMIT := $(if $(shell git status --porcelain --untracked-files=no 2>/dev/null || true),${COMMIT_NO}-dirty,${COMMIT_NO})
VERSION_COMMIT := $(if $(COMMIT),$(VERSION)-$(COMMIT),$(VERSION)) VERSION_COMMIT := $(if $(COMMIT),$(VERSION)-$(COMMIT),$(VERSION))
ifeq ($(filter $(BUILD_METHOD),$(BUILD_METHOD_LIST)),) ifeq ($(filter $(BUILD_METHOD),$(BUILD_METHOD_LIST)),)

View File

@ -181,7 +181,8 @@ create_summary_file()
[ "$AGENT_INIT" = yes ] && agent="${init}" [ "$AGENT_INIT" = yes ] && agent="${init}"
local -r agentdir="${script_dir}/../../../" local -r agentdir="${script_dir}/../../../"
local -r agent_version=$(cat ${agentdir}/VERSION) local agent_version=$(cat ${agentdir}/VERSION 2> /dev/null)
[ -z "$agent_version" ] && agent_version="unknown"
cat >"$file"<<-EOF cat >"$file"<<-EOF
--- ---