buildtools/wafsamba: Decode output of cmd_output (which is bytes)
[samba.git] / buildtools / wafsamba / samba_conftests.py
index 9c0b651094293361c99034bb566a0f0b736f5dee..c0b9ae4929649692c9870edf28e8e0aa94fca113 100644 (file)
@@ -2,35 +2,35 @@
 # to test for commonly needed configuration options
 
 import os, shutil, re
-import Build, Configure, Utils
-from Configure import conf
-import config_c
-from samba_utils import *
+from waflib import Build, Configure, Utils, Options, Logs, Errors
+from waflib.Configure import conf
+from samba_utils import TO_LIST, ADD_LD_LIBRARY_PATH
 
 
 def add_option(self, *k, **kw):
     '''syntax help: provide the "match" attribute to opt.add_option() so that folders can be added to specific config tests'''
+    Options.OptionsContext.parser = self
     match = kw.get('match', [])
     if match:
         del kw['match']
     opt = self.parser.add_option(*k, **kw)
     opt.match = match
     return opt
-Options.Handler.add_option = add_option
+Options.OptionsContext.add_option = add_option
 
 @conf
 def check(self, *k, **kw):
     '''Override the waf defaults to inject --with-directory options'''
 
     if not 'env' in kw:
-        kw['env'] = self.env.copy()
+        kw['env'] = self.env.derive()
 
-    # match the configuration test with speficic options, for example:
+    # match the configuration test with specific options, for example:
     # --with-libiconv -> Options.options.iconv_open -> "Checking for library iconv"
     additional_dirs = []
     if 'msg' in kw:
         msg = kw['msg']
-        for x in Options.Handler.parser.parser.option_list:
+        for x in Options.OptionsContext.parser.parser.option_list:
              if getattr(x, 'match', None) and msg in x.match:
                  d = getattr(Options.options, x.dest, '')
                  if d:
@@ -47,12 +47,12 @@ def check(self, *k, **kw):
     add_options_dir(additional_dirs, kw['env'])
 
     self.validate_c(kw)
-    self.check_message_1(kw['msg'])
+    self.start_msg(kw['msg'])
     ret = None
     try:
         ret = self.run_c_code(*k, **kw)
-    except Configure.ConfigurationError, e:
-        self.check_message_2(kw['errmsg'], 'YELLOW')
+    except Configure.ConfigurationError as e:
+        self.end_msg(kw['errmsg'], 'YELLOW')
         if 'mandatory' in kw and kw['mandatory']:
             if Logs.verbose > 1:
                 raise
@@ -60,7 +60,7 @@ def check(self, *k, **kw):
                 self.fatal('the configuration failed (see %r)' % self.log.name)
     else:
         kw['success'] = ret
-        self.check_message_2(self.ret_msg(kw['okmsg'], kw))
+        self.end_msg(self.ret_msg(kw['okmsg'], kw))
 
         # success! keep the CPPPATH/LIBPATH
         add_options_dir(additional_dirs, self.env)
@@ -163,7 +163,7 @@ def find_config_dir(conf):
     '''find a directory to run tests in'''
     k = 0
     while k < 10000:
-        dir = os.path.join(conf.blddir, '.conf_check_%d' % k)
+        dir = os.path.join(conf.bldnode.abspath(), '.conf_check_%d' % k)
         try:
             shutil.rmtree(dir)
         except OSError:
@@ -197,7 +197,7 @@ int foo(int v) {
     return v * 2;
 }
 '''
-    return conf.check(features='c cshlib',vnum="1",fragment=snip,msg=msg)
+    return conf.check(features='c cshlib',vnum="1",fragment=snip,msg=msg, mandatory=False)
 
 @conf
 def CHECK_NEED_LC(conf, msg):
@@ -247,9 +247,6 @@ def CHECK_SHLIB_W_PYTHON(conf, msg):
     '''check if we need -undefined dynamic_lookup'''
 
     dir = find_config_dir(conf)
-
-    env = conf.env
-
     snip = '''
 #include <Python.h>
 #include <crt_externs.h>
@@ -262,7 +259,7 @@ int foo(int v) {
     ldb_module = PyImport_ImportModule("ldb");
     return v * 2;
 }'''
-    return conf.check(features='c cshlib',uselib='PYEMBED',fragment=snip,msg=msg)
+    return conf.check(features='c cshlib',uselib='PYEMBED',fragment=snip,msg=msg, mandatory=False)
 
 # this one is quite complex, and should probably be broken up
 # into several parts. I'd quite like to create a set of CHECK_COMPOUND()
@@ -290,7 +287,9 @@ def CHECK_LIBRARY_SUPPORT(conf, rpath=False, version_script=False, msg=None):
     os.makedirs(subdir)
 
     Utils.writef(os.path.join(subdir, 'lib1.c'), 'int lib_func(void) { return 42; }\n')
-    Utils.writef(os.path.join(dir, 'main.c'), 'int main(void) {return !(lib_func() == 42);}\n')
+    Utils.writef(os.path.join(dir, 'main.c'),
+                 'int lib_func(void);\n'
+                 'int main(void) {return !(lib_func() == 42);}\n')
 
     bld = Build.BuildContext()
     bld.log = conf.log
@@ -339,7 +338,8 @@ def CHECK_LIBRARY_SUPPORT(conf, rpath=False, version_script=False, msg=None):
 
     # we need to run the program, try to get its result
     args = conf.SAMBA_CROSS_ARGS(msg=msg)
-    proc = Utils.pproc.Popen([lastprog] + args, stdout=Utils.pproc.PIPE, stderr=Utils.pproc.PIPE)
+    proc = Utils.subprocess.Popen([lastprog] + args,
+            stdout=Utils.subprocess.PIPE, stderr=Utils.subprocess.PIPE)
     (out, err) = proc.communicate()
     w = conf.log.write
     w(str(out))
@@ -366,7 +366,7 @@ def CHECK_PERL_MANPAGE(conf, msg=None, section=None):
         else:
             msg = "perl manpage generation"
 
-    conf.check_message_1(msg)
+    conf.start_msg(msg)
 
     dir = find_config_dir(conf)
 
@@ -383,28 +383,28 @@ WriteMakefile(
 """)
     back = os.path.abspath('.')
     os.chdir(bdir)
-    proc = Utils.pproc.Popen(['perl', 'Makefile.PL'],
-                             stdout=Utils.pproc.PIPE,
-                             stderr=Utils.pproc.PIPE)
+    proc = Utils.subprocess.Popen(['perl', 'Makefile.PL'],
+                             stdout=Utils.subprocess.PIPE,
+                             stderr=Utils.subprocess.PIPE)
     (out, err) = proc.communicate()
     os.chdir(back)
 
     ret = (proc.returncode == 0)
     if not ret:
-        conf.check_message_2('not found', color='YELLOW')
+        conf.end_msg('not found', color='YELLOW')
         return
 
     if section:
         man = Utils.readf(os.path.join(bdir,'Makefile'))
         m = re.search('MAN%sEXT\s+=\s+(\w+)' % section, man)
         if not m:
-            conf.check_message_2('not found', color='YELLOW')
+            conf.end_msg('not found', color='YELLOW')
             return
         ext = m.group(1)
-        conf.check_message_2(ext)
+        conf.end_msg(ext)
         return ext
 
-    conf.check_message_2('ok')
+    conf.end_msg('ok')
     return True
 
 
@@ -418,7 +418,7 @@ def CHECK_COMMAND(conf, cmd, msg=None, define=None, on_target=True, boolean=Fals
     if on_target:
         cmd.extend(conf.SAMBA_CROSS_ARGS(msg=msg))
     try:
-        ret = Utils.cmd_output(cmd)
+        ret = Utils.cmd_output(cmd).decode('utf8')
     except:
         conf.COMPOUND_END(False)
         return False
@@ -440,6 +440,7 @@ def CHECK_UNAME(conf):
     ret = True
     for v in "sysname machine release version".split():
         if not conf.CHECK_CODE('''
+                               int printf(const char *format, ...);
                                struct utsname n;
                                if (uname(&n) == -1) return -1;
                                printf("%%s", n.%s);
@@ -487,13 +488,13 @@ def CHECK_XSLTPROC_MANPAGES(conf):
         return False
 
     s='http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
-    conf.CHECK_COMMAND('%s --nonet %s 2> /dev/null' % (conf.env.XSLTPROC, s),
+    conf.CHECK_COMMAND('%s --nonet %s 2> /dev/null' % (conf.env.get_flat('XSLTPROC'), s),
                              msg='Checking for stylesheet %s' % s,
                              define='XSLTPROC_MANPAGES', on_target=False,
                              boolean=True)
     if not conf.CONFIG_SET('XSLTPROC_MANPAGES'):
-        print "A local copy of the docbook.xsl wasn't found on your system" \
-              " consider installing package like docbook-xsl"
+        print("A local copy of the docbook.xsl wasn't found on your system" \
+              " consider installing package like docbook-xsl")
 
 #
 # Determine the standard libpath for the used compiler,
@@ -507,12 +508,12 @@ def CHECK_STANDARD_LIBPATH(conf):
     # at least gcc and clang support this:
     try:
         cmd = conf.env.CC + ['-print-search-dirs']
-        out = Utils.cmd_output(cmd).split('\n')
+        out = Utils.cmd_output(cmd).decode('utf8').split('\n')
     except ValueError:
         # option not supported by compiler - use a standard list of directories
         dirlist = [ '/usr/lib', '/usr/lib64' ]
     except:
-        raise Utils.WafError('Unexpected error running "%s"' % (cmd))
+        raise Errors.WafError('Unexpected error running "%s"' % (cmd))
     else:
         dirlist = []
         for line in out:
@@ -524,53 +525,3 @@ def CHECK_STANDARD_LIBPATH(conf):
 
     conf.env.STANDARD_LIBPATH = dirlist
 
-
-waf_config_c_parse_flags = config_c.parse_flags;
-def samba_config_c_parse_flags(line1, uselib, env):
-    #
-    # We do a special treatment of the rpath components
-    # in the linkflags line, because currently the upstream
-    # parse_flags function is incomplete with respect to
-    # treatment of the rpath. The remainder of the linkflags
-    # line is later passed to the original funcion.
-    #
-    lst1 = shlex.split(line1)
-    lst2 = []
-    while lst1:
-        x = lst1.pop(0)
-
-        #
-        # NOTE on special treatment of -Wl,-R and -Wl,-rpath:
-        #
-        # It is important to not put a library provided RPATH
-        # into the LINKFLAGS but in the RPATH instead, since
-        # the provided LINKFLAGS get prepended to our own internal
-        # RPATH later, and hence can potentially lead to linking
-        # in too old versions of our internal libs.
-        #
-        # We do this filtering here on our own because of some
-        # bugs in the real parse_flags() function.
-        #
-        if x == '-Wl,-rpath' or x == '-Wl,-R':
-            x = lst1.pop(0)
-            if x.startswith('-Wl,'):
-                rpath = x[4:]
-            else:
-                rpath = x
-        elif x.startswith('-Wl,-R,'):
-            rpath = x[7:]
-        elif x.startswith('-Wl,-R'):
-            rpath = x[6:]
-        elif x.startswith('-Wl,-rpath,'):
-            rpath = x[11:]
-        else:
-            lst2.append(x)
-            continue
-
-        env.append_value('RPATH_' + uselib, rpath)
-
-    line2 = ' '.join(lst2)
-    waf_config_c_parse_flags(line2, uselib, env)
-
-    return
-config_c.parse_flags = samba_config_c_parse_flags