File: wscript

package info (click to toggle)
audacity 2.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 129,312 kB
  • sloc: ansic: 373,350; cpp: 276,880; sh: 56,060; python: 18,922; makefile: 10,309; lisp: 8,365; xml: 1,888; perl: 1,798; java: 1,551; asm: 545; pascal: 395; sed: 58; awk: 35
file content (543 lines) | stat: -rw-r--r-- 20,027 bytes parent folder | download | duplicates (3)
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
#!/usr/bin/env python
import glob
import os
import shutil
import subprocess
import waflib.Logs as Logs
import waflib.Options as Options
import waflib.extras.autowaf as autowaf

# Library and package version (UNIX style major, minor, micro)
# major increment <=> incompatible changes
# minor increment <=> compatible changes (additions)
# micro increment <=> no interface changes
SERD_VERSION       = '0.20.0'
SERD_MAJOR_VERSION = '0'

# Mandatory waf variables
APPNAME = 'serd'        # Package name for waf dist
VERSION = SERD_VERSION  # Package version for waf dist
top     = '.'           # Source directory
out     = 'build'       # Build directory

def options(opt):
    opt.load('compiler_c')
    autowaf.set_options(opt)
    opt.add_option('--no-utils', action='store_true', dest='no_utils',
                   help='Do not build command line utilities')
    opt.add_option('--test', action='store_true', dest='build_tests',
                   help='Build unit tests')
    opt.add_option('--stack-check', action='store_true', dest='stack_check',
                   help='Include runtime stack sanity checks')
    opt.add_option('--static', action='store_true', dest='static',
                   help='Build static library')
    opt.add_option('--no-shared', action='store_true', dest='no_shared',
                   help='Do not build shared library')
    opt.add_option('--static-progs', action='store_true', dest='static_progs',
                   help='Build programs as static binaries')
    opt.add_option('--largefile', action='store_true', dest='largefile',
                   help='Build with large file support on 32-bit systems')
    opt.add_option('--no-posix', action='store_true', dest='no_posix',
                   help='Do not use posix_memalign, posix_fadvise, and fileno, even if present')

def configure(conf):
    conf.load('compiler_c')
    autowaf.configure(conf)
    autowaf.display_header('Serd Configuration')
    autowaf.set_c99_mode(conf)

    conf.env.BUILD_TESTS  = Options.options.build_tests
    conf.env.BUILD_UTILS  = not Options.options.no_utils
    conf.env.BUILD_SHARED = not Options.options.no_shared
    conf.env.STATIC_PROGS = Options.options.static_progs
    conf.env.BUILD_STATIC = (Options.options.static or
                             Options.options.static_progs)

    if not conf.env.BUILD_SHARED and not conf.env.BUILD_STATIC:
        conf.fatal('Neither a shared nor a static build requested')

    if Options.options.stack_check:
        autowaf.define(conf, 'SERD_STACK_CHECK', SERD_VERSION)

    if Options.options.largefile:
        conf.env.append_unique('DEFINES', ['_FILE_OFFSET_BITS=64'])

    if conf.env.BUILD_TESTS:
        conf.check(lib         = 'gcov',
                   define_name = 'HAVE_GCOV',
                   mandatory   = False)

    conf.check(function_name = 'fmax',
               header_name   = 'math.h',
               define_name   = 'HAVE_FMAX',
               lib           = ['m'],
               mandatory     = False)

    if not Options.options.no_posix:
        conf.check(function_name = 'posix_memalign',
                   header_name   = 'stdlib.h',
                   define_name   = 'HAVE_POSIX_MEMALIGN',
                   defines       = ['_POSIX_C_SOURCE=201112L'],
                   mandatory     = False)

        conf.check(function_name = 'posix_fadvise',
                   header_name   = 'fcntl.h',
                   define_name   = 'HAVE_POSIX_FADVISE',
                   defines       = ['_POSIX_C_SOURCE=201112L'],
                   mandatory     = False)

        conf.check(function_name = 'fileno',
                   header_name   = 'stdio.h',
                   define_name   = 'HAVE_FILENO',
                   defines       = ['_POSIX_C_SOURCE=201112L'],
                   mandatory     = False)

    autowaf.define(conf, 'SERD_VERSION', SERD_VERSION)
    autowaf.set_lib_env(conf, 'serd', SERD_VERSION)
    conf.write_config_header('serd_config.h', remove=False)

    autowaf.display_msg(conf, 'Utilities', str(conf.env.BUILD_UTILS))
    autowaf.display_msg(conf, 'Unit tests', str(conf.env.BUILD_TESTS))
    print('')

lib_source = [
    'src/env.c',
    'src/node.c',
    'src/reader.c',
    'src/string.c',
    'src/uri.c',
    'src/writer.c',
]

def build(bld):
    # C Headers
    includedir = '${INCLUDEDIR}/serd-%s/serd' % SERD_MAJOR_VERSION
    bld.install_files(includedir, bld.path.ant_glob('serd/*.h'))

    # Pkgconfig file
    autowaf.build_pc(bld, 'SERD', SERD_VERSION, SERD_MAJOR_VERSION, [],
                     {'SERD_MAJOR_VERSION' : SERD_MAJOR_VERSION})

    libflags = ['-fvisibility=hidden']
    libs     = ['m']
    defines  = []
    if bld.env.MSVC_COMPILER:
        libflags = []
        libs     = []
        defines  = ['snprintf=_snprintf']

    # Shared Library
    if bld.env.BUILD_SHARED:
        bld(features        = 'c cshlib',
            export_includes = ['.'],
            source          = lib_source,
            includes        = ['.', './src'],
            lib             = libs,
            name            = 'libserd',
            target          = 'serd-%s' % SERD_MAJOR_VERSION,
            vnum            = SERD_VERSION,
            install_path    = '${LIBDIR}',
            defines         = defines + ['SERD_SHARED', 'SERD_INTERNAL'],
            cflags          = libflags)

    # Static library
    if bld.env.BUILD_STATIC:
        bld(features        = 'c cstlib',
            export_includes = ['.'],
            source          = lib_source,
            includes        = ['.', './src'],
            lib             = libs,
            name            = 'libserd_static',
            target          = 'serd-%s' % SERD_MAJOR_VERSION,
            vnum            = SERD_VERSION,
            install_path    = '${LIBDIR}',
            defines         = defines + ['SERD_INTERNAL'])

    if bld.env.BUILD_TESTS:
        test_libs   = libs
        test_cflags = ['']
        if bld.is_defined('HAVE_GCOV'):
            test_libs   += ['gcov']
            test_cflags += ['-fprofile-arcs', '-ftest-coverage']

        # Profiled static library for test coverage
        bld(features     = 'c cstlib',
            source       = lib_source,
            includes     = ['.', './src'],
            lib          = test_libs,
            name         = 'libserd_profiled',
            target       = 'serd_profiled',
            install_path = '',
            defines      = defines + ['SERD_INTERNAL'],
            cflags       = test_cflags)

        # Static profiled serdi for tests
        bld(features     = 'c cprogram',
            source       = 'src/serdi.c',
            includes     = ['.', './src'],
            use          = 'libserd_profiled',
            lib          = test_libs,
            target       = 'serdi_static',
            install_path = '',
            defines      = defines,
            cflags       = test_cflags)

        # Unit test program
        bld(features     = 'c cprogram',
            source       = 'tests/serd_test.c',
            includes     = ['.', './src'],
            use          = 'libserd_profiled',
            lib          = test_libs,
            target       = 'serd_test',
            install_path = '',
            defines      = defines,
            cflags       = test_cflags)

    # Utilities
    if bld.env.BUILD_UTILS:
        obj = bld(features     = 'c cprogram',
                  source       = 'src/serdi.c',
                  target       = 'serdi',
                  includes     = ['.', './src'],
                  use          = 'libserd',
                  lib          = libs,
                  install_path = '${BINDIR}')
        if not bld.env.BUILD_SHARED or bld.env.STATIC_PROGS:
            obj.use = 'libserd_static'
        if bld.env.STATIC_PROGS:
            obj.env.SHLIB_MARKER = obj.env.STLIB_MARKER
            obj.linkflags        = ['-static']

    # Documentation
    autowaf.build_dox(bld, 'SERD', SERD_VERSION, top, out)

    # Man page
    bld.install_files('${MANDIR}/man1', 'doc/serdi.1')

    bld.add_post_fun(autowaf.run_ldconfig)
    if bld.env.DOCS:
        bld.add_post_fun(fix_docs)

def lint(ctx):
    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)

def amalgamate(ctx):
    shutil.copy('serd/serd.h', 'build/serd.h')
    amalgamation = open('build/serd.c', 'w')

    serd_internal_h = open('src/serd_internal.h')
    for l in serd_internal_h:
        if l == '#include "serd/serd.h"\n':
            amalgamation.write('#include "serd.h"\n')
        else:
            amalgamation.write(l)
    serd_internal_h.close()

    for f in lib_source:
        fd = open(f)
        amalgamation.write('\n/**\n   @file %s\n*/' % f)
        header = True
        for l in fd:
            if header:
                if l == '*/\n':
                    header = False
            else:
                if l != '#include "serd_internal.h"\n':
                    amalgamation.write(l)
        fd.close()
    amalgamation.close()

    for i in ['c', 'h']:
        Logs.info('Wrote build/serd.%s' % i)

def fix_docs(ctx):
    if ctx.cmd == 'build':
        autowaf.make_simple_dox(APPNAME)

def upload_docs(ctx):
    os.system('rsync -ravz --delete -e ssh build/doc/html/ drobilla@drobilla.net:~/drobilla.net/docs/serd/')
    for page in glob.glob('doc/*.[1-8]'):
        os.system('soelim %s | pre-grohtml troff -man -wall -Thtml | post-grohtml > build/%s.html' % (page, page))
        os.system('rsync -avz --delete -e ssh build/%s.html drobilla@drobilla.net:~/drobilla.net/man/' % page)

def file_equals(patha, pathb, subst_from='', subst_to=''):
    fa = open(patha, 'rU')
    fb = open(pathb, 'rU')
    for line in fa:
        if line.replace(subst_from, subst_to) != fb.readline().replace(subst_from, subst_to):
            return False
    fa.close()
    fb.close()
    return True

def earl_assertion(test, passed, asserter):
    import datetime

    asserter_str = ''
    if asserter is not None:
        asserter_str = '\n\tearl:assertedBy <%s> ;' % asserter

    passed_str = 'earl:failed'
    if passed:
        passed_str = 'earl:passed'

    return '''
[]
	a earl:Assertion ;%s
	earl:subject <http://drobilla.net/sw/serd> ;
	earl:test <%s> ;
	earl:result [
		a earl:TestResult ;
		earl:outcome %s ;
		dc:date "%s"^^xsd:dateTime
	] .
''' % (asserter_str,
       test,
       passed_str,
       datetime.datetime.now().replace(microsecond=0).isoformat())

def test_thru(ctx, base, path, check_filename, flags):
    in_filename = os.path.join(ctx.path.abspath(), path);
    out_filename = path + '.thru'

    command = ('%s %s -i turtle -o turtle -p foo "%s" "%s" | '
               '%s -i turtle -o ntriples -c foo - "%s" > %s') % (
        'serdi_static', flags.ljust(5),
        in_filename, base,
        'serdi_static', base, out_filename)

    passed = autowaf.run_test(ctx, APPNAME, command, 0, name=out_filename)
    if not passed:
        Logs.pprint('RED', '** Failed command: %s' % command)
        return False

    if not os.access(out_filename, os.F_OK):
        Logs.pprint('RED', 'FAIL: %s is missing' % out_filename)
    elif not file_equals(check_filename, out_filename, '_:docid', '_:genid'):
        Logs.pprint('RED', 'FAIL: %s != %s' % (out_filename, check_filename))
    else:
        #Logs.pprint('GREEN', '** Pass %s == %s' % (out_filename, check_filename))
        return True

    return False

def test_manifest(ctx, srcdir, testdir, report, base_uri):
    import rdflib
    import urlparse

    rdf  = rdflib.Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#')
    rdfs = rdflib.Namespace('http://www.w3.org/2000/01/rdf-schema#')
    mf   = rdflib.Namespace('http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#')
    rdft = rdflib.Namespace('http://www.w3.org/ns/rdftest#')
    earl = rdflib.Namespace('http://www.w3.org/ns/earl#')

    model = rdflib.ConjunctiveGraph()
    model.parse(os.path.join(srcdir, 'tests', testdir, 'manifest.ttl'),
                rdflib.URIRef(base_uri + 'manifest.ttl'),
                format='n3')

    asserter = ''
    if os.getenv('USER') == 'drobilla':
        asserter = 'http://drobilla.net/drobilla#me'

    def run_test(action_node, expected_return):
        output  = os.path.join('tests', testdir, action_node + '.out')
        action  = os.path.join(srcdir, 'tests', testdir, action_node)
        rel     = os.path.relpath(action, os.path.join(srcdir, 'tests', testdir))
        command = 'serdi_static -f "%s" "%s" > %s' % (action, base_uri + rel, output)

        return autowaf.run_test(ctx, APPNAME, command, expected_return, name=name)

    for i in sorted(model.triples([None, rdf.type, rdft.TestTurtlePositiveSyntax])):
        test        = i[0]
        name        = model.value(test, mf.name, None)
        action_node = model.value(test, mf.action, None)[len(base_uri):]

        passed = run_test(action_node, 0)
        report.write(earl_assertion(test, passed, asserter))

    for i in sorted(model.triples([None, rdf.type, rdft.TestTurtleNegativeSyntax])):
        test        = i[0]
        name        = model.value(test, mf.name, None)
        action_node = model.value(test, mf.action, None)[len(base_uri):]

        passed = run_test(action_node, 1)
        report.write(earl_assertion(test, passed, asserter))

    for i in sorted(model.triples([None, rdf.type, rdft.TestTurtleNegativeEval])):
        test        = i[0]
        name        = model.value(test, mf.name, None)
        action_node = model.value(test, mf.action, None)[len(base_uri):]

        passed = run_test(action_node, 1)
        report.write(earl_assertion(test, passed, asserter))

    for i in sorted(model.triples([None, rdf.type, rdft.TestTurtleEval])):
        test        = i[0]
        name        = model.value(test, mf.name, None)
        action_node = model.value(test, mf.action, None)[len(base_uri):]
        result_node = model.value(test, mf.result, None)[len(base_uri):]

        passed = run_test(action_node, 0)

        if passed:
            action = os.path.join('tests', testdir, action_node)
            output = action + '.out'
            result = os.path.join(srcdir, 'tests', testdir, result_node)

            if not os.access(output, os.F_OK):
                passed = False
                Logs.pprint('RED', 'FAIL: %s output %s is missing' % (name, output))
            elif not file_equals(result, output):
                passed = False
                Logs.pprint('RED', 'FAIL: %s != %s' % (os.path.abspath(output), result))
            else:
                Logs.pprint('GREEN', '** Pass %s' % output)

            test_thru(ctx, base_uri + action_node, action, result, "")

        report.write(earl_assertion(test, passed, asserter))

def test(ctx):
    blddir = autowaf.build_dir(APPNAME, 'tests')
    for i in ['', 'bad', 'good', 'new', 'TurtleTests', 'extra']:
        try:
            os.makedirs(os.path.join(blddir, i))
        except:
            pass

    for i in glob.glob(blddir + '/*.*'):
        os.remove(i)

    srcdir   = ctx.path.abspath()
    orig_dir = os.path.abspath(os.curdir)

    os.chdir(os.path.join(srcdir, 'tests', 'good'))
    old_good_tests = glob.glob('*.ttl')
    old_good_tests.sort()
    old_good_tests.remove('manifest.ttl')
    good_tests = { 'good': old_good_tests }
    os.chdir(orig_dir)

    os.chdir(srcdir)
    bad_tests = glob.glob('tests/bad/*.ttl')
    bad_tests.sort()
    os.chdir(orig_dir)

    autowaf.pre_test(ctx, APPNAME)

    os.environ['PATH'] = '.' + os.pathsep + os.getenv('PATH')

    autowaf.run_tests(ctx, APPNAME, ['serd_test'], dirs=['.'])

    autowaf.run_tests(ctx, APPNAME, [
            'serdi_static -q -o turtle %s/tests/good/base.ttl "base.ttl" > tests/good/base.ttl.out' % srcdir],
                      0, name='base')

    if not file_equals('%s/tests/good/base.ttl' % srcdir, 'tests/good/base.ttl.out'):
        Logs.pprint('RED', 'FAIL: build/tests/base.ttl.out is incorrect')

    nul = os.devnull
    autowaf.run_tests(ctx, APPNAME, [
            'serdi_static file://%s/tests/good/manifest.ttl > %s' % (srcdir, nul),
#            'serdi_static %s/tests/good/UTF-8.ttl > %s' % (srcdir, nul),
            'serdi_static -v > %s' % nul,
            'serdi_static -h > %s' % nul,
            'serdi_static -s "<foo> a <#Thingie> ." > %s' % nul,
            'serdi_static %s > %s' % (nul, nul)],
                      0, name='serdi-cmd-good')

    autowaf.run_tests(ctx, APPNAME, [
            'serdi_static -q file://%s/tests/bad-id-clash.ttl > %s' % (srcdir, nul),
            'serdi_static > %s' % nul,
            'serdi_static ftp://example.org/unsupported.ttl > %s' % nul,
            'serdi_static -i > %s' % nul,
            'serdi_static -o > %s' % nul,
            'serdi_static -z > %s' % nul,
            'serdi_static -p > %s' % nul,
            'serdi_static -c > %s' % nul,
            'serdi_static -r > %s' % nul,
            'serdi_static -i illegal > %s' % nul,
            'serdi_static -o illegal > %s' % nul,
            'serdi_static -i turtle > %s' % nul,
            'serdi_static /no/such/file > %s' % nul],
                      1, name='serdi-cmd-bad')

    def test_base(test):
        return ('http://www.w3.org/2001/sw/DataAccess/df1/tests/'
                + test.replace('\\', '/'))

    # Good tests
    for tdir, tests in good_tests.items():
        commands = []

        for test in tests:
            path = os.path.join('tests', tdir, test)
            commands += [ 'serdi_static -f "%s" "%s" > %s.out' % (
                    os.path.join(srcdir, path), test_base(test), path) ]

        autowaf.run_tests(ctx, APPNAME, commands, 0, name=tdir)

        Logs.pprint('BOLD', '\nVerifying turtle => ntriples')
        for test in tests:
            check_filename = os.path.join(
                srcdir, 'tests', tdir, test.replace('.ttl', '.nt'))
            out_filename = os.path.join('tests', tdir, test + '.out')
            if not os.access(out_filename, os.F_OK):
                Logs.pprint('RED', 'FAIL: %s output is missing' % test)
            elif not file_equals(check_filename, out_filename):
                Logs.pprint('RED', 'FAIL: %s is incorrect' % out_filename)
            else:
                Logs.pprint('GREEN', 'Pass: %s' % test)

    # Bad tests
    commands = []
    for test in bad_tests:
        commands += [ 'serdi_static -q "%s" "%s" > %s.out' % (
                os.path.join(srcdir, test), test_base(test), test) ]

    autowaf.run_tests(ctx, APPNAME, commands, 1, name='bad')

    # Don't do a round-trip test for test-id.ttl, IDs have changed
    good_tests['good'].remove('test-id.ttl')

    # Round-trip good tests
    for tdir, tests in good_tests.items():
        thru_tests = tests;

        commands = []
        num = 0
        for test in thru_tests:
            num += 1
            flags = ''
            if (num % 2 == 0):
                flags += '-b'
            if (num % 5 == 0):
                flags += ' -f'
            if (num % 3 == 0):
                flags += ' -r http://www.w3.org/'
            if (num % 7 == 0):
                flags += ' -e'

            path  = os.path.join('tests', tdir, test)
            check = os.path.join(srcdir, path.replace('.ttl', '.nt'))
            test_thru(ctx, test_base(test), path, check, flags)

    # New manifest-driven tests
    try:
        report = open('earl.ttl', 'w')
        report.write('''@prefix earl: <http://www.w3.org/ns/earl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n''')

        serd_ttl = open(os.path.join(srcdir, 'serd.ttl'))
        for line in serd_ttl:
            report.write(line)
        serd_ttl.close()
        turtle_tests = 'http://www.w3.org/2013/TurtleTests/'
        test_manifest(ctx, srcdir, 'TurtleTests', report, turtle_tests)
        report.close()

    except:
        pass

    autowaf.post_test(ctx, APPNAME)