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