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