File: check-abi

package info (click to toggle)
libxmlb 0.3.24-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,052 kB
  • sloc: ansic: 12,692; python: 569; xml: 83; sh: 81; makefile: 2
file content (150 lines) | stat: -rwxr-xr-x 3,588 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/python3


import argparse
import contextlib
import os
import shutil
import subprocess
import sys


def format_title(title):
    box = {
        "tl": "╔",
        "tr": "╗",
        "bl": "╚",
        "br": "╝",
        "h": "═",
        "v": "║",
    }
    hline = box["h"] * (len(title) + 2)

    return "\n".join(
        [
            f"{box['tl']}{hline}{box['tr']}",
            f"{box['v']} {title} {box['v']}",
            f"{box['bl']}{hline}{box['br']}",
        ]
    )


def rm_rf(path):
    try:
        shutil.rmtree(path)
    except FileNotFoundError:
        pass


def sanitize_path(name):
    return name.replace("/", "-")


def get_current_revision():
    revision = subprocess.check_output(
        ["git", "rev-parse", "--abbrev-ref", "HEAD"], encoding="utf-8"
    ).strip()

    if revision == "HEAD":
        # This is a detached HEAD, get the commit hash
        revision = (
            subprocess.check_output(["git", "rev-parse", "HEAD"])
            .strip()
            .decode("utf-8")
        )

    return revision


@contextlib.contextmanager
def checkout_git_revision(revision):
    current_revision = get_current_revision()
    subprocess.check_call(["git", "checkout", "-q", revision])

    try:
        yield
    finally:
        subprocess.check_call(["git", "checkout", "-q", current_revision])


def build_install(revision):
    build_dir = "_build"
    dest_dir = os.path.abspath(sanitize_path(revision))
    print(
        format_title(f"# Building and installing {revision} in {dest_dir}"),
        end="\n\n",
        flush=True,
    )

    with checkout_git_revision(revision):
        rm_rf(build_dir)
        rm_rf(revision)

        subprocess.check_call(
            [
                "meson",
                build_dir,
                "--prefix=/usr",
                "--libdir=lib",
                "-Db_coverage=false",
                "-Dgtkdoc=false",
                "-Dtests=false",
            ]
        )
        subprocess.check_call(["ninja", "-v", "-C", build_dir])
        subprocess.check_call(
            ["ninja", "-v", "-C", build_dir, "install"], env={"DESTDIR": dest_dir}
        )

    return dest_dir


def compare(old_tree, new_tree):
    print(format_title(f"# Comparing the two ABIs"), end="\n\n", flush=True)

    old_headers = os.path.join(old_tree, "usr", "include")
    old_lib = os.path.join(old_tree, "usr", "lib", "libxmlb.so")

    new_headers = os.path.join(new_tree, "usr", "include")
    new_lib = os.path.join(new_tree, "usr", "lib", "libxmlb.so")

    subprocess.check_call(
        [
            "abidiff",
            "--headers-dir1",
            old_headers,
            "--headers-dir2",
            new_headers,
            "--drop-private-types",
            "--suppressions",
            "contrib/ci/abidiff.suppr",
            "--fail-no-debug-info",
            "--no-added-syms",
            old_lib,
            new_lib,
        ]
    )


if __name__ == "__main__":
    parser = argparse.ArgumentParser()

    parser.add_argument("old", help="the previous revision, considered the reference")
    parser.add_argument("new", help="the new revision, to compare to the reference")

    args = parser.parse_args()

    if args.old == args.new:
        print("Let's not waste time comparing something to itself")
        sys.exit(0)

    old_tree = build_install(args.old)
    new_tree = build_install(args.new)

    try:
        compare(old_tree, new_tree)

    except Exception:
        sys.exit(1)

    print(f"Hurray! {args.old} and {args.new} are ABI-compatible!")