Skip to content

Instantly share code, notes, and snippets.

@eddyb

eddyb/errfilt.rs Secret

Last active February 24, 2020 16:11
Show Gist options
  • Save eddyb/a6f1176f265105105bbecbf4680a3a10 to your computer and use it in GitHub Desktop.
Save eddyb/a6f1176f265105105bbecbf4680a3a10 to your computer and use it in GitHub Desktop.
use std::io;
use std::io::prelude::*;
fn main() {
let stdin = io::stdin();
let mut stderr = io::stderr();
let mut last_message = String::new();
let mut last_loc = String::new();
for line in stdin.lock().lines() {
let line = line.unwrap();
let trimmed = line.trim();
if trimmed.starts_with("Finished ") {
continue;
}
let message = std::mem::replace(&mut last_message, String::new());
let loc_prefix = "--> ";
if trimmed.starts_with(loc_prefix) {
last_loc = trimmed[loc_prefix.len()..].to_string();
if !message.is_empty() {
writeln!(stderr, "{}: {}", last_loc, message).unwrap();
}
continue;
}
if !message.is_empty() {
writeln!(stderr, "{}", message).unwrap();
}
if line.starts_with("error") || line.starts_with("warn") {
let after = line.trim_left_matches(char::is_alphabetic);
if after.starts_with("[") || after.starts_with(":") {
last_message.push_str(&line);
continue;
}
}
// Empty line, reset location.
if line.is_empty() {
last_loc.clear();
}
// Source snippet.
if trimmed.starts_with(|c: char| c.is_digit(10)) {
continue;
}
// Weird thing in a source snippet.
if trimmed.starts_with("::: ") {
continue;
}
// Empty line.
if trimmed == "|" {
continue;
}
// Extra messages.
if line.starts_with(" ") && !last_loc.is_empty() {
let message = trimmed.trim_left_matches(&[' ', '|', '=', '_', '-', '^'][..]);
if !message.is_empty() {
writeln!(stderr, "{}: {}", last_loc, message).unwrap();
}
continue;
}
writeln!(stderr, "{}", line).unwrap();
}
}
@eddyb
Copy link
Author

eddyb commented Aug 26, 2017

Used with:

# git push build -qf $((git stash create; echo HEAD) | head -n1):build &&
# ssh spock.edef.eu "
# nix-shell -p python27 cmake ninja gdb file clang_39 --run '
cd /home/eddy/Projects/rust-2 &&
git checkout -q --detach build &&
env SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt hardeningDisable=all ./x.py test --stage 0 src/tools/tidy 2> >(errfilt) | grep -v '^\\*' &&
env SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt hardeningDisable=all ./x.py build --stage 1 src/tools/rustdoc 2> >(errfilt) &&
env SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt hardeningDisable=all ./x.py test --stage 1 src/test/{codegen,codegen-units,incremental,mir-opt,debuginfo,parse-fail,ui,compile-fail,run-fail,run-pass} 2> >(errfilt)
# '
# "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment