@@ -551,49 +551,6 @@ fn doc_std(
551
551
extra_args : & [ & OsStr ] ,
552
552
requested_crates : & [ String ] ,
553
553
) {
554
- // `cargo` uses the same directory for both JSON docs and HTML docs.
555
- // This could lead to cross-contamination when copying files into the specified `out` directory.
556
- // For example:
557
- // ```bash
558
- // x doc std
559
- // x doc std --json
560
- // ```
561
- // could lead to HTML docs being copied into the JSON docs output directory.
562
- // To avoid this issue, we copy generated docs instead of whole directory by
563
- // checking doc format and generated files.
564
- fn cp_docs_by_doc_format (
565
- format : & DocumentationFormat ,
566
- builder : & Builder < ' _ > ,
567
- src : & Path ,
568
- dst : & Path ,
569
- ) {
570
- for f in builder. read_dir ( src) {
571
- let path = f. path ( ) ;
572
- let name = path. file_name ( ) . unwrap ( ) ;
573
- let dst = dst. join ( name) ;
574
-
575
- if t ! ( f. file_type( ) ) . is_dir ( ) && format == & DocumentationFormat :: HTML {
576
- t ! ( fs:: create_dir_all( & dst) ) ;
577
- cp_docs_by_doc_format ( format, builder, & path, & dst) ;
578
- } else {
579
- let _ = fs:: remove_file ( & dst) ;
580
- let extension = path. extension ( ) . and_then ( OsStr :: to_str) ;
581
-
582
- match format {
583
- DocumentationFormat :: HTML if extension != Some ( "json" ) => {
584
- builder. copy ( & path, & dst)
585
- }
586
- DocumentationFormat :: JSON
587
- if extension == Some ( "json" ) || name. to_str ( ) == Some ( ".stamp" ) =>
588
- {
589
- builder. copy ( & path, & dst)
590
- }
591
- _ => { }
592
- }
593
- }
594
- }
595
- }
596
-
597
554
builder. info ( & format ! (
598
555
"Documenting stage{} std ({}) in {} format" ,
599
556
stage,
@@ -607,15 +564,22 @@ fn doc_std(
607
564
) ;
608
565
}
609
566
let compiler = builder. compiler ( stage, builder. config . build ) ;
567
+
568
+ let target_doc_dir_name = if format == DocumentationFormat :: JSON { "json-doc" } else { "doc" } ;
569
+ let target_dir =
570
+ builder. stage_out ( compiler, Mode :: Std ) . join ( target. triple ) . join ( target_doc_dir_name) ;
571
+
610
572
// This is directory where the compiler will place the output of the command.
611
573
// We will then copy the files from this directory into the final `out` directory, the specified
612
574
// as a function parameter.
613
- let out_dir = builder . stage_out ( compiler , Mode :: Std ) . join ( target. triple ) . join ( "doc" ) ;
575
+ let out_dir = target_dir . join ( target. triple ) . join ( "doc" ) ;
614
576
615
577
let run_cargo_rustdoc_for = |package : & str | {
616
578
let mut cargo = builder. cargo ( compiler, Mode :: Std , SourceType :: InTree , target, "rustdoc" ) ;
617
579
compile:: std_cargo ( builder, target, compiler. stage , & mut cargo) ;
618
580
cargo
581
+ . arg ( "--target-dir" )
582
+ . arg ( & * target_dir. to_string_lossy ( ) )
619
583
. arg ( "-p" )
620
584
. arg ( package)
621
585
. arg ( "-Zskip-rustdoc-fingerprint" )
@@ -636,9 +600,7 @@ fn doc_std(
636
600
}
637
601
}
638
602
639
- if !builder. config . dry_run ( ) {
640
- cp_docs_by_doc_format ( & format, builder, & out_dir, & out) ;
641
- }
603
+ builder. cp_r ( & out_dir, & out) ;
642
604
}
643
605
644
606
#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
0 commit comments