mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 02:03:53 +00:00
rustc: rename -Z emit-directives to -Z emit-artifact-notifications and simplify the output.
This commit is contained in:
parent
f0e43fc986
commit
1618c079ab
@ -1462,8 +1462,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
|
|||||||
the same values as the target option of the same name"),
|
the same values as the target option of the same name"),
|
||||||
allow_features: Option<Vec<String>> = (None, parse_opt_comma_list, [TRACKED],
|
allow_features: Option<Vec<String>> = (None, parse_opt_comma_list, [TRACKED],
|
||||||
"only allow the listed language features to be enabled in code (space separated)"),
|
"only allow the listed language features to be enabled in code (space separated)"),
|
||||||
emit_directives: bool = (false, parse_bool, [UNTRACKED],
|
emit_artifact_notifications: bool = (false, parse_bool, [UNTRACKED],
|
||||||
"emit build directives if producing JSON output"),
|
"emit notifications after each artifact has been output (only in the JSON format)"),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_lib_output() -> CrateType {
|
pub fn default_lib_output() -> CrateType {
|
||||||
|
@ -16,6 +16,7 @@ use std::borrow::Cow;
|
|||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::cmp::{min, Reverse};
|
use std::cmp::{min, Reverse};
|
||||||
|
use std::path::Path;
|
||||||
use termcolor::{StandardStream, ColorChoice, ColorSpec, BufferWriter, Ansi};
|
use termcolor::{StandardStream, ColorChoice, ColorSpec, BufferWriter, Ansi};
|
||||||
use termcolor::{WriteColor, Color, Buffer};
|
use termcolor::{WriteColor, Color, Buffer};
|
||||||
|
|
||||||
@ -52,9 +53,10 @@ pub trait Emitter {
|
|||||||
/// Emit a structured diagnostic.
|
/// Emit a structured diagnostic.
|
||||||
fn emit_diagnostic(&mut self, db: &DiagnosticBuilder<'_>);
|
fn emit_diagnostic(&mut self, db: &DiagnosticBuilder<'_>);
|
||||||
|
|
||||||
/// Emit a JSON directive. The default is to do nothing; this should only
|
/// Emit a notification that an artifact has been output.
|
||||||
/// be emitted with --error-format=json.
|
/// This is currently only supported for the JSON format,
|
||||||
fn maybe_emit_json_directive(&mut self, _directive: String) {}
|
/// other formats can, and will, simply ignore it.
|
||||||
|
fn emit_artifact_notification(&mut self, _path: &Path) {}
|
||||||
|
|
||||||
/// Checks if should show explanations about "rustc --explain"
|
/// Checks if should show explanations about "rustc --explain"
|
||||||
fn should_show_explain(&self) -> bool {
|
fn should_show_explain(&self) -> bool {
|
||||||
|
@ -26,6 +26,7 @@ use std::borrow::Cow;
|
|||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::{error, fmt};
|
use std::{error, fmt};
|
||||||
use std::panic;
|
use std::panic;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use termcolor::{ColorSpec, Color};
|
use termcolor::{ColorSpec, Color};
|
||||||
|
|
||||||
@ -294,16 +295,9 @@ impl error::Error for ExplicitBug {
|
|||||||
pub use diagnostic::{Diagnostic, SubDiagnostic, DiagnosticStyledString, DiagnosticId};
|
pub use diagnostic::{Diagnostic, SubDiagnostic, DiagnosticStyledString, DiagnosticId};
|
||||||
pub use diagnostic_builder::DiagnosticBuilder;
|
pub use diagnostic_builder::DiagnosticBuilder;
|
||||||
|
|
||||||
/// A handler deals with two kinds of compiler output.
|
/// A handler deals with errors and other compiler output.
|
||||||
/// - Errors: certain errors (fatal, bug, unimpl) may cause immediate exit,
|
/// Certain errors (fatal, bug, unimpl) may cause immediate exit,
|
||||||
/// others log errors for later reporting.
|
/// others log errors for later reporting.
|
||||||
/// - Directives: with --error-format=json, the compiler produces directives
|
|
||||||
/// that indicate when certain actions have completed, which are useful for
|
|
||||||
/// Cargo. They may change at any time and should not be considered a public
|
|
||||||
/// API.
|
|
||||||
///
|
|
||||||
/// This crate's name (rustc_errors) doesn't encompass the directives, because
|
|
||||||
/// directives were added much later.
|
|
||||||
pub struct Handler {
|
pub struct Handler {
|
||||||
pub flags: HandlerFlags,
|
pub flags: HandlerFlags,
|
||||||
|
|
||||||
@ -775,8 +769,8 @@ impl Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maybe_emit_json_directive(&self, directive: String) {
|
pub fn emit_artifact_notification(&self, path: &Path) {
|
||||||
self.emitter.borrow_mut().maybe_emit_json_directive(directive);
|
self.emitter.borrow_mut().emit_artifact_notification(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1048,14 +1048,11 @@ fn encode_and_write_metadata<'tcx>(
|
|||||||
tcx.sess.fatal(&format!("couldn't create a temp dir: {}", err))
|
tcx.sess.fatal(&format!("couldn't create a temp dir: {}", err))
|
||||||
});
|
});
|
||||||
let metadata_filename = emit_metadata(tcx.sess, &metadata, &metadata_tmpdir);
|
let metadata_filename = emit_metadata(tcx.sess, &metadata, &metadata_tmpdir);
|
||||||
match std::fs::rename(&metadata_filename, &out_filename) {
|
if let Err(e) = fs::rename(&metadata_filename, &out_filename) {
|
||||||
Ok(_) => {
|
tcx.sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e));
|
||||||
if tcx.sess.opts.debugging_opts.emit_directives {
|
}
|
||||||
tcx.sess.parse_sess.span_diagnostic.maybe_emit_json_directive(
|
if tcx.sess.opts.debugging_opts.emit_artifact_notifications {
|
||||||
format!("metadata file written: {}", out_filename.display()));
|
tcx.sess.parse_sess.span_diagnostic.emit_artifact_notification(&out_filename);
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => tcx.sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ use errors::emitter::{Emitter, HumanReadableErrorType};
|
|||||||
use syntax_pos::{MacroBacktrace, Span, SpanLabel, MultiSpan};
|
use syntax_pos::{MacroBacktrace, Span, SpanLabel, MultiSpan};
|
||||||
use rustc_data_structures::sync::{self, Lrc};
|
use rustc_data_structures::sync::{self, Lrc};
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
use std::path::Path;
|
||||||
use std::vec;
|
use std::vec;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
@ -91,15 +92,15 @@ impl Emitter for JsonEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_emit_json_directive(&mut self, directive: String) {
|
fn emit_artifact_notification(&mut self, path: &Path) {
|
||||||
let data = Directive { directive };
|
let data = ArtifactNotification { artifact: path };
|
||||||
let result = if self.pretty {
|
let result = if self.pretty {
|
||||||
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
|
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
|
||||||
} else {
|
} else {
|
||||||
writeln!(&mut self.dst, "{}", as_json(&data))
|
writeln!(&mut self.dst, "{}", as_json(&data))
|
||||||
};
|
};
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
panic!("failed to print message: {:?}", e);
|
panic!("failed to print notification: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,9 +182,9 @@ struct DiagnosticCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(RustcEncodable)]
|
#[derive(RustcEncodable)]
|
||||||
struct Directive {
|
struct ArtifactNotification<'a> {
|
||||||
/// The directive itself.
|
/// The path of the artifact.
|
||||||
directive: String,
|
artifact: &'a Path,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Diagnostic {
|
impl Diagnostic {
|
||||||
|
1
src/test/ui/emit-artifact-notifications.nll.stderr
Normal file
1
src/test/ui/emit-artifact-notifications.nll.stderr
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"artifact":"$TEST_BUILD_DIR/emit-artifact-notifications.nll/libemit_artifact_notifications.rmeta"}
|
6
src/test/ui/emit-artifact-notifications.rs
Normal file
6
src/test/ui/emit-artifact-notifications.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
// compile-flags:--emit=metadata --error-format=json -Z emit-artifact-notifications
|
||||||
|
// compile-pass
|
||||||
|
|
||||||
|
// A very basic test for the emission of artifact notifications in JSON output.
|
||||||
|
|
||||||
|
fn main() {}
|
1
src/test/ui/emit-artifact-notifications.stderr
Normal file
1
src/test/ui/emit-artifact-notifications.stderr
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"artifact":"$TEST_BUILD_DIR/emit-artifact-notifications/libemit_artifact_notifications.rmeta"}
|
@ -1,6 +0,0 @@
|
|||||||
// compile-flags:--emit=metadata --error-format=json -Z emit-directives
|
|
||||||
// compile-pass
|
|
||||||
|
|
||||||
// A very basic test for the emission of build directives in JSON output.
|
|
||||||
|
|
||||||
fn main() {}
|
|
@ -1 +0,0 @@
|
|||||||
{"directive":"metadata file written: $TEST_BUILD_DIR/emit-directives/libemit_directives.rmeta"}
|
|
@ -4,7 +4,7 @@
|
|||||||
use crate::errors::{Error, ErrorKind};
|
use crate::errors::{Error, ErrorKind};
|
||||||
use crate::runtest::ProcRes;
|
use crate::runtest::ProcRes;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
@ -18,9 +18,9 @@ struct Diagnostic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Directive {
|
struct ArtifactNotification {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
directive: String,
|
artifact: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize, Clone)]
|
||||||
@ -75,8 +75,8 @@ pub fn extract_rendered(output: &str) -> String {
|
|||||||
if line.starts_with('{') {
|
if line.starts_with('{') {
|
||||||
if let Ok(diagnostic) = serde_json::from_str::<Diagnostic>(line) {
|
if let Ok(diagnostic) = serde_json::from_str::<Diagnostic>(line) {
|
||||||
diagnostic.rendered
|
diagnostic.rendered
|
||||||
} else if let Ok(_directive) = serde_json::from_str::<Directive>(line) {
|
} else if let Ok(_) = serde_json::from_str::<ArtifactNotification>(line) {
|
||||||
// Swallow the directive.
|
// Ignore the notification.
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
print!(
|
print!(
|
||||||
|
Loading…
Reference in New Issue
Block a user