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