Index: third_party/sqlite/patches/0007-Custom-shell.c-helpers-to-load-Chromium-s-ICU-data.patch |
diff --git a/third_party/sqlite/patches/0007-Custom-shell.c-helpers-to-load-Chromium-s-ICU-data.patch b/third_party/sqlite/patches/0007-Custom-shell.c-helpers-to-load-Chromium-s-ICU-data.patch |
new file mode 100644 |
index 0000000000000000000000000000000000000000..48cf68c262c2ac4e56505bfb56099e9bb8fe3261 |
--- /dev/null |
+++ b/third_party/sqlite/patches/0007-Custom-shell.c-helpers-to-load-Chromium-s-ICU-data.patch |
@@ -0,0 +1,145 @@ |
+From c7020c4c8f2e786436804819d11ca2e4b9878a5f Mon Sep 17 00:00:00 2001 |
+From: "tc@google.com" <tc@google.com> |
+Date: Tue, 6 Jan 2009 22:39:41 +0000 |
+Subject: [PATCH 07/16] Custom shell.c helpers to load Chromium's ICU data. |
+ |
+History uses fts3 with an icu-based segmenter. These changes allow building a |
+sqlite3 binary for Linux or Windows which can read those files. |
+ |
+Original review URL: https://codereview.chromium.org/42250 |
+--- |
+ third_party/sqlite/src/Makefile.linux-gcc | 7 ++++++ |
+ third_party/sqlite/src/main.mk | 2 +- |
+ third_party/sqlite/src/src/shell.c | 10 +++++++++ |
+ third_party/sqlite/src/src/shell_icu_linux.c | 27 +++++++++++++++++++++++ |
+ third_party/sqlite/src/src/shell_icu_win.c | 32 ++++++++++++++++++++++++++++ |
+ 5 files changed, 77 insertions(+), 1 deletion(-) |
+ create mode 100644 third_party/sqlite/src/src/shell_icu_linux.c |
+ create mode 100644 third_party/sqlite/src/src/shell_icu_win.c |
+ |
+diff --git a/third_party/sqlite/src/Makefile.linux-gcc b/third_party/sqlite/src/Makefile.linux-gcc |
+index e631816..f60f1a1 100644 |
+--- a/third_party/sqlite/src/Makefile.linux-gcc |
++++ b/third_party/sqlite/src/Makefile.linux-gcc |
+@@ -86,6 +86,13 @@ OPTS += -DOS_UNIX=1 |
+ # purposes. |
+ OPTS += -DDEFAULT_ENABLE_RECOVER=1 |
+ |
++# Support for loading Chromium ICU data in sqlite3. |
++ifeq ($(shell uname -s),Darwin) |
++SHELL_ICU = |
++else |
++SHELL_ICU = $(TOP)/src/shell_icu_linux.c -licuuc |
++endif |
++ |
+ #### The suffix to add to executable files. ".exe" for windows. |
+ # Nothing for unix. |
+ # |
+diff --git a/third_party/sqlite/src/main.mk b/third_party/sqlite/src/main.mk |
+index 2189fd6..54b5b35 100644 |
+--- a/third_party/sqlite/src/main.mk |
++++ b/third_party/sqlite/src/main.mk |
+@@ -395,7 +395,7 @@ libsqlite3.a: $(LIBOBJ) |
+ |
+ sqlite3$(EXE): $(TOP)/src/shell.c libsqlite3.a sqlite3.h |
+ $(TCCX) $(READLINE_FLAGS) -o sqlite3$(EXE) \ |
+- $(TOP)/src/shell.c \ |
++ $(TOP)/src/shell.c $(SHELL_ICU) \ |
+ libsqlite3.a $(LIBREADLINE) $(TLIBS) $(THREADLIB) |
+ |
+ mptester$(EXE): sqlite3.c $(TOP)/mptest/mptest.c |
+diff --git a/third_party/sqlite/src/src/shell.c b/third_party/sqlite/src/src/shell.c |
+index 3ca4b09..0951481 100644 |
+--- a/third_party/sqlite/src/src/shell.c |
++++ b/third_party/sqlite/src/src/shell.c |
+@@ -3963,6 +3963,16 @@ int main(int argc, char **argv){ |
+ signal(SIGINT, interrupt_handler); |
+ #endif |
+ |
++ /* Begin evanm patch. */ |
++#if !defined(__APPLE__) |
++ extern int sqlite_shell_init_icu(); |
++ if( !sqlite_shell_init_icu() ){ |
++ fprintf(stderr, "%s: warning: couldn't find icudt38.dll; " |
++ "queries against ICU FTS tables will fail.\n", argv[0]); |
++ } |
++#endif /* !defined(__APPLE__) */ |
++ /* End evanm patch. */ |
++ |
+ /* Do an initial pass through the command-line argument to locate |
+ ** the name of the database file, the name of the initialization file, |
+ ** the size of the alternative malloc heap, |
+diff --git a/third_party/sqlite/src/src/shell_icu_linux.c b/third_party/sqlite/src/src/shell_icu_linux.c |
+new file mode 100644 |
+index 0000000..4ad0e42 |
+--- /dev/null |
++++ b/third_party/sqlite/src/src/shell_icu_linux.c |
+@@ -0,0 +1,27 @@ |
++/* Copyright 2007 Google Inc. All Rights Reserved. |
++**/ |
++ |
++#include <limits.h> |
++#include <unistd.h> |
++#include "unicode/putil.h" |
++#include "unicode/udata.h" |
++ |
++/* |
++** This function attempts to load the ICU data tables from a data file. |
++** Returns 0 on failure, nonzero on success. |
++** This a hack job of icu_utils.cc:Initialize(). It's Chrome-specific code. |
++*/ |
++int sqlite_shell_init_icu() { |
++ char bin_dir[PATH_MAX + 1]; |
++ int bin_dir_size = readlink("/proc/self/exe", bin_dir, PATH_MAX); |
++ if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) |
++ return 0; |
++ bin_dir[bin_dir_size] = 0;; |
++ |
++ u_setDataDirectory(bin_dir); |
++ // Only look for the packaged data file; |
++ // the default behavior is to look for individual files. |
++ UErrorCode err = U_ZERO_ERROR; |
++ udata_setFileAccess(UDATA_ONLY_PACKAGES, &err); |
++ return err == U_ZERO_ERROR; |
++} |
+diff --git a/third_party/sqlite/src/src/shell_icu_win.c b/third_party/sqlite/src/src/shell_icu_win.c |
+new file mode 100644 |
+index 0000000..67ebbf4 |
+--- /dev/null |
++++ b/third_party/sqlite/src/src/shell_icu_win.c |
+@@ -0,0 +1,32 @@ |
++/* Copyright 2011 Google Inc. All Rights Reserved. |
++**/ |
++ |
++#include <windows.h> |
++#include "unicode/udata.h" |
++ |
++/* |
++** This function attempts to load the ICU data tables from a DLL. |
++** Returns 0 on failure, nonzero on success. |
++** This a hack job of icu_utils.cc:Initialize(). It's Chrome-specific code. |
++*/ |
++ |
++#define ICU_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat" |
++int sqlite_shell_init_icu() { |
++ HMODULE module; |
++ FARPROC addr; |
++ UErrorCode err; |
++ |
++ // Chrome dropped U_ICU_VERSION_SHORT from the icu data dll name. |
++ module = LoadLibrary(L"icudt.dll"); |
++ if (!module) |
++ return 0; |
++ |
++ addr = GetProcAddress(module, ICU_DATA_SYMBOL); |
++ if (!addr) |
++ return 0; |
++ |
++ err = U_ZERO_ERROR; |
++ udata_setCommonData(addr, &err); |
++ |
++ return 1; |
++} |
+-- |
+2.2.1 |
+ |