Skip to content

Commit 4bbc035

Browse files
committed
Added prebuild script to auto generate version info based on git hash
* In case git executable is in path, the genVersion.py script will read the commit hash and the modification state. * if git executable is not found a default version is generated * version tag includes the versin from config.h and combines it with git hash, modification state and date & time of build
1 parent 1f52d66 commit 4bbc035

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

eloc610LowPowerPartition/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch
6+
.vscode/*
7+
8+
#ignore auto generated files
9+
src/version.h

eloc610LowPowerPartition/platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ framework = espidf
2222
monitor_speed = 115200
2323
monitor_filters = esp32_exception_decoder
2424
board_build.partitions = elocPartitions.csv
25+
extra_scripts = pre:tools/genVersion.py

eloc610LowPowerPartition/src/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "rtc_wdt.h"
3131
//#include "soc/efuse_reg.h"
3232

33+
#include "version.h"
34+
3335
#include "lis3dh.h"
3436
#include "ElocSystem.hpp"
3537
#include "ManualWakeup.hpp"
@@ -604,7 +606,7 @@ void mountSDCard() {
604606
void app_main(void)
605607
{
606608
changeBootPartition(); // so if reboots, always boot into the bluetooth partition
607-
ESP_LOGI(TAG, "\n\n---------VERSION %s\n\n", VERSION);
609+
ESP_LOGI(TAG, "\n\n---------VERSION %s\n\n", VERSIONTAG);
608610

609611
printRevision();
610612

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import os
2+
import subprocess
3+
4+
FILENAME_VERSION_H = 'src/version.h'
5+
6+
gitFound = False
7+
try:
8+
build_hash = subprocess.run(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE).stdout.decode('utf-8')
9+
gitFound = True
10+
except:
11+
print("git not found in path. Please add git to system path variable to be able to use git commit hash in version")
12+
build_hash = "UNKNOWN"
13+
14+
if gitFound:
15+
subprocess.run(['git', 'update-index', '-q', '--ignore-submodules', '--refresh'], stdout=subprocess.PIPE).stdout.decode('utf-8')
16+
# check for unstaged changes in working tree, option -uno checks only tracked files
17+
modifiedFiles = subprocess.run(['git', 'status', '--porcelain', '-uno'], stdout=subprocess.PIPE).stdout.decode('utf-8')
18+
19+
print("Build Hash: " + build_hash[:8])
20+
print(modifiedFiles)
21+
22+
BUILD_CHECKEDIN = ""
23+
if (len(modifiedFiles) != 0):
24+
BUILD_CHECKEDIN = "_MODIFIED"
25+
26+
27+
hf = """
28+
29+
// AUTO GENERATED FILE, DO NOT EDIT THIS FILE
30+
// this file is generated by the genVersion.py prebuild script
31+
32+
#ifndef BUILDINFO_H_
33+
#define BUILDINFO_H_
34+
#include "config.h"
35+
36+
#ifndef BUILD_HASH
37+
#define BUILD_HASH "{}"
38+
#endif
39+
40+
#ifndef BUILD_CHECKEDIN
41+
#define BUILD_CHECKEDIN "{}"
42+
#endif
43+
44+
#ifndef VERSIONTAG
45+
#define VERSIONTAG VERSION "_" BUILD_HASH BUILD_CHECKEDIN " " __DATE__ " " __TIME__""
46+
#endif
47+
48+
#endif /* BUILDINFO_H_ */
49+
""".format(build_hash[:8], BUILD_CHECKEDIN)
50+
with open(FILENAME_VERSION_H, 'w+') as f:
51+
f.write(hf)

0 commit comments

Comments
 (0)