gsettings: stay compatible with installed schemas
authorRyan Lortie <desrt@desrt.ca>
Thu, 9 Apr 2015 01:55:58 +0000 (21:55 -0400)
committerRyan Lortie <desrt@desrt.ca>
Thu, 9 Apr 2015 02:35:35 +0000 (22:35 -0400)
Bug 747209 introduced an error when multiple <summary> or <description>
tags are found for a single key in a GSettings schema.  This check
should have been present from the start, but it was left out because the
schema compiler doesn't include these items in the cache file.  Even
still -- part of the schema compiler's job is validation, and it should
be enforcing proper syntax here.

Repeated <summary> and <description> tags are a semi-common problem when
intltool has been misconfigured in the build system of a package, but
it's possible to imagine mistakes being made by hand as well.

The idea is that these problems would be caught during the build of a
package and maintainers would be forced to fix their build systems.

An unintended side-effect of this change, however, is that the schema
compiler started ignoring already-installed schemas that contained these
problems, when rebuilding the cache.  This means that the installation
of _any_ application would cause the regeneration of the entire cache,
with these already-installed applications being excluded.  Without the
schema in the cache, the application would crash on next startup.

The validation check in the gsettings m4 macro passes --strict to the
compiler, which is not used when rebuilding the cache after
installation.  Pass this flag down into the parser and only throw the
error in case --strict was given.  This will result in the (desired)
build failure without also causing already-installed apps to stop
functioning.

This means that we will not get even a warning about the invalid schema
file in the already-installed case, but that's fine.  There is no sense
spamming the user with these messages when they are already quite fatal
for the developer at build time.

https://bugzilla.gnome.org/show_bug.cgi?id=747472

gio/glib-compile-schemas.c

index 4e0604b..a09ceae 100644 (file)
@@ -1063,6 +1063,8 @@ override_state_end (KeyState **key_state,
 /* Handling of toplevel state {{{1 */
 typedef struct
 {
+  gboolean     strict;                  /* TRUE if --strict was given */
+
   GHashTable  *schema_table;            /* string -> SchemaState */
   GHashTable  *flags_table;             /* string -> EnumState */
   GHashTable  *enum_table;              /* string -> EnumState */
@@ -1381,7 +1383,7 @@ start_element (GMarkupParseContext  *context,
 
       else if (strcmp (element_name, "summary") == 0)
         {
-          if (state->key_state->summary_seen)
+          if (state->key_state->summary_seen && state->strict)
             g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                          _("Only one <%s> element allowed inside <%s>"),
                          element_name, container);
@@ -1394,7 +1396,7 @@ start_element (GMarkupParseContext  *context,
 
       else if (strcmp (element_name, "description") == 0)
         {
-          if (state->key_state->description_seen)
+          if (state->key_state->description_seen && state->strict)
             g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                          _("Only one <%s> element allowed inside <%s>"),
                          element_name, container);
@@ -1721,6 +1723,8 @@ parse_gschema_files (gchar    **files,
   const gchar *filename;
   GError *error = NULL;
 
+  state.strict = strict;
+
   state.enum_table = g_hash_table_new_full (g_str_hash, g_str_equal,
                                             g_free, enum_state_free);