blob: 297799c06a42760c01e6870c44bd798f0ce138e4 [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
Lee Shombertfd845c32024-03-24 11:06:59 -070017# This script updates SQLite source files with a SQLite tarball. The tarball is
18# downloaded from the sqlite website.
Makoto Onuki86e52722018-12-21 13:45:51 -080019#
Lee Shombertfd845c32024-03-24 11:06:59 -070020# Usage: UPDATE-SOURCE.bash [-nF] <year> <sqlite-release>
Makoto Onuki86e52722018-12-21 13:45:51 -080021#
Lee Shombertfd845c32024-03-24 11:06:59 -070022# This script must be executed in $ANDROID_BUILD_TOP/external/sqlite/. However,
23# for testing it can run anywhere: use the -F switch.
Makoto Onuki86e52722018-12-21 13:45:51 -080024#
25
26set -e
27
28script_name="$(basename "$0")"
Lee Shombertfd845c32024-03-24 11:06:59 -070029script_dir=$(dirname $(realpath ${BASH_SOURCE[0]}))
Makoto Onuki86e52722018-12-21 13:45:51 -080030
Lee Shombert152fb622024-03-25 15:35:08 -070031source $script_dir/common-functions.sh
32
Lee Shombertfd845c32024-03-24 11:06:59 -070033usage() {
34 if [[ $# -gt 0 ]]; then echo "$*" >&2; fi
Lee Shombert152fb622024-03-25 15:35:08 -070035 echo "Usage: ${script_name} [-nF] [-u <url>] <year> <version>"
Lee Shombertfd845c32024-03-24 11:06:59 -070036 echo " year the 4-digit year the sqlite version was released"
37 echo " version the sqlite version as <major>.<minor>[.<patch>]"
38 echo " the patch level defaults to 0"
39 echo " -n dry-run: evaluate arguments but d not change anything"
Lee Shombert152fb622024-03-25 15:35:08 -070040 echo " -u url download the tarball from the specified url"
Lee Shombertfd845c32024-03-24 11:06:59 -070041 echo " -F force execution even if not in external/sqlite"
42 echo
Shai Barack40495502024-01-29 17:51:51 +000043 echo "Example:"
Lee Shombertfd845c32024-03-24 11:06:59 -070044 echo "${script_name} 2023 3.42"
45}
Makoto Onuki86e52722018-12-21 13:45:51 -080046
Lee Shombertfd845c32024-03-24 11:06:59 -070047dry_run=
48force=
Lee Shombert152fb622024-03-25 15:35:08 -070049src_tarball_url=
50while getopts "hnFu:" option; do
Lee Shombertfd845c32024-03-24 11:06:59 -070051 case $option in
52 h) usage; exit 0;;
53 n) dry_run=y;;
Lee Shombert152fb622024-03-25 15:35:08 -070054 u) src_tarball_url=$OPTARG;;
Lee Shombertfd845c32024-03-24 11:06:59 -070055 F) force=y;;
56 *) usage "unknown switch"; exit 1;;
57 esac
58done
59shift $((OPTIND- 1))
60
61if [[ $# -lt 2 ]]; then
62 usage; die "missing required arguments"
63elif [[ $# -gt 2 ]]; then
64 die "extra arguments on command line"
65fi
66year=$1
67validate_year "$year" || die "invalid year"
68sqlite_release=$(normalize_release "$2") || die "invalid release"
69
70sqlite_base="sqlite-autoconf-${sqlite_release}"
71sqlite_file="${sqlite_base}.tar.gz"
Lee Shombert152fb622024-03-25 15:35:08 -070072if [[ -z $src_tarball_url ]]; then
73 src_tarball_url="https://www.sqlite.org/$year/${sqlite_file}"
74fi
Lee Shombertfd845c32024-03-24 11:06:59 -070075
76if [[ -n $dry_run ]]; then
77 echo "fetching $src_tarball_url"
78 echo "installing in dist/$sqlite_base"
79 exit 0
80fi
81
Makoto Onuki86e52722018-12-21 13:45:51 -080082pwd="$(pwd)"
Lee Shombertfd845c32024-03-24 11:06:59 -070083if [[ -z $force && ! "$pwd" =~ .*/external/sqlite/? ]] ; then
Makoto Onuki86e52722018-12-21 13:45:51 -080084 die 'Execute this script in $ANDROID_BUILD_TOP/external/sqlite/'
85fi
86
Lee Shombertfd845c32024-03-24 11:06:59 -070087source_tgz=$(mktemp /tmp/sqlite-${sqlite_release}.zip.XXXXXX)
88source_ext_dir="${source_tgz}.extracted"
89trap "rm -r ${source_tgz} ${source_ext_dir}" EXIT
Shai Barack40495502024-01-29 17:51:51 +000090wget ${src_tarball_url} -O ${source_tgz}
Makoto Onuki86e52722018-12-21 13:45:51 -080091
92echo
93echo "# Extracting the source tgz..."
94echo_and_exec rm -fr "$source_ext_dir"
95echo_and_exec mkdir -p "$source_ext_dir"
96echo_and_exec tar xvf "$source_tgz" -C "$source_ext_dir" --strip-components=1
97
98echo
99echo "# Making file sqlite3.c in $source_ext_dir ..."
100(
101 cd "$source_ext_dir"
102 echo_and_exec ./configure
103 echo_and_exec make -j 4 sqlite3.c
104)
105
Lee Shombertfd845c32024-03-24 11:06:59 -0700106export dist_dir="dist/${sqlite_base}"
Makoto Onuki86e52722018-12-21 13:45:51 -0800107echo
108echo "# Copying the source files ..."
Lee Shombertfd845c32024-03-24 11:06:59 -0700109echo_and_exec rm -rf ${dist_dir}
Shai Barack40495502024-01-29 17:51:51 +0000110echo_and_exec mkdir -p "${dist_dir}"
111echo_and_exec mkdir -p "${dist_dir}/orig"
112for to in ${dist_dir}/orig/ ${dist_dir}/ ; do
Makoto Onuki86e52722018-12-21 13:45:51 -0800113 echo_and_exec cp "$source_ext_dir/"{shell.c,sqlite3.c,sqlite3.h,sqlite3ext.h} "$to"
114done
115
Lee Shombertfd845c32024-03-24 11:06:59 -0700116export patch_dir=${script_dir}/dist
Makoto Onuki86e52722018-12-21 13:45:51 -0800117echo
118echo "# Applying Android.patch ..."
119(
Shai Barack40495502024-01-29 17:51:51 +0000120 cd ${dist_dir}
Lee Shombertfd845c32024-03-24 11:06:59 -0700121 echo "PATCHING IN $dist_dir" >&2
122 echo_and_exec patch -i ${patch_dir}/Android.patch
Makoto Onuki86e52722018-12-21 13:45:51 -0800123)
124
125echo
126echo "# Regenerating Android.patch ..."
127(
Shai Barack40495502024-01-29 17:51:51 +0000128 cd ${dist_dir}
Makoto Onuki86e52722018-12-21 13:45:51 -0800129 echo_and_exec bash -c '(for x in orig/*; do diff -u -d $x ${x#orig/}; done) > Android.patch'
Lee Shombertfd845c32024-03-24 11:06:59 -0700130 echo_and_exec cp Android.patch ${patch_dir}/
Makoto Onuki86e52722018-12-21 13:45:51 -0800131)
132
Shai Barack40495502024-01-29 17:51:51 +0000133echo
134echo "# Generating metadata ..."
135(
136 export SQLITE_URL=${src_tarball_url}
Lee Shombertfd845c32024-03-24 11:06:59 -0700137 export SQLITE_VERSION=$(prettify_release ${sqlite_release})
Shai Barack40495502024-01-29 17:51:51 +0000138 export YEAR=$(date +%Y)
139 export MONTH=$(date +%M)
140 export DAY=$(date +%D)
141 envsubst < README.version.TEMPLATE > ${dist_dir}/README.version
142 envsubst < METADATA.TEMPLATE > ${dist_dir}/METADATA
143)
144
Makoto Onuki86e52722018-12-21 13:45:51 -0800145cat <<EOF
146
147=======================================================
148
149 Finished successfully!
150
151 Make sure to update README.version
152
153=======================================================
154
155EOF
156