From 0b6acf86056319ffa01516dc43ca18f94eb2c822 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Mon, 30 Nov 2015 09:29:24 -0800 Subject: [PATCH] common: add support for using COREOS_BUILD_ID from the environment This allows build systems to export COREOS_BUILD_ID, making it practical to map built images to the job that created them. --- common.sh | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/common.sh b/common.sh index 3e101a41c7..a1e526b0ea 100644 --- a/common.sh +++ b/common.sh @@ -219,11 +219,8 @@ get_gclient_root() { # Populate the ENVIRONMENT_WHITELIST array. load_environment_whitelist() { ENVIRONMENT_WHITELIST=( - CHROMEOS_OFFICIAL - CHROMEOS_VERSION_AUSERVER - CHROMEOS_VERSION_DEVSERVER - CHROMEOS_VERSION_TRACK - GCC_GITHASH + COREOS_BUILD_ID + COREOS_OFFICIAL GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME GIT_COMMITTER_EMAIL @@ -244,6 +241,13 @@ load_environment_whitelist() { ) } +load_environment_var() { + local file="$1" name="$2" + local value + value=$(grep "^${name}=" "${file}") + export "${value}" +} + # Find root of source tree get_gclient_root @@ -267,23 +271,22 @@ BUILD_LIBRARY_DIR="${SCRIPTS_DIR}/build_library" REPO_CACHE_DIR="${REPO_ROOT}/.cache" REPO_MANIFESTS_DIR="${REPO_ROOT}/.repo/manifests" -# Source COREOS_* from manifest for version information. -COREOS_VERSION_FILE="${REPO_MANIFESTS_DIR}/version.txt" -if [[ ! -f "${COREOS_VERSION_FILE}" ]]; then - COREOS_VERSION_FILE="${SCRIPT_LOCATION}/version.txt" +# Source COREOS_VERSION_ID from manifest. +if [[ -f "${REPO_MANIFESTS_DIR}/version.txt" ]]; then + load_environment_var "${REPO_MANIFESTS_DIR}/version.txt" COREOS_VERSION_ID + # The build id may be provided externally by the build system. + : ${COREOS_BUILD_ID:=$(date +%Y-%m-%d-%H%M)} +elif [[ -f "${SCRIPT_LOCATION}/version.txt" ]]; then + load_environment_var "${SCRIPT_LOCATION}/version.txt" COREOS_VERSION_ID + # This only happens in update.zip where we must use the current build id. + load_environment_var "${SCRIPT_LOCATION}/version.txt" COREOS_BUILD_ID +else + die "Unable to locate version.txt" fi -source "$COREOS_VERSION_FILE" || die "Cannot source version.txt" - -# Set version based on old variables if undefined -: ${COREOS_VERSION_ID:=${COREOS_BUILD}.${COREOS_BRANCH}.${COREOS_PATCH}} # Official builds must set COREOS_OFFICIAL=1 to use an official version. -# Unofficial builds always appended the date/time as a build identifier. -# Also do not alter the version if using an alternate version.txt path. -COREOS_BUILD_ID="" -if [[ ${COREOS_OFFICIAL:-0} -ne 1 && - "${COREOS_VERSION_FILE}" =~ /\.repo/manifests/version.txt ]]; then - COREOS_BUILD_ID=$(date +%Y-%m-%d-%H%M) +# Unofficial builds always appended the build identifier. +if [[ ${COREOS_OFFICIAL:-0} -ne 1 && -n "${COREOS_BUILD_ID}" ]]; then COREOS_VERSION="${COREOS_VERSION_ID}+${COREOS_BUILD_ID}" else COREOS_VERSION="${COREOS_VERSION_ID}"