tdb: Make tdb_find circular-safe
[samba.git] / lib / tdb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'tdb'
4 VERSION = '1.3.16'
5
6 import sys, os
7
8 # find the buildtools directory
9 top = '.'
10 while not os.path.exists(top+'/buildtools') and len(top.split('/')) < 5:
11     top = top + '/..'
12 sys.path.insert(0, top + '/buildtools/wafsamba')
13
14 out = 'bin'
15
16 import wafsamba
17 from wafsamba import samba_dist, samba_utils
18 from waflib import Options, Logs, Context
19 import shutil
20
21 samba_dist.DIST_DIRS('lib/tdb:. lib/replace:lib/replace buildtools:buildtools third_party/waf:third_party/waf')
22
23 tdb1_unit_tests = [
24     'run-3G-file',
25     'run-bad-tdb-header',
26     'run',
27     'run-check',
28     'run-corrupt',
29     'run-die-during-transaction',
30     'run-endian',
31     'run-incompatible',
32     'run-nested-transactions',
33     'run-nested-traverse',
34     'run-no-lock-during-traverse',
35     'run-oldhash',
36     'run-open-during-transaction',
37     'run-readonly-check',
38     'run-rescue',
39     'run-rescue-find_entry',
40     'run-rdlock-upgrade',
41     'run-rwlock-check',
42     'run-summary',
43     'run-transaction-expand',
44     'run-traverse-in-transaction',
45     'run-wronghash-fail',
46     'run-zero-append',
47     'run-fcntl-deadlock',
48     'run-marklock-deadlock',
49     'run-allrecord-traverse-deadlock',
50     'run-mutex-openflags2',
51     'run-mutex-trylock',
52     'run-mutex-allrecord-bench',
53     'run-mutex-allrecord-trylock',
54     'run-mutex-allrecord-block',
55     'run-mutex-transaction1',
56     'run-mutex-die',
57     'run-mutex1',
58 ]
59
60 def options(opt):
61     opt.BUILTIN_DEFAULT('replace')
62     opt.PRIVATE_EXTENSION_DEFAULT('tdb', noextension='tdb')
63     opt.RECURSE('lib/replace')
64     opt.add_option('--disable-tdb-mutex-locking',
65                    help=("Disable the use of pthread robust mutexes"),
66                    action="store_true", dest='disable_tdb_mutex_locking',
67                    default=False)
68
69
70 def configure(conf):
71     conf.env.disable_tdb_mutex_locking = getattr(Options.options,
72                                                  'disable_tdb_mutex_locking',
73                                                  False)
74     if not conf.env.disable_tdb_mutex_locking:
75         conf.env.replace_add_global_pthread = True
76     conf.RECURSE('lib/replace')
77
78     conf.env.standalone_tdb = conf.IN_LAUNCH_DIR()
79     conf.env.building_tdb = True
80
81     if not conf.env.standalone_tdb:
82         if conf.CHECK_BUNDLED_SYSTEM_PKG('tdb', minversion=VERSION,
83                                      implied_deps='replace'):
84             conf.define('USING_SYSTEM_TDB', 1)
85             conf.env.building_tdb = False
86             if not conf.env.disable_python and \
87                 conf.CHECK_BUNDLED_SYSTEM_PYTHON('pytdb', 'tdb', minversion=VERSION):
88                 conf.define('USING_SYSTEM_PYTDB', 1)
89
90     if (conf.CONFIG_SET('HAVE_ROBUST_MUTEXES') and
91         conf.env.building_tdb and
92         not conf.env.disable_tdb_mutex_locking):
93         conf.define('USE_TDB_MUTEX_LOCKING', 1)
94
95     conf.CHECK_XSLTPROC_MANPAGES()
96
97     if not conf.env.disable_python:
98         # also disable if we don't have the python libs installed
99         conf.SAMBA_CHECK_PYTHON(mandatory=False)
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
105
106     conf.SAMBA_CONFIG_H()
107
108     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
109
110 def build(bld):
111     bld.RECURSE('lib/replace')
112
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'''
117
118     COMMON_SRC = bld.SUBDIR('common', COMMON_FILES)
119
120     if bld.env.standalone_tdb:
121         bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
122         private_library = False
123     else:
124         private_library = True
125
126     if not bld.CONFIG_SET('USING_SYSTEM_TDB'):
127
128         tdb_deps = 'replace'
129
130         if bld.CONFIG_SET('USE_TDB_MUTEX_LOCKING'):
131             tdb_deps += ' pthread'
132
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=('' if private_library else 'include/tdb.h'),
142                           public_headers_install=not private_library,
143                           pc_files='tdb.pc',
144                           private_library=private_library)
145
146         bld.SAMBA_BINARY('tdbtorture',
147                          'tools/tdbtorture.c',
148                          'tdb',
149                          install=False)
150
151         bld.SAMBA_BINARY('tdbrestore',
152                          'tools/tdbrestore.c',
153                          'tdb', manpages='man/tdbrestore.8')
154
155         bld.SAMBA_BINARY('tdbdump',
156                          'tools/tdbdump.c',
157                          'tdb', manpages='man/tdbdump.8')
158
159         bld.SAMBA_BINARY('tdbbackup',
160                          'tools/tdbbackup.c',
161                          'tdb',
162                          manpages='man/tdbbackup.8')
163
164         bld.SAMBA_BINARY('tdbtool',
165                          'tools/tdbtool.c',
166                          'tdb', manpages='man/tdbtool.8')
167
168         if bld.env.standalone_tdb:
169             # FIXME: This hardcoded list is stupid, stupid, stupid.
170             bld.SAMBA_SUBSYSTEM('tdb-test-helpers',
171                                 'test/external-agent.c test/lock-tracking.c test/logging.c',
172                                 tdb_deps,
173                                 includes='include')
174
175             for t in tdb1_unit_tests:
176                 b = "tdb1-" + t
177                 s = "test/" + t + ".c"
178                 bld.SAMBA_BINARY(b, s, 'replace tdb-test-helpers',
179                                  includes='include', install=False)
180
181     if not bld.CONFIG_SET('USING_SYSTEM_PYTDB'):
182         for env in bld.gen_python_environments(['PKGCONFIGDIR']):
183             bld.SAMBA_PYTHON('pytdb',
184                              'pytdb.c',
185                              deps='tdb',
186                              enabled=not bld.env.disable_python,
187                              realname='tdb.so',
188                              cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
189
190         if not bld.env.disable_python:
191             for env in bld.gen_python_environments(['PKGCONFIGDIR']):
192                 bld.SAMBA_SCRIPT('_tdb_text.py',
193                                  pattern='_tdb_text.py',
194                                  installdir='python')
195
196                 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_tdb_text.py')
197
198 def testonly(ctx):
199     '''run tdb testsuite'''
200     ecode = 0
201
202     blddir = Context.g_module.out
203     test_prefix = "%s/st" % (blddir)
204     shutil.rmtree(test_prefix, ignore_errors=True)
205     os.makedirs(test_prefix)
206     os.environ['TEST_DATA_PREFIX'] = test_prefix
207
208     env = samba_utils.LOAD_ENVIRONMENT()
209     # FIXME: This is horrible :(
210     if env.building_tdb:
211         # Create scratch directory for tests.
212         testdir = os.path.join(test_prefix, 'tdb-tests')
213         samba_utils.mkdir_p(testdir)
214         # Symlink back to source dir so it can find tests in test/
215         link = os.path.join(testdir, 'test')
216         if not os.path.exists(link):
217             os.symlink(ctx.path.make_node('test').abspath(), link)
218
219         sh_tests = ["test/test_tdbbackup.sh test/jenkins-be-hash.tdb"]
220
221         for sh_test in sh_tests:
222             cmd = "BINDIR={} {}".format(blddir, sh_test)
223             print("shell test: " + cmd)
224             ret = samba_utils.RUN_COMMAND(cmd)
225             if ret != 0:
226                 print("%s sh test failed" % cmd)
227                 ecode = ret
228                 break
229
230         for t in tdb1_unit_tests:
231             f = "tdb1-" + t
232             cmd = "cd " + testdir + " && " + os.path.abspath(os.path.join(blddir, f)) + " > test-output 2>&1"
233             print("..." + f)
234             ret = samba_utils.RUN_COMMAND(cmd)
235             if ret != 0:
236                 print("%s failed:" % f)
237                 samba_utils.RUN_COMMAND("cat " + os.path.join(testdir, 'test-output'))
238                 ecode = ret
239                 break
240
241     if ecode == 0:
242         cmd = os.path.join(blddir, 'tdbtorture')
243         ret = samba_utils.RUN_COMMAND(cmd)
244         print("testsuite returned %d" % ret)
245         if ret != 0:
246             ecode = ret
247
248     pyret = samba_utils.RUN_PYTHON_TESTS(['python/tests/simple.py'])
249     print("python testsuite returned %d" % pyret)
250     sys.exit(ecode or pyret)
251
252 # WAF doesn't build the unit tests for this, maybe because they don't link with tdb?
253 # This forces it
254 def test(ctx):
255     Options.commands.append('build')
256     Options.commands.append('testonly')
257
258 def dist():
259     '''makes a tarball for distribution'''
260     samba_dist.dist()
261
262 def reconfigure(ctx):
263     '''reconfigure if config scripts have changed'''
264     samba_utils.reconfigure(ctx)