Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mdbook-spec: Fix Spec::new creation #1658

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions mdbook-spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static ADMONITION_RE: Lazy<Regex> = Lazy::new(|| {
});

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

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

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