From 24faf2ba5f6ac3672aa053f2b07928cd3a38e5f1 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Sat, 28 Oct 2023 16:21:10 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20zx:=20add=20split=20interfaces=20op?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zbus_xmlgen/src/main.rs | 49 ++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/zbus_xmlgen/src/main.rs b/zbus_xmlgen/src/main.rs index 10fb9be9c..3ef91fbf3 100644 --- a/zbus_xmlgen/src/main.rs +++ b/zbus_xmlgen/src/main.rs @@ -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, }; @@ -25,6 +25,7 @@ fn usage() { zbus-xmlgen zbus-xmlgen --system|--session zbus-xmlgen --address
+ zbus-xmlgen --split-interfaces "# ); } @@ -113,20 +114,46 @@ fn main() -> Result<(), Box> { } }; + 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(()) } @@ -134,8 +161,8 @@ fn main() -> Result<(), Box> { fn write_interfaces( interfaces: &[&Interface<'_>], standard_interfaces: &[&Interface<'_>], - service: Option>, - path: Option>, + service: &Option>, + path: &Option>, input_src: &str, ) -> Result> { let mut process = match Command::new("rustfmt")