Skip to content

Commit c8d927f

Browse files
committed
Added versioning and script to read the version and hash version.h
1 parent 3837ff1 commit c8d927f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

scripts/generate_version_header.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# generate_version_header.py
2+
import subprocess
3+
4+
def get_git_tag():
5+
try:
6+
return subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]).strip().decode()
7+
except subprocess.CalledProcessError:
8+
return "unknown"
9+
10+
def get_git_commit_hash():
11+
try:
12+
return subprocess.check_output(["git", "rev-parse", "HEAD"]).strip().decode()
13+
except subprocess.CalledProcessError:
14+
return "unknown"
15+
16+
def main():
17+
tag = get_git_tag()
18+
commit_hash = get_git_commit_hash()
19+
20+
with open("version.h", "w") as f:
21+
f.write("#ifndef VERSION_H\n")
22+
f.write("#define VERSION_H\n")
23+
f.write(f'#define GIT_TAG "{tag}"\n')
24+
f.write(f'#define GIT_COMMIT_HASH "{commit_hash}"\n')
25+
f.write("#endif // VERSION_H\n")
26+
27+
if __name__ == "__main__":
28+
main()

0 commit comments

Comments
 (0)