tdb: version 1.3.4
[Samba.git] / lib / tdb / wscript
blobb283795870b7959198308ba330bc72a98388fc5b
1 #!/usr/bin/env python
3 APPNAME = 'tdb'
4 VERSION = '1.3.4'
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
18 samba_dist.DIST_DIRS('lib/tdb:. lib/replace:lib/replace buildtools:buildtools')
20 tdb1_unit_tests = [
21 'run-3G-file',
22 'run-bad-tdb-header',
23 'run',
24 'run-check',
25 'run-corrupt',
26 'run-die-during-transaction',
27 'run-endian',
28 'run-incompatible',
29 'run-nested-transactions',
30 'run-nested-traverse',
31 'run-no-lock-during-traverse',
32 'run-oldhash',
33 'run-open-during-transaction',
34 'run-readonly-check',
35 'run-rescue',
36 'run-rescue-find_entry',
37 'run-rwlock-check',
38 'run-summary',
39 'run-transaction-expand',
40 'run-traverse-in-transaction',
41 'run-wronghash-fail',
42 'run-zero-append',
43 'run-marklock-deadlock',
44 'run-mutex-openflags2',
45 'run-mutex-trylock',
46 'run-mutex-allrecord-bench',
47 'run-mutex-allrecord-trylock',
48 'run-mutex-allrecord-block',
49 'run-mutex-transaction1',
50 'run-mutex-die',
51 'run-mutex1',
54 def set_options(opt):
55 opt.BUILTIN_DEFAULT('replace')
56 opt.PRIVATE_EXTENSION_DEFAULT('tdb', noextension='tdb')
57 opt.RECURSE('lib/replace')
58 opt.add_option('--disable-tdb-mutex-locking',
59 help=("Disable the use of pthread robust mutexes"),
60 action="store_true", dest='disable_tdb_mutex_locking',
61 default=False)
62 if opt.IN_LAUNCH_DIR():
63 opt.add_option('--disable-python',
64 help=("disable the pytdb module"),
65 action="store_true", dest='disable_python', default=False)
68 def configure(conf):
69 conf.env.disable_tdb_mutex_locking = getattr(Options.options,
70 'disable_tdb_mutex_locking',
71 False)
72 if not conf.env.disable_tdb_mutex_locking:
73 conf.env.replace_add_global_pthread = True
74 conf.RECURSE('lib/replace')
76 conf.env.standalone_tdb = conf.IN_LAUNCH_DIR()
77 conf.env.building_tdb = True
79 if not conf.env.standalone_tdb:
80 if conf.CHECK_BUNDLED_SYSTEM_PKG('tdb', minversion=VERSION,
81 implied_deps='replace'):
82 conf.define('USING_SYSTEM_TDB', 1)
83 conf.env.building_tdb = False
84 if conf.CHECK_BUNDLED_SYSTEM_PYTHON('pytdb', 'tdb', minversion=VERSION):
85 conf.define('USING_SYSTEM_PYTDB', 1)
87 conf.env.disable_python = getattr(Options.options, 'disable_python', False)
89 if (conf.CONFIG_SET('HAVE_ROBUST_MUTEXES') and
90 conf.env.building_tdb and
91 not conf.env.disable_tdb_mutex_locking):
92 conf.define('USE_TDB_MUTEX_LOCKING', 1)
94 conf.CHECK_XSLTPROC_MANPAGES()
96 if not conf.env.disable_python:
97 # also disable if we don't have the python libs installed
98 conf.find_program('python', var='PYTHON')
99 conf.check_tool('python')
100 conf.check_python_version((2,4,2))
101 conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
102 if not conf.env.HAVE_PYTHON_H:
103 Logs.warn('Disabling pytdb as python devel libs not found')
104 conf.env.disable_python = True
106 conf.SAMBA_CONFIG_H()
108 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
110 def build(bld):
111 bld.RECURSE('lib/replace')
113 COMMON_FILES='''check.c error.c tdb.c traverse.c
114 freelistcheck.c lock.c dump.c freelist.c
115 io.c open.c transaction.c hash.c summary.c rescue.c
116 mutex.c'''
118 COMMON_SRC = bld.SUBDIR('common', COMMON_FILES)
120 if bld.env.standalone_tdb:
121 bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
122 private_library = False
123 else:
124 private_library = True
126 if not bld.CONFIG_SET('USING_SYSTEM_TDB'):
128 tdb_deps = 'replace'
130 if bld.CONFIG_SET('USE_TDB_MUTEX_LOCKING'):
131 tdb_deps += ' pthread'
133 bld.SAMBA_LIBRARY('tdb',
134 COMMON_SRC,
135 deps=tdb_deps,
136 includes='include',
137 abi_directory='ABI',
138 abi_match='tdb_*',
139 hide_symbols=True,
140 vnum=VERSION,
141 public_headers='include/tdb.h',
142 public_headers_install=not private_library,
143 pc_files='tdb.pc',
144 private_library=private_library)
146 bld.SAMBA_BINARY('tdbtorture',
147 'tools/tdbtorture.c',
148 'tdb',
149 install=False)
151 bld.SAMBA_BINARY('tdbrestore',
152 'tools/tdbrestore.c',
153 'tdb', manpages='man/tdbrestore.8')
155 bld.SAMBA_BINARY('tdbdump',
156 'tools/tdbdump.c',
157 'tdb', manpages='man/tdbdump.8')
159 bld.SAMBA_BINARY('tdbbackup',
160 'tools/tdbbackup.c',
161 'tdb',
162 manpages='man/tdbbackup.8')
164 bld.SAMBA_BINARY('tdbtool',
165 'tools/tdbtool.c',
166 'tdb', manpages='man/tdbtool.8')
168 # FIXME: This hardcoded list is stupid, stupid, stupid.
169 bld.SAMBA_SUBSYSTEM('tdb-test-helpers',
170 'test/external-agent.c test/lock-tracking.c test/logging.c',
171 tdb_deps,
172 includes='include')
174 for t in tdb1_unit_tests:
175 b = "tdb1-" + t
176 s = "test/" + t + ".c"
177 bld.SAMBA_BINARY(b, s, 'replace tdb-test-helpers',
178 includes='include', install=False)
180 if not bld.CONFIG_SET('USING_SYSTEM_PYTDB'):
181 bld.SAMBA_PYTHON('pytdb',
182 'pytdb.c',
183 deps='tdb',
184 enabled=not bld.env.disable_python,
185 realname='tdb.so',
186 cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
188 def testonly(ctx):
189 '''run tdb testsuite'''
190 import Utils, samba_utils, shutil
191 ecode = 0
193 test_prefix = "%s/st" % (Utils.g_module.blddir)
194 shutil.rmtree(test_prefix, ignore_errors=True)
195 os.makedirs(test_prefix)
196 os.environ['TEST_DATA_PREFIX'] = test_prefix
198 env = samba_utils.LOAD_ENVIRONMENT()
199 # FIXME: This is horrible :(
200 if env.building_tdb:
201 # Create scratch directory for tests.
202 testdir = os.path.join(test_prefix, 'tdb-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)
209 for t in tdb1_unit_tests:
210 f = "tdb1-" + t
211 cmd = "cd " + testdir + " && " + os.path.abspath(os.path.join(Utils.g_module.blddir, f)) + " > test-output 2>&1"
212 print("..." + f)
213 ret = samba_utils.RUN_COMMAND(cmd)
214 if ret != 0:
215 print("%s failed:" % f)
216 samba_utils.RUN_COMMAND("cat " + os.path.join(testdir, 'test-output'))
217 ecode = ret
218 break
220 if ecode == 0:
221 cmd = os.path.join(Utils.g_module.blddir, 'tdbtorture')
222 ret = samba_utils.RUN_COMMAND(cmd)
223 print("testsuite returned %d" % ret)
224 if ret != 0:
225 ecode = ret
226 sys.exit(ecode)
228 # WAF doesn't build the unit tests for this, maybe because they don't link with tdb?
229 # This forces it
230 def test(ctx):
231 import Scripting
232 Scripting.commands.append('build')
233 Scripting.commands.append('testonly')
235 def dist():
236 '''makes a tarball for distribution'''
237 samba_dist.dist()
239 def reconfigure(ctx):
240 '''reconfigure if config scripts have changed'''
241 import samba_utils
242 samba_utils.reconfigure(ctx)