Skip to content
pi-c Artifact [b0a0e57b69]
Login

Artifact [b0a0e57b69]

Artifact b0a0e57b696c8e9dcdd3675dc7de2a78f28f1019050097d757ee380eee428a78:


#!/bin/sh
# Re-vendor libfossil and SQLite from a libfossil build output.
#
#   sh tools/vendor-libfossil.sh [CUT_DIR]   (default ~/libfossil-builds/current)
#
# Copies the amalgamations, SQLite's shell.c and the license into
# vendor/libfossil, refuses a cut whose shell.c and sqlite3.c come from
# different SQLite check-ins (the shell would refuse to start), rewrites
# SHA256SUMS and the first line of README.md, and prints what changed.
# It does not commit: run `make test-pic` and Fil-C, then land the branch.
set -eu
cut=${1:-"$HOME/libfossil-builds/current"}
dst=vendor/libfossil
files='sqlite3.c sqlite3.h shell.c libfossil.c libfossil.h libfossil-config.h LICENSE'
fail() { printf 'vendor-libfossil: %s\n' "$*" >&2; exit 1; }

[ -f Makefile ] && [ -d "$dst" ] || fail "run from the pi-c checkout root"
[ -d "$cut" ] || fail "no cut at $cut"
for f in $files CHECKIN; do [ -f "$cut/$f" ] || fail "cut lacks $f"; done
checkin=$(tr -d ' \n' < "$cut/CHECKIN")
case "$checkin" in *[!0-9a-f]*|'') fail "CHECKIN is not a hash: $checkin" ;; esac

# The shell and the library must name the same SQLite check-in.
id_h=$(sed -n 's/^#define SQLITE_SOURCE_ID *"\(.*\)"$/\1/p' "$cut/sqlite3.h")
id_c=$(sed -n 's/^#define SQLITE_SOURCE_ID *"\(.*\)"$/\1/p' "$cut/sqlite3.c" | head -1)
[ -n "$id_h" ] && [ "$id_h" = "$id_c" ] || fail "sqlite3.h and sqlite3.c disagree on SQLITE_SOURCE_ID"
grep -q 'SQLITE_SOURCE_ID' "$cut/shell.c" || fail "shell.c does not check the source id"
hash=${id_h##* }
grep -q "$hash" "$cut/shell.c" 2>/dev/null ||
    printf 'note: shell.c does not embed %s; the build compares ids at run time (test-sqlite3 checks it)\n' "$hash"
version=$(sed -n 's/^#define SQLITE_VERSION *"\(.*\)"$/\1/p' "$cut/sqlite3.h")

old=$(sed -n '1s/.*check-in \([0-9a-f]*\).*/\1/p' "$dst/README.md")
for f in $files; do cp "$cut/$f" "$dst/$f"; done

short=$(printf '%.10s' "$checkin")
tmp=$(mktemp "$dst/README.XXXXXX")
{
    printf 'Amalgamations from libfossil check-in %s (full hash %s), with the SQLite\n' "$short" "$checkin"
    printf '%s (%s) they are built against and its shell.c from the same check-in.\n' "$version" "$hash"
    sed '1,2d' "$dst/README.md"
} > "$tmp"
mv "$tmp" "$dst/README.md"

(cd "$dst" && for f in $files README.md; do shasum -a 256 "$f"; done > SHA256SUMS)
(cd "$dst" && shasum -a 256 -c SHA256SUMS > /dev/null) || fail "SHA256SUMS does not verify"
printf 'vendored libfossil %s (was %s), SQLite %s %s\n' "$short" "${old:-?}" "$version" "$hash"
printf 'next: review README.md lines 3+, make test-pic, Fil-C (tools/remote/run.sh), land\n'