Skip to content

Commit 543810c

Browse files
authored
Merge pull request #1658 from ehuss/spec-pub
mdbook-spec: Fix Spec::new creation
2 parents 8676ab7 + f9132d9 commit 543810c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

mdbook-spec/src/lib.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static ADMONITION_RE: Lazy<Regex> = Lazy::new(|| {
2323
});
2424

2525
pub fn handle_preprocessing() -> Result<(), Error> {
26-
let pre = Spec::new()?;
26+
let pre = Spec::new(None)?;
2727
let (ctx, book) = CmdPreprocessor::parse_input(io::stdin())?;
2828

2929
let book_version = Version::parse(&ctx.mdbook_version)?;
@@ -57,9 +57,16 @@ pub struct Spec {
5757
}
5858

5959
impl Spec {
60-
fn new() -> Result<Spec> {
60+
/// Creates a new `Spec` preprocessor.
61+
///
62+
/// The `rust_root` parameter specifies an optional path to the root of
63+
/// the rust git checkout. If `None`, it will use the `SPEC_RUST_ROOT`
64+
/// environment variable. If the root is not specified, then no tests will
65+
/// be linked unless `SPEC_DENY_WARNINGS` is set in which case this will
66+
/// return an error..
67+
pub fn new(rust_root: Option<PathBuf>) -> Result<Spec> {
6168
let deny_warnings = std::env::var("SPEC_DENY_WARNINGS").as_deref() == Ok("1");
62-
let rust_root = std::env::var_os("SPEC_RUST_ROOT").map(PathBuf::from);
69+
let rust_root = rust_root.or_else(|| std::env::var_os("SPEC_RUST_ROOT").map(PathBuf::from));
6370
if deny_warnings && rust_root.is_none() {
6471
bail!("SPEC_RUST_ROOT environment variable must be set");
6572
}

0 commit comments

Comments
 (0)