| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #!/usr/bin/env bash
- #
- # update.sh - keep libsmartbotic-db-client.symbols in step with a built library.
- #
- # The symbols file records, for every symbol the library exports, the first
- # version that shipped it. dpkg-shlibdeps reads it (from the library package,
- # where create-debs.sh installs it) to give each dependent package - our CLI
- # included - the LOWEST library version that has every symbol it uses, instead
- # of pinning it to its own version.
- #
- # - a symbol the library now exports and the file lacks is ADDED at the
- # current VERSION (run this after bumping VERSION, before releasing);
- # - a PUBLIC symbol (smartbotic::database::..., not ::Impl) that disappeared
- # is an ABI break under soname 2: this script refuses (exit 2);
- # - an (optional) symbol that disappeared (internals, template instances,
- # generated protobuf code) is dropped.
- #
- # usage: update.sh <libsmartbotic-db-client.so.X.Y.Z> [--check]
- # --check change nothing; exit 1 if the file is out of date (the release
- # gate in packaging/build.sh --sync runs this).
- set -euo pipefail
- HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
- ROOT="$(cd "$HERE/../../.." && pwd)"
- SO="${1:?usage: update.sh <library .so> [--check]}"
- MODE="${2:-write}"
- FILE="$HERE/libsmartbotic-db-client.symbols"
- VERSION="$(cat "$ROOT/VERSION")"
- WORK="$(mktemp -d)"
- trap 'rm -rf "$WORK"' EXIT
- nm -D --defined-only "$SO" | awk '{print $NF}' | sort -u > "$WORK/names"
- c++filt < "$WORK/names" > "$WORK/dem"
- paste -d '\t' "$WORK/names" "$WORK/dem" > "$WORK/current"
- # Committed entries: "<name>\t<tag>\t<version>" (tag is "(optional)" or "").
- tail -n +2 "$FILE" | sed -E 's/^ (\(optional\))?([^@]+)@Base (.+)$/\2\t\1\t\3/' > "$WORK/committed"
- awk -F '\t' -v ver="$VERSION" -v out="$WORK/new" -v lost="$WORK/lost" '
- NR == FNR { tag[$1] = $2; v[$1] = $3; next }
- {
- seen[$1] = 1
- if ($1 in v) { printf " %s%s@Base %s\n", tag[$1], $1, v[$1] > out; next }
- pub = index($2, "smartbotic::database::") > 0 && index($2, "::Impl") == 0 && index($2, "(anonymous namespace)") == 0
- printf " %s%s@Base %s\n", (pub ? "" : "(optional)"), $1, ver > out
- printf "added %s %s\n", ver, $2
- }
- END {
- for (s in v) if (!(s in seen)) printf "%s\t%s\n", s, tag[s] > lost
- }' "$WORK/committed" "$WORK/current" > "$WORK/added"
- touch "$WORK/lost"
- broke=0
- while IFS=$'\t' read -r name tag; do
- [ -n "$name" ] || continue
- if [ -z "$tag" ]; then
- echo "ABI BREAK: public symbol removed: $(echo "$name" | c++filt)" >&2
- broke=1
- fi
- done < "$WORK/lost"
- [ "$broke" = 0 ] || { echo "refusing: a public symbol may not disappear under soname 2" >&2; exit 2; }
- { head -1 "$FILE"; sort "$WORK/new"; } > "$WORK/file"
- dropped=$(grep -c . "$WORK/lost" || true)
- added=$(grep -c . "$WORK/added" || true)
- if cmp -s <(head -1 "$FILE"; tail -n +2 "$FILE" | sort) "$WORK/file"; then
- echo "symbols file up to date ($(($(wc -l < "$FILE") - 1)) symbols)"
- exit 0
- fi
- if [ "$MODE" = "--check" ]; then
- echo "symbols file OUT OF DATE: $added to add at $VERSION, $dropped internal symbol(s) to drop" >&2
- grep -v "(optional)" <(sed 's/^added //' "$WORK/added") | head -20 >&2 || true
- echo "run: packaging/deb/symbols/update.sh $SO and commit the file" >&2
- exit 1
- fi
- cp "$WORK/file" "$FILE"
- echo "updated $FILE: $added added at $VERSION, $dropped internal symbol(s) dropped"
- cat "$WORK/added" | grep -v "^added $VERSION _Z" | head -20 || true
|