Browse Source

Allow passthrough when message-format is specified

pull/15/head
Ian Chamberlain 3 years ago
parent
commit
935594b309
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 34
      src/main.rs

34
src/main.rs

@ -140,9 +140,25 @@ impl CargoCommand {
let cargo = env::var("CARGO").unwrap_or_else(|_| "cargo".to_string()); let cargo = env::var("CARGO").unwrap_or_else(|_| "cargo".to_string());
let mut command = Command::new(cargo) let has_message_format = self
.arg(&self.command) .args
.iter()
.any(|arg| arg.starts_with("--message-format"));
let mut command = Command::new(cargo);
command.arg(&self.command);
if has_message_format {
// The user presumably cares about the message format, so we should
// print to stdout like usual.
command.stdout(Stdio::inherit())
} else {
command
.stdout(Stdio::piped())
.arg("--message-format=json-render-diagnostics") .arg("--message-format=json-render-diagnostics")
};
let mut command = command
.arg("-Z") .arg("-Z")
.arg("build-std") .arg("build-std")
.arg("--target") .arg("--target")
@ -150,16 +166,22 @@ impl CargoCommand {
.args(&self.args) .args(&self.args)
.env("RUSTFLAGS", rustflags) .env("RUSTFLAGS", rustflags)
.stdin(Stdio::inherit()) .stdin(Stdio::inherit())
.stdout(Stdio::piped())
.stderr(Stdio::inherit()) .stderr(Stdio::inherit())
.spawn() .spawn()
.unwrap(); .unwrap();
let messages = if has_message_format {
// if the user specified message format, we can't parse the messages
// for anything since we wrote them all to stdout.
// TODO: should we exit early in this case? We can't get the
// metadata about the built artifacts or anything in this case.
Vec::new()
} else {
let stdout_reader = std::io::BufReader::new(command.stdout.take().unwrap()); let stdout_reader = std::io::BufReader::new(command.stdout.take().unwrap());
Message::parse_stream(stdout_reader)
let messages = Message::parse_stream(stdout_reader)
.collect::<io::Result<Vec<Message>>>() .collect::<io::Result<Vec<Message>>>()
.unwrap(); .unwrap()
};
(command.wait().unwrap(), messages) (command.wait().unwrap(), messages)
} }

Loading…
Cancel
Save