[Groonga-commit] groonga/groonga at c9ea214 [master] Add groonga-mruby command

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Nov 3 13:56:09 JST 2014


Kouhei Sutou	2014-11-03 13:56:09 +0900 (Mon, 03 Nov 2014)

  New Revision: c9ea214b1448123b4cc32219abbde95186e4c860
  https://github.com/groonga/groonga/commit/c9ea214b1448123b4cc32219abbde95186e4c860

  Message:
    Add groonga-mruby command
    
    You can evaluate Ruby script in the specified database context with
    groonga-mruby.
    
    Groonga-mruby is added just for testing.

  Added files:
    src/groonga_mruby.c
    src/groonga_mruby_sources.am
  Modified files:
    .gitignore
    config.sh.in
    configure.ac
    src/Makefile.am

  Modified: .gitignore (+1 -0)
===================================================================
--- .gitignore    2014-11-03 13:54:41 +0900 (9254cb3)
+++ .gitignore    2014-11-03 13:56:09 +0900 (ed85e48)
@@ -51,6 +51,7 @@ aclocal.m4
 /src/groonga
 /src/groonga-benchmark
 /src/grnslap
+/src/groonga-mruby
 Makefile
 Makefile.in
 version.sh

  Modified: config.sh.in (+1 -0)
===================================================================
--- config.sh.in    2014-11-03 13:54:41 +0900 (b4cec3c)
+++ config.sh.in    2014-11-03 13:56:09 +0900 (d15e5e3)
@@ -4,3 +4,4 @@ export GROONGA="@GROONGA@"
 export GROONGA_HTTPD="@GROONGA_HTTPD@"
 export GROONGA_SUGGEST_CREATE_DATASET="@GROONGA_SUGGEST_CREATE_DATASET@"
 export GROONGA_BENCHMARK="@GROONGA_BENCHMARK@"
+export GROONGA_MRUBY="@GROONGA_MRUBY@"

  Modified: configure.ac (+4 -0)
===================================================================
--- configure.ac    2014-11-03 13:54:41 +0900 (6cbe623)
+++ configure.ac    2014-11-03 13:56:09 +0900 (3838296)
@@ -683,6 +683,10 @@ AC_SUBST(GROONGA_BENCHMARK)
 GROONGA_SUGGEST_CREATE_DATASET="${ac_pwd}/src/suggest/groonga-suggest-create-dataset"
 AC_SUBST(GROONGA_SUGGEST_CREATE_DATASET)
 
+# groonga-mruby binary path
+GROONGA_MRUBY="${ac_pwd}/src/groonga-mruby"
+AC_SUBST(GROONGA_MRUBY)
+
 # check Cutter with GLib support if available
 REQUIRED_MINIMUM_CUTTER_VERSION=1.1.6
 REQUIRED_MINIMUM_CPPCUTTER_VERSION=1.2.0

  Modified: src/Makefile.am (+9 -0)
===================================================================
--- src/Makefile.am    2014-11-03 13:54:41 +0900 (b125db5)
+++ src/Makefile.am    2014-11-03 13:56:09 +0900 (8c05b0c)
@@ -5,6 +5,9 @@ SUBDIRS =					\
 NONEXISTENT_CXX_SOURCE = nonexistent.cpp
 
 bin_PROGRAMS = groonga groonga-benchmark
+if WITH_MRUBY
+bin_PROGRAMS += groonga-mruby
+endif
 noinst_PROGRAMS = grnslap
 
 EXTRA_DIST =					\
@@ -46,3 +49,9 @@ nodist_EXTRA_groonga_benchmark_SOURCES = $(NONEXISTENT_CXX_SOURCE)
 groonga_benchmark_LDADD =			\
 	$(top_builddir)/lib/libgroonga.la	\
 	$(MESSAGE_PACK_LIBS)
+
+include groonga_mruby_sources.am
+nodist_EXTRA_groonga_mruby_SOURCES = $(NONEXISTENT_CXX_SOURCE)
+groonga_mruby_LDADD =				\
+	$(top_builddir)/lib/libgroonga.la	\
+	$(MESSAGE_PACK_LIBS)

  Added: src/groonga_mruby.c (+84 -0) 100644
===================================================================
--- /dev/null
+++ src/groonga_mruby.c    2014-11-03 13:56:09 +0900 (8fb9f76)
@@ -0,0 +1,84 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2014 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "../lib/grn_mrb.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+static int
+run(grn_ctx *ctx, const char *db_path, const char *ruby_script_path)
+{
+  grn_obj *db;
+
+  db = grn_db_open(ctx, db_path);
+  if (!db) {
+    if (ctx->rc == GRN_NO_SUCH_FILE_OR_DIRECTORY) {
+      db = grn_db_create(ctx, db_path, NULL);
+      if (!db) {
+        fprintf(stderr, "Failed to create database: <%s>: %s",
+                db_path, ctx->errbuf);
+        return EXIT_FAILURE;
+      }
+    } else {
+      fprintf(stderr, "Failed to open database: <%s>: %s",
+              db_path, ctx->errbuf);
+      return EXIT_FAILURE;
+    }
+  }
+
+  grn_mrb_load(ctx, ruby_script_path);
+  if (ctx->rc != GRN_SUCCESS) {
+      fprintf(stderr, "Failed to load Ruby script: <%s>: %s",
+              ruby_script_path, ctx->errbuf);
+  }
+
+  grn_obj_close(ctx, db);
+
+  if (ctx->rc == GRN_SUCCESS) {
+    return EXIT_SUCCESS;
+  } else {
+    return EXIT_FAILURE;
+  }
+}
+
+int
+main(int argc, char **argv)
+{
+  int exit_code = EXIT_SUCCESS;
+
+  if (argc != 3) {
+    fprintf(stderr, "Usage: %s DB_PATH RUBY_SCRIPT_PATH\n", argv[0]);
+    return EXIT_FAILURE;
+  }
+
+  if (grn_init() != GRN_SUCCESS) {
+    return EXIT_FAILURE;
+  }
+
+  {
+    grn_ctx ctx;
+    grn_ctx_init(&ctx, 0);
+    exit_code = run(&ctx, argv[1], argv[2]);
+    grn_ctx_fin(&ctx);
+  }
+
+  grn_fin();
+
+  return exit_code;
+}

  Added: src/groonga_mruby_sources.am (+2 -0) 100644
===================================================================
--- /dev/null
+++ src/groonga_mruby_sources.am    2014-11-03 13:56:09 +0900 (c900675)
@@ -0,0 +1,2 @@
+groonga_mruby_SOURCES =				\
+	groonga_mruby.c
-------------- next part --------------
HTML����������������������������...
下載 



More information about the Groonga-commit mailing list
Back to archive index