diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2019-04-15 08:26:08 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2019-04-30 08:51:57 +1000 |
| commit | 7bcb0cffb61d5e1e4fbe08a51d92883556daed04 (patch) | |
| tree | 5967374e659ac96d365d8d3b381af68ccea38d53 /src/tools/compiletest | |
| parent | 91d5b764ea1e717641b146d5c3169058a18f3919 (diff) | |
| download | rust-7bcb0cffb61d5e1e4fbe08a51d92883556daed04.tar.gz rust-7bcb0cffb61d5e1e4fbe08a51d92883556daed04.zip | |
In JSON output, emit a directive after metadata is generated.
To implement pipelining, Cargo needs to know when metadata generation is
finished. This commit adds code to do that. Unfortunately, metadata file
writing currently occurs very late during compilation, so pipelining
won't produce a speed-up. Moving metadata file writing earlier will be a
follow-up.
The change involves splitting the existing `Emitter::emit` method in
two: `Emitter::emit_diagnostic` and `Emitter::emit_directive`.
The JSON directives look like this:
```
{"directive":"metadata file written: liba.rmeta"}
```
The functionality is behind the `-Z emit-directives` option, and also
requires `--error-format=json`.
Diffstat (limited to 'src/tools/compiletest')
| -rw-r--r-- | src/tools/compiletest/src/json.rs | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/tools/compiletest/src/json.rs b/src/tools/compiletest/src/json.rs index a7615f5f423..26a3c4dee40 100644 --- a/src/tools/compiletest/src/json.rs +++ b/src/tools/compiletest/src/json.rs @@ -17,6 +17,12 @@ struct Diagnostic { rendered: Option<String>, } +#[derive(Deserialize)] +struct Directive { + #[allow(dead_code)] + directive: String, +} + #[derive(Deserialize, Clone)] struct DiagnosticSpan { file_name: String, @@ -67,16 +73,17 @@ pub fn extract_rendered(output: &str) -> String { .lines() .filter_map(|line| { if line.starts_with('{') { - match serde_json::from_str::<Diagnostic>(line) { - Ok(diagnostic) => diagnostic.rendered, - Err(error) => { - print!( - "failed to decode compiler output as json: \ - `{}`\nline: {}\noutput: {}", - error, line, output - ); - panic!() - } + if let Ok(diagnostic) = serde_json::from_str::<Diagnostic>(line) { + diagnostic.rendered + } else if let Ok(_directive) = serde_json::from_str::<Directive>(line) { + // Swallow the directive. + None + } else { + print!( + "failed to decode compiler output as json: line: {}\noutput: {}", + line, output + ); + panic!() } } else { // preserve non-JSON lines, such as ICEs |
