Skip to content

Commit

Permalink
Update scripts for new release format (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
resilar committed Feb 17, 2019
1 parent aec9656 commit 023447c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion rekeyvacuum.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
** Change 2: Remove local variable 'int nRes'
** Change 3: Remove initialization 'nRes = sqlite3BtreeGetOptimalReserve(pMain)'
**
** This code is generated by script/rekeyvacuum.sh from SQLite version 3.27.1.
** Code generated by script/rekeyvacuum.sh from SQLite v3.27.1 amalgamation.
*/
SQLITE_PRIVATE int sqlite3RekeyVacuum(
char **pzErrMsg, /* Write error message here */
Expand Down
1 change: 1 addition & 0 deletions script/amalgamate.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
# Generate amalgamation by replacing '#include "..."' lines with file contents.
# Usage: ./script/amalgamate.sh <sqleet.c >amalgamation.c
while IFS='' read -r ln; do
if echo "$ln" | grep -q '^#include "[^"]\+"$'; then
Expand Down
14 changes: 8 additions & 6 deletions script/rekeyvacuum.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/sh
# Generate rekeyvacuum.c from SQLite3 amalgamation and print it to stdout.
# Generate rekeyvacuum.c from an SQLite3 amalgamation and write it to stdout.
# Usage: ./script/rekeyvacuum.sh sqlite3.c >rekeyvacuum.c

if [ "$#" -ne 1 ] || ! [ "$1" = "-" -o -f "$1" ]; then
INPUT="$([ "$#" -eq 1 ] && echo "$1" || echo "sqlite3.c")"
if ! [ -f "$INPUT" ]; then
echo "Usage: $0 <SQLITE3_AMALGAMATION>" >&2
echo " e.g.: $0 sqlite3.c" >&2
exit 1
Expand All @@ -12,8 +14,8 @@ die() {
exit 2
}

VERSION="$(sed -n 's/^#define SQLITE_VERSION[^"]*"\([0-9]\+\.[0-9]\+\.[0-9]\+\)"$/\1/p' sqlite3.h)"
[ -z "$VERSION" ] && die "Cannot find SQLite3 version"
VERSION="$(sed -n 's/^#define SQLITE_VERSION[^"]*"\([0-9]\+\.[0-9]\+\.[0-9]\+\)"$/\1/p' "$INPUT")"
[ -z "$VERSION" ] && die "cannot find SQLite3 version (is '$INPUT' a valid amalgamation?)"

cat <<EOF
/*
Expand All @@ -26,10 +28,10 @@ cat <<EOF
** Change 2: Remove local variable 'int nRes'
** Change 3: Remove initialization 'nRes = sqlite3BtreeGetOptimalReserve(pMain)'
**
** This code is generated by script/rekeyvacuum.sh from SQLite version $VERSION.
** Code generated by script/rekeyvacuum.sh from SQLite v$VERSION amalgamation.
*/
EOF
sed -n '/^SQLITE_PRIVATE int sqlite3RunVacuum([^;]*$/,/^}$/p' "$1" \
sed -n '/^SQLITE_PRIVATE int sqlite3RunVacuum([^;]*$/,/^}$/p' "$INPUT" \
| sed 's/sqlite3RunVacuum/sqlite3RekeyVacuum/' \
| sed 's/^\([^ )][^)]*\)\?){$/\1, int nRes){/' \
| grep -v "int nRes;\|nRes = " \
Expand Down
37 changes: 19 additions & 18 deletions script/release.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh
# Prepare sqleet.c sqleet.h amalgamation for a release.
# Prepare release archives.

set -e

die() {
rm -f tmp-rekeyvacuum.c tmp-sqleet.c tmp-sqleet.h
[ ! -z "$RELEASE" ] && rm -rf "$RELEASE_DIR" "$RELEASE.zip" "$RELEASE.tar.gz"
[ "$#" -ne 0 ] && echo "[-] Error:" "$@" >&2
exit 1
}
Expand All @@ -14,32 +14,33 @@ cd "$(git rev-parse --show-toplevel)"
git status --short | grep -vq '^[!?]' && die "dirty working tree (commit or stash your changes)"
VERSION="$(sed -n 's/^#define SQLITE_VERSION[^"]*"\([0-9]\+\.[0-9]\+\.[0-9]\+\)"$/\1/p' sqlite3.h)"
[ -z "$VERSION" ] && die "cannot find SQLite3 version"
SQLEET_VERSION="$(echo "$VERSION" | sed 's/^3/0/')"
RELEASE="sqleet-v$SQLEET_VERSION"
RELEASE_DIR="$RELEASE"

echo "[+] SQLite version $VERSION" >&2

echo "[+] Generating rekeyvacuum.c" >&2
./script/rekeyvacuum.sh sqlite3.c >tmp-rekeyvacuum.c || die "generating rekeyvacuum.c failed"
echo "[+] Checking rekeyvacuum.c" >&2
./script/rekeyvacuum.sh sqlite3.c | cmp -s - rekeyvacuum.c || die "rekeyvacuum.c outdated"

echo "[+] Creating release directory $RELEASE_DIR" >&2
mkdir -p "$RELEASE_DIR"
cp README.md "$RELEASE_DIR"

echo "[+] Generating sqleet.c amalgamation" >&2
./script/amalgamate.sh <sqleet.c >tmp-sqleet.c || die "sqleet.c amalgamation failed"
./script/amalgamate.sh <sqleet.c >"$RELEASE_DIR/sqleet.c" || die "sqleet.c amalgamation failed"

echo "[+] Generating sqleet.h amalgamation" >&2
./script/amalgamate.sh <sqleet.h >tmp-sqleet.h || die "sqleet.h amalgamation failed"
./script/amalgamate.sh <sqleet.h >"$RELEASE_DIR/sqleet.h" || die "sqleet.h amalgamation failed"

echo '[+] Updating shell.c #include "sqlite3.h" -> "sqleet.h"' >&2
sed -i 's/^#include "sqlite3.h"$/#include "sqleet.h"/' shell.c
grep -Fq '#include "sqleet.h"' shell.c || die "failed to update shell.c include"
sed 's/^#include "sqlite3.h"$/#include "sqleet.h"/' shell.c >"$RELEASE_DIR/shell.c"
grep -Fq '#include "sqleet.h"' "$RELEASE_DIR/shell.c" || die "failed to update shell.c include"

echo "[+] Moving files around a bit" >&2
mv tmp-sqleet.h sqleet.h
mv tmp-sqleet.c sqleet.c
mv tmp-rekeyvacuum.c rekeyvacuum.c
git add sqleet.c sqleet.h shell.c
git ls-files | grep ".[ch]$\|^script/" | grep -v "sqleet.[ch]\|shell.c" | xargs git rm -fq
echo "[+] Creating release archives" >&2
zip -qr "$RELEASE-amalgamation.zip" "$RELEASE_DIR" || die "failed to create $RELEASE-amalgamation.zip"
tar -czf "$RELEASE-amalgamation.tar.gz" --owner=0 --group=0 "$RELEASE_DIR" || die "failed to create $RELEASE-amalgamation.tar.gz"

sync
SQLEET_VERSION="$(echo "$VERSION" | sed 's/^3/0/')"
echo "[+] Success!" >&2
echo "git checkout -b v$SQLEET_VERSION"
echo "git commit -m \"Release v$SQLEET_VERSION\""
echo "git push -u origin v$SQLEET_VERSION"
echo "git tag v$SQLEET_VERSION && git push origin v$SQLEET_VERSION"

0 comments on commit 023447c

Please sign in to comment.