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-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)
45 if Options.options.developer:
46 conf.env.DEVELOPER_MODE = True
48 conf.env.TEST_RUN_SRC=['test/run-001-encode.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',
72 'test/run-remap-in-read_traverse.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',
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',
107 'test/tap-interface.c']
109 if Options.options.BUILD_TDB2:
110 conf.DEFINE('BUILD_TDB2', 1)
111 conf.RECURSE('lib/replace')
112 conf.RECURSE('lib/ccan')
114 conf.env.standalone_tdb2 = conf.IN_LAUNCH_DIR()
115 conf.env.disable_python = getattr(Options.options, 'disable_python', False)
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)
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
134 # This make #include <ccan/...> work.
135 conf.ADD_EXTRA_INCLUDES('''#lib''')
137 conf.SAMBA_CONFIG_H()
140 if bld.env.BUILD_TDB2:
141 bld.RECURSE('lib/replace')
142 bld.RECURSE('lib/ccan')
144 if bld.env.standalone_tdb2:
145 bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
146 private_library = False
148 private_library = True
150 SRC = '''check.c free.c hash.c io.c lock.c open.c
151 summary.c tdb.c transaction.c traverse.c'''
153 if not bld.CONFIG_SET('USING_SYSTEM_TDB2'):
154 bld.SAMBA_LIBRARY('tdb',
162 public_headers='tdb2.h',
163 public_headers_install=not private_library,
165 private_library=private_library)
167 bld.SAMBA_BINARY('tdbtorture',
168 'tools/tdb2torture.c',
172 bld.SAMBA_BINARY('tdbtool',
176 bld.SAMBA_BINARY('tdbdump',
180 bld.SAMBA_BINARY('tdbrestore',
181 'tools/tdb2restore.c',
184 bld.SAMBA_BINARY('tdbbackup',
185 'tools/tdb2backup.c',
188 if not bld.CONFIG_SET('USING_SYSTEM_PYTDB'):
189 bld.SAMBA_PYTHON('pytdb',
192 enabled=not bld.env.disable_python,
194 cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
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',
205 bld.SAMBA_SUBSYSTEM('tdb2-test-helpers', bld.env.TEST_HELPER_SRC,
207 bld.SAMBA_SUBSYSTEM('tdb2-run-helpers', bld.env.TEST_RUN_HELPER_SRC,
209 bld.SAMBA_SUBSYSTEM('tdb2-api-helpers', bld.env.TEST_API_HELPER_SRC,
210 deps='replace tdb2-testing')
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',
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',
225 '''run tdb2 testsuite'''
226 import Utils, samba_utils, shutil
229 env = samba_utils.LOAD_ENVIRONMENT()
231 if env.BUILD_TDB2 and env.standalone_tdb2 and env.DEVELOPER_MODE:
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)
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)
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
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"
255 ret = samba_utils.RUN_COMMAND(cmd)
257 print("%s (%s) failed:" % (name, f))
258 samba_utils.RUN_COMMAND("cat " + os.path.join(testdir, 'test-output'))
264 # WAF doesn't build the unit tests for this, maybe because they don't link with tdb?
268 Scripting.commands.append('build')
269 Scripting.commands.append('testonly')
272 '''makes a tarball for distribution'''
275 def reconfigure(ctx):
276 '''reconfigure if config scripts have changed'''
278 samba_utils.reconfigure(ctx)