Skip to content

Commit 5194f73

Browse files
Rename book_location into book_source and add a new field to store the target location
1 parent d265210 commit 5194f73

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

src/librustdoc/config.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,10 @@ pub(crate) struct RenderOptions {
321321
pub(crate) parts_out_dir: Option<PathToParts>,
322322
/// disable minification of CSS/JS
323323
pub(crate) disable_minification: bool,
324-
/// Location where the associated book is located.
325-
pub(crate) book_location: Option<PathOrUrl>,
324+
/// Location where the associated book source is located.
325+
pub(crate) book_source: Option<PathOrUrl>,
326+
/// Location where the associated book is generated. None if it's not local.
327+
pub(crate) book_target: Option<PathOrUrl>,
326328
}
327329

328330
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -826,7 +828,7 @@ impl Options {
826828
rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref());
827829

828830
let disable_minification = matches.opt_present("disable-minification");
829-
let book_location = matches.opt_str("book-location").map(PathOrUrl::new);
831+
let book_source = matches.opt_str("book-location").map(PathOrUrl::new);
830832

831833
let options = Options {
832834
bin_crate,
@@ -905,7 +907,9 @@ impl Options {
905907
include_parts_dir,
906908
parts_out_dir,
907909
disable_minification,
908-
book_location,
910+
book_source,
911+
// This field is updated in `generate_book`.
912+
book_target: None,
909913
};
910914
Some((input, options, render_options))
911915
}

src/librustdoc/html/render/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub(crate) struct SharedContext<'tcx> {
146146
/// Controls whether we read / write to cci files in the doc root. Defaults read=true,
147147
/// write=true
148148
should_merge: ShouldMerge,
149-
pub(crate) book_location: Option<crate::config::PathOrUrl>,
149+
pub(crate) book_target: Option<crate::config::PathOrUrl>,
150150
}
151151

152152
impl SharedContext<'_> {
@@ -490,7 +490,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
490490
call_locations,
491491
no_emit_shared,
492492
html_no_source,
493-
book_location,
493+
book_target,
494494
..
495495
} = options;
496496

@@ -577,7 +577,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
577577
cache,
578578
call_locations,
579579
should_merge: options.should_merge,
580-
book_location,
580+
book_target,
581581
};
582582

583583
let dst = output;
@@ -649,7 +649,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
649649
parent_is_crate: false,
650650
blocks: vec![blocks],
651651
path: String::new(),
652-
book_location: shared.book_location.as_ref(),
652+
book_location: shared.book_target.as_ref(),
653653
};
654654

655655
bar.render_into(&mut sidebar).unwrap();

src/librustdoc/html/render/sidebar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Str
195195
parent_is_crate: sidebar_path.len() == 1,
196196
blocks,
197197
path,
198-
book_location: cx.shared.book_location.as_ref(),
198+
book_location: cx.shared.book_target.as_ref(),
199199
};
200200
sidebar.render_into(buffer).unwrap();
201201
}

src/librustdoc/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,12 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>(
760760
}
761761

762762
fn generate_book(render_options: &mut config::RenderOptions) -> Result<(), String> {
763-
let Some(config::PathOrUrl::Path(ref mut book_dir)) = render_options.book_location else {
764-
return Ok(());
763+
let book_dir = match &render_options.book_source {
764+
Some(config::PathOrUrl::Path(book_dir)) => book_dir,
765+
other => {
766+
render_options.book_target = other.clone();
767+
return Ok(());
768+
}
765769
};
766770
if !book_dir.is_dir() {
767771
return Err(format!(
@@ -774,14 +778,15 @@ fn generate_book(render_options: &mut config::RenderOptions) -> Result<(), Strin
774778
Err(error) => return Err(format!("failed to load book: {error:?}")),
775779
};
776780
let output_dir = render_options.output.join("doc-book");
777-
*book_dir = output_dir.join("index.html");
781+
let book_target = output_dir.join("index.html");
778782
book.config.build.build_dir = output_dir;
779783
if let Err(error) = book.build() {
780784
return Err(format!(
781785
"failed to generate book into `{}`: {error:?}",
782786
book.config.build.build_dir.display()
783787
));
784788
}
789+
render_options.book_target = Some(config::PathOrUrl::Path(book_target));
785790
Ok(())
786791
}
787792

0 commit comments

Comments
 (0)