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