forked from libswift/libswift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svn-build-rev.py
44 lines (37 loc) · 1.16 KB
/
svn-build-rev.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
import sys
import subprocess
import time
argstr = "svn info"
pobj = subprocess.Popen(argstr,stdout=subprocess.PIPE,cwd='.',shell=True)
count = 0.0
while count < 10.0: # 10 seconds
pobj.poll()
if pobj.returncode is not None:
break
time.sleep(1)
count += 1.0
revstr = pobj.stdout.read()
if len(revstr) == 0:
print >>sys.stderr,"Error getting svn revision"
else:
urlprefix = "URL: "
sidx = revstr.find(urlprefix)
if sidx == -1:
print >>sys.stderr,"Error getting svn revision, no URL"
os._exit(-1)
eidx = revstr.find("\n",sidx)
url = revstr[sidx+len(urlprefix):eidx].rstrip()
revprefix = "Revision: "
sidx = revstr.find(revprefix)
if sidx == -1:
print >>sys.stderr,"Error getting svn revision, no Revision"
os._exit(-1)
eidx = revstr.find("\n",sidx)
rev = revstr[sidx+len(revprefix):eidx].rstrip()
urlrev = url+"@"+rev
f = open("svn-revision.h","w")
f.write("std::string SubversionRevisionString = \"")
f.write(urlrev)
f.write("\";")
f.close()
print >>sys.stderr,"Wrote svn revision to svn-revision.h"