[geocode-glib/wip/hadess/fixes: 4/4] ci: Add ABI checking



commit 21848bb03e64d50af2e7affba4bb732a6467f59b
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Nov 6 13:22:47 2019 +0100

    ci: Add ABI checking

 .ci/check-abi  | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 .gitlab-ci.yml |  13 ++++++-
 2 files changed, 124 insertions(+), 2 deletions(-)
---
diff --git a/.ci/check-abi b/.ci/check-abi
new file mode 100755
index 0000000..6a0db45
--- /dev/null
+++ b/.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', '-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', 'libgweather-3.so')
+
+    new_headers = os.path.join(new_tree, 'usr', 'include')
+    new_lib = os.path.join(new_tree, 'usr', 'lib', 'libgweather-3.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:
+        sys.exit(1)
+
+    print(f'Hurray! {args.old} and {args.new} are ABI-compatible!')
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index b491643..73c3ac5 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,8 +1,17 @@
+variables:
+    LAST_ABI_BREAK: 3c74d75703b62aa0d0086f877cd85026d7232ae6
+
 build-fedora:
   image: fedora:latest
   before_script:
-    - dnf install -y redhat-rpm-config meson json-glib-devel gettext itstool gobject-introspection-devel 
libsoup-devel gtk-doc
+    # Undo delangification present in the Fedora Docker images
+    - rm -f /etc/rpm/macros.image-language-conf
+    - dnf reinstall -y glib2 glibc
+    # Add French locale support for tests
+    - dnf install -y glibc-langpack-fr glibc-langpack-cs glibc-langpack-en
+    - dnf install -y glib2-devel json-glib-devel libsoup-devel gtk-doc meson git gcc glibc-devel
   script:
     - meson _build
-    - ninja -C _build test
     - ninja -C _build install
+    - ninja -C _build test
+    - ./.ci/check-abi ${LAST_ABI_BREAK} $(git rev-parse HEAD)


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