comparison src/sord-0.12.0/wscript @ 0:c7265573341e

Import initial set of sources
author Chris Cannam
date Mon, 18 Mar 2013 14:12:14 +0000
parents
children c29fa680fb5a
comparison
equal deleted inserted replaced
-1:000000000000 0:c7265573341e
1 #!/usr/bin/env python
2 import glob
3 import os
4 import subprocess
5 import waflib.Logs as Logs
6 import waflib.Options as Options
7 import waflib.extras.autowaf as autowaf
8
9 # Library and package version (UNIX style major, minor, micro)
10 # major increment <=> incompatible changes
11 # minor increment <=> compatible changes (additions)
12 # micro increment <=> no interface changes
13 SORD_VERSION = '0.12.0'
14 SORD_MAJOR_VERSION = '0'
15
16 # Mandatory waf variables
17 APPNAME = 'sord' # Package name for waf dist
18 VERSION = SORD_VERSION # Package version for waf dist
19 top = '.' # Source directory
20 out = 'build' # Build directory
21
22 def options(opt):
23 opt.load('compiler_c')
24 opt.load('compiler_cxx')
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('--static', action='store_true', dest='static',
31 help='Build static library')
32 opt.add_option('--no-shared', action='store_true', dest='no_shared',
33 help='Do not build shared library')
34 opt.add_option('--static-progs', action='store_true', dest='static_progs',
35 help='Build programs as static binaries')
36 opt.add_option('--dump', type='string', default='', dest='dump',
37 help='Dump debugging output (iter, search, write, all)')
38
39 def configure(conf):
40 conf.load('compiler_c')
41 if Options.options.build_tests:
42 try:
43 conf.load('compiler_cxx')
44 except:
45 Logs.warn("No C++ compiler, sordmm.hpp compile test skipped")
46 pass
47
48 autowaf.configure(conf)
49 autowaf.set_c99_mode(conf)
50 autowaf.display_header('Sord configuration')
51
52 conf.env.BUILD_TESTS = Options.options.build_tests
53 conf.env.BUILD_UTILS = not Options.options.no_utils
54 conf.env.BUILD_SHARED = not Options.options.no_shared
55 conf.env.STATIC_PROGS = Options.options.static_progs
56 conf.env.BUILD_STATIC = (Options.options.static or
57 Options.options.static_progs)
58
59 if conf.env.BUILD_TESTS:
60 conf.check(lib = 'gcov',
61 define_name = 'HAVE_GCOV',
62 mandatory = False)
63
64 autowaf.check_pkg(conf, 'serd-0', uselib_store='SERD',
65 atleast_version='0.18.0', mandatory=True)
66 autowaf.check_pkg(conf, 'libpcre', uselib_store='PCRE', mandatory=False)
67
68 # Parse dump options and define things accordingly
69 dump = Options.options.dump.split(',')
70 all = 'all' in dump
71 if all or 'iter' in dump:
72 autowaf.define(conf, 'SORD_DEBUG_ITER', 1)
73 if all or 'search' in dump:
74 autowaf.define(conf, 'SORD_DEBUG_SEARCH', 1)
75 if all or 'write' in dump:
76 autowaf.define(conf, 'SORD_DEBUG_WRITE', 1)
77
78 autowaf.define(conf, 'SORD_VERSION', SORD_VERSION)
79 autowaf.set_lib_env(conf, 'sord', SORD_VERSION)
80 conf.write_config_header('sord_config.h', remove=False)
81
82 autowaf.display_msg(conf, 'Utilities', bool(conf.env.BUILD_UTILS))
83 autowaf.display_msg(conf, 'Unit tests', bool(conf.env.BUILD_TESTS))
84 autowaf.display_msg(conf, 'Debug dumping', dump)
85 print('')
86
87 def build(bld):
88 # C/C++ Headers
89 includedir = '${INCLUDEDIR}/sord-%s/sord' % SORD_MAJOR_VERSION
90 bld.install_files(includedir, bld.path.ant_glob('sord/*.h'))
91 bld.install_files(includedir, bld.path.ant_glob('sord/*.hpp'))
92
93 # Pkgconfig file
94 autowaf.build_pc(bld, 'SORD', SORD_VERSION, SORD_MAJOR_VERSION, 'SERD',
95 {'SORD_MAJOR_VERSION' : SORD_MAJOR_VERSION})
96
97 source = 'src/sord.c src/syntax.c'
98
99 libflags = ['-fvisibility=hidden']
100 libs = ['m']
101 defines = []
102 if bld.env.MSVC_COMPILER:
103 libflags = []
104 libs = []
105 defines = ['snprintf=_snprintf']
106
107 # Shared Library
108 if bld.env.BUILD_SHARED:
109 obj = bld(features = 'c cshlib',
110 source = source,
111 includes = ['.', './src'],
112 export_includes = ['.'],
113 name = 'libsord',
114 target = 'sord-%s' % SORD_MAJOR_VERSION,
115 vnum = SORD_VERSION,
116 install_path = '${LIBDIR}',
117 libs = libs,
118 defines = defines + ['SORD_SHARED', 'SORD_INTERNAL'],
119 cflags = libflags)
120 autowaf.use_lib(bld, obj, 'SERD')
121
122 # Static Library
123 if bld.env.BUILD_STATIC:
124 obj = bld(features = 'c cstlib',
125 source = source,
126 includes = ['.', './src'],
127 export_includes = ['.'],
128 name = 'libsord_static',
129 target = 'sord-%s' % SORD_MAJOR_VERSION,
130 vnum = SORD_VERSION,
131 install_path = '${LIBDIR}',
132 libs = libs,
133 defines = ['SORD_INTERNAL'])
134 autowaf.use_lib(bld, obj, 'SERD')
135
136 if bld.env.BUILD_TESTS:
137 test_libs = libs
138 test_cflags = ['']
139 if bld.is_defined('HAVE_GCOV'):
140 test_libs += ['gcov']
141 test_cflags += ['-fprofile-arcs', '-ftest-coverage']
142
143 # Profiled static library for test coverage
144 obj = bld(features = 'c cstlib',
145 source = source,
146 includes = ['.', './src'],
147 name = 'libsord_profiled',
148 target = 'sord_profiled',
149 install_path = '',
150 defines = defines,
151 cflags = test_cflags,
152 lib = test_libs)
153 autowaf.use_lib(bld, obj, 'SERD')
154
155 # Unit test program
156 obj = bld(features = 'c cprogram',
157 source = 'src/sord_test.c',
158 includes = ['.', './src'],
159 use = 'libsord_profiled',
160 lib = test_libs,
161 target = 'sord_test',
162 install_path = '',
163 defines = defines,
164 cflags = test_cflags)
165 autowaf.use_lib(bld, obj, 'SERD')
166
167 # Static profiled sordi for tests
168 obj = bld(features = 'c cprogram',
169 source = 'src/sordi.c',
170 includes = ['.', './src'],
171 use = 'libsord_profiled',
172 lib = test_libs,
173 target = 'sordi_static',
174 install_path = '',
175 defines = defines,
176 cflags = test_cflags)
177 autowaf.use_lib(bld, obj, 'SERD')
178
179 # C++ build test
180 if bld.env.COMPILER_CXX:
181 obj = bld(features = 'cxx cxxprogram',
182 source = 'src/sordmm_test.cpp',
183 includes = ['.', './src'],
184 use = 'libsord_profiled',
185 lib = test_libs,
186 target = 'sordmm_test',
187 install_path = '',
188 defines = defines)
189 autowaf.use_lib(bld, obj, 'SERD')
190
191 # Utilities
192 if bld.env.BUILD_UTILS:
193 for i in ['sordi', 'sord_validate']:
194 obj = bld(features = 'c cprogram',
195 source = 'src/%s.c' % i,
196 includes = ['.', './src'],
197 use = 'libsord',
198 lib = libs,
199 target = i,
200 install_path = '${BINDIR}',
201 defines = defines)
202 if not bld.env.BUILD_SHARED or bld.env.STATIC_PROGS:
203 obj.use = 'libsord_static'
204 if bld.env.STATIC_PROGS:
205 obj.env.SHLIB_MARKER = obj.env.STLIB_MARKER
206 obj.linkflags = ['-static', '-Wl,--start-group']
207 autowaf.use_lib(bld, obj, 'SERD PCRE')
208
209 # Documentation
210 autowaf.build_dox(bld, 'SORD', SORD_VERSION, top, out)
211
212 # Man pages
213 bld.install_files('${MANDIR}/man1', bld.path.ant_glob('doc/*.1'))
214
215 bld.add_post_fun(autowaf.run_ldconfig)
216 if bld.env.DOCS:
217 bld.add_post_fun(fix_docs)
218
219 def lint(ctx):
220 subprocess.call('cpplint.py --filter=+whitespace/comments,-whitespace/tab,-whitespace/braces,-whitespace/labels,-build/header_guard,-readability/casting,-readability/todo,-build/include src/*.* sord/* src/zix/*.*', shell=True)
221
222 def fix_docs(ctx):
223 if ctx.cmd == 'build':
224 autowaf.make_simple_dox(APPNAME)
225
226 def upload_docs(ctx):
227 os.system('rsync -ravz --delete -e ssh build/doc/html/ drobilla@drobilla.net:~/drobilla.net/docs/sord/')
228
229 def test(ctx):
230 blddir = autowaf.build_dir(APPNAME, 'tests')
231 try:
232 os.makedirs(blddir)
233 except:
234 pass
235
236 for i in glob.glob(blddir + '/*.*'):
237 os.remove(i)
238
239 srcdir = ctx.path.abspath()
240 orig_dir = os.path.abspath(os.curdir)
241
242 os.chdir(srcdir)
243
244 good_tests = glob.glob('tests/test-*.ttl')
245 good_tests.sort()
246
247 os.chdir(orig_dir)
248
249 autowaf.pre_test(ctx, APPNAME)
250
251 os.environ['PATH'] = '.' + os.pathsep + os.getenv('PATH')
252
253 nul = os.devnull
254
255 autowaf.run_tests(ctx, APPNAME, [
256 'sordi_static file://%s/tests/manifest.ttl > %s' % (srcdir, nul),
257 'sordi_static %s/tests/UTF-8.ttl > %s' % (srcdir, nul),
258 'sordi_static -v > %s' % nul,
259 'sordi_static -h > %s' % nul,
260 'sordi_static -s "<foo> a <#Thingie> ." file:///test > %s' % nul,
261 'sordi_static %s > %s' % (nul, nul)],
262 0, name='sordi-cmd-good')
263
264 autowaf.run_tests(ctx, APPNAME, [
265 'sordi_static > %s' % nul,
266 'sordi_static ftp://example.org/unsupported.ttl > %s' % nul,
267 'sordi_static -i > %s' % nul,
268 'sordi_static -o > %s' % nul,
269 'sordi_static -z > %s' % nul,
270 'sordi_static -p > %s' % nul,
271 'sordi_static -c > %s' % nul,
272 'sordi_static -i illegal > %s' % nul,
273 'sordi_static -o illegal > %s' % nul,
274 'sordi_static -i turtle > %s' % nul,
275 'sordi_static /no/such/file > %s' % nul],
276 1, name='sordi-cmd-bad')
277
278 autowaf.run_tests(ctx, APPNAME, ['sord_test'])
279
280 commands = []
281 for test in good_tests:
282 base_uri = 'http://www.w3.org/2001/sw/DataAccess/df1/' + test.replace('\\', '/')
283 commands += [ 'sordi_static "%s" "%s" > %s.out' % (
284 os.path.join(srcdir, test), base_uri, test) ]
285
286 autowaf.run_tests(ctx, APPNAME, commands, 0, name='good')
287
288 Logs.pprint('BOLD', '\nVerifying turtle => ntriples')
289 for test in good_tests:
290 out_filename = test + '.out'
291 cmp_filename = srcdir + '/' + test.replace('.ttl', '.out')
292 if not os.access(out_filename, os.F_OK):
293 Logs.pprint('RED', 'FAIL: %s output is missing' % test)
294 else:
295 out_lines = sorted(open(out_filename).readlines())
296 cmp_lines = sorted(open(cmp_filename).readlines())
297 if out_lines != cmp_lines:
298 Logs.pprint('RED', 'FAIL: %s is incorrect' % out_filename)
299 else:
300 Logs.pprint('GREEN', 'Pass: %s' % test)
301
302 autowaf.post_test(ctx, APPNAME)