-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathupdate.sh
executable file
·59 lines (45 loc) · 2.33 KB
/
update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bash
set -eu -o pipefail
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")"
git diff --exit-code -- . ':(exclude)update.sh' > /dev/null || { echo "Commit changes before updating!" ; exit 1 ; }
(( ${HAS_NIMTEROP:-0} )) || nimble install -y [email protected]
# https://www.sqlite.org/download.html
MAJOR="${1:-3}"
MINOR="${2:-49}"
PATCH="${3:-0}"
YEAR="${4:-2025}"
HASH="${5:-138b6922eb274c953c9d8f3249c39706ad3e40f3eef5d81bbeb73509b41f52c9}"
VER_INT="$(printf "%d%02d%02d00" "$MAJOR" "$MINOR" "$PATCH")"
cd sqlite3_abi
ZIP="sqlite-amalgamation-$VER_INT.zip"
[ -f "$ZIP" ] || curl -OL https://www.sqlite.org/$YEAR/$ZIP
HASH_ACTUAL=$(python3 -c "import hashlib; print(hashlib.sha3_256(open('$ZIP', 'rb').read()).hexdigest())")
if [[ "${HASH_ACTUAL}" != "${HASH}" ]]; then
echo "Incorrect ${ZIP} hash: ${HASH}"
false
fi
unzip -jo $ZIP "sqlite-amalgamation-$VER_INT/sqlite3.c" "sqlite-amalgamation-$VER_INT/sqlite3.h"
cd ..
nim c -o:wrap --skipParentCfg --verbosity:0 --hints:off ./sqlite3_abi/wrap.nim
./wrap
sed -i.bak \
-e "s|cdecl|sqlitedecl|g" \
-e "\|Generated @|d" \
-e "s|$PWD/||g" \
-e "s|$HOME|~|g" \
-e "s|--nim:[^ ]*|--nim:nim|g" \
-e 's|{.experimental: "codeReordering".}|{.experimental: "codeReordering".}\nwhen (NimMajor, NimMinor) < (1, 4):\n {.pragma: sqlitedecl, cdecl, gcsafe, raises: [Defect].}\nelse:\n {.pragma: sqlitedecl, cdecl, gcsafe, raises: [].}|' \
-e "s|sqlite3_column_text\\*(a1: ptr sqlite3_stmt; iCol: cint): ptr cuchar|sqlite3_column_text\\*(a1: ptr sqlite3_stmt; iCol: cint): cstring|" \
-e "s|sqlite3_value_text\\*(a1: ptr sqlite3_value): ptr cuchar|sqlite3_value_text\\*(a1: ptr sqlite3_value): cstring|" \
sqlite3_abi/sqlite3_gen.nim
rm -f sqlite3_abi/sqlite3_gen.nim.bak # Portable GNU/macOS `sed` needs backup
sed -i.bak \
-e "s|version.*|version = \"${MAJOR}.${MINOR}.${PATCH}.0\"|g" \
sqlite3_abi.nimble
rm -f sqlite3_abi.nimble.bak # Portable GNU/macOS `sed` needs backup
! git diff --exit-code > /dev/null || { echo "This repository is already up to date" ; exit 0 ; }
git commit -a \
-m "Bump sqlite-amalgamation to \`${MAJOR}.${MINOR}.${PATCH}\`" \
-m "- https://www.sqlite.org/releaselog/${MAJOR}_${MINOR}_${PATCH}.html"
echo "The repo has been updated with a commit recording the update."
echo "You can review the changes with 'git diff HEAD^' before pushing to a public repository."