diff --git a/docs/reference/gtk/gtk4-builder-tool.rst b/docs/reference/gtk/gtk4-builder-tool.rst index a7e38e73d4..ad38532949 100644 --- a/docs/reference/gtk/gtk4-builder-tool.rst +++ b/docs/reference/gtk/gtk4-builder-tool.rst @@ -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. diff --git a/tools/gtk-builder-tool-validate.c b/tools/gtk-builder-tool-validate.c index 244771f875..db94242dff 100644 --- a/tools/gtk-builder-tool-validate.c +++ b/tools/gtk-builder-tool-validate.c @@ -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)