From 647945077235a0fa40b363a616280b3b093b16b1 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 21 Oct 2024 12:33:49 -0700 Subject: [PATCH 1/2] mdbook-spec: Fix Spec::new visibility In https://github.com/rust-lang/reference/pull/1646 I accidentally changed the visibility of `Spec::new`. It needs to be `pub` in order to work in the upstream integration. --- mdbook-spec/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdbook-spec/src/lib.rs b/mdbook-spec/src/lib.rs index e55935023..3b1f32e29 100644 --- a/mdbook-spec/src/lib.rs +++ b/mdbook-spec/src/lib.rs @@ -57,7 +57,7 @@ pub struct Spec { } impl Spec { - fn new() -> Result { + pub fn new() -> Result { 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); if deny_warnings && rust_root.is_none() { From f9132d9635cae08e4c2cd94e3080eaf93b549ef3 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 21 Oct 2024 13:06:39 -0700 Subject: [PATCH 2/2] Add ability to set the rust root directory via the API This adds the ability to set the rust_root via `Spec::new` so that the upstream tool can more easily set this value (since env vars are a little awkward). --- mdbook-spec/src/lib.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mdbook-spec/src/lib.rs b/mdbook-spec/src/lib.rs index 3b1f32e29..27a6d807d 100644 --- a/mdbook-spec/src/lib.rs +++ b/mdbook-spec/src/lib.rs @@ -23,7 +23,7 @@ static ADMONITION_RE: Lazy = 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)?; @@ -57,9 +57,16 @@ pub struct Spec { } impl Spec { - pub fn new() -> Result { + /// 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) -> Result { 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"); }