@@ -132,6 +132,8 @@ pub(crate) struct SharedContext<'tcx> {
132132 pub ( crate ) cache : Cache ,
133133
134134 pub ( crate ) call_locations : AllCallLocations ,
135+ /// Controls whether we write to the doc root. Default is true from cli.
136+ write_rendered_cci : bool ,
135137}
136138
137139impl SharedContext < ' _ > {
@@ -553,6 +555,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
553555 span_correspondence_map : matches,
554556 cache,
555557 call_locations,
558+ write_rendered_cci : options. write_rendered_cci ,
556559 } ;
557560
558561 let dst = output;
@@ -640,92 +643,99 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
640643 ) ;
641644 shared. fs . write ( final_file, v) ?;
642645
643- // Generating settings page.
644- page. title = "Settings" ;
645- page. description = "Settings of Rustdoc" ;
646- page. root_path = "./" ;
647- page. rust_logo = true ;
646+ // if to avoid writing files to doc root unless we're on the final invocation
647+ if shared. write_rendered_cci {
648+ // Generating settings page.
649+ page. title = "Settings" ;
650+ page. description = "Settings of Rustdoc" ;
651+ page. root_path = "./" ;
652+ page. rust_logo = true ;
648653
649- let sidebar = "<h2 class=\" location\" >Settings</h2><div class=\" sidebar-elems\" ></div>" ;
650- let v = layout:: render (
651- & shared. layout ,
652- & page,
653- sidebar,
654- |buf : & mut Buffer | {
655- write ! (
656- buf,
657- "<div class=\" main-heading\" >\
658- <h1>Rustdoc settings</h1>\
659- <span class=\" out-of-band\" >\
660- <a id=\" back\" href=\" javascript:void(0)\" onclick=\" history.back();\" >\
661- Back\
662- </a>\
663- </span>\
664- </div>\
665- <noscript>\
666- <section>\
667- You need to enable JavaScript be able to update your settings.\
668- </section>\
669- </noscript>\
670- <script defer src=\" {static_root_path}{settings_js}\" ></script>",
671- static_root_path = page. get_static_root_path( ) ,
672- settings_js = static_files:: STATIC_FILES . settings_js,
673- ) ;
674- // Pre-load all theme CSS files, so that switching feels seamless.
675- //
676- // When loading settings.html as a popover, the equivalent HTML is
677- // generated in main.js.
678- for file in & shared. style_files {
679- if let Ok ( theme) = file. basename ( ) {
680- write ! (
681- buf,
682- "<link rel=\" preload\" href=\" {root_path}{theme}{suffix}.css\" \
683- as=\" style\" >",
684- root_path = page. static_root_path. unwrap_or( "" ) ,
685- suffix = page. resource_suffix,
686- ) ;
654+ let sidebar = "<h2 class=\" location\" >Settings</h2><div class=\" sidebar-elems\" ></div>" ;
655+ let v = layout:: render (
656+ & shared. layout ,
657+ & page,
658+ sidebar,
659+ |buf : & mut Buffer | {
660+ write ! (
661+ buf,
662+ "<div class=\" main-heading\" >\
663+ <h1>Rustdoc settings</h1>\
664+ <span class=\" out-of-band\" >\
665+ <a id=\" back\" href=\" javascript:void(0)\" onclick=\" history.back();\" >\
666+ Back\
667+ </a>\
668+ </span>\
669+ </div>\
670+ <noscript>\
671+ <section>\
672+ You need to enable JavaScript be able to update your settings.\
673+ </section>\
674+ </noscript>\
675+ <script defer src=\" {static_root_path}{settings_js}\" ></script>",
676+ static_root_path = page. get_static_root_path( ) ,
677+ settings_js = static_files:: STATIC_FILES . settings_js,
678+ ) ;
679+ // Pre-load all theme CSS files, so that switching feels seamless.
680+ //
681+ // When loading settings.html as a popover, the equivalent HTML is
682+ // generated in main.js.
683+ for file in & shared. style_files {
684+ if let Ok ( theme) = file. basename ( ) {
685+ write ! (
686+ buf,
687+ "<link rel=\" preload\" href=\" {root_path}{theme}{suffix}.css\" \
688+ as=\" style\" >",
689+ root_path = page. static_root_path. unwrap_or( "" ) ,
690+ suffix = page. resource_suffix,
691+ ) ;
692+ }
687693 }
688- }
689- } ,
690- & shared . style_files ,
691- ) ;
692- shared . fs . write ( settings_file , v ) ? ;
694+ } ,
695+ & shared . style_files ,
696+ ) ;
697+ shared . fs . write ( settings_file , v ) ? ;
698+ }
693699
694- // Generating help page.
695- page. title = "Help" ;
696- page. description = "Documentation for Rustdoc" ;
697- page. root_path = "./" ;
698- page. rust_logo = true ;
700+ // if to avoid writing files to doc root unless we're on the final invocation
701+ if shared. write_rendered_cci {
702+ // Generating help page.
703+ page. title = "Help" ;
704+ page. description = "Documentation for Rustdoc" ;
705+ page. root_path = "./" ;
706+ page. rust_logo = true ;
699707
700- let sidebar = "<h2 class=\" location\" >Help</h2><div class=\" sidebar-elems\" ></div>" ;
701- let v = layout:: render (
702- & shared. layout ,
703- & page,
704- sidebar,
705- |buf : & mut Buffer | {
706- write ! (
707- buf,
708- "<div class=\" main-heading\" >\
709- <h1>Rustdoc help</h1>\
710- <span class=\" out-of-band\" >\
711- <a id=\" back\" href=\" javascript:void(0)\" onclick=\" history.back();\" >\
712- Back\
713- </a>\
714- </span>\
715- </div>\
716- <noscript>\
717- <section>\
718- <p>You need to enable JavaScript to use keyboard commands or search.</p>\
719- <p>For more information, browse the <a href=\" https://doc.rust-lang.org/rustdoc/\" >rustdoc handbook</a>.</p>\
720- </section>\
721- </noscript>",
722- )
723- } ,
724- & shared. style_files ,
725- ) ;
726- shared. fs . write ( help_file, v) ?;
708+ let sidebar = "<h2 class=\" location\" >Help</h2><div class=\" sidebar-elems\" ></div>" ;
709+ let v = layout:: render (
710+ & shared. layout ,
711+ & page,
712+ sidebar,
713+ |buf : & mut Buffer | {
714+ write ! (
715+ buf,
716+ "<div class=\" main-heading\" >\
717+ <h1>Rustdoc help</h1>\
718+ <span class=\" out-of-band\" >\
719+ <a id=\" back\" href=\" javascript:void(0)\" onclick=\" history.back();\" >\
720+ Back\
721+ </a>\
722+ </span>\
723+ </div>\
724+ <noscript>\
725+ <section>\
726+ <p>You need to enable JavaScript to use keyboard commands or search.</p>\
727+ <p>For more information, browse the <a href=\" https://doc.rust-lang.org/rustdoc/\" >rustdoc handbook</a>.</p>\
728+ </section>\
729+ </noscript>",
730+ )
731+ } ,
732+ & shared. style_files ,
733+ ) ;
734+ shared. fs . write ( help_file, v) ?;
735+ }
727736
728- if shared. layout . scrape_examples_extension {
737+ // if to avoid writing files to doc root unless we're on the final invocation
738+ if shared. layout . scrape_examples_extension && shared. write_rendered_cci {
729739 page. title = "About scraped examples" ;
730740 page. description = "How the scraped examples feature works in Rustdoc" ;
731741 let v = layout:: render (
0 commit comments