@@ -18,6 +18,7 @@ load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
1818load ("@rules_python//sphinxdocs/private:sphinx_docs_library_info.bzl" , "SphinxDocsLibraryInfo" )
1919load ("//bazel/rules/rules_score:providers.bzl" , "FilteredExecpathInfo" , "SphinxIndexFileInfo" , "SphinxModuleInfo" , "SphinxNeedsInfo" )
2020load ("//bazel/rules/rules_score/private:verbosity.bzl" , "VERBOSITY_ATTR" , "get_log_level" )
21+ load ("//third_party/docs_runtime:defs.bzl" , "DOCS_RUNTIME_TREE" , "GRAPHVIZ_DEB" , "dot_action_env" )
2122
2223def _get_index_file (ctx ):
2324 """Extract the index file from the index attribute.
@@ -69,6 +70,11 @@ sphinx_rule_attrs = dict(
6970 "deps" : attr .label_list (
7071 doc = "List of other sphinx_module targets this module depends on for intersphinx." ,
7172 ),
73+ "_plantuml" : attr .label (
74+ default = Label ("//third_party/plantuml:plantuml" ),
75+ executable = True ,
76+ cfg = "exec" ,
77+ ),
7278 },
7379 ** VERBOSITY_ATTR
7480)
@@ -110,10 +116,12 @@ def _score_needs_impl(ctx):
110116 inputs = needs_inputs ,
111117 outputs = [needs_output ],
112118 arguments = needs_args ,
119+ env = {"PLANTUML_BIN" : ctx .executable ._plantuml .path },
113120 progress_message = "Generating needs.json for: %s" % ctx .label .name ,
114121 executable = sphinx_toolchain .sphinx .files_to_run .executable ,
115122 tools = [
116123 sphinx_toolchain .sphinx .files_to_run ,
124+ ctx .attr ._plantuml .files_to_run ,
117125 ],
118126 )
119127 transitive_needs = [dep [SphinxNeedsInfo ].needs_json_files for dep in ctx .attr .deps if SphinxNeedsInfo in dep ]
@@ -238,39 +246,26 @@ def _score_html_impl(ctx):
238246 get_log_level (ctx ),
239247 ]
240248
241- # Wire in the hermetic graphviz deb (dot_builtins + bundled shared libs) if provided.
242- # conf.template.py resolves all three env vars (GRAPHVIZ_DOT,
243- # LD_LIBRARY_PATH, LTDL_LIBRARY_PATH) from execroot-relative to absolute
244- # paths so dot_builtins can load its plugins without a system installation.
245- graphviz_env = {}
246- graphviz_files = ctx .files .graphviz
247- if graphviz_files :
248- _dot_suffix = "/usr/bin/dot_builtins"
249- dot_binary = None
250- for f in graphviz_files :
251- if f .path .endswith (_dot_suffix ):
252- dot_binary = f
253- break
254- if not dot_binary :
255- fail ("graphviz target {} must provide usr/bin/dot_builtins" .format (ctx .attr .graphviz ))
256-
257- graphviz_prefix = dot_binary .path [:- len (_dot_suffix )]
258- graphviz_env = {
259- "GRAPHVIZ_DOT" : dot_binary .path ,
260- "LD_LIBRARY_PATH" : graphviz_prefix + "/usr/lib" ,
261- "LTDL_LIBRARY_PATH" : graphviz_prefix + "/usr/lib/graphviz" ,
262- }
263- html_inputs = html_inputs + graphviz_files
249+ # Wire in the hermetic graphviz `dot` (relocatable cmake deb @graphviz_deb)
250+ # plus the docs_runtime sysroot (libexpat/libltdl/libz). conf.template.py
251+ # reads GRAPHVIZ_DOT for both sphinx.ext.graphviz and PlantUML, and resolves
252+ # LD_LIBRARY_PATH / GVBINDIR / LTDL_LIBRARY_PATH to absolute paths so dot can
253+ # load its plugins without a system graphviz installation.
254+ action_env = {"PLANTUML_BIN" : ctx .executable ._plantuml .path }
255+ if ctx .files ._graphviz and ctx .file ._docs_runtime :
256+ action_env .update (dot_action_env (ctx .files ._graphviz , ctx .file ._docs_runtime ))
257+ html_inputs = html_inputs + ctx .files ._graphviz + [ctx .file ._docs_runtime ]
264258
265259 ctx .actions .run (
266260 inputs = html_inputs ,
267261 outputs = [sphinx_html_output ],
268262 arguments = html_args + [args ],
269- env = graphviz_env ,
263+ env = action_env ,
270264 progress_message = "Building HTML: %s" % ctx .label .name ,
271265 executable = sphinx_toolchain .sphinx .files_to_run .executable ,
272266 tools = [
273267 sphinx_toolchain .sphinx .files_to_run ,
268+ ctx .attr ._plantuml .files_to_run ,
274269 ],
275270 )
276271
@@ -358,12 +353,13 @@ _score_html = rule(
358353 "destination paths relative to the Sphinx source root. Exactly one " +
359354 "file per label. Mirrors sphinx_docs.renamed_srcs from rules_python." ,
360355 ),
361- graphviz = attr .label (
362- default = None ,
356+ _graphviz = attr .label (
357+ default = GRAPHVIZ_DEB ,
363358 allow_files = True ,
364- doc = "Graphviz cmake-release deb files (dot_builtins binary + bundled libs). " +
365- "Only available on Linux x86_64; provides a hermetic 'dot' binary without requiring a system graphviz installation. " +
366- "Defaults to @graphviz_deb//:all on Linux x86_64." ,
359+ ),
360+ _docs_runtime = attr .label (
361+ default = DOCS_RUNTIME_TREE ,
362+ allow_single_file = True ,
367363 ),
368364 ),
369365 toolchains = ["//bazel/rules/rules_score:toolchain_type" ],
@@ -383,7 +379,6 @@ def sphinx_module(
383379 strip_prefix = "" ,
384380 extra_opts = [],
385381 extra_opts_targets = [],
386- graphviz = None ,
387382 testonly = False ,
388383 ** kwargs ):
389384 """Build a Sphinx module with transitive HTML dependencies.
@@ -408,10 +403,6 @@ def sphinx_module(
408403 extra_opts_targets: {type}`list[label]` Label targets that resolve to extra Sphinx
409404 arguments at analysis time. Each target must provide FilteredExecpathInfo
410405 (e.g. filter_execpath targets).
411- graphviz: Graphviz cmake-release deb files (dot_builtins + bundled libs). On Linux x86_64,
412- defaults to @graphviz_deb//:all for hermetic graphviz support. On other platforms
413- or if explicitly set to None, no graphviz support is provided (the sphinx.ext.graphviz
414- extension will not be available).
415406 visibility: Bazel visibility
416407 """
417408 _score_needs (
@@ -432,7 +423,6 @@ def sphinx_module(
432423 needs = [d + "_needs" for d in deps ],
433424 extra_opts = extra_opts ,
434425 extra_opts_targets = extra_opts_targets ,
435- graphviz = graphviz ,
436426 testonly = testonly ,
437427 ** kwargs
438428 )
0 commit comments