ctdb-protocol: Fix typo in type of return variable
[samba.git] / ctdb / wscript
index 446bd8d3529dce6d2dc28fd5f81b32e66071932d..fdd187b7d26c99550f911385aafc322b40ac0ec7 100644 (file)
@@ -107,8 +107,8 @@ def configure(conf):
     if conf.env.standalone_ctdb:
         conf.SAMBA_CHECK_PERL(mandatory=True)
 
-        conf.SAMBA_CHECK_PYTHON(mandatory=True, version=(2,5,0))
-        conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=True)
+        conf.SAMBA_CHECK_PYTHON(mandatory=False, version=(2,5,0))
+        conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
 
     if conf.CHECK_FOR_THIRD_PARTY():
         conf.RECURSE('third_party/popt')
@@ -287,34 +287,28 @@ def configure(conf):
             else:
                 Logs.info("  %s: no" % (m))
 
+def gen_ctdb_version(task):
+    fp = file(task.outputs[0].bldpath(task.env), 'w')
+    fp.write('/* This file is auto-generated from waf */\n')
+    fp.write('#include "version.h"\n')
+    fp.write('\n')
+    fp.write('#define CTDB_VERSION_STRING "%s"\n' % VERSION)
+    fp.close()
+
+
 def build(bld):
     if bld.env.standalone_ctdb:
         # enable building of public headers in the build tree
         bld.env.build_public_headers = 'include/public'
 
-    version_h = samba_utils.os_path_relpath(os.path.join(Options.launch_dir,
-                                                         "version.h"),
-                                            bld.curdir)
-
     if bld.env.standalone_ctdb:
-        ctdb_mkversion = '../packaging/mkversion.sh'
-        t = bld.SAMBA_GENERATOR('ctdb-version-header',
-                                target='include/ctdb_version.h',
-                                rule='%s ${TGT} %s' % (ctdb_mkversion, VERSION),
-                                dep_vars=['VERSION'])
-        t.env.VERSION = VERSION
-
-        t = bld.SAMBA_GENERATOR('ctdb-samba-version-header',
-                                target=version_h,
-                                rule='printf "#include \\"ctdb_version.h\\" \\n#define SAMBA_VERSION_STRING CTDB_VERSION_STRING\\n" > ${TGT}',
-                                dep_vars=['VERSION'])
-        t.env.VERSION = VERSION
-    else:
-        t = bld.SAMBA_GENERATOR('ctdb-samba-version-header',
-                                target='include/ctdb_version.h',
-                                rule='printf "#include \\"%s\\" \\n#define CTDB_VERSION_STRING SAMBA_VERSION_STRING\\n" > ${TGT}' % version_h,
-                                dep_vars=['VERSION'])
-        t.env.VERSION = VERSION
+        bld.SAMBA_MKVERSION('version.h', '%s/VERSION' % vdir)
+
+    t = bld.SAMBA_GENERATOR('ctdb-version-header',
+                            target='include/ctdb_version.h',
+                            rule=gen_ctdb_version,
+                            dep_vars=['VERSION'])
+    t.env.VERSION = VERSION
 
     bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
 
@@ -383,30 +377,40 @@ def build(bld):
                                           '''ctdb_io.c ctdb_util.c ctdb_ltdb.c
                                              sock_io.c'''),
                         includes='include',
-                        deps='replace popt talloc tevent tdb popt ctdb-system')
+                        deps='''replace popt talloc tevent tdb popt ctdb-system
+                                ctdb-protocol-util''')
 
     bld.SAMBA_SUBSYSTEM('ctdb-util',
                         source=bld.SUBDIR('common',
                                           '''db_hash.c srvid.c reqid.c
                                              pkt_read.c pkt_write.c comm.c
                                              logging.c rb_tree.c tunable.c
-                                             pidfile.c run_proc.c'''),
+                                             pidfile.c run_proc.c
+                                             hash_count.c run_event.c
+                                             sock_client.c version.c'''),
                         deps='''samba-util sys_rw tevent-util
                                 replace talloc tevent tdb''')
 
     bld.SAMBA_SUBSYSTEM('ctdb-protocol',
                         source=bld.SUBDIR('protocol',
                                           '''protocol_header.c protocol_packet.c
-                                             protocol_types.c protocol_call.c
+                                             protocol_basic.c protocol_types.c
+                                             protocol_call.c
                                              protocol_message.c
                                              protocol_control.c
+                                             protocol_keepalive.c
+                                             protocol_tunnel.c
                                              protocol_client.c
                                              protocol_debug.c
-                                             protocol_util.c
-                                             protocol_event.c'''),
+                                             protocol_event.c
+                                             protocol_sock.c'''),
                         includes='include',
                         deps='replace talloc tdb')
 
+    bld.SAMBA_SUBSYSTEM('ctdb-protocol-util',
+                        source='protocol/protocol_util.c',
+                        deps='replace talloc tdb')
+
     bld.SAMBA_SUBSYSTEM('ctdb-client',
                         source=bld.SUBDIR('client', 'ctdb_client.c'),
                         includes='include',
@@ -420,7 +424,7 @@ def build(bld):
                                              client_message_sync.c
                                              client_control_sync.c
                                              client_db.c client_util.c
-                                             client_event.c
+                                             client_event.c client_tunnel.c
                                           '''),
                         includes='include',
                         deps='replace talloc tevent tdb tdb-wrap')
@@ -440,7 +444,7 @@ def build(bld):
                                              ipalloc.c
                                           '''),
                         includes='include',
-                        deps='ctdb-protocol replace talloc tevent')
+                        deps='ctdb-protocol-util replace talloc tevent')
 
     bld.SAMBA_BINARY('ctdbd',
                      source='server/ctdbd.c ' +
@@ -459,9 +463,10 @@ def build(bld):
                                              ctdb_vacuum.c ctdb_banning.c
                                              ctdb_statistics.c
                                              ctdb_update_record.c
-                                             ctdb_lock.c ctdb_fork.c'''),
+                                             ctdb_lock.c ctdb_fork.c
+                                             ctdb_tunnel.c'''),
                      includes='include',
-                     deps='''ctdb-ipalloc ctdb-client ctdb-common ctdb-system
+                     deps='''ctdb-client ctdb-common ctdb-system ctdb-protocol
                              ctdb-tcp ctdb-util replace sys_rw popt
                              talloc tevent tdb talloc_report''' +
                           ib_deps,
@@ -470,21 +475,21 @@ def build(bld):
 
     bld.SAMBA_BINARY('ctdb',
                      source='tools/ctdb.c',
-                     deps='''ctdb-client2 ctdb-protocol ctdb-util ctdb-system
-                             samba-util sys_rw popt''',
+                     deps='''ctdb-client2 ctdb-protocol ctdb-protocol-util
+                             ctdb-util ctdb-system samba-util sys_rw popt''',
                      install_path='${BINDIR}',
                      manpages='ctdb.1')
 
     bld.SAMBA_BINARY('ctdb_killtcp',
                      source='tools/ctdb_killtcp.c',
-                     deps='''ctdb-protocol ctdb-util ctdb-system
+                     deps='''ctdb-protocol-util ctdb-util ctdb-system
                              samba-util replace''',
                      install_path='${CTDB_HELPER_BINDIR}')
 
     bld.SAMBA_BINARY('ctdb_event',
                      source='tools/ctdb_event.c',
-                     deps='''ctdb-client2 ctdb-protocol ctdb-util ctdb-system
-                             samba-util replace''',
+                     deps='''ctdb-client2 ctdb-protocol ctdb-protocol-util
+                             ctdb-util ctdb-system samba-util replace''',
                      install_path='${CTDB_HELPER_BINDIR}')
 
     bld.SAMBA_BINARY('ltdbtool',
@@ -496,8 +501,8 @@ def build(bld):
 
     bld.SAMBA_BINARY('ctdb_eventd',
                      source='server/ctdb_eventd.c',
-                     deps='''ctdb-server-util ctdb-protocol ctdb-util
-                             samba-util LIBASYNC_REQ replace popt''',
+                     deps='''ctdb-server-util ctdb-protocol ctdb-protocol-util
+                             ctdb-util samba-util LIBASYNC_REQ replace popt''',
                      install_path='${CTDB_HELPER_BINDIR}')
 
     bld.SAMBA_BINARY('ctdb_lock_helper',
@@ -732,12 +737,12 @@ def build(bld):
         'comm_test',
         'comm_server_test',
         'comm_client_test',
-        'protocol_types_test',
-        'protocol_client_test',
         'pidfile_test',
         'run_proc_test',
         'sock_daemon_test',
         'sock_io_test',
+        'hash_count_test',
+        'run_event_test',
     ]
 
     for target in ctdb_unit_tests:
@@ -769,6 +774,33 @@ def build(bld):
                      deps='samba-util ctdb-system popt',
                      install_path='${CTDB_TEST_LIBEXECDIR}')
 
+    bld.SAMBA_SUBSYSTEM('protocol-tests-common',
+                        source=bld.SUBDIR('tests/src',
+                                          '''protocol_common.c
+                                             protocol_common_ctdb.c
+                                             protocol_common_event.c
+                                          '''),
+                        includes='include',
+                        deps='replace popt talloc tevent tdb')
+
+    ctdb_protocol_tests = [
+            'protocol_basic_test',
+            'protocol_types_test',
+            'protocol_ctdb_test',
+            'protocol_event_test',
+            'protocol_util_test',
+            'protocol_types_compat_test',
+            'protocol_ctdb_compat_test',
+    ]
+
+    for target in ctdb_protocol_tests:
+        src = 'tests/src/' + target + '.c'
+
+        bld.SAMBA_BINARY(target,
+                         source=src,
+                         deps='''protocol-tests-common
+                                 samba-util talloc tdb''',
+                         install_path='${CTDB_TEST_LIBEXECDIR}')
 
     bld.SAMBA_SUBSYSTEM('ctdb-tests-common',
                         source=bld.SUBDIR('tests/src',
@@ -776,11 +808,6 @@ def build(bld):
                         includes='include',
                         deps='replace popt talloc tevent tdb')
 
-    bld.SAMBA_BINARY('protocol_util_test',
-                     source='tests/src/protocol_util_test.c',
-                     deps='talloc ctdb-protocol samba-util',
-                     install_path='${CTDB_TEST_LIBEXECDIR}')
-
     # Test binaries
     ctdb_tests = [
         'g_lock_loop',
@@ -793,7 +820,10 @@ def build(bld):
         'transaction_loop',
         'update_record',
         'update_record_persistent',
-        'lock_tdb'
+        'lock_tdb',
+        'dummy_client',
+        'tunnel_test',
+        'tunnel_cmd',
     ]
 
     for target in ctdb_tests:
@@ -818,8 +848,9 @@ def build(bld):
     bld.SAMBA_BINARY('fake_ctdbd',
                      source='''tests/src/fake_ctdbd.c
                                tests/src/ipalloc_read_known_ips.c''',
-                     deps='''ctdb-util ctdb-protocol ctdb-system
-                             samba-util tevent-util LIBASYNC_REQ popt''',
+                     deps='''ctdb-util ctdb-protocol ctdb-protocol-util
+                             ctdb-system samba-util tevent-util
+                             LIBASYNC_REQ popt''',
                      install_path='${CTDB_TEST_LIBEXECDIR}')
 
     if bld.env.HAVE_INFINIBAND:
@@ -830,7 +861,7 @@ def build(bld):
                               ib_deps,
                          install_path='${CTDB_TEST_LIBEXECDIR}')
 
-    if bld.env.HAVE_ROBUST_MUTEXES:
+    if bld.env.HAVE_ROBUST_MUTEXES and sys.platform.startswith('linux'):
         bld.SAMBA_BINARY('test_mutex_raw',
                          source='tests/src/test_mutex_raw.c',
                          deps='pthread',
@@ -850,8 +881,13 @@ def build(bld):
         'tool'
     ]
 
+    if bld.env.standalone_ctdb:
+        testdir = 'tests'
+    else:
+        testdir = 'ctdb/tests'
+
     for t in test_subdirs:
-        files = SUBDIR_MODE('tests/%s' % t, trim_path='tests')
+        files = SUBDIR_MODE('%s/%s' % (testdir, t), trim_path=testdir)
         for fmode in files:
             bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR, 'tests/%s' % fmode[0],
                               destname=fmode[0], chmod=fmode[1])
@@ -885,8 +921,9 @@ def build(bld):
                       'script_install_paths.sh',
                       destname='script_install_paths.sh', chmod=0644)
 
-    sed_expr1 = 's@^test_dir=.*@test_dir=%s\\nexport TEST_BIN_DIR=\"%s\"@' % (
-                bld.env.CTDB_TEST_DATADIR, bld.env.CTDB_TEST_LIBEXECDIR)
+    sed_expr1 = 's@^\(export %s\)=.*@\\1=%s\\nexport %s=\"%s\"@''' % (
+                    'CTDB_TEST_DIR', bld.env.CTDB_TEST_DATADIR,
+                    'TEST_BIN_DIR', bld.env.CTDB_TEST_LIBEXECDIR)
     sed_expr2 = 's@^\(export CTDB_TESTS_ARE_INSTALLED\)=false@\\1=true@'
     bld.SAMBA_GENERATOR('ctdb-test-runner',
                         source='tests/run_tests.sh',
@@ -952,28 +989,7 @@ def show_version(ctx):
     print VERSION
 
 
-def dist():
-    samba_dist.DIST_FILES('VERSION:VERSION', extend=True)
-
-    t = 'include/ctdb_version.h'
-    cmd = 'packaging/mkversion.sh %s %s' % (t, VERSION)
-    ret = samba_utils.RUN_COMMAND(cmd)
-    if ret != 0:
-        print('Command "%s" failed with exit status %d' % (cmd, ret))
-        sys.exit(ret)
-    samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
-
-    t = 'ctdb.spec'
-    sed_expr1 = 's/@VERSION@/%s/g' % VERSION
-    sed_expr2 = 's/@RELEASE@/%s/g' % '1'
-    cmd = 'sed -e "%s" -e "%s" packaging/RPM/ctdb.spec.in > %s' % (
-        sed_expr1, sed_expr2, t)
-    ret = samba_utils.RUN_COMMAND(cmd)
-    if ret != 0:
-        print('Command "%s" failed with exit status %d' % (cmd, ret))
-        sys.exit(ret)
-    samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
-
+def manpages(ctx):
     BASE_URL = 'http://docbook.sourceforge.net/release/xsl/current'
     MAN_XSL = '%s/manpages/docbook.xsl' % BASE_URL
     HTML_XSL = '%s/html/docbook.xsl' % BASE_URL
@@ -992,6 +1008,29 @@ def dist():
             print('Command %s failed with exit status %d' % (cmd, ret))
             sys.exit(ret)
 
+
+def distonly(ctx):
+    samba_dist.DIST_FILES('VERSION:VERSION', extend=True)
+
+    distfile = file('.distversion', 'w')
+    for field in version.vcs_fields:
+        distfile.write('%s=%s\n' % (field, str(version.vcs_fields[field])))
+    distfile.close()
+    samba_dist.DIST_FILES('ctdb/.distversion:.distversion', extend=True)
+
+    t = 'ctdb.spec'
+    sed_expr1 = 's/@VERSION@/%s/g' % VERSION
+    sed_expr2 = 's/@RELEASE@/%s/g' % '1'
+    cmd = 'sed -e "%s" -e "%s" packaging/RPM/ctdb.spec.in > %s' % (
+        sed_expr1, sed_expr2, t)
+    ret = samba_utils.RUN_COMMAND(cmd)
+    if ret != 0:
+        print('Command "%s" failed with exit status %d' % (cmd, ret))
+        sys.exit(ret)
+    samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
+
+    manpages = manpages_binary + manpages_misc + manpages_etcd + manpages_ceph
+    for t in manpages:
         samba_dist.DIST_FILES('ctdb/doc/%s:doc/%s' % (t, t), extend=True)
         samba_dist.DIST_FILES('ctdb/doc/%s.html:doc/%s.html' % (t, t),
                               extend=True)
@@ -999,6 +1038,12 @@ def dist():
     samba_dist.dist()
 
 
+def dist():
+    import Scripting
+    Scripting.commands.append('manpages')
+    Scripting.commands.append('distonly')
+
+
 def rpmonly(ctx):
     opts = os.getenv('RPM_OPTIONS') or ''
     cmd = 'rpmbuild -ta --clean --rmsource %s ctdb-%s.tar.gz' % (opts, VERSION)
@@ -1010,7 +1055,8 @@ def rpmonly(ctx):
 
 def rpm(ctx):
     import Scripting
-    Scripting.commands.append('dist')
+    Scripting.commands.append('manpages')
+    Scripting.commands.append('distonly')
     Scripting.commands.append('rpmonly')