diff --git a/.gitignore b/.gitignore index 5e9eb31..91bb5d6 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/generate_version_file.py b/generate_version_file.py deleted file mode 100644 index 79967d1..0000000 --- a/generate_version_file.py +++ /dev/null @@ -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 diff --git a/platformio.ini b/platformio.ini index 78d9f0e..d459a2c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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 = diff --git a/src/data_nodes.cpp b/src/data_nodes.cpp index e4dd69a..846513d 100644 --- a/src/data_nodes.cpp +++ b/src/data_nodes.cpp @@ -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 diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 0738b6a..e9c53f7 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -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}")