summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLee Shombert <shombert@google.com>2024-02-08 16:52:33 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-02-08 16:52:33 +0000
commite52d4d5743ecd2c014fe32c1e257524e70c62eaa (patch)
tree18e1c5ad9a05943d3773334002855dd0045c7f06
parentc752a40cc62d5eb731628b4caa604e1928bfce1e (diff)
parent40495500c9ff086a2d9a981b431ff9ae5625c614 (diff)
downloadsqlite-e52d4d5743ecd2c014fe32c1e257524e70c62eaa.tar.gz
Merge "[sqlite] Allow multiple source versions" into main
-rw-r--r--Android.patch153
-rw-r--r--METADATA.TEMPLATE21
-rw-r--r--README-upgrade.md34
-rw-r--r--README.version.TEMPLATE3
-rwxr-xr-xUPDATE-SOURCE.bash45
5 files changed, 213 insertions, 43 deletions
diff --git a/Android.patch b/Android.patch
new file mode 100644
index 0000000..cd39abc
--- /dev/null
+++ b/Android.patch
@@ -0,0 +1,153 @@
+--- orig/shell.c 2023-06-13 13:30:22.470500137 -0700
++++ shell.c 2023-06-13 13:30:22.546500365 -0700
+@@ -127,6 +127,11 @@
+ #endif
+ #include <ctype.h>
+ #include <stdarg.h>
++// Begin Android Add
++#ifndef NO_ANDROID_FUNCS
++#include <sqlite3_android.h>
++#endif
++// End Android Add
+
+ #if !defined(_WIN32) && !defined(WIN32)
+ # include <signal.h>
+@@ -246,7 +251,9 @@
+ #if SQLITE_OS_WINRT
+ #include <intrin.h>
+ #endif
++#ifndef WIN32_LEAN_AND_MEAN
+ #define WIN32_LEAN_AND_MEAN
++#endif
+ #include <windows.h>
+
+ /* string conversion routines only needed on Win32 */
+@@ -20793,6 +20800,21 @@
+ editFunc, 0, 0);
+ #endif
+
++// Begin Android Add
++#ifndef NO_ANDROID_FUNCS
++ int err = register_localized_collators(p->db, "en_US", 0);
++ if (err != SQLITE_OK) {
++ fprintf(stderr, "register_localized_collators() failed\n");
++ exit(1);
++ }
++ err = register_android_functions(p->db, 0);
++ if (err != SQLITE_OK) {
++ fprintf(stderr, "register_android_functions() failed\n");
++ exit(1);
++ }
++#endif
++// End Android Add
++
+ if( p->openMode==SHELL_OPEN_ZIPFILE ){
+ char *zSql = sqlite3_mprintf(
+ "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", zDbFilename);
+--- orig/sqlite3.c 2023-06-13 13:30:22.494500209 -0700
++++ sqlite3.c 2023-06-13 13:30:22.590500496 -0700
+@@ -37314,6 +37314,10 @@
+ # include <sys/mount.h>
+ #endif
+
++#if defined(__BIONIC__)
++# include <android/fdsan.h>
++#endif
++
+ #ifdef HAVE_UTIME
+ # include <utime.h>
+ #endif
+@@ -37922,6 +37926,12 @@
+ #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
+ osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
+ #endif
++
++#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
++ uint64_t tag = android_fdsan_create_owner_tag(
++ ANDROID_FDSAN_OWNER_TYPE_SQLITE, fd);
++ android_fdsan_exchange_owner_tag(fd, 0, tag);
++#endif
+ }
+ return fd;
+ }
+@@ -38502,7 +38512,13 @@
+ ** and move on.
+ */
+ static void robust_close(unixFile *pFile, int h, int lineno){
++#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
++ uint64_t tag = android_fdsan_create_owner_tag(
++ ANDROID_FDSAN_OWNER_TYPE_SQLITE, h);
++ if( android_fdsan_close_with_tag(h, tag) ){
++#else
+ if( osClose(h) ){
++#endif
+ unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
+ pFile ? pFile->zPath : 0, lineno);
+ }
+@@ -41051,7 +41067,7 @@
+ SimulateIOError( rc=1 );
+ if( rc!=0 ){
+ storeLastErrno((unixFile*)id, errno);
+- return SQLITE_IOERR_FSTAT;
++ return unixLogError(SQLITE_IOERR_FSTAT, "fstat", ((unixFile*)id)->zPath);
+ }
+ *pSize = buf.st_size;
+
+@@ -41087,7 +41103,7 @@
+ struct stat buf; /* Used to hold return values of fstat() */
+
+ if( osFstat(pFile->h, &buf) ){
+- return SQLITE_IOERR_FSTAT;
++ return unixLogError(SQLITE_IOERR_FSTAT, "fstat", pFile->zPath);
+ }
+
+ nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
+@@ -41829,7 +41845,7 @@
+ ** with the same permissions.
+ */
+ if( osFstat(pDbFd->h, &sStat) ){
+- rc = SQLITE_IOERR_FSTAT;
++ rc = unixLogError(SQLITE_IOERR_FSTAT, "fstat", pDbFd->zPath);
+ goto shm_open_err;
+ }
+
+@@ -138266,7 +138282,7 @@
+ }
+ if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){
+ sqlite3SetString(pzErrMsg, db, "unsupported file format");
+- rc = SQLITE_ERROR;
++ rc = SQLITE_CORRUPT_BKPT; // Android Change from "rc = SQLITE_ERROR;";
+ goto initone_error_out;
+ }
+
+@@ -185208,7 +185224,9 @@
+ ** module with sqlite.
+ */
+ if( SQLITE_OK==rc
++#ifndef ANDROID /* fts3_tokenizer disabled for security reasons */
+ && SQLITE_OK==(rc=sqlite3Fts3InitHashTable(db,&pHash->hash,"fts3_tokenizer"))
++#endif
+ && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
+ && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
+ && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
+@@ -185219,6 +185237,20 @@
+ rc = sqlite3_create_module_v2(
+ db, "fts3", &fts3Module, (void *)pHash, hashDestroy
+ );
++#ifdef SQLITE_ENABLE_FTS3_BACKWARDS
++ if( rc==SQLITE_OK ){
++ pHash->nRef++;
++ rc = sqlite3_create_module_v2(
++ db, "fts1", &fts3Module, (void *)pHash, hashDestroy
++ );
++ }
++ if( rc==SQLITE_OK ){
++ pHash->nRef++;
++ rc = sqlite3_create_module_v2(
++ db, "fts2", &fts3Module, (void *)pHash, hashDestroy
++ );
++ }
++#endif
+ if( rc==SQLITE_OK ){
+ pHash->nRef++;
+ rc = sqlite3_create_module_v2(
diff --git a/METADATA.TEMPLATE b/METADATA.TEMPLATE
new file mode 100644
index 0000000..10702c1
--- /dev/null
+++ b/METADATA.TEMPLATE
@@ -0,0 +1,21 @@
+name: "SQLite"
+description:
+ "SQLite database"
+
+third_party {
+ url {
+ type: HOMEPAGE
+ value: "https://www.sqlite.org"
+ }
+ url {
+ type: ARCHIVE
+ value: "${SQLITE_URL}"
+ }
+ version: "${SQLITE_VERSION}"
+ last_upgrade_date { year: ${YEAR} month: ${MONTH} day: ${DAY} }
+ license_type: NOTICE
+
+ security: {
+ tag: "NVD-CPE2.3:cpe:/a:sqlite:sqlite" # see http://go/metadata-cpe
+ }
+}
diff --git a/README-upgrade.md b/README-upgrade.md
index 060fabd..ee01a63 100644
--- a/README-upgrade.md
+++ b/README-upgrade.md
@@ -14,12 +14,12 @@ external/sqlite
The upgrade steps are:
* Select a version for the upgrade.
-* Download the autoconf amalgamation tarball. For release 3.42.0, the URL is
+* Find the autoconf amalgamation tarball. For release 3.42.0, the URL is
[sqlite-autoconf-3420000.tar.gz](https://sqlite.org/2023/sqlite-autoconf-3420000.tar.gz).
* Change to the directory `external/sqlite` in the workspace.
-* Run the script `UPDATE-SOURCE.bash`. This script is executable. The single
- argument is the path to the tarball.
-* Update the internal bookkeeping files (see below).
+* Run the script `UPDATE-SOURCE.bash`. This script is executable. The
+ arguments are the tarball URL and the version. Invoke the script without
+ arguments for an example.
`UPDATE-SOURCE.bash` may fail if the Android patch cannot be applied cleanly. If
this happens, correct the patch failures by hand and rebuild the Android patch
@@ -27,25 +27,7 @@ file. Use the script `REBUILD-ANDROID-PATCH.bash` to rebuild the patch file.
Then rerun `UPDATE-SOURCE.bash`. It is important that `UPDATE-SOURCE.bash` run
without errors.
-A number of files in this directory require special handling.
-
-### README.version
-
-This contains the URL of the source code, the version information, and the bug
-component under which the Android tree was updated. An example is below.
-
-```text
-URL: https://sqlite.org/2023/sqlite-autoconf-3420000.tar.gz
-Version: 3.42.0
-BugComponent: 24950
-```
-
-### METADATA
-
-This file contains a security tag and a reference to the license file. The
-format changes now and then; ensure that it is up to date.
-
-### LICENSE
+## LICENSE
This file contains the license that allows Android to use the third-party
software. SQLite is unusual because it has no license: it is in the public
@@ -76,11 +58,7 @@ Update the following two constants (the values below are for SQLite 3.42.0).
static final int EXPECTED_MIN_PATCH_LEVEL = 0;
```
-## Miscellaneous Files
-
-The following files are updated in an internal Android branch (such as `main`)
-
-### package.html
+## package.html
```text
frameworks/base/core/java/android/database/sqlite/package.html
diff --git a/README.version.TEMPLATE b/README.version.TEMPLATE
new file mode 100644
index 0000000..9344a88
--- /dev/null
+++ b/README.version.TEMPLATE
@@ -0,0 +1,3 @@
+URL: ${SQLITE_URL}
+Version: ${SQLITE_VERSION}
+BugComponent: 24950
diff --git a/UPDATE-SOURCE.bash b/UPDATE-SOURCE.bash
index 408ce07..fdd9093 100755
--- a/UPDATE-SOURCE.bash
+++ b/UPDATE-SOURCE.bash
@@ -25,8 +25,12 @@ set -e
script_name="$(basename "$0")"
-source_tgz="$1"
-source_ext_dir="$1.extracted"
+if [ $# -eq 0 ]; then
+ echo "Usage: ${script_name} [src_tarball_url] [sqlite_version]"
+ echo "Example:"
+ echo "${script_name} https://sqlite.org/2023/sqlite-autoconf-3420000.tar.gz 3.42.0"
+ exit 1
+fi
die() {
echo "$script_name: $*"
@@ -38,24 +42,20 @@ echo_and_exec() {
"$@"
}
-# Make sure the source tgz file exists.
pwd="$(pwd)"
if [[ ! "$pwd" =~ .*/external/sqlite/? ]] ; then
die 'Execute this script in $ANDROID_BUILD_TOP/external/sqlite/'
fi
-# Make sure the source tgz file exists.
-
-if [[ ! -f "$source_tgz" ]] ; then
- die " Missing or invalid argument.
-
- Usage: $script_name SQLITE-SOURCE_TGZ
-"
-fi
+src_tarball_url="$1"
+sqlite_version="$2"
+source_tgz=$(mktemp /tmp/sqlite-${sqlite_version}.zip.XXXXXX)
+wget ${src_tarball_url} -O ${source_tgz}
echo
echo "# Extracting the source tgz..."
+source_ext_dir="${source_tgz}.extracted"
echo_and_exec rm -fr "$source_ext_dir"
echo_and_exec mkdir -p "$source_ext_dir"
echo_and_exec tar xvf "$source_tgz" -C "$source_ext_dir" --strip-components=1
@@ -68,26 +68,41 @@ echo "# Making file sqlite3.c in $source_ext_dir ..."
echo_and_exec make -j 4 sqlite3.c
)
+dist_dir="dist-${sqlite_version}"
echo
echo "# Copying the source files ..."
-for to in dist/orig/ dist/ ; do
+echo_and_exec mkdir -p "${dist_dir}"
+echo_and_exec mkdir -p "${dist_dir}/orig"
+for to in ${dist_dir}/orig/ ${dist_dir}/ ; do
echo_and_exec cp "$source_ext_dir/"{shell.c,sqlite3.c,sqlite3.h,sqlite3ext.h} "$to"
done
echo
echo "# Applying Android.patch ..."
(
- cd dist
- echo_and_exec patch -i Android.patch
+ cd ${dist_dir}
+ echo_and_exec patch -i ../Android.patch
)
echo
echo "# Regenerating Android.patch ..."
(
- cd dist
+ cd ${dist_dir}
echo_and_exec bash -c '(for x in orig/*; do diff -u -d $x ${x#orig/}; done) > Android.patch'
)
+echo
+echo "# Generating metadata ..."
+(
+ export SQLITE_URL=${src_tarball_url}
+ export SQLITE_VERSION=${sqlite_version}
+ export YEAR=$(date +%Y)
+ export MONTH=$(date +%M)
+ export DAY=$(date +%D)
+ envsubst < README.version.TEMPLATE > ${dist_dir}/README.version
+ envsubst < METADATA.TEMPLATE > ${dist_dir}/METADATA
+)
+
cat <<EOF
=======================================================