ctdb-build: popt has moved from lib/ to third_party/
[obnox/samba/samba-obnox.git] / ctdb / wscript
index 1dcc11cbc2ba214b06407d6e32098c8e696d61fb..35eeac49a39f00f061aafd0d239604d26115db7c 100755 (executable)
@@ -12,14 +12,14 @@ while not os.path.exists(srcdir+'/buildtools') and len(srcdir.split('/')) < 5:
     srcdir = srcdir + '/..'
 sys.path.insert(0, srcdir + '/buildtools/wafsamba')
 
-import wafsamba, samba_dist, Options, Logs
+import wafsamba, samba_dist, Options, Logs, Utils
 import samba_utils, samba_version
 
 env = samba_utils.LOAD_ENVIRONMENT()
 if os.path.isfile('./VERSION'):
-    vdir='.'
+    vdir = '.'
 elif os.path.isfile('../VERSION'):
-    vdir='..'
+    vdir = '..'
 else:
     Logs.error("VERSION file not found")
 
@@ -29,10 +29,12 @@ VERSION = version.STRING.replace('-', '.')
 Options.default_prefix = '/usr/local'
 
 samba_dist.DIST_DIRS('''ctdb:. lib/replace:lib/replace lib/talloc:lib/talloc
-                        lib/tevent:lib/tevent lib/tdb:lib/tdb lib/popt:lib/popt
+                        lib/tevent:lib/tevent lib/tdb:lib/tdb
                         lib/socket_wrapper:lib/socket_wrapper
+                        third_party/popt:third_party/popt
                         buildtools:buildtools''')
 
+
 def set_options(opt):
     opt.PRIVATE_EXTENSION_DEFAULT('ctdb')
     opt.RECURSE('lib/replace')
@@ -51,8 +53,9 @@ def set_options(opt):
                    help=("Path to log directory"),
                    action="store", dest='ctdb_logdir', default=None)
     opt.add_option('--with-socketpath',
-                  help=("path to CTDB daemon socket"),
-                  action="store_true", dest='ctdb_sockpath', default=False)
+                   help=("path to CTDB daemon socket"),
+                   action="store_true", dest='ctdb_sockpath', default=False)
+
 
 def configure(conf):
 
@@ -64,7 +67,14 @@ def configure(conf):
         Options.options.disable_python = True
 
     conf.RECURSE('lib/replace')
-    conf.RECURSE('lib/popt')
+    if conf.CHECK_FOR_THIRD_PARTY():
+        conf.RECURSE('third_party/popt')
+    else:
+        if not conf.CHECK_POPT():
+            raise Utils.WafError('popt development packages have not been found\nIf third_party is installed, check that it is in the proper place.')
+        else:
+            conf.define('USING_SYSTEM_POPT', 1)
+
     conf.RECURSE('lib/talloc')
     conf.RECURSE('lib/tevent')
     conf.RECURSE('lib/tdb')
@@ -150,9 +160,12 @@ def configure(conf):
     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
     conf.SAMBA_CONFIG_H()
 
+
 def build(bld):
     bld.RECURSE('lib/replace')
-    bld.RECURSE('lib/popt')
+    if bld.CHECK_FOR_THIRD_PARTY():
+        bld.RECURSE('third_party/popt')
+
     bld.RECURSE('lib/talloc')
     bld.RECURSE('lib/tevent')
     bld.RECURSE('lib/tdb')
@@ -357,9 +370,9 @@ def build(bld):
             arg['file_list'].append([fl, mode])
 
     def SUBDIR_MODE(path, trim_path=None):
-         pd = {'trim_path': trim_path, 'file_list': []}
-         os.path.walk(path, SUBDIR_MODE_callback, pd)
-         return pd['file_list']
+        pd = {'trim_path': trim_path, 'file_list': []}
+        os.path.walk(path, SUBDIR_MODE_callback, pd)
+        return pd['file_list']
 
     etc_subdirs = [
         'events.d',
@@ -426,14 +439,14 @@ def build(bld):
     ]
 
     for t in ctdb_tests:
-         target = 'bin/' + t
-         src = 'tests/src/' + t + '.c'
+        target = 'bin/' + t
+        src = 'tests/src/' + t + '.c'
 
-         bld.SAMBA_BINARY(target,
-                          source=src,
-                          deps='''ctdb-client ctdb-common ctdb-common-util
-                                  ctdb-system ctdb-util ctdb-util-misc''',
-                          install_path='${CTDB_TEST_LIBDIR}')
+        bld.SAMBA_BINARY(target,
+                         source=src,
+                         deps='''ctdb-client ctdb-common ctdb-common-util
+                                 ctdb-system ctdb-util ctdb-util-misc''',
+                         install_path='${CTDB_TEST_LIBDIR}')
 
     bld.SAMBA_BINARY('bin/ctdb_takeover_tests',
                      source='tests/src/ctdb_takeover_tests.c',
@@ -468,7 +481,6 @@ def build(bld):
         'events.d',
         'eventscripts',
         'onnode',
-        'scripts',
         'simple',
         'takeover',
         'tool'
@@ -480,16 +492,30 @@ def build(bld):
             bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR, 'tests/%s' % fmode[0],
                               destname=fmode[0], chmod=fmode[1])
 
+    # Install tests/scripts directory without test_wrap
+    test_scripts = [
+        'common.sh',
+        'integration.bash',
+        'unit.sh'
+    ]
+
+    for t in test_scripts:
+        bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR,
+                          os.path.join('tests/scripts', t),
+                          destname=os.path.join('scripts', t))
+
     sed_expr = 's@^TEST_SCRIPTS_DIR=.*@&\\nexport TEST_BIN_DIR=\"%s\"@' % (
                bld.env.CTDB_TEST_LIBDIR)
     bld.SAMBA_GENERATOR('ctdb-test-wrap',
                         source='tests/scripts/test_wrap',
                         target='test_wrap',
                         rule='sed -e "%s" ${SRC} > ${TGT}' % sed_expr)
+    bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts", 'test_wrap',
+                      destname='test_wrap', chmod=0755)
 
     sed_expr1 = 's@^test_dir=.*@test_dir=%s\\nexport TEST_BIN_DIR=\"%s\"@' % (
-                bld.env.CTDB_DATA_DIR, bld.env.CTDB_LIBDIR)
-    sed_expr2 = 's@^\(export CTDB_TESTS_ARE_INSTALLED\)=false@\1=true@'
+                bld.env.CTDB_TEST_DATADIR, bld.env.CTDB_TEST_LIBDIR)
+    sed_expr2 = 's@^\(export CTDB_TESTS_ARE_INSTALLED\)=false@\\1=true@'
     bld.SAMBA_GENERATOR('ctdb-test-runner',
                         source='tests/run_tests.sh',
                         target='ctdb_run_tests.sh',
@@ -515,32 +541,50 @@ def build(bld):
 
 def testonly(ctx):
     cmd = 'tests/run_tests.sh -V tests/var'
-    samba_utils.RUN_COMMAND(cmd)
+    ret = samba_utils.RUN_COMMAND(cmd)
+    if ret != 0:
+        print('tests exited with exit status %d' % ret)
+        sys.exit(ret)
+
 
 def test(ctx):
     import Scripting
     Scripting.commands.append('build')
     Scripting.commands.append('testonly')
 
+
 def autotest(ctx):
     cmd = 'LD_PRELOAD=bin/shared/libsocket-wrapper.so tests/run_tests.sh -e -S -C'
-    samba_utils.RUN_COMMAND(cmd)
+    ret = samba_utils.RUN_COMMAND(cmd)
+    if ret != 0:
+        print('autotest exited with exit status %d' % ret)
+        sys.exit(ret)
+
 
 def show_version(ctx):
     print VERSION
 
+
 def dist():
     samba_dist.DIST_FILES('VERSION:VERSION', extend=True)
 
     t = 'include/ctdb_version.h'
-    out = os.system('packaging/mkversion.sh %s %s' % (t, VERSION))
+    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'
-    os.system('sed -e "%s" -e "%s" packaging/RPM/ctdb.spec.in > %s' %
-              (sed_expr1, sed_expr2, t))
+    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 = [
@@ -553,7 +597,11 @@ def dist():
         'ltdbtool.1'
     ]
 
-    os.system('make -C doc')
+    cmd = 'make -C doc'
+    ret = samba_utils.RUN_COMMAND(cmd)
+    if ret != 0:
+        print('Command "%s" failed with exit status %d' % (cmd, ret))
+        sys.exit(ret)
     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),
@@ -561,19 +609,28 @@ def dist():
 
     samba_dist.dist()
 
+
 def rpmonly(ctx):
     cmd = 'rpmbuild -ta --clean --rmsource ctdb-%s.tar.gz' % VERSION
-    samba_utils.RUN_COMMAND(cmd)
+    ret = samba_utils.RUN_COMMAND(cmd)
+    if ret != 0:
+        print('rpmbuild exited with exit status %d' % ret)
+        sys.exit(ret)
+
 
 def rpm(ctx):
     import Scripting
     Scripting.commands.append('dist')
     Scripting.commands.append('rpmonly')
 
+
 def ctags(ctx):
     "build 'tags' file using ctags"
     import Utils
     source_root = os.path.dirname(Utils.g_module.root_path)
-    cmd = 'ctags $(find %s/.. -name "*.[ch]" | grep -v "*_proto\.h")' % source_root
+    cmd = 'ctags $(find %s -name "*.[ch]")' % source_root
     print("Running: %s" % cmd)
-    os.system(cmd)
+    ret = samba_utils.RUN_COMMAND(cmd)
+    if ret != 0:
+        print('ctags failed with exit status %d' % ret)
+        sys.exit(ret)