Skip to content

Commit 89d00af

Browse files
laurenshobertLaurens Hobert
andauthored
fix: prevent a 404 error when serving Sphinx docs and Bazel is configured with a --symlink_prefix option (#3492)
When Bazel is configured with the [`--symlink_prefix`](https://bazel.build/reference/command-line-reference#build-flag--symlink_prefix) option, the sphinxdocs `.serve` target fails to serve files from the correct directory. This happens because the directory layout under `execroot` and the workspace no longer match, causing the target to miss the generated HTML files. This change updates the logic to use rpathlocation instead, ensuring the correct path is resolved regardless of symlink configuration. Fixes #3410 --------- Co-authored-by: Laurens Hobert <[email protected]>
1 parent 352f405 commit 89d00af

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ END_UNRELEASED_TEMPLATE
135135
* (gazelle) Fix `gazelle_python_manifest.test` so that it accesses manifest files via `runfile` path handling rather than directly ([#3397](https://github.com/bazel-contrib/rules_python/issues/3397)).
136136
* (core rules) For the system_python bootstrap, the runfiles root is added to
137137
sys.path.
138+
* (sphinxdocs) The sphinxdocs `.serve` target is now compatible with Bazel's `--symlink_prefix`
139+
flag ([#3410](https://github.com/bazel-contrib/rules_python/issues/3410)).
138140

139141
{#v1-8-0-added}
140142
### Added

sphinxdocs/private/sphinx.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ def sphinx_docs(
189189
srcs = [_SPHINX_SERVE_MAIN_SRC],
190190
main = _SPHINX_SERVE_MAIN_SRC,
191191
data = [html_name],
192+
deps = [Label("//python/runfiles")],
192193
args = [
193-
"$(execpath {})".format(html_name),
194+
"$(rlocationpath {})".format(html_name),
194195
],
195196
**common_kwargs_with_manual_tag
196197
)

sphinxdocs/private/sphinx_server.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
import time
66
from http import server
77

8+
from python.runfiles import Runfiles
9+
810

911
def main(argv):
10-
build_workspace_directory = os.environ["BUILD_WORKSPACE_DIRECTORY"]
11-
docs_directory = argv[1]
12-
serve_directory = os.path.join(build_workspace_directory, docs_directory)
12+
r = Runfiles.Create()
13+
serve_directory = r.Rlocation(argv[1])
14+
if not serve_directory:
15+
print(f"Error: could not find runfile for '{argv[1]}'", file=sys.stderr)
16+
return 1
1317

1418
class DirectoryHandler(server.SimpleHTTPRequestHandler):
1519
def __init__(self, *args, **kwargs):

0 commit comments

Comments
 (0)