dbus2 / zbus-old

Rust D-Bus crate.
https://gitlab.freedesktop.org/dbus/zbus
Other
49 stars 13 forks source link

xmlgen fails to generate rust code for Suse Snapper #182

Closed zeenix closed 1 year ago

zeenix commented 3 years ago

In GitLab by @legezam on Jun 30, 2021, 13:42

I am trying to generate Rust code for Suse's snapper tool:

> busctl --xml-interface introspect org.opensuse.Snapper /org/opensuse/Snapper > snapper.xml
> zbus-xmlgen snapper.xml

Getting many errors like:

error: expected one of `:` or `@`, found `-`
  --> <stdin>:26:42
   |
26 |     fn calculate_used_space(&self, config-name: &str) -> zbus::Result<()>;
   |                                          ^ expected one of `:` or `@`

error: expected one of `:` or `@`, found `-`
  --> <stdin>:29:39
   |
29 |     fn create_comparison(&self, config-name: &str, number1: u32, number2: u32) -> zbus::Result<u32>;
   |                                       ^ expected one of `:` or `@`

error: expected one of `:` or `@`, found `-`
  --> <stdin>:32:35
   |
32 |     fn create_config(&self, config-name: &str, subvolume: &str, fstype: &str, template-name: &str) -> zbus::Result<()>;
   |                                   ^ expected one of `:` or `@`

error: expected one of `:` or `@`, found `-`
  --> <stdin>:32:87
   |
32 |     fn create_config(&self, config-name: &str, subvolume: &str, fstype: &str, template-name: &str) -> zbus::Result<()>;
   |                                                                                       ^ expected one of `:` or `@`

error: expected one of `:` or `@`, found `-`
  --> <stdin>:35:42
   |
35 |     fn create_post_snapshot(&self, config-name: &str, pre-number: u32, description: &str, cleanup: &str, userdata: std::collections::HashMap<&str, &str>) -> zbus::Result<u32>;
   |                                          ^ expected one of `:` or `@`

error: expected one of `:` or `@`, found `-`
  --> <stdin>:35:58
   |
35 |     fn create_post_snapshot(&self, config-name: &str, pre-number: u32, description: &str, cleanup: &str, userdata: std::collections::HashMap<&str, &str>) -> zbus::Result<u32>;
   |                                                          ^ expected one of `:` or `@`

error: expected one of `:` or `@`, found `-`
  --> <stdin>:38:41
   |
38 |     fn create_pre_snapshot(&self, config-name: &str, description: &str, cleanup: &str, userdata: std::collections::HashMap<&str, &str>) -> zbus::Result<u32>;
   |                                         ^ expected one of `:` or `@`

<the rest are omitted but very similar>

Please note, this happens even when i try to use the xml generated by zbus-xmlgen.

To reproduce the issue all you need is to have snapper installed through any package manager.

Please help me, i can give any further help if needed.

zeenix commented 3 years ago

oh wow! this service in question uses - in the names of method arguments. That's very strange and I didn't realize it was even allowed. So obviously the issue here is that our tool doesn't anticipate that and uses the provided name as is, which of course doesn't work in Rust.

Should be pretty easy fix though but the workaround is also pretty easy: change config-name to config_name and it would just work.

Please also note that currently xmlgen tool is meant only to give you a starting point. In most cases, you'll need to adjust/fix the generated code. However, that is not to say that we don't appreciate such reports so please do report any other issues you find. Fixing all these issues will lead us to the day when we can confidently say xmlgen should be expected to generated readily usable code. :)

zeenix commented 3 years ago

In GitLab by @legezam on Jun 30, 2021, 14:39

Cool! Thanks for the suggestion!

zeenix commented 3 years ago

but the workaround is also pretty easy: change config-name to config_name and it would just work.

Oh sorry. That's not actually true. The error is from xmlgen itself, not when compiling the generated code. So the workaround is to modify the source xml instead.

zeenix commented 3 years ago

mentioned in commit zeenix/zbus@86e325e29ffac7e95b0fdda20cc046834aaaa57d

zeenix commented 3 years ago

In GitLab by @elmarco on Jun 30, 2021, 16:00

mentioned in commit 77785833b96eca9be4ede7a94b1b96d10f33e6f5