aboutsummaryrefslogtreecommitdiff
path: root/test cases/frameworks
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2016-09-17 13:23:45 +0100
committerSam Thursfield <ssssam@gmail.com>2016-10-13 21:18:14 +0100
commit25f13067c2aae06748654b9a48869c0da17ea07d (patch)
tree83e010b5a9645b35f649c2c863586fe8e7b3ab10 /test cases/frameworks
parentc1d2b65c7328fcfcea8a4b985af4410002035e33 (diff)
downloadmeson-25f13067c2aae06748654b9a48869c0da17ea07d.zip
meson-25f13067c2aae06748654b9a48869c0da17ea07d.tar.gz
meson-25f13067c2aae06748654b9a48869c0da17ea07d.tar.bz2
gnome: allow use of generated files with compile_resources()
This commit adds a 'dependencies' keyword to the gnome.compile_resources() function, which allows your resource blob to depend on files generated at build-time from custom_target() or configure_file() targets. My current use case for this is source data that gets processed with Gettext translation tools before being compiled into the resource blob. This feature only works with GLib version 2.48.2 and above. So the compile_resources() function now detects GLib version and raises an error if the version of GLib being used is too old. The compile_resources() test case is now split into two, so that the existing one can continue to run on systems with old GLib versions (such as Ubuntu Xenial, which the automated tests on travisci.org use), but where new enough GLib is available we also test generating gresource content. The existing warning about glib-compile-resources is now only printed if GLib version is older than 2.50.0 because <https://bugzilla.gnome.org/show_bug.cgi?id=745754> is fixed in the 2.50.0 release.
Diffstat (limited to 'test cases/frameworks')
-rw-r--r--test cases/frameworks/7 gnome/meson.build1
-rw-r--r--test cases/frameworks/7 gnome/resources-data/meson.build16
-rw-r--r--test cases/frameworks/7 gnome/resources-data/res1.txt (renamed from test cases/frameworks/7 gnome/resources/data/res1.txt)0
-rw-r--r--test cases/frameworks/7 gnome/resources-data/res3.txt.in1
-rw-r--r--test cases/frameworks/7 gnome/resources-data/subdir/meson.build8
-rw-r--r--test cases/frameworks/7 gnome/resources-data/subdir/res2.txt1
-rw-r--r--test cases/frameworks/7 gnome/resources-data/subdir/res4.txt.in1
-rw-r--r--test cases/frameworks/7 gnome/resources/generated-main.c27
-rw-r--r--test cases/frameworks/7 gnome/resources/generated.gresource.xml9
-rw-r--r--test cases/frameworks/7 gnome/resources/meson.build34
-rw-r--r--test cases/frameworks/7 gnome/resources/myresource.gresource.xml3
-rw-r--r--test cases/frameworks/7 gnome/resources/simple-main.c (renamed from test cases/frameworks/7 gnome/resources/main.c)4
-rw-r--r--test cases/frameworks/7 gnome/resources/simple.gresource.xml7
13 files changed, 104 insertions, 8 deletions
diff --git a/test cases/frameworks/7 gnome/meson.build b/test cases/frameworks/7 gnome/meson.build
index 2c2e953..a771e71 100644
--- a/test cases/frameworks/7 gnome/meson.build
+++ b/test cases/frameworks/7 gnome/meson.build
@@ -9,6 +9,7 @@ gir = dependency('gobject-introspection-1.0')
gmod = dependency('gmodule-2.0')
add_global_arguments('-DMESON_TEST', language : 'c')
+subdir('resources-data')
subdir('resources')
subdir('gir')
subdir('schemas')
diff --git a/test cases/frameworks/7 gnome/resources-data/meson.build b/test cases/frameworks/7 gnome/resources-data/meson.build
new file mode 100644
index 0000000..6343c0e
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources-data/meson.build
@@ -0,0 +1,16 @@
+subdir('subdir')
+
+fake_generator_script = '''
+import os, sys
+assert os.path.exists(sys.argv[1]), "File %s not found" % sys.argv[1]
+print("This is a generated resource")
+'''
+
+# Generate file res3.txt from file res3.txt.in. This is then included
+# in a GResource file, driven by resources/meson.build.
+res3_txt = custom_target('res3.txt',
+ input: 'res3.txt.in',
+ output: 'res3.txt',
+ command: ['python3', '-c', fake_generator_script, '@INPUT@'],
+ capture: true,
+)
diff --git a/test cases/frameworks/7 gnome/resources/data/res1.txt b/test cases/frameworks/7 gnome/resources-data/res1.txt
index e10afea..e10afea 100644
--- a/test cases/frameworks/7 gnome/resources/data/res1.txt
+++ b/test cases/frameworks/7 gnome/resources-data/res1.txt
diff --git a/test cases/frameworks/7 gnome/resources-data/res3.txt.in b/test cases/frameworks/7 gnome/resources-data/res3.txt.in
new file mode 100644
index 0000000..077a8e3
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources-data/res3.txt.in
@@ -0,0 +1 @@
+This content is ignored, but Meson doesn't need to know that.
diff --git a/test cases/frameworks/7 gnome/resources-data/subdir/meson.build b/test cases/frameworks/7 gnome/resources-data/subdir/meson.build
new file mode 100644
index 0000000..b41300f
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources-data/subdir/meson.build
@@ -0,0 +1,8 @@
+cdata = configuration_data()
+cdata.set('NOISE', 'BARK')
+
+res4_txt = configure_file(
+ input: 'res4.txt.in',
+ output: 'res4.txt',
+ configuration: cdata
+)
diff --git a/test cases/frameworks/7 gnome/resources-data/subdir/res2.txt b/test cases/frameworks/7 gnome/resources-data/subdir/res2.txt
new file mode 100644
index 0000000..d297899
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources-data/subdir/res2.txt
@@ -0,0 +1 @@
+This is a resource in a subdirectory.
diff --git a/test cases/frameworks/7 gnome/resources-data/subdir/res4.txt.in b/test cases/frameworks/7 gnome/resources-data/subdir/res4.txt.in
new file mode 100644
index 0000000..c0ec6f2
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources-data/subdir/res4.txt.in
@@ -0,0 +1 @@
+@NOISE@ @NOISE@ @NOISE@
diff --git a/test cases/frameworks/7 gnome/resources/generated-main.c b/test cases/frameworks/7 gnome/resources/generated-main.c
new file mode 100644
index 0000000..fc9efbd
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources/generated-main.c
@@ -0,0 +1,27 @@
+#include<stdio.h>
+#include<string.h>
+#include<gio/gio.h>
+#include"generated-resources.h"
+
+#define EXPECTED "This is a generated resource.\n"
+
+int main(int argc, char **argv) {
+ GResource *res = generated_resources_get_resource();
+ GError *err = NULL;
+ GBytes *data = g_resources_lookup_data("/com/example/myprog/res3.txt",
+ G_RESOURCE_LOOKUP_FLAGS_NONE, &err);
+
+ if(data == NULL) {
+ fprintf(stderr, "Data lookup failed: %s\n", err->message);
+ return 1;
+ }
+ if(strcmp(g_bytes_get_data(data, NULL), EXPECTED) != 0) {
+ fprintf(stderr, "Resource contents are wrong:\n %s\n",
+ (const char*)g_bytes_get_data(data, NULL));
+ return 1;
+ }
+ fprintf(stdout, "All ok.\n");
+ g_bytes_unref(data);
+ g_resource_unref(res);
+ return 0;
+}
diff --git a/test cases/frameworks/7 gnome/resources/generated.gresource.xml b/test cases/frameworks/7 gnome/resources/generated.gresource.xml
new file mode 100644
index 0000000..7a242d7
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources/generated.gresource.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/com/example/myprog">
+ <file>res1.txt</file>
+ <file>subdir/res2.txt</file>
+ <file>res3.txt</file>
+ <file>subdir/res4.txt</file>
+ </gresource>
+</gresources>
diff --git a/test cases/frameworks/7 gnome/resources/meson.build b/test cases/frameworks/7 gnome/resources/meson.build
index 937dc47..5762a8c 100644
--- a/test cases/frameworks/7 gnome/resources/meson.build
+++ b/test cases/frameworks/7 gnome/resources/meson.build
@@ -1,7 +1,29 @@
-myres = gnome.compile_resources('myresources', 'myresource.gresource.xml',
-source_dir : 'data',
-c_name : 'myres')
+# There are two tests here, because the 2nd one depends on a version of
+# GLib (2.48.2) that is very recent at the time of writing.
-resexe = executable('resprog', 'main.c', myres,
-dependencies : gio)
-test('resource test', resexe)
+simple_resources = gnome.compile_resources('simple-resources',
+ 'simple.gresource.xml',
+ source_dir : '../resources-data',
+ c_name : 'simple_resources')
+
+simple_res_exe = executable('simple-resources-test',
+ 'simple-main.c', simple_resources,
+ dependencies: gio)
+test('simple resource test', simple_res_exe)
+
+if glib.version() >= '2.48.2'
+ # This test cannot pass if GLib version is older than 2.48.2.
+ # Meson will raise an error if the user tries to use the 'dependencies'
+ # argument and the version of GLib is too old for generated resource
+ # dependencies to work correctly.
+ generated_resources = gnome.compile_resources('generated-resources',
+ 'generated.gresource.xml',
+ source_dir : '../resources-data',
+ c_name : 'generated_resources',
+ dependencies : [res3_txt, res4_txt])
+
+ generated_res_exe = executable('generated-resources-test',
+ 'generated-main.c', generated_resources,
+ dependencies: gio)
+ test('generated resource test', generated_res_exe)
+endif
diff --git a/test cases/frameworks/7 gnome/resources/myresource.gresource.xml b/test cases/frameworks/7 gnome/resources/myresource.gresource.xml
index b44c879..7a242d7 100644
--- a/test cases/frameworks/7 gnome/resources/myresource.gresource.xml
+++ b/test cases/frameworks/7 gnome/resources/myresource.gresource.xml
@@ -2,5 +2,8 @@
<gresources>
<gresource prefix="/com/example/myprog">
<file>res1.txt</file>
+ <file>subdir/res2.txt</file>
+ <file>res3.txt</file>
+ <file>subdir/res4.txt</file>
</gresource>
</gresources>
diff --git a/test cases/frameworks/7 gnome/resources/main.c b/test cases/frameworks/7 gnome/resources/simple-main.c
index b765468..3569901 100644
--- a/test cases/frameworks/7 gnome/resources/main.c
+++ b/test cases/frameworks/7 gnome/resources/simple-main.c
@@ -1,12 +1,12 @@
#include<stdio.h>
#include<string.h>
#include<gio/gio.h>
-#include"myresources.h"
+#include"simple-resources.h"
#define EXPECTED "This is a resource.\n"
int main(int argc, char **argv) {
- GResource *res = myres_get_resource();
+ GResource *res = simple_resources_get_resource();
GError *err = NULL;
GBytes *data = g_resources_lookup_data("/com/example/myprog/res1.txt",
G_RESOURCE_LOOKUP_FLAGS_NONE, &err);
diff --git a/test cases/frameworks/7 gnome/resources/simple.gresource.xml b/test cases/frameworks/7 gnome/resources/simple.gresource.xml
new file mode 100644
index 0000000..6e55910
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources/simple.gresource.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/com/example/myprog">
+ <file>res1.txt</file>
+ <file>subdir/res2.txt</file>
+ </gresource>
+</gresources>