builder-tool: Try harder to find template parents

This will make it work (in some cases) to add extra
libraries via LD_PRELOAD.

Based on work by Julian Sparber,
https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/5084

Fixes: #5232
This commit is contained in:
Matthias Clasen 2023-02-19 13:07:16 -05:00
parent d67bdb96ad
commit a9f03be588
2 changed files with 11 additions and 5 deletions

View File

@ -33,6 +33,11 @@ Validation
The ``validate`` command validates the given UI definition file and reports
errors to ``stderr``.
Note that there are limitations to the validation that can be done for templates,
since they are closely tied to the class_init function they are used in.
If your UI file uses types from third-party libraries, it may help to add those
libraries to the `LD_PRELOAD` environment variable.
``--deprecations``
Warn about uses of deprecated types in the UI definition file.

View File

@ -149,10 +149,15 @@ validate_template (const char *filename,
GError *error = NULL;
gboolean ret;
builder = gtk_builder_new ();
scope = fake_scope_new ();
gtk_builder_set_scope (builder, GTK_BUILDER_SCOPE (scope));
g_object_unref (scope);
/* Only make a fake type if it doesn't exist yet.
* This lets us e.g. validate the GtkFileChooserWidget template.
*/
template_type = g_type_from_name (type_name);
template_type = gtk_builder_get_type_from_name (builder, type_name);
if (template_type == G_TYPE_INVALID)
template_type = make_fake_type (type_name, parent_name);
@ -163,15 +168,11 @@ validate_template (const char *filename,
return FALSE;
}
builder = gtk_builder_new ();
scope = fake_scope_new ();
gtk_builder_set_scope (builder, GTK_BUILDER_SCOPE (scope));
ret = gtk_builder_extend_with_template (builder, object, template_type, " ", 1, &error);
if (ret)
ret = gtk_builder_add_from_file (builder, filename, &error);
if (ret && deprecations)
ret = fake_scope_check_deprecations (scope, &error);
g_object_unref (scope);
g_object_unref (builder);
if (!ret)