@@ -68,53 +68,45 @@ 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 ) ;
72
- let metadata = match metadata_kind {
71
+
72
+ match metadata_kind {
73
73
MetadataKind :: None => {
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
- }
89
- }
90
- EncodedMetadata :: empty ( )
74
+ std:: fs:: File :: create ( & metadata_filename) . unwrap_or_else ( |e| {
75
+ tcx. sess . fatal ( & format ! (
76
+ "failed to create the file {}: {}" ,
77
+ out_filename. display( ) ,
78
+ e
79
+ ) )
80
+ } ) ;
91
81
}
92
82
MetadataKind :: Uncompressed | MetadataKind :: Compressed => {
93
83
encode_metadata ( tcx, & metadata_filename) ;
84
+ }
85
+ } ;
94
86
95
- let _prof_timer = tcx. sess . prof . generic_activity ( "write_crate_metadata" ) ;
96
-
97
- let ( metadata_filename, metadata_tmpdir) = if need_metadata_file {
98
- if let Err ( e) = non_durable_rename ( & metadata_filename, & out_filename) {
99
- tcx. sess . fatal ( & format ! ( "failed to write {}: {}" , out_filename. display( ) , e) ) ;
100
- }
101
- if tcx. sess . opts . json_artifact_notifications {
102
- tcx. sess
103
- . parse_sess
104
- . span_diagnostic
105
- . emit_artifact_notification ( & out_filename, "metadata" ) ;
106
- }
107
- ( out_filename, None )
108
- } else {
109
- ( metadata_filename, Some ( metadata_tmpdir) )
110
- } ;
111
-
112
- EncodedMetadata :: from_path ( metadata_filename, metadata_tmpdir) . unwrap_or_else ( |e| {
113
- tcx. sess . fatal ( & format ! ( "failed to create encoded metadata from file: {}" , e) )
114
- } )
87
+ let _prof_timer = tcx. sess . prof . generic_activity ( "write_crate_metadata" ) ;
88
+
89
+ let need_metadata_file = tcx. sess . opts . output_types . contains_key ( & OutputType :: Metadata ) ;
90
+ let ( metadata_filename, metadata_tmpdir) = if need_metadata_file {
91
+ if let Err ( e) = non_durable_rename ( & metadata_filename, & out_filename) {
92
+ tcx. sess . fatal ( & format ! ( "failed to write {}: {}" , out_filename. display( ) , e) ) ;
115
93
}
94
+ if tcx. sess . opts . json_artifact_notifications {
95
+ tcx. sess
96
+ . parse_sess
97
+ . span_diagnostic
98
+ . emit_artifact_notification ( & out_filename, "metadata" ) ;
99
+ }
100
+ ( out_filename, None )
101
+ } else {
102
+ ( metadata_filename, Some ( metadata_tmpdir) )
116
103
} ;
117
104
105
+ let metadata =
106
+ EncodedMetadata :: from_path ( metadata_filename, metadata_tmpdir) . unwrap_or_else ( |e| {
107
+ tcx. sess . fatal ( & format ! ( "failed to create encoded metadata from file: {}" , e) )
108
+ } ) ;
109
+
118
110
let need_metadata_module = metadata_kind == MetadataKind :: Compressed ;
119
111
120
112
( metadata, need_metadata_module)
0 commit comments