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