Compare commits

...

2 Commits

Author SHA1 Message Date
Matthias Clasen
1cc3c019e6 Include precompiled versions of .ui files
These are smaller, and a faster to process than .ui files.
2021-12-14 01:51:22 -05:00
Matthias Clasen
319aa558a5 buildertool: Add a precompile command
This writes out the precompiled format of .ui
files that we are using internally.
2021-12-14 01:51:22 -05:00
35 changed files with 124 additions and 6 deletions

View File

@@ -16,6 +16,7 @@ SYNOPSIS
| **gtk4-builder-tool** enumerate <FILE>
| **gtk4-builder-tool** simplify [OPTIONS...] <FILE>
| **gtk4-builder-tool** preview [OPTIONS...] <FILE>
| **gtk4-builder-tool** precompile [OPTIONS...] <FILE>
DESCRIPTION
-----------
@@ -83,3 +84,10 @@ to do manual fixups after the initial conversion.
``--3to4``
Transform a GTK 3 UI definition file to the equivalent GTK 4 definitions.
Precompilation
^^^^^^^^^^^^^^
The ``precompile`` command creates a more compact, and faster to load compiled
form of the ui file that is understood by GtkBuilder. The output is written
to a file with the extension ``.precompiled``.

View File

@@ -66,7 +66,7 @@ for f in get_files('theme/Default/assets-hc', '.svg'):
xml += ' <file preprocess=\'xml-stripblanks\'>theme/Default/assets-hc/{0}</file>\n'.format(f)
for f in get_files('ui', '.ui'):
xml += ' <file>ui/{0}</file>\n'.format(f)
xml += ' <file alias="ui/{0}">ui/{0}.precompiled</file>\n'.format(f)
xml += '\n'

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,106 @@
/* Copyright 2020 Red Hat, Inc.
*
* GTK+ is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* GLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with GTK+; see the file COPYING. If not,
* see <http://www.gnu.org/licenses/>.
*
* Author: Matthias Clasen
*/
#define GTK_COMPILATION
#include "../gtk/gtkbuilderprecompile.c"
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <glib/gi18n.h>
#include <glib/gprintf.h>
#include <glib/gstdio.h>
#include <gtk/gtk.h>
#include "gtk-builder-tool.h"
static void
precompile_file (const char *filename)
{
char *data;
gsize len;
GError *error = NULL;
char *outfile;
GBytes *bytes;
if (!g_file_get_contents (filename, &data, &len, &error))
{
g_warning ("Failed to load '%s': %s", filename, error->message);
exit (1);
}
bytes = _gtk_buildable_parser_precompile (data, len, &error);
if (bytes == NULL)
{
g_warning ("Failed to precompile '%s': %s", filename, error->message);
exit (1);
}
outfile = g_strconcat (filename, ".precompiled", NULL);
if (!g_file_set_contents (outfile, g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes), &error))
if (bytes == NULL)
{
g_warning ("Failed to write precompiled data to '%s': %s", outfile, error->message);
exit (1);
}
g_print ("Wrote %ld bytes to %s.\n", g_bytes_get_size (bytes), outfile);
g_free (outfile);
g_bytes_unref (bytes);
}
void
do_precompile (int *argc,
const char ***argv)
{
GOptionContext *context;
char **filenames = NULL;
const GOptionEntry entries[] = {
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL, NULL },
{ NULL, }
};
GError *error = NULL;
int i;
context = g_option_context_new (NULL);
g_option_context_set_help_enabled (context, FALSE);
g_option_context_add_main_entries (context, entries, NULL);
if (!g_option_context_parse (context, argc, (char ***)argv, &error))
{
g_printerr ("%s\n", error->message);
g_error_free (error);
exit (1);
}
g_option_context_free (context);
if (filenames == NULL)
{
g_printerr ("No .ui file specified\n");
exit (1);
}
for (i = 0; filenames[i]; i++)
precompile_file (filenames[i]);
g_strfreev (filenames);
}

View File

@@ -134,6 +134,8 @@ main (int argc, const char *argv[])
do_enumerate (&argc, &argv);
else if (strcmp (argv[0], "preview") == 0)
do_preview (&argc, &argv);
else if (strcmp (argv[0], "precompile") == 0)
do_precompile (&argc, &argv);
else
usage ();

View File

@@ -2,9 +2,10 @@
#ifndef __GTK_BUILDER_TOOL_H__
#define __GTK_BUILDER_TOOL_H__
void do_simplify (int *argc, const char ***argv);
void do_validate (int *argc, const char ***argv);
void do_enumerate (int *argc, const char ***argv);
void do_preview (int *argc, const char ***argv);
void do_simplify (int *argc, const char ***argv);
void do_validate (int *argc, const char ***argv);
void do_enumerate (int *argc, const char ***argv);
void do_preview (int *argc, const char ***argv);
void do_precompile (int *argc, const char ***argv);
#endif

View File

@@ -28,7 +28,8 @@ gtk_tools = [
'gtk-builder-tool-simplify.c',
'gtk-builder-tool-validate.c',
'gtk-builder-tool-enumerate.c',
'gtk-builder-tool-preview.c'], [libgtk_dep] ],
'gtk-builder-tool-preview.c',
'gtk-builder-tool-precompile.c'], [libgtk_dep] ],
['gtk4-update-icon-cache', ['updateiconcache.c'] + extra_update_icon_cache_objs, [ libgtk_static_dep ] ],
['gtk4-encode-symbolic-svg', ['encodesymbolic.c'], [ libgtk_static_dep ] ],
]