Skip to content

mdbook: fix support for external repositories - #4027

Merged
UebelAndre merged 1 commit into
bazelbuild:mainfrom
mgeisler:fix-mdbook-external-repository-handling
May 14, 2026
Merged

mdbook: fix support for external repositories#4027
UebelAndre merged 1 commit into
bazelbuild:mainfrom
mgeisler:fix-mdbook-external-repository-handling

Conversation

@mgeisler

@mgeisler mgeisler commented May 9, 2026

Copy link
Copy Markdown
Contributor

When any part of an mdbook target (either the book.toml or the source files) comes from an external repository, the build was failing because the rule's staging logic and its invocation logic handled repository boundaries inconsistently.

This change:

  • Updates _map_inputs in mdbook.bzl to map external repository paths to 'external/' instead of '../'.
  • Hardens the process wrapper with a bounds check to ensure files are not staged outside the shadow work directory.
  • Adds an integration test to verify the fix and prevent regressions.

Made by Gemini, fixes #4026.

When any part of an mdbook target (either the book.toml or the source files)
comes from an external repository, the build was failing because the
rule's staging logic and its invocation logic handled repository
boundaries inconsistently.

This change:
- Updates _map_inputs in mdbook.bzl to map external repository paths
  to 'external/' instead of '../'.
- Hardens the process wrapper with a bounds check to ensure files are
  not staged outside the shadow work directory.
- Adds an integration test to verify the fix and prevent regressions.
@mgeisler

mgeisler commented May 9, 2026

Copy link
Copy Markdown
Contributor Author
  • Updates _map_inputs in mdbook.bzl to map external repository paths to 'external/' instead of '../'.

Please note that I don't know what the idiomatic way to handle such things are. Gemini came up with this and it seems to work based on its new test.

@UebelAndre
UebelAndre self-requested a review May 13, 2026 15:38

@UebelAndre UebelAndre left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thank you!

@UebelAndre
UebelAndre added this pull request to the merge queue May 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 13, 2026
@UebelAndre
UebelAndre added this pull request to the merge queue May 14, 2026
Merged via the queue into bazelbuild:main with commit 2fd7311 May 14, 2026
3 checks passed
mgeisler added a commit to mgeisler/rules_rust that referenced this pull request Jun 6, 2026
…dencies

This is a follow-up to bazelbuild#4027. While bazelbuild#4027 enabled the staging of files
from external repositories, mdBook still requires all configuration,
source files, and themes to sit in a contiguous directory structure.

This change implements path flattening for both build and serve actions:
- Build Action: Strips repository and package prefixes during workdir
  staging in mdbook.bzl.
- Serve Action: Implements conditional staging in server.rs. If files
  are split across repositories, it flattens them into a temporary
  directory using symlinks to preserve live-reloading. Standard books
  run in-place for maximum plugin compatibility.

Includes a new integration test in test/flattening that verifies
resolution across three different packages, and unit tests in
private/server.rs for the staging logic.
mgeisler added a commit to mgeisler/rules_rust that referenced this pull request Jun 10, 2026
…dencies

This is a follow-up to bazelbuild#4027. While bazelbuild#4027 enabled the staging of files
from external repositories, mdBook still requires all configuration,
source files, and themes to sit in a contiguous directory structure.

This change implements path flattening for both build and serve actions:
- Build Action: Strips repository and package prefixes during workdir
  staging in mdbook.bzl.
- Serve Action: Implements conditional staging in server.rs. If files
  are split across repositories, it flattens them into a temporary
  directory using symlinks to preserve live-reloading. Standard books
  run in-place for maximum plugin compatibility.

Includes a new integration test in test/flattening that verifies
resolution across three different packages, and unit tests in
private/server.rs for the staging logic.
mgeisler added a commit to mgeisler/rules_rust that referenced this pull request Jun 10, 2026
…dencies

This is a follow-up to bazelbuild#4027. While bazelbuild#4027 enabled the staging of files
from external repositories, mdBook still requires all configuration,
source files, and themes to sit in a contiguous directory structure.

This change implements path flattening for both build and serve actions:
- Build Action: Strips repository and package prefixes during workdir
  staging in mdbook.bzl.
- Serve Action: Implements conditional staging in server.rs. If files
  are split across repositories, it flattens them into a temporary
  directory using symlinks to preserve live-reloading. Standard books
  run in-place for maximum plugin compatibility.

Includes a new integration test in test/flattening that verifies
resolution across three different packages, and unit tests in
private/server.rs for the staging logic.
mgeisler added a commit to mgeisler/rules_rust that referenced this pull request Jun 10, 2026
…dencies

This is a follow-up to bazelbuild#4027. While bazelbuild#4027 enabled the staging of files
from external repositories, mdBook still requires all configuration,
source files, and themes to sit in a contiguous directory structure.

This change implements path flattening for both build and serve actions:
- Build Action: Strips repository and package prefixes during workdir
  staging in mdbook.bzl.
- Serve Action: Implements conditional staging in server.rs. If files
  are split across repositories, it flattens them into a temporary
  directory using symlinks to preserve live-reloading. Standard books
  run in-place for maximum plugin compatibility.

Includes a new integration test in test/flattening that verifies
resolution across three different packages, and unit tests in
private/server.rs for the staging logic.
mgeisler added a commit to mgeisler/rules_rust that referenced this pull request Jun 11, 2026
…dencies

This is a follow-up to bazelbuild#4027. While bazelbuild#4027 enabled the staging of files
from external repositories, mdBook still requires all configuration,
source files, and themes to sit in a contiguous directory structure.

This change implements path flattening for both build and serve actions:
- Build Action: Strips repository and package prefixes during workdir
  staging in mdbook.bzl.
- Serve Action: Implements conditional staging in server.rs. If files
  are split across repositories, it flattens them into a temporary
  directory using symlinks to preserve live-reloading. Standard books
  run in-place for maximum plugin compatibility.

Includes a new integration test in test/flattening that verifies
resolution across three different packages, and unit tests in
private/server.rs for the staging logic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mdbook fails when used with external repository

2 participants