wafsamba: allow SAMBA_LIBRARY() to get and use original 'version-script.map' for...
authorStefan Metzmacher <metze@samba.org>
Wed, 18 Aug 2021 15:34:09 +0000 (17:34 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 30 Nov 2021 15:53:34 +0000 (15:53 +0000)
We'll soon use this for the internal Heimdal build and take the raw
version-script.map files in order to create our own .vscript file
with our private version suffix.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14780

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
buildtools/wafsamba/samba_abi.py
buildtools/wafsamba/wafsamba.py

index 725f6ddd06e5563e8b8060a6d6730c277c4aaaad..80643aa28d7d7a09f2cb32ce2ff1614c566c2e0e 100644 (file)
@@ -157,6 +157,46 @@ def abi_process_file(fname, version, symmap):
         if not symname in symmap:
             symmap[symname] = version
 
+def version_script_map_process_file(fname, version, abi_match):
+    '''process one standard version_script file, adding the symbols to the
+    abi_match'''
+    in_section = False
+    in_global = False
+    in_local = False
+    for _line in Utils.readf(fname).splitlines():
+        line = _line.strip()
+        if line == "":
+            continue
+        if line.startswith("#"):
+            continue
+        if line.endswith(" {"):
+            in_section = True
+            continue
+        if line == "};":
+            assert in_section
+            in_section = False
+            in_global = False
+            in_local = False
+            continue
+        if not in_section:
+            continue
+        if line == "global:":
+            in_global = True
+            in_local = False
+            continue
+        if line == "local:":
+            in_global = False
+            in_local = True
+            continue
+
+        symname = line.split(";")[0]
+        assert symname != ""
+        if in_local:
+            if symname == "*":
+                continue
+            symname = "!%s" % symname
+        if not symname in abi_match:
+            abi_match.append(symname)
 
 def abi_write_vscript(f, libname, current_version, versions, symmap, abi_match):
     """Write a vscript file for a library in --version-script format.
@@ -223,6 +263,9 @@ def abi_build_vscript(task):
             versions.append(version)
             abi_process_file(fname, version, symmap)
             continue
+        if basename == "version-script.map":
+            version_script_map_process_file(fname, task.env.VERSION, abi_match)
+            continue
         raise Errors.WafError('Unsupported input "%s"' % fname)
     if task.env.PRIVATE_LIBRARY:
         # For private libraries we need to inject
@@ -241,6 +284,19 @@ def abi_build_vscript(task):
     finally:
         f.close()
 
+def VSCRIPT_MAP_PRIVATE(bld, libname, orig_vscript, version, private_vscript):
+    version = version.replace("-", "_").replace("+","_").upper()
+    t = bld.SAMBA_GENERATOR(private_vscript,
+                            rule=abi_build_vscript,
+                            source=orig_vscript,
+                            group='vscripts',
+                            target=private_vscript)
+    t.env.ABI_MATCH = []
+    t.env.VERSION = version
+    t.env.LIBNAME = libname
+    t.env.PRIVATE_LIBRARY = True
+    t.vars = ['LIBNAME', 'VERSION', 'ABI_MATCH', 'PRIVATE_LIBRARY']
+Build.BuildContext.VSCRIPT_MAP_PRIVATE = VSCRIPT_MAP_PRIVATE
 
 def ABI_VSCRIPT(bld, libname, abi_directory, version, vscript, abi_match=None, private_library=False):
     '''generate a vscript file for our public libraries'''
index b0fd817410f49ee0431d350f2dc17fe18c451634..185ef3b73a22705fe8963a54bc084a840df91108 100644 (file)
@@ -127,6 +127,7 @@ def SAMBA_LIBRARY(bld, libname, source,
                   link_name=None,
                   abi_directory=None,
                   abi_match=None,
+                  orig_vscript_map=None,
                   hide_symbols=False,
                   manpages=None,
                   private_library=False,
@@ -160,6 +161,17 @@ def SAMBA_LIBRARY(bld, libname, source,
         raise Errors.WafError("private library '%s' must not have public header files" %
                              libname)
 
+    if orig_vscript_map and not private_library:
+        raise Errors.WafError("public library '%s' must not have orig_vscript_map" %
+                             libname)
+
+    if orig_vscript_map and abi_directory:
+        raise Errors.WafError("private library '%s' with orig_vscript_map must not have abi_directory" %
+                             libname)
+    if orig_vscript_map and abi_match:
+        raise Errors.WafError("private library '%s' with orig_vscript_map must not have abi_match" %
+                             libname)
+
     if LIB_MUST_BE_PRIVATE(bld, libname) and target_type not in ['PLUGIN']:
         private_library = True
 
@@ -327,8 +339,11 @@ def SAMBA_LIBRARY(bld, libname, source,
             version = None
         if version:
             vscript = "%s.vscript" % libname
-            bld.ABI_VSCRIPT(version_libname, abi_directory, version, vscript,
-                            abi_match, private_library)
+            if orig_vscript_map:
+                bld.VSCRIPT_MAP_PRIVATE(version_libname, orig_vscript_map, version, vscript)
+            else:
+                bld.ABI_VSCRIPT(version_libname, abi_directory, version, vscript,
+                                abi_match, private_library)
             fullname = apply_pattern(bundled_name, bld.env.cshlib_PATTERN)
             fullpath = bld.path.find_or_declare(fullname)
             vscriptpath = bld.path.find_or_declare(vscript)