samba_abi.py: avoid inefficient string concatenations
[samba.git] / buildtools / wafsamba / symbols.py
index 7ff4bac7c4905547275649d9897949dd02625463..3eca3d46bd71cf0780b3c8e36a26b96bd3aa3b83 100644 (file)
@@ -2,8 +2,8 @@
 # using nm, producing a set of exposed defined/undefined symbols
 
 import os, re, subprocess
-import Utils, Build, Options, Logs
-from Logs import debug
+from waflib import Utils, Build, Options, Logs, Errors
+from waflib.Logs import debug
 from samba_utils import TO_LIST, LOCAL_CACHE, get_tgt_list, os_path_relpath
 
 # these are the data structures used in symbols.py:
@@ -59,12 +59,12 @@ def symbols_extract(bld, objfiles, dynamic=False):
 
     for line in nmpipe:
         line = line.strip()
-        if line.endswith(':'):
+        if line.endswith(b':'):
             filename = line[:-1]
             ret[filename] = { "PUBLIC": set(), "UNDEFINED" : set() }
             continue
-        cols = line.split(" ")
-        if cols == ['']:
+        cols = line.split(b" ")
+        if cols == [b'']:
             continue
         # see if the line starts with an address
         if len(cols) == 3:
@@ -73,10 +73,10 @@ def symbols_extract(bld, objfiles, dynamic=False):
         else:
             symbol_type = cols[0]
             symbol = cols[1]
-        if symbol_type in "BDGTRVWSi":
+        if symbol_type in b"BDGTRVWSi":
             # its a public symbol
             ret[filename]["PUBLIC"].add(symbol)
-        elif symbol_type in "U":
+        elif symbol_type in b"U":
             ret[filename]["UNDEFINED"].add(symbol)
 
     # add to the cache
@@ -106,10 +106,10 @@ def find_ldd_path(bld, libname, binary):
     lddpipe = subprocess.Popen(['ldd', binary], stdout=subprocess.PIPE).stdout
     for line in lddpipe:
         line = line.strip()
-        cols = line.split(" ")
-        if len(cols) < 3 or cols[1] != "=>":
+        cols = line.split(b" ")
+        if len(cols) < 3 or cols[1] != b"=>":
             continue
-        if cols[0].startswith("libc."):
+        if cols[0].startswith(b"libc."):
             # save this one too
             bld.env.libc_path = cols[2]
         if cols[0].startswith(libname):
@@ -119,8 +119,9 @@ def find_ldd_path(bld, libname, binary):
 
 
 # some regular expressions for parsing readelf output
-re_sharedlib = re.compile('Shared library: \[(.*)\]')
-re_rpath     = re.compile('Library rpath: \[(.*)\]')
+re_sharedlib = re.compile(b'Shared library: \[(.*)\]')
+# output from readelf could be `Library rpath` or `Libray runpath`
+re_rpath     = re.compile(b'Library (rpath|runpath): \[(.*)\]')
 
 def get_libs(bld, binname):
     '''find the list of linked libraries for any binary or library
@@ -146,7 +147,8 @@ def get_libs(bld, binname):
             libs.add(m.group(1))
         m = re_rpath.search(line)
         if m:
-            rpath.extend(m.group(1).split(":"))
+            # output from Popen is always bytestr even in py3
+            rpath.extend(m.group(2).split(b":"))
 
     ret = set()
     for lib in libs:
@@ -410,7 +412,7 @@ def check_library_deps(bld, t):
             if dep2 == name and t.in_library != t2.in_library:
                 Logs.warn("WARNING: mutual dependency %s <=> %s" % (name, real_name(t2.sname)))
                 Logs.warn("Libraries should match. %s != %s" % (t.in_library, t2.in_library))
-                # raise Utils.WafError("illegal mutual dependency")
+                # raise Errors.WafError("illegal mutual dependency")
 
 
 def check_syslib_collisions(bld, tgt_list):
@@ -430,7 +432,7 @@ def check_syslib_collisions(bld, tgt_list):
                 Logs.error("ERROR: Target '%s' has symbols '%s' which is also in syslib '%s'" % (t.sname, common, lib))
                 has_error = True
     if has_error:
-        raise Utils.WafError("symbols in common with system libraries")
+        raise Errors.WafError("symbols in common with system libraries")
 
 
 def check_dependencies(bld, t):
@@ -546,7 +548,7 @@ def symbols_whyneeded(task):
 
     why = Options.options.WHYNEEDED.split(":")
     if len(why) != 2:
-        raise Utils.WafError("usage: WHYNEEDED=TARGET:DEPENDENCY")
+        raise Errors.WafError("usage: WHYNEEDED=TARGET:DEPENDENCY")
     target = why[0]
     subsystem = why[1]
 
@@ -579,7 +581,7 @@ def report_duplicate(bld, binname, sym, libs, fail_on_error):
         else:
             libnames.append(lib)
     if fail_on_error:
-        raise Utils.WafError("%s: Symbol %s linked in multiple libraries %s" % (binname, sym, libnames))
+        raise Errors.WafError("%s: Symbol %s linked in multiple libraries %s" % (binname, sym, libnames))
     else:
         print("%s: Symbol %s linked in multiple libraries %s" % (binname, sym, libnames))