@@ -594,42 +594,54 @@ pub fn create_bcx<'a, 'cfg>(
594
594
}
595
595
596
596
if let Some ( filter) = rustdoc_scrape_examples {
597
- let compile_mode = CompileMode :: Doc { deps : false } ;
598
- let mut example_compile_opts = CompileOptions :: new ( ws. config ( ) , compile_mode) ?;
599
- example_compile_opts. cli_features = options. cli_features . clone ( ) ;
600
- example_compile_opts. build_config . mode = compile_mode;
601
- example_compile_opts. spec = Packages :: All ;
602
- example_compile_opts. filter = filter. clone ( ) ;
603
- example_compile_opts. rustdoc_scrape_examples = None ;
604
-
605
- let exec: Arc < dyn Executor > = Arc :: new ( DefaultExecutor ) ;
606
- let interner = UnitInterner :: new ( ) ;
607
- let mut bcx = create_bcx ( ws, & example_compile_opts, & interner) ?;
608
- let dest = bcx. profiles . get_dir_name ( ) ;
597
+ // Run cargo rustdoc --scrape-examples to generate calls.jsons for each file in `filter`
609
598
let paths = {
610
- // FIXME(wcrichto): is there a better place to store these files?
611
- let layout = Layout :: new ( ws, None , & dest) ?;
612
- let output_dir = layout. prepare_tmp ( ) ?;
613
- bcx. roots
614
- . iter ( )
615
- . map ( |unit| output_dir. join ( format ! ( "{}-calls.json" , unit. buildkey( ) ) ) )
616
- . collect :: < Vec < _ > > ( )
617
- } ;
599
+ // Run in doc mode with the given `filter`
600
+ let compile_mode = CompileMode :: Doc { deps : false } ;
601
+ let mut example_compile_opts = CompileOptions :: new ( ws. config ( ) , compile_mode) ?;
602
+ example_compile_opts. cli_features = options. cli_features . clone ( ) ;
603
+ example_compile_opts. build_config . mode = compile_mode;
604
+ example_compile_opts. spec = Packages :: All ;
605
+ example_compile_opts. filter = filter. clone ( ) ;
606
+ example_compile_opts. rustdoc_scrape_examples = None ;
607
+
608
+ // Setup recursive Cargo context
609
+ let exec: Arc < dyn Executor > = Arc :: new ( DefaultExecutor ) ;
610
+ let interner = UnitInterner :: new ( ) ;
611
+ let mut bcx = create_bcx ( ws, & example_compile_opts, & interner) ?;
612
+
613
+ // Make an output path for calls.json for each build unit
614
+ let paths = {
615
+ // FIXME(wcrichto): is there a better place to store these files?
616
+ let dest = bcx. profiles . get_dir_name ( ) ;
617
+ let layout = Layout :: new ( ws, None , & dest) ?;
618
+ let output_dir = layout. prepare_tmp ( ) ?;
619
+ bcx. roots
620
+ . iter ( )
621
+ . map ( |unit| output_dir. join ( format ! ( "{}-calls.json" , unit. buildkey( ) ) ) )
622
+ . collect :: < Vec < _ > > ( )
623
+ } ;
618
624
619
- for ( path, unit) in paths. iter ( ) . zip ( bcx. roots . iter ( ) ) {
620
- bcx. extra_compiler_args
621
- . entry ( unit. clone ( ) )
622
- . or_insert_with ( Vec :: new)
623
- . extend_from_slice ( & [
624
- "-Zunstable-options" . into ( ) ,
625
- "--scrape-examples" . into ( ) ,
626
- path. clone ( ) . into_os_string ( ) ,
627
- ] ) ;
628
- }
625
+ // Add --scrape-examples to each build unit's rustdoc args
626
+ for ( path, unit) in paths. iter ( ) . zip ( bcx. roots . iter ( ) ) {
627
+ bcx. extra_compiler_args
628
+ . entry ( unit. clone ( ) )
629
+ . or_insert_with ( Vec :: new)
630
+ . extend_from_slice ( & [
631
+ "-Zunstable-options" . into ( ) ,
632
+ "--scrape-examples" . into ( ) ,
633
+ path. clone ( ) . into_os_string ( ) ,
634
+ ] ) ;
635
+ }
629
636
630
- let cx = Context :: new ( & bcx) ?;
631
- cx. compile ( & exec) ?;
637
+ // Invoke recursive Cargo
638
+ let cx = Context :: new ( & bcx) ?;
639
+ cx. compile ( & exec) ?;
640
+
641
+ paths
642
+ } ;
632
643
644
+ // Add "--with-examples *-calls.json" to the current rustdoc invocation
633
645
let args = paths
634
646
. into_iter ( )
635
647
. map ( |path| vec ! [ "--with-examples" . into( ) , path. into_os_string( ) ] . into_iter ( ) )
0 commit comments