@@ -18,7 +18,7 @@ use std::io::Write;
1818use std:: path:: { Path , PathBuf } ;
1919use std:: sync:: Arc ;
2020
21- use failure:: { bail , Error } ;
21+ use failure:: Error ;
2222use lazycell:: LazyCell ;
2323use log:: debug;
2424use same_file:: is_same_file;
@@ -607,7 +607,6 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
607607 rustdoc. arg ( "--crate-name" ) . arg ( & unit. target . crate_name ( ) ) ;
608608 add_path_args ( bcx, unit, & mut rustdoc) ;
609609 add_cap_lints ( bcx, unit, & mut rustdoc) ;
610- add_color ( bcx, & mut rustdoc) ;
611610
612611 if unit. kind != Kind :: Host {
613612 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
628627 rustdoc. arg ( "--cfg" ) . arg ( & format ! ( "feature=\" {}\" " , feat) ) ;
629628 }
630629
631- add_error_format ( cx, & mut rustdoc, false , false ) ?;
630+ add_error_format_and_color ( cx, & mut rustdoc, false ) ?;
632631
633632 if let Some ( args) = bcx. extra_args_for ( unit) {
634633 rustdoc. args ( args) ;
@@ -715,39 +714,20 @@ fn add_cap_lints(bcx: &BuildContext<'_, '_>, unit: &Unit<'_>, cmd: &mut ProcessB
715714 }
716715}
717716
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-
728717/// Add error-format flags to the command.
729718///
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.
741724///
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 (
747728 cx : & Context < ' _ , ' _ > ,
748729 cmd : & mut ProcessBuilder ,
749730 pipelined : bool ,
750- supports_termcolor : bool ,
751731) -> CargoResult < ( ) > {
752732 // If this unit is producing a required rmeta file then we need to know
753733 // when the rmeta file is ready so we can signal to the rest of Cargo that
@@ -762,26 +742,15 @@ fn add_error_format(
762742 // internally understand that we should extract the `rendered` field and
763743 // present it if we can.
764744 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" ) ;
768749 }
769750 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" ) ;
784752 }
753+ cmd. arg ( json) ;
785754 } else {
786755 match cx. bcx . build_config . message_format {
787756 MessageFormat :: Human => ( ) ,
@@ -792,6 +761,13 @@ fn add_error_format(
792761 cmd. arg ( "--error-format" ) . arg ( "short" ) ;
793762 }
794763 }
764+
765+ let color = if cx. bcx . config . shell ( ) . supports_color ( ) {
766+ "always"
767+ } else {
768+ "never"
769+ } ;
770+ cmd. args ( & [ "--color" , color] ) ;
795771 }
796772 Ok ( ( ) )
797773}
@@ -822,8 +798,7 @@ fn build_base_args<'a, 'cfg>(
822798 cmd. arg ( "--crate-name" ) . arg ( & unit. target . crate_name ( ) ) ;
823799
824800 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) ) ?;
827802
828803 if !test {
829804 for crate_type in crate_types. iter ( ) {
@@ -1227,11 +1202,11 @@ fn on_stderr_line(
12271202 } else {
12281203 // Remove color information from the rendered string. rustc has not
12291204 // 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
12311206 // unconditionally under the assumption that Cargo will eventually
12321207 // move to this as the default mode. Perhaps in the future, cargo
12331208 // 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).
12351210 #[ derive( serde:: Deserialize , serde:: Serialize ) ]
12361211 struct CompilerMessage {
12371212 rendered : String ,
@@ -1297,10 +1272,8 @@ fn replay_output_cache(
12971272) -> Work {
12981273 let target = target. clone ( ) ;
12991274 let extract_rendered_messages = match format {
1300- MessageFormat :: Human => true ,
1275+ MessageFormat :: Human | MessageFormat :: Short => true ,
13011276 MessageFormat :: Json => false ,
1302- // FIXME: short not supported.
1303- MessageFormat :: Short => false ,
13041277 } ;
13051278 let mut options = OutputOptions {
13061279 extract_rendered_messages,
0 commit comments