summaryrefslogtreecommitdiffstats
path: root/doc/abi-check.in
blob: 5a5e253f74f5b6ad493047fc2596b2cfe938ce0e (plain)
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
151
152
153
154
155
156
157
158
#!@BASH_PATH@
#
# Copyright 2011-2022 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# or later (GPLv2+) WITHOUT ANY WARRANTY.
#

#
# abi-check [-u] <package-name> <version> [...]
#
# Build ABI dumps for all listed versions. If exactly two are given,
# build an ABI compatibility report for them, and if -u is given,
# upload it to the website.
#

# Top-level rsync destination for www targets (without trailing slash)
: ${RSYNC_DEST:=root@www.clusterlabs.org:/var/www/html}

# If the argument is of form x.y.z, print Pacemaker-x.y.z,
# otherwise print the argument (presumably a commit ID) directly
tag() {
    if [[ "$1" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} ]]; then
        echo "Pacemaker-$1"
    else
        echo "$1"
    fi
}

# Strip anything up to and including a dash from the argument
version() {
    echo "$1" | sed s:.*-::
}

# Create configuration file for ABI dumper
abi_config() {
    PACKAGE="$1"
    VERSION="$2"
    BUILD_ROOT="$3"
    DESC="$4"

    # Create header
    DESC="$BUILD_ROOT/$VERSION.xml"
    cat <<EOF > "$DESC"
<?xml version="1.0" encoding="utf-8"?>
<descriptor>
<version>
    $VERSION
</version>
<headers>
        $BUILD_ROOT/root/usr/include/$PACKAGE/crm
</headers>
<libs>
EOF

    # Build checkout, installing into subdirectory
    ( cd "$BUILD_ROOT" && ./autogen.sh && ./configure --disable-fatal-warnings )
    make -C "$BUILD_ROOT" V=0 DESTDIR="${BUILD_ROOT}/root" install
    if [ $? -ne 0 ]; then
        echo "Build for $TAG failed. Repair, populate <libs/> and re-run: "
        echo "  abi-compliance-checker -l $PACKAGE -dump_abi $DESC"
        echo ""
        echo "To find libraries after building:"
        echo "  find $BUILD_ROOT/root -name "*.so" -print"
        exit 1
    fi

    # Add library names to configuration file
    find $BUILD_ROOT/root -name "*.so" -print >> $DESC

    # Add footer
    cat <<EOF >> "$DESC"
</libs>
</descriptor>
EOF
}

# Dump the ABI for a particular version
extract_one() {
    TAG="$1"
    VERSION="$2"

    # If dump already exists, remove it if dumping HEAD (which changes),
    # otherwise use it (a dump for a particular commit stays the same).
    TARBALL="abi_dumps/$PACKAGE/${PACKAGE}_$VERSION.abi.tar.gz"
    if [ "$VERSION" = HEAD ]; then
        rm -rf "$TARBALL"
    elif [ -f "$TARBALL" ]; then
        return
    fi

    echo "Building ABI dump for $*"

    # Get a clean checkout at the desired commit
    BUILD_ROOT=".ABI-build"
    rm -rf "$BUILD_ROOT"
    ( cd .. ; git archive --prefix "doc/$BUILD_ROOT/" "$TAG" | tar xv )
    if [ $? -ne 0 ]; then
        exit
    fi

    # Remove "doc" from SUBDIRS in Makefile (but why?)
    BUILD_ROOT="$(pwd)/$BUILD_ROOT"
    sed -i.sed 's: doc::' "$BUILD_ROOT/Makefile.am"

    # Run ABI dump
    abi_config "$PACKAGE" "$VERSION" "$BUILD_ROOT" "$DESC"
    abi-compliance-checker -l "$PACKAGE" -dump_abi "$DESC" \
        -dump-path "abi_dumps/${PACKAGE}/${PACKAGE}_${VERSION}.abi.tar.gz"

    # Clean up
    rm -rf "$BUILD_ROOT"
}

extract_all() {
    for arg in $*; do
        T=$(tag "$arg")
        V=$(version "$T")
        extract_one "$T" "$V"
    done
}

die() {
	echo "$@" 1>&2
	exit 1
}

which git 2>/dev/null || die "abi-check: git must be installed"
git rev-parse --git-dir >/dev/null 2>/dev/null	\
	|| die "abi-check: must be run from git checkout"

UPLOAD=0
if [ "$1" = "-u" ]; then
    UPLOAD=1; shift
fi

PACKAGE="$1"; shift

extract_all "$@"

if [ $# -eq 2 ]; then
    V1=$(version "$1")
    V2=$(version "$2")

    abi-compliance-checker -l ${PACKAGE} \
        -d1 abi_dumps/${PACKAGE}/${PACKAGE}_${V1}.abi.tar.gz \
        -d2 abi_dumps/${PACKAGE}/${PACKAGE}_${V2}.abi.tar.gz
    if [ $? -ne 0 ]; then
        echo "WARNING: compliance checker exited $?"
    fi

    COMPAT_REPORT="compat_reports/${PACKAGE}/${V1}_to_${V2}"
    if [ $UPLOAD -eq 1 ] && [ -d "$COMPAT_REPORT" ]; then
        rsync -azxlSD --progress "$COMPAT_REPORT" "${RSYNC_DEST}/${PACKAGE}/abi/"
    fi
fi