#!/usr/bin/env bash # # bootstrap.sh - derive the initial libsmartbotic-db-client symbols file from # the RELEASED libraries, so every exported symbol carries the first version # that shipped it. # # Run once (it was run to create libsmartbotic-db-client.symbols); afterwards # the build maintains that file (see packaging/deb/create-debs.sh). Kept so the # floors can be re-derived and audited. # # Baseline 2.8.0: soname 2 exists since 2.0.0, but 2.1.0, 2.4.5 and 2.6.0 # changed public struct layouts under it. From 2.7.0 on every public struct is # byte-identical (the v2.7.1 crash rule), so 2.8.0 - the oldest released # library under that rule - is the lowest floor any symbol may have. A symbol # first seen in an earlier release is given 2.8.0. # # Symbols outside the public API (internals, the Client::Impl members, template # instantiations, generated protobuf classes) are marked (optional): they may # appear and disappear between builds without breaking anyone, so their loss # must not fail the build. Their floors still count when a binary uses them. # # usage: packaging/deb/symbols/bootstrap.sh set -euo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT="$(cd "$HERE/../../.." && pwd)" CURRENT="${1:?usage: bootstrap.sh }" DEB_REPO_DIR="${DEB_REPO_DIR:-$(dirname "$ROOT")/smartbotics-deb-repo}" POOL="$DEB_REPO_DIR/repo/pool/trixie/main" BASELINE="2.8.0" OUT="$HERE/libsmartbotic-db-client.symbols" WORK="$(mktemp -d)" trap 'rm -rf "$WORK"' EXIT exports() { nm -D --defined-only "$1" | awk '{print $NF}' | sort -u; } # First released version that exported each symbol (upstream versions >= baseline). # One "symbol version" line per release, oldest release first; awk keeps the # first version seen for each symbol. : > "$WORK/all" seen="" for deb in $(ls "$POOL"/libsmartbotic-db-client_*_amd64.deb | sort -V); do v="$(basename "$deb" | sed -E 's/^libsmartbotic-db-client_([0-9.]+)-[0-9]+_amd64\.deb$/\1/')" [ "$(printf '%s\n%s\n' "$BASELINE" "$v" | sort -V | head -1)" = "$BASELINE" ] || continue case " $seen " in *" $v "*) continue ;; esac # 2.8.0-1 and -2: the first wins seen="$seen $v" d="$WORK/x-$v"; mkdir -p "$d" (cd "$d" && ar x "$deb" data.tar.xz && tar -xJf data.tar.xz) so="$(find "$d" -name 'libsmartbotic-db-client.so.*.*' -type f | head -1)" exports "$so" | sed "s/\$/ $v/" >> "$WORK/all" rm -rf "$d" done awk '!($1 in f) {f[$1] = $2} END {for (s in f) print s, f[s]}' "$WORK/all" > "$WORK/first" CUR_VERSION="$(cat "$ROOT/VERSION")" exports "$CURRENT" > "$WORK/current" c++filt < "$WORK/current" > "$WORK/current.dem" { echo "libsmartbotic-db-client.so.2 libsmartbotic-db-client #MINVER#" paste -d '\t' "$WORK/current" "$WORK/current.dem" | awk -F '\t' -v cur="$CUR_VERSION" ' NR == FNR { f[$1] = $2; next } { v = ($1 in f) ? f[$1] : cur pub = index($2, "smartbotic::database::") > 0 && index($2, "::Impl") == 0 && index($2, "(anonymous namespace)") == 0 printf " %s%s@Base %s\n", (pub ? "" : "(optional)"), $1, v }' <(tr ' ' '\t' < "$WORK/first") - } > "$OUT" echo "wrote $OUT: $(($(wc -l < "$OUT") - 1)) symbols, $(grep -c '(optional)' "$OUT") optional"