@@ -551,49 +551,6 @@ fn doc_std(
551551 extra_args : & [ & OsStr ] ,
552552 requested_crates : & [ String ] ,
553553) {
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-
597554 builder. info ( & format ! (
598555 "Documenting stage{} std ({}) in {} format" ,
599556 stage,
@@ -607,15 +564,22 @@ fn doc_std(
607564 ) ;
608565 }
609566 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+
610572 // This is directory where the compiler will place the output of the command.
611573 // We will then copy the files from this directory into the final `out` directory, the specified
612574 // 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" ) ;
614576
615577 let run_cargo_rustdoc_for = |package : & str | {
616578 let mut cargo = builder. cargo ( compiler, Mode :: Std , SourceType :: InTree , target, "rustdoc" ) ;
617579 compile:: std_cargo ( builder, target, compiler. stage , & mut cargo) ;
618580 cargo
581+ . arg ( "--target-dir" )
582+ . arg ( & * target_dir. to_string_lossy ( ) )
619583 . arg ( "-p" )
620584 . arg ( package)
621585 . arg ( "-Zskip-rustdoc-fingerprint" )
@@ -636,9 +600,7 @@ fn doc_std(
636600 }
637601 }
638602
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) ;
642604}
643605
644606#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
0 commit comments