Skip to content

Commit

Permalink
[wip] Update boostrap tests to support book dependencies
Browse files Browse the repository at this point in the history
Since TRPL now depends on a `trpl` crate, the test needs to be able to
build that crate to run mdbook against it, and also to invoke mdbook
with `--library-path` in that case.

Still to-do:

- [ ] Validate the correct argument form for `--library-path`.
- [ ] Test this to make sure it works (!) and that it does not generate
      any extra noise during build.
  • Loading branch information
chriskrycho committed Oct 18, 2024
1 parent daa8e32 commit a242ded
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,7 @@ struct BookTest {
path: PathBuf,
name: &'static str,
is_ext_doc: bool,
cli_args: Vec<&'static str>,
}

impl Step for BookTest {
Expand Down Expand Up @@ -2223,6 +2224,11 @@ impl BookTest {
// Books often have feature-gated example text.
rustbook_cmd.env("RUSTC_BOOTSTRAP", "1");
rustbook_cmd.env("PATH", new_path).arg("test").arg(path);

if !self.cli_args.is_empty() {
rustbook_cmd.args(self.cli_args);
}

builder.add_rust_test_threads(&mut rustbook_cmd);
let _guard = builder.msg(
Kind::Test,
Expand Down Expand Up @@ -2281,6 +2287,7 @@ macro_rules! test_book {
$name:ident, $path:expr, $book_name:expr,
default=$default:expr
$(,submodules = $submodules:expr)?
$(,dependencies=$dependencies:expr)?
;
)+) => {
$(
Expand Down Expand Up @@ -2310,11 +2317,33 @@ macro_rules! test_book {
builder.require_submodule(submodule, None);
}
)*

let dependencies = vec![];
let cli_args = vec![];
$(
let mut dependencies = dependencies;
let mut cli_args = cli_args;
for dep in $dependencies {
dependencies.push(dep.into_string());
}

if !dependencies.is_empty() {
cli_args.push("--library-path");
cli_args.extend(
dependencies
.iter()
.map(|dep| format!("{dep}/target/debug/deps"))
.collect()
);
}
)?

builder.ensure(BookTest {
compiler: self.compiler,
path: PathBuf::from($path),
name: $book_name,
is_ext_doc: !$default,
cli_args,
});
}
}
Expand All @@ -2329,7 +2358,7 @@ test_book!(
RustcBook, "src/doc/rustc", "rustc", default=true;
RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false, submodules=["src/doc/rust-by-example"];
EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false, submodules=["src/doc/embedded-book"];
TheBook, "src/doc/book", "book", default=false, submodules=["src/doc/book"];
TheBook, "src/doc/book", "book", default=false, submodules=["src/doc/book"], dependencies=["src/doc/book/packages/trpl"];
UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
EditionGuide, "src/doc/edition-guide", "edition-guide", default=false, submodules=["src/doc/edition-guide"];
);
Expand Down

0 comments on commit a242ded

Please sign in to comment.