From ce7169c9279a30068f15863c720f61b5460417f7 Mon Sep 17 00:00:00 2001 From: Ted Horst Date: Wed, 8 Feb 2012 07:31:17 -0600 Subject: [PATCH 1/4] log to stderr instead of stdout includes rustc diagnostics runtest updated to check stderr for errors --- src/comp/driver/diagnostic.rs | 18 +++++++++--------- src/compiletest/runtest.rs | 4 ++-- src/rt/rust_srv.cpp | 6 +----- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/comp/driver/diagnostic.rs b/src/comp/driver/diagnostic.rs index ebda3956bfd41..427bac77197d5 100644 --- a/src/comp/driver/diagnostic.rs +++ b/src/comp/driver/diagnostic.rs @@ -159,16 +159,16 @@ fn diagnosticcolor(lvl: level) -> u8 { fn print_diagnostic(topic: str, lvl: level, msg: str) { if str::is_not_empty(topic) { - io::stdout().write_str(#fmt["%s ", topic]); + io::stderr().write_str(#fmt["%s ", topic]); } if term::color_supported() { - term::fg(io::stdout(), diagnosticcolor(lvl)); + term::fg(io::stderr(), diagnosticcolor(lvl)); } - io::stdout().write_str(#fmt["%s:", diagnosticstr(lvl)]); + io::stderr().write_str(#fmt["%s:", diagnosticstr(lvl)]); if term::color_supported() { - term::reset(io::stdout()); + term::reset(io::stderr()); } - io::stdout().write_str(#fmt[" %s\n", msg]); + io::stderr().write_str(#fmt[" %s\n", msg]); } fn emit(cmsp: option<(codemap::codemap, span)>, @@ -202,10 +202,10 @@ fn highlight_lines(cm: codemap::codemap, sp: span, } // Print the offending lines for line: uint in display_lines { - io::stdout().write_str(#fmt["%s:%u ", fm.name, line + 1u]); + io::stderr().write_str(#fmt["%s:%u ", fm.name, line + 1u]); let s = codemap::get_line(fm, line as int); if !str::ends_with(s, "\n") { s += "\n"; } - io::stdout().write_str(s); + io::stderr().write_str(s); } if elided { let last_line = display_lines[vec::len(display_lines) - 1u]; @@ -214,7 +214,7 @@ fn highlight_lines(cm: codemap::codemap, sp: span, let out = ""; while indent > 0u { out += " "; indent -= 1u; } out += "...\n"; - io::stdout().write_str(out); + io::stderr().write_str(out); } @@ -239,7 +239,7 @@ fn highlight_lines(cm: codemap::codemap, sp: span, let width = hi.col - lo.col - 1u; while width > 0u { str::push_char(s, '~'); width -= 1u; } } - io::stdout().write_str(s + "\n"); + io::stderr().write_str(s + "\n"); } } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 68b821bc1c94f..cf5a57c60defd 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -198,7 +198,7 @@ fn check_error_patterns(props: test_props, let next_err_idx = 0u; let next_err_pat = props.error_patterns[next_err_idx]; - for line: str in str::split_byte(procres.stdout, '\n' as u8) { + for line: str in str::split_byte(procres.stderr, '\n' as u8) { if str::find(line, next_err_pat) > 0 { #debug("found error pattern %s", next_err_pat); next_err_idx += 1u; @@ -245,7 +245,7 @@ fn check_expected_errors(expected_errors: [errors::expected_error], // filename:line1:col1: line2:col2: *warning:* msg // where line1:col1: is the starting point, line2:col2: // is the ending point, and * represents ANSI color codes. - for line: str in str::split_byte(procres.stdout, '\n' as u8) { + for line: str in str::split_byte(procres.stderr, '\n' as u8) { let was_expected = false; vec::iteri(expected_errors) {|i, ee| if !found_flags[i] { diff --git a/src/rt/rust_srv.cpp b/src/rt/rust_srv.cpp index 758174a4ebb11..9192af511d953 100644 --- a/src/rt/rust_srv.cpp +++ b/src/rt/rust_srv.cpp @@ -25,11 +25,7 @@ rust_srv::realloc(void *p, size_t bytes) { void rust_srv::log(char const *msg) { - printf("rust: %s\n", msg); - // FIXME: flushing each time is expensive, but at the moment - // necessary to get output through before a rust_task::fail - // call. This should be changed. - fflush(stdout); + fprintf(stderr, "rust: %s\n", msg); } void From 79c11b9b788a7c5c241881067c58ffcda9f25de2 Mon Sep 17 00:00:00 2001 From: Ted Horst Date: Wed, 8 Feb 2012 07:35:53 -0600 Subject: [PATCH 2/4] read stderr before stdout tests all write to stderr, so read stderr first to keep from blocking while reading stdout --- src/compiletest/procsrv.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiletest/procsrv.rs b/src/compiletest/procsrv.rs index e82ef76b3a315..28bbcd86d06f9 100644 --- a/src/compiletest/procsrv.rs +++ b/src/compiletest/procsrv.rs @@ -52,8 +52,8 @@ fn run(lib_path: str, prog: str, args: [str], writeclose(pipe_in.out, input); - let output = readclose(pipe_out.in); let errput = readclose(pipe_err.in); + let output = readclose(pipe_out.in); let status = run::waitpid(pid); ret {status: status, out: output, err: errput}; } From c5ba001dbb8384cfaf84f7e5ba75bed42cfbb307 Mon Sep 17 00:00:00 2001 From: Ted Horst Date: Thu, 9 Feb 2012 19:43:26 -0600 Subject: [PATCH 3/4] put fflush back in --- src/rt/rust_srv.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rt/rust_srv.cpp b/src/rt/rust_srv.cpp index 9192af511d953..3efac3b391097 100644 --- a/src/rt/rust_srv.cpp +++ b/src/rt/rust_srv.cpp @@ -26,6 +26,10 @@ rust_srv::realloc(void *p, size_t bytes) { void rust_srv::log(char const *msg) { fprintf(stderr, "rust: %s\n", msg); + // FIXME: flushing each time is expensive, but at the moment + // necessary to get output through before a rust_task::fail + // call. This should be changed. + fflush(stderr); } void From 61b7604e61446b814196e0bdf689d9f92084d3dc Mon Sep 17 00:00:00 2001 From: Ted Horst Date: Fri, 10 Feb 2012 10:03:34 -0600 Subject: [PATCH 4/4] use task::spawn_sched to read stdout and stderr at the same time Hopefully this addresses the root cause of the hangs when running make check on windows. --- src/compiletest/procsrv.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/compiletest/procsrv.rs b/src/compiletest/procsrv.rs index 28bbcd86d06f9..9304e359321d5 100644 --- a/src/compiletest/procsrv.rs +++ b/src/compiletest/procsrv.rs @@ -52,10 +52,33 @@ fn run(lib_path: str, prog: str, args: [str], writeclose(pipe_in.out, input); - let errput = readclose(pipe_err.in); - let output = readclose(pipe_out.in); + let p = comm::port(); + let ch = comm::chan(p); + task::spawn_sched(1u) {|| + let errput = readclose(pipe_err.in); + comm::send(ch, (2, errput)); + }; + task::spawn_sched(1u) {|| + let output = readclose(pipe_out.in); + comm::send(ch, (1, output)); + }; let status = run::waitpid(pid); - ret {status: status, out: output, err: errput}; + let errs = ""; + let outs = ""; + let count = 2; + while count > 0 { + let stream = comm::recv(p); + alt stream { + (1, s) { + outs = s; + } + (2, s) { + errs = s; + } + }; + count -= 1; + }; + ret {status: status, out: outs, err: errs}; } fn writeclose(fd: fd_t, s: option) {