Thanks for the suggestion.
My take is that since this is specific functionality for your application and your workflow, it’s best implemented in a custom user makefile. Add a file named build.mk
in your application src
directory and it will get picked up by Workbench when doing local compilation.
Note that since this is advanced customized functionality you may need to update this file in a future Device OS release due to build system changes.
# src/build.mk
ifneq "$(wildcard $(APPDIR)/.git )" "" #check if local repo exist
#Create variable GIT_MSG with:
#1) git sha and additionally dirty flag
GIT_MSG := sha:$(shell git --git-dir=${APPDIR}/.git --work-tree=${APPDIR} --no-pager describe --tags --always --dirty)
#2) last commit msg
GIT_MSG += msg:$(shell git --git-dir=${APPDIR}/.git --work-tree=${APPDIR} --no-pager log -1 --pretty=%B)
else
GIT_MSG := Can't find git repo
endif
#add user define macro (-D) for gcc preprocessor
CFLAGS += -DGIT_MSG=\"$(strip "$(GIT_MSG)")\"
# default functionality from https://github.com/particle-iot/device-os/blob/e9b7157c04298f976819af77b4d88c0c915571a3/user/build.mk#L57
INCLUDE_DIRS += $(SOURCE_PATH)/$(USRSRC) # add user sources to include path
# add C and CPP files - if USRSRC is not empty, then add a slash
CPPSRC += $(call target_files,$(USRSRC_SLASH),*.cpp)
CSRC += $(call target_files,$(USRSRC_SLASH),*.c)
APPSOURCES=$(call target_files,$(USRSRC_SLASH),*.cpp)
APPSOURCES+=$(call target_files,$(USRSRC_SLASH),*.c)