From f309f586c9e224eadb0fd3f061cae661ffb752d1 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 5 Aug 2019 19:18:43 +0200 Subject: [PATCH] ci: Add ABI check Last ABI break was when we fixed the return value for fp_get_pollfds() in commit 056ea54. --- .ci/check-abi | 113 +++++++++++++++++++++++++++++++++++++++++++++++++ .gitlab-ci.yml | 7 +++ 2 files changed, 120 insertions(+) create mode 100755 .ci/check-abi diff --git a/.ci/check-abi b/.ci/check-abi new file mode 100755 index 0000000..06eb1ac --- /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', + '-Dx11-examples=false', '-Ddoc=false', '-Dgtk-examples=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', 'libfprint.so') + + new_headers = os.path.join(new_tree, 'usr', 'include') + new_lib = os.path.join(new_tree, 'usr', 'lib', 'libfprint.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 838c33c..82846fb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,6 +7,7 @@ variables: DEPENDENCIES: libusb1-devel glib2-devel nss-devel pixman-devel systemd meson gtk-doc gcc gcc-c++ glibc-devel libX11-devel libXv-devel gtk3-devel flatpak-builder BUNDLE: "org.freedesktop.libfprint.Demo.flatpak" + LAST_ABI_BREAK: "056ea541ddc97f5806cffbd99a12dc87e4da3546" .build_one_driver_template: &build_one_driver script: @@ -24,10 +25,16 @@ variables: - ninja -C _build - ninja -C _build install +.build_template: &check_abi + script: + - dnf update -y --nogpgcheck && dnf install -y --nogpgcheck $DEPENDENCIES doxygen libabigail git + - ./.ci/check-abi ${LAST_ABI_BREAK} $(git rev-parse HEAD) + build: stage: build <<: *build_one_driver <<: *build + <<: *check_abi .flatpak_script_template: &flatpak_script script: