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>] [-y <year>] <version>" 36 echo " version the sqlite version as <major>.<minor>[.<patch>]" 37 echo " the patch level defaults to 0" 38 echo " -n dry-run: evaluate arguments but d not change anything" 39 echo " -u url download the tarball from the specified url" 40 echo " -y year the 4-digit year the sqlite version was released - required" 41 echo " if a full url is not specified and the year is not this year" 42 echo " -F force execution even if not in external/sqlite" 43 echo 44 echo "Example:" 45 echo "${script_name} 2023 3.42" 46} 47 48dry_run= 49force= 50src_tarball_url= 51year=$(date +%Y) 52while getopts "hnFu:y:" option; do 53 case $option in 54 h) usage; exit 0;; 55 n) dry_run=y;; 56 u) src_tarball_url=$OPTARG;; 57 y) year=$OPTARG;; 58 F) force=y;; 59 *) usage "unknown switch"; exit 1;; 60 esac 61done 62shift $((OPTIND- 1)) 63 64if [[ $# -lt 1 ]]; then 65 usage; die "missing required arguments" 66elif [[ $# -gt 1 ]]; then 67 die "extra arguments on command line" 68fi 69sqlite_release=$(normalize_release "$1") || die "invalid release" 70 71sqlite_base="sqlite-autoconf-${sqlite_release}" 72sqlite_file="${sqlite_base}.tar.gz" 73if [[ -z $src_tarball_url ]]; then 74 validate_year "$year" || die "invalid year" 75 src_tarball_url="https://www.sqlite.org/$year/${sqlite_file}" 76fi 77 78if [[ -n $dry_run ]]; then 79 echo "fetching $src_tarball_url" 80 echo "installing in dist/$sqlite_base" 81 exit 0 82fi 83 84pwd="$(pwd)" 85if [[ -z $force && ! "$pwd" =~ .*/external/sqlite/? ]] ; then 86 die 'Execute this script in $ANDROID_BUILD_TOP/external/sqlite/' 87fi 88 89source_tgz=$(mktemp /tmp/sqlite-${sqlite_release}.zip.XXXXXX) 90source_ext_dir="${source_tgz}.extracted" 91trap "rm -r ${source_tgz} ${source_ext_dir}" EXIT 92wget ${src_tarball_url} -O ${source_tgz} 93 94echo 95echo "# Extracting the source tgz..." 96echo_and_exec rm -fr "$source_ext_dir" 97echo_and_exec mkdir -p "$source_ext_dir" 98echo_and_exec tar xvf "$source_tgz" -C "$source_ext_dir" --strip-components=1 99 100echo 101echo "# Making file sqlite3.c in $source_ext_dir ..." 102( 103 cd "$source_ext_dir" 104 echo_and_exec ./configure 105 echo_and_exec make -j 4 sqlite3.c 106) 107 108export dist_dir="dist/${sqlite_base}" 109echo 110echo "# Copying the source files ..." 111echo_and_exec rm -rf ${dist_dir} 112echo_and_exec mkdir -p "${dist_dir}" 113echo_and_exec mkdir -p "${dist_dir}/orig" 114for to in ${dist_dir}/orig/ ${dist_dir}/ ; do 115 echo_and_exec cp "$source_ext_dir/"{shell.c,sqlite3.c,sqlite3.h,sqlite3ext.h} "$to" 116done 117 118export patch_dir=${script_dir}/dist 119echo 120echo "# Applying Android.patch ..." 121( 122 cd ${dist_dir} 123 echo "PATCHING IN $dist_dir" >&2 124 echo_and_exec patch -i ${patch_dir}/Android.patch 125) 126 127echo 128echo "# Regenerating Android.patch ..." 129( 130 cd ${dist_dir} 131 echo_and_exec bash -c '(for x in orig/*; do diff -u -d $x ${x#orig/}; done) > Android.patch' 132 echo_and_exec cp Android.patch ${patch_dir}/ 133) 134 135echo 136echo "# Generating metadata ..." 137( 138 export SQLITE_URL=${src_tarball_url} 139 export SQLITE_VERSION=$(prettify_release ${sqlite_release}) 140 export YEAR=$(date +%Y) 141 export MONTH=$(date +%-m) 142 export DAY=$(date +%-d) 143 envsubst < README.version.TEMPLATE > ${dist_dir}/README.version 144 envsubst < METADATA.TEMPLATE > ${dist_dir}/METADATA 145) 146 147cat <<EOF 148 149======================================================= 150 151 Finished successfully! 152 153 Make sure to update README.version 154 155======================================================= 156 157EOF 158 159