Skip to content

Commit eda5e44

Browse files
Rename book_location into book_source and add a new field to store the target location
1 parent 1cdcf58 commit eda5e44

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

src/librustdoc/config.rs

+8-4
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

+4-4
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

+1-1
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

+8-3
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,12 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>(
758758
}
759759

760760
fn generate_book(render_options: &mut config::RenderOptions) -> Result<(), String> {
761-
let Some(config::PathOrUrl::Path(ref mut book_dir)) = render_options.book_location else {
762-
return Ok(());
761+
let book_dir = match &render_options.book_source {
762+
Some(config::PathOrUrl::Path(book_dir)) => book_dir,
763+
other => {
764+
render_options.book_target = other.clone();
765+
return Ok(());
766+
}
763767
};
764768
if !book_dir.is_dir() {
765769
return Err(format!(
@@ -772,14 +776,15 @@ fn generate_book(render_options: &mut config::RenderOptions) -> Result<(), Strin
772776
Err(error) => return Err(format!("failed to load book: {error:?}")),
773777
};
774778
let output_dir = render_options.output.join("doc-book");
775-
*book_dir = output_dir.join("index.html");
779+
let book_target = output_dir.join("index.html");
776780
book.config.build.build_dir = output_dir;
777781
if let Err(error) = book.build() {
778782
return Err(format!(
779783
"failed to generate book into `{}`: {error:?}",
780784
book.config.build.build_dir.display()
781785
));
782786
}
787+
render_options.book_target = Some(config::PathOrUrl::Path(book_target));
783788
Ok(())
784789
}
785790

0 commit comments

Comments
 (0)