1#!/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. The tarball is 18# downloaded from the sqlite website. 19# 20# Usage: UPDATE-SOURCE.bash [-nF] <year> <sqlite-release> 21# 22# This script must be executed in $ANDROID_BUILD_TOP/external/sqlite/. However, 23# for testing it can run anywhere: use the -F switch. 24# 25 26set -e 27 28script_name="$(basename "$0")" 29script_dir=$(dirname $(realpath ${BASH_SOURCE[0]})) 30 31source $script_dir/common-functions.sh 32 33usage() { 34 if [[ $# -gt 0 ]]; then echo "$*" >&2; fi 35 echo "Usage: ${script_name} [-nF] [-u <url>] <year> <version>" 36 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" 40 echo " -u url download the tarball from the specified url" 41 echo " -F force execution even if not in external/sqlite" 42 echo 43 echo "Example:" 44 echo "${script_name} 2023 3.42" 45} 46 47dry_run= 48force= 49src_tarball_url= 50while getopts "hnFu:" option; do 51 case $option in 52 h) usage; exit 0;; 53 n) dry_run=y;; 54 u) src_tarball_url=$OPTARG;; 55 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" 72if [[ -z $src_tarball_url ]]; then 73 src_tarball_url="https://www.sqlite.org/$year/${sqlite_file}" 74fi 75 76if [[ -n $dry_run ]]; then 77 echo "fetching $src_tarball_url" 78 echo "installing in dist/$sqlite_base" 79 exit 0 80fi 81 82pwd="$(pwd)" 83if [[ -z $force && ! "$pwd" =~ .*/external/sqlite/? ]] ; then 84 die 'Execute this script in $ANDROID_BUILD_TOP/external/sqlite/' 85fi 86 87source_tgz=$(mktemp /tmp/sqlite-${sqlite_release}.zip.XXXXXX) 88source_ext_dir="${source_tgz}.extracted" 89trap "rm -r ${source_tgz} ${source_ext_dir}" EXIT 90wget ${src_tarball_url} -O ${source_tgz} 91 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 106export dist_dir="dist/${sqlite_base}" 107echo 108echo "# Copying the source files ..." 109echo_and_exec rm -rf ${dist_dir} 110echo_and_exec mkdir -p "${dist_dir}" 111echo_and_exec mkdir -p "${dist_dir}/orig" 112for to in ${dist_dir}/orig/ ${dist_dir}/ ; do 113 echo_and_exec cp "$source_ext_dir/"{shell.c,sqlite3.c,sqlite3.h,sqlite3ext.h} "$to" 114done 115 116export patch_dir=${script_dir}/dist 117echo 118echo "# Applying Android.patch ..." 119( 120 cd ${dist_dir} 121 echo "PATCHING IN $dist_dir" >&2 122 echo_and_exec patch -i ${patch_dir}/Android.patch 123) 124 125echo 126echo "# Regenerating Android.patch ..." 127( 128 cd ${dist_dir} 129 echo_and_exec bash -c '(for x in orig/*; do diff -u -d $x ${x#orig/}; done) > Android.patch' 130 echo_and_exec cp Android.patch ${patch_dir}/ 131) 132 133echo 134echo "# Generating metadata ..." 135( 136 export SQLITE_URL=${src_tarball_url} 137 export SQLITE_VERSION=$(prettify_release ${sqlite_release}) 138 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 145cat <<EOF 146 147======================================================= 148 149 Finished successfully! 150 151 Make sure to update README.version 152 153======================================================= 154 155EOF 156 157