After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 783133 - --gresources not support xml files located in a different of directory
--gresources not support xml files located in a different of directory
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator
0.34.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2017-05-26 17:46 UTC by Daniel Espinosa
Modified: 2017-06-07 16:25 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
simple UI test file (966 bytes, application/x-designer)
2017-05-26 17:46 UTC, Daniel Espinosa
  Details
gresources files (147 bytes, text/xml)
2017-05-26 17:47 UTC, Daniel Espinosa
  Details
Source file (184 bytes, text/x-vala)
2017-05-26 17:48 UTC, Daniel Espinosa
  Details
simple UI test file updated (609 bytes, application/x-designer)
2017-05-26 18:48 UTC, Daniel Espinosa
  Details
Source file adding a GtkChild element (210 bytes, text/x-vala)
2017-05-26 18:49 UTC, Daniel Espinosa
  Details
Patch to fix this bug (4.03 KB, patch)
2017-05-26 18:54 UTC, Daniel Espinosa
none Details | Review
compiler: Add --gresourcesdir option (5.04 KB, patch)
2017-06-07 14:28 UTC, Rico Tzschichholz
committed Details | Review
Backported valac's --gresourcesdir switch to 0.34 (4.71 KB, patch)
2017-06-07 15:30 UTC, Daniel Espinosa
none Details | Review

Description Daniel Espinosa 2017-05-26 17:46:45 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>
Comment 1 Daniel Espinosa 2017-05-26 17:47:48 UTC
Created attachment 352659 [details]
gresources files
Comment 2 Daniel Espinosa 2017-05-26 17:48:10 UTC
Created attachment 352660 [details]
Source file
Comment 3 Daniel Espinosa 2017-05-26 18:48:52 UTC
Created attachment 352662 [details]
simple UI test file updated

Set ID to GtkEntry to validate valac is reading correct file
Comment 4 Daniel Espinosa 2017-05-26 18:49:31 UTC
Created attachment 352663 [details]
Source file adding a GtkChild element
Comment 5 Daniel Espinosa 2017-05-26 18:54:09 UTC
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
Comment 6 Al Thomas 2017-05-26 20:58:53 UTC
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;
}
Comment 7 Daniel Espinosa 2017-05-26 21:11:11 UTC
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.
Comment 8 Rico Tzschichholz 2017-06-07 14:28:19 UTC
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 9 Daniel Espinosa 2017-06-07 15:24:52 UTC
Comment on attachment 353336 [details] [review]
compiler: Add --gresourcesdir option

It works for me.

Many thanks.
Comment 10 Daniel Espinosa 2017-06-07 15:30:25 UTC
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.
Comment 11 Rico Tzschichholz 2017-06-07 15:56:23 UTC
@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.
Comment 12 Rico Tzschichholz 2017-06-07 16:25:27 UTC
Attachment 353336 [details] pushed as a667b82 - compiler: Add --gresourcesdir option