Changeset: e5c0bec89214 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e5c0bec89214
Modified Files:
        monetdb5/mal/mal_session.c
        tools/embedded/build-rpkg.sh
        tools/embedded/encode.R
Branch: embedded
Log Message:

now two scripts, one to startup mal and one to create db


diffs (137 lines):

diff --git a/monetdb5/mal/mal_session.c b/monetdb5/mal/mal_session.c
--- a/monetdb5/mal/mal_session.c
+++ b/monetdb5/mal/mal_session.c
@@ -21,6 +21,10 @@
 #include "mal_private.h"
 #include <gdk.h>       /* for opendir and friends */
 
+#ifdef HAVE_EMBEDDED
+#include "mal_init_inline.h"
+#endif
+
 /*
  * The MonetDB server uses a startup script to boot the system.
  * This script is an ordinary MAL program, but will mostly
diff --git a/tools/embedded/build-rpkg.sh b/tools/embedded/build-rpkg.sh
--- a/tools/embedded/build-rpkg.sh
+++ b/tools/embedded/build-rpkg.sh
@@ -21,18 +21,21 @@ sed -i -e "/^SUBDIRS = .*$/d" sql/backen
 cd ..
 mv sourcetree/tools/embedded/rpackage .
 rsync -av --exclude-from sourcetree/tools/embedded/pkg-excludes sourcetree/ 
rpackage/src
-
-# binarize all MAL/SQL scripts
-R --slave -f rpackage/src/tools/embedded/encode.R --args rpackage/src/ 
rpackage/src/tools/embedded/include_files.h
-
-# generate sql_parser.tab.c/h to remove our dependency on bison.
-cd sourcetree
-./configure
-cd sql/server/
-make sql_parser.tab.h
-make sql_parser.tab.c
-cd ../../../
+ 
+# generate mal/sql scripts and sql_parser.tab.c/h to remove our dependency on 
bison.
+ln -s sourcetree src
+export R_INCLUDE_DIR=`R CMD config --cppflags | sed s/^-I//`
+export R_PACKAGE_DIR=$STAGEDIR/dummytarget
+mkdir $R_PACKAGE_DIR
+# install a build in the dummytarget dir to collect mal/sql scripts
+# need these two files so the dummy build goes through, they are generated 
later
+touch sourcetree/monetdb5/mal/mal_init_inline.h 
sourcetree/sql/backends/monet5/createdb_inline.h
+# run dummy build
+./rpackage/configure
+# steal the sql parser files
 cp sourcetree/sql/server/sql_parser.tab.* rpackage/src/sql/server/
+# inline mal/sql scripts, we need R with the stringr package for that
+R --slave -f sourcetree/tools/embedded/encode.R --args 
dummytarget/libs/monetdb5/ rpackage/src/
 
 # bundle pcre for windows
 wget http://dev.monetdb.org/Assets/R/misc/pcre-8.37.zip
@@ -43,7 +46,6 @@ mv msvcr100.dll rpackage/src/tools/embed
 
 mkdir -p rpackage/src/monetdb5/extras/rapi
 touch rpackage/src/monetdb5/extras/rapi/placeholder
-# rm "rpackage/src/buildtools/conf/lt~obsolete.m4"
 
 R CMD build rpackage
 
diff --git a/tools/embedded/encode.R b/tools/embedded/encode.R
--- a/tools/embedded/encode.R
+++ b/tools/embedded/encode.R
@@ -1,33 +1,44 @@
-# this script generates a C file containing the content of all mal/sql files 
-# mentioned in Makefile.ag files as well as a mapping from file name to index
+# this script generates startup createdb scripts for MonetDBlite
 args <- commandArgs(trailingOnly = TRUE)
-makefiles <- dir(path=args[1], 
-       pattern="Makefile.ag", full.names=T, recursive=T)
-con <- file(args[2], open="wb"); fidx <- character(0)
-ct <- function(x, ...) cat(x, file=con, append=T, ...)
-ct("char* include_file_data[] = {\n")
-for (mf in makefiles) {
-       message("Processing ", mf)
-       instfiles <- stringr::str_extract_all(
-               readChar(mf, file.info(mf)$size), "\\w+\\.(mal|sql)")[[1]]
-       for (instf in file.path(dirname(mf), instfiles)) {
-               ct("\"\\x")
-               message("Including ", instf, " into ", args[2])
-               ct(readBin(instf, what="raw", n=file.info(instf)$size), 
sep="\\x")
-               ct("\\0\",\n")
-       }
-       fidx <- c(fidx, instfiles)
+
+dp <- function(fn, fl, sn) {
+       con <- file(fn, open="wb");
+       ct <- function(x, ...) cat(x, file=con, append=T, ...)
+       ct("char*")
+       ct(sn)
+       ct(" = \"")
+       invisible(lapply(fl, function(mf) {
+               ct("\\x")
+               message("Including ", mf, " into ", fn)
+               ct(readBin(mf, what="raw", n=file.info(mf)$size), sep="\\x")
+               ct("\\n")
+       }))
+       ct("\";\n")
+       close(con)
 }
-ct("NULL};\nchar* include_file_name[] = {\"")
-ct(as.character(fidx), sep="\",\"")
-ct("\",NULL};\n")
-ct("char* include_file_get(char* fname) {
-       size_t i = 0;
-       while(1) {
-               if (include_file_name[i] == NULL) break;
-               if (strncmp(fname, include_file_name[i], 
strlen(include_file_name[i])) == 0)
-                       return include_file_data[i];    
-               i++;
-       }
-       return NULL;
-}\n")
+
+# find all include'd modules in mal_init
+mal_init <- file.path(args[1], "mal_init.mal")
+mal_init_modules <- stringr::str_match_all(readChar(mal_init, 
file.info(mal_init)$size), 
+       "include (\\w+);")[[1]][,2]
+
+# modules we don't load.
+ignored_modules <- c("autoload", "mcurl", "sabaoth", "recycle", "remote", 
"txtsim", 
+       "tokenizer", "zorder", "srvpool", "mal_mapi")
+
+# make sure files exist and male full paths
+mal_init_modules <- file.path(args[1], paste0(setdiff(mal_init_modules, 
ignored_modules), ".mal"))
+mal_init_modules <- mal_init_modules[file.exists(mal_init_modules)]
+
+# scan autoload directory and add those too
+autoload <- sort(dir(path=file.path(args[1], "autoload"), pattern="*.mal", 
full.names=T))
+mal_init_modules <- c(mal_init_modules, autoload)
+
+# dump everything into header file
+mal_init_file <- file.path(args[2], "monetdb5", "mal", "mal_init_inline.h")
+dp(mal_init_file, mal_init_modules, "mal_init_inline")
+
+# do the same for sql createdb
+createdb <- sort(dir(path=file.path(args[1], "createdb"), pattern="*.sql", 
full.names=T))
+createdb_file <- file.path(args[2], "sql", "backends", "monet5", 
"createdb_inline.h")
+dp(createdb_file, createdb, "createdb_inline")
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to