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