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