@@ -14,7 +14,7 @@ mod unit;
14
14
use std:: env;
15
15
use std:: ffi:: { OsStr , OsString } ;
16
16
use std:: fs:: { self , File } ;
17
- use std:: io:: { BufRead , BufReader , Write } ;
17
+ use std:: io:: Write ;
18
18
use std:: path:: { Path , PathBuf } ;
19
19
use std:: sync:: Arc ;
20
20
@@ -769,17 +769,21 @@ fn add_error_format(
769
769
if supports_termcolor {
770
770
cmd. arg ( "--json-rendered=termcolor" ) ;
771
771
}
772
+ if cx. bcx . build_config . message_format == MessageFormat :: Short {
773
+ // FIXME(rust-lang/rust#60419): right now we have no way of
774
+ // turning on JSON messages from the compiler and also asking
775
+ // the rendered field to be in the `short` format.
776
+ bail ! (
777
+ "currently `--message-format short` is incompatible with {}" ,
778
+ if pipelined {
779
+ "pipelined compilation"
780
+ } else {
781
+ "cached output"
782
+ }
783
+ ) ;
784
+ }
772
785
if pipelined {
773
786
cmd. arg ( "-Zemit-artifact-notifications" ) ;
774
- if cx. bcx . build_config . message_format == MessageFormat :: Short {
775
- // FIXME(rust-lang/rust#60419): right now we have no way of
776
- // turning on JSON messages from the compiler and also asking
777
- // the rendered field to be in the `short` format.
778
- bail ! (
779
- "currently `--message-format short` is incompatible with \
780
- pipelined compilation"
781
- ) ;
782
- }
783
787
}
784
788
} else {
785
789
match cx. bcx . build_config . message_format {
@@ -1130,10 +1134,13 @@ fn on_stderr_line(
1130
1134
color : bool ,
1131
1135
cache_cell : & mut Option < ( PathBuf , LazyCell < File > ) > ,
1132
1136
) -> CargoResult < ( ) > {
1137
+ // Check if caching is enabled.
1133
1138
if let Some ( ( path, cell) ) = cache_cell {
1139
+ // Cache the output, which will be replayed later when Fresh.
1134
1140
// The file is created lazily so that in the normal case, lots of
1135
1141
// empty files are not created.
1136
1142
let f = cell. try_borrow_mut_with ( || File :: create ( path) ) ?;
1143
+ debug_assert ! ( !line. contains( '\n' ) ) ;
1137
1144
f. write_all ( line. as_bytes ( ) ) ?;
1138
1145
f. write_all ( & [ b'\n' ] ) ?;
1139
1146
}
@@ -1179,9 +1186,11 @@ fn on_stderr_line(
1179
1186
let rendered = if color {
1180
1187
error. rendered
1181
1188
} else {
1189
+ // Strip only fails if the the Writer fails, which is Cursor
1190
+ // on a Vec, which should never fail.
1182
1191
strip_ansi_escapes:: strip ( & error. rendered )
1183
1192
. map ( |v| String :: from_utf8 ( v) . expect ( "utf8" ) )
1184
- . unwrap_or ( error . rendered )
1193
+ . expect ( "strip should never fail" )
1185
1194
} ;
1186
1195
state. stderr ( rendered) ;
1187
1196
return Ok ( ( ) ) ;
@@ -1265,25 +1274,22 @@ fn replay_output_cache(
1265
1274
MessageFormat :: Short => false ,
1266
1275
} ;
1267
1276
Work :: new ( move |state| {
1268
- if path. exists ( ) {
1269
- let mut f = BufReader :: new ( File :: open ( & path) ?) ;
1270
- let mut line = String :: new ( ) ;
1271
- loop {
1272
- if f. read_line ( & mut line) ? == 0 {
1273
- break ;
1274
- }
1275
- on_stderr_line (
1276
- state,
1277
- & line,
1278
- package_id,
1279
- & target,
1280
- extract_rendered_messages,
1281
- false , // look_for_metadata_directive
1282
- color,
1283
- & mut None ,
1284
- ) ?;
1285
- line. clear ( ) ;
1286
- }
1277
+ if !path. exists ( ) {
1278
+ // No cached output, probably didn't emit anything.
1279
+ return Ok ( ( ) ) ;
1280
+ }
1281
+ let contents = fs:: read_to_string ( & path) ?;
1282
+ for line in contents. lines ( ) {
1283
+ on_stderr_line (
1284
+ state,
1285
+ & line,
1286
+ package_id,
1287
+ & target,
1288
+ extract_rendered_messages,
1289
+ false , // look_for_metadata_directive
1290
+ color,
1291
+ & mut None ,
1292
+ ) ?;
1287
1293
}
1288
1294
Ok ( ( ) )
1289
1295
} )
0 commit comments