[Groonga-commit] groonga/groonga [master] support plugins search from relative path of groonga DLL on Windows.

Back to archive index

null+****@clear***** null+****@clear*****
2010年 11月 16日 (火) 14:22:27 JST


Kouhei Sutou	2010-11-16 05:22:27 +0000 (Tue, 16 Nov 2010)

  New Revision: b0ae8622342c4a652797d97b952a6223668623da

  Log:
    support plugins search from relative path of groonga DLL on Windows.

  Modified files:
    configure.ac
    lib/plugin.c

  Modified: configure.ac (+6 -2)
===================================================================
--- configure.ac    2010-11-16 04:22:54 +0000 (89a3c48)
+++ configure.ac    2010-11-16 05:22:27 +0000 (3bdd038)
@@ -669,7 +669,10 @@ AC_MSG_CHECKING([for sphinx availablity])
 AC_MSG_RESULT($ac_sphinx_available (sphinx-build=$SPHINX_BUILD version=$sphinx_build_version required=$sphinx_required_version))
 
 # plugins check
-pluginsdir="\${libdir}/\$(PACKAGE)/plugins"
+relative_pluginsdir="\$(PACKAGE)/plugins"
+AC_SUBST(relative_pluginsdir)
+
+pluginsdir="\${libdir}/\$(relative_pluginsdir)"
 AC_SUBST(pluginsdir)
 
 tokenizer_pluginsdir="\${pluginsdir}/tokenizers"
@@ -699,7 +702,8 @@ AC_SUBST(examples_dictionarydir)
 GROONGA_CFLAGS=""
 AC_SUBST(GROONGA_CFLAGS)
 GROONGA_DEFS=""
-GROONGA_DEFS="$GROONGA_DEFS -DPLUGINS_DIR=\\\"\"\$(pluginsdir)\"\\\""
+GROONGA_DEFS="$GROONGA_DEFS -DGROONGA_PLUGINS_DIR=\\\"\"\$(pluginsdir)\"\\\""
+GROONGA_DEFS="$GROONGA_DEFS -DGROONGA_RELATIVE_PLUGINS_DIR=\\\"\"lib/\$(relative_pluginsdir)\"\\\""
 GROONGA_DEFS="$GROONGA_DEFS -DGROONGA_LOG_PATH=\\\"\"\$(groonga_log_path)\"\\\""
 AC_SUBST(GROONGA_DEFS)
 CFLAGS="$CFLAGS $OPT_CFLAGS "

  Modified: lib/plugin.c (+60 -1)
===================================================================
--- lib/plugin.c    2010-11-16 04:22:54 +0000 (9a291f8)
+++ lib/plugin.c    2010-11-16 05:22:27 +0000 (6102266)
@@ -299,6 +299,65 @@ grn_db_register(grn_ctx *ctx, const char *path)
   GRN_API_RETURN(ctx->rc);
 }
 
+#ifdef WIN32
+static char *win32_plugins_dir = NULL;
+static const char *
+default_plugins_dir(void)
+{
+  if (!win32_plugins_dir) {
+    wchar_t dll_filename[MAX_PATH];
+    DWORD dll_filename_size;
+    dll_filename_size = GetModuleFileNameW(NULL, dll_filename, MAX_PATH);
+    if (dll_filename_size == 0) {
+      win32_plugins_dir = GROONGA_PLUGINS_DIR;
+    } else {
+      char *plugins_dir;
+      DWORD ansi_dll_filename_size;
+      ansi_dll_filename_size =
+        WideCharToMultiByte(CP_ACP, 0, dll_filename, dll_filename_size,
+                            NULL, 0, NULL, NULL);
+      if (ansi_dll_filename_size == 0) {
+        win32_plugins_dir = GROONGA_PLUGINS_DIR;
+      } else {
+        char *path;
+        const char *relative_path = GROONGA_RELATIVE_PLUGINS_DIR;
+        plugins_dir = malloc(ansi_dll_filename_size +
+                             strlen(relative_path));
+        WideCharToMultiByte(CP_ACP, 0, dll_filename, dll_filename_size,
+                            plugins_dir, ansi_dll_filename_size,
+                            NULL, NULL);
+        if ((path = strrchr(plugins_dir, '\\'))) {
+          *path = '\0';
+        }
+        path = strrchr(plugins_dir, '\\');
+        if (path && (strcasecmp(path + 1, "bin") == 0 ||
+                     strcasecmp(path + 1, "lib") == 0)) {
+          *path = '\0';
+        } else {
+          path = plugins_dir + strlen(plugins_dir);
+        }
+        *path = '\\';
+        path++;
+        while (*relative_path) {
+          if (*relative_path == '/') {
+            *path = '\\';
+          } else {
+            *path = *relative_path;
+          }
+          relative_path++;
+          path++;
+        }
+        *path = '\0';
+        win32_plugins_dir = plugins_dir;
+      }
+    }
+  }
+  return win32_plugins_dir;
+}
+#else /* WIN32 */
+#  define default_plugins_dir() GROONGA_PLUGINS_DIR;
+#endif /* WIN32 */
+
 grn_rc
 grn_db_register_by_name(grn_ctx *ctx, const char *name)
 {
@@ -308,7 +367,7 @@ grn_db_register_by_name(grn_ctx *ctx, const char *name)
 
   plugins_dir = getenv("GRN_PLUGINS_DIR");
   if (!plugins_dir) {
-    plugins_dir = PLUGINS_DIR;
+    plugins_dir = default_plugins_dir();
   }
   strcpy(path, plugins_dir);
   dir_last_char = plugins_dir[strlen(plugins_dir) - 1];




Groonga-commit メーリングリストの案内
Back to archive index