[librest] build: add abi-check to check for abi stability



commit 536fba3256d008f0e24fe49be4cd8932a51e04d6
Author: Günther Wagner <info gunibert de>
Date:   Thu Feb 3 08:02:09 2022 +0100

    build: add abi-check to check for abi stability

 .gitlab-ci.yml       |   4 +-
 .gitlab-ci/check-abi | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 116 insertions(+), 1 deletion(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 10ff914..18f53d1 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -6,6 +6,7 @@ variables:
   MANIFEST_PATH: 'examples/demo/org.gnome.RestDemo.json'
   FLATPAK_MODULE: 'librest-demo'
   FLATPAK_BUILD_DIR: build
+  LAST_ABI_BREAK: "85bd00adfa6e06d3426ce7c9007e68e62f51be14"
 
 image: fedora:36
 
@@ -23,11 +24,12 @@ build-librest:
     - dnf -y install --nogpgcheck redhat-rpm-config
       glib2-devel gobject-introspection-devel libxml2-devel meson ninja-build
       libsoup-devel vala json-glib-devel git python3-jinja2 python3-toml python3-typogrify python3-pygments
-      libadwaita-devel gtksourceview5-devel
+      libadwaita-devel gtksourceview5-devel git libabigail
   script:
     - meson _build -Dexamples=true
     - ninja -C _build
     - bash +x ./.gitlab-ci/run-tests.sh
+    - ./.ci/check-abi ${LAST_ABI_BREAK} $(git rev-parse HEAD)
   artifacts:
     reports:
       junit: "_build/${CI_JOB_NAME}-report.xml"
diff --git a/.gitlab-ci/check-abi b/.gitlab-ci/check-abi
new file mode 100755
index 0000000..fc2296d
--- /dev/null
+++ b/.gitlab-ci/check-abi
@@ -0,0 +1,113 @@
+#!/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', '-Dgtk_doc=false', '-Dtests=false', '-Dexamples=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', 'librest-1.0.so')
+
+    new_headers = os.path.join(new_tree, 'usr', 'include')
+    new_lib = os.path.join(new_tree, 'usr', 'lib', 'librest-1.0.so')
+
+    subprocess.check_call([
+        'abidiff', '--headers-dir1', old_headers, '--headers-dir2', new_headers,
+        '--drop-private-types', '--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 as e:
+        print ('ABI comparison failed: '+ str(e))
+        sys.exit(1)
+
+    print(f'Hurray! {args.old} and {args.new} are ABI-compatible!')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]