update.sh 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env bash
  2. #
  3. # update.sh - keep libsmartbotic-db-client.symbols in step with a built library.
  4. #
  5. # The symbols file records, for every symbol the library exports, the first
  6. # version that shipped it. dpkg-shlibdeps reads it (from the library package,
  7. # where create-debs.sh installs it) to give each dependent package - our CLI
  8. # included - the LOWEST library version that has every symbol it uses, instead
  9. # of pinning it to its own version.
  10. #
  11. # - a symbol the library now exports and the file lacks is ADDED at the
  12. # current VERSION (run this after bumping VERSION, before releasing);
  13. # - a PUBLIC symbol (smartbotic::database::..., not ::Impl) that disappeared
  14. # is an ABI break under soname 2: this script refuses (exit 2);
  15. # - an (optional) symbol that disappeared (internals, template instances,
  16. # generated protobuf code) is dropped.
  17. #
  18. # usage: update.sh <libsmartbotic-db-client.so.X.Y.Z> [--check]
  19. # --check change nothing; exit 1 if the file is out of date (the release
  20. # gate in packaging/build.sh --sync runs this).
  21. set -euo pipefail
  22. HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  23. ROOT="$(cd "$HERE/../../.." && pwd)"
  24. SO="${1:?usage: update.sh <library .so> [--check]}"
  25. MODE="${2:-write}"
  26. FILE="$HERE/libsmartbotic-db-client.symbols"
  27. VERSION="$(cat "$ROOT/VERSION")"
  28. WORK="$(mktemp -d)"
  29. trap 'rm -rf "$WORK"' EXIT
  30. nm -D --defined-only "$SO" | awk '{print $NF}' | sort -u > "$WORK/names"
  31. c++filt < "$WORK/names" > "$WORK/dem"
  32. paste -d '\t' "$WORK/names" "$WORK/dem" > "$WORK/current"
  33. # Committed entries: "<name>\t<tag>\t<version>" (tag is "(optional)" or "").
  34. tail -n +2 "$FILE" | sed -E 's/^ (\(optional\))?([^@]+)@Base (.+)$/\2\t\1\t\3/' > "$WORK/committed"
  35. awk -F '\t' -v ver="$VERSION" -v out="$WORK/new" -v lost="$WORK/lost" '
  36. NR == FNR { tag[$1] = $2; v[$1] = $3; next }
  37. {
  38. seen[$1] = 1
  39. if ($1 in v) { printf " %s%s@Base %s\n", tag[$1], $1, v[$1] > out; next }
  40. pub = index($2, "smartbotic::database::") > 0 && index($2, "::Impl") == 0 && index($2, "(anonymous namespace)") == 0
  41. printf " %s%s@Base %s\n", (pub ? "" : "(optional)"), $1, ver > out
  42. printf "added %s %s\n", ver, $2
  43. }
  44. END {
  45. for (s in v) if (!(s in seen)) printf "%s\t%s\n", s, tag[s] > lost
  46. }' "$WORK/committed" "$WORK/current" > "$WORK/added"
  47. touch "$WORK/lost"
  48. broke=0
  49. while IFS=$'\t' read -r name tag; do
  50. [ -n "$name" ] || continue
  51. if [ -z "$tag" ]; then
  52. echo "ABI BREAK: public symbol removed: $(echo "$name" | c++filt)" >&2
  53. broke=1
  54. fi
  55. done < "$WORK/lost"
  56. [ "$broke" = 0 ] || { echo "refusing: a public symbol may not disappear under soname 2" >&2; exit 2; }
  57. { head -1 "$FILE"; sort "$WORK/new"; } > "$WORK/file"
  58. dropped=$(grep -c . "$WORK/lost" || true)
  59. added=$(grep -c . "$WORK/added" || true)
  60. if cmp -s <(head -1 "$FILE"; tail -n +2 "$FILE" | sort) "$WORK/file"; then
  61. echo "symbols file up to date ($(($(wc -l < "$FILE") - 1)) symbols)"
  62. exit 0
  63. fi
  64. if [ "$MODE" = "--check" ]; then
  65. echo "symbols file OUT OF DATE: $added to add at $VERSION, $dropped internal symbol(s) to drop" >&2
  66. grep -v "(optional)" <(sed 's/^added //' "$WORK/added") | head -20 >&2 || true
  67. echo "run: packaging/deb/symbols/update.sh $SO and commit the file" >&2
  68. exit 1
  69. fi
  70. cp "$WORK/file" "$FILE"
  71. echo "updated $FILE: $added added at $VERSION, $dropped internal symbol(s) dropped"
  72. cat "$WORK/added" | grep -v "^added $VERSION _Z" | head -20 || true