glib-compile-resources: Add external data option

Add option to not encode resource data into the C source file
in order to embed the data using `ld -b binary`. This improves compilation
times, but can only be done on Linux or other platforms with a
supporting linker.

(Rebased by Philip Withnall, fixing minor rebase conflicts.)

Fixes #1489
This commit is contained in:
Ninja-Koala
2018-09-09 18:31:38 +02:00
committed by Philip Withnall
parent c33a98f42f
commit d04b9c371d
6 changed files with 171 additions and 36 deletions

View File

@@ -558,6 +558,43 @@ test_resource_manual2 (void)
g_resource_unref (resource);
}
/* Test building resources with external data option,
* where data is linked in as binary instead of compiled in.
* Checks if resources are automatically registered and
* data can be found and read. */
static void
test_resource_binary_linked (void)
{
#ifndef __linux__
g_test_skip ("--external-data test only works on Linux");
return;
#else /* if __linux__ */
GError *error = NULL;
gboolean found;
gsize size;
guint32 flags;
GBytes *data;
found = g_resources_get_info ("/binary_linked/test1.txt",
G_RESOURCE_LOOKUP_FLAGS_NONE,
&size, &flags, &error);
g_assert_true (found);
g_assert_no_error (error);
g_assert_cmpint (size, ==, 6);
g_assert_cmpuint (flags, ==, 0);
data = g_resources_lookup_data ("/binary_linked/test1.txt",
G_RESOURCE_LOOKUP_FLAGS_NONE,
&error);
g_assert_nonnull (data);
g_assert_no_error (error);
size = g_bytes_get_size (data);
g_assert_cmpint (size, ==, 6);
g_assert_cmpstr (g_bytes_get_data (data, NULL), ==, "test1\n");
g_bytes_unref (data);
#endif /* if __linux__ */
}
static void
test_resource_module (void)
{
@@ -877,6 +914,7 @@ main (int argc,
g_test_add_func ("/resource/automatic", test_resource_automatic);
/* This only uses automatic resources too, so it tests the constructors and destructors */
g_test_add_func ("/resource/module", test_resource_module);
g_test_add_func ("/resource/binary-linked", test_resource_binary_linked);
#endif
g_test_add_func ("/resource/uri/query-info", test_uri_query_info);
g_test_add_func ("/resource/uri/file", test_uri_file);