TDB2: remove TDB1 compatibility.
[kai/samba-autobuild/.git] / lib / tdb2 / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'tdb'
4 VERSION = '2.0.1'
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, glob
17
18 samba_dist.DIST_DIRS('lib/tdb2:. lib/replace:lib/replace lib/ccan:lib/ccan buildtools:buildtools')
19
20 def set_options(opt):
21     opt.BUILTIN_DEFAULT('replace,ccan')
22     opt.PRIVATE_EXTENSION_DEFAULT('tdb2', noextension='tdb2')
23     opt.RECURSE('lib/replace')
24     opt.add_option('--enable-developer',
25                    help=("Turn on developer warnings and debugging"),
26                    action="store_true", dest='developer', default=False)
27     opt.add_option('--enable-tdb2',
28                    help=("Use tdb2 API instead of tdb1 [True]"),
29                    action="store_true", dest='BUILD_TDB2', default=True)
30     opt.add_option('--disable-tdb2',
31                    help=("Use old tdb1 API instead of tdb2"),
32                    action="store_false", dest='BUILD_TDB2')
33     opt.add_option('--valgrind',
34                    help=("use valgrind on tests programs"),
35                    action="store_true", dest='VALGRIND', default=False)
36     opt.add_option('--valgrind-log',
37                    help=("where to put the valgrind log"),
38                    action="store", dest='VALGRINDLOG', default=None)
39     if opt.IN_LAUNCH_DIR():
40         opt.add_option('--disable-python',
41                        help=("disable the pytdb module"),
42                        action="store_true", dest='disable_python', default=False)
43
44 def configure(conf):
45     if Options.options.developer:
46         conf.env.DEVELOPER_MODE = True
47
48     conf.env.TEST_RUN_SRC=['test/run-001-encode.c',
49                            'test/run-001-fls.c',
50                            'test/run-01-new_database.c',
51                            'test/run-02-expand.c',
52                            'test/run-03-coalesce.c',
53                            'test/run-04-basichash.c',
54                            'test/run-05-readonly-open.c',
55                            'test/run-10-simple-store.c',
56                            'test/run-11-simple-fetch.c',
57                            'test/run-12-check.c',
58                            'test/run-15-append.c',
59                            'test/run-20-growhash.c',
60                            'test/run-25-hashoverload.c',
61                            'test/run-30-exhaust-before-expand.c',
62                            'test/run-35-convert.c',
63                            'test/run-50-multiple-freelists.c',
64                            'test/run-56-open-during-transaction.c',
65                            'test/run-57-die-during-transaction.c',
66                            'test/run-64-bit-tdb.c',
67                            'test/run-90-get-set-attributes.c',
68                            'test/run-capabilities.c',
69                            'test/run-expand-in-transaction.c',
70                            'test/run-features.c',
71                            'test/run-lockall.c',
72                            'test/run-remap-in-read_traverse.c',
73                            'test/run-seed.c',
74                            'test/run-tdb_errorstr.c',
75                            'test/run-tdb_foreach.c',
76                            'test/run-traverse.c']
77     conf.env.TEST_API_SRC=['test/api-12-store.c',
78                            'test/api-13-delete.c',
79                            'test/api-14-exists.c',
80                            'test/api-16-wipe_all.c',
81                            'test/api-21-parse_record.c',
82                            'test/api-55-transaction.c',
83                            'test/api-80-tdb_fd.c',
84                            'test/api-81-seqnum.c',
85                            'test/api-82-lockattr.c',
86                            'test/api-83-openhook.c',
87                            'test/api-91-get-stats.c',
88                            'test/api-92-get-set-readonly.c',
89                            'test/api-93-repack.c',
90                            'test/api-add-remove-flags.c',
91                            'test/api-check-callback.c',
92                            'test/api-firstkey-nextkey.c',
93                            'test/api-fork-test.c',
94                            'test/api-locktimeout.c',
95                            'test/api-missing-entries.c',
96                            'test/api-open-multiple-times.c',
97                            'test/api-record-expand.c',
98                            'test/api-simple-delete.c',
99                            'test/api-summary.c']
100     conf.env.TEST_API_HELPER_SRC=['test/helpapi-external-agent.c']
101     conf.env.TEST_RUN_HELPER_SRC=['test/helprun-external-agent.c',
102                                   'test/helprun-layout.c']
103     conf.env.TEST_HELPER_SRC=['test/external-agent.c',
104                               'test/failtest_helper.c',
105                               'test/lock-tracking.c',
106                               'test/logging.c',
107                               'test/tap-interface.c']
108
109     if Options.options.BUILD_TDB2:
110         conf.DEFINE('BUILD_TDB2', 1)
111         conf.RECURSE('lib/replace')
112         conf.RECURSE('lib/ccan')
113
114         conf.env.standalone_tdb2 = conf.IN_LAUNCH_DIR()
115         conf.env.disable_python = getattr(Options.options, 'disable_python', False)
116
117         if not conf.env.standalone_tdb2:
118             if conf.CHECK_BUNDLED_SYSTEM('tdb', minversion=VERSION,
119                                          implied_deps='replace'):
120                 conf.define('USING_SYSTEM_TDB2', 1)
121                 if conf.CHECK_BUNDLED_SYSTEM_PYTHON('pytdb', 'tdb', minversion=VERSION):
122                     conf.define('USING_SYSTEM_PYTDB', 1)
123
124         if not conf.env.disable_python:
125             # also disable if we don't have the python libs installed
126             conf.find_program('python', var='PYTHON')
127             conf.check_tool('python')
128             conf.check_python_version((2,4,2))
129             conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
130             if not conf.env.HAVE_PYTHON_H:
131                 Logs.warn('Disabling pytdb as python devel libs not found')
132                 conf.env.disable_python = True
133
134         # This make #include <ccan/...> work.
135         conf.ADD_EXTRA_INCLUDES('''#lib''')
136
137         conf.SAMBA_CONFIG_H()
138
139 def build(bld):
140     if bld.env.BUILD_TDB2:
141         bld.RECURSE('lib/replace')
142         bld.RECURSE('lib/ccan')
143
144         if bld.env.standalone_tdb2:
145             bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
146             private_library = False
147         else:
148             private_library = True
149
150         SRC = '''check.c free.c hash.c io.c lock.c open.c
151                  summary.c tdb.c transaction.c traverse.c'''
152
153         if not bld.CONFIG_SET('USING_SYSTEM_TDB2'):
154             bld.SAMBA_LIBRARY('tdb',
155                               SRC,
156                               deps='replace ccan',
157                               includes='.',
158                               abi_directory='ABI',
159                               abi_match='tdb_*',
160                               hide_symbols=True,
161                               vnum=VERSION,
162                               public_headers='tdb2.h',
163                               public_headers_install=not private_library,
164                               pc_files='tdb.pc',
165                               private_library=private_library)
166
167             bld.SAMBA_BINARY('tdbtorture',
168                              'tools/tdb2torture.c',
169                              deps='tdb',
170                              install=False)
171
172             bld.SAMBA_BINARY('tdbtool',
173                              'tools/tdb2tool.c',
174                              deps='tdb')
175
176             bld.SAMBA_BINARY('tdbdump',
177                              'tools/tdb2dump.c',
178                              deps='tdb')
179
180             bld.SAMBA_BINARY('tdbrestore',
181                              'tools/tdb2restore.c',
182                              deps='tdb')
183
184             bld.SAMBA_BINARY('tdbbackup',
185                              'tools/tdb2backup.c',
186                              deps='tdb')
187
188             if not bld.CONFIG_SET('USING_SYSTEM_PYTDB'):
189                 bld.SAMBA_PYTHON('pytdb',
190                                  source='pytdb.c',
191                                  deps='tdb',
192                                  enabled=not bld.env.disable_python,
193                                  realname='tdb.so',
194                                  cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
195
196             if bld.env.DEVELOPER_MODE:
197                 # FIXME: We need CCAN for some API tests, but waf thinks it's
198                 # already available via tdb2.  It is, but not publicly.
199                 # Workaround is to build a private, non-hiding version.
200                 bld.SAMBA_SUBSYSTEM('tdb2-testing',
201                                     SRC,
202                                     deps='replace ccan',
203                                     includes='.')
204
205                 bld.SAMBA_SUBSYSTEM('tdb2-test-helpers', bld.env.TEST_HELPER_SRC,
206                                     deps='replace')
207                 bld.SAMBA_SUBSYSTEM('tdb2-run-helpers', bld.env.TEST_RUN_HELPER_SRC,
208                                     deps='replace')
209                 bld.SAMBA_SUBSYSTEM('tdb2-api-helpers', bld.env.TEST_API_HELPER_SRC,
210                                     deps='replace tdb2-testing')
211
212                 for f in bld.env.TEST_RUN_SRC:
213                     base = os.path.splitext(os.path.basename(f))[0]
214                     bld.SAMBA_BINARY('tdb2-' + base, f,
215                                      deps='ccan replace tdb2-test-helpers tdb2-run-helpers ccan-failtest',
216                                      install=False)
217
218                 for f in bld.env.TEST_API_SRC:
219                     base = os.path.splitext(os.path.basename(f))[0]
220                     bld.SAMBA_BINARY('tdb2-' + base, f,
221                                      deps='ccan replace tdb2-test-helpers tdb2-api-helpers',
222                                      install=False)
223
224 def testonly(ctx):
225     '''run tdb2 testsuite'''
226     import Utils, samba_utils, shutil
227     ecode = 0;
228
229     env = samba_utils.LOAD_ENVIRONMENT()
230
231     if env.BUILD_TDB2 and env.standalone_tdb2 and env.DEVELOPER_MODE:
232
233         # FIXME: This is horrible :(
234         test_prefix = "%s/st" % (Utils.g_module.blddir)
235         shutil.rmtree(test_prefix, ignore_errors=True)
236         os.makedirs(test_prefix)
237
238         # Create scratch directory for tests.
239         testdir = os.path.join(test_prefix, 'tdb2-tests')
240         samba_utils.mkdir_p(testdir)
241         # Symlink back to source dir so it can find tests in test/
242         link = os.path.join(testdir, 'test')
243         if not os.path.exists(link):
244             os.symlink(os.path.abspath(os.path.join(env.cwd, 'test')), link)
245
246         if Options.options.VALGRIND:
247             os.environ['VALGRIND'] = 'valgrind -q --num-callers=30'
248         if Options.options.VALGRINDLOG is not None:
249             os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG
250
251         for f in env.TEST_RUN_SRC + env.TEST_API_SRC:
252             name = "tdb2-" + os.path.splitext(os.path.basename(f))[0]
253             cmd = "cd " + testdir + " && $VALGRIND " + os.path.abspath(os.path.join(Utils.g_module.blddir, name)) + " > test-output 2>&1"
254             print("..." + f)
255             ret = samba_utils.RUN_COMMAND(cmd)
256             if ret != 0:
257                 print("%s (%s) failed:" % (name, f))
258                 samba_utils.RUN_COMMAND("cat " + os.path.join(testdir, 'test-output'))
259                 ecode = ret;
260                 break;
261
262     sys.exit(ecode)
263
264 # WAF doesn't build the unit tests for this, maybe because they don't link with tdb?
265 # This forces it
266 def test(ctx):
267     import Scripting
268     Scripting.commands.append('build')
269     Scripting.commands.append('testonly')
270
271 def dist():
272     '''makes a tarball for distribution'''
273     samba_dist.dist()
274
275 def reconfigure(ctx):
276     '''reconfigure if config scripts have changed'''
277     import samba_utils
278     samba_utils.reconfigure(ctx)