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