Mercurial > hg > sv-dependency-builds
comparison src/serd-0.18.2/wscript @ 0:c7265573341e
Import initial set of sources
author | Chris Cannam |
---|---|
date | Mon, 18 Mar 2013 14:12:14 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c7265573341e |
---|---|
1 #!/usr/bin/env python | |
2 import glob | |
3 import os | |
4 import shutil | |
5 import subprocess | |
6 import waflib.Logs as Logs | |
7 import waflib.Options as Options | |
8 import waflib.extras.autowaf as autowaf | |
9 | |
10 # Library and package version (UNIX style major, minor, micro) | |
11 # major increment <=> incompatible changes | |
12 # minor increment <=> compatible changes (additions) | |
13 # micro increment <=> no interface changes | |
14 SERD_VERSION = '0.18.2' | |
15 SERD_MAJOR_VERSION = '0' | |
16 | |
17 # Mandatory waf variables | |
18 APPNAME = 'serd' # Package name for waf dist | |
19 VERSION = SERD_VERSION # Package version for waf dist | |
20 top = '.' # Source directory | |
21 out = 'build' # Build directory | |
22 | |
23 def options(opt): | |
24 opt.load('compiler_c') | |
25 autowaf.set_options(opt) | |
26 opt.add_option('--no-utils', action='store_true', dest='no_utils', | |
27 help='Do not build command line utilities') | |
28 opt.add_option('--test', action='store_true', dest='build_tests', | |
29 help='Build unit tests') | |
30 opt.add_option('--stack-check', action='store_true', dest='stack_check', | |
31 help='Include runtime stack sanity checks') | |
32 opt.add_option('--static', action='store_true', dest='static', | |
33 help='Build static library') | |
34 opt.add_option('--no-shared', action='store_true', dest='no_shared', | |
35 help='Do not build shared library') | |
36 opt.add_option('--static-progs', action='store_true', dest='static_progs', | |
37 help='Build programs as static binaries') | |
38 opt.add_option('--largefile', action='store_true', dest='largefile', | |
39 help='Build with large file support on 32-bit systems') | |
40 | |
41 def configure(conf): | |
42 conf.load('compiler_c') | |
43 autowaf.configure(conf) | |
44 autowaf.set_c99_mode(conf) | |
45 autowaf.display_header('Serd Configuration') | |
46 | |
47 conf.env.BUILD_TESTS = Options.options.build_tests | |
48 conf.env.BUILD_UTILS = not Options.options.no_utils | |
49 conf.env.BUILD_SHARED = not Options.options.no_shared | |
50 conf.env.STATIC_PROGS = Options.options.static_progs | |
51 conf.env.BUILD_STATIC = (Options.options.static or | |
52 Options.options.static_progs) | |
53 | |
54 if not conf.env.BUILD_SHARED and not conf.env.BUILD_STATIC: | |
55 conf.fatal('Neither a shared nor a static build requested') | |
56 | |
57 if Options.options.stack_check: | |
58 autowaf.define(conf, 'SERD_STACK_CHECK', SERD_VERSION) | |
59 | |
60 if Options.options.largefile: | |
61 conf.env.append_unique('DEFINES', ['_FILE_OFFSET_BITS=64']) | |
62 | |
63 if conf.env.BUILD_TESTS: | |
64 conf.check(lib = 'gcov', | |
65 define_name = 'HAVE_GCOV', | |
66 mandatory = False) | |
67 | |
68 conf.check(function_name = 'fmax', | |
69 header_name = 'math.h', | |
70 define_name = 'HAVE_FMAX', | |
71 lib = ['m'], | |
72 mandatory = False) | |
73 | |
74 conf.check(function_name = 'posix_memalign', | |
75 header_name = 'stdlib.h', | |
76 define_name = 'HAVE_POSIX_MEMALIGN', | |
77 defines = ['_POSIX_C_SOURCE=201112L'], | |
78 mandatory = False) | |
79 | |
80 conf.check(function_name = 'posix_fadvise', | |
81 header_name = 'fcntl.h', | |
82 define_name = 'HAVE_POSIX_FADVISE', | |
83 defines = ['_POSIX_C_SOURCE=201112L'], | |
84 mandatory = False) | |
85 | |
86 conf.check(function_name = 'fileno', | |
87 header_name = 'stdio.h', | |
88 define_name = 'HAVE_FILENO', | |
89 defines = ['_POSIX_C_SOURCE=201112L'], | |
90 mandatory = False) | |
91 | |
92 autowaf.define(conf, 'SERD_VERSION', SERD_VERSION) | |
93 autowaf.set_lib_env(conf, 'serd', SERD_VERSION) | |
94 conf.write_config_header('serd_config.h', remove=False) | |
95 | |
96 autowaf.display_msg(conf, 'Utilities', str(conf.env.BUILD_UTILS)) | |
97 autowaf.display_msg(conf, 'Unit tests', str(conf.env.BUILD_TESTS)) | |
98 print('') | |
99 | |
100 lib_source = [ | |
101 'src/env.c', | |
102 'src/node.c', | |
103 'src/reader.c', | |
104 'src/string.c', | |
105 'src/uri.c', | |
106 'src/writer.c', | |
107 ] | |
108 | |
109 def build(bld): | |
110 # C Headers | |
111 includedir = '${INCLUDEDIR}/serd-%s/serd' % SERD_MAJOR_VERSION | |
112 bld.install_files(includedir, bld.path.ant_glob('serd/*.h')) | |
113 | |
114 # Pkgconfig file | |
115 autowaf.build_pc(bld, 'SERD', SERD_VERSION, SERD_MAJOR_VERSION, [], | |
116 {'SERD_MAJOR_VERSION' : SERD_MAJOR_VERSION}) | |
117 | |
118 libflags = ['-fvisibility=hidden'] | |
119 libs = ['m'] | |
120 defines = [] | |
121 if bld.env.MSVC_COMPILER: | |
122 libflags = [] | |
123 libs = [] | |
124 defines = ['snprintf=_snprintf'] | |
125 | |
126 # Shared Library | |
127 if bld.env.BUILD_SHARED: | |
128 bld(features = 'c cshlib', | |
129 export_includes = ['.'], | |
130 source = lib_source, | |
131 includes = ['.', './src'], | |
132 lib = libs, | |
133 name = 'libserd', | |
134 target = 'serd-%s' % SERD_MAJOR_VERSION, | |
135 vnum = SERD_VERSION, | |
136 install_path = '${LIBDIR}', | |
137 defines = defines + ['SERD_SHARED', 'SERD_INTERNAL'], | |
138 cflags = libflags) | |
139 | |
140 # Static library | |
141 if bld.env.BUILD_STATIC: | |
142 bld(features = 'c cstlib', | |
143 export_includes = ['.'], | |
144 source = lib_source, | |
145 includes = ['.', './src'], | |
146 lib = libs, | |
147 name = 'libserd_static', | |
148 target = 'serd-%s' % SERD_MAJOR_VERSION, | |
149 vnum = SERD_VERSION, | |
150 install_path = '${LIBDIR}', | |
151 defines = defines + ['SERD_INTERNAL']) | |
152 | |
153 if bld.env.BUILD_TESTS: | |
154 test_libs = libs | |
155 test_cflags = [''] | |
156 if bld.is_defined('HAVE_GCOV'): | |
157 test_libs += ['gcov'] | |
158 test_cflags += ['-fprofile-arcs', '-ftest-coverage'] | |
159 | |
160 # Profiled static library for test coverage | |
161 bld(features = 'c cstlib', | |
162 source = lib_source, | |
163 includes = ['.', './src'], | |
164 lib = test_libs, | |
165 name = 'libserd_profiled', | |
166 target = 'serd_profiled', | |
167 install_path = '', | |
168 defines = defines + ['SERD_INTERNAL'], | |
169 cflags = test_cflags) | |
170 | |
171 # Static profiled serdi for tests | |
172 bld(features = 'c cprogram', | |
173 source = 'src/serdi.c', | |
174 includes = ['.', './src'], | |
175 use = 'libserd_profiled', | |
176 lib = test_libs, | |
177 target = 'serdi_static', | |
178 install_path = '', | |
179 defines = defines, | |
180 cflags = test_cflags) | |
181 | |
182 # Unit test program | |
183 bld(features = 'c cprogram', | |
184 source = 'tests/serd_test.c', | |
185 includes = ['.', './src'], | |
186 use = 'libserd_profiled', | |
187 lib = test_libs, | |
188 target = 'serd_test', | |
189 install_path = '', | |
190 defines = defines, | |
191 cflags = test_cflags) | |
192 | |
193 # Utilities | |
194 if bld.env.BUILD_UTILS: | |
195 obj = bld(features = 'c cprogram', | |
196 source = 'src/serdi.c', | |
197 target = 'serdi', | |
198 includes = ['.', './src'], | |
199 use = 'libserd', | |
200 lib = libs, | |
201 install_path = '${BINDIR}') | |
202 if not bld.env.BUILD_SHARED or bld.env.STATIC_PROGS: | |
203 obj.use = 'libserd_static' | |
204 if bld.env.STATIC_PROGS: | |
205 obj.env.SHLIB_MARKER = obj.env.STLIB_MARKER | |
206 obj.linkflags = ['-static'] | |
207 | |
208 # Documentation | |
209 autowaf.build_dox(bld, 'SERD', SERD_VERSION, top, out) | |
210 | |
211 # Man page | |
212 bld.install_files('${MANDIR}/man1', 'doc/serdi.1') | |
213 | |
214 bld.add_post_fun(autowaf.run_ldconfig) | |
215 if bld.env.DOCS: | |
216 bld.add_post_fun(fix_docs) | |
217 | |
218 def lint(ctx): | |
219 subprocess.call('cpplint.py --filter=+whitespace/comments,-whitespace/tab,-whitespace/braces,-whitespace/labels,-build/header_guard,-readability/casting,-readability/todo,-build/include src/* serd/*', shell=True) | |
220 | |
221 def amalgamate(ctx): | |
222 shutil.copy('serd/serd.h', 'build/serd.h') | |
223 amalgamation = open('build/serd.c', 'w') | |
224 | |
225 serd_internal_h = open('src/serd_internal.h') | |
226 for l in serd_internal_h: | |
227 if l == '#include "serd/serd.h"\n': | |
228 amalgamation.write('#include "serd.h"\n') | |
229 else: | |
230 amalgamation.write(l) | |
231 serd_internal_h.close() | |
232 | |
233 for f in lib_source: | |
234 fd = open(f) | |
235 amalgamation.write('\n/**\n @file %s\n*/' % f) | |
236 header = True | |
237 for l in fd: | |
238 if header: | |
239 if l == '*/\n': | |
240 header = False | |
241 else: | |
242 if l != '#include "serd_internal.h"\n': | |
243 amalgamation.write(l) | |
244 fd.close() | |
245 amalgamation.close() | |
246 | |
247 for i in ['c', 'h']: | |
248 Logs.info('Wrote build/serd.%s' % i) | |
249 | |
250 def fix_docs(ctx): | |
251 if ctx.cmd == 'build': | |
252 autowaf.make_simple_dox(APPNAME) | |
253 | |
254 def upload_docs(ctx): | |
255 os.system('rsync -ravz --delete -e ssh build/doc/html/ drobilla@drobilla.net:~/drobilla.net/docs/serd/') | |
256 | |
257 def file_equals(patha, pathb, subst_from='', subst_to=''): | |
258 fa = open(patha, 'rU') | |
259 fb = open(pathb, 'rU') | |
260 for line in fa: | |
261 if line.replace(subst_from, subst_to) != fb.readline().replace(subst_from, subst_to): | |
262 return False | |
263 fa.close() | |
264 fb.close() | |
265 return True | |
266 | |
267 def test(ctx): | |
268 blddir = autowaf.build_dir(APPNAME, 'tests') | |
269 try: | |
270 os.makedirs(blddir) | |
271 except: | |
272 pass | |
273 | |
274 for i in glob.glob(blddir + '/*.*'): | |
275 os.remove(i) | |
276 | |
277 srcdir = ctx.path.abspath() | |
278 orig_dir = os.path.abspath(os.curdir) | |
279 | |
280 os.chdir(srcdir) | |
281 | |
282 good_tests = glob.glob('tests/test-*.ttl') | |
283 good_tests.sort() | |
284 | |
285 bad_tests = glob.glob('tests/bad-*.ttl') | |
286 bad_tests.sort() | |
287 | |
288 os.chdir(orig_dir) | |
289 | |
290 autowaf.pre_test(ctx, APPNAME) | |
291 | |
292 os.environ['PATH'] = '.' + os.pathsep + os.getenv('PATH') | |
293 | |
294 autowaf.run_tests(ctx, APPNAME, ['serd_test'], dirs=['.']) | |
295 | |
296 autowaf.run_tests(ctx, APPNAME, [ | |
297 'serdi_static -o turtle %s/tests/base.ttl "base.ttl" > tests/base.ttl.out' % srcdir], | |
298 0, name='base') | |
299 | |
300 if not file_equals('%s/tests/base.ttl' % srcdir, 'tests/base.ttl.out'): | |
301 Logs.pprint('RED', 'FAIL: build/tests/base.ttl.out is incorrect') | |
302 | |
303 nul = os.devnull | |
304 autowaf.run_tests(ctx, APPNAME, [ | |
305 'serdi_static file://%s/tests/manifest.ttl > %s' % (srcdir, nul), | |
306 'serdi_static %s/tests/UTF-8.ttl > %s' % (srcdir, nul), | |
307 'serdi_static -v > %s' % nul, | |
308 'serdi_static -h > %s' % nul, | |
309 'serdi_static -s "<foo> a <#Thingie> ." > %s' % nul, | |
310 'serdi_static %s > %s' % (nul, nul)], | |
311 0, name='serdi-cmd-good') | |
312 | |
313 autowaf.run_tests(ctx, APPNAME, [ | |
314 'serdi_static -q file://%s/tests/bad-id-clash.ttl > %s' % (srcdir, nul), | |
315 'serdi_static > %s' % nul, | |
316 'serdi_static ftp://example.org/unsupported.ttl > %s' % nul, | |
317 'serdi_static -i > %s' % nul, | |
318 'serdi_static -o > %s' % nul, | |
319 'serdi_static -z > %s' % nul, | |
320 'serdi_static -p > %s' % nul, | |
321 'serdi_static -c > %s' % nul, | |
322 'serdi_static -r > %s' % nul, | |
323 'serdi_static -i illegal > %s' % nul, | |
324 'serdi_static -o illegal > %s' % nul, | |
325 'serdi_static -i turtle > %s' % nul, | |
326 'serdi_static /no/such/file > %s' % nul], | |
327 1, name='serdi-cmd-bad') | |
328 | |
329 commands = [] | |
330 for test in good_tests: | |
331 base_uri = 'http://www.w3.org/2001/sw/DataAccess/df1/' + test.replace('\\', '/') | |
332 commands += [ 'serdi_static -f "%s" "%s" > %s.out' % ( | |
333 os.path.join(srcdir, test), base_uri, test) ] | |
334 | |
335 autowaf.run_tests(ctx, APPNAME, commands, 0, name='good') | |
336 | |
337 Logs.pprint('BOLD', '\nVerifying turtle => ntriples') | |
338 for test in good_tests: | |
339 out_filename = test + '.out' | |
340 if not os.access(out_filename, os.F_OK): | |
341 Logs.pprint('RED', 'FAIL: %s output is missing' % test) | |
342 elif not file_equals(srcdir + '/' + test.replace('.ttl', '.out'), | |
343 test + '.out'): | |
344 Logs.pprint('RED', 'FAIL: %s is incorrect' % out_filename) | |
345 else: | |
346 Logs.pprint('GREEN', 'Pass: %s' % test) | |
347 | |
348 commands = [] | |
349 for test in bad_tests: | |
350 commands += [ 'serdi_static "%s" "http://www.w3.org/2001/sw/DataAccess/df1/%s" > %s.out' % (os.path.join(srcdir, test), test.replace('\\', '/'), test) ] | |
351 | |
352 autowaf.run_tests(ctx, APPNAME, commands, 1, name='bad') | |
353 | |
354 thru_tests = good_tests | |
355 thru_tests.remove(os.path.join('tests', 'test-id.ttl')) # IDs are mapped so files won't be identical | |
356 | |
357 commands = [] | |
358 num = 0 | |
359 for test in thru_tests: | |
360 num += 1 | |
361 flags = '' | |
362 if (num % 2 == 0): | |
363 flags += '-b' | |
364 if (num % 5 == 0): | |
365 flags += ' -f' | |
366 if (num % 3 == 0): | |
367 flags += ' -r http://www.w3.org/' | |
368 if (num % 7 == 0): | |
369 flags += ' -e' | |
370 base_uri = 'http://www.w3.org/2001/sw/DataAccess/df1/' + test.replace('\\', '/') | |
371 out_filename = test + '.thru' | |
372 commands += [ | |
373 '%s %s -i ntriples -o turtle -p foo "%s" "%s" | %s -i turtle -o ntriples -c foo - "%s" > %s.thru' % ( | |
374 'serdi_static', flags.ljust(5), | |
375 os.path.join(srcdir, test), base_uri, | |
376 'serdi_static', base_uri, test) ] | |
377 | |
378 autowaf.run_tests(ctx, APPNAME, commands, 0, name='turtle-round-trip') | |
379 Logs.pprint('BOLD', '\nVerifying ntriples => turtle => ntriples') | |
380 for test in thru_tests: | |
381 out_filename = test + '.thru' | |
382 if not os.access(out_filename, os.F_OK): | |
383 Logs.pprint('RED', 'FAIL: %s output is missing' % test) | |
384 elif not file_equals(srcdir + '/' + test.replace('.ttl', '.out'), | |
385 test + '.thru', | |
386 '_:docid', '_:genid'): | |
387 Logs.pprint('RED', 'FAIL: %s is incorrect' % out_filename) | |
388 else: | |
389 Logs.pprint('GREEN', 'Pass: %s' % test) | |
390 | |
391 autowaf.post_test(ctx, APPNAME) |