Skip to content

Commit

Permalink
gtk4-macros: Wait for blueprint-compiler process in all branches
Browse files Browse the repository at this point in the history
Otherwise clippy complains and zombie processes might stay around.

Also make sure to never panic on normal errors for the same reason, and
provide more useful error messages.
  • Loading branch information
sdroege authored and bilelmoussaoui committed Dec 18, 2024
1 parent efa5c1c commit 0dd2564
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions gtk4-macros/src/blueprint.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use std::{
io::{Error, ErrorKind, Result, Write},
io::Write,
process::{Command, Stdio},
};

pub(crate) fn compile_blueprint(blueprint: &[u8]) -> Result<String> {
pub(crate) fn compile_blueprint(blueprint: &[u8]) -> Result<String, String> {
let mut compiler = Command::new("blueprint-compiler")
.args(["compile", "-"])
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.unwrap_or_else(|_| panic!("blueprint-compiler not found"));
.map_err(|e| format!("blueprint-compiler couldn't be spawned: {e}"))?;
let mut stdin = compiler.stdin.take().unwrap();
stdin.write_all(blueprint)?;
if let Err(e) = stdin.write_all(blueprint) {
let _ = compiler.wait();
return Err(format!(
"Couldn't send blueprint to blueprint-compiler: {e}"
));
}
drop(stdin);

let output = compiler
.wait_with_output()
.unwrap_or_else(|e| panic!("blueprint-compiler process failed {e}"));
.map_err(|e| format!("blueprint-compiler process failed: {e}"))?;

let buf = String::from_utf8(output.stdout).unwrap();

if !buf.starts_with('<') {
return Err(Error::new(ErrorKind::Other, buf));
return Err(format!("blueprint-compiler failed: {buf}"));
}

Ok(buf)
Expand Down

0 comments on commit 0dd2564

Please sign in to comment.