Skip to content

Commit b8fa4cb

Browse files
committed
Auto merge of #60464 - eddyb:not-overly-specific-pipelining, r=alexcrichton
rustc: rename -Z emit-directives to -Z emit-artifact-notifications and simplify the output. This is my take on #60006 / #60419 (see #60006 (comment)). I'm not too attached the "notifications" part, it's pretty much bikeshed material. **EDIT**: for "artifact", @matklad pointed out Cargo already uses it (in #60464 (comment)) The first two commits are fixes that could be landed independently, especially the `compiletest` one, which removes the need for any of the normalization added in #60006 to land the test. The last commit enables the emission for all outputs, which was my main suggestion for #60006, mostly to show that it's minimal and not really a "scope creep" (as suggested in #60006 (comment)). cc @alexcrichton @nnethercote
2 parents eeedd3a + c89a131 commit b8fa4cb

File tree

16 files changed

+87
-74
lines changed

16 files changed

+87
-74
lines changed

src/librustc/session/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,8 +1462,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
14621462
the same values as the target option of the same name"),
14631463
allow_features: Option<Vec<String>> = (None, parse_opt_comma_list, [TRACKED],
14641464
"only allow the listed language features to be enabled in code (space separated)"),
1465-
emit_directives: bool = (false, parse_bool, [UNTRACKED],
1466-
"emit build directives if producing JSON output"),
1465+
emit_artifact_notifications: bool = (false, parse_bool, [UNTRACKED],
1466+
"emit notifications after each artifact has been output (only in the JSON format)"),
14671467
}
14681468

14691469
pub fn default_lib_output() -> CrateType {

src/librustc_codegen_ssa/back/link.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
9595
);
9696
}
9797
}
98+
if sess.opts.debugging_opts.emit_artifact_notifications {
99+
sess.parse_sess.span_diagnostic.emit_artifact_notification(&out_filename);
100+
}
98101
}
99102

100103
if sess.opts.cg.save_temps {

src/librustc_errors/emitter.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::borrow::Cow;
1616
use std::io::prelude::*;
1717
use std::io;
1818
use std::cmp::{min, Reverse};
19+
use std::path::Path;
1920
use termcolor::{StandardStream, ColorChoice, ColorSpec, BufferWriter, Ansi};
2021
use termcolor::{WriteColor, Color, Buffer};
2122

@@ -52,9 +53,10 @@ pub trait Emitter {
5253
/// Emit a structured diagnostic.
5354
fn emit_diagnostic(&mut self, db: &DiagnosticBuilder<'_>);
5455

55-
/// Emit a JSON directive. The default is to do nothing; this should only
56-
/// be emitted with --error-format=json.
57-
fn maybe_emit_json_directive(&mut self, _directive: String) {}
56+
/// Emit a notification that an artifact has been output.
57+
/// This is currently only supported for the JSON format,
58+
/// other formats can, and will, simply ignore it.
59+
fn emit_artifact_notification(&mut self, _path: &Path) {}
5860

5961
/// Checks if should show explanations about "rustc --explain"
6062
fn should_show_explain(&self) -> bool {

src/librustc_errors/lib.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use std::borrow::Cow;
2626
use std::cell::Cell;
2727
use std::{error, fmt};
2828
use std::panic;
29+
use std::path::Path;
2930

3031
use termcolor::{ColorSpec, Color};
3132

@@ -294,16 +295,9 @@ impl error::Error for ExplicitBug {
294295
pub use diagnostic::{Diagnostic, SubDiagnostic, DiagnosticStyledString, DiagnosticId};
295296
pub use diagnostic_builder::DiagnosticBuilder;
296297

297-
/// A handler deals with two kinds of compiler output.
298-
/// - Errors: certain errors (fatal, bug, unimpl) may cause immediate exit,
299-
/// others log errors for later reporting.
300-
/// - Directives: with --error-format=json, the compiler produces directives
301-
/// that indicate when certain actions have completed, which are useful for
302-
/// Cargo. They may change at any time and should not be considered a public
303-
/// API.
304-
///
305-
/// This crate's name (rustc_errors) doesn't encompass the directives, because
306-
/// directives were added much later.
298+
/// A handler deals with errors and other compiler output.
299+
/// Certain errors (fatal, bug, unimpl) may cause immediate exit,
300+
/// others log errors for later reporting.
307301
pub struct Handler {
308302
pub flags: HandlerFlags,
309303

@@ -775,8 +769,8 @@ impl Handler {
775769
}
776770
}
777771

778-
pub fn maybe_emit_json_directive(&self, directive: String) {
779-
self.emitter.borrow_mut().maybe_emit_json_directive(directive);
772+
pub fn emit_artifact_notification(&self, path: &Path) {
773+
self.emitter.borrow_mut().emit_artifact_notification(path);
780774
}
781775
}
782776

src/librustc_interface/passes.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,14 +1048,11 @@ fn encode_and_write_metadata<'tcx>(
10481048
tcx.sess.fatal(&format!("couldn't create a temp dir: {}", err))
10491049
});
10501050
let metadata_filename = emit_metadata(tcx.sess, &metadata, &metadata_tmpdir);
1051-
match std::fs::rename(&metadata_filename, &out_filename) {
1052-
Ok(_) => {
1053-
if tcx.sess.opts.debugging_opts.emit_directives {
1054-
tcx.sess.parse_sess.span_diagnostic.maybe_emit_json_directive(
1055-
format!("metadata file written: {}", out_filename.display()));
1056-
}
1057-
}
1058-
Err(e) => tcx.sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e)),
1051+
if let Err(e) = fs::rename(&metadata_filename, &out_filename) {
1052+
tcx.sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e));
1053+
}
1054+
if tcx.sess.opts.debugging_opts.emit_artifact_notifications {
1055+
tcx.sess.parse_sess.span_diagnostic.emit_artifact_notification(&out_filename);
10591056
}
10601057
}
10611058

src/libserialize/serialize.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,12 +764,18 @@ macro_rules! tuple {
764764

765765
tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }
766766

767-
impl Encodable for path::PathBuf {
767+
impl Encodable for path::Path {
768768
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
769769
self.to_str().unwrap().encode(e)
770770
}
771771
}
772772

773+
impl Encodable for path::PathBuf {
774+
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
775+
path::Path::encode(self, e)
776+
}
777+
}
778+
773779
impl Decodable for path::PathBuf {
774780
fn decode<D: Decoder>(d: &mut D) -> Result<path::PathBuf, D::Error> {
775781
let bytes: String = Decodable::decode(d)?;

src/libsyntax/json.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use errors::emitter::{Emitter, HumanReadableErrorType};
1919
use syntax_pos::{MacroBacktrace, Span, SpanLabel, MultiSpan};
2020
use rustc_data_structures::sync::{self, Lrc};
2121
use std::io::{self, Write};
22+
use std::path::Path;
2223
use std::vec;
2324
use std::sync::{Arc, Mutex};
2425

@@ -91,15 +92,15 @@ impl Emitter for JsonEmitter {
9192
}
9293
}
9394

94-
fn maybe_emit_json_directive(&mut self, directive: String) {
95-
let data = Directive { directive };
95+
fn emit_artifact_notification(&mut self, path: &Path) {
96+
let data = ArtifactNotification { artifact: path };
9697
let result = if self.pretty {
9798
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
9899
} else {
99100
writeln!(&mut self.dst, "{}", as_json(&data))
100101
};
101102
if let Err(e) = result {
102-
panic!("failed to print message: {:?}", e);
103+
panic!("failed to print notification: {:?}", e);
103104
}
104105
}
105106
}
@@ -181,9 +182,9 @@ struct DiagnosticCode {
181182
}
182183

183184
#[derive(RustcEncodable)]
184-
struct Directive {
185-
/// The directive itself.
186-
directive: String,
185+
struct ArtifactNotification<'a> {
186+
/// The path of the artifact.
187+
artifact: &'a Path,
187188
}
188189

189190
impl Diagnostic {

src/test/ui/consts/const-eval/unused-broken-const.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
warning: due to multiple output types requested, the explicitly specified output file name will be adapted for each output type
2-
31
error: any use of this value will cause an error
42
--> $DIR/unused-broken-const.rs:5:18
53
|
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"artifact":"$TEST_BUILD_DIR/emit-artifact-notifications.nll/libemit_artifact_notifications.rmeta"}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// compile-flags:--emit=metadata --error-format=json -Z emit-artifact-notifications
2+
// compile-pass
3+
4+
// A very basic test for the emission of artifact notifications in JSON output.
5+
6+
fn main() {}

0 commit comments

Comments
 (0)