File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments