forked from JeffersonLab/g4sbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pullgitinfo3.py
65 lines (44 loc) · 1.38 KB
/
pullgitinfo3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import sys
import binascii
presentcwd = os.getcwd()
os.chdir(sys.argv[1])
f = os.popen("git log -n 1 && git status -bs && echo \"\nGeant4 version\" `geant4-config --version` && echo \" ROOT version\" `root-config --version` && echo \" `cmake --version`\" && echo \"\nGenerated at `date`\"")
boringstring = "";
fullstring = "";
if( f != 0):
for line in f:
boringstring += line
else:
boringstring = "git information unavailable"
maxlen = 2048
boringstring += "Source dir " + os.getcwd()
boringstring += "\nBuild dir " + presentcwd + "\n"
if len(boringstring) > maxlen:
print("WARNING: Truncating info from git");
boringstring = boringstring[0:maxlen-1]
for x in boringstring:
fullstring += '\\x'+x.encode('utf-8').hex()
newheadertext = """#ifndef __GITINFO_HH
#define __GITINFO_HH
/*
Generated automatically by cmake process
Encoding:
-------------------------------------------------------------
""" + boringstring + """
-------------------------------------------------------------
*/
#define __GITMAXINFO_SIZE 2048
#define gGitInfoStr \"""" + fullstring + '\"' \
+ \
"""
#endif//__GITINFO_HH
"""
os.chdir(presentcwd)
outdir = "include/"
if not os.path.exists(outdir):
os.makedirs(outdir)
newheader = open( outdir + "/gitinfo.hh", "w")
newheader.write(newheadertext)
newheader.close()
print("Repository information\n", boringstring)