@@ -68,13 +68,24 @@ pub fn encode_and_write_metadata(
68
68
. unwrap_or_else ( |err| tcx. sess . fatal ( & format ! ( "couldn't create a temp dir: {}" , err) ) ) ;
69
69
let metadata_tmpdir = MaybeTempDir :: new ( metadata_tmpdir, tcx. sess . opts . cg . save_temps ) ;
70
70
let metadata_filename = metadata_tmpdir. as_ref ( ) . join ( METADATA_FILENAME ) ;
71
+ let need_metadata_file = tcx. sess . opts . output_types . contains_key ( & OutputType :: Metadata ) ;
71
72
let metadata = match metadata_kind {
72
73
MetadataKind :: None => {
73
- if tcx. sess . opts . json_artifact_notifications {
74
- tcx. sess
75
- . parse_sess
76
- . span_diagnostic
77
- . emit_artifact_notification ( & out_filename, "metadata" ) ;
74
+ if need_metadata_file {
75
+ // Though creating the empty file here seems to be meaningless, cargo expects it.
76
+ if let Err ( e) = std:: fs:: File :: create ( & out_filename) {
77
+ tcx. sess . fatal ( & format ! (
78
+ "failed to create the file {}: {}" ,
79
+ out_filename. display( ) ,
80
+ e
81
+ ) ) ;
82
+ }
83
+ if tcx. sess . opts . json_artifact_notifications {
84
+ tcx. sess
85
+ . parse_sess
86
+ . span_diagnostic
87
+ . emit_artifact_notification ( & out_filename, "metadata" ) ;
88
+ }
78
89
}
79
90
EncodedMetadata :: empty ( )
80
91
}
@@ -83,7 +94,6 @@ pub fn encode_and_write_metadata(
83
94
84
95
let _prof_timer = tcx. sess . prof . generic_activity ( "write_crate_metadata" ) ;
85
96
86
- let need_metadata_file = tcx. sess . opts . output_types . contains_key ( & OutputType :: Metadata ) ;
87
97
let ( metadata_filename, metadata_tmpdir) = if need_metadata_file {
88
98
if let Err ( e) = non_durable_rename ( & metadata_filename, & out_filename) {
89
99
tcx. sess . fatal ( & format ! ( "failed to write {}: {}" , out_filename. display( ) , e) ) ;
0 commit comments