| OLD | NEW |
| (Empty) | |
| 1 From c9842fae7d9dea4f309a736939af9ea68d4b41fb Mon Sep 17 00:00:00 2001 |
| 2 From: Scott Hess <shess@chromium.org> |
| 3 Date: Tue, 16 Dec 2014 13:03:21 -0800 |
| 4 Subject: [PATCH 09/24] Custom shell.c helpers to load Chromium's ICU data. |
| 5 |
| 6 History uses fts3 with an icu-based segmenter. These changes allow building a |
| 7 sqlite3 binary for Linux or Windows which can read those files. |
| 8 --- |
| 9 third_party/sqlite/src/Makefile.linux-gcc | 7 ++++++ |
| 10 third_party/sqlite/src/main.mk | 2 +- |
| 11 third_party/sqlite/src/src/shell.c | 10 +++++++++ |
| 12 third_party/sqlite/src/src/shell_icu_linux.c | 27 +++++++++++++++++++++++ |
| 13 third_party/sqlite/src/src/shell_icu_win.c | 32 ++++++++++++++++++++++++++++ |
| 14 5 files changed, 77 insertions(+), 1 deletion(-) |
| 15 create mode 100644 third_party/sqlite/src/src/shell_icu_linux.c |
| 16 create mode 100644 third_party/sqlite/src/src/shell_icu_win.c |
| 17 |
| 18 diff --git a/third_party/sqlite/src/Makefile.linux-gcc b/third_party/sqlite/src/
Makefile.linux-gcc |
| 19 index e631816..f60f1a1 100644 |
| 20 --- a/third_party/sqlite/src/Makefile.linux-gcc |
| 21 +++ b/third_party/sqlite/src/Makefile.linux-gcc |
| 22 @@ -86,6 +86,13 @@ OPTS += -DOS_UNIX=1 |
| 23 # purposes. |
| 24 OPTS += -DDEFAULT_ENABLE_RECOVER=1 |
| 25 |
| 26 +# Support for loading Chromium ICU data in sqlite3. |
| 27 +ifeq ($(shell uname -s),Darwin) |
| 28 +SHELL_ICU = |
| 29 +else |
| 30 +SHELL_ICU = $(TOP)/src/shell_icu_linux.c -licuuc |
| 31 +endif |
| 32 + |
| 33 #### The suffix to add to executable files. ".exe" for windows. |
| 34 # Nothing for unix. |
| 35 # |
| 36 diff --git a/third_party/sqlite/src/main.mk b/third_party/sqlite/src/main.mk |
| 37 index 65dd690..d20103f 100644 |
| 38 --- a/third_party/sqlite/src/main.mk |
| 39 +++ b/third_party/sqlite/src/main.mk |
| 40 @@ -358,7 +358,7 @@ libsqlite3.a: $(LIBOBJ) |
| 41 |
| 42 sqlite3$(EXE): $(TOP)/src/shell.c libsqlite3.a sqlite3.h |
| 43 $(TCCX) $(READLINE_FLAGS) -o sqlite3$(EXE) \ |
| 44 - $(TOP)/src/shell.c \ |
| 45 + $(TOP)/src/shell.c $(SHELL_ICU) \ |
| 46 libsqlite3.a $(LIBREADLINE) $(TLIBS) $(THREADLIB) |
| 47 |
| 48 # This target creates a directory named "tsrc" and fills it with |
| 49 diff --git a/third_party/sqlite/src/src/shell.c b/third_party/sqlite/src/src/she
ll.c |
| 50 index aab70b2..ffb4698 100644 |
| 51 --- a/third_party/sqlite/src/src/shell.c |
| 52 +++ b/third_party/sqlite/src/src/shell.c |
| 53 @@ -2663,6 +2663,16 @@ int main(int argc, char **argv){ |
| 54 int i; |
| 55 int rc = 0; |
| 56 |
| 57 + /* Begin evanm patch. */ |
| 58 +#if !defined(__APPLE__) |
| 59 + extern int sqlite_shell_init_icu(); |
| 60 + if( !sqlite_shell_init_icu() ){ |
| 61 + fprintf(stderr, "%s: warning: couldn't find icudt38.dll; " |
| 62 + "queries against ICU FTS tables will fail.\n", argv[0]); |
| 63 + } |
| 64 +#endif /* !defined(__APPLE__) */ |
| 65 + /* End evanm patch. */ |
| 66 + |
| 67 Argv0 = argv[0]; |
| 68 main_init(&data); |
| 69 stdin_is_interactive = isatty(0); |
| 70 diff --git a/third_party/sqlite/src/src/shell_icu_linux.c b/third_party/sqlite/s
rc/src/shell_icu_linux.c |
| 71 new file mode 100644 |
| 72 index 0000000..4ad0e42 |
| 73 --- /dev/null |
| 74 +++ b/third_party/sqlite/src/src/shell_icu_linux.c |
| 75 @@ -0,0 +1,27 @@ |
| 76 +/* Copyright 2007 Google Inc. All Rights Reserved. |
| 77 +**/ |
| 78 + |
| 79 +#include <limits.h> |
| 80 +#include <unistd.h> |
| 81 +#include "unicode/putil.h" |
| 82 +#include "unicode/udata.h" |
| 83 + |
| 84 +/* |
| 85 +** This function attempts to load the ICU data tables from a data file. |
| 86 +** Returns 0 on failure, nonzero on success. |
| 87 +** This a hack job of icu_utils.cc:Initialize(). It's Chrome-specific code. |
| 88 +*/ |
| 89 +int sqlite_shell_init_icu() { |
| 90 + char bin_dir[PATH_MAX + 1]; |
| 91 + int bin_dir_size = readlink("/proc/self/exe", bin_dir, PATH_MAX); |
| 92 + if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) |
| 93 + return 0; |
| 94 + bin_dir[bin_dir_size] = 0;; |
| 95 + |
| 96 + u_setDataDirectory(bin_dir); |
| 97 + // Only look for the packaged data file; |
| 98 + // the default behavior is to look for individual files. |
| 99 + UErrorCode err = U_ZERO_ERROR; |
| 100 + udata_setFileAccess(UDATA_ONLY_PACKAGES, &err); |
| 101 + return err == U_ZERO_ERROR; |
| 102 +} |
| 103 diff --git a/third_party/sqlite/src/src/shell_icu_win.c b/third_party/sqlite/src
/src/shell_icu_win.c |
| 104 new file mode 100644 |
| 105 index 0000000..67ebbf4 |
| 106 --- /dev/null |
| 107 +++ b/third_party/sqlite/src/src/shell_icu_win.c |
| 108 @@ -0,0 +1,32 @@ |
| 109 +/* Copyright 2011 Google Inc. All Rights Reserved. |
| 110 +**/ |
| 111 + |
| 112 +#include <windows.h> |
| 113 +#include "unicode/udata.h" |
| 114 + |
| 115 +/* |
| 116 +** This function attempts to load the ICU data tables from a DLL. |
| 117 +** Returns 0 on failure, nonzero on success. |
| 118 +** This a hack job of icu_utils.cc:Initialize(). It's Chrome-specific code. |
| 119 +*/ |
| 120 + |
| 121 +#define ICU_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat" |
| 122 +int sqlite_shell_init_icu() { |
| 123 + HMODULE module; |
| 124 + FARPROC addr; |
| 125 + UErrorCode err; |
| 126 + |
| 127 + // Chrome dropped U_ICU_VERSION_SHORT from the icu data dll name. |
| 128 + module = LoadLibrary(L"icudt.dll"); |
| 129 + if (!module) |
| 130 + return 0; |
| 131 + |
| 132 + addr = GetProcAddress(module, ICU_DATA_SYMBOL); |
| 133 + if (!addr) |
| 134 + return 0; |
| 135 + |
| 136 + err = U_ZERO_ERROR; |
| 137 + udata_setCommonData(addr, &err); |
| 138 + |
| 139 + return 1; |
| 140 +} |
| 141 -- |
| 142 2.2.1 |
| 143 |
| OLD | NEW |