tdb: Reproducer for Bug 11381
[obnox/samba/samba-obnox.git] / lib / tdb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'tdb'
4 VERSION = '1.3.6'
5
6 blddir = 'bin'
7
8 import sys, os
9
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')
15
16 import wafsamba, samba_dist, Options, Logs
17
18 samba_dist.DIST_DIRS('lib/tdb:. lib/replace:lib/replace buildtools:buildtools third_party/waf:third_party/waf')
19
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-allrecord-traverse-deadlock',
45     'run-mutex-openflags2',
46     'run-mutex-trylock',
47     'run-mutex-allrecord-bench',
48     'run-mutex-allrecord-trylock',
49     'run-mutex-allrecord-block',
50     'run-mutex-transaction1',
51     'run-mutex-die',
52     'run-mutex1',
53 ]
54
55 def set_options(opt):
56     opt.BUILTIN_DEFAULT('replace')
57     opt.PRIVATE_EXTENSION_DEFAULT('tdb', noextension='tdb')
58     opt.RECURSE('lib/replace')
59     opt.add_option('--disable-tdb-mutex-locking',
60                    help=("Disable the use of pthread robust mutexes"),
61                    action="store_true", dest='disable_tdb_mutex_locking',
62                    default=False)
63     if opt.IN_LAUNCH_DIR():
64         opt.add_option('--disable-python',
65                        help=("disable the pytdb module"),
66                        action="store_true", dest='disable_python', default=False)
67
68
69 def configure(conf):
70     conf.env.disable_tdb_mutex_locking = getattr(Options.options,
71                                                  'disable_tdb_mutex_locking',
72                                                  False)
73     if not conf.env.disable_tdb_mutex_locking:
74         conf.env.replace_add_global_pthread = True
75     conf.RECURSE('lib/replace')
76
77     conf.env.standalone_tdb = conf.IN_LAUNCH_DIR()
78     conf.env.building_tdb = True
79
80     if not conf.env.standalone_tdb:
81         if conf.CHECK_BUNDLED_SYSTEM_PKG('tdb', minversion=VERSION,
82                                      implied_deps='replace'):
83             conf.define('USING_SYSTEM_TDB', 1)
84             conf.env.building_tdb = False
85             if conf.CHECK_BUNDLED_SYSTEM_PYTHON('pytdb', 'tdb', minversion=VERSION):
86                 conf.define('USING_SYSTEM_PYTDB', 1)
87
88     conf.env.disable_python = getattr(Options.options, 'disable_python', False)
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.find_program('python', var='PYTHON')
100         conf.check_tool('python')
101         conf.check_python_version((2,4,2))
102         conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
103         if not conf.env.HAVE_PYTHON_H:
104             Logs.warn('Disabling pytdb as python devel libs not found')
105             conf.env.disable_python = True
106
107     conf.SAMBA_CONFIG_H()
108
109     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
110
111 def build(bld):
112     bld.RECURSE('lib/replace')
113
114     COMMON_FILES='''check.c error.c tdb.c traverse.c
115                     freelistcheck.c lock.c dump.c freelist.c
116                     io.c open.c transaction.c hash.c summary.c rescue.c
117                     mutex.c'''
118
119     COMMON_SRC = bld.SUBDIR('common', COMMON_FILES)
120
121     if bld.env.standalone_tdb:
122         bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
123         private_library = False
124     else:
125         private_library = True
126
127     if not bld.CONFIG_SET('USING_SYSTEM_TDB'):
128
129         tdb_deps = 'replace'
130
131         if bld.CONFIG_SET('USE_TDB_MUTEX_LOCKING'):
132             tdb_deps += ' pthread'
133
134         bld.SAMBA_LIBRARY('tdb',
135                           COMMON_SRC,
136                           deps=tdb_deps,
137                           includes='include',
138                           abi_directory='ABI',
139                           abi_match='tdb_*',
140                           hide_symbols=True,
141                           vnum=VERSION,
142                           public_headers='include/tdb.h',
143                           public_headers_install=not private_library,
144                           pc_files='tdb.pc',
145                           private_library=private_library)
146
147         bld.SAMBA_BINARY('tdbtorture',
148                          'tools/tdbtorture.c',
149                          'tdb',
150                          install=False)
151
152         bld.SAMBA_BINARY('tdbrestore',
153                          'tools/tdbrestore.c',
154                          'tdb', manpages='man/tdbrestore.8')
155
156         bld.SAMBA_BINARY('tdbdump',
157                          'tools/tdbdump.c',
158                          'tdb', manpages='man/tdbdump.8')
159
160         bld.SAMBA_BINARY('tdbbackup',
161                          'tools/tdbbackup.c',
162                          'tdb',
163                          manpages='man/tdbbackup.8')
164
165         bld.SAMBA_BINARY('tdbtool',
166                          'tools/tdbtool.c',
167                          'tdb', manpages='man/tdbtool.8')
168
169         if bld.env.standalone_tdb:
170             # FIXME: This hardcoded list is stupid, stupid, stupid.
171             bld.SAMBA_SUBSYSTEM('tdb-test-helpers',
172                                 'test/external-agent.c test/lock-tracking.c test/logging.c',
173                                 tdb_deps,
174                                 includes='include')
175
176             for t in tdb1_unit_tests:
177                 b = "tdb1-" + t
178                 s = "test/" + t + ".c"
179                 bld.SAMBA_BINARY(b, s, 'replace tdb-test-helpers',
180                                  includes='include', install=False)
181
182     if not bld.CONFIG_SET('USING_SYSTEM_PYTDB'):
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 def testonly(ctx):
191     '''run tdb testsuite'''
192     import Utils, samba_utils, shutil
193     ecode = 0
194
195     test_prefix = "%s/st" % (Utils.g_module.blddir)
196     shutil.rmtree(test_prefix, ignore_errors=True)
197     os.makedirs(test_prefix)
198     os.environ['TEST_DATA_PREFIX'] = test_prefix
199
200     env = samba_utils.LOAD_ENVIRONMENT()
201     # FIXME: This is horrible :(
202     if env.building_tdb:
203         # Create scratch directory for tests.
204         testdir = os.path.join(test_prefix, 'tdb-tests')
205         samba_utils.mkdir_p(testdir)
206         # Symlink back to source dir so it can find tests in test/
207         link = os.path.join(testdir, 'test')
208         if not os.path.exists(link):
209             os.symlink(os.path.abspath(os.path.join(env.cwd, 'test')), link)
210
211         for t in tdb1_unit_tests:
212             f = "tdb1-" + t
213             cmd = "cd " + testdir + " && " + os.path.abspath(os.path.join(Utils.g_module.blddir, f)) + " > test-output 2>&1"
214             print("..." + f)
215             ret = samba_utils.RUN_COMMAND(cmd)
216             if ret != 0:
217                 print("%s failed:" % f)
218                 samba_utils.RUN_COMMAND("cat " + os.path.join(testdir, 'test-output'))
219                 ecode = ret
220                 break
221
222     if ecode == 0:
223         cmd = os.path.join(Utils.g_module.blddir, 'tdbtorture')
224         ret = samba_utils.RUN_COMMAND(cmd)
225         print("testsuite returned %d" % ret)
226         if ret != 0:
227             ecode = ret
228     sys.exit(ecode)
229
230 # WAF doesn't build the unit tests for this, maybe because they don't link with tdb?
231 # This forces it
232 def test(ctx):
233     import Scripting
234     Scripting.commands.append('build')
235     Scripting.commands.append('testonly')
236
237 def dist():
238     '''makes a tarball for distribution'''
239     samba_dist.dist()
240
241 def reconfigure(ctx):
242     '''reconfigure if config scripts have changed'''
243     import samba_utils
244     samba_utils.reconfigure(ctx)