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/libsyntax | |
| 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/libsyntax')
| -rw-r--r-- | src/libsyntax/json.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/libsyntax/json.rs b/src/libsyntax/json.rs index c19b408442a..65f8d0e77d7 100644 --- a/src/libsyntax/json.rs +++ b/src/libsyntax/json.rs @@ -79,7 +79,7 @@ impl JsonEmitter { } impl Emitter for JsonEmitter { - fn emit(&mut self, db: &DiagnosticBuilder<'_>) { + fn emit_diagnostic(&mut self, db: &DiagnosticBuilder<'_>) { let data = Diagnostic::from_diagnostic_builder(db, self); let result = if self.pretty { writeln!(&mut self.dst, "{}", as_pretty_json(&data)) @@ -90,6 +90,18 @@ impl Emitter for JsonEmitter { panic!("failed to print diagnostics: {:?}", e); } } + + fn maybe_emit_json_directive(&mut self, directive: String) { + let data = Directive { directive }; + let result = if self.pretty { + writeln!(&mut self.dst, "{}", as_pretty_json(&data)) + } else { + writeln!(&mut self.dst, "{}", as_json(&data)) + }; + if let Err(e) = result { + panic!("failed to print message: {:?}", e); + } + } } // The following data types are provided just for serialisation. @@ -168,6 +180,12 @@ struct DiagnosticCode { explanation: Option<&'static str>, } +#[derive(RustcEncodable)] +struct Directive { + /// The directive itself. + directive: String, +} + impl Diagnostic { fn from_diagnostic_builder(db: &DiagnosticBuilder<'_>, je: &JsonEmitter) @@ -200,7 +218,7 @@ impl Diagnostic { let buf = BufWriter::default(); let output = buf.clone(); je.json_rendered.new_emitter(Box::new(buf), Some(je.sm.clone()), false) - .ui_testing(je.ui_testing).emit(db); + .ui_testing(je.ui_testing).emit_diagnostic(db); let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap(); let output = String::from_utf8(output).unwrap(); |
