Skip to content

Commit b94ef9e

Browse files
committed
Add setup_sqlcipher.sh
1 parent 4eb9d27 commit b94ef9e

File tree

3 files changed

+192
-20
lines changed

3 files changed

+192
-20
lines changed

.github/README.md

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# GRBD + SQLCipher
1+
# GRDB + SQLCipher
22

33
## What is this?
4-
This is a fork of [GRBD](https://github.com/groue/GRDB.swift) which contains a [SQLCipher Community Edition](https://www.zetetic.net/sqlcipher/open-source/) amalgamation packaged so that it can be consumed as a Swift Package.
4+
This is a fork of [GRDB](https://github.com/groue/GRDB.swift) which contains a [SQLCipher Community Edition](https://www.zetetic.net/sqlcipher/open-source/) amalgamation packaged so that it can be consumed as a Swift Package.
55

66
The default branch for this repository is `SQLCipher` so that we can more easily pull upstream changes if we need to.
77

@@ -27,33 +27,39 @@ Check out upstream's master branch locally:
2727

2828
* `git fetch upstream +master:upstream-master && git checkout upstream-master`
2929

30-
Branch off upstream's branch:
30+
Update upstream's master branch if needed:
3131

32-
* `git checkout -b relase/x.y.z-grdb-a.b.c-sqlcipher-i.j.k`
32+
* `git pull upstream master`
3333

34-
where `x.y.z` is the new version, `a.b.c` is the upstream GRDB version and `i.j.k` is the SQLCipher version.
34+
Resolve any conflicts that may occur (normally there should be none or only in Package.swift)
35+
and commit the merge. Once done, run `setup_sqlcipher.sh` script to fetch and compile the latest tag
36+
of SQLCipher and embed it in GRDB.swift:
3537

36-
Apply the original version of the SQLCipher patch:
38+
* `./setup_sqlcipher.sh`
3739

38-
* `git am -3 0001-SQLCipher-support.patch`
40+
The script will also:
41+
* present the summary of updated versions and ask you to pick the new version number for DuckDuckGo GRDB fork,
42+
* create a new release branch and commit changes.
3943

40-
Compile SQLCipher amalgamation package [see general instructions](https://github.com/sqlcipher/sqlcipher#compiling-for-unix-like-systems):
44+
For versioning, follow [Semantic Versioning Rules](https://semver.org), but note you don't need
45+
to use the same version as GRDB. Examples:
4146

42-
* Use `./configure --with-crypto-lib=none`
43-
* Remember to use `make sqlite3.c` and not `make`.
44-
* Copy `sqlite3.c` and `sqlite3.h` to `Sources/SQLCipher/sqlite3.c` and `Sources/SQLCipher/include/sqlite3.h`
47+
* Upstream GRDB 5.6.0, after merge -> 5.12.0
48+
* This project 1.0.0 -> 1.1.0
49+
50+
* Upstream GRDB 5.12.0, after merge -> 6.0.0
51+
* This project 1.1.0 -> 2.0.0
4552

46-
Then update the README to state the versions used. Commit and push your branch, create PR for BSK referencing your new branch,
53+
If everything looks fine, push your branch, create PR for BSK referencing your new branch,
4754
and then create PRs for iOS and macOS apps referencing your BSK branch.
4855

49-
Once merged, tag the branch with a version according to how the version of GRDB was updated,
50-
i.e. maintaining [Semantic Versioning Rules](https://semver.org), but note you don't need
51-
to follow the version number of GRDB directly.
56+
Once merged, tag the branch with a version picked earlier and push the tag.
5257

53-
Examples:
58+
# Compiling SQLCipher manually
5459

55-
* Upstream GRDB 5.6.0, after merge -> 5.12.0
56-
* This project 1.0.0 -> 1.1.0
60+
In case `setup_sqlcipher.sh` script fails, you need to compile SQLCipher amalgamation package
61+
manually. See [general instructions](https://github.com/sqlcipher/sqlcipher#compiling-for-unix-like-systems):
5762

58-
* Upstream GRDB 5.12.0, after merge -> 6.0.0
59-
* This project 1.1.0 -> 2.0.0
63+
* Use `./configure --with-crypto-lib=none`.
64+
* Remember to use `make sqlite3.c` and not `make`.
65+
* Copy `sqlite3.c` and `sqlite3.h` to `Sources/SQLCipher/sqlite3.c` and `Sources/SQLCipher/include/sqlite3.h`.

.github/README.md.in

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# GRDB + SQLCipher
2+
3+
## What is this?
4+
This is a fork of [GRDB](https://github.com/groue/GRDB.swift) which contains a [SQLCipher Community Edition](https://www.zetetic.net/sqlcipher/open-source/) amalgamation packaged so that it can be consumed as a Swift Package.
5+
6+
The default branch for this repository is `SQLCipher` so that we can more easily pull upstream changes if we need to.
7+
8+
## Versioning
9+
10+
* This Package: *${new_version}*
11+
* GRDB: *${upstream_version}*
12+
* SQLCipher: *${sqlcipher_version}*
13+
14+
## Contributions
15+
We do not accept contributions to this repository at this time. However, feel free to open an issue in order to start a discussion.
16+
17+
## We are hiring!
18+
DuckDuckGo is growing fast and we continue to expand our fully distributed team. We embrace diverse perspectives, and seek out passionate, self-motivated people, committed to our shared vision of raising the standard of trust online. If you are a senior software engineer capable in either iOS or Android, visit our [careers](https://duckduckgo.com/hiring/#open) page to find out more about our openings!
19+
20+
## Updating from Upstream
21+
22+
Add remote upstream:
23+
24+
* `git remote add upstream [email protected]:groue/GRDB.swift.git`
25+
26+
Check out upstream's master branch locally:
27+
28+
* `git fetch upstream +master:upstream-master && git checkout upstream-master`
29+
30+
Update upstream's master branch if needed:
31+
32+
* `git pull upstream master`
33+
34+
Resolve any conflicts that may occur (normally there should be none or only in Package.swift)
35+
and commit the merge. Once done, run `setup_sqlcipher.sh` script to fetch and compile the latest tag
36+
of SQLCipher and embed it in GRDB.swift:
37+
38+
* `./setup_sqlcipher.sh`
39+
40+
The script will also:
41+
* present the summary of updated versions and ask you to pick the new version number for DuckDuckGo GRDB fork,
42+
* create a new release branch and commit changes.
43+
44+
For versioning, follow [Semantic Versioning Rules](https://semver.org), but note you don't need
45+
to use the same version as GRDB. Examples:
46+
47+
* Upstream GRDB 5.6.0, after merge -> 5.12.0
48+
* This project 1.0.0 -> 1.1.0
49+
50+
* Upstream GRDB 5.12.0, after merge -> 6.0.0
51+
* This project 1.1.0 -> 2.0.0
52+
53+
If everything looks fine, push your branch, create PR for BSK referencing your new branch,
54+
and then create PRs for iOS and macOS apps referencing your BSK branch.
55+
56+
Once merged, tag the branch with a version picked earlier and push the tag.
57+
58+
### Compiling SQLCipher manually
59+
60+
In case `setup_sqlcipher.sh` script fails, you need to compile SQLCipher amalgamation package
61+
manually. See [general instructions](https://github.com/sqlcipher/sqlcipher#compiling-for-unix-like-systems):
62+
63+
* Use `./configure --with-crypto-lib=none`.
64+
* Remember to use `make sqlite3.c` and not `make`.
65+
* Copy `sqlite3.c` and `sqlite3.h` to `Sources/SQLCipher/sqlite3.c` and `Sources/SQLCipher/include/sqlite3.h`.

setup_sqlcipher.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
mute=">/dev/null 2>&1"
6+
if [[ "$1" == "-v" ]]; then
7+
mute=
8+
fi
9+
10+
cwd="$(dirname "${BASH_SOURCE[0]}")"
11+
12+
build_sqlcipher() {
13+
local tempdir
14+
tempdir="$(mktemp -d)"
15+
trap 'rm -rf "$tempdir"' EXIT
16+
17+
sqlcipher_path="${cwd}/Sources/SQLCipher"
18+
local header_path="${sqlcipher_path}/include/sqlite3.h"
19+
local impl_path="${sqlcipher_path}/sqlite3.c"
20+
21+
printf '%s' "Cloning SQLCipher ... "
22+
eval git clone https://github.com/sqlcipher/sqlcipher.git "$tempdir" "$mute"
23+
echo ""
24+
25+
export GIT_DIR="${tempdir}/.git"
26+
sqlcipher_tag="$(git describe --tags --abbrev=0)"
27+
eval git checkout "$(git describe --tags --abbrev=0)" "$mute"
28+
unset GIT_DIR
29+
echo "Checked out SQLCipher latest tag: $sqlcipher_tag"
30+
31+
eval pushd "$tempdir" "$mute" || { echo "pushd failed"; exit 1; }
32+
33+
printf '%s' "Configuring SQLCipher ... "
34+
eval ./configure --with-crypto-lib=none "$mute"
35+
echo ""
36+
37+
printf '%s' "Building SQLCipher ... "
38+
eval make sqlite3.c "$mute"
39+
echo ""
40+
41+
eval popd "$mute" || { echo "popd failed"; exit 1; }
42+
43+
printf '%s' "Moving SQLCipher artifacts into place ... "
44+
rm -f "$header_path" "$impl_path"
45+
mkdir -p "${sqlcipher_path}/include"
46+
cp -f "${tempdir}/sqlite3.h" "$header_path"
47+
cp -f "${tempdir}/sqlite3.c" "$impl_path"
48+
echo ""
49+
}
50+
51+
update_sqlcipher_config() {
52+
sed -e 's:<SQLCipher/sqlite3.h>:"sqlite3.h":' "${cwd}/Support/SQLCipher_config.h" \
53+
> "${sqlcipher_path}/include/SQLCipher_config.h"
54+
git add "${sqlcipher_path}/include/SQLCipher_config.h"
55+
echo "Adjusted SQLCipher_config.h ✅"
56+
}
57+
58+
update_readme() {
59+
current_version="$(git describe --tags --abbrev=0 --exclude=v* origin/SQLCipher)"
60+
current_upstream_version="$(grep '\* GRDB' .github/README.md | cut -d '*' -f 3)"
61+
current_sqlcipher_version="$(grep '\* SQLCipher' .github/README.md | cut -d '*' -f 3)"
62+
grdb_tag="$(git describe --tags --abbrev=0 --match=v* upstream-master)"
63+
64+
new_version=
65+
echo "DuckDuckGo GRDB.swift current version: ${current_version}"
66+
echo "Upstream GRDB.swift version: ${current_upstream_version} -> ${grdb_tag}"
67+
echo "SQLCipher version: ${current_sqlcipher_version} -> ${sqlcipher_tag}"
68+
while ! [[ "${new_version}" =~ [0-9]\.[0-9]\.[0-9] ]]; do
69+
read -rp "Input DuckDuckGo GRDB.swift desired version number (x.y.z): " new_version < /dev/tty
70+
done
71+
72+
export new_version upstream_version="${grdb_tag#v}" sqlcipher_version="${sqlcipher_tag#v}"
73+
envsubst < "${cwd}/.github/README.md.in" > "${cwd}/.github/README.md"
74+
git add "${cwd}/.github/README.md"
75+
76+
echo "Updated .github/README.md ✅"
77+
}
78+
79+
setup_new_release_branch() {
80+
echo "Setting up new release branch ..."
81+
82+
git checkout -b "release/${new_version}-grdb-${grdb_tag#v}-sqlcipher-${sqlcipher_tag#v}"
83+
git add \
84+
"${cwd}/.github/README.md" \
85+
"${cwd}/GRDB/Export.swift" \
86+
"${cwd}/Package.swift" \
87+
"${cwd}/Sources/CSQLite" \
88+
"$sqlcipher_path"
89+
90+
}
91+
92+
main() {
93+
build_sqlcipher
94+
update_sqlcipher_config
95+
update_readme
96+
#setup_new_release_branch
97+
98+
echo "SQLCipher ${sqlcipher_tag} is ready to use with GRDB.swift ${grdb_tag} 🎉"
99+
}
100+
101+
main

0 commit comments

Comments
 (0)