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