-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_package.py
executable file
·172 lines (127 loc) · 4.27 KB
/
create_package.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# -*- python -*-
import os
import sys
import subprocess
def run(cmd):
print "running:"
print cmd
print "--------------"
theproc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out = theproc.stdout.read()
theproc.stdout.close()
return out
def build_package(home, package, dep='', lib=False):
if os.path.exists(home + '/' + package):
import shutil
shutil.rmtree(home + '/' + package)
os.mkdir(home + '/' + package)
for b in ('include', 'src', 'lib', 'tests', 'ups'):
os.mkdir(home + '/' + package + '/' + b)
with open(home + '/' + package + '/SConstruct', 'w') as f:
f.write('''# -*- python -*-
from lsst.sconsUtils import scripts
scripts.BasicSConstruct("%s")
''' % package)
with open(home + '/' + package + '/ups/%s.build' % package, 'w') as f:
f.write('''@LSST BUILD@
build_lsst @PRODUCT@ @VERSION@ @REPOVERSION@
''')
required = ""
if dep != "":
required = '"%s"' % dep
with open(home + '/' + package + '/ups/%s.cfg' % package, 'w') as f:
f.write('''# -*- python -*-
import lsst.sconsUtils
# Dependencies that provide heard files and or libraries should be included here.
# Pure-Python dependencies do not need to be included.
# Packages that use swig or boost_tests should declare them as build dependencies.
# Otherwise, the rules for which packages to list here are the same as those for
# table files.
dependencies = {
"required": [%s],
}
# For packages that build a C++ library and a SWIG module, the below should be sufficient.
# Pure-Python packages should set headers=[], libs=[] (not libs=None). and hasSwigFiles=False.
# For more information, see the sconsUtils Doxygen documentation.
config = lsst.sconsUtils.Configuration(
__file__,
hasDoxygenInclude=False,
hasSwigFiles=False,
)
''' % required)
required = ''
if dep != '':
required = 'setupRequired(%s)' % dep
with open(home + '/' + package + '/ups/%s.table' % package, 'w') as f:
f.write('''%s
envPrepend(LD_LIBRARY_PATH, ${PRODUCT_DIR}/lib)
envPrepend(DYLD_LIBRARY_PATH, ${PRODUCT_DIR}/lib)
envPrepend(PYTHONPATH, ${PRODUCT_DIR}/python)
envAppend(PATH, ${PRODUCT_DIR}/bin)
''' % required)
with open(home + '/' + package + '/tests/SConscript', 'w') as f:
f.write('''# -*- python -*-
from lsst.sconsUtils import scripts
scripts.BasicSConscript.tests()
''')
decl = ''
call = ''
if dep != '':
decl = 'void a();'
call = ' a();'
with open(home + '/' + package + '/tests/hello.cc', 'w') as f:
f.write('''#include <iostream>
%s
int main ()
{
std::cout << "hello world" << std::endl;
%s
}
''' % (decl, call))
if lib:
with open(home + '/' + package + '/lib/a.cc', 'w') as f:
f.write('''#include <iostream>
void a ()
{
std::cout << "a" << std::endl;
}
''')
with open(home + '/' + package + '/lib/SConscript', 'w') as f:
f.write('''# -*- python -*-
from lsst.sconsUtils import scripts, targets, env
objs = env.SourcesForSharedLibrary(Glob("#lib/*.cc"))
targets["lib"].extend(env.SharedLibrary(env["packageName"], objs, LIBS=env.getLibs("self")))
''')
def declare(home, package, version):
print run('''
source %(stack)s/loadLSST.bash;
echo "======= eups path"
export EUPS_PATH=%(home)s:$EUPS_PATH;
eups path;
eups declare --nolocks -v -F -r %(home)s/%(package)s %(package)s %(version)s;
eups list -D %(package)s;
pwd''' % {'stack':stack, 'home':home, 'package':package, 'version':version})
def undeclare(home, package, version):
print run('''
source %(stack)s/loadLSST.bash;
export EUPS_PATH=%(home)s:$EUPS_PATH;
unsetup $(package)s;
eups undeclare --nolocks -F %(package)s %(version)s;
echo "======= end";
pwd''' % {'stack':stack, 'home':home, 'package':package, 'version':version})
if __name__ == '__main__':
print ' '.join(sys.argv)
if len(sys.argv) <= 1:
print 'Give the name of the package'
exit()
stack = '/sps/lsst/Library/stack_v11_0'
home = os.getcwd()
package = sys.argv[1]
dep = ''
if len(sys.argv) > 2:
dep = sys.argv[2]
version = '1.0'
if not os.path.exists(home + '/ups_db'):
os.mkdir(home + '/ups_db')
build_package(home, package, lib=True, dep=dep)
declare(home, package, '1.0')