@@ -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;
@@ -614,7 +614,6 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
614614 rustdoc. arg ( "--crate-name" ) . arg ( & unit. target . crate_name ( ) ) ;
615615 add_path_args ( bcx, unit, & mut rustdoc) ;
616616 add_cap_lints ( bcx, unit, & mut rustdoc) ;
617- add_color ( bcx, & mut rustdoc) ;
618617
619618 if unit. kind != Kind :: Host {
620619 if let Some ( ref target) = bcx. build_config . requested_target {
@@ -635,7 +634,7 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
635634 rustdoc. arg ( "--cfg" ) . arg ( & format ! ( "feature=\" {}\" " , feat) ) ;
636635 }
637636
638- add_error_format ( cx, & mut rustdoc, false , false ) ?;
637+ add_error_format_and_color ( cx, & mut rustdoc, false ) ?;
639638
640639 if let Some ( args) = bcx. extra_args_for ( unit) {
641640 rustdoc. args ( args) ;
@@ -722,39 +721,20 @@ fn add_cap_lints(bcx: &BuildContext<'_, '_>, unit: &Unit<'_>, cmd: &mut ProcessB
722721 }
723722}
724723
725- fn add_color ( bcx : & BuildContext < ' _ , ' _ > , cmd : & mut ProcessBuilder ) {
726- let shell = bcx. config . shell ( ) ;
727- let color = if shell. supports_color ( ) {
728- "always"
729- } else {
730- "never"
731- } ;
732- cmd. args ( & [ "--color" , color] ) ;
733- }
734-
735724/// Add error-format flags to the command.
736725///
737- /// This is rather convoluted right now. The general overview is:
738- /// - If -Zcache-messages or `build.pipelining` is enabled, Cargo always uses
739- /// JSON output. This has several benefits, such as being easier to parse,
740- /// handles changing formats (for replaying cached messages), ensures
741- /// atomic output (so messages aren't interleaved), etc.
742- /// - `supports_termcolor` is a temporary flag. rustdoc does not yet support
743- /// the `--json-rendered` flag, but it is intended to fix that soon.
744- /// - `short` output is not yet supported for JSON output. We haven't yet
745- /// decided how this problem will be resolved. Probably either adding
746- /// "short" to the JSON output, or more ambitiously moving diagnostic
747- /// rendering to an external library that Cargo can share with rustc.
726+ /// This is somewhat odd right now, but the general overview is that if
727+ /// `-Zcache-messages` or `pipelined` is enabled then Cargo always uses JSON
728+ /// output. This has several benefits, such as being easier to parse, handles
729+ /// changing formats (for replaying cached messages), ensures atomic output (so
730+ /// messages aren't interleaved), etc.
748731///
749- /// It is intended in the future that Cargo *always* uses the JSON output, and
750- /// this function can be simplified. The above issues need to be resolved, the
751- /// flags need to be stabilized, and we need more testing to ensure there
752- /// aren't any regressions.
753- fn add_error_format (
732+ /// It is intended in the future that Cargo *always* uses the JSON output (by
733+ /// turning on cache-messages by default), and this function can be simplified.
734+ fn add_error_format_and_color (
754735 cx : & Context < ' _ , ' _ > ,
755736 cmd : & mut ProcessBuilder ,
756737 pipelined : bool ,
757- supports_termcolor : bool ,
758738) -> CargoResult < ( ) > {
759739 // If this unit is producing a required rmeta file then we need to know
760740 // when the rmeta file is ready so we can signal to the rest of Cargo that
@@ -769,26 +749,15 @@ fn add_error_format(
769749 // internally understand that we should extract the `rendered` field and
770750 // present it if we can.
771751 if cx. bcx . build_config . cache_messages ( ) || pipelined {
772- cmd. arg ( "--error-format=json" ) . arg ( "-Zunstable-options" ) ;
773- if supports_termcolor {
774- cmd. arg ( "--json-rendered=termcolor" ) ;
752+ cmd. arg ( "--error-format=json" ) ;
753+ let mut json = String :: from ( "--json=diagnostic-rendered-ansi" ) ;
754+ if pipelined {
755+ json. push_str ( ",artifacts" ) ;
775756 }
776757 if cx. bcx . build_config . message_format == MessageFormat :: Short {
777- // FIXME(rust-lang/rust#60419): right now we have no way of
778- // turning on JSON messages from the compiler and also asking
779- // the rendered field to be in the `short` format.
780- bail ! (
781- "currently `--message-format short` is incompatible with {}" ,
782- if pipelined {
783- "pipelined compilation"
784- } else {
785- "cached output"
786- }
787- ) ;
788- }
789- if pipelined {
790- cmd. arg ( "-Zemit-artifact-notifications" ) ;
758+ json. push_str ( ",diagnostic-short" ) ;
791759 }
760+ cmd. arg ( json) ;
792761 } else {
793762 match cx. bcx . build_config . message_format {
794763 MessageFormat :: Human => ( ) ,
@@ -799,6 +768,13 @@ fn add_error_format(
799768 cmd. arg ( "--error-format" ) . arg ( "short" ) ;
800769 }
801770 }
771+
772+ let color = if cx. bcx . config . shell ( ) . supports_color ( ) {
773+ "always"
774+ } else {
775+ "never"
776+ } ;
777+ cmd. args ( & [ "--color" , color] ) ;
802778 }
803779 Ok ( ( ) )
804780}
@@ -829,8 +805,7 @@ fn build_base_args<'a, 'cfg>(
829805 cmd. arg ( "--crate-name" ) . arg ( & unit. target . crate_name ( ) ) ;
830806
831807 add_path_args ( bcx, unit, cmd) ;
832- add_color ( bcx, cmd) ;
833- add_error_format ( cx, cmd, cx. rmeta_required ( unit) , true ) ?;
808+ add_error_format_and_color ( cx, cmd, cx. rmeta_required ( unit) ) ?;
834809
835810 if !test {
836811 for crate_type in crate_types. iter ( ) {
@@ -1234,11 +1209,11 @@ fn on_stderr_line(
12341209 } else {
12351210 // Remove color information from the rendered string. rustc has not
12361211 // included color in the past, so to avoid breaking anything, strip it
1237- // out when --json-rendered=termcolor is used. This runs
1212+ // out when --json=diagnostic -rendered-ansi is used. This runs
12381213 // unconditionally under the assumption that Cargo will eventually
12391214 // move to this as the default mode. Perhaps in the future, cargo
12401215 // could allow the user to enable/disable color (such as with a
1241- // `--json-rendered ` or `--color` or `--message-format` flag).
1216+ // `--json` or `--color` or `--message-format` flag).
12421217 #[ derive( serde:: Deserialize , serde:: Serialize ) ]
12431218 struct CompilerMessage {
12441219 rendered : String ,
@@ -1304,10 +1279,8 @@ fn replay_output_cache(
13041279) -> Work {
13051280 let target = target. clone ( ) ;
13061281 let extract_rendered_messages = match format {
1307- MessageFormat :: Human => true ,
1282+ MessageFormat :: Human | MessageFormat :: Short => true ,
13081283 MessageFormat :: Json => false ,
1309- // FIXME: short not supported.
1310- MessageFormat :: Short => false ,
13111284 } ;
13121285 let mut options = OutputOptions {
13131286 extract_rendered_messages,
0 commit comments