1#!/bin/bash
2
3# Script originally based on GTK+'s own abicheck.sh; it should be run anytime
4# there is a change in the stable branch of wxWidgets which could lead to an
5# ABI breakage and thus result in a binary-incompatible change (see tech docs).
6#
7
8
9expected_abi_file="expected_abi"
10actual_abi_file="actual_abi"
11
12if [[ "$(uname)" == "Darwin" ]]; then
13   file_mask=*.dylib
14   nm_options="-g -U"
15else
16   file_mask=*.so
17   nm_options="-D -g --defined-only"
18fi
19
20if [[ "$1" == "--generate" ]]; then
21
22    # IMPORTANT: we need a shared build of wxWidgets to proceed
23    if [[ $(echo $file_mask) == "$file_mask" ]]; then
24        echo "No shared objects ($file_mask) were found... aborting"
25        exit 1
26    fi
27
28    # generated the "expected ABI" for later comparison
29    rm -f $expected_abi_file
30    for library in $file_mask; do
31        # NOTE: don't use -C option as otherwise cut won't work correctly
32        nm $nm_options $library | cut -d ' ' -f 2,3 | sort >>$expected_abi_file
33    done
34
35    echo "Expected wxWidgets ABI generated in \"$expected_abi_file\"..."
36
37elif [[ -z "$1" ]]; then
38
39    if [[ ! -f "$expected_abi_file" ]]; then
40        echo "The file containing the expected wxWidgets ABI '$expected_abi_file' does not exist!"
41        echo "Please generate it first using the '--generate' option"
42        exit 1
43    fi
44
45    echo "Comparing actual ABI with the expected ABI (loading it from \"$expected_abi_file\")..."
46
47    # IMPORTANT: we need a shared build of wxWidgets to do the check
48    if [[ $(echo $file_mask) == "*$file_mask" ]]; then
49        echo "No shared objects ($file_mask) were found... aborting"
50        exit 1
51    fi
52
53    rm -f $actual_abi_file
54    for library in $file_mask; do
55        # NOTE: don't use -C option as otherwise cut won't work correctly
56        nm $nm_options $library | cut -d ' ' -f 2,3 | sort >>$actual_abi_file
57    done
58
59    result=`diff -u $expected_abi_file $actual_abi_file`
60
61    if [[ -z "$result" ]]; then
62        echo "No binary (in)compatible changes were found."
63    else
64        echo "========================================================="
65        echo "WARNING: Possible binary-incompatible changes were found:"
66        echo "========================================================="
67        echo
68        echo "$result"
69
70        # this doesn't necessarly indicate that binary compatibility was surely
71        # broken; e.g. adding non-virtual methods will generate a new line in the
72        # $actual_abi_file but that's a compatible change.
73    fi
74
75else
76
77    echo "Usage: $0 [--generate]"
78    echo "When running without options, compares the wxWidgets ABI saved in '$expected_abi_file'"
79    echo "with the current ABI of the .so files of the working directory."
80    echo "When --generate is given, saves in '$expected_abi_file' the ABI of the .so files"
81    echo "(for later comparisons)."
82
83fi
84
85