Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save build timestamp to local tmp file at the start of build #2108

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Makefile.work
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 :
Expand Down
23 changes: 22 additions & 1 deletion functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down