-
Notifications
You must be signed in to change notification settings - Fork 4
/
wscript
277 lines (248 loc) · 10.2 KB
/
wscript
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#! /usr/bin/env python
# encoding: utf-8
#
# Copyright (C) 2011-2022 the SciSQL authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Authors:
# - Serge Monkewitz, IPAC/Caltech
#
# Work on this project has been sponsored by LSST and SLAC/DOE.
#
from __future__ import with_statement
import os
import stat
import sys
import traceback
from waflib import Build, Logs, Utils
_have_mako = True
try:
import mako.template
import mako.lookup
except:
_have_mako = False
APPNAME = 'scisql'
VERSION = '0.3'
top = '.'
out = 'build'
BUILD_CONST_MODULE='const.py'
def options(ctx):
ctx.add_option('--client-only', dest='client_only', action='store_true',
default=False, help='Build client utilities only')
ctx.add_option('--scisql-prefix', dest='scisql_prefix', default='scisql_',
help='UDF/stored procedure name prefix (defaulting to %default). ' +
'An empty string means: do not prefix.')
ctx.load('compiler_c')
ctx.load('mysql_waf', tooldir='tools')
def configure(ctx):
ctx.env.SCISQL_CLIENT_ONLY = ctx.options.client_only
ctx.env.SCISQL_VERSION = VERSION
ctx.load('compiler_c')
if not ctx.options.client_only:
ctx.load('mysql_waf', tooldir='tools')
ctx.check_mysql()
ctx.define('SCISQL_PREFIX', ctx.options.scisql_prefix, quote=False)
ctx.env.SCISQL_PREFIX = ctx.options.scisql_prefix
ctx.env['CFLAGS'] = ['-Wall',
'-Wextra',
'-O3'
]
# Test for __attribute__ support
ctx.check_cc(fragment='''__attribute__ ((visibility("default"))) int foo() { return 0; }
__attribute__ ((visibility("hidden"))) int bar() { return 0; }
int main() { return foo() + bar(); }''',
define_name='HAVE_ATTRIBUTE_VISIBILITY',
execute=True,
mandatory=False,
msg='Checking for __attribute__ ((visibility()))')
ctx.check_cc(fragment='''void foo(int x __attribute__ ((unused))) { }
__attribute__ ((unused)) void bar() { }
int main() { return 0; }''',
define_name='HAVE_ATTRIBUTE_UNUSED',
mandatory=False,
msg='Checking for __attribute__ ((unused))')
ctx.check_cc(fragment='''typedef struct { double a; double b; } test __attribute__ ((aligned(16)));
int main() { return 0; }''',
define_name='HAVE_ATTRIBUTE_ALIGNED',
mandatory=False,
msg='Checking for __attribute__ ((aligned()))')
# Check endianness of platform
ctx.check_cc(fragment='''union { int val; unsigned char bytes[sizeof(int)]; } u;
int main() {
u.val = 0x0201;
return u.bytes[0] != 0x01;
}''',
define_name='IS_LITTLE_ENDIAN',
execute=True,
mandatory=False,
okmsg='ok',
msg='Checking byte order')
# Check for libm
ctx.check_cc(lib='m', uselib_store='M')
# Add scisql version to configuration header
ctx.define(APPNAME.upper() + '_VERSION_STRING', VERSION)
ctx.define(APPNAME.upper() + '_VERSION_STRING_LENGTH', len(VERSION))
versions = [int(v) for v in VERSION.split('.')]
if len(versions) < 3:
versions.extend([0]*(3 - len(versions)))
for v, n in zip(versions, ('MAJOR', 'MINOR', 'PATCH')):
ctx.define(APPNAME.upper() + '_VERSION_' + n, v)
ctx.define(APPNAME.upper() + '_VERSION_NUM',
versions[0]*100**2 + versions[1]*100 + versions[2])
ctx.env.SCISQL_VSUFFIX = '_' + '_'.join(map(str, versions))
ctx.env.SCISQL_LIBNAME = ctx.env['cshlib_PATTERN'] % ('scisql-' + ctx.env.SCISQL_PREFIX + VERSION)
ctx.define('SCISQL_VSUFFIX', ctx.env.SCISQL_VSUFFIX, quote=False)
ctx.write_config_header('src/config.h')
# Create run-time environment for tasks
env = os.environ.copy()
env['SCISQL_PREFIX'] = ctx.env.SCISQL_PREFIX
env['SCISQL_VERSION'] = VERSION
env['SCISQL_VSUFFIX'] = ctx.env.SCISQL_VSUFFIX
env['SCISQL_LIBNAME'] = ctx.env.SCISQL_LIBNAME
ctx.env.env = env
if not ctx.options.client_only:
ctx.start_msg('Writing build parameters')
dest = ctx.bldnode.make_node(BUILD_CONST_MODULE)
dest.parent.mkdir()
dest.write(
"SCISQL_PREFIX = \"{0}\"\n".format(ctx.env.SCISQL_PREFIX) +
"SCISQL_VERSION = \"{0}\"\n".format(ctx.env.SCISQL_VERSION) +
"SCISQL_VSUFFIX = \"{0}\"\n".format(ctx.env.SCISQL_VSUFFIX) +
"SCISQL_LIBNAME = \"{0}\"\n".format(ctx.env.SCISQL_LIBNAME)
)
ctx.env.append_value('cfg_files', dest.abspath())
ctx.end_msg(BUILD_CONST_MODULE)
def build(ctx):
# UDF shared library
if not ctx.env.SCISQL_CLIENT_ONLY:
libname='scisql-' + ctx.env.SCISQL_PREFIX + VERSION
ctx.shlib(
source=ctx.path.ant_glob('src/*.c') +
ctx.path.ant_glob('src/udfs/*.c'),
includes='src',
target=libname,
name='scisql',
use='MYSQL M',
install_path=os.path.join(ctx.env.PREFIX, 'lib')
)
# Off-line spatial indexing tool
ctx.program(
source='src/util/index.c src/geometry.c src/htm.c',
includes='src',
target='scisql_index',
install_path=os.path.join(ctx.env.PREFIX, 'bin'),
use='M'
)
# C test cases, executed in build process, against shared library
ctx.program(
source='test/testSelect.c src/select.c',
includes='src',
target='test/testSelect',
install_path=False,
use='M'
)
ctx.program(
source='test/testHtm.c src/geometry.c src/htm.c',
includes='src',
target='test/testHtm',
install_path=False,
use='M'
)
# docs directory
docs_dir = ctx.path.find_dir('docs')
ctx.install_files('${PREFIX}/docs', docs_dir.ant_glob('**/*'),
cwd=docs_dir, relative_trick=True)
# bin directory
bin_dir = ctx.path.find_dir('bin')
ctx.install_files('${PREFIX}/bin', bin_dir.ant_glob('**/*.py'),
chmod=Utils.O755, cwd=bin_dir, relative_trick=True)
if not ctx.env.SCISQL_CLIENT_ONLY:
# install build configuration module whose parameters will be used by
# deployment script
ctx.install_files('${PREFIX}/python/scisql', BUILD_CONST_MODULE)
# python modules
python_dir = ctx.path.find_dir('python')
ctx.install_files('${PREFIX}/python', python_dir.ant_glob('**/*.py'),
cwd=python_dir, relative_trick=True)
# tools directory
tool_dir = ctx.path.find_dir('tools')
ctx.install_files('${PREFIX}/tools', tool_dir.ant_glob('**/*'),
cwd=tool_dir, relative_trick=True)
# template directory
template_dir = ctx.path.find_dir('templates')
ctx.install_files('${PREFIX}/templates', template_dir.ant_glob('**/*'),
cwd=template_dir, relative_trick=True)
# python tests
test_dir = ctx.path.find_dir('test')
ctx.install_files('${PREFIX}/test', test_dir.ant_glob('**/*.py'),
cwd=test_dir, relative_trick=True)
if ctx.cmd == 'build':
ctx.add_post_fun(test)
class TestContext(Build.BuildContext):
cmd = 'test'
fun = 'test'
class Tests(object):
def __init__(self):
self.unit_tests = []
def utest(self, **kw):
nodes = kw.get('source', [])
if not isinstance(nodes, list):
self.unit_tests.append(nodes)
else:
self.unit_tests.extend(nodes)
def run(self, ctx):
nok, nfail, nexcept = (0, 0, 0)
for utest in self.unit_tests:
msg = 'Running %s' % utest
msg += ' ' * max(0, 40 - len(msg))
Logs.pprint('CYAN', msg, sep=': ')
out = utest.change_ext('.log')
with open(out.abspath(), 'wb') as f:
try:
proc = Utils.subprocess.Popen([utest.abspath()],
shell=False, env=ctx.env.env or None,
stderr=f, stdout=f)
proc.communicate()
except:
nexcept += 1
ex_type, ex_val, _ = sys.exc_info()
msg = traceback.format_exception_only(ex_type, ex_val)[-1].strip()
Logs.pprint('RED', msg)
else:
if proc.returncode != 0:
nfail += 1
Logs.pprint('YELLOW', 'FAIL [see %s]' % out.abspath())
else:
nok += 1
Logs.pprint('CYAN', 'OK')
if nfail == 0 and nexcept == 0:
Logs.pprint('CYAN', '\nAll %d tests passed!\n' % nok)
else:
Logs.pprint('YELLOW', '\n%d tests passed, %d failed, and %d failed to run\n' %
(nok, nfail, nexcept))
ctx.fatal('One or more sciSQL unit tests failed')
def test(ctx):
tests = Tests()
tests.utest(source=ctx.path.get_bld().make_node('test/testHtm'))
tests.utest(source=ctx.path.get_bld().make_node('test/testSelect'))
tests.run(ctx)
class HtmlDocsContext(Build.BuildContext):
cmd = 'html_docs'
fun = 'html_docs'
def html_docs(ctx):
if not _have_mako:
ctx.fatal('You must install mako 0.4+ to generate HTML documentation')
ctx(rule='${SRC} html_docs',
source='tools/docs.py',
always=True)