From 6c3862594210cc0a5e60fbad32d3aab7a4fb512c Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Tue, 21 May 2019 12:38:46 -0700 Subject: [PATCH] Make -Zemit-artifact-notifications also emit the artifact type This is easier for tooling to handle than trying to reverse-engineer it from the filename extension. --- src/librustc_codegen_ssa/back/link.rs | 2 +- src/librustc_errors/emitter.rs | 2 +- src/librustc_errors/lib.rs | 4 ++-- src/librustc_interface/passes.rs | 3 ++- src/libsyntax/json.rs | 6 ++++-- src/test/ui/emit-artifact-notifications.nll.stderr | 2 +- src/test/ui/emit-artifact-notifications.stderr | 2 +- 7 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index d5a56f6a09e02..c1ec2071789eb 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -96,7 +96,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(sess: &'a Session, } } if sess.opts.debugging_opts.emit_artifact_notifications { - sess.parse_sess.span_diagnostic.emit_artifact_notification(&out_filename); + sess.parse_sess.span_diagnostic.emit_artifact_notification(&out_filename, "link"); } } diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 59cbd65f05c68..b56162deaf1cc 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -56,7 +56,7 @@ pub trait Emitter { /// Emit a notification that an artifact has been output. /// This is currently only supported for the JSON format, /// other formats can, and will, simply ignore it. - fn emit_artifact_notification(&mut self, _path: &Path) {} + fn emit_artifact_notification(&mut self, _path: &Path, _artifact_type: &str) {} /// Checks if should show explanations about "rustc --explain" fn should_show_explain(&self) -> bool { diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 3aa87fad07174..2dcf7be2aa8b1 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -769,8 +769,8 @@ impl Handler { } } - pub fn emit_artifact_notification(&self, path: &Path) { - self.emitter.borrow_mut().emit_artifact_notification(path); + pub fn emit_artifact_notification(&self, path: &Path, artifact_type: &str) { + self.emitter.borrow_mut().emit_artifact_notification(path, artifact_type); } } diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index c5ac8860ccd9b..f17554b1fbdc9 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -1052,7 +1052,8 @@ fn encode_and_write_metadata<'tcx>( tcx.sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e)); } if tcx.sess.opts.debugging_opts.emit_artifact_notifications { - tcx.sess.parse_sess.span_diagnostic.emit_artifact_notification(&out_filename); + tcx.sess.parse_sess.span_diagnostic + .emit_artifact_notification(&out_filename, "metadata"); } } diff --git a/src/libsyntax/json.rs b/src/libsyntax/json.rs index 2dd2ecb749300..767ab74355e66 100644 --- a/src/libsyntax/json.rs +++ b/src/libsyntax/json.rs @@ -92,8 +92,8 @@ impl Emitter for JsonEmitter { } } - fn emit_artifact_notification(&mut self, path: &Path) { - let data = ArtifactNotification { artifact: path }; + fn emit_artifact_notification(&mut self, path: &Path, artifact_type: &str) { + let data = ArtifactNotification { artifact: path, emit: artifact_type }; let result = if self.pretty { writeln!(&mut self.dst, "{}", as_pretty_json(&data)) } else { @@ -185,6 +185,8 @@ struct DiagnosticCode { struct ArtifactNotification<'a> { /// The path of the artifact. artifact: &'a Path, + /// What kind of artifact we're emitting. + emit: &'a str, } impl Diagnostic { diff --git a/src/test/ui/emit-artifact-notifications.nll.stderr b/src/test/ui/emit-artifact-notifications.nll.stderr index 347d9aeac2307..5547631a4b022 100644 --- a/src/test/ui/emit-artifact-notifications.nll.stderr +++ b/src/test/ui/emit-artifact-notifications.nll.stderr @@ -1 +1 @@ -{"artifact":"$TEST_BUILD_DIR/emit-artifact-notifications.nll/libemit_artifact_notifications.rmeta"} +{"artifact":"$TEST_BUILD_DIR/emit-artifact-notifications.nll/libemit_artifact_notifications.rmeta","emit":"metadata"} diff --git a/src/test/ui/emit-artifact-notifications.stderr b/src/test/ui/emit-artifact-notifications.stderr index 56c977181ff51..260d41b8f15cc 100644 --- a/src/test/ui/emit-artifact-notifications.stderr +++ b/src/test/ui/emit-artifact-notifications.stderr @@ -1 +1 @@ -{"artifact":"$TEST_BUILD_DIR/emit-artifact-notifications/libemit_artifact_notifications.rmeta"} +{"artifact":"$TEST_BUILD_DIR/emit-artifact-notifications/libemit_artifact_notifications.rmeta","emit":"metadata"}