Skip to content

Commit 4a9d132

Browse files
committed
fix version file ouside of git
1 parent c01b9bb commit 4a9d132

1 file changed

Lines changed: 28 additions & 23 deletions

File tree

buildbot/make_version_file.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,46 @@
44
strfile = ""
55

66
try:
7-
fvers = open(sys.argv[1],'r')
7+
fvers = open(sys.argv[1], "r")
88
strfile = fvers.read()
99
fvers.close()
10-
except :
10+
except:
1111
None
1212

13-
14-
15-
str_git = os.popen("git log -n 1 --decorate=full").read()
16-
git_hash = str_git.split()[1]
17-
git_head = str_git[str_git.find("HEAD -> ")+8:str_git.find(")")]
18-
19-
20-
21-
str_ = '''
22-
#include "version.hpp"
23-
24-
const std::string git_info_str = R"%%('''
25-
26-
str_ += " commit : "+git_hash+"\n"
27-
str_ += " HEAD : "+git_head+"\n"
28-
str_ += " modified files (since last commit):"+"\n"
29-
str_ += os.popen("git diff-index --name-only HEAD -- | sed \"s/^/ /g\"").read()
13+
try:
14+
str_git = os.popen("git log -n 1 --decorate=full").read()
15+
git_hash = str_git.split()[1]
16+
git_head = str_git[str_git.find("HEAD -> ") + 8 : str_git.find(")")]
17+
git_diffindex = os.popen('git diff-index --name-only HEAD -- | sed "s/^/ /g"').read()
18+
is_git = "true"
19+
except:
20+
git_hash = "unknown"
21+
git_head = "unknown"
22+
git_diffindex = "unknown"
23+
is_git = "false"
24+
25+
str_ = """
26+
#include "shamrock/version.hpp"
27+
28+
const std::string git_info_str = R"%%("""
29+
30+
str_ += " commit : " + git_hash + "\n"
31+
str_ += " HEAD : " + git_head + "\n"
32+
str_ += " modified files (since last commit):" + "\n"
33+
str_ += git_diffindex
3034
str_ += r')%%";'
3135
str_ += "\n\n"
3236

33-
str_ += "const std::string git_commit_hash = \""+git_hash+"\";\n"
37+
str_ += 'const std::string git_commit_hash = "' + git_hash + '";\n'
3438

35-
str_ += "const std::string compile_arg = \""+sys.argv[2]+"\";\n"
39+
str_ += 'const std::string compile_arg = "' + sys.argv[2] + '";\n'
3640

37-
str_ += "const std::string version_string = \""+sys.argv[3]+"\";\n"
41+
str_ += 'const std::string version_string = "' + sys.argv[3] + '";\n'
3842

43+
str_ += "const bool is_git = " + str(is_git) + ";\n"
3944

4045
if not (strfile == str_):
41-
f = open(sys.argv[1],'w')
46+
f = open(sys.argv[1], "w")
4247
f.write(str_)
4348
f.close()
4449

0 commit comments

Comments
 (0)