GNOME Bugzilla – Bug 783133
--gresources not support xml files located in a different of directory
Last modified: 2017-06-07 16:25:32 UTC
Created attachment 352658 [details] simple UI test file Supouse you have a resource.xml located in a directory and your files are located in a different directory, Vala can't find resources files referenced by resource.xml file, because no path to them exists. Then, for the test case: a) Put xml file in a different directory than your UI files b) Try to compile valac --pkg gtk+-3.0 --gresources xml/template.xml template-test.vala This will fail with the following message: template-test.vala:4.1-4.26: error: UI resource not found: `/org/gnome/vala/mygrid.ui'. Please make sure to specify the proper GResources xml files with --gresources. So, may a switch to add a directory to search resources files from will help. Test case: Vala code: using Gtk; [GtkTemplate (ui="/org/gnome/vala/mygrid.ui")] public class MyGrid : Grid {} public class Test : Object { public static void main () { var w = new MyGrid (); } } Resource file: <?xml version="1.0" encoding="UTF-8"?> <gresources> <gresource prefix="/org/gnome/vala"> <file>mygrid.ui</file> </gresource> </gresources> UI file: <?xml version="1.0" encoding="UTF-8"?> <!-- Generated with glade 3.20.0 --> <interface> <requires lib="gtk+" version="3.20"/> <template class="MyGrid" parent="GtkGrid"> <property name="visible">True</property> <property name="can_focus">False</property> <child> <object class="GtkEntry"> <property name="visible">True</property> <property name="can_focus">True</property> </object> <packing> <property name="left_attach">0</property> <property name="top_attach">0</property> </packing> </child> <child> <placeholder/> </child> <child> <placeholder/> </child> <child> <placeholder/> </child> <child> <placeholder/> </child> <child> <placeholder/> </child> <child> <placeholder/> </child> <child> <placeholder/> </child> <child> <placeholder/> </child> </template> </interface>
Created attachment 352659 [details] gresources files
Created attachment 352660 [details] Source file
Created attachment 352662 [details] simple UI test file updated Set ID to GtkEntry to validate valac is reading correct file
Created attachment 352663 [details] Source file adding a GtkChild element
Created attachment 352664 [details] [review] Patch to fix this bug This patch adds a new switch --gresources-dir, this makes valac to search UI files referenced in gresource in specific directory. This is important if consider that you can generated gresource file in a build directory, different of UI files source directory, so you need stablish where to locate them. New gresource XML file generator is located at: https://gitlab.com/esodan/gresg
You can have files in a sub-directory of the GResource XML file directory, but you need to include the sub-directory in both the GResource XML file and the Vala template identifier. So for a directory structure such as: ├── resources │ ├── template.xml │ └── ui │ └── mygrid.ui └── template-test.vala Your GResource XML file would be: <?xml version="1.0" encoding="UTF-8"?> <gresources> <gresource prefix="/org/gnome/vala"> <file>ui/mygrid.ui</file> </gresource> </gresources> and your Vala GtkTemplate attribute should be: [GtkTemplate (ui="/org/gnome/vala/ui/mygrid.ui")] public class MyGrid : Grid { [GtkChild] public Gtk.Entry entry; }
For my UI project I'm using Meson and I've created a tool to generate XML resources automatically. So all builds are out of source tree and resources XML is generated each time you add a new file. GLib compiler have an option to generate C/H files you should use as sources, so out of tree compilations requires to know where your resources are located (resources/ in your example). Because of this out of tree build, valac requires a setting to find UI files, they are no longer in a subdirectora of resources.xml I've tested locally and now when I add a file in meson.build, a new XML is created a --gresources-dir switch is used for valac so it can find UI files referenced in XML.
Created attachment 353336 [details] [review] compiler: Add --gresourcesdir option In case a gresources.xml is located in a different directory than its corresponding resources, --gresourcesdir will add additional search locations for UI files of Gtk+ templates.
Comment on attachment 353336 [details] [review] compiler: Add --gresourcesdir option It works for me. Many thanks.
Created attachment 353342 [details] [review] Backported valac's --gresourcesdir switch to 0.34 This patch back ports Rico's patch to 0.34 branch, because it will be included in Debian stable.
@daniel: You don't have to attach a backport patch here, a simple request to include it in 0.34.9/0.36.4 is sufficient. FYI, https://tracker.debian.org/pkg/vala and 0.34.8 is available quite some time. So feel free to file a request to have it actually picked up in Debian.
Attachment 353336 [details] pushed as a667b82 - compiler: Add --gresourcesdir option