@@ -18,7 +18,7 @@ use std::io::Write;
18
18
use std:: path:: { Path , PathBuf } ;
19
19
use std:: sync:: Arc ;
20
20
21
- use failure:: { bail , Error } ;
21
+ use failure:: Error ;
22
22
use lazycell:: LazyCell ;
23
23
use log:: debug;
24
24
use same_file:: is_same_file;
@@ -607,7 +607,6 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
607
607
rustdoc. arg ( "--crate-name" ) . arg ( & unit. target . crate_name ( ) ) ;
608
608
add_path_args ( bcx, unit, & mut rustdoc) ;
609
609
add_cap_lints ( bcx, unit, & mut rustdoc) ;
610
- add_color ( bcx, & mut rustdoc) ;
611
610
612
611
if unit. kind != Kind :: Host {
613
612
if let Some ( ref target) = bcx. build_config . requested_target {
@@ -628,7 +627,7 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
628
627
rustdoc. arg ( "--cfg" ) . arg ( & format ! ( "feature=\" {}\" " , feat) ) ;
629
628
}
630
629
631
- add_error_format ( cx, & mut rustdoc, false , false ) ?;
630
+ add_error_format_and_color ( cx, & mut rustdoc, false ) ?;
632
631
633
632
if let Some ( args) = bcx. extra_args_for ( unit) {
634
633
rustdoc. args ( args) ;
@@ -715,39 +714,20 @@ fn add_cap_lints(bcx: &BuildContext<'_, '_>, unit: &Unit<'_>, cmd: &mut ProcessB
715
714
}
716
715
}
717
716
718
- fn add_color ( bcx : & BuildContext < ' _ , ' _ > , cmd : & mut ProcessBuilder ) {
719
- let shell = bcx. config . shell ( ) ;
720
- let color = if shell. supports_color ( ) {
721
- "always"
722
- } else {
723
- "never"
724
- } ;
725
- cmd. args ( & [ "--color" , color] ) ;
726
- }
727
-
728
717
/// Add error-format flags to the command.
729
718
///
730
- /// This is rather convoluted right now. The general overview is:
731
- /// - If -Zcache-messages or `build.pipelining` is enabled, Cargo always uses
732
- /// JSON output. This has several benefits, such as being easier to parse,
733
- /// handles changing formats (for replaying cached messages), ensures
734
- /// atomic output (so messages aren't interleaved), etc.
735
- /// - `supports_termcolor` is a temporary flag. rustdoc does not yet support
736
- /// the `--json-rendered` flag, but it is intended to fix that soon.
737
- /// - `short` output is not yet supported for JSON output. We haven't yet
738
- /// decided how this problem will be resolved. Probably either adding
739
- /// "short" to the JSON output, or more ambitiously moving diagnostic
740
- /// rendering to an external library that Cargo can share with rustc.
719
+ /// This is somewhat odd right now, but the general overview is that if
720
+ /// `-Zcache-messages` or `pipelined` is enabled then Cargo always uses JSON
721
+ /// output. This has several benefits, such as being easier to parse, handles
722
+ /// changing formats (for replaying cached messages), ensures atomic output (so
723
+ /// messages aren't interleaved), etc.
741
724
///
742
- /// It is intended in the future that Cargo *always* uses the JSON output, and
743
- /// this function can be simplified. The above issues need to be resolved, the
744
- /// flags need to be stabilized, and we need more testing to ensure there
745
- /// aren't any regressions.
746
- fn add_error_format (
725
+ /// It is intended in the future that Cargo *always* uses the JSON output (by
726
+ /// turning on cache-messages by default), and this function can be simplified.
727
+ fn add_error_format_and_color (
747
728
cx : & Context < ' _ , ' _ > ,
748
729
cmd : & mut ProcessBuilder ,
749
730
pipelined : bool ,
750
- supports_termcolor : bool ,
751
731
) -> CargoResult < ( ) > {
752
732
// If this unit is producing a required rmeta file then we need to know
753
733
// when the rmeta file is ready so we can signal to the rest of Cargo that
@@ -762,26 +742,15 @@ fn add_error_format(
762
742
// internally understand that we should extract the `rendered` field and
763
743
// present it if we can.
764
744
if cx. bcx . build_config . cache_messages ( ) || pipelined {
765
- cmd. arg ( "--error-format=json" ) . arg ( "-Zunstable-options" ) ;
766
- if supports_termcolor {
767
- cmd. arg ( "--json-rendered=termcolor" ) ;
745
+ cmd. arg ( "--error-format=json" ) ;
746
+ let mut json = String :: from ( "--json=diagnostic-rendered-ansi" ) ;
747
+ if pipelined {
748
+ json. push_str ( ",artifacts" ) ;
768
749
}
769
750
if cx. bcx . build_config . message_format == MessageFormat :: Short {
770
- // FIXME(rust-lang/rust#60419): right now we have no way of
771
- // turning on JSON messages from the compiler and also asking
772
- // the rendered field to be in the `short` format.
773
- bail ! (
774
- "currently `--message-format short` is incompatible with {}" ,
775
- if pipelined {
776
- "pipelined compilation"
777
- } else {
778
- "cached output"
779
- }
780
- ) ;
781
- }
782
- if pipelined {
783
- cmd. arg ( "-Zemit-artifact-notifications" ) ;
751
+ json. push_str ( ",diagnostic-short" ) ;
784
752
}
753
+ cmd. arg ( json) ;
785
754
} else {
786
755
match cx. bcx . build_config . message_format {
787
756
MessageFormat :: Human => ( ) ,
@@ -792,6 +761,13 @@ fn add_error_format(
792
761
cmd. arg ( "--error-format" ) . arg ( "short" ) ;
793
762
}
794
763
}
764
+
765
+ let color = if cx. bcx . config . shell ( ) . supports_color ( ) {
766
+ "always"
767
+ } else {
768
+ "never"
769
+ } ;
770
+ cmd. args ( & [ "--color" , color] ) ;
795
771
}
796
772
Ok ( ( ) )
797
773
}
@@ -822,8 +798,7 @@ fn build_base_args<'a, 'cfg>(
822
798
cmd. arg ( "--crate-name" ) . arg ( & unit. target . crate_name ( ) ) ;
823
799
824
800
add_path_args ( bcx, unit, cmd) ;
825
- add_color ( bcx, cmd) ;
826
- add_error_format ( cx, cmd, cx. rmeta_required ( unit) , true ) ?;
801
+ add_error_format_and_color ( cx, cmd, cx. rmeta_required ( unit) ) ?;
827
802
828
803
if !test {
829
804
for crate_type in crate_types. iter ( ) {
@@ -1227,11 +1202,11 @@ fn on_stderr_line(
1227
1202
} else {
1228
1203
// Remove color information from the rendered string. rustc has not
1229
1204
// included color in the past, so to avoid breaking anything, strip it
1230
- // out when --json-rendered=termcolor is used. This runs
1205
+ // out when --json=diagnostic -rendered-ansi is used. This runs
1231
1206
// unconditionally under the assumption that Cargo will eventually
1232
1207
// move to this as the default mode. Perhaps in the future, cargo
1233
1208
// could allow the user to enable/disable color (such as with a
1234
- // `--json-rendered ` or `--color` or `--message-format` flag).
1209
+ // `--json` or `--color` or `--message-format` flag).
1235
1210
#[ derive( serde:: Deserialize , serde:: Serialize ) ]
1236
1211
struct CompilerMessage {
1237
1212
rendered : String ,
@@ -1297,10 +1272,8 @@ fn replay_output_cache(
1297
1272
) -> Work {
1298
1273
let target = target. clone ( ) ;
1299
1274
let extract_rendered_messages = match format {
1300
- MessageFormat :: Human => true ,
1275
+ MessageFormat :: Human | MessageFormat :: Short => true ,
1301
1276
MessageFormat :: Json => false ,
1302
- // FIXME: short not supported.
1303
- MessageFormat :: Short => false ,
1304
1277
} ;
1305
1278
let mut options = OutputOptions {
1306
1279
extract_rendered_messages,
0 commit comments