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:
@@ -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
|
||||
|
||||
@@ -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
@@ -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 =
|
||||
|
||||
@@ -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,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}")
|
||||
|
||||
Reference in New Issue
Block a user