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 https://github.com/bazel-contrib/rules_python/issues/3410

---------

Co-authored-by: Laurens Hobert <laurens.hobert@gridtogreat.com>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 40d1aff..0df0de8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -135,6 +135,8 @@
 * (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)).
 * (core rules) For the system_python bootstrap, the runfiles root is added to
   sys.path.
+* (sphinxdocs) The sphinxdocs `.serve` target is now compatible with Bazel's `--symlink_prefix`
+  flag ([#3410](https://github.com/bazel-contrib/rules_python/issues/3410)).
 
 {#v1-8-0-added}
 ### Added
diff --git a/sphinxdocs/private/sphinx.bzl b/sphinxdocs/private/sphinx.bzl
index e444429..0efbc26 100644
--- a/sphinxdocs/private/sphinx.bzl
+++ b/sphinxdocs/private/sphinx.bzl
@@ -189,8 +189,9 @@
         srcs = [_SPHINX_SERVE_MAIN_SRC],
         main = _SPHINX_SERVE_MAIN_SRC,
         data = [html_name],
+        deps = [Label("//python/runfiles")],
         args = [
-            "$(execpath {})".format(html_name),
+            "$(rlocationpath {})".format(html_name),
         ],
         **common_kwargs_with_manual_tag
     )
diff --git a/sphinxdocs/private/sphinx_server.py b/sphinxdocs/private/sphinx_server.py
index 1f4fae8..1bd6ee5 100644
--- a/sphinxdocs/private/sphinx_server.py
+++ b/sphinxdocs/private/sphinx_server.py
@@ -5,11 +5,15 @@
 import time
 from http import server
 
+from python.runfiles import Runfiles
+
 
 def main(argv):
-    build_workspace_directory = os.environ["BUILD_WORKSPACE_DIRECTORY"]
-    docs_directory = argv[1]
-    serve_directory = os.path.join(build_workspace_directory, docs_directory)
+    r = Runfiles.Create()
+    serve_directory = r.Rlocation(argv[1])
+    if not serve_directory:
+        print(f"Error: could not find runfile for '{argv[1]}'", file=sys.stderr)
+        return 1
 
     class DirectoryHandler(server.SimpleHTTPRequestHandler):
         def __init__(self, *args, **kwargs):