[tracker/wip/carlosg/compiler-warnings: 2515/2517] docs: Avoid warnings doubly parsing base ontology




commit 9b99b074c1a985988f2c86f67de2681a6724dc2b
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Aug 28 14:16:35 2022 +0200

    docs: Avoid warnings doubly parsing base ontology
    
    Separate ontology parsing so that we can provide separate locations for
    .ontology and .description files, so that we can avoid doubly parsing the
    base ontology just for the sake of parsing the description files.
    
    This avoids redefinition warnings by the ontology docgen tool while
    generating the docs for the base ontology.

 docs/reference/libtracker-sparql/meson.build | 12 ++++++-----
 docs/tools/tracker-main.c                    | 30 ++++++++++++++++++++--------
 docs/tools/tracker-ontology-model.c          |  9 +++++----
 docs/tools/tracker-ontology-model.h          |  1 +
 4 files changed, 35 insertions(+), 17 deletions(-)
---
diff --git a/docs/reference/libtracker-sparql/meson.build b/docs/reference/libtracker-sparql/meson.build
index 72c03e352..b6dad9c9a 100644
--- a/docs/reference/libtracker-sparql/meson.build
+++ b/docs/reference/libtracker-sparql/meson.build
@@ -13,8 +13,10 @@ base_ontology_docs = custom_target('ontology-docgen',
     output: ['dc-ontology.md'],
     command: [tracker_docgen,
               '--md',
-              '-d', join_paths(source_root, 'src/ontologies/'),
-              '-o', join_paths(meson.current_build_dir())],
+              '--ontology-dir', meson.current_build_dir(), # Directory without ontology files
+              '--output-dir', meson.current_build_dir(),
+              '--introduction-dir', meson.current_source_dir(),
+              '--ontology-description-dir', join_paths(source_root, 'src/ontologies/')],
     depends: tracker_docgen,
     depend_files: [base_ontology],
     build_by_default: true,
@@ -24,9 +26,9 @@ nepomuk_ontology_docs = custom_target('nepomuk-docgen',
     output: ['nie-ontology.md'],
     command: [tracker_docgen,
               '--md',
-              '-d', join_paths(source_root, 'src/ontologies/nepomuk'),
-              '-o', join_paths(meson.current_build_dir()),
-              '-e', meson.current_source_dir()],
+              '--ontology-dir', join_paths(source_root, 'src/ontologies/nepomuk'),
+              '--output-dir', meson.current_build_dir(),
+              '--introduction-dir', meson.current_source_dir()],
     depends: tracker_docgen,
     depend_files: [base_ontology],
     build_by_default: true,
diff --git a/docs/tools/tracker-main.c b/docs/tools/tracker-main.c
index 754193e25..863b2ab2d 100644
--- a/docs/tools/tracker-main.c
+++ b/docs/tools/tracker-main.c
@@ -27,8 +27,9 @@
 #include "tracker-ontology-model.h"
 
 static gchar *ontology_dir = NULL;
+static gchar *ontology_desc_dir = NULL;
 static gchar *output_dir = NULL;
-static gchar *description_dir = NULL;
+static gchar *introduction_dir = NULL;
 static gboolean xml = FALSE;
 static gboolean markdown = FALSE;
 
@@ -37,12 +38,16 @@ static GOptionEntry   entries[] = {
          "Ontology directory",
          NULL
        },
+       { "ontology-description-dir", 'e', 0, G_OPTION_ARG_FILENAME, &ontology_desc_dir,
+         "Ontology description directory",
+         NULL
+       },
        { "output-dir", 'o', 0, G_OPTION_ARG_FILENAME, &output_dir,
          "File to write the output (default stdout)",
          NULL
        },
-       { "description-dir", 'e', 0, G_OPTION_ARG_FILENAME, &description_dir,
-         "Directory to find ontology descriptions",
+       { "introduction-dir", 'i', 0, G_OPTION_ARG_FILENAME, &introduction_dir,
+         "Directory to find ontology introduction",
          NULL
        },
        { "xml", 'x', 0, G_OPTION_ARG_NONE, &xml,
@@ -62,7 +67,7 @@ main (gint argc, gchar **argv)
        GOptionContext *context;
        TrackerOntologyDescription *description = NULL;
        TrackerOntologyModel *model = NULL;
-       g_autoptr(GFile) ontology_file = NULL, output_file = NULL;
+       g_autoptr(GFile) ontology_file = NULL, output_file = NULL, ontology_desc_file = NULL;
        gchar *path;
        GStrv prefixes = NULL;
        gint i;
@@ -75,7 +80,11 @@ main (gint argc, gchar **argv)
        /* Translators: this message will appear after the usage string */
        /* and before the list of options.                              */
        g_option_context_add_main_entries (context, entries, NULL);
-       g_option_context_parse (context, &argc, &argv, NULL);
+
+       if (!g_option_context_parse (context, &argc, &argv, &error)) {
+               g_printerr ("%s\n", error->message);
+               return -1;
+       }
 
        if (!!xml == !!markdown) {
                g_printerr ("%s\n",
@@ -100,7 +109,12 @@ main (gint argc, gchar **argv)
        ontology_file = g_file_new_for_commandline_arg (ontology_dir);
        output_file = g_file_new_for_commandline_arg (output_dir);
 
-       model = tracker_ontology_model_new (ontology_file, &error);
+       if (ontology_desc_dir)
+               ontology_desc_file = g_file_new_for_commandline_arg (ontology_desc_dir);
+       else
+               ontology_desc_file = g_object_ref (ontology_file);
+
+       model = tracker_ontology_model_new (ontology_file, ontology_desc_file, &error);
        if (error) {
                g_printerr ("Error loading ontology: %s\n", error->message);
                return -1;
@@ -118,9 +132,9 @@ main (gint argc, gchar **argv)
                        continue;
 
                if (xml)
-                       ttl_xml_print (description, model, prefixes[i], output_file, description_dir);
+                       ttl_xml_print (description, model, prefixes[i], output_file, introduction_dir);
                else if (markdown)
-                       ttl_md_print (description, model, prefixes[i], output_file, description_dir);
+                       ttl_md_print (description, model, prefixes[i], output_file, introduction_dir);
        }
 
        g_strfreev (prefixes);
diff --git a/docs/tools/tracker-ontology-model.c b/docs/tools/tracker-ontology-model.c
index 7ecbd1af6..51236608a 100644
--- a/docs/tools/tracker-ontology-model.c
+++ b/docs/tools/tracker-ontology-model.c
@@ -299,7 +299,8 @@ tracker_ontology_model_init_properties (TrackerOntologyModel *model)
 
 TrackerOntologyModel *
 tracker_ontology_model_new (GFile   *ontology_location,
-                           GError **error)
+                            GFile   *description_location,
+                            GError **error)
 {
        TrackerOntologyModel *model;
        TrackerSparqlConnection *ontology_conn, *desc_conn = NULL;
@@ -325,7 +326,7 @@ tracker_ontology_model_new (GFile   *ontology_location,
                goto error;
 
        /* Load all .description files into desc_conn */
-       enumerator = g_file_enumerate_children (ontology_location,
+       enumerator = g_file_enumerate_children (description_location,
                                                G_FILE_ATTRIBUTE_STANDARD_NAME,
                                                G_FILE_QUERY_INFO_NONE,
                                                NULL, error);
@@ -385,8 +386,8 @@ tracker_ontology_model_free (TrackerOntologyModel *model)
 {
        g_object_unref (model->ontology_conn);
        g_object_unref (model->desc_conn);
-       g_object_unref (model->classes_stmt);
-       g_object_unref (model->props_stmt);
+       g_clear_object (&model->classes_stmt);
+       g_clear_object (&model->props_stmt);
        g_hash_table_unref (model->stmts);
        g_hash_table_unref (model->classes);
        g_hash_table_unref (model->properties);
diff --git a/docs/tools/tracker-ontology-model.h b/docs/tools/tracker-ontology-model.h
index 60339fe46..8ea6d17cd 100644
--- a/docs/tools/tracker-ontology-model.h
+++ b/docs/tools/tracker-ontology-model.h
@@ -72,6 +72,7 @@ typedef struct {
 } TrackerOntologyDescription;
 
 TrackerOntologyModel * tracker_ontology_model_new (GFile   *ontology_location,
+                                                   GFile   *description_location,
                                                    GError **error);
 void tracker_ontology_model_free (TrackerOntologyModel *model);
 


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