From db432debdeb07a8f4bc9e4026d2efdbc6a568991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 3 Feb 2020 16:12:24 +0100 Subject: [PATCH] librustc_driver: Make --print file-names do a minor accounting of --emit. Otherwise we print bogus output which prevents using `cargo check` with sccache, see https://bugzilla.mozilla.org/show_bug.cgi?id=1612855#c2 for a reduced test-case. Ideally --print file-names will emit all the files emitted by the session, but that seems a bit hard to do in a general way, so this is a best effort thing which fixes the cargo check use-case. --- src/librustc_driver/lib.rs | 8 ++++++-- src/librustc_session/config.rs | 15 +++++++++++++++ .../run-make-fulldeps/crate-data-smoke/Makefile | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 019ff431bcb97..86647e08f94de 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -669,9 +669,13 @@ impl RustcDefaultCalls { continue; } let crate_types = rustc_interface::util::collect_crate_types(sess, attrs); - for &style in &crate_types { + let should_codegen = sess.opts.output_types.should_codegen(); + for &crate_type in &crate_types { + if !should_codegen && crate_type.requires_codegen() { + continue; + } let fname = rustc_codegen_utils::link::filename_for_input( - sess, style, &id, &t_outputs, + sess, crate_type, &id, &t_outputs, ); println!("{}", fname.file_name().unwrap().to_string_lossy()); } diff --git a/src/librustc_session/config.rs b/src/librustc_session/config.rs index 813d14d616d42..4cadb3b55c9ae 100644 --- a/src/librustc_session/config.rs +++ b/src/librustc_session/config.rs @@ -651,6 +651,21 @@ pub enum CrateType { ProcMacro, } +impl CrateType { + /// Whether the output of this crate type requires codegen to be generated. + /// + /// This is a bit of a hack to prevent bogus library names being outputted + /// from the PrintRequest code. Ideally that code would be fully aware of + /// the output requests, but that seems hard to do generally. + pub fn requires_codegen(self) -> bool { + use CrateType::*; + match self { + Cdylib | Dylib | Executable | Staticlib => true, + ProcMacro | Rlib => false, + } + } +} + impl_stable_hash_via_hash!(CrateType); #[derive(Clone, Hash)] diff --git a/src/test/run-make-fulldeps/crate-data-smoke/Makefile b/src/test/run-make-fulldeps/crate-data-smoke/Makefile index 1afda457411da..ab6b3246551c7 100644 --- a/src/test/run-make-fulldeps/crate-data-smoke/Makefile +++ b/src/test/run-make-fulldeps/crate-data-smoke/Makefile @@ -6,5 +6,6 @@ all: [ `$(RUSTC) --print file-names --crate-type=lib \ --test crate.rs` = "$(call BIN,foo)" ] [ `$(RUSTC) --print file-names --test lib.rs` = "$(call BIN,mylib)" ] + [ "`$(RUSTC) --emit=dep-info,metadata --print file-names crate.rs`" = "" ] # Shouldn't print the binary name. $(RUSTC) --print file-names lib.rs $(RUSTC) --print file-names rlib.rs