Skip to content

Commit 91aa125

Browse files
committed
Add script to build for generating VCS ID.
1 parent cf7e909 commit 91aa125

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ Alternatively the software may be executed in a simulation environment.
3939
This project uses [PlatformIO](https://platformio.org/) as build system and package manager.
4040
PlatformIO may be used via a GUI (PlatformIO IDE) or command line interface (PlatformIO Core). The project configuration ([`platformio.ini`](platformio.ini)) is part of this repository.
4141

42+
System requirements:
43+
44+
- [PlatformIO](https://platformio.org/)
45+
- [Python](https://www.python.org/) interpreter
46+
- optional: [git](https://git-scm.com/) client is used to generate version identifier if project files are in a git clone
47+
4248
In order to use the software (some call it "firmware"), the following steps are required:
4349

4450
1. Build (the default configuration of) the project.

generate_vcs_identifier.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Adds a CPP definition of a version identifier using version control system.
2+
3+
This script shall be loaded by PlatformIO when building the project.
4+
It is not designed to be run independently.
5+
"""
6+
7+
import subprocess
8+
Import("env")
9+
10+
def get_vcs_id():
11+
vcs_output = subprocess.run(["git", "describe", "--always", "--dirty", "--all"], stdout=subprocess.PIPE, text=True)
12+
vcs_string = vcs_output.stdout.strip()
13+
print ("vcs string: " + vcs_string)
14+
return (vcs_string)
15+
16+
env.Append(CPPDEFINES=[
17+
("VCS_ID", env.StringifyMacro(get_vcs_id())),
18+
])

platformio.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ build_flags =
2121
-DLV_CONF_PATH="${PROJECT_DIR}/lib/3rd_party_adapters/LVGL/lv_conf.h" ; lvgl: use this config file
2222
-DBAUD_RATE=${this.monitor_speed}
2323
monitor_speed = 115200
24+
extra_scripts =
25+
pre:generate_vcs_identifier.py
2426

2527
[env:native]
2628
platform = native

0 commit comments

Comments
 (0)