Edit

kc3-lang/libxkbcommon/test/symbols-leak-test.py

Branch :

  • Show log

    Commit

  • Author : Ran Benita
    Date : 2025-01-25 03:18:01
    Hash : 113ac304
    Message : meson: link tests and benches against shared library, not static library This makes the tests, and especially benches, more realistic, since xkbcommon is almost always used as a shared library. Also significantly reduces the build time with LTO enabled (for me, from 90s to 30s). Signed-off-by: Ran Benita <ran@unusedvar.com>

  • test/symbols-leak-test.py
  • #!/usr/bin/env python3
    """Check that all exported symbols are specified in the symbol version scripts.
    
    If this fails, please update the appropriate .map file (adding new version
    nodes as needed).
    """
    
    import os
    import pathlib
    import re
    import sys
    
    
    top_srcdir = pathlib.Path(os.environ["top_srcdir"])
    
    
    def symbols_from_map(path):
        return re.findall(r"^\s+(xkb_.*);", path.read_text("utf-8"), re.MULTILINE)
    
    
    def symbols_from_src(path):
        return re.findall(r"\bXKB_EXPORT\b.*\n(xkb_.*)\(", path.read_text("utf-8"))
    
    
    def diff(map_path, src_paths):
        map_symbols = set(symbols_from_map(map_path))
        src_symbols = set.union(set(), *(symbols_from_src(path) for path in src_paths))
        return sorted(map_symbols - src_symbols), sorted(src_symbols - map_symbols)
    
    
    exit = 0
    
    # xkbcommon symbols
    left, right = diff(
        top_srcdir / "xkbcommon.map",
        [
            top_srcdir / "include/xkbcommon/xkbcommon.h",
            top_srcdir / "include/xkbcommon/xkbcommon-compose.h",
        ],
    )
    if left:
        print("xkbcommon map has extra symbols:", " ".join(left))
        exit = 1
    if right:
        print("xkbcommon src has extra symbols:", " ".join(right))
        exit = 1
    
    # xkbcommon-x11 symbols
    left, right = diff(
        top_srcdir / "xkbcommon-x11.map",
        [
            top_srcdir / "include/xkbcommon/xkbcommon-x11.h",
        ],
    )
    if left:
        print("xkbcommon-x11 map has extra symbols:", " ".join(left))
        exit = 1
    if right:
        print("xkbcommon-x11 src has extra symbols:", " ".join(right))
        exit = 1
    
    sys.exit(exit)