Generate COMMIT_HASH define via CMake

Previously the commit hash was generated with a python script which was only
called by PlatformIO and caused issues when using Zephyr SDK directly.
This commit is contained in:
Martin Jäger
2020-07-23 17:34:41 +02:00
parent c2ef955a63
commit 5e213fdfb1
5 changed files with 13 additions and 27 deletions
-3
View File
@@ -3,9 +3,6 @@
.gcc-flags.json
.vscode/browse.vc.db*
.vscode
src/config.cpp
src/config.h
src/version.h
html
memory.map
custom.ini
-19
View File
@@ -1,19 +0,0 @@
# Custom script to generate src/version.h file containing the git commit hash
#
# See also http://docs.platformio.org/en/latest/projectconf.html#extra-script
#
import subprocess
try:
commit_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).strip()
except:
commit_hash = ""
f = open("src/version.h","w+")
f.write("/* Auto-generated file with git commit hash to be included by C code\n")
f.write(" * Do not change this file manually!\n")
f.write(" */\n")
f.write("\n")
f.write('#define COMMIT_HASH "' + commit_hash.decode('utf-8') + '"\n')
f.close
+1 -3
View File
@@ -45,8 +45,6 @@ build_flags =
-Wl,-Map,memory.map
build_unflags = -std=gnu++98 -std=gnu++14
extra_scripts =
generate_version_file.py
check_tool = cppcheck, clangtidy
check_flags =
@@ -84,7 +82,7 @@ build_flags =
-Wall
-D UNIT_TEST
-D __STDC_FORMAT_MACROS
-D COMMIT_HASH=\"test\"
-I test
# include src directory (otherwise unit-tests will only include lib directory)
test_build_project_src = true
extra_scripts =
-2
View File
@@ -19,8 +19,6 @@ LOG_MODULE_REGISTER(data_nodes, CONFIG_LOG_DEFAULT_LEVEL);
#include "setup.h"
#include "version.h"
// can be used to configure custom data objects in separate file instead
// (e.g. data_nodes_custom.cpp)
#ifndef CONFIG_CUSTOM_DATA_NODES_FILE
+12
View File
@@ -12,3 +12,15 @@ add_subdirectory(../src build/src)
add_subdirectory(../lib/thingset build/thingset)
add_subdirectory(../lib/oled-display build/oled-display)
# determine git commit hash and provide it as a compiler define
find_package(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
OUTPUT_VARIABLE COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
set(COMMIT_HASH "")
endif()
add_definitions(-DCOMMIT_HASH="${COMMIT_HASH}")