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