10 # find the buildtools directory
12 while not os
.path
.exists(srcdir
+'/buildtools') and len(srcdir
.split('/')) < 5:
13 srcdir
= '../' + srcdir
14 sys
.path
.insert(0, srcdir
+ '/buildtools/wafsamba')
16 import wafsamba
, samba_dist
, Options
, Logs
, glob
18 samba_dist
.DIST_DIRS('lib/tdb2:. lib/replace:lib/replace lib/ccan:lib/ccan buildtools:buildtools')
21 opt
.BUILTIN_DEFAULT('replace,ccan')
22 opt
.PRIVATE_EXTENSION_DEFAULT('tdb2', noextension
='tdb2')
23 opt
.RECURSE('lib/replace')
24 opt
.add_option('--enable-tdb2',
25 help=("Use tdb2 API instead of tdb1 [True]"),
26 action
="store_true", dest
='BUILD_TDB2', default
=True)
27 opt
.add_option('--disable-tdb2',
28 help=("Use old tdb1 API instead of tdb2"),
29 action
="store_false", dest
='BUILD_TDB2')
30 opt
.add_option('--valgrind',
31 help=("use valgrind on tests programs"),
32 action
="store_true", dest
='VALGRIND', default
=False)
33 opt
.add_option('--valgrind-log',
34 help=("where to put the valgrind log"),
35 action
="store", dest
='VALGRINDLOG', default
=None)
36 if opt
.IN_LAUNCH_DIR():
37 opt
.add_option('--disable-python',
38 help=("disable the pytdb module"),
39 action
="store_true", dest
='disable_python', default
=False)
42 if Options
.options
.BUILD_TDB2
:
43 conf
.DEFINE('BUILD_TDB2', 1)
44 conf
.RECURSE('lib/replace')
45 conf
.RECURSE('lib/ccan')
47 conf
.env
.standalone_tdb2
= conf
.IN_LAUNCH_DIR()
48 conf
.env
.disable_python
= getattr(Options
.options
, 'disable_python', False)
50 if not conf
.env
.standalone_tdb2
:
51 if conf
.CHECK_BUNDLED_SYSTEM('tdb', minversion
=VERSION
,
52 implied_deps
='replace'):
53 conf
.define('USING_SYSTEM_TDB2', 1)
54 if conf
.CHECK_BUNDLED_SYSTEM_PYTHON('pytdb', 'tdb', minversion
=VERSION
):
55 conf
.define('USING_SYSTEM_PYTDB', 1)
57 if not conf
.env
.disable_python
:
58 # also disable if we don't have the python libs installed
59 conf
.find_program('python', var
='PYTHON')
60 conf
.check_tool('python')
61 conf
.check_python_version((2,4,2))
62 conf
.SAMBA_CHECK_PYTHON_HEADERS(mandatory
=False)
63 if not conf
.env
.HAVE_PYTHON_H
:
64 Logs
.warn('Disabling pytdb as python devel libs not found')
65 conf
.env
.disable_python
= True
67 # This make #include <ccan/...> work.
68 conf
.ADD_EXTRA_INCLUDES('''#lib''')
72 # Seems like env can't contain sets?
73 conf
.env
.tdb2_test
= {}
74 conf
.env
.tdb2_test
['run'] = glob
.glob('test/run*.c')
75 conf
.env
.tdb2_test
['api'] = glob
.glob('test/api*.c')
76 conf
.env
.tdb2_test
['runhelper'] = glob
.glob('test/helprun*.c')
77 conf
.env
.tdb2_test
['apihelper'] = glob
.glob('test/helpapi*.c')
78 conf
.env
.tdb2_test
['helper'] = list(set(glob
.glob('test/*.c'))
79 - set(conf
.env
.tdb2_test
['run'])
80 - set(conf
.env
.tdb2_test
['api'])
81 - set(conf
.env
.tdb2_test
['runhelper'])
82 - set(conf
.env
.tdb2_test
['apihelper']))
85 if bld
.env
.BUILD_TDB2
:
86 bld
.RECURSE('lib/replace')
87 bld
.RECURSE('lib/ccan')
89 if bld
.env
.standalone_tdb2
:
90 bld
.env
.PKGCONFIGDIR
= '${LIBDIR}/pkgconfig'
91 private_library
= False
93 private_library
= True
95 SRC
= '''check.c free.c hash.c io.c lock.c open.c
96 summary.c tdb.c transaction.c traverse.c
97 tdb1_check.c tdb1_freelist.c tdb1_hash.c
98 tdb1_io.c tdb1_lock.c tdb1_open.c
99 tdb1_summary.c tdb1_tdb.c tdb1_transaction.c
102 if not bld
.CONFIG_SET('USING_SYSTEM_TDB2'):
103 bld
.SAMBA_LIBRARY('tdb',
108 abi_match
='tdb_* tdb1_incompatible_hash',
111 public_headers
='tdb2.h',
112 public_headers_install
=not private_library
,
114 private_library
=private_library
)
116 bld
.SAMBA_BINARY('tdbtorture',
117 'tools/tdb2torture.c',
121 bld
.SAMBA_BINARY('tdbtool',
125 bld
.SAMBA_BINARY('tdbdump',
129 bld
.SAMBA_BINARY('tdbrestore',
130 'tools/tdb2restore.c',
133 bld
.SAMBA_BINARY('tdbbackup',
134 'tools/tdb2backup.c',
137 # FIXME: We need CCAN for some API tests, but waf thinks it's
138 # already available via tdb. It is, but not publicly.
139 # Workaround is to build a private, non-hiding version.
140 bld
.SAMBA_SUBSYSTEM('tdb-testing',
145 bld
.SAMBA_SUBSYSTEM('tdb2-test-helpers',
146 bld
.env
.tdb2_test
['helper'], deps
='replace')
147 bld
.SAMBA_SUBSYSTEM('tdb2-run-helpers',
148 bld
.env
.tdb2_test
['runhelper'], deps
='replace')
149 bld
.SAMBA_SUBSYSTEM('tdb2-api-helpers',
150 bld
.env
.tdb2_test
['apihelper'], deps
='replace tdb-testing')
152 for f
in bld
.env
.tdb2_test
['run']:
153 base
= os
.path
.splitext(os
.path
.basename(f
))[0]
154 bld
.SAMBA_BINARY('tdb2-' + base
, f
,
155 deps
='ccan replace tdb2-test-helpers tdb2-run-helpers',
158 for f
in bld
.env
.tdb2_test
['api']:
159 base
= os
.path
.splitext(os
.path
.basename(f
))[0]
160 bld
.SAMBA_BINARY('tdb2-' + base
, f
,
161 deps
='ccan replace tdb2-test-helpers tdb2-api-helpers',
164 if not bld
.CONFIG_SET('USING_SYSTEM_PYTDB'):
165 bld
.SAMBA_PYTHON('pytdb',
168 enabled
=not bld
.env
.disable_python
,
170 cflags
='-DPACKAGE_VERSION=\"%s\"' % VERSION
)
173 '''run tdb2 testsuite'''
174 import Utils
, samba_utils
, shutil
177 env
= samba_utils
.LOAD_ENVIRONMENT()
179 if env
.BUILD_TDB2
and env
.standalone_tdb2
:
180 # FIXME: This is horrible :(
181 test_prefix
= "%s/st" % (Utils
.g_module
.blddir
)
182 shutil
.rmtree(test_prefix
, ignore_errors
=True)
183 os
.makedirs(test_prefix
)
185 # Create scratch directory for tests.
186 testdir
= os
.path
.join(test_prefix
, 'tdb2-tests')
187 samba_utils
.mkdir_p(testdir
)
188 # Symlink back to source dir so it can find tests in test/
189 link
= os
.path
.join(testdir
, 'test')
190 if not os
.path
.exists(link
):
191 os
.symlink(os
.path
.abspath(os
.path
.join(env
.cwd
, 'test')), link
)
193 if Options
.options
.VALGRIND
:
194 os
.environ
['VALGRIND'] = 'valgrind -q --num-callers=30'
195 if Options
.options
.VALGRINDLOG
is not None:
196 os
.environ
['VALGRIND'] += ' --log-file=%s' % Options
.options
.VALGRINDLOG
198 for f
in env
.tdb2_test
['run'] + env
.tdb2_test
['api']:
199 name
= "tdb2-" + os
.path
.splitext(os
.path
.basename(f
))[0]
200 cmd
= "cd " + testdir
+ " && $VALGRIND " + os
.path
.abspath(os
.path
.join(Utils
.g_module
.blddir
, name
)) + " > test-output 2>&1"
202 ret
= samba_utils
.RUN_COMMAND(cmd
)
204 print("%s (%s) failed:" % (name
, f
))
205 samba_utils
.RUN_COMMAND("cat " + os
.path
.join(testdir
, 'test-output'))
211 # WAF doesn't build the unit tests for this, maybe because they don't link with tdb?
215 Scripting
.commands
.append('build')
216 Scripting
.commands
.append('testonly')
219 '''makes a tarball for distribution'''
222 def reconfigure(ctx
):
223 '''reconfigure if config scripts have changed'''
225 samba_utils
.reconfigure(ctx
)