ctdb-tests: Make the fake log timestamp string easy to modify
[vlendec/samba-autobuild/.git] / ctdb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'ctdb'
4
5 blddir = 'bin'
6
7 import sys, os
8
9 # find the buildtools directory
10 srcdir = '.'
11 while not os.path.exists(srcdir+'/buildtools') and len(srcdir.split('/')) < 5:
12     srcdir = srcdir + '/..'
13 sys.path.insert(0, srcdir + '/buildtools/wafsamba')
14
15 import wafsamba, samba_dist, Options, Logs, Utils
16 import samba_utils, samba_version
17
18 env = samba_utils.LOAD_ENVIRONMENT()
19 if os.path.isfile('./VERSION'):
20     vdir = '.'
21 elif os.path.isfile('../VERSION'):
22     vdir = '..'
23 else:
24     Logs.error("VERSION file not found")
25
26 version = samba_version.samba_version_file('%s/VERSION' % vdir, vdir, env)
27 VERSION = version.STRING.replace('-', '.')
28
29 Options.default_prefix = '/usr/local'
30
31 samba_dist.DIST_DIRS('''ctdb:. lib/replace:lib/replace lib/talloc:lib/talloc
32                         lib/tevent:lib/tevent lib/tdb:lib/tdb
33                         lib/socket_wrapper:lib/socket_wrapper
34                         third_party/popt:third_party/popt
35                         buildtools:buildtools''')
36
37
38 def set_options(opt):
39     opt.PRIVATE_EXTENSION_DEFAULT('ctdb')
40     opt.RECURSE('lib/replace')
41     opt.RECURSE('lib/talloc')
42     opt.RECURSE('lib/tevent')
43     opt.RECURSE('lib/tdb')
44
45     opt.add_option('--enable-infiniband',
46                    help=("Turn on infiniband support (default=no)"),
47                    action="store_true", dest='ctdb_infiniband', default=False)
48     opt.add_option('--enable-pmda',
49                    help=("Turn on PCP pmda support (default=no)"),
50                    action="store_true", dest='ctdb_pmda', default=False)
51
52     opt.add_option('--with-logdir',
53                    help=("Path to log directory"),
54                    action="store", dest='ctdb_logdir', default=None)
55     opt.add_option('--with-socketpath',
56                    help=("path to CTDB daemon socket"),
57                    action="store_true", dest='ctdb_sockpath', default=False)
58
59
60 def configure(conf):
61
62     # CTDB relies on nested event loops
63     conf.env.TEVENT_DEPRECATED = 1
64
65     # No need to build python bindings for talloc/tevent/tdb
66     if conf.IN_LAUNCH_DIR():
67         Options.options.disable_python = True
68
69     conf.RECURSE('lib/replace')
70     if conf.CHECK_FOR_THIRD_PARTY():
71         conf.RECURSE('third_party/popt')
72     else:
73         if not conf.CHECK_POPT():
74             raise Utils.WafError('popt development packages have not been found\nIf third_party is installed, check that it is in the proper place.')
75         else:
76             conf.define('USING_SYSTEM_POPT', 1)
77
78     conf.RECURSE('lib/talloc')
79     conf.RECURSE('lib/tevent')
80     conf.RECURSE('lib/tdb')
81     conf.RECURSE('lib/socket_wrapper')
82
83     conf.CHECK_HEADERS('sched.h')
84     conf.CHECK_HEADERS('procinfo.h')
85     if sys.platform.startswith('aix') and not conf.CHECK_FUNCS('thread_setsched'):
86         Logs.error('Need thread_setsched() on AIX')
87         sys.exit(1)
88     elif not conf.CHECK_FUNCS('sched_setscheduler'):
89         Logs.error('Need sched_setscheduler()')
90         sys.exit(1)
91     conf.CHECK_FUNCS('mlockall')
92
93     if not conf.CHECK_VARIABLE('ETIME', headers='errno.h'):
94         conf.DEFINE('ETIME', 'ETIMEDOUT')
95
96     if sys.platform.startswith('linux'):
97         conf.SET_TARGET_TYPE('pcap', 'EMPTY')
98     else:
99         if not conf.CHECK_HEADERS('pcap.h'):
100             Logs.error('Need libpcap')
101             sys.exit(1)
102         if not conf.CHECK_FUNCS_IN('pcap_open_live', 'pcap', headers='pcap.h'):
103             Logs.error('Need libpcap')
104             sys.exit(1)
105
106     if not conf.CHECK_FUNCS_IN('backtrace backtrace_symbols', 'execinfo',
107                                checklibc=True, headers='execinfo.h'):
108         Logs.error('backtrace support not available')
109
110     have_pmda = False
111     if Options.options.ctdb_pmda:
112         pmda_support = True
113
114         if not conf.CHECK_HEADERS('pcp/pmapi.h pcp/impl.h pcp/pmda.h',
115                                   together=True):
116             pmda_support = False
117         if not conf.CHECK_FUNCS_IN('pmProgname', 'pcp'):
118             pmda_support = False
119         if not conf.CHECK_FUNCS_IN('pmdaDaemon', 'pcp_pmda'):
120             pmda_support = False
121         if pmda_support:
122             have_pmda = True
123         else:
124             Logs.error("PMDA support not available")
125     if have_pmda:
126         Logs.info('Building with PMDA support')
127         conf.define('HAVE_PMDA', 1)
128         conf.env.CTDB_PMDADIR = os.path.join(conf.env.LOCALSTATEDIR,
129                                              'lib/pcp/pmdas/ctdb')
130
131     have_infiniband = False
132     if Options.options.ctdb_infiniband:
133         ib_support = True
134
135         if not conf.CHECK_HEADERS('infiniband/verbs.h rdma/rdma_cma.h'):
136             ib_support = False
137         if not conf.CHECK_FUNCS_IN('ibv_create_qp', 'ibverbs'):
138             ib_support = False
139         if not conf.CHECK_FUNCS_IN('rdma_connect', 'rdmacm'):
140             ib_support = False
141         if ib_support:
142             have_infiniband = True
143         else:
144             Logs.error("Infiniband support not available")
145     if have_infiniband:
146         Logs.info('Building with Infiniband support')
147         conf.define('HAVE_INFINIBAND', 1)
148         conf.define('USE_INFINIBAND', 1)
149
150     conf.env.CTDB_BINDIR = os.path.join(conf.env.EXEC_PREFIX, 'bin')
151     conf.env.CTDB_ETCDIR = os.path.join(conf.env.SYSCONFDIR, 'ctdb')
152     conf.env.CTDB_VARDIR = os.path.join(conf.env.LOCALSTATEDIR, 'lib/ctdb')
153     conf.env.CTDB_RUNDIR = os.path.join(conf.env.LOCALSTATEDIR, 'run/ctdb')
154
155     if Options.options.ctdb_logdir:
156         conf.env.CTDB_LOGDIR = Options.options.ctdb_logdir
157     else:
158         conf.env.CTDB_LOGDIR = os.path.join(conf.env.LOCALSTATEDIR, 'log')
159
160     if Options.options.ctdb_sockpath:
161         conf.env.CTDB_SOCKPATH = Options.options.ctdb_sockpath
162     else:
163         conf.env.CTDB_SOCKPATH = os.path.join(conf.env.CTDB_RUNDIR,
164                                               'ctdbd.socket')
165
166     conf.ADD_CFLAGS('''-DBINDIR=\"%s\"
167                        -DLOGDIR=\"%s\"
168                        -DSOCKPATH=\"%s\"
169                        -DCTDB_ETCDIR=\"%s\"
170                        -DCTDB_VARDIR=\"%s\"
171                        -DCTDB_RUNDIR=\"%s\"''' % (
172                     conf.env.CTDB_BINDIR,
173                     conf.env.CTDB_LOGDIR,
174                     conf.env.CTDB_SOCKPATH,
175                     conf.env.CTDB_ETCDIR,
176                     conf.env.CTDB_VARDIR,
177                     conf.env.CTDB_RUNDIR))
178
179     conf.env.CTDB_TEST_DATADIR = os.path.join(conf.env.EXEC_PREFIX,
180                                               'share/ctdb-tests')
181     conf.env.CTDB_TEST_LIBDIR = os.path.join(conf.env.LIBDIR, 'ctdb-tests')
182
183     # Allow separate compilation of utilities to find includes
184     if srcdir == '.':
185         # Building from tarball
186         conf.ADD_EXTRA_INCLUDES('#include')
187         conf.ADD_EXTRA_INCLUDES('#include/internal')
188     else:
189         # Building standalone CTDB from within Samba tree
190         conf.ADD_EXTRA_INCLUDES('#ctdb/include')
191         conf.ADD_EXTRA_INCLUDES('#ctdb/include/internal')
192         conf.ADD_EXTRA_INCLUDES('#ctdb')
193
194     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
195     conf.SAMBA_CONFIG_H()
196
197
198 def build(bld):
199     bld.RECURSE('lib/replace')
200     if bld.CHECK_FOR_THIRD_PARTY():
201         bld.RECURSE('third_party/popt')
202
203     bld.RECURSE('lib/tdb_wrap')
204     bld.RECURSE('lib/util')
205
206     bld.RECURSE('lib/talloc')
207     bld.RECURSE('lib/tevent')
208     bld.RECURSE('lib/tdb')
209     bld.RECURSE('lib/socket_wrapper')
210
211     t = bld.SAMBA_GENERATOR('ctdb-version-header',
212                             target='include/ctdb_version.h',
213                             rule='../packaging/mkversion.sh ${TGT} %s' % (VERSION),
214                             dep_vars=['VERSION'])
215     t.env.VERSION = VERSION
216
217     bld.SAMBA_SUBSYSTEM('ctdb-tcp',
218                         source=bld.SUBDIR('tcp',
219                                           'tcp_connect.c tcp_init.c tcp_io.c'),
220                         includes='include include/internal',
221                         deps='replace tdb talloc tevent')
222
223     ib_deps = ''
224     if bld.env.HAVE_INFINIBAND:
225         bld.SAMBA_SUBSYSTEM('ctdb-ib',
226                             source=bld.SUBDIR('ib',
227                                               '''ibwrapper.c ibw_ctdb.c
228                                                  ibw_ctdb_init.c'''),
229                             includes='include include/internal',
230                             deps='replace')
231         ib_deps = ' ctdb-ib rdmacm ibverbs'
232
233     bld.SAMBA_SUBSYSTEM('ctdb-common',
234                         source=bld.SUBDIR('common',
235                                           '''ctdb_io.c ctdb_util.c ctdb_ltdb.c
236                                              ctdb_message.c cmdline.c rb_tree.c
237                                              system_common.c ctdb_fork.c'''),
238                         includes='include include/internal common .',
239                         deps='replace popt talloc tevent tdb popt')
240
241     bld.SAMBA_SUBSYSTEM('ctdb-common-util',
242                         source=bld.SUBDIR('common',
243                                           'system_util.c ctdb_logging.c'),
244                         includes='include include/internal',
245                         deps='replace tevent tdb')
246
247     if sys.platform.startswith('linux'):
248         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_linux.c')
249     elif sys.platform.startswith('aix'):
250         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_aix.c')
251     elif sys.platform.startswith('freebsd'):
252         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_freebsd.c')
253     elif sys.platform == 'kfreebsd':
254         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_kfreebsd.c')
255     elif sys.platform == 'gnu':
256         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_gnu.c')
257     else:
258         Logs.error("Platform %s not supported" % sys.platform)
259
260     bld.SAMBA_SUBSYSTEM('ctdb-system',
261                         source=CTDB_SYSTEM_SRC,
262                         includes='include include/internal',
263                         deps='replace talloc tevent tdb pcap')
264
265     bld.SAMBA_SUBSYSTEM('ctdb-client',
266                         source=bld.SUBDIR('client', 'ctdb_client.c'),
267                         includes='include include/internal',
268                         public_headers='include/ctdb_client.h',
269                         deps='''replace popt talloc tevent tdb
270                                 ctdb-util tdb-wrap''')
271
272     bld.SAMBA_SUBSYSTEM('ctdb-server',
273                         source='server/ctdbd.c ' +
274                                bld.SUBDIR('server',
275                                           '''ctdb_daemon.c ctdb_recoverd.c
276                                              ctdb_recover.c ctdb_freeze.c
277                                              ctdb_tunables.c ctdb_monitor.c
278                                              ctdb_server.c ctdb_control.c
279                                              ctdb_call.c ctdb_ltdb_server.c
280                                              ctdb_traverse.c eventscript.c
281                                              ctdb_takeover.c ctdb_serverids.c
282                                              ctdb_persistent.c ctdb_keepalive.c
283                                              ctdb_logging.c ctdb_uptime.c
284                                              ctdb_vacuum.c ctdb_banning.c
285                                              ctdb_statistics.c
286                                              ctdb_update_record.c
287                                              ctdb_lock.c'''),
288                         includes='include include/internal',
289                         public_headers='''include/ctdb.h
290                                           include/ctdb_private.h
291                                           include/ctdb_protocol.h
292                                           include/ctdb_typesafe_cb.h''',
293                         deps='replace popt talloc tevent tdb')
294
295     bld.SAMBA_BINARY('ctdbd',
296                      source='',
297                      deps='''ctdb-server ctdb-client ctdb-common
298                              ctdb-common-util ctdb-system ctdb-tcp''' +
299                           ib_deps,
300                      install_path='${SBINDIR}',
301                      manpages='doc/ctdbd.1')
302
303     bld.SAMBA_BINARY('ctdb',
304                      source='tools/ctdb.c tools/ctdb_vacuum.c',
305                      deps='''ctdb-client ctdb-common ctdb-common-util
306                              ctdb-system''',
307                      includes='include include/internal',
308                      install_path='${BINDIR}',
309                      manpages='doc/ctdb.1')
310
311     bld.SAMBA_BINARY('ltdbtool',
312                      source='tools/ltdbtool.c',
313                      includes='include',
314                      deps='tdb',
315                      install_path='${BINDIR}',
316                      manpages='doc/ltdbtool.1')
317
318     bld.SAMBA_BINARY('ctdb_lock_helper',
319                      source='server/ctdb_lock_helper.c',
320                      deps='ctdb-util ctdb-common-util talloc tdb',
321                      includes='include include/internal',
322                      install_path='${BINDIR}')
323
324     bld.SAMBA_BINARY('ctdb_event_helper',
325                      source='server/ctdb_event_helper.c',
326                      includes='include include/internal',
327                      deps='ctdb-util ctdb-common-util replace tdb',
328                      install_path='${BINDIR}')
329
330     bld.SAMBA_GENERATOR('ctdb-smnotify-h',
331                         source='utils/smnotify/smnotify.x',
332                         target='utils/smnotify/smnotify.h',
333                         rule='rpcgen -h ${SRC} > ${TGT}')
334
335     xdr_buf_hack = 'sed -e "s@^\([ \t]*register int32_t \*buf\);@\\1 = buf;@"'
336
337     bld.SAMBA_GENERATOR('ctdb-smnotify-x',
338                         source='utils/smnotify/smnotify.x',
339                         target='utils/smnotify/gen_xdr.c',
340                         rule='rpcgen -c ${SRC} | ' + xdr_buf_hack + ' > ${TGT}')
341
342     bld.SAMBA_GENERATOR('ctdb-smnotify-c',
343                         source='utils/smnotify/smnotify.x',
344                         target='utils/smnotify/gen_smnotify.c',
345                         rule='rpcgen -l ${SRC} > ${TGT}')
346
347     bld.SAMBA_BINARY('smnotify',
348                      source=bld.SUBDIR('utils/smnotify',
349                                        'smnotify.c gen_smnotify.c gen_xdr.c'),
350                      deps='ctdb-smnotify-h ctdb-smnotify-c ctdb-smnotify-x popt',
351                      includes='utils utils/smnotify',
352                      install_path='${BINDIR}')
353
354     bld.SAMBA_BINARY('ping_pong',
355                      source='utils/ping_pong/ping_pong.c',
356                      deps='',
357                      install_path='${BINDIR}',
358                      manpages='doc/ping_pong.1')
359
360     if bld.env.HAVE_PMDA:
361         bld.SAMBA_BINARY('pmdactdb',
362                          source='utils/pmda/pmda_ctdb.c',
363                          includes='include include/internal',
364                          deps='''ctdb-client ctdb-common ctdb-system
365                                  pcp_pmda pcp''',
366                          install_path='${CTDB_PMDADIR}')
367         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Install',
368                           destname='Install')
369         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Remove',
370                           destname='Remove')
371         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/pmns',
372                           destname='pmns')
373         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/domain.h',
374                           destname='domain.h')
375         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/help',
376                           destname='help')
377         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/README',
378                           destname='README')
379
380     bld.MANPAGES('''doc/onnode.1 doc/ctdbd_wrapper.1 doc/ctdbd.conf.5
381                     doc/ctdb.7 doc/ctdb-statistics.7 doc/ctdb-tunables.7''',
382                  True)
383
384     bld.INSTALL_FILES('${BINDIR}', 'tools/onnode',
385                       destname='onnode', chmod=0755)
386     bld.INSTALL_FILES('${BINDIR}', 'tools/ctdb_diagnostics',
387                       destname='ctdb_diagnostics', chmod=0755)
388     bld.INSTALL_FILES('${SBINDIR}', 'config/ctdbd_wrapper',
389                       destname='ctdbd_wrapper', chmod=0755)
390
391     def SUBDIR_MODE_callback(arg, dirname, fnames):
392         for f in fnames:
393             fl = os.path.join(dirname, f)
394             if os.path.isdir(fl) or os.path.islink(fl):
395                 continue
396             mode = os.lstat(fl).st_mode & 0777
397             if arg['trim_path']:
398                     fl = samba_utils.os_path_relpath(fl, arg['trim_path'])
399             arg['file_list'].append([fl, mode])
400
401     def SUBDIR_MODE(path, trim_path=None):
402         pd = {'trim_path': trim_path, 'file_list': []}
403         os.path.walk(path, SUBDIR_MODE_callback, pd)
404         return pd['file_list']
405
406     etc_subdirs = [
407         'events.d',
408         'nfs-rpc-checks.d'
409     ]
410
411     for t in etc_subdirs:
412         files = SUBDIR_MODE('config/%s' % t, trim_path='config')
413         for fmode in files:
414             bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % fmode[0],
415                               destname=fmode[0], chmod=fmode[1])
416
417     bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/functions',
418                       destname='functions')
419
420     etc_scripts = [
421         'ctdb-crash-cleanup.sh',
422         'debug-hung-script.sh',
423         'debug_locks.sh',
424         'gcore_trace.sh',
425         'notify.sh',
426         'statd-callout'
427     ]
428
429     for t in etc_scripts:
430         bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/' + t,
431                           destname=t, chmod=0755)
432
433     bld.INSTALL_FILES('${SYSCONFDIR}/sudoers.d', 'config/ctdb.sudoers',
434                       destname='ctdb')
435
436     bld.INSTALL_FILES('${CTDB_ETCDIR}/notify.d', 'config/notify.d.README',
437                       destname='README')
438
439     bld.install_dir(bld.env.CTDB_LOGDIR)
440     bld.install_dir(bld.env.CTDB_RUNDIR)
441     bld.install_dir(bld.env.CTDB_VARDIR)
442
443     sed_expr = 's/@PACKAGE_VERSION@/%s/g' % VERSION
444     t = bld.SAMBA_GENERATOR('ctdb-pc',
445                             source='ctdb.pc.in',
446                             target='ctdb.pc',
447                             rule='sed -e "%s" ${SRC} > ${TGT}' % sed_expr,
448                             dep_vars=['VERSION'])
449     t.env.VERSION = VERSION
450     bld.INSTALL_FILES('${LIBDIR}/pkgconfig', 'ctdb.pc')
451
452     # Test binaries
453     ctdb_tests = [
454         'rb_test',
455         'ctdb_bench',
456         'ctdb_fetch',
457         'ctdb_fetch_one',
458         'ctdb_fetch_readonly_once',
459         'ctdb_fetch_readonly_loop',
460         'ctdb_trackingdb_test',
461         'ctdb_update_record',
462         'ctdb_update_record_persistent',
463         'ctdb_store',
464         'ctdb_traverse',
465         'ctdb_randrec',
466         'ctdb_persistent',
467         'ctdb_porting_tests',
468         'ctdb_transaction',
469         'ctdb_lock_tdb'
470     ]
471
472     for target in ctdb_tests:
473         src = 'tests/src/' + target + '.c'
474
475         bld.SAMBA_BINARY(target,
476                          source=src,
477                          includes='include include/internal',
478                          deps='''ctdb-client ctdb-common ctdb-common-util
479                                  ctdb-system''',
480                          install_path='${CTDB_TEST_LIBDIR}')
481
482     bld.SAMBA_BINARY('ctdb_takeover_tests',
483                      source='tests/src/ctdb_takeover_tests.c',
484                      deps='''replace popt tdb tevent talloc ctdb-system
485                              ctdb-util tdb-wrap''' +
486                           ib_deps,
487                      includes='include include/internal',
488                      install_path='${CTDB_TEST_LIBDIR}')
489
490     bld.SAMBA_BINARY('ctdb_functest',
491                      source='tests/src/ctdb_functest.c',
492                      deps='''replace tdb tevent talloc popt ctdb-system
493                              ctdb-util tdb-wrap''',
494                      includes='include include/internal',
495                      install_path='${CTDB_TEST_LIBDIR}')
496
497     bld.SAMBA_BINARY('ctdb_stubtest',
498                      source='tests/src/ctdb_test.c',
499                      deps='''replace tdb tevent talloc popt ctdb-system
500                              ctdb-util tdb-wrap''',
501                      includes='include include/internal',
502                      install_path='${CTDB_TEST_LIBDIR}')
503
504     if bld.env.HAVE_INFINIBAND:
505         bld.SAMBA_BINARY('ibwrapper_test',
506                          source='ib/ibwrapper_test.c',
507                          includes='include include/internal',
508                          deps='''replace talloc ctdb-client ctdb-common
509                                  ctdb-system''' +
510                               ib_deps,
511                          install_path='${CTDB_TEST_LIBDIR}')
512
513     test_subdirs = [
514         'complex',
515         'events.d',
516         'eventscripts',
517         'onnode',
518         'simple',
519         'takeover',
520         'tool'
521     ]
522
523     for t in test_subdirs:
524         files = SUBDIR_MODE('tests/%s' % t, trim_path='tests')
525         for fmode in files:
526             bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR, 'tests/%s' % fmode[0],
527                               destname=fmode[0], chmod=fmode[1])
528
529     # Install tests/scripts directory without test_wrap
530     test_scripts = [
531         'common.sh',
532         'integration.bash',
533         'unit.sh'
534     ]
535
536     for t in test_scripts:
537         bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR,
538                           os.path.join('tests/scripts', t),
539                           destname=os.path.join('scripts', t))
540
541     sed_expr = 's@^TEST_SCRIPTS_DIR=.*@&\\nexport TEST_BIN_DIR=\"%s\"@' % (
542                bld.env.CTDB_TEST_LIBDIR)
543     bld.SAMBA_GENERATOR('ctdb-test-wrap',
544                         source='tests/scripts/test_wrap',
545                         target='test_wrap',
546                         rule='sed -e "%s" ${SRC} > ${TGT}' % sed_expr)
547     bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts", 'test_wrap',
548                       destname='test_wrap', chmod=0755)
549
550     sed_expr1 = 's@^test_dir=.*@test_dir=%s\\nexport TEST_BIN_DIR=\"%s\"@' % (
551                 bld.env.CTDB_TEST_DATADIR, bld.env.CTDB_TEST_LIBDIR)
552     sed_expr2 = 's@^\(export CTDB_TESTS_ARE_INSTALLED\)=false@\\1=true@'
553     bld.SAMBA_GENERATOR('ctdb-test-runner',
554                         source='tests/run_tests.sh',
555                         target='ctdb_run_tests.sh',
556                         rule='sed -e "%s" -e "%s" ${SRC} > ${TGT}' % (
557                              sed_expr1, sed_expr2))
558     bld.INSTALL_FILES('${BINDIR}', 'ctdb_run_tests.sh',
559                       destname='ctdb_run_tests', chmod=0755)
560     bld.symlink_as(os.path.join(bld.env.BINDIR, 'ctdb_run_cluster_tests'),
561                    'ctdb_run_tests')
562
563     test_eventscript_links = [
564         'events.d',
565         'functions',
566         'nfs-rpc-checks.d'
567     ]
568
569     test_link_dir = os.path.join(bld.env.CTDB_TEST_DATADIR,
570                                  'eventscripts/etc-ctdb')
571     for t in test_eventscript_links:
572         bld.symlink_as(os.path.join(test_link_dir, t),
573                        os.path.join(bld.env.CTDB_ETCDIR, t))
574
575
576 def testonly(ctx):
577     cmd = 'tests/run_tests.sh -V tests/var'
578     ret = samba_utils.RUN_COMMAND(cmd)
579     if ret != 0:
580         print('tests exited with exit status %d' % ret)
581         sys.exit(ret)
582
583
584 def test(ctx):
585     import Scripting
586     Scripting.commands.append('build')
587     Scripting.commands.append('testonly')
588
589
590 def autotest(ctx):
591     cmd = 'LD_PRELOAD=bin/shared/libsocket-wrapper.so tests/run_tests.sh -e -S -C'
592     ret = samba_utils.RUN_COMMAND(cmd)
593     if ret != 0:
594         print('autotest exited with exit status %d' % ret)
595         sys.exit(ret)
596
597
598 def show_version(ctx):
599     print VERSION
600
601
602 def dist():
603     samba_dist.DIST_FILES('VERSION:VERSION', extend=True)
604
605     t = 'include/ctdb_version.h'
606     cmd = 'packaging/mkversion.sh %s %s' % (t, VERSION)
607     ret = samba_utils.RUN_COMMAND(cmd)
608     if ret != 0:
609         print('Command "%s" failed with exit status %d' % (cmd, ret))
610         sys.exit(ret)
611     samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
612
613     t = 'ctdb.spec'
614     sed_expr1 = 's/@VERSION@/%s/g' % VERSION
615     sed_expr2 = 's/@RELEASE@/%s/g' % '1'
616     cmd = 'sed -e "%s" -e "%s" packaging/RPM/ctdb.spec.in > %s' % (
617         sed_expr1, sed_expr2, t)
618     ret = samba_utils.RUN_COMMAND(cmd)
619     if ret != 0:
620         print('Command "%s" failed with exit status %d' % (cmd, ret))
621         sys.exit(ret)
622     samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
623
624     manpages = [
625         'ctdb.1',
626         'ctdb.7',
627         'ctdbd.1',
628         'ctdbd.conf.5',
629         'ctdbd_wrapper.1',
630         'ctdb-statistics.7',
631         'ctdb-tunables.7',
632         'ltdbtool.1'
633     ]
634
635     cmd = 'make -C doc'
636     ret = samba_utils.RUN_COMMAND(cmd)
637     if ret != 0:
638         print('Command "%s" failed with exit status %d' % (cmd, ret))
639         sys.exit(ret)
640     for t in manpages:
641         samba_dist.DIST_FILES('ctdb/doc/%s:doc/%s' % (t, t), extend=True)
642         samba_dist.DIST_FILES('ctdb/doc/%s.html:doc/%s.html' % (t, t),
643                               extend=True)
644
645     samba_dist.dist()
646
647
648 def rpmonly(ctx):
649     cmd = 'rpmbuild -ta --clean --rmsource ctdb-%s.tar.gz' % VERSION
650     ret = samba_utils.RUN_COMMAND(cmd)
651     if ret != 0:
652         print('rpmbuild exited with exit status %d' % ret)
653         sys.exit(ret)
654
655
656 def rpm(ctx):
657     import Scripting
658     Scripting.commands.append('dist')
659     Scripting.commands.append('rpmonly')
660
661
662 def ctags(ctx):
663     "build 'tags' file using ctags"
664     import Utils
665     source_root = os.path.dirname(Utils.g_module.root_path)
666     cmd = 'ctags $(find %s -name "*.[ch]")' % source_root
667     print("Running: %s" % cmd)
668     ret = samba_utils.RUN_COMMAND(cmd)
669     if ret != 0:
670         print('ctags failed with exit status %d' % ret)
671         sys.exit(ret)