@@ -49,6 +49,8 @@ use crate::util::machine_message::Message;
49
49
use crate :: util:: { self , machine_message, ProcessBuilder } ;
50
50
use crate :: util:: { internal, join_paths, paths, profile} ;
51
51
52
+ const RUSTDOC_CRATE_VERSION_FLAG : & str = "--crate-version" ;
53
+
52
54
/// A glorified callback for executing calls to rustc. Rather than calling rustc
53
55
/// directly, we'll use an `Executor`, giving clients an opportunity to intercept
54
56
/// the build calls.
@@ -562,7 +564,6 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
562
564
let mut rustdoc = cx. compilation . rustdoc_process ( unit. pkg , unit. target ) ?;
563
565
rustdoc. inherit_jobserver ( & cx. jobserver ) ;
564
566
rustdoc. arg ( "--crate-name" ) . arg ( & unit. target . crate_name ( ) ) ;
565
- add_crate_versions_if_requested ( bcx, unit, & mut rustdoc) ;
566
567
add_path_args ( bcx, unit, & mut rustdoc) ;
567
568
add_cap_lints ( bcx, unit, & mut rustdoc) ;
568
569
@@ -593,6 +594,8 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
593
594
594
595
rustdoc. args ( bcx. rustdocflags_args ( unit) ) ;
595
596
597
+ add_crate_versions_if_requested ( bcx, unit, & mut rustdoc) ;
598
+
596
599
let name = unit. pkg . name ( ) . to_string ( ) ;
597
600
let build_script_outputs = Arc :: clone ( & cx. build_script_outputs ) ;
598
601
let package_id = unit. pkg . package_id ( ) ;
@@ -629,19 +632,31 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
629
632
} ) )
630
633
}
631
634
632
- fn add_crate_versions_if_requested (
633
- bcx : & BuildContext < ' _ , ' _ > ,
634
- unit : & Unit < ' _ > ,
635
+ fn add_crate_versions_if_requested < ' a > (
636
+ bcx : & BuildContext < ' a , ' _ > ,
637
+ unit : & Unit < ' a > ,
635
638
rustdoc : & mut ProcessBuilder ,
636
639
) {
637
- if ! bcx. config . cli_unstable ( ) . crate_versions {
638
- return ;
640
+ if bcx. config . cli_unstable ( ) . crate_versions && ! crate_version_flag_already_present ( rustdoc ) {
641
+ append_crate_version_flag ( unit , rustdoc ) ;
639
642
}
643
+ }
644
+
645
+ // The --crate-version flag could have already been passed in RUSTDOCFLAGS
646
+ // or as an extra compiler argument for rustdoc
647
+ fn crate_version_flag_already_present ( rustdoc : & ProcessBuilder ) -> bool {
648
+ rustdoc. get_args ( ) . iter ( ) . any ( |flag| {
649
+ flag. to_str ( )
650
+ . map_or ( false , |flag| flag. starts_with ( RUSTDOC_CRATE_VERSION_FLAG ) )
651
+ } )
652
+ }
653
+
654
+ fn append_crate_version_flag ( unit : & Unit < ' _ > , rustdoc : & mut ProcessBuilder ) {
640
655
rustdoc
641
656
. arg ( "-Z" )
642
657
. arg ( "unstable-options" )
643
- . arg ( "--crate-version" )
644
- . arg ( & unit. pkg . version ( ) . to_string ( ) ) ;
658
+ . arg ( RUSTDOC_CRATE_VERSION_FLAG )
659
+ . arg ( unit. pkg . version ( ) . to_string ( ) ) ;
645
660
}
646
661
647
662
// The path that we pass to rustc is actually fairly important because it will
0 commit comments