blob: fdd9093bc03115043821988a611c760e291e8b2d [file] [log] [blame]
Makoto Onuki86e52722018-12-21 13:45:51 -08001#!/bin/bash
2#
3# Copyright (C) 2018 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# This script updates SQLite source files with a SQLite tarball.
18#
19# Usage: UPDATE-SOURCE.bash SQLITE-SOURCE.tgz
20#
21# This script must be executed in $ANDROID_BUILD_TOP/external/sqlite/
22#
23
24set -e
25
26script_name="$(basename "$0")"
27
Shai Barack40495502024-01-29 17:51:51 +000028if [ $# -eq 0 ]; then
29 echo "Usage: ${script_name} [src_tarball_url] [sqlite_version]"
30 echo "Example:"
31 echo "${script_name} https://sqlite.org/2023/sqlite-autoconf-3420000.tar.gz 3.42.0"
32 exit 1
33fi
Makoto Onuki86e52722018-12-21 13:45:51 -080034
35die() {
36 echo "$script_name: $*"
37 exit 1
38}
39
40echo_and_exec() {
41 echo " Running: $@"
42 "$@"
43}
44
Makoto Onuki86e52722018-12-21 13:45:51 -080045pwd="$(pwd)"
46if [[ ! "$pwd" =~ .*/external/sqlite/? ]] ; then
47 die 'Execute this script in $ANDROID_BUILD_TOP/external/sqlite/'
48fi
49
Shai Barack40495502024-01-29 17:51:51 +000050src_tarball_url="$1"
51sqlite_version="$2"
Makoto Onuki86e52722018-12-21 13:45:51 -080052
Shai Barack40495502024-01-29 17:51:51 +000053source_tgz=$(mktemp /tmp/sqlite-${sqlite_version}.zip.XXXXXX)
54wget ${src_tarball_url} -O ${source_tgz}
Makoto Onuki86e52722018-12-21 13:45:51 -080055
56echo
57echo "# Extracting the source tgz..."
Shai Barack40495502024-01-29 17:51:51 +000058source_ext_dir="${source_tgz}.extracted"
Makoto Onuki86e52722018-12-21 13:45:51 -080059echo_and_exec rm -fr "$source_ext_dir"
60echo_and_exec mkdir -p "$source_ext_dir"
61echo_and_exec tar xvf "$source_tgz" -C "$source_ext_dir" --strip-components=1
62
63echo
64echo "# Making file sqlite3.c in $source_ext_dir ..."
65(
66 cd "$source_ext_dir"
67 echo_and_exec ./configure
68 echo_and_exec make -j 4 sqlite3.c
69)
70
Shai Barack40495502024-01-29 17:51:51 +000071dist_dir="dist-${sqlite_version}"
Makoto Onuki86e52722018-12-21 13:45:51 -080072echo
73echo "# Copying the source files ..."
Shai Barack40495502024-01-29 17:51:51 +000074echo_and_exec mkdir -p "${dist_dir}"
75echo_and_exec mkdir -p "${dist_dir}/orig"
76for to in ${dist_dir}/orig/ ${dist_dir}/ ; do
Makoto Onuki86e52722018-12-21 13:45:51 -080077 echo_and_exec cp "$source_ext_dir/"{shell.c,sqlite3.c,sqlite3.h,sqlite3ext.h} "$to"
78done
79
80echo
81echo "# Applying Android.patch ..."
82(
Shai Barack40495502024-01-29 17:51:51 +000083 cd ${dist_dir}
84 echo_and_exec patch -i ../Android.patch
Makoto Onuki86e52722018-12-21 13:45:51 -080085)
86
87echo
88echo "# Regenerating Android.patch ..."
89(
Shai Barack40495502024-01-29 17:51:51 +000090 cd ${dist_dir}
Makoto Onuki86e52722018-12-21 13:45:51 -080091 echo_and_exec bash -c '(for x in orig/*; do diff -u -d $x ${x#orig/}; done) > Android.patch'
92)
93
Shai Barack40495502024-01-29 17:51:51 +000094echo
95echo "# Generating metadata ..."
96(
97 export SQLITE_URL=${src_tarball_url}
98 export SQLITE_VERSION=${sqlite_version}
99 export YEAR=$(date +%Y)
100 export MONTH=$(date +%M)
101 export DAY=$(date +%D)
102 envsubst < README.version.TEMPLATE > ${dist_dir}/README.version
103 envsubst < METADATA.TEMPLATE > ${dist_dir}/METADATA
104)
105
Makoto Onuki86e52722018-12-21 13:45:51 -0800106cat <<EOF
107
108=======================================================
109
110 Finished successfully!
111
112 Make sure to update README.version
113
114=======================================================
115
116EOF
117