forked from casacore/casarest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
batchbuild.py
executable file
·97 lines (90 loc) · 2.45 KB
/
batchbuild.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
import sys
import os
import re
deps = {'graphics' : None,
'msvis' : None,
'flagging' : ['msvis'],
'calibration': ['msvis'],
'synthesis': ['calibration'],
'simulators': None
}
def get_libs(pkg):
if pkg not in deps.keys():
return
pkgs = [pkg]
def getpkg(pkg, pgs):
plist = deps.get(pkg)
if plist is None: return
for p in plist:
pgs.insert(0, p)
getpkg(p, pgs)
getpkg(pkg, pkgs)
outpkgs = []
# strip off duplicates
for i in pkgs:
if i not in outpkgs:
outpkgs.append(i)
return outpkgs
def run_scons(targets, args=[]):
cwd = os.getcwd()
for target in targets:
os.chdir(target)
command = "scons " #+ os.path.basename(target)
# copy the command line args into the new command
pfx = None
tests = False
for arg in args:
command += " " + arg
if arg.startswith("prefix"):
pfx = arg.split("=")[-1]
print "Building package: " + target
sys.stdout.flush()
print command
try:
failed = os.system(command)
except KeyboardInterrupt:
sys.exit()
if failed:
sys.exit(failed)
sys.stdout.flush()
os.chdir(cwd)
args = sys.argv[1:]
if "-h" not in args:
if "doc" in args:
os.system("doxygen doxygen.cfg")
sys.exit(0)
if "install" not in args:
if "-c" not in args and "test" not in args:
args.append("install")
pth = "./stage"
if not os.path.exists(pth):
os.mkdir(pth)
for a in args:
if a.startswith("prefix="):
args.remove(a)
if a.startswith("casarestroot="):
args.remove(a)
args.append("prefix=%s" % os.path.abspath(pth))
args.append("casarestroot=%s" % os.path.abspath(pth))
else:
hasprefix = False
for a in args:
hasprefix = a.startswith("prefix=")
if hasprefix:
args.append(a.replace("prefix", "casarestroot"))
break
if not hasprefix:
args.append("casarestroot=/usr/local")
# build all by default
##tobuild = ['tableplot', 'msvis', 'flagging', 'calibration', 'synthesis', 'simulators']
tobuild = ['msvis', 'flagging', 'calibration', 'simulators', 'synthesis']
for k in deps.keys():
k = k.rstrip("/")
if k in args:
tobuild = get_libs(k)
args.remove(k)
if "-c" in args or "--clean" in args:
# clean up highest level package first
tobuild.reverse()
run_scons(tobuild, args)