blob: b0da4b05a683f17435983a499963d83d5202d8eb [file] [log] [blame]
#!/usr/bin/env bash
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -euo pipefail
function usage() {
echo "Usage: $0 [LIBRARY_NAME] [CURRENT_IFS] [REFERENCE_IFS] [STAMP] [--warn]"
echo "Verifies the list of public symbols against a golden file."
echo "Additionally, checks that none of the symbols is a C++ symbol."
echo "[LIBRARY_NAME]: a human-readable name for the library"
echo "[CURRENT]: path to the ifs file from this library"
echo "[REFERENCE]: path to the checked in ifs file"
echo "[STAMP]: touch this file when the script succeeds"
echo "[--warn]: (optional) if is specified, only output warnings and do not fail the build"
exit 1
}
readonly LIBRARY_NAME=$1
readonly CURRENT=$2
readonly REFERENCE=$3
readonly STAMP=$4
WARN_ON_CHANGES=0
if [[ ($# -eq 5) && ($5 == "--warn") ]]; then
WARN_ON_CHANGES=1
fi
for file in $CURRENT $REFERENCE
do
if ! [[ -e "$file" ]]; then
echo "Error: $file not found" >&2
usage
fi
done
# Detect presence of C++ symbols
if grep -q "Name: _Z" $REFERENCE; then
echo
echo "Error: Prebuilt libraries exported to the SDK should not have C++ symbols"
echo "In library $LIBRARY_NAME"
echo "NOTE: the following functions are exported with C++ linkage:"
grep "Name: _Z" $REFERENCE
if [[ "$WARN_ON_CHANGES" -eq 0 ]]; then
exit 1
fi
fi
if ! diff $CURRENT $REFERENCE; then
echo
echo "Error: ABI has changed! In library $LIBRARY_NAME"
echo
echo -e "Please acknowledge this change by running:\ncp $CURRENT $REFERENCE\n"
if [[ "$WARN_ON_CHANGES" -eq 0 ]]; then
exit 1
fi
fi
touch ${STAMP}