[libgda] gda: convert information schema to gresource



commit 42c9f94f4440ec8e36d0ef922259ccbd69c32b03
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date:   Thu Jan 17 09:03:13 2019 -0600

    gda: convert information schema to gresource
    
    Adds a new resource embeded to the libray binary,
    for xml and dtd files. For now, just information
    schema has been ported to use it.

 libgda/gda-meta-store.c      | 49 ++++++++++++++++++++++++++++----------------
 libgda/libgda.gresources.xml | 10 +++++++++
 libgda/meson.build           | 33 ++++++++++++++++++++++++++++-
 3 files changed, 73 insertions(+), 19 deletions(-)
---
diff --git a/libgda/gda-meta-store.c b/libgda/gda-meta-store.c
index 53d4f8196..a806ca431 100644
--- a/libgda/gda-meta-store.c
+++ b/libgda/gda-meta-store.c
@@ -1570,31 +1570,44 @@ create_db_objects (GdaMetaStoreClass *klass, GdaMetaStore *store)
        xmlNodePtr node;
        GError *lerror = NULL;
        GError **error = &lerror;
-       gchar *file;
+       GOutputStream *ostream;
+       GInputStream *istream;
+       GFile *res;
        xmlDocPtr doc = NULL;
+       gssize size;
+       gchar *schema;
        GdaMetaStorePrivate *priv;
 
        /* load information schema's structure XML file */
-       file = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "information_schema.xml", NULL);
-       if (g_file_test (file, G_FILE_TEST_EXISTS))
-               doc = xmlParseFile (file);
-       if (!doc) {
-               if (g_getenv ("GDA_TOP_SRC_DIR")) {
-                       g_free (file);
-                       file = g_build_filename (g_getenv ("GDA_TOP_SRC_DIR"), "libgda", 
"information_schema.xml", NULL);
-                       doc = xmlParseFile (file);
-               }
-               if (!doc) {
-                       g_warning ("Missing or malformed file '%s', check your installation", file);
-                       g_free (file);
-                       return;
-               }
+       ostream = g_memory_output_stream_new_resizable ();
+       res = g_file_new_for_uri ("resource:///libgda/information_schema.xml");
+       istream = g_file_read (res, NULL, lerror);
+       if (istream == NULL) {
+               g_warning (_("Internal error: no information schema was found: %s"),
+                                                        lerror && lerror->message ? lerror->message : "No 
error message was set");
+               g_clear_error (lerror);
+               return;
        }
+       g_clear_error (lerror);
+       size = g_output_stream_splice (ostream, istream, G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE, NULL, lerror);
+       if (size == -1) {
+               g_warning (_("Internal error: can't read information schema: %s"),
+                                                        lerror && lerror->message ? lerror->message : "No 
error message was set");
+               g_clear_error (lerror);
+               return;
+       }
+       g_clear_error (lerror);
+       schema = (gchar*) g_memory_output_stream_get_data (ostream);
+       doc = xmlReadDoc (schema, "", NULL, XML_PARSE_RECOVER);
+       g_object_unref (ostream);
+       g_object_unref (istream);
+       g_object_unref (res);
 
        node = xmlDocGetRootElement (doc);
-       if (!node || strcmp ((gchar *) node->name, "schema"))
-               g_error ("Root node of file '%s' should be <schema>.", file);
-       g_free (file);
+       if (!node || strcmp ((gchar *) node->name, "schema")) {
+               g_warning ("Root node of current information schema should be <schema>.");
+               return;
+       }
 
        /* walk through the xmlDoc */
        if (store) {
diff --git a/libgda/libgda.gresources.xml b/libgda/libgda.gresources.xml
new file mode 100644
index 000000000..399db9a43
--- /dev/null
+++ b/libgda/libgda.gresources.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/libgda">
+    <file compressed="true">information_schema.xml</file>
+    <file compressed="true">libgda-array.dtd</file>
+    <file compressed="true">libgda-db-catalog.dtd</file>
+    <file compressed="true">libgda-paramlist.dtd</file>
+    <file compressed="true">libgda-server-operation.dtd</file>
+  </gresource>
+</gresources>
diff --git a/libgda/meson.build b/libgda/meson.build
index 8dd31c8db..32e9f1e16 100644
--- a/libgda/meson.build
+++ b/libgda/meson.build
@@ -218,12 +218,43 @@ libgda_source_all = files([
        'gda-statement-priv.h',
        ])
 
+libgda_resourcesc = custom_target('libgda_resourcesc',
+       command: [compile_resources,
+               '--sourcedir='+meson.current_source_dir(),
+               '--generate-source',
+               '--target', '@OUTPUT@',
+               '--internal',
+               '@INPUT@'
+               ],
+       input: 'libgda.gresources.xml',
+       output: 'libgda_resource.c',
+       install: false
+       )
+
+libgda_resourcesh = custom_target('libgda_resourcesh',
+       command: [compile_resources,
+               '--sourcedir='+meson.current_source_dir(),
+               '--generate-header',
+               '--target', '@OUTPUT@',
+               '--internal',
+               '@INPUT@'
+               ],
+       input: 'libgda.gresources.xml',
+       output: 'libgda_resource.h',
+       install: false
+       )
+libgda_resources = [
+       libgda_resourcesc,
+       libgda_resourcesh
+       ]
+
 libgda_source_all += [
        libgda_sources,
        libgda_headers_all,
        gda_enums,
        gda_marshalls,
-       libgda_source_csvh
+       libgda_source_csvh,
+       libgda_resources
        ]
 libgda_source_all += [
        sqlitesources,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]