Merge branch 'master' of ctdb into 'master' of samba
[samba.git] / lib / tdb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'tdb'
4 VERSION = '1.2.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')
19
20 def set_options(opt):
21     opt.BUILTIN_DEFAULT('replace')
22     opt.PRIVATE_EXTENSION_DEFAULT('tdb', noextension='tdb')
23     opt.RECURSE('lib/replace')
24     if opt.IN_LAUNCH_DIR():
25         opt.add_option('--disable-python',
26                        help=("disable the pytdb module"),
27                        action="store_true", dest='disable_python', default=False)
28
29
30 def configure(conf):
31     conf.RECURSE('lib/replace')
32
33     conf.env.standalone_tdb = conf.IN_LAUNCH_DIR()
34     conf.env.building_tdb = True
35
36     if not conf.env.standalone_tdb:
37         if conf.CHECK_BUNDLED_SYSTEM_PKG('tdb', minversion=VERSION,
38                                      implied_deps='replace'):
39             conf.define('USING_SYSTEM_TDB', 1)
40             conf.env.building_tdb = False
41             if conf.CHECK_BUNDLED_SYSTEM_PYTHON('pytdb', 'tdb', minversion=VERSION):
42                 conf.define('USING_SYSTEM_PYTDB', 1)
43
44     conf.env.disable_python = getattr(Options.options, 'disable_python', False)
45
46     conf.CHECK_XSLTPROC_MANPAGES()
47
48     if not conf.env.disable_python:
49         # also disable if we don't have the python libs installed
50         conf.find_program('python', var='PYTHON')
51         conf.check_tool('python')
52         conf.check_python_version((2,4,2))
53         conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
54         if not conf.env.HAVE_PYTHON_H:
55             Logs.warn('Disabling pytdb as python devel libs not found')
56             conf.env.disable_python = True
57
58     conf.SAMBA_CONFIG_H()
59
60     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
61
62 def build(bld):
63     bld.RECURSE('lib/replace')
64
65     COMMON_SRC = bld.SUBDIR('common',
66                             '''check.c error.c tdb.c traverse.c
67                             freelistcheck.c lock.c dump.c freelist.c
68                             io.c open.c transaction.c hash.c summary.c rescue.c''')
69
70     if bld.env.standalone_tdb:
71         bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
72         private_library = False
73     else:
74         private_library = True
75
76     if not bld.CONFIG_SET('USING_SYSTEM_TDB'):
77         bld.SAMBA_LIBRARY('tdb',
78                           COMMON_SRC,
79                           deps='replace',
80                           includes='include',
81                           abi_directory='ABI',
82                           abi_match='tdb_*',
83                           hide_symbols=True,
84                           vnum=VERSION,
85                           public_headers='include/tdb.h',
86                           public_headers_install=not private_library,
87                           pc_files='tdb.pc',
88                           private_library=private_library)
89
90         bld.SAMBA_BINARY('tdbtorture',
91                          'tools/tdbtorture.c',
92                          'tdb',
93                          install=False)
94
95         bld.SAMBA_BINARY('tdbrestore',
96                          'tools/tdbrestore.c',
97                          'tdb', manpages='man/tdbrestore.8')
98
99         bld.SAMBA_BINARY('tdbdump',
100                          'tools/tdbdump.c',
101                          'tdb', manpages='man/tdbdump.8')
102
103         bld.SAMBA_BINARY('tdbbackup',
104                          'tools/tdbbackup.c',
105                          'tdb',
106                          manpages='man/tdbbackup.8')
107
108         bld.SAMBA_BINARY('tdbtool',
109                          'tools/tdbtool.c',
110                          'tdb', manpages='man/tdbtool.8')
111
112         # FIXME: This hardcoded list is stupid, stupid, stupid.
113         bld.SAMBA_SUBSYSTEM('tdb-test-helpers',
114                             'test/external-agent.c test/lock-tracking.c test/logging.c',
115                             'replace',
116                             includes='include')
117
118         bld.SAMBA_BINARY('tdb1-run-3G-file', 'test/run-3G-file.c',
119                          'replace tdb-test-helpers', includes='include', install=False)
120         bld.SAMBA_BINARY('tdb1-run-bad-tdb-header', 'test/run-bad-tdb-header.c',
121                          'replace tdb-test-helpers', includes='include', install=False)
122         bld.SAMBA_BINARY('tdb1-run', 'test/run.c',
123                          'replace tdb-test-helpers', includes='include', install=False)
124         bld.SAMBA_BINARY('tdb1-run-check', 'test/run-check.c',
125                          'replace tdb-test-helpers', includes='include', install=False)
126         bld.SAMBA_BINARY('tdb1-run-corrupt', 'test/run-corrupt.c',
127                          'replace tdb-test-helpers', includes='include', install=False)
128         bld.SAMBA_BINARY('tdb1-run-die-during-transaction', 'test/run-die-during-transaction.c',
129                          'replace tdb-test-helpers', includes='include', install=False)
130         bld.SAMBA_BINARY('tdb1-run-endian', 'test/run-endian.c',
131                          'replace tdb-test-helpers', includes='include', install=False)
132         bld.SAMBA_BINARY('tdb1-run-incompatible', 'test/run-incompatible.c',
133                          'replace tdb-test-helpers', includes='include', install=False)
134         bld.SAMBA_BINARY('tdb1-run-nested-transactions', 'test/run-nested-transactions.c',
135                          'replace tdb-test-helpers', includes='include', install=False)
136         bld.SAMBA_BINARY('tdb1-run-nested-traverse', 'test/run-nested-traverse.c',
137                          'replace tdb-test-helpers', includes='include', install=False)
138         bld.SAMBA_BINARY('tdb1-run-no-lock-during-traverse', 'test/run-no-lock-during-traverse.c',
139                          'replace tdb-test-helpers', includes='include', install=False)
140         bld.SAMBA_BINARY('tdb1-run-oldhash', 'test/run-oldhash.c',
141                          'replace tdb-test-helpers', includes='include', install=False)
142         bld.SAMBA_BINARY('tdb1-run-open-during-transaction', 'test/run-open-during-transaction.c',
143                          'replace tdb-test-helpers', includes='include', install=False)
144         bld.SAMBA_BINARY('tdb1-run-readonly-check', 'test/run-readonly-check.c',
145                          'replace tdb-test-helpers', includes='include', install=False)
146         bld.SAMBA_BINARY('tdb1-run-rescue', 'test/run-rescue.c',
147                          'replace tdb-test-helpers', includes='include', install=False)
148         bld.SAMBA_BINARY('tdb1-run-rescue-find_entry', 'test/run-rescue-find_entry.c',
149                          'replace tdb-test-helpers', includes='include', install=False)
150         bld.SAMBA_BINARY('tdb1-run-rwlock-check', 'test/run-rwlock-check.c',
151                          'replace tdb-test-helpers', includes='include', install=False)
152         bld.SAMBA_BINARY('tdb1-run-summary', 'test/run-summary.c',
153                          'replace tdb-test-helpers', includes='include', install=False)
154         bld.SAMBA_BINARY('tdb1-run-transaction-expand', 'test/run-transaction-expand.c',
155                          'replace tdb-test-helpers', includes='include', install=False)
156         bld.SAMBA_BINARY('tdb1-run-traverse-in-transaction', 'test/run-traverse-in-transaction.c',
157                          'replace tdb-test-helpers', includes='include', install=False)
158         bld.SAMBA_BINARY('tdb1-run-wronghash-fail', 'test/run-wronghash-fail.c',
159                          'replace tdb-test-helpers', includes='include', install=False)
160         bld.SAMBA_BINARY('tdb1-run-zero-append', 'test/run-zero-append.c',
161                          'replace tdb-test-helpers', includes='include', install=False)
162
163     if not bld.CONFIG_SET('USING_SYSTEM_PYTDB'):
164         bld.SAMBA_PYTHON('pytdb',
165                          'pytdb.c',
166                          deps='tdb',
167                          enabled=not bld.env.disable_python,
168                          realname='tdb.so',
169                          cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
170
171 def testonly(ctx):
172     '''run tdb testsuite'''
173     import Utils, samba_utils, shutil
174     ecode = 0
175
176     test_prefix = "%s/st" % (Utils.g_module.blddir)
177     shutil.rmtree(test_prefix, ignore_errors=True)
178     os.makedirs(test_prefix)
179     os.environ['TEST_DATA_PREFIX'] = test_prefix
180
181     env = samba_utils.LOAD_ENVIRONMENT()
182     # FIXME: This is horrible :(
183     if env.building_tdb:
184         # Create scratch directory for tests.
185         testdir = os.path.join(test_prefix, 'tdb-tests')
186         samba_utils.mkdir_p(testdir)
187         # Symlink back to source dir so it can find tests in test/
188         link = os.path.join(testdir, 'test')
189         if not os.path.exists(link):
190             os.symlink(os.path.abspath(os.path.join(env.cwd, 'test')), link)
191
192         for f in 'tdb1-run-3G-file', 'tdb1-run-bad-tdb-header', 'tdb1-run', 'tdb1-run-check', 'tdb1-run-corrupt', 'tdb1-run-die-during-transaction', 'tdb1-run-endian', 'tdb1-run-incompatible', 'tdb1-run-nested-transactions', 'tdb1-run-nested-traverse', 'tdb1-run-no-lock-during-traverse', 'tdb1-run-oldhash', 'tdb1-run-open-during-transaction', 'tdb1-run-readonly-check', 'tdb1-run-rescue', 'tdb1-run-rescue-find_entry', 'tdb1-run-rwlock-check', 'tdb1-run-summary', 'tdb1-run-transaction-expand', 'tdb1-run-traverse-in-transaction', 'tdb1-run-wronghash-fail', 'tdb1-run-zero-append':
193             cmd = "cd " + testdir + " && " + os.path.abspath(os.path.join(Utils.g_module.blddir, f)) + " > test-output 2>&1"
194             print("..." + f)
195             ret = samba_utils.RUN_COMMAND(cmd)
196             if ret != 0:
197                 print("%s failed:" % f)
198                 samba_utils.RUN_COMMAND("cat " + os.path.join(testdir, 'test-output'))
199                 ecode = ret
200                 break
201
202     if ecode == 0:
203         cmd = os.path.join(Utils.g_module.blddir, 'tdbtorture')
204         ret = samba_utils.RUN_COMMAND(cmd)
205         print("testsuite returned %d" % ret)
206         if ret != 0:
207             ecode = ret
208     sys.exit(ecode)
209
210 # WAF doesn't build the unit tests for this, maybe because they don't link with tdb?
211 # This forces it
212 def test(ctx):
213     import Scripting
214     Scripting.commands.append('build')
215     Scripting.commands.append('testonly')
216
217 def dist():
218     '''makes a tarball for distribution'''
219     samba_dist.dist()
220
221 def reconfigure(ctx):
222     '''reconfigure if config scripts have changed'''
223     import samba_utils
224     samba_utils.reconfigure(ctx)