Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wscript 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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. # 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. SERD_VERSION = '0.20.0'
  14. SERD_MAJOR_VERSION = '0'
  15. # Mandatory waf variables
  16. APPNAME = 'serd' # Package name for waf dist
  17. VERSION = SERD_VERSION # Package version for waf dist
  18. top = '.' # Source directory
  19. out = 'build' # Build directory
  20. def options(opt):
  21. opt.load('compiler_c')
  22. autowaf.set_options(opt)
  23. opt.add_option('--no-utils', action='store_true', dest='no_utils',
  24. help='Do not build command line utilities')
  25. opt.add_option('--test', action='store_true', dest='build_tests',
  26. help='Build unit tests')
  27. opt.add_option('--stack-check', action='store_true', dest='stack_check',
  28. help='Include runtime stack sanity checks')
  29. opt.add_option('--static', action='store_true', dest='static',
  30. help='Build static library')
  31. opt.add_option('--no-shared', action='store_true', dest='no_shared',
  32. help='Do not build shared library')
  33. opt.add_option('--static-progs', action='store_true', dest='static_progs',
  34. help='Build programs as static binaries')
  35. opt.add_option('--largefile', action='store_true', dest='largefile',
  36. help='Build with large file support on 32-bit systems')
  37. opt.add_option('--no-posix', action='store_true', dest='no_posix',
  38. help='Do not use posix_memalign, posix_fadvise, and fileno, even if present')
  39. def configure(conf):
  40. conf.load('compiler_c')
  41. autowaf.configure(conf)
  42. autowaf.display_header('Serd Configuration')
  43. autowaf.set_c99_mode(conf)
  44. conf.env.BUILD_TESTS = Options.options.build_tests
  45. conf.env.BUILD_UTILS = not Options.options.no_utils
  46. conf.env.BUILD_SHARED = not Options.options.no_shared
  47. conf.env.STATIC_PROGS = Options.options.static_progs
  48. conf.env.BUILD_STATIC = (Options.options.static or
  49. Options.options.static_progs)
  50. if not conf.env.BUILD_SHARED and not conf.env.BUILD_STATIC:
  51. conf.fatal('Neither a shared nor a static build requested')
  52. if Options.options.stack_check:
  53. autowaf.define(conf, 'SERD_STACK_CHECK', SERD_VERSION)
  54. if Options.options.largefile:
  55. conf.env.append_unique('DEFINES', ['_FILE_OFFSET_BITS=64'])
  56. if conf.env.BUILD_TESTS:
  57. conf.check(lib = 'gcov',
  58. define_name = 'HAVE_GCOV',
  59. mandatory = False)
  60. conf.check(function_name = 'fmax',
  61. header_name = 'math.h',
  62. define_name = 'HAVE_FMAX',
  63. lib = ['m'],
  64. mandatory = False)
  65. if not Options.options.no_posix:
  66. conf.check(function_name = 'posix_memalign',
  67. header_name = 'stdlib.h',
  68. define_name = 'HAVE_POSIX_MEMALIGN',
  69. defines = ['_POSIX_C_SOURCE=201112L'],
  70. mandatory = False)
  71. conf.check(function_name = 'posix_fadvise',
  72. header_name = 'fcntl.h',
  73. define_name = 'HAVE_POSIX_FADVISE',
  74. defines = ['_POSIX_C_SOURCE=201112L'],
  75. mandatory = False)
  76. conf.check(function_name = 'fileno',
  77. header_name = 'stdio.h',
  78. define_name = 'HAVE_FILENO',
  79. defines = ['_POSIX_C_SOURCE=201112L'],
  80. mandatory = False)
  81. autowaf.define(conf, 'SERD_VERSION', SERD_VERSION)
  82. autowaf.set_lib_env(conf, 'serd', SERD_VERSION)
  83. conf.write_config_header('serd_config.h', remove=False)
  84. autowaf.display_msg(conf, 'Utilities', str(conf.env.BUILD_UTILS))
  85. autowaf.display_msg(conf, 'Unit tests', str(conf.env.BUILD_TESTS))
  86. print('')
  87. lib_source = [
  88. 'src/env.c',
  89. 'src/node.c',
  90. 'src/reader.c',
  91. 'src/string.c',
  92. 'src/uri.c',
  93. 'src/writer.c',
  94. ]
  95. def build(bld):
  96. # C Headers
  97. includedir = '${INCLUDEDIR}/serd-%s/serd' % SERD_MAJOR_VERSION
  98. bld.install_files(includedir, bld.path.ant_glob('serd/*.h'))
  99. # Pkgconfig file
  100. autowaf.build_pc(bld, 'SERD', SERD_VERSION, SERD_MAJOR_VERSION, [],
  101. {'SERD_MAJOR_VERSION' : SERD_MAJOR_VERSION})
  102. libflags = ['-fvisibility=hidden']
  103. libs = ['m']
  104. defines = []
  105. if bld.env.MSVC_COMPILER:
  106. libflags = []
  107. libs = []
  108. defines = ['snprintf=_snprintf']
  109. # Shared Library
  110. if bld.env.BUILD_SHARED:
  111. bld(features = 'c cshlib',
  112. export_includes = ['.'],
  113. source = lib_source,
  114. includes = ['.', './src'],
  115. lib = libs,
  116. name = 'libserd',
  117. target = 'serd-%s' % SERD_MAJOR_VERSION,
  118. vnum = SERD_VERSION,
  119. install_path = '${LIBDIR}',
  120. defines = defines + ['SERD_SHARED', 'SERD_INTERNAL'],
  121. cflags = libflags)
  122. # Static library
  123. if bld.env.BUILD_STATIC:
  124. bld(features = 'c cstlib',
  125. export_includes = ['.'],
  126. source = lib_source,
  127. includes = ['.', './src'],
  128. lib = libs,
  129. name = 'libserd_static',
  130. target = 'serd-%s' % SERD_MAJOR_VERSION,
  131. vnum = SERD_VERSION,
  132. install_path = '${LIBDIR}',
  133. defines = defines + ['SERD_INTERNAL'])
  134. if bld.env.BUILD_TESTS:
  135. test_libs = libs
  136. test_cflags = ['']
  137. if bld.is_defined('HAVE_GCOV'):
  138. test_libs += ['gcov']
  139. test_cflags += ['-fprofile-arcs', '-ftest-coverage']
  140. # Profiled static library for test coverage
  141. bld(features = 'c cstlib',
  142. source = lib_source,
  143. includes = ['.', './src'],
  144. lib = test_libs,
  145. name = 'libserd_profiled',
  146. target = 'serd_profiled',
  147. install_path = '',
  148. defines = defines + ['SERD_INTERNAL'],
  149. cflags = test_cflags)
  150. # Static profiled serdi for tests
  151. bld(features = 'c cprogram',
  152. source = 'src/serdi.c',
  153. includes = ['.', './src'],
  154. use = 'libserd_profiled',
  155. lib = test_libs,
  156. target = 'serdi_static',
  157. install_path = '',
  158. defines = defines,
  159. cflags = test_cflags)
  160. # Unit test program
  161. bld(features = 'c cprogram',
  162. source = 'tests/serd_test.c',
  163. includes = ['.', './src'],
  164. use = 'libserd_profiled',
  165. lib = test_libs,
  166. target = 'serd_test',
  167. install_path = '',
  168. defines = defines,
  169. cflags = test_cflags)
  170. # Utilities
  171. if bld.env.BUILD_UTILS:
  172. obj = bld(features = 'c cprogram',
  173. source = 'src/serdi.c',
  174. target = 'serdi',
  175. includes = ['.', './src'],
  176. use = 'libserd',
  177. lib = libs,
  178. install_path = '${BINDIR}')
  179. if not bld.env.BUILD_SHARED or bld.env.STATIC_PROGS:
  180. obj.use = 'libserd_static'
  181. if bld.env.STATIC_PROGS:
  182. obj.env.SHLIB_MARKER = obj.env.STLIB_MARKER
  183. obj.linkflags = ['-static']
  184. # Documentation
  185. autowaf.build_dox(bld, 'SERD', SERD_VERSION, top, out)
  186. # Man page
  187. bld.install_files('${MANDIR}/man1', 'doc/serdi.1')
  188. bld.add_post_fun(autowaf.run_ldconfig)
  189. if bld.env.DOCS:
  190. bld.add_post_fun(fix_docs)
  191. def lint(ctx):
  192. 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)
  193. def amalgamate(ctx):
  194. shutil.copy('serd/serd.h', 'build/serd.h')
  195. amalgamation = open('build/serd.c', 'w')
  196. serd_internal_h = open('src/serd_internal.h')
  197. for l in serd_internal_h:
  198. if l == '#include "serd/serd.h"\n':
  199. amalgamation.write('#include "serd.h"\n')
  200. else:
  201. amalgamation.write(l)
  202. serd_internal_h.close()
  203. for f in lib_source:
  204. fd = open(f)
  205. amalgamation.write('\n/**\n @file %s\n*/' % f)
  206. header = True
  207. for l in fd:
  208. if header:
  209. if l == '*/\n':
  210. header = False
  211. else:
  212. if l != '#include "serd_internal.h"\n':
  213. amalgamation.write(l)
  214. fd.close()
  215. amalgamation.close()
  216. for i in ['c', 'h']:
  217. Logs.info('Wrote build/serd.%s' % i)
  218. def fix_docs(ctx):
  219. if ctx.cmd == 'build':
  220. autowaf.make_simple_dox(APPNAME)
  221. def upload_docs(ctx):
  222. os.system('rsync -ravz --delete -e ssh build/doc/html/ drobilla@drobilla.net:~/drobilla.net/docs/serd/')
  223. for page in glob.glob('doc/*.[1-8]'):
  224. os.system('soelim %s | pre-grohtml troff -man -wall -Thtml | post-grohtml > build/%s.html' % (page, page))
  225. os.system('rsync -avz --delete -e ssh build/%s.html drobilla@drobilla.net:~/drobilla.net/man/' % page)
  226. def file_equals(patha, pathb, subst_from='', subst_to=''):
  227. fa = open(patha, 'rU')
  228. fb = open(pathb, 'rU')
  229. for line in fa:
  230. if line.replace(subst_from, subst_to) != fb.readline().replace(subst_from, subst_to):
  231. return False
  232. fa.close()
  233. fb.close()
  234. return True
  235. def earl_assertion(test, passed, asserter):
  236. import datetime
  237. asserter_str = ''
  238. if asserter is not None:
  239. asserter_str = '\n\tearl:assertedBy <%s> ;' % asserter
  240. passed_str = 'earl:failed'
  241. if passed:
  242. passed_str = 'earl:passed'
  243. return '''
  244. []
  245. a earl:Assertion ;%s
  246. earl:subject <http://drobilla.net/sw/serd> ;
  247. earl:test <%s> ;
  248. earl:result [
  249. a earl:TestResult ;
  250. earl:outcome %s ;
  251. dc:date "%s"^^xsd:dateTime
  252. ] .
  253. ''' % (asserter_str,
  254. test,
  255. passed_str,
  256. datetime.datetime.now().replace(microsecond=0).isoformat())
  257. def test_thru(ctx, base, path, check_filename, flags):
  258. in_filename = os.path.join(ctx.path.abspath(), path);
  259. out_filename = path + '.thru'
  260. command = ('%s %s -i turtle -o turtle -p foo "%s" "%s" | '
  261. '%s -i turtle -o ntriples -c foo - "%s" > %s') % (
  262. 'serdi_static', flags.ljust(5),
  263. in_filename, base,
  264. 'serdi_static', base, out_filename)
  265. passed = autowaf.run_test(ctx, APPNAME, command, 0, name=out_filename)
  266. if not passed:
  267. Logs.pprint('RED', '** Failed command: %s' % command)
  268. return False
  269. if not os.access(out_filename, os.F_OK):
  270. Logs.pprint('RED', 'FAIL: %s is missing' % out_filename)
  271. elif not file_equals(check_filename, out_filename, '_:docid', '_:genid'):
  272. Logs.pprint('RED', 'FAIL: %s != %s' % (out_filename, check_filename))
  273. else:
  274. #Logs.pprint('GREEN', '** Pass %s == %s' % (out_filename, check_filename))
  275. return True
  276. return False
  277. def test_manifest(ctx, srcdir, testdir, report, base_uri):
  278. import rdflib
  279. import urlparse
  280. rdf = rdflib.Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#')
  281. rdfs = rdflib.Namespace('http://www.w3.org/2000/01/rdf-schema#')
  282. mf = rdflib.Namespace('http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#')
  283. rdft = rdflib.Namespace('http://www.w3.org/ns/rdftest#')
  284. earl = rdflib.Namespace('http://www.w3.org/ns/earl#')
  285. model = rdflib.ConjunctiveGraph()
  286. model.parse(os.path.join(srcdir, 'tests', testdir, 'manifest.ttl'),
  287. rdflib.URIRef(base_uri + 'manifest.ttl'),
  288. format='n3')
  289. asserter = ''
  290. if os.getenv('USER') == 'drobilla':
  291. asserter = 'http://drobilla.net/drobilla#me'
  292. def run_test(action_node, expected_return):
  293. output = os.path.join('tests', testdir, action_node + '.out')
  294. action = os.path.join(srcdir, 'tests', testdir, action_node)
  295. rel = os.path.relpath(action, os.path.join(srcdir, 'tests', testdir))
  296. command = 'serdi_static -f "%s" "%s" > %s' % (action, base_uri + rel, output)
  297. return autowaf.run_test(ctx, APPNAME, command, expected_return, name=name)
  298. for i in sorted(model.triples([None, rdf.type, rdft.TestTurtlePositiveSyntax])):
  299. test = i[0]
  300. name = model.value(test, mf.name, None)
  301. action_node = model.value(test, mf.action, None)[len(base_uri):]
  302. passed = run_test(action_node, 0)
  303. report.write(earl_assertion(test, passed, asserter))
  304. for i in sorted(model.triples([None, rdf.type, rdft.TestTurtleNegativeSyntax])):
  305. test = i[0]
  306. name = model.value(test, mf.name, None)
  307. action_node = model.value(test, mf.action, None)[len(base_uri):]
  308. passed = run_test(action_node, 1)
  309. report.write(earl_assertion(test, passed, asserter))
  310. for i in sorted(model.triples([None, rdf.type, rdft.TestTurtleNegativeEval])):
  311. test = i[0]
  312. name = model.value(test, mf.name, None)
  313. action_node = model.value(test, mf.action, None)[len(base_uri):]
  314. passed = run_test(action_node, 1)
  315. report.write(earl_assertion(test, passed, asserter))
  316. for i in sorted(model.triples([None, rdf.type, rdft.TestTurtleEval])):
  317. test = i[0]
  318. name = model.value(test, mf.name, None)
  319. action_node = model.value(test, mf.action, None)[len(base_uri):]
  320. result_node = model.value(test, mf.result, None)[len(base_uri):]
  321. passed = run_test(action_node, 0)
  322. if passed:
  323. action = os.path.join('tests', testdir, action_node)
  324. output = action + '.out'
  325. result = os.path.join(srcdir, 'tests', testdir, result_node)
  326. if not os.access(output, os.F_OK):
  327. passed = False
  328. Logs.pprint('RED', 'FAIL: %s output %s is missing' % (name, output))
  329. elif not file_equals(result, output):
  330. passed = False
  331. Logs.pprint('RED', 'FAIL: %s != %s' % (os.path.abspath(output), result))
  332. else:
  333. Logs.pprint('GREEN', '** Pass %s' % output)
  334. test_thru(ctx, base_uri + action_node, action, result, "")
  335. report.write(earl_assertion(test, passed, asserter))
  336. def test(ctx):
  337. blddir = autowaf.build_dir(APPNAME, 'tests')
  338. for i in ['', 'bad', 'good', 'new', 'TurtleTests', 'extra']:
  339. try:
  340. os.makedirs(os.path.join(blddir, i))
  341. except:
  342. pass
  343. for i in glob.glob(blddir + '/*.*'):
  344. os.remove(i)
  345. srcdir = ctx.path.abspath()
  346. orig_dir = os.path.abspath(os.curdir)
  347. os.chdir(os.path.join(srcdir, 'tests', 'good'))
  348. old_good_tests = glob.glob('*.ttl')
  349. old_good_tests.sort()
  350. old_good_tests.remove('manifest.ttl')
  351. good_tests = { 'good': old_good_tests }
  352. os.chdir(orig_dir)
  353. os.chdir(srcdir)
  354. bad_tests = glob.glob('tests/bad/*.ttl')
  355. bad_tests.sort()
  356. os.chdir(orig_dir)
  357. autowaf.pre_test(ctx, APPNAME)
  358. os.environ['PATH'] = '.' + os.pathsep + os.getenv('PATH')
  359. autowaf.run_tests(ctx, APPNAME, ['serd_test'], dirs=['.'])
  360. autowaf.run_tests(ctx, APPNAME, [
  361. 'serdi_static -q -o turtle %s/tests/good/base.ttl "base.ttl" > tests/good/base.ttl.out' % srcdir],
  362. 0, name='base')
  363. if not file_equals('%s/tests/good/base.ttl' % srcdir, 'tests/good/base.ttl.out'):
  364. Logs.pprint('RED', 'FAIL: build/tests/base.ttl.out is incorrect')
  365. nul = os.devnull
  366. autowaf.run_tests(ctx, APPNAME, [
  367. 'serdi_static file://%s/tests/good/manifest.ttl > %s' % (srcdir, nul),
  368. # 'serdi_static %s/tests/good/UTF-8.ttl > %s' % (srcdir, nul),
  369. 'serdi_static -v > %s' % nul,
  370. 'serdi_static -h > %s' % nul,
  371. 'serdi_static -s "<foo> a <#Thingie> ." > %s' % nul,
  372. 'serdi_static %s > %s' % (nul, nul)],
  373. 0, name='serdi-cmd-good')
  374. autowaf.run_tests(ctx, APPNAME, [
  375. 'serdi_static -q file://%s/tests/bad-id-clash.ttl > %s' % (srcdir, nul),
  376. 'serdi_static > %s' % nul,
  377. 'serdi_static ftp://example.org/unsupported.ttl > %s' % nul,
  378. 'serdi_static -i > %s' % nul,
  379. 'serdi_static -o > %s' % nul,
  380. 'serdi_static -z > %s' % nul,
  381. 'serdi_static -p > %s' % nul,
  382. 'serdi_static -c > %s' % nul,
  383. 'serdi_static -r > %s' % nul,
  384. 'serdi_static -i illegal > %s' % nul,
  385. 'serdi_static -o illegal > %s' % nul,
  386. 'serdi_static -i turtle > %s' % nul,
  387. 'serdi_static /no/such/file > %s' % nul],
  388. 1, name='serdi-cmd-bad')
  389. def test_base(test):
  390. return ('http://www.w3.org/2001/sw/DataAccess/df1/tests/'
  391. + test.replace('\\', '/'))
  392. # Good tests
  393. for tdir, tests in good_tests.items():
  394. commands = []
  395. for test in tests:
  396. path = os.path.join('tests', tdir, test)
  397. commands += [ 'serdi_static -f "%s" "%s" > %s.out' % (
  398. os.path.join(srcdir, path), test_base(test), path) ]
  399. autowaf.run_tests(ctx, APPNAME, commands, 0, name=tdir)
  400. Logs.pprint('BOLD', '\nVerifying turtle => ntriples')
  401. for test in tests:
  402. check_filename = os.path.join(
  403. srcdir, 'tests', tdir, test.replace('.ttl', '.nt'))
  404. out_filename = os.path.join('tests', tdir, test + '.out')
  405. if not os.access(out_filename, os.F_OK):
  406. Logs.pprint('RED', 'FAIL: %s output is missing' % test)
  407. elif not file_equals(check_filename, out_filename):
  408. Logs.pprint('RED', 'FAIL: %s is incorrect' % out_filename)
  409. else:
  410. Logs.pprint('GREEN', 'Pass: %s' % test)
  411. # Bad tests
  412. commands = []
  413. for test in bad_tests:
  414. commands += [ 'serdi_static -q "%s" "%s" > %s.out' % (
  415. os.path.join(srcdir, test), test_base(test), test) ]
  416. autowaf.run_tests(ctx, APPNAME, commands, 1, name='bad')
  417. # Don't do a round-trip test for test-id.ttl, IDs have changed
  418. good_tests['good'].remove('test-id.ttl')
  419. # Round-trip good tests
  420. for tdir, tests in good_tests.items():
  421. thru_tests = tests;
  422. commands = []
  423. num = 0
  424. for test in thru_tests:
  425. num += 1
  426. flags = ''
  427. if (num % 2 == 0):
  428. flags += '-b'
  429. if (num % 5 == 0):
  430. flags += ' -f'
  431. if (num % 3 == 0):
  432. flags += ' -r http://www.w3.org/'
  433. if (num % 7 == 0):
  434. flags += ' -e'
  435. path = os.path.join('tests', tdir, test)
  436. check = os.path.join(srcdir, path.replace('.ttl', '.nt'))
  437. test_thru(ctx, test_base(test), path, check, flags)
  438. # New manifest-driven tests
  439. try:
  440. report = open('earl.ttl', 'w')
  441. report.write('''@prefix earl: <http://www.w3.org/ns/earl#> .
  442. @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n''')
  443. serd_ttl = open(os.path.join(srcdir, 'serd.ttl'))
  444. for line in serd_ttl:
  445. report.write(line)
  446. serd_ttl.close()
  447. turtle_tests = 'http://www.w3.org/2013/TurtleTests/'
  448. test_manifest(ctx, srcdir, 'TurtleTests', report, turtle_tests)
  449. report.close()
  450. except:
  451. pass
  452. autowaf.post_test(ctx, APPNAME)