@@ -696,8 +696,13 @@ fn prepare_rustc(cx: &Context<'_, '_>, unit: &Unit) -> CargoResult<ProcessBuilde
696
696
Ok ( base)
697
697
}
698
698
699
- /// Creates a unit of work invoking `rustdoc` for documenting the `unit`.
700
- fn rustdoc ( cx : & mut Context < ' _ , ' _ > , unit : & Unit ) -> CargoResult < Work > {
699
+ /// Prepares flags and environments we can compute for a `rustdoc` invocation
700
+ /// before the job queue starts compiling any unit.
701
+ ///
702
+ /// This builds a static view of the invocation. Flags depending on the
703
+ /// completion of other units will be added later in runtime, such as flags
704
+ /// from build scripts.
705
+ fn prepare_rustdoc ( cx : & Context < ' _ , ' _ > , unit : & Unit ) -> CargoResult < ProcessBuilder > {
701
706
let bcx = cx. bcx ;
702
707
// script_metadata is not needed here, it is only for tests.
703
708
let mut rustdoc = cx. compilation . rustdoc_process ( unit, None ) ?;
@@ -711,12 +716,6 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
711
716
rustdoc. arg ( "--target" ) . arg ( target. rustc_target ( ) ) ;
712
717
}
713
718
let doc_dir = cx. files ( ) . out_dir ( unit) ;
714
-
715
- // Create the documentation directory ahead of time as rustdoc currently has
716
- // a bug where concurrent invocations will race to create this directory if
717
- // it doesn't already exist.
718
- paths:: create_dir_all ( & doc_dir) ?;
719
-
720
719
rustdoc. arg ( "-o" ) . arg ( & doc_dir) ;
721
720
rustdoc. args ( & features_args ( unit) ) ;
722
721
rustdoc. args ( & check_cfg_args ( cx, unit) ) ;
@@ -732,10 +731,6 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
732
731
let metadata = cx. metadata_for_doc_units [ unit] ;
733
732
rustdoc. arg ( "-C" ) . arg ( format ! ( "metadata={}" , metadata) ) ;
734
733
735
- let scrape_output_path = |unit : & Unit | -> CargoResult < PathBuf > {
736
- cx. outputs ( unit) . map ( |outputs| outputs[ 0 ] . path . clone ( ) )
737
- } ;
738
-
739
734
if unit. mode . is_doc_scrape ( ) {
740
735
debug_assert ! ( cx. bcx. scrape_units. contains( unit) ) ;
741
736
@@ -747,7 +742,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
747
742
748
743
rustdoc
749
744
. arg ( "--scrape-examples-output-path" )
750
- . arg ( scrape_output_path ( unit) ?) ;
745
+ . arg ( scrape_output_path ( cx , unit) ?) ;
751
746
752
747
// Only scrape example for items from crates in the workspace, to reduce generated file size
753
748
for pkg in cx. bcx . ws . members ( ) {
@@ -762,21 +757,9 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
762
757
}
763
758
}
764
759
765
- let should_include_scrape_units = unit. mode . is_doc ( )
766
- && cx. bcx . scrape_units . len ( ) > 0
767
- && cx. bcx . ws . unit_needs_doc_scrape ( unit) ;
768
- let scrape_outputs = if should_include_scrape_units {
760
+ if should_include_scrape_units ( cx. bcx , unit) {
769
761
rustdoc. arg ( "-Zunstable-options" ) ;
770
- Some (
771
- cx. bcx
772
- . scrape_units
773
- . iter ( )
774
- . map ( |unit| Ok ( ( cx. files ( ) . metadata ( unit) , scrape_output_path ( unit) ?) ) )
775
- . collect :: < CargoResult < HashMap < _ , _ > > > ( ) ?,
776
- )
777
- } else {
778
- None
779
- } ;
762
+ }
780
763
781
764
build_deps_args ( & mut rustdoc, cx, unit) ?;
782
765
rustdoc:: add_root_urls ( cx, unit, & mut rustdoc) ?;
@@ -787,6 +770,20 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
787
770
append_crate_version_flag ( unit, & mut rustdoc) ;
788
771
}
789
772
773
+ Ok ( rustdoc)
774
+ }
775
+
776
+ /// Creates a unit of work invoking `rustdoc` for documenting the `unit`.
777
+ fn rustdoc ( cx : & mut Context < ' _ , ' _ > , unit : & Unit ) -> CargoResult < Work > {
778
+ let mut rustdoc = prepare_rustdoc ( cx, unit) ?;
779
+
780
+ let crate_name = unit. target . crate_name ( ) ;
781
+ let doc_dir = cx. files ( ) . out_dir ( unit) ;
782
+ // Create the documentation directory ahead of time as rustdoc currently has
783
+ // a bug where concurrent invocations will race to create this directory if
784
+ // it doesn't already exist.
785
+ paths:: create_dir_all ( & doc_dir) ?;
786
+
790
787
let target_desc = unit. target . description_named ( ) ;
791
788
let name = unit. pkg . name ( ) . to_string ( ) ;
792
789
let build_script_outputs = Arc :: clone ( & cx. build_script_outputs ) ;
@@ -795,6 +792,17 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
795
792
let target = Target :: clone ( & unit. target ) ;
796
793
let mut output_options = OutputOptions :: new ( cx, unit) ;
797
794
let script_metadata = cx. find_build_script_metadata ( unit) ;
795
+ let scrape_outputs = if should_include_scrape_units ( cx. bcx , unit) {
796
+ Some (
797
+ cx. bcx
798
+ . scrape_units
799
+ . iter ( )
800
+ . map ( |unit| Ok ( ( cx. files ( ) . metadata ( unit) , scrape_output_path ( cx, unit) ?) ) )
801
+ . collect :: < CargoResult < HashMap < _ , _ > > > ( ) ?,
802
+ )
803
+ } else {
804
+ None
805
+ } ;
798
806
799
807
let failed_scrape_units = Arc :: clone ( & cx. failed_scrape_units ) ;
800
808
let hide_diagnostics_for_scrape_unit = cx. bcx . unit_can_fail_for_docscraping ( unit)
@@ -1774,3 +1782,14 @@ fn apply_env_config(config: &crate::Config, cmd: &mut ProcessBuilder) -> CargoRe
1774
1782
}
1775
1783
Ok ( ( ) )
1776
1784
}
1785
+
1786
+ /// Checks if there are some scrape units waiting to be processed.
1787
+ fn should_include_scrape_units ( bcx : & BuildContext < ' _ , ' _ > , unit : & Unit ) -> bool {
1788
+ unit. mode . is_doc ( ) && bcx. scrape_units . len ( ) > 0 && bcx. ws . unit_needs_doc_scrape ( unit)
1789
+ }
1790
+
1791
+ /// Gets the file path of function call information output from `rustdoc`.
1792
+ fn scrape_output_path ( cx : & Context < ' _ , ' _ > , unit : & Unit ) -> CargoResult < PathBuf > {
1793
+ assert ! ( unit. mode. is_doc( ) || unit. mode. is_doc_scrape( ) ) ;
1794
+ cx. outputs ( unit) . map ( |outputs| outputs[ 0 ] . path . clone ( ) )
1795
+ }
0 commit comments