Skip to content

Commit

Permalink
fix(cli): duplicated newlines on child process output (#8042)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Oct 18, 2023
1 parent 94bef1c commit be8e5aa
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 29 deletions.
7 changes: 7 additions & 0 deletions .changes/fix-cmd-output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@tauri-apps/cli": patch:bug
"tauri-cli": patch:bug
"tauri-bundler": patch:bug
---

Fixes duplicated newlines on command outputs.
2 changes: 1 addition & 1 deletion examples/api/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 11 additions & 13 deletions tooling/bundler/src/bundle/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use log::debug;
use std::{
ffi::OsStr,
fs::{self, File},
io::{self, BufReader, BufWriter},
io::{self, BufRead, BufReader, BufWriter},
path::Path,
process::{Command, ExitStatus, Output, Stdio},
sync::{Arc, Mutex},
Expand Down Expand Up @@ -165,33 +165,31 @@ impl CommandExt for Command {
let stdout_lines = Arc::new(Mutex::new(Vec::new()));
let stdout_lines_ = stdout_lines.clone();
std::thread::spawn(move || {
let mut buf = Vec::new();
let mut line = String::new();
let mut lines = stdout_lines_.lock().unwrap();
loop {
buf.clear();
if let Ok(0) = tauri_utils::io::read_line(&mut stdout, &mut buf) {
line.clear();
if let Ok(0) = stdout.read_line(&mut line) {
break;
}
debug!(action = "stdout"; "{}", String::from_utf8_lossy(&buf));
lines.extend(buf.clone());
lines.push(b'\n');
debug!(action = "stdout"; "{}", &line[0..line.len() - 1]);
lines.extend(line.as_bytes().to_vec());
}
});

let mut stderr = child.stderr.take().map(BufReader::new).unwrap();
let stderr_lines = Arc::new(Mutex::new(Vec::new()));
let stderr_lines_ = stderr_lines.clone();
std::thread::spawn(move || {
let mut buf = Vec::new();
let mut line = String::new();
let mut lines = stderr_lines_.lock().unwrap();
loop {
buf.clear();
if let Ok(0) = tauri_utils::io::read_line(&mut stderr, &mut buf) {
line.clear();
if let Ok(0) = stderr.read_line(&mut line) {
break;
}
debug!(action = "stderr"; "{}", String::from_utf8_lossy(&buf));
lines.extend(buf.clone());
lines.push(b'\n');
debug!(action = "stderr"; "{}", &line[0..line.len() - 1]);
lines.extend(line.as_bytes().to_vec());
}
});

Expand Down
3 changes: 0 additions & 3 deletions tooling/cli/src/interface/rust/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@ fn build_dev_app<F: FnOnce(ExitStatus, ExitReason) + Send + 'static>(
break;
}
let _ = io_stderr.write_all(&buf);
if !buf.ends_with(&[b'\r']) {
let _ = io_stderr.write_all(b"\n");
}
lines.push(String::from_utf8_lossy(&buf).into_owned());
}
});
Expand Down
23 changes: 11 additions & 12 deletions tooling/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::io::{BufReader, Write};
use std::process::{exit, Command, ExitStatus, Output, Stdio};
use std::{
ffi::OsString,
io::BufRead,
sync::{Arc, Mutex},
};

Expand Down Expand Up @@ -226,33 +227,31 @@ impl CommandExt for Command {
let stdout_lines = Arc::new(Mutex::new(Vec::new()));
let stdout_lines_ = stdout_lines.clone();
std::thread::spawn(move || {
let mut buf = Vec::new();
let mut line = String::new();
let mut lines = stdout_lines_.lock().unwrap();
loop {
buf.clear();
if let Ok(0) = tauri_utils::io::read_line(&mut stdout, &mut buf) {
line.clear();
if let Ok(0) = stdout.read_line(&mut line) {
break;
}
debug!(action = "stdout"; "{}", String::from_utf8_lossy(&buf));
lines.extend(buf.clone());
lines.push(b'\n');
debug!(action = "stdout"; "{}", &line[0..line.len() - 1]);
lines.extend(line.as_bytes().to_vec());
}
});

let mut stderr = child.stderr.take().map(BufReader::new).unwrap();
let stderr_lines = Arc::new(Mutex::new(Vec::new()));
let stderr_lines_ = stderr_lines.clone();
std::thread::spawn(move || {
let mut buf = Vec::new();
let mut line = String::new();
let mut lines = stderr_lines_.lock().unwrap();
loop {
buf.clear();
if let Ok(0) = tauri_utils::io::read_line(&mut stderr, &mut buf) {
line.clear();
if let Ok(0) = stderr.read_line(&mut line) {
break;
}
debug!(action = "stderr"; "{}", String::from_utf8_lossy(&buf));
lines.extend(buf.clone());
lines.push(b'\n');
debug!(action = "stderr"; "{}", &line[0..line.len() - 1]);
lines.extend(line.as_bytes().to_vec());
}
});

Expand Down

0 comments on commit be8e5aa

Please sign in to comment.