Back Port of Git Versioning - without side effects Part 1

This commit is contained in:
David Sidrane 2015-06-12 06:49:15 -10:00
parent bcc49268ca
commit 17fddb1556
5 changed files with 38 additions and 12 deletions

View File

@ -58,12 +58,6 @@ endif
GIT_DESC_SHORT := $(shell echo $(GIT_DESC) | cut -c1-16)
$(shell mkdir -p $(BUILD_DIR))
$(shell rm -f $(BUILD_DIR)git_version.*)
$(shell echo "#include <systemlib/git_version.h>" > $(BUILD_DIR)git_version.c)
$(shell echo "const char* px4_git_version = \"$(GIT_DESC)\";" >> $(BUILD_DIR)git_version.c)
$(shell echo "const uint64_t px4_git_version_binary = 0x$(GIT_DESC_SHORT);" >> $(BUILD_DIR)git_version.c)
#
# Canned firmware configurations that we (know how to) build.
#
@ -139,7 +133,7 @@ $(STAGED_FIRMWARES): $(IMAGE_DIR)%.px4: $(BUILD_DIR)%.build/firmware.px4
.PHONY: $(FIRMWARES)
$(BUILD_DIR)%.build/firmware.px4: config = $(patsubst $(BUILD_DIR)%.build/firmware.px4,%,$@)
$(BUILD_DIR)%.build/firmware.px4: work_dir = $(BUILD_DIR)$(config).build/
$(FIRMWARES): $(BUILD_DIR)%.build/firmware.px4: generateuorbtopicheaders checksubmodules
$(FIRMWARES): $(BUILD_DIR)%.build/firmware.px4: checkgitversion generateuorbtopicheaders checksubmodules
@$(ECHO) %%%%
@$(ECHO) %%%% Building $(config) in $(work_dir)
@$(ECHO) %%%%
@ -227,7 +221,7 @@ menuconfig:
endif
$(NUTTX_SRC): checksubmodules
$(NUTTX_SRC): checkgitversion checksubmodules
$(UAVCAN_DIR):
$(Q) (./Tools/check_submodules.sh)
@ -248,6 +242,32 @@ ifeq ($(PX4_TARGET_OS),qurt)
include $(PX4_BASE)makefiles/firmware_qurt.mk
endif
#
# Versioning
#
GIT_VER_FILE = $(PX4_VERSIONING_DIR).build_git_ver
GIT_HEADER_FILE = $(PX4_VERSIONING_DIR)build_git_version.h
$(GIT_VER_FILE) :
$(Q) if [ ! -f $(GIT_VER_FILE) ]; then \
$(MKDIR) -p $(PX4_VERSIONING_DIR); \
$(ECHO) "" > $(GIT_VER_FILE); \
fi
.PHONY: checkgitversion
checkgitversion: $(GIT_VER_FILE)
$(Q) if [ "$(GIT_DESC)" != "$(shell cat $(GIT_VER_FILE))" ]; then \
$(ECHO) "/* Auto Magically Generated file */" > $(GIT_HEADER_FILE); \
$(ECHO) "/* Do not edit! */" >> $(GIT_HEADER_FILE); \
$(ECHO) "#define PX4_GIT_VERSION_STR \"$(GIT_DESC)\"" >> $(GIT_HEADER_FILE); \
$(ECHO) "#define PX4_GIT_VERSION_BINARY 0x$(GIT_DESC_SHORT)" >> $(GIT_HEADER_FILE); \
$(ECHO) $(GIT_DESC) > $(GIT_VER_FILE); \
fi
#
# Submodule Checks
#
.PHONY: checksubmodules
checksubmodules:
@ -321,7 +341,7 @@ check_format:
clean:
@echo > /dev/null
$(Q) $(RMDIR) $(BUILD_DIR)*.build
$(Q) $(REMOVE) $(BUILD_DIR)git_version.*
$(Q) $(RMDIR) $(PX4_VERSIONING_DIR)
$(Q) $(REMOVE) $(IMAGE_DIR)*.px4
.PHONY: distclean

View File

@ -62,6 +62,7 @@ export ROMFS_SRC = $(abspath $(PX4_BASE)/ROMFS)/
export IMAGE_DIR = $(abspath $(PX4_BASE)/Images)/
export BUILD_DIR = $(abspath $(PX4_BASE)/Build)/
export ARCHIVE_DIR = $(abspath $(PX4_BASE)/Archives)/
export PX4_VERSIONING_DIR = $(BUILD_DIR)versioning/
#
# Default include paths
@ -70,7 +71,8 @@ export INCLUDE_DIRS := $(PX4_MODULE_SRC) \
$(PX4_MODULE_SRC)/modules/ \
$(PX4_INCLUDE_DIR) \
$(PX4_LIB_DIR) \
$(PX4_PLATFORMS_DIR)
$(PX4_PLATFORMS_DIR) \
$(PX4_VERSIONING_DIR)
#
# Tools

View File

@ -41,6 +41,8 @@
#include <stdint.h>
#include "build_git_version.h"
__BEGIN_DECLS
__EXPORT extern const char* px4_git_version;

View File

@ -52,8 +52,7 @@ SRCS = \
mcu_version.c \
bson/tinybson.c \
circuit_breaker.cpp \
circuit_breaker_params.c \
$(BUILD_DIR)git_version.c
circuit_breaker_params.c
ifeq ($(PX4_TARGET_OS),nuttx)
SRCS += err.c \

View File

@ -57,6 +57,9 @@ static const char sz_ver_all_str[] = "all";
static const char mcu_ver_str[] = "mcu";
static const char mcu_uid_str[] = "uid";
const char* px4_git_version = PX4_GIT_VERSION_STR;
const uint64_t px4_git_version_binary = PX4_GIT_VERSION_BINARY;
static void usage(const char *reason)
{
if (reason != NULL) {