|
4 | 4 | strfile = "" |
5 | 5 |
|
6 | 6 | try: |
7 | | - fvers = open(sys.argv[1],'r') |
| 7 | + fvers = open(sys.argv[1], "r") |
8 | 8 | strfile = fvers.read() |
9 | 9 | fvers.close() |
10 | | -except : |
| 10 | +except: |
11 | 11 | None |
12 | 12 |
|
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 |
30 | 34 | str_ += r')%%";' |
31 | 35 | str_ += "\n\n" |
32 | 36 |
|
33 | | -str_ += "const std::string git_commit_hash = \""+git_hash+"\";\n" |
| 37 | +str_ += 'const std::string git_commit_hash = "' + git_hash + '";\n' |
34 | 38 |
|
35 | | -str_ += "const std::string compile_arg = \""+sys.argv[2]+"\";\n" |
| 39 | +str_ += 'const std::string compile_arg = "' + sys.argv[2] + '";\n' |
36 | 40 |
|
37 | | -str_ += "const std::string version_string = \""+sys.argv[3]+"\";\n" |
| 41 | +str_ += 'const std::string version_string = "' + sys.argv[3] + '";\n' |
38 | 42 |
|
| 43 | +str_ += "const bool is_git = " + str(is_git) + ";\n" |
39 | 44 |
|
40 | 45 | if not (strfile == str_): |
41 | | - f = open(sys.argv[1],'w') |
| 46 | + f = open(sys.argv[1], "w") |
42 | 47 | f.write(str_) |
43 | 48 | f.close() |
44 | 49 |
|
|
0 commit comments