From patchwork Mon May 15 09:58:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 18627 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 97220C3284 for ; Mon, 15 May 2023 09:58:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 003A062864; Mon, 15 May 2023 11:58:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1684144699; bh=KYUMbwyFpH59xBndsUDHsL8c52aSCrg6t6LqnfCicyw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=n5EeHjZ2q7I303IWYnT+NAKBSIQ49Ii/JwbTLtskrDk1v6nxaOS+qxLe6yIujj1OK AyAyWzhxM3u6rQmiIiKb+GriOCyJYEcywl7ykks/Ew8b/JY/xU+Qtn/5g0R82jjf0a MZQLpTXjvLBVoHvwDuyN5gSCPNNO2tg29NywXfpcy3O7Vdv+hrREZGri+0O0zLXVNE Yam3ASJN+zMDasUjo+71gpuhAq7nvaJzJMkpDj53GTsHMkUY3tN+vO5zi9Wt5cDSV+ Jjmet//9SICKmGN1g7amfOeXgYPpnXlpmnsxraAh/hgKUXD1P7nMuRqK1QhRzADrLI Vks6tFA1LYpFA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1E9A96039F for ; Mon, 15 May 2023 11:58:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="oHGy/1m2"; dkim-atps=neutral Received: from Monstersaurus.local (aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net [82.37.23.78]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5DD3A4DB; Mon, 15 May 2023 11:58:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1684144686; bh=KYUMbwyFpH59xBndsUDHsL8c52aSCrg6t6LqnfCicyw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oHGy/1m2zvbEHprd43LUsItsCHCQQEM2/z0mywrie9F1M036X588iFf34WEV8/Ef8 2YzpLhdIZ34nGEoT68MX7GO2XaYyTBoMN0rOZuT9kp60JzTCJsbz0K8ZJ8gFM4m5mm Dopl+v5U2md/+A5Y8Bx2G9RYXp3oafHdlq/a5WvI= To: libcamera devel Date: Mon, 15 May 2023 10:58:11 +0100 Message-Id: <20230515095812.3409747-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230515095812.3409747-1-kieran.bingham@ideasonboard.com> References: <20230515095812.3409747-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] utils: ABI Compatibility checker X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Kieran Bingham via libcamera-devel From: Kieran Bingham Reply-To: Kieran Bingham Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Provide support to compare ABI compatibility between any two git commits or by a commit and the most recent ancestral tag of that commit. Signed-off-by: Kieran Bingham --- utils/abi-compat.sh | 198 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100755 utils/abi-compat.sh diff --git a/utils/abi-compat.sh b/utils/abi-compat.sh new file mode 100755 index 000000000000..b1944dc7d594 --- /dev/null +++ b/utils/abi-compat.sh @@ -0,0 +1,198 @@ +#!/bin/bash + +NAME=$(basename "$0") +usage() { +cat << EOF +$NAME: Determine the ABI/API compatibility of two build versions + + $NAME [--help] [--abi-dir=] [--tmp-dir=] ARGS + +The positional arguments (ARGS) determine the versions that will be compared and +take three variants: + + - No positional arguments: + $NAME [optional arguments] + + It is assumed to compare the current git HEAD against the most recent TAG + + - One positional argument: + $NAME [optional aguments] COMMITISH + + The given COMMITISH is compared against it's most recent TAG + + - Two positional arguments: + $NAME [optional aguments] BASE COMMITISH + + The given COMMITISH is compared against the given BASE. + +Optional Arguments: + --abi-dir Use for storing (or retrieving existing) ABI data + files + + --tmp-dir Specify temporary build location for building ABI data. + This could be a tmpfs/RAM disk to save on disk writes. +EOF +} + +POSITIONAL=() +while [[ $# -gt 0 ]] +do +case $1 in + -h|--help) + usage + exit 127; + ;; + + --abi-dir) + ABI_DIR=$2 + shift; shift; + ;; + + --tmp-dir) + TMP=$2 + shift; shift; + ;; + + *) # Parse unidentified arguments based on position + POSITIONAL+=("$1") + shift # past argument + ;; +esac +done +set -- "${POSITIONAL[@]}" # restore positional parameters + +ABI_DIR=${ABI_DIR:-abi} +TMP=${TMP:-"$ABI_DIR/tmp/"} + +mkdir -p "$ABI_DIR" +mkdir -p "$TMP" + +dbg () { + echo "$@" >> /dev/stderr +} + +die () { + echo "$NAME: $*" >> /dev/stderr + exit 128 +} + +prev_release () { + git describe --tags --abbrev=0 "$1"^ \ + || die "Failed to identify previous release tag from $1" +} + +describe () { + git describe --tags "$@" \ + || die "Failed to describe $1" +} + +# Make sure we exit on errors during argument parsing +set -Eeuo pipefail + +# Check HEAD against previous 'release' +if test $# -eq 0; +then + FROM=$(prev_release HEAD) + TO=$(describe HEAD) +fi + +# Check COMMIT against previous release +if test $# -eq 1; +then + FROM=$(prev_release "$1") + TO=$(describe "$1") +fi + +# Check ABI between FROM and TO explicitly +if test $# -eq 2; +then + FROM=$(describe "$1") + TO=$(describe "$2") +fi + +echo "Validating ABI compatibility between $FROM and $TO" + +# Generate an abi-compliance-checker xml description file +# $PREFIX is assumed to be /usr/local/ +create_xml() { + # $1: Output file + # $2: Version + # $3: Install root + + echo "$2" > "$1" + echo "$3/usr/local/include/" >> "$1" + echo "$3/usr/local/lib/" >> "$1" +} + +# Check if an ABI dump file exists, and if not create one +# by building a minimal configuration of libcamera at the specified +# version using a clean worktree. +create_abi_dump() { + VERSION="$1" + ABI_FILE="$ABI_DIR/$VERSION.abi.dump" + WORKTREE="$TMP/$VERSION" + BUILD="$TMP/$VERSION-build" + + # Use a fully qualified path when calling ninja -C + INSTALL=$(realpath "$TMP/$VERSION-install") + + if test ! -e "$ABI_FILE"; + then + dbg "Creating ABI dump for $VERSION in $ABI_DIR" + git worktree add "$WORKTREE" "$VERSION" + + meson setup "$BUILD" "$WORKTREE" \ + -Ddocumentation=disabled \ + -Dcam=disabled \ + -Dqcam=disabled \ + -Dgstreamer=disabled \ + -Dlc-compliance=disabled \ + -Dtracing=disabled \ + -Dpipelines= + + ninja -C "$BUILD" + DESTDIR="$INSTALL" ninja -C "$BUILD" install + + # Create an xml descriptor with parameters to generate the dump file + create_xml \ + "$INSTALL/libcamera-abi-dump.xml" \ + "$VERSION" \ + "$INSTALL" + + + # We currently have warnings produced that we can ignore + # While we have pipefail set, finish with || true + abi-compliance-checker \ + -lib libcamera \ + -v1 "$VERSION" \ + -dump "$INSTALL/libcamera-abi-dump.xml" \ + -dump-path "$ABI_FILE" || true + + dbg Created "$ABI_FILE" + + dbg Removing Worktree "$WORKTREE" + git worktree remove -f "$WORKTREE" + + dbg Removing "$BUILD" + rm -r "$BUILD" + + dbg Removing "$INSTALL" + rm -r "$INSTALL" + fi +} + +# Create the requested ABI dump files if they don't yet exist +create_abi_dump "$FROM" +create_abi_dump "$TO" + +# Todo: Future iterations and extensions here could add "-stdout -xml" and +# parse the results automatically +abi-compliance-checker -l libcamera \ + -old "$ABI_DIR/$FROM.abi.dump" \ + -new "$ABI_DIR/$TO.abi.dump" \ + ; + +# On (far too many) occasions, the tools keep running leaving a cpu core @ 100% +# CPU usage. Perhaps some subprocess gets launched but never rejoined. Stop +# them all +killall abi-compliance-checker 2>/dev/null