Skip to content

Commit

Permalink
✨ zx: add split interfaces option
Browse files Browse the repository at this point in the history
  • Loading branch information
FineFindus committed Oct 28, 2023
1 parent e208136 commit 24faf2b
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions zbus_xmlgen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
fs::File,
io::{Read, Write},
path::Path,
process::{Child, ChildStdin, ChildStdout, Command, Stdio},
process::{ChildStdin, Command, Stdio},
result::Result,
};

Expand All @@ -25,6 +25,7 @@ fn usage() {
zbus-xmlgen <interface.xml>
zbus-xmlgen --system|--session <service> <object_path>
zbus-xmlgen --address <address> <service> <object_path>
zbus-xmlgen <interface> --split-interfaces
"#
);
}
Expand Down Expand Up @@ -113,29 +114,55 @@ fn main() -> Result<(), Box<dyn Error>> {
}
};

let split_interfaces = args().any(|arg| arg == "--split-interfaces");

let fdo_iface_prefix = "org.freedesktop.DBus";
let (fdo_standard_ifaces, needed_ifaces): (Vec<&Interface<'_>>, Vec<&Interface<'_>>) = node
.interfaces()
.iter()
.partition(|&i| i.name().starts_with(fdo_iface_prefix));

let output = write_interfaces(
&needed_ifaces,
&fdo_standard_ifaces,
service,
path,
&input_src,
)?;
println!("{}", output);
if !split_interfaces {
let output = write_interfaces(
&needed_ifaces,
&fdo_standard_ifaces,
&service,
&path,
&input_src,
)?;
println!("{}", output);
return Ok(());
}

for interface in needed_ifaces {
let output = write_interfaces(
&[&interface],
&fdo_standard_ifaces,
&service,
&path,
&input_src,
)?;
std::fs::write(
format!(
"{}.rs",
interface
.name()
.split('.')
.last()
.expect("Failed to split name")
),
output,
)?;
}

Ok(())
}

fn write_interfaces(
interfaces: &[&Interface<'_>],
standard_interfaces: &[&Interface<'_>],
service: Option<BusName<'_>>,
path: Option<ObjectPath<'_>>,
service: &Option<BusName<'_>>,
path: &Option<ObjectPath<'_>>,
input_src: &str,
) -> Result<String, Box<dyn Error>> {
let mut process = match Command::new("rustfmt")
Expand Down

0 comments on commit 24faf2b

Please sign in to comment.