ldb: Add tests for the schema and index override hooks
[samba.git] / lib / ldb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'ldb'
4 VERSION = '1.1.29'
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, Utils
17
18 samba_dist.DIST_DIRS('''lib/ldb:. lib/replace:lib/replace lib/talloc:lib/talloc
19                         lib/tdb:lib/tdb lib/tdb:lib/tdb lib/tevent:lib/tevent
20                         third_party/popt:third_party/popt
21                         third_party/cmocka:third_party/cmocka
22                         buildtools:buildtools third_party/waf:third_party/waf''')
23
24
25 def set_options(opt):
26     opt.BUILTIN_DEFAULT('replace')
27     opt.PRIVATE_EXTENSION_DEFAULT('ldb', noextension='ldb')
28     opt.RECURSE('lib/tdb')
29     opt.RECURSE('lib/tevent')
30     opt.RECURSE('lib/replace')
31     opt.tool_options('python') # options for disabling pyc or pyo compilation
32
33 def configure(conf):
34     conf.RECURSE('lib/tdb')
35     conf.RECURSE('lib/tevent')
36
37     if conf.CHECK_FOR_THIRD_PARTY():
38         conf.RECURSE('third_party/popt')
39         conf.RECURSE('third_party/cmocka')
40     else:
41         if not conf.CHECK_POPT():
42             raise Utils.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
43         else:
44             conf.define('USING_SYSTEM_POPT', 1)
45
46         if not conf.CHECK_CMOCKA():
47             raise Utils.WafError('cmocka development package have not been found.\nIf third_party is installed, check that it is in the proper place.')
48         else:
49             conf.define('USING_SYSTEM_CMOCKA', 1)
50
51     conf.RECURSE('lib/replace')
52     conf.find_program('python', var='PYTHON')
53     conf.find_program('xsltproc', var='XSLTPROC')
54     conf.check_tool('python')
55     conf.check_python_version((2,4,2))
56     conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=not conf.env.disable_python)
57
58     # where does the default LIBDIR end up? in conf.env somewhere?
59     #
60     conf.CONFIG_PATH('LDB_MODULESDIR', conf.SUBST_ENV_VAR('MODULESDIR') + '/ldb')
61
62     conf.env.standalone_ldb = conf.IN_LAUNCH_DIR()
63
64     if not conf.env.standalone_ldb:
65         if conf.env.disable_python:
66             if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb', minversion=VERSION,
67                                          onlyif='talloc tdb tevent',
68                                          implied_deps='replace talloc tdb tevent'):
69                 conf.define('USING_SYSTEM_LDB', 1)
70         else:
71             using_system_pyldb_util = True
72             if not conf.CHECK_BUNDLED_SYSTEM_PKG('pyldb-util', minversion=VERSION,
73                                              onlyif='talloc tdb tevent',
74                                              implied_deps='replace talloc tdb tevent ldb'):
75                 using_system_pyldb_util = False
76
77             # We need to get a pyldb-util for all the python versions
78             # we are building for
79             if conf.env['EXTRA_PYTHON']:
80                 name = 'pyldb-util' + conf.all_envs['extrapython']['PYTHON_SO_ABI_FLAG']
81                 if not conf.CHECK_BUNDLED_SYSTEM_PKG(name, minversion=VERSION,
82                                                      onlyif='talloc tdb tevent',
83                                                      implied_deps='replace talloc tdb tevent ldb'):
84                     using_system_pyldb_util = False
85
86             if using_system_pyldb_util:
87                 conf.define('USING_SYSTEM_PYLDB_UTIL', 1)
88
89             if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb', minversion=VERSION,
90                                          onlyif='talloc tdb tevent pyldb-util',
91                                          implied_deps='replace talloc tdb tevent'):
92                 conf.define('USING_SYSTEM_LDB', 1)
93
94     if conf.env.standalone_ldb:
95         conf.CHECK_XSLTPROC_MANPAGES()
96
97         # we need this for the ldap backend
98         if conf.CHECK_FUNCS_IN('ber_flush ldap_open ldap_initialize', 'lber ldap', headers='lber.h ldap.h'):
99             conf.env.ENABLE_LDAP_BACKEND = True
100
101         # we don't want any libraries or modules to rely on runtime
102         # resolution of symbols
103         if not sys.platform.startswith("openbsd"):
104             conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
105
106     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
107
108     conf.SAMBA_CONFIG_H()
109
110     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
111
112 def build(bld):
113     bld.RECURSE('lib/tevent')
114
115     if bld.CHECK_FOR_THIRD_PARTY():
116         bld.RECURSE('third_party/popt')
117         bld.RECURSE('third_party/cmocka')
118
119     bld.RECURSE('lib/replace')
120     bld.RECURSE('lib/tdb')
121
122     if bld.env.standalone_ldb:
123         private_library = False
124     else:
125         private_library = True
126
127     LDB_MAP_SRC = bld.SUBDIR('ldb_map',
128                              'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
129
130     COMMON_SRC = bld.SUBDIR('common',
131                             '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
132                             ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c ldb_pack.c
133                             ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
134
135     bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
136                      init_function='ldb_ldap_init',
137                      module_init_name='ldb_init_module',
138                      deps='talloc lber ldap ldb',
139                      enabled=bld.env.ENABLE_LDAP_BACKEND,
140                      internal_module=False,
141                      subsystem='ldb')
142
143     if bld.PYTHON_BUILD_IS_ENABLED():
144         if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
145             for env in bld.gen_python_environments(['PKGCONFIGDIR']):
146                 # we're not currently linking against the ldap libs, but ldb.pc.in
147                 # has @LDAP_LIBS@
148                 bld.env.LDAP_LIBS = ''
149
150                 if not 'PACKAGE_VERSION' in bld.env:
151                     bld.env.PACKAGE_VERSION = VERSION
152                     bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
153
154                 name = bld.pyembed_libname('pyldb-util')
155                 bld.SAMBA_LIBRARY(name,
156                                   deps='ldb',
157                                   source='pyldb_util.c',
158                                   public_headers=('' if private_library else 'pyldb.h'),
159                                   public_headers_install=not private_library,
160                                   vnum=VERSION,
161                                   private_library=private_library,
162                                   pc_files='pyldb-util.pc',
163                                   pyembed=True,
164                                   enabled=bld.PYTHON_BUILD_IS_ENABLED(),
165                                   abi_directory='ABI',
166                                   abi_match='pyldb_*')
167
168                 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
169                     bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
170                                      deps='ldb ' + name,
171                                      realname='ldb.so',
172                                      cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
173
174         for env in bld.gen_python_environments(['PKGCONFIGDIR']):
175                 bld.SAMBA_SCRIPT('_ldb_text.py',
176                                  pattern='_ldb_text.py',
177                                  installdir='python')
178
179                 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
180
181     if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
182         if bld.is_install:
183             modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
184         else:
185             # when we run from the source directory, we want to use
186             # the current modules, not the installed ones
187             modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
188
189         abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
190
191         ldb_headers = ('include/ldb.h include/ldb_errors.h '
192                        'include/ldb_module.h include/ldb_handlers.h')
193
194         bld.SAMBA_LIBRARY('ldb',
195                           COMMON_SRC + ' ' + LDB_MAP_SRC,
196                           deps='tevent LIBLDB_MAIN replace',
197                           includes='include',
198                           public_headers=('' if private_library else ldb_headers),
199                           public_headers_install=not private_library,
200                           pc_files='ldb.pc',
201                           vnum=VERSION,
202                           private_library=private_library,
203                           manpages='man/ldb.3',
204                           abi_directory='ABI',
205                           abi_match = abi_match)
206
207         # generate a include/ldb_version.h
208         t = bld.SAMBA_GENERATOR('ldb_version.h',
209                                 rule='echo "#define LDB_VERSION \\"${LDB_VERSION}\\"" > ${TGT}',
210                                 dep_vars=['LDB_VERSION'],
211                                 target='include/ldb_version.h',
212                                 public_headers='include/ldb_version.h',
213                                 public_headers_install=not private_library)
214         t.env.LDB_VERSION = VERSION
215
216
217         bld.SAMBA_MODULE('ldb_paged_results',
218                          'modules/paged_results.c',
219                          init_function='ldb_paged_results_init',
220                          module_init_name='ldb_init_module',
221                          internal_module=False,
222                          deps='ldb',
223                          subsystem='ldb')
224
225         bld.SAMBA_MODULE('ldb_asq',
226                          'modules/asq.c',
227                          init_function='ldb_asq_init',
228                          module_init_name='ldb_init_module',
229                          internal_module=False,
230                          deps='ldb',
231                          subsystem='ldb')
232
233         bld.SAMBA_MODULE('ldb_server_sort',
234                          'modules/sort.c',
235                          init_function='ldb_server_sort_init',
236                          internal_module=False,
237                          module_init_name='ldb_init_module',
238                          deps='ldb',
239                          subsystem='ldb')
240
241         bld.SAMBA_MODULE('ldb_paged_searches',
242                          'modules/paged_searches.c',
243                          init_function='ldb_paged_searches_init',
244                          internal_module=False,
245                          module_init_name='ldb_init_module',
246                          deps='ldb',
247                          subsystem='ldb')
248
249         bld.SAMBA_MODULE('ldb_rdn_name',
250                          'modules/rdn_name.c',
251                          init_function='ldb_rdn_name_init',
252                          internal_module=False,
253                          module_init_name='ldb_init_module',
254                          deps='ldb',
255                          subsystem='ldb')
256
257         bld.SAMBA_MODULE('ldb_sample',
258                          'tests/sample_module.c',
259                          init_function='ldb_sample_init',
260                          internal_module=False,
261                          module_init_name='ldb_init_module',
262                          deps='ldb',
263                          subsystem='ldb')
264
265         bld.SAMBA_MODULE('ldb_skel',
266                          'modules/skel.c',
267                          init_function='ldb_skel_init',
268                          internal_module=False,
269                          module_init_name='ldb_init_module',
270                          deps='ldb',
271                          subsystem='ldb')
272
273         bld.SAMBA_MODULE('ldb_sqlite3',
274                          'sqlite3/ldb_sqlite3.c',
275                          init_function='ldb_sqlite3_init',
276                          internal_module=False,
277                          module_init_name='ldb_init_module',
278                          enabled=False,
279                          deps='ldb',
280                          subsystem='ldb')
281
282         bld.SAMBA_MODULE('ldb_tdb',
283                          bld.SUBDIR('ldb_tdb',
284                                     '''ldb_tdb.c ldb_search.c ldb_index.c
285                                     ldb_cache.c ldb_tdb_wrap.c'''),
286                          init_function='ldb_tdb_init',
287                          module_init_name='ldb_init_module',
288                          internal_module=False,
289                          deps='tdb ldb',
290                          subsystem='ldb')
291
292         # have a separate subsystem for common/ldb.c, so it can rebuild
293         # for install with a different -DLDB_MODULESDIR=
294         bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
295                             'common/ldb.c',
296                             deps='tevent tdb',
297                             includes='include',
298                             cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
299
300         LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
301         for t in LDB_TOOLS.split():
302             bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
303                              manpages='man/%s.1' % t)
304
305         # ldbtest doesn't get installed
306         bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
307                          install=False)
308
309         # ldbdump doesn't get installed
310         bld.SAMBA_BINARY('ldbdump', 'tools/ldbdump.c', deps='ldb-cmdline ldb',
311                          install=False)
312
313         bld.SAMBA_LIBRARY('ldb-cmdline',
314                           source='tools/ldbutil.c tools/cmdline.c',
315                           deps='ldb dl popt',
316                           private_library=True)
317
318         bld.SAMBA_BINARY('ldb_tdb_mod_op_test',
319                          source='tests/ldb_mod_op_test.c',
320                          cflags='-DTEST_BE=\"tdb\"',
321                          deps='cmocka ldb',
322                          install=False)
323
324 def test(ctx):
325     '''run ldb testsuite'''
326     import Utils, samba_utils, shutil
327     env = samba_utils.LOAD_ENVIRONMENT()
328     ctx.env = env
329
330     test_prefix = "%s/st" % (Utils.g_module.blddir)
331     shutil.rmtree(test_prefix, ignore_errors=True)
332     os.makedirs(test_prefix)
333     os.environ['TEST_DATA_PREFIX'] = test_prefix
334     os.environ['LD_LIBRARY_PATH'] = Utils.g_module.blddir + '/bin/default/lib/ldb'
335     cmd = 'tests/test-tdb.sh %s' % Utils.g_module.blddir
336     ret = samba_utils.RUN_COMMAND(cmd)
337     print("testsuite returned %d" % ret)
338
339     tmp_dir = os.path.join(test_prefix, 'tmp')
340     if not os.path.exists(tmp_dir):
341         os.mkdir(tmp_dir)
342     pyret = samba_utils.RUN_PYTHON_TESTS(
343         ['tests/python/api.py'],
344         extra_env={'SELFTEST_PREFIX': test_prefix})
345     print("Python testsuite returned %d" % pyret)
346
347     os.environ['LDB_MODULES_PATH'] = Utils.g_module.blddir + '/modules/ldb'
348     os.environ['LD_LIBRARY_PATH'] = Utils.g_module.blddir + '/bin/default/lib/ldb'
349     cmd = Utils.g_module.blddir + '/ldb_tdb_mod_op_test'
350     cmocka_ret = samba_utils.RUN_COMMAND(cmd)
351
352     sys.exit(ret or pyret or cmocka_ret)
353
354 def dist():
355     '''makes a tarball for distribution'''
356     samba_dist.dist()
357
358 def reconfigure(ctx):
359     '''reconfigure if config scripts have changed'''
360     import samba_utils
361     samba_utils.reconfigure(ctx)