bootstrap.sh 3.2 KB

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