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.

357 lines
14KB

  1. #!/usr/bin/env python
  2. import glob
  3. import os
  4. import subprocess
  5. import sys
  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. SORD_VERSION = '0.16.0'
  14. SORD_MAJOR_VERSION = '0'
  15. # Mandatory waf variables
  16. APPNAME = 'sord' # Package name for waf dist
  17. VERSION = SORD_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. opt.load('compiler_cxx')
  23. autowaf.set_options(opt, test=True)
  24. opt.add_option('--no-utils', action='store_true', dest='no_utils',
  25. help='Do not build command line utilities')
  26. opt.add_option('--static', action='store_true', dest='static',
  27. help='Build static library')
  28. opt.add_option('--no-shared', action='store_true', dest='no_shared',
  29. help='Do not build shared library')
  30. opt.add_option('--static-progs', action='store_true', dest='static_progs',
  31. help='Build programs as static binaries')
  32. opt.add_option('--dump', type='string', default='', dest='dump',
  33. help='Dump debugging output (iter, search, write, all)')
  34. def configure(conf):
  35. conf.load('compiler_c')
  36. if Options.options.build_tests:
  37. try:
  38. conf.load('compiler_cxx')
  39. except:
  40. Logs.warn("No C++ compiler, sordmm.hpp compile test skipped")
  41. pass
  42. autowaf.configure(conf)
  43. autowaf.set_c99_mode(conf)
  44. autowaf.display_header('Sord configuration')
  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. autowaf.check_pkg(conf, 'serd-0', uselib_store='SERD',
  51. atleast_version='0.22.4', mandatory=True)
  52. autowaf.check_pkg(conf, 'libpcre', uselib_store='PCRE', mandatory=False)
  53. if conf.env.HAVE_PCRE:
  54. if conf.check(cflags=['-pthread'], mandatory=False):
  55. conf.env.PTHREAD_CFLAGS = ['-pthread']
  56. conf.env.PTHREAD_LINKFLAGS = ['-pthread']
  57. elif conf.check(linkflags=['-lpthread'], mandatory=False):
  58. conf.env.PTHREAD_CFLAGS = []
  59. conf.env.PTHREAD_LINKFLAGS = ['-lpthread']
  60. else:
  61. conf.env.PTHREAD_CFLAGS = []
  62. conf.env.PTHREAD_LINKFLAGS = []
  63. # Parse dump options and define things accordingly
  64. dump = Options.options.dump.split(',')
  65. all = 'all' in dump
  66. if all or 'iter' in dump:
  67. autowaf.define(conf, 'SORD_DEBUG_ITER', 1)
  68. if all or 'search' in dump:
  69. autowaf.define(conf, 'SORD_DEBUG_SEARCH', 1)
  70. if all or 'write' in dump:
  71. autowaf.define(conf, 'SORD_DEBUG_WRITE', 1)
  72. autowaf.define(conf, 'SORD_VERSION', SORD_VERSION)
  73. autowaf.set_lib_env(conf, 'sord', SORD_VERSION)
  74. conf.write_config_header('sord_config.h', remove=False)
  75. autowaf.display_msg(conf, 'Utilities', bool(conf.env.BUILD_UTILS))
  76. autowaf.display_msg(conf, 'Unit tests', bool(conf.env.BUILD_TESTS))
  77. autowaf.display_msg(conf, 'Debug dumping', dump)
  78. print('')
  79. def build(bld):
  80. # C/C++ Headers
  81. includedir = '${INCLUDEDIR}/sord-%s/sord' % SORD_MAJOR_VERSION
  82. bld.install_files(includedir, bld.path.ant_glob('sord/*.h'))
  83. bld.install_files(includedir, bld.path.ant_glob('sord/*.hpp'))
  84. # Pkgconfig file
  85. autowaf.build_pc(bld, 'SORD', SORD_VERSION, SORD_MAJOR_VERSION, 'SERD',
  86. {'SORD_MAJOR_VERSION' : SORD_MAJOR_VERSION})
  87. source = 'src/sord.c src/syntax.c'
  88. libflags = ['-fvisibility=hidden']
  89. libs = ['m']
  90. defines = []
  91. if bld.env.MSVC_COMPILER:
  92. libflags = []
  93. libs = []
  94. defines = ['snprintf=_snprintf']
  95. # Shared Library
  96. if bld.env.BUILD_SHARED:
  97. obj = bld(features = 'c cshlib',
  98. source = source,
  99. includes = ['.', './src'],
  100. export_includes = ['.'],
  101. name = 'libsord',
  102. target = 'sord-%s' % SORD_MAJOR_VERSION,
  103. vnum = SORD_VERSION,
  104. install_path = '${LIBDIR}',
  105. libs = libs,
  106. defines = defines + ['SORD_SHARED', 'SORD_INTERNAL'],
  107. cflags = libflags)
  108. autowaf.use_lib(bld, obj, 'SERD')
  109. # Static Library
  110. if bld.env.BUILD_STATIC:
  111. obj = bld(features = 'c cstlib',
  112. source = source,
  113. includes = ['.', './src'],
  114. export_includes = ['.'],
  115. name = 'libsord_static',
  116. target = 'sord-%s' % SORD_MAJOR_VERSION,
  117. vnum = SORD_VERSION,
  118. install_path = '${LIBDIR}',
  119. libs = libs,
  120. defines = ['SORD_INTERNAL'])
  121. autowaf.use_lib(bld, obj, 'SERD')
  122. if bld.env.BUILD_TESTS:
  123. test_libs = libs
  124. test_cflags = ['']
  125. test_linkflags = ['']
  126. if not bld.env.NO_COVERAGE:
  127. test_cflags += ['--coverage']
  128. test_linkflags += ['--coverage']
  129. # Profiled static library for test coverage
  130. obj = bld(features = 'c cstlib',
  131. source = source,
  132. includes = ['.', './src'],
  133. name = 'libsord_profiled',
  134. target = 'sord_profiled',
  135. install_path = '',
  136. defines = defines,
  137. cflags = test_cflags,
  138. linkflags = test_linkflags,
  139. lib = test_libs)
  140. autowaf.use_lib(bld, obj, 'SERD')
  141. # Unit test program
  142. obj = bld(features = 'c cprogram',
  143. source = 'src/sord_test.c',
  144. includes = ['.', './src'],
  145. use = 'libsord_profiled',
  146. lib = test_libs,
  147. target = 'sord_test',
  148. install_path = '',
  149. defines = defines,
  150. cflags = test_cflags,
  151. linkflags = test_linkflags)
  152. autowaf.use_lib(bld, obj, 'SERD')
  153. # Static profiled sordi for tests
  154. obj = bld(features = 'c cprogram',
  155. source = 'src/sordi.c',
  156. includes = ['.', './src'],
  157. use = 'libsord_profiled',
  158. lib = test_libs,
  159. target = 'sordi_static',
  160. install_path = '',
  161. defines = defines,
  162. cflags = test_cflags,
  163. linkflags = test_linkflags)
  164. autowaf.use_lib(bld, obj, 'SERD')
  165. # C++ build test
  166. if bld.env.COMPILER_CXX:
  167. obj = bld(features = 'cxx cxxprogram',
  168. source = 'src/sordmm_test.cpp',
  169. includes = ['.', './src'],
  170. use = 'libsord_profiled',
  171. lib = test_libs,
  172. target = 'sordmm_test',
  173. install_path = '',
  174. defines = defines,
  175. cxxflags = test_cflags,
  176. linkflags = test_linkflags)
  177. autowaf.use_lib(bld, obj, 'SERD')
  178. # Utilities
  179. if bld.env.BUILD_UTILS:
  180. utils = ['sordi']
  181. if bld.env.HAVE_PCRE:
  182. utils += ['sord_validate']
  183. for i in utils:
  184. obj = bld(features = 'c cprogram',
  185. source = 'src/%s.c' % i,
  186. includes = ['.', './src'],
  187. use = 'libsord',
  188. lib = libs,
  189. target = i,
  190. install_path = '${BINDIR}',
  191. defines = defines)
  192. if not bld.env.BUILD_SHARED or bld.env.STATIC_PROGS:
  193. obj.use = 'libsord_static'
  194. if bld.env.STATIC_PROGS:
  195. obj.env.SHLIB_MARKER = obj.env.STLIB_MARKER
  196. obj.linkflags = ['-static', '-Wl,--start-group']
  197. autowaf.use_lib(bld, obj, 'SERD')
  198. if i == 'sord_validate':
  199. autowaf.use_lib(bld, obj, 'PCRE')
  200. obj.cflags = bld.env.PTHREAD_CFLAGS
  201. obj.linkflags = bld.env.PTHREAD_LINKFLAGS
  202. # Documentation
  203. autowaf.build_dox(bld, 'SORD', SORD_VERSION, top, out)
  204. # Man pages
  205. bld.install_files('${MANDIR}/man1', bld.path.ant_glob('doc/*.1'))
  206. bld.add_post_fun(autowaf.run_ldconfig)
  207. if bld.env.DOCS:
  208. bld.add_post_fun(fix_docs)
  209. def lint(ctx):
  210. 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)
  211. def fix_docs(ctx):
  212. if ctx.cmd == 'build':
  213. autowaf.make_simple_dox(APPNAME)
  214. def upload_docs(ctx):
  215. os.system('rsync -ravz --delete -e ssh build/doc/html/ drobilla@drobilla.net:~/drobilla.net/docs/sord/')
  216. for page in glob.glob('doc/*.[1-8]'):
  217. os.system('soelim %s | pre-grohtml troff -man -wall -Thtml | post-grohtml > build/%s.html' % (page, page))
  218. os.system('rsync -avz --delete -e ssh build/%s.html drobilla@drobilla.net:~/drobilla.net/man/' % page)
  219. def test(ctx):
  220. blddir = autowaf.build_dir(APPNAME, 'tests')
  221. try:
  222. os.makedirs(blddir)
  223. except:
  224. pass
  225. for i in glob.glob(blddir + '/*.*'):
  226. os.remove(i)
  227. srcdir = ctx.path.abspath()
  228. orig_dir = os.path.abspath(os.curdir)
  229. os.chdir(srcdir)
  230. good_tests = glob.glob('tests/test-*.ttl')
  231. good_tests.sort()
  232. os.chdir(orig_dir)
  233. autowaf.pre_test(ctx, APPNAME)
  234. os.environ['PATH'] = '.' + os.pathsep + os.getenv('PATH')
  235. nul = os.devnull
  236. snippet = '<s> <p> <o> .'
  237. if sys.platform == "win32":
  238. snippet = snippet.replace('<', '^<').replace('>', '^>')
  239. else:
  240. snippet = '"%s"' % snippet
  241. autowaf.run_tests(ctx, APPNAME, [
  242. 'sordi_static "file://%s/tests/manifest.ttl" > %s' % (srcdir, nul),
  243. 'sordi_static "%s/tests/UTF-8.ttl" > %s' % (srcdir, nul),
  244. 'sordi_static -v > %s' % nul,
  245. 'sordi_static -h > %s' % nul,
  246. 'sordi_static -s "<foo> a <#Thingie> ." file:///test > %s' % nul,
  247. 'echo %s | sordi_static - http://example.org/' % snippet,
  248. 'echo %s | sordi_static -o turtle - http://example.org/' % snippet,
  249. 'sordi_static %s > %s' % (nul, nul)],
  250. 0, name='sordi-cmd-good')
  251. # Test read error by reading a directory
  252. autowaf.run_test(ctx, APPNAME, 'sordi_static "file://%s/"' % srcdir,
  253. 1, name='read_error')
  254. # Test write error by writing to /dev/full
  255. if os.path.exists('/dev/full'):
  256. autowaf.run_test(ctx, APPNAME,
  257. 'sordi_static "file://%s/tests/good/manifest.ttl" > /dev/full' % srcdir,
  258. 1, name='write_error')
  259. autowaf.run_tests(ctx, APPNAME, [
  260. 'sordi_static > %s' % nul,
  261. 'sordi_static ftp://example.org/unsupported.ttl > %s' % nul,
  262. 'sordi_static -i > %s' % nul,
  263. 'sordi_static -o > %s' % nul,
  264. 'sordi_static -z > %s' % nul,
  265. 'sordi_static -p > %s' % nul,
  266. 'sordi_static -c > %s' % nul,
  267. 'sordi_static -i illegal > %s' % nul,
  268. 'sordi_static -o illegal > %s' % nul,
  269. 'sordi_static -i turtle > %s' % nul,
  270. 'sordi_static -i ntriples > %s' % nul,
  271. 'echo "<s> <p> <o> ." | sordi_static -',
  272. 'sordi_static /no/such/file > %s' % nul],
  273. 1, name='sordi-cmd-bad')
  274. Logs.pprint('GREEN', '')
  275. autowaf.run_test(ctx, APPNAME, 'sord_test', name='sord_test')
  276. commands = []
  277. for test in good_tests:
  278. base_uri = 'http://www.w3.org/2001/sw/DataAccess/df1/' + test.replace('\\', '/')
  279. commands += [ 'sordi_static "%s" "%s" > %s.out' % (
  280. os.path.join(srcdir, test), base_uri, test) ]
  281. autowaf.run_tests(ctx, APPNAME, commands, 0, name='good')
  282. verify_tests = []
  283. for test in good_tests:
  284. out_filename = test + '.out'
  285. cmp_filename = srcdir + '/' + test.replace('.ttl', '.out')
  286. if not os.access(out_filename, os.F_OK):
  287. Logs.pprint('RED', '** FAIL %s output is missing' % test)
  288. verify_tests += [[out_filename, 1]]
  289. else:
  290. out_lines = sorted(open(out_filename).readlines())
  291. cmp_lines = sorted(open(cmp_filename).readlines())
  292. if out_lines != cmp_lines:
  293. verify_tests += [[out_filename, 1]]
  294. else:
  295. verify_tests += [[out_filename, 0]]
  296. autowaf.run_tests(ctx, APPNAME, verify_tests, name='verify_turtle_to_ntriples')
  297. autowaf.post_test(ctx, APPNAME)
  298. def posts(ctx):
  299. path = str(ctx.path.abspath())
  300. autowaf.news_to_posts(
  301. os.path.join(path, 'NEWS'),
  302. {'title' : 'Sord',
  303. 'description' : autowaf.get_blurb(os.path.join(path, 'README')),
  304. 'dist_pattern' : 'http://download.drobilla.net/sord-%s.tar.bz2'},
  305. { 'Author' : 'drobilla',
  306. 'Tags' : 'Hacking, RDF, Sord' },
  307. os.path.join(out, 'posts'))