From 21649b2cb3454608b273b2abef98f930e1aac341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Mon, 22 Jul 2019 11:44:12 +0200 Subject: [PATCH 1/3] makefiles/git_version.inc.mk: deferred GIT_VERSION definition Move git version evaluation to a separate file. The definition has been updated it to a deferred only definition. This way git is not called when GIT_VERSION is not used. --- makefiles/git_version.inc.mk | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 makefiles/git_version.inc.mk diff --git a/makefiles/git_version.inc.mk b/makefiles/git_version.inc.mk new file mode 100644 index 0000000000..03a2194564 --- /dev/null +++ b/makefiles/git_version.inc.mk @@ -0,0 +1,11 @@ +# GIT_VERSION is git description + branch name if it not master +# Empty when not in a git repository +# +# 2019.10-devel-97-g3bcc72 +# 2019.10-devel-97-g3bcc72-pr/git_version + +GIT_DESCRIBE = $(call memoized,GIT_DESCRIBE,$(shell git --git-dir="$(RIOTBASE)/.git" describe --always --abbrev=4 2> /dev/null)) +GIT_BRANCH = $(call memoized,GIT_BRANCH,$(shell git --git-dir="$(RIOTBASE)/.git" rev-parse --abbrev-ref HEAD)) +_GIT_VERSION = $(GIT_DESCRIBE)$(addprefix -,$(GIT_BRANCH:master=)) + +GIT_VERSION ?= $(if $(GIT_DESCRIBE),$(_GIT_VERSION)) From cfd46773158a3871daa02cb457cd3bad7cb250bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Mon, 22 Jul 2019 12:01:18 +0200 Subject: [PATCH 2/3] Makefile.include: use GIT_VERSION for RIOT_VERSION Use 'GIT_VERSION' for 'RIOT_VERSION'. This prevents evaluating 'git describe' and 'git rev-parse' when their value is not used. --- Makefile.include | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/Makefile.include b/Makefile.include index 1072231bd6..efa575e7f5 100644 --- a/Makefile.include +++ b/Makefile.include @@ -350,20 +350,8 @@ include $(RIOTMAKE)/cflags.inc.mk # Include VERSION for releases -include $(RIOTBASE)/VERSION -# make the RIOT version available to the program -ifeq ($(origin RIOT_VERSION), undefined) - GIT_STRING := $(shell git --git-dir="$(RIOTBASE)/.git" describe --always --abbrev=4 2> /dev/null) - ifneq (,$(GIT_STRING)) - GIT_BRANCH := $(shell git --git-dir="$(RIOTBASE)/.git" rev-parse --abbrev-ref HEAD) - ifeq ($(strip $(GIT_BRANCH)),master) - RIOT_VERSION := $(GIT_STRING) - else - RIOT_VERSION := $(GIT_STRING)-$(GIT_BRANCH) - endif - else - RIOT_VERSION := 'UNKNOWN (builddir: $(RIOTBASE))' - endif -endif +include $(RIOTMAKE)/git_version.inc.mk +RIOT_VERSION ?= $(or $(GIT_VERSION),'UNKNOWN (builddir: $(RIOTBASE))') # Set module by prepending APPLICATION name with 'application_'. # It prevents conflict with application and modules with the same name. From 8859e1e1d9c65b1dfb002b11325485f67e0c9291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Mon, 22 Jul 2019 12:03:05 +0200 Subject: [PATCH 3/3] Makefile.include: Only evaluate RIOT_VERSION when needed This changes CFLAGS_WITH_MACROS to be: * a deferred variable * not exported so only evaluated when actually used The value is only used by `Makefile.include` and `makefiles/eclipse.inc.mk` so not required to export it. --- Makefile.include | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile.include b/Makefile.include index efa575e7f5..d3b2eb8d7c 100644 --- a/Makefile.include +++ b/Makefile.include @@ -721,12 +721,14 @@ $(RIOTBUILD_CONFIG_HEADER_C): FORCE $(Q)'$(RIOTTOOLS)/genconfigheader/genconfigheader.sh' $(CFLAGS_WITH_MACROS) \ | '$(LAZYSPONGE)' $(LAZYSPONGE_FLAGS) '$@' -CFLAGS_WITH_MACROS := $(CFLAGS) +# Immediate evaluation but keep CLAGS_WITH_MACROS deferred +_CFLAGS := $(CFLAGS) +CFLAGS_WITH_MACROS = $(_CFLAGS) ifneq (,$(RIOT_VERSION_OVERRIDE)) -export CFLAGS_WITH_MACROS += -DRIOT_VERSION=\"$(RIOT_VERSION_OVERRIDE)\" + CFLAGS_WITH_MACROS += -DRIOT_VERSION=\"$(RIOT_VERSION_OVERRIDE)\" else -export CFLAGS_WITH_MACROS += -DRIOT_VERSION=\"$(RIOT_VERSION)\" + CFLAGS_WITH_MACROS += -DRIOT_VERSION=\"$(RIOT_VERSION)\" endif CFLAGS := $(patsubst -D%,,$(CFLAGS))