wscript 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. #!/usr/bin/env python
  2. APPNAME = 'ntdb'
  3. VERSION = '1.0'
  4. blddir = 'bin'
  5. import sys, os
  6. # find the buildtools directory
  7. srcdir = '.'
  8. while not os.path.exists(srcdir+'/buildtools') and len(srcdir.split('/')) < 5:
  9. srcdir = srcdir + '/..'
  10. sys.path.insert(0, srcdir + '/buildtools/wafsamba')
  11. import wafsamba, samba_dist, Options, Logs, glob
  12. samba_dist.DIST_DIRS('lib/ntdb:. lib/replace:lib/replace lib/ccan:lib/ccan buildtools:buildtools')
  13. def set_options(opt):
  14. opt.BUILTIN_DEFAULT('replace,ccan')
  15. opt.PRIVATE_EXTENSION_DEFAULT('ntdb', noextension='ntdb')
  16. opt.RECURSE('lib/replace')
  17. opt.add_option('--valgrind',
  18. help=("use valgrind on tests programs"),
  19. action="store_true", dest='VALGRIND', default=False)
  20. opt.add_option('--valgrind-log',
  21. help=("where to put the valgrind log"),
  22. action="store", dest='VALGRINDLOG', default=None)
  23. if opt.IN_LAUNCH_DIR():
  24. opt.add_option('--disable-python',
  25. help=("disable the pyntdb module"),
  26. action="store_true", dest='disable_python', default=False)
  27. def configure(conf):
  28. conf.RECURSE('lib/replace')
  29. conf.RECURSE('lib/ccan')
  30. conf.env.NTDB_TEST_RUN_SRC=['test/run-001-encode.c',
  31. 'test/run-001-fls.c',
  32. 'test/run-01-new_database.c',
  33. 'test/run-02-expand.c',
  34. 'test/run-03-coalesce.c',
  35. 'test/run-04-basichash.c',
  36. 'test/run-05-readonly-open.c',
  37. 'test/run-10-simple-store.c',
  38. 'test/run-11-simple-fetch.c',
  39. 'test/run-12-check.c',
  40. 'test/run-15-append.c',
  41. 'test/run-25-hashoverload.c',
  42. 'test/run-30-exhaust-before-expand.c',
  43. 'test/run-35-convert.c',
  44. 'test/run-50-multiple-freelists.c',
  45. 'test/run-56-open-during-transaction.c',
  46. 'test/run-57-die-during-transaction.c',
  47. 'test/run-64-bit-tdb.c',
  48. 'test/run-90-get-set-attributes.c',
  49. 'test/run-capabilities.c',
  50. 'test/run-expand-in-transaction.c',
  51. 'test/run-features.c',
  52. 'test/run-lockall.c',
  53. 'test/run-remap-in-read_traverse.c',
  54. 'test/run-seed.c',
  55. 'test/run-tdb_errorstr.c',
  56. 'test/run-tdb_foreach.c',
  57. 'test/run-traverse.c']
  58. conf.env.NTDB_TEST_API_SRC=['test/api-12-store.c',
  59. 'test/api-13-delete.c',
  60. 'test/api-14-exists.c',
  61. 'test/api-16-wipe_all.c',
  62. 'test/api-20-alloc-attr.c',
  63. 'test/api-21-parse_record.c',
  64. 'test/api-55-transaction.c',
  65. 'test/api-60-noop-transaction.c',
  66. 'test/api-80-tdb_fd.c',
  67. 'test/api-81-seqnum.c',
  68. 'test/api-82-lockattr.c',
  69. 'test/api-83-openhook.c',
  70. 'test/api-91-get-stats.c',
  71. 'test/api-92-get-set-readonly.c',
  72. 'test/api-93-repack.c',
  73. 'test/api-94-expand-during-parse.c',
  74. 'test/api-95-read-only-during-parse.c',
  75. 'test/api-add-remove-flags.c',
  76. 'test/api-check-callback.c',
  77. 'test/api-firstkey-nextkey.c',
  78. 'test/api-fork-test.c',
  79. 'test/api-locktimeout.c',
  80. 'test/api-missing-entries.c',
  81. 'test/api-open-multiple-times.c',
  82. 'test/api-record-expand.c',
  83. 'test/api-simple-delete.c',
  84. 'test/api-summary.c']
  85. conf.env.NTDB_TEST_API_PY=['test/python-api.py']
  86. conf.env.NTDB_TEST_API_HELPER_SRC=['test/helpapi-external-agent.c']
  87. conf.env.NTDB_TEST_RUN_HELPER_SRC=['test/helprun-external-agent.c',
  88. 'test/helprun-layout.c']
  89. conf.env.NTDB_TEST_HELPER_SRC=['test/external-agent.c',
  90. 'test/failtest_helper.c',
  91. 'test/lock-tracking.c',
  92. 'test/logging.c',
  93. 'test/tap-interface.c']
  94. conf.env.standalone_ntdb = conf.IN_LAUNCH_DIR()
  95. conf.env.disable_python = getattr(Options.options, 'disable_python', False)
  96. if not conf.env.standalone_ntdb:
  97. if conf.CHECK_BUNDLED_SYSTEM('ntdb', minversion=VERSION,
  98. implied_deps='replace'):
  99. conf.define('USING_SYSTEM_NTDB', 1)
  100. if conf.CHECK_BUNDLED_SYSTEM_PYTHON('pyntdb', 'ntdb', minversion=VERSION):
  101. conf.define('USING_SYSTEM_PYNTDB', 1)
  102. if not conf.env.disable_python:
  103. # also disable if we don't have the python libs installed
  104. conf.find_program('python', var='PYTHON')
  105. conf.check_tool('python')
  106. conf.check_python_version((2,4,2))
  107. conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
  108. if not conf.env.HAVE_PYTHON_H:
  109. Logs.warn('Disabling pyntdb as python devel libs not found')
  110. conf.env.disable_python = True
  111. conf.CHECK_XSLTPROC_MANPAGES()
  112. # This make #include <ccan/...> work.
  113. conf.ADD_EXTRA_INCLUDES('''#lib''')
  114. conf.SAMBA_CONFIG_H()
  115. def build(bld):
  116. bld.RECURSE('lib/replace')
  117. bld.RECURSE('lib/ccan')
  118. if bld.env.standalone_ntdb:
  119. bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
  120. private_library = False
  121. else:
  122. private_library = True
  123. SRC = '''check.c free.c hash.c io.c lock.c open.c
  124. summary.c ntdb.c transaction.c traverse.c'''
  125. if not bld.CONFIG_SET('USING_SYSTEM_NTDB'):
  126. NTDB_CCAN='ccan-likely ccan-ilog ccan-hash ccan-tally'
  127. bld.SAMBA_LIBRARY('ntdb',
  128. SRC,
  129. deps='replace ' + NTDB_CCAN ,
  130. includes='.',
  131. abi_directory='ABI',
  132. abi_match='ntdb_*',
  133. hide_symbols=True,
  134. vnum=VERSION,
  135. public_headers='ntdb.h',
  136. public_headers_install=not private_library,
  137. pc_files='ntdb.pc',
  138. private_library=private_library,
  139. manpages='man/ntdb.3')
  140. bld.SAMBA_BINARY('ntdbtorture',
  141. 'tools/ntdbtorture.c',
  142. deps='ntdb ccan-err',
  143. install=False)
  144. bld.SAMBA_BINARY('ntdbtool',
  145. 'tools/ntdbtool.c',
  146. deps='ntdb', manpages='man/ntdbtool.8')
  147. bld.SAMBA_BINARY('ntdbdump',
  148. 'tools/ntdbdump.c',
  149. deps='ntdb', manpages='man/ntdbdump.8')
  150. bld.SAMBA_BINARY('ntdbrestore',
  151. 'tools/ntdbrestore.c',
  152. deps='ntdb', manpages='man/ntdbrestore.8')
  153. bld.SAMBA_BINARY('ntdbbackup',
  154. 'tools/ntdbbackup.c',
  155. deps='ntdb', manpages='man/ntdbbackup.8')
  156. if bld.env.DEVELOPER_MODE:
  157. # FIXME: We need CCAN for some API tests, but waf thinks it's
  158. # already available via ntdb. It is, but not publicly.
  159. # Workaround is to build a private, non-hiding version.
  160. bld.SAMBA_SUBSYSTEM('ntdb-testing',
  161. SRC,
  162. deps='replace ' + NTDB_CCAN,
  163. includes='.')
  164. bld.SAMBA_SUBSYSTEM('ntdb-test-helpers',
  165. bld.env.NTDB_TEST_HELPER_SRC,
  166. deps='replace',
  167. allow_warnings=True)
  168. bld.SAMBA_SUBSYSTEM('ntdb-run-helpers',
  169. bld.env.NTDB_TEST_RUN_HELPER_SRC,
  170. deps='replace')
  171. bld.SAMBA_SUBSYSTEM('ntdb-api-helpers',
  172. bld.env.NTDB_TEST_API_HELPER_SRC,
  173. deps='replace')
  174. for f in bld.env.NTDB_TEST_RUN_SRC:
  175. base = os.path.splitext(os.path.basename(f))[0]
  176. bld.SAMBA_BINARY('ntdb-' + base, f,
  177. deps=NTDB_CCAN + ' ccan-failtest ntdb-test-helpers ntdb-run-helpers',
  178. install=False)
  179. for f in bld.env.NTDB_TEST_API_SRC:
  180. base = os.path.splitext(os.path.basename(f))[0]
  181. bld.SAMBA_BINARY('ntdb-' + base, f,
  182. deps='ntdb-test-helpers ntdb-api-helpers ntdb-testing',
  183. install=False)
  184. if not bld.CONFIG_SET('USING_SYSTEM_PYNTDB'):
  185. bld.SAMBA_PYTHON('pyntdb',
  186. source='pyntdb.c',
  187. deps='ntdb',
  188. enabled=not bld.env.disable_python,
  189. realname='ntdb.so',
  190. cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
  191. def testonly(ctx):
  192. '''run ntdb testsuite'''
  193. import Utils, samba_utils, shutil
  194. ecode = 0;
  195. env = samba_utils.LOAD_ENVIRONMENT()
  196. if env.standalone_ntdb:
  197. # FIXME: This is horrible :(
  198. test_prefix = "%s/st" % (Utils.g_module.blddir)
  199. shutil.rmtree(test_prefix, ignore_errors=True)
  200. os.makedirs(test_prefix)
  201. # Create scratch directory for tests.
  202. testdir = os.path.join(test_prefix, 'ntdb-tests')
  203. samba_utils.mkdir_p(testdir)
  204. # Symlink back to source dir so it can find tests in test/
  205. link = os.path.join(testdir, 'test')
  206. if not os.path.exists(link):
  207. os.symlink(os.path.abspath(os.path.join(env.cwd, 'test')), link)
  208. if env.options['VALGRIND']:
  209. os.environ['VALGRIND'] = 'valgrind -q --num-callers=30 --error-exitcode=11'
  210. if env.options['VALGRINDLOG']:
  211. os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG
  212. for f in env.NTDB_TEST_RUN_SRC + env.NTDB_TEST_API_SRC:
  213. name = "ntdb-" + os.path.splitext(os.path.basename(f))[0]
  214. cmd = "cd " + testdir + " && $VALGRIND " + os.path.abspath(os.path.join(Utils.g_module.blddir, name)) + " > test-output 2>&1"
  215. print("..." + f)
  216. ret = samba_utils.RUN_COMMAND(cmd)
  217. if ret != 0:
  218. print("%s (%s) failed:" % (name, f))
  219. samba_utils.RUN_COMMAND("cat " + os.path.join(testdir, 'test-output'))
  220. ecode = ret;
  221. break;
  222. if not env.disable_python:
  223. for f in env.NTDB_TEST_API_PY:
  224. print("..." + f)
  225. cmd = "cd " + testdir + " && PYTHONPATH=%s %s %s > test-output 2>&1" % (
  226. os.path.abspath(os.path.join(Utils.g_module.blddir, "python")),
  227. env["PYTHON"], os.path.abspath(f))
  228. ret = samba_utils.RUN_COMMAND(cmd)
  229. if ret != 0:
  230. print("%s (%s) failed:" % (name, f))
  231. samba_utils.RUN_COMMAND("cat " + os.path.join(testdir, 'test-output'))
  232. ecode = ret
  233. break
  234. sys.exit(ecode)
  235. # WAF doesn't build the unit tests for this, maybe because they don't link with ntdb?
  236. # This forces it
  237. def test(ctx):
  238. import Scripting
  239. Scripting.commands.append('build')
  240. Scripting.commands.append('testonly')
  241. def dist():
  242. '''makes a tarball for distribution'''
  243. samba_dist.dist()
  244. def reconfigure(ctx):
  245. '''reconfigure if config scripts have changed'''
  246. import samba_utils
  247. samba_utils.reconfigure(ctx)