diff --git a/Makefile.work b/Makefile.work index fff349dc759..1f3609d7969 100644 --- a/Makefile.work +++ b/Makefile.work @@ -59,6 +59,8 @@ SLAVE_DIR = sonic-slave endif OVERLAY_MODULE_CHECK := lsmod | grep "^overlay " > /dev/null 2>&1 || (echo "ERROR: Module 'overlay' not loaded. Try running 'sudo modprobe overlay'."; exit 1) +SONIC_SET_BUILD_TIMESTAMP = . functions.sh && sonic_set_build_timestamp +SONIC_CLEAR_BUILD_TIMESTAMP = . functions.sh && sonic_clear_build_timestamp DOCKER_RUN := docker run --rm=true --privileged \ -v $(PWD):/sonic \ @@ -114,12 +116,12 @@ SONIC_BUILD_INSTRUCTION := make \ $(DOCKER_BUILD) ; } ifeq "$(KEEP_SLAVE_ON)" "yes" ifdef SOURCE_FOLDER - @$(DOCKER_RUN) -v $(SOURCE_FOLDER):/var/$(USER)/src $(SLAVE_IMAGE):$(SLAVE_TAG) bash -c "$(SONIC_BUILD_INSTRUCTION) $@; /bin/bash" + @$(DOCKER_RUN) -v $(SOURCE_FOLDER):/var/$(USER)/src $(SLAVE_IMAGE):$(SLAVE_TAG) bash -c "$(SONIC_SET_BUILD_TIMESTAMP); $(SONIC_BUILD_INSTRUCTION) $@; $(SONIC_CLEAR_BUILD_TIMESTAMP); /bin/bash" else - @$(DOCKER_RUN) $(SLAVE_IMAGE):$(SLAVE_TAG) bash -c "$(SONIC_BUILD_INSTRUCTION) $@; /bin/bash" + @$(DOCKER_RUN) $(SLAVE_IMAGE):$(SLAVE_TAG) bash -c "$(SONIC_SET_BUILD_TIMESTAMP); $(SONIC_BUILD_INSTRUCTION) $@; $(SONIC_CLEAR_BUILD_TIMESTAMP); /bin/bash" endif else - @$(DOCKER_RUN) $(SLAVE_IMAGE):$(SLAVE_TAG) $(SONIC_BUILD_INSTRUCTION) $@ + @$(DOCKER_RUN) $(SLAVE_IMAGE):$(SLAVE_TAG) bash -c "$(SONIC_SET_BUILD_TIMESTAMP); $(SONIC_BUILD_INSTRUCTION) $@" endif sonic-slave-build : diff --git a/functions.sh b/functions.sh index 3605877834f..d0a50f6cb72 100644 --- a/functions.sh +++ b/functions.sh @@ -50,8 +50,29 @@ docker_try_rmi() { } } +sonic_set_build_timestamp() { + local timestamp="$(date +%Y%m%d\.%H%M%S)" + echo "${timestamp}" > /tmp/sonic_build_timestamp +} + +sonic_clear_build_timestamp() { + rm /tmp/sonic_build_timestamp +} + +## Get build time stamp from temporary file if exists, +## otherwise get it in real time. +sonic_get_build_timestamp() { + local timestamp="invalid" + if [ ! -f /tmp/sonic_build_timestamp ]; then + timestamp="$(date +%Y%m%d\.%H%M%S)" + else + timestamp="$(cat /tmp/sonic_build_timestamp)" + fi + echo "${timestamp}" +} + sonic_get_version() { - DIRTY_SUFFIX="$(date +%Y%m%d\.%H%M%S)" + DIRTY_SUFFIX=$(sonic_get_build_timestamp) local describe=$(git describe --tags) local latest_tag=$(git describe --tags --abbrev=0) local branch_name=$(git rev-parse --abbrev-ref HEAD)