11# *******************************************************************************
2- # Copyright (c) 2024 Contributors to the Eclipse Foundation
2+ # Copyright (c) 2025 Contributors to the Eclipse Foundation
33#
44# See the NOTICE file(s) distributed with this work for additional
55# information regarding copyright ownership.
3737#
3838# For user-facing documentation, refer to `/README.md`.
3939
40- load ("@aspect_rules_py//py:defs.bzl" , "py_binary" , "py_library" , "py_venv" )
41- load ("@pip_sphinx//:requirements.bzl" , "all_requirements" , "requirement" )
42- load ("@rules_java//java:defs.bzl" , "java_binary" )
43- load ("@rules_pkg//pkg:mappings.bzl" , "pkg_files" )
44- load ("@rules_pkg//pkg:tar.bzl" , "pkg_tar" )
45- load ("@rules_python//python:pip.bzl" , "compile_pip_requirements" )
40+ load ("@aspect_rules_py//py:defs.bzl" , "py_binary" )
41+ load ("@pip_process//:requirements.bzl" , "all_requirements" , "requirement" )
4642load ("@rules_python//sphinxdocs:sphinx.bzl" , "sphinx_build_binary" , "sphinx_docs" )
47- load ("//docs:_tooling/extensions/score_source_code_linker/collect_source_files.bzl" , "parse_source_files_for_needs_links" )
48- load ("//tools/testing/pytest:defs.bzl" , "score_py_pytest" )
43+ load ("@rules_python//sphinxdocs:sphinx_docs_library.bzl" , "sphinx_docs_library" )
44+ load ("@score_python_basics//:defs.bzl" , "score_virtualenv" )
45+ load ("//src/extensions:score_source_code_linker/collect_source_files.bzl" , "parse_source_files_for_needs_links" )
4946
5047sphinx_requirements = all_requirements + [
51- "@rules_python//python/runfiles " ,
52- ":plantuml_for_python " ,
48+ "//src:plantuml_for_python " ,
49+ "//src/extensions:score_extensions " ,
5350]
5451
55- def docs (source_files_to_scan_for_needs_links = None , source_dir = "docs" , conf_dir = "docs" , build_dir_for_incremental = "_build" ):
52+ def docs (source_files_to_scan_for_needs_links = None , source_dir = "docs" , conf_dir = "docs" , build_dir_for_incremental = "_build" , docs_targets = [] ):
5653 """
5754 Creates all targets related to documentation.
5855 By using this function, you'll get any and all updates for documentation targets in one place.
@@ -61,30 +58,42 @@ def docs(source_files_to_scan_for_needs_links = None, source_dir = "docs", conf_
6158 """
6259
6360 # Parse source files for needs links
61+ # This needs to be created to generate a target, otherwise it won't execute as dependency for other macros
6462 parse_source_files_for_needs_links (
6563 name = "score_source_code_parser" ,
6664 srcs_and_deps = source_files_to_scan_for_needs_links if source_files_to_scan_for_needs_links else [],
6765 )
6866
69- # Get the output of source_code_linker
70- # Does not work:
71- # rule_info = native.existing_rule(source_code_linker.name)
72- # source_code_links = rule_info[SourceCodeLinks].file.path
73- # Workaround:
74- source_code_links = "score_source_code_parser.json"
75-
76- # Run-time build of documentation, incl. incremental build support and non-IDE live preview.
77- _incremental (":score_source_code_parser" , source_code_links , source_dir = source_dir , conf_dir = conf_dir , build_dir = build_dir_for_incremental )
67+ # TODO: Explain what this does / how it works?
68+ for target in docs_targets :
69+ suffix = "_" + target ["suffix" ] if target ["suffix" ] else ""
70+ external_needs_deps = target .get ("target" , [])
71+ external_needs_def = target .get ("external_needs_info" , [])
72+ _incremental (
73+ incremental_name = "incremental" + suffix ,
74+ live_name = "live_preview" + suffix ,
75+ conf_dir = conf_dir ,
76+ source_dir = source_dir ,
77+ build_dir = build_dir_for_incremental ,
78+ external_needs_deps = external_needs_deps ,
79+ external_needs_def = external_needs_def ,
80+ )
81+ _docs (
82+ name = "docs" + suffix ,
83+ format = "html" ,
84+ external_needs_deps = external_needs_deps ,
85+ external_needs_def = external_needs_def ,
86+ )
7887
7988 # Virtual python environment for working on the documentation (esbonio).
8089 # incl. python support when working on conf.py and sphinx extensions.
8190 # creates :ide_support target for virtualenv
8291 _ide_support ()
8392
84- # creates :docs target for build time documentation
85- _docs ()
93+ # creates 'needs.json' build target
94+ _docs (name = "docs_needs" , format = "needs" )
8695
87- def _incremental (source_code_linker , source_code_links , source_dir = "docs" , conf_dir = "docs" , build_dir = "_build" , extra_dependencies = list ()):
96+ def _incremental (incremental_name = "incremental" , live_name = "live_preview" , source_dir = "docs" , conf_dir = "docs" , build_dir = "_build" , extra_dependencies = list (), external_needs_deps = list (), external_needs_def = None ):
8897 """
8998 A target for building docs incrementally at runtime, incl live preview.
9099 Args:
@@ -97,44 +106,47 @@ def _incremental(source_code_linker, source_code_links, source_dir = "docs", con
97106 """
98107
99108 dependencies = sphinx_requirements + extra_dependencies
100-
101109 py_binary (
102- name = "incremental" ,
103- srcs = ["//docs:_tooling/incremental.py" ],
104- data = [source_code_linker , "//docs:docs_assets" ],
110+ name = incremental_name ,
111+ srcs = ["//src:incremental.py" ],
105112 deps = dependencies ,
113+ data = [":score_source_code_parser" ] + external_needs_deps ,
106114 env = {
107- "SOURCE_CODE_LINKS" : source_code_links ,
108115 "SOURCE_DIRECTORY" : source_dir ,
109116 "CONF_DIRECTORY" : conf_dir ,
110117 "BUILD_DIRECTORY" : build_dir ,
118+ "EXTERNAL_NEEDS_INFO" : json .encode (external_needs_def ),
111119 "ACTION" : "incremental" ,
112120 },
113121 )
114122
115123 py_binary (
116- name = "live_preview" ,
117- srcs = ["//docs:_tooling/incremental.py" ],
118- data = ["//docs:docs_assets" ],
124+ name = live_name ,
125+ srcs = ["//src:incremental.py" ],
119126 deps = dependencies ,
127+ data = external_needs_deps ,
120128 env = {
121129 "SOURCE_DIRECTORY" : source_dir ,
122130 "CONF_DIRECTORY" : conf_dir ,
123131 "BUILD_DIRECTORY" : build_dir ,
132+ "EXTERNAL_NEEDS_INFO" : json .encode (external_needs_def ),
124133 "ACTION" : "live_preview" ,
125134 },
126135 )
127136
128137def _ide_support ():
129- py_venv (
138+ score_virtualenv (
130139 name = "ide_support" ,
131140 venv_name = ".venv_docs" ,
132- deps = sphinx_requirements ,
141+ reqs = sphinx_requirements ,
133142 )
134143
135- def _docs ():
144+ def _docs (name = "docs" , format = "html" , external_needs_deps = list (), external_needs_def = dict ()):
145+ ext_needs_arg = "--define=external_needs_source=" + json .encode (external_needs_def )
146+
147+ #fail(ext_needs_arg)
136148 sphinx_docs (
137- name = "docs" ,
149+ name = name ,
138150 srcs = native .glob ([
139151 "**/*.png" ,
140152 "**/*.svg" ,
@@ -143,29 +155,28 @@ def _docs():
143155 "**/*.css" ,
144156 "**/*.puml" ,
145157 "**/*.need" ,
146- # Include the docs tooling itself
158+ # Include the docs src itself
147159 # Note: we don't use py_library here to make it as close as possible to docs:incremental.
148160 "**/*.py" ,
149161 "**/*.yaml" ,
150162 "**/*.json" ,
151163 "**/*.csv" ,
152- ], exclude = ["**/tests/rst/**/*.rst " ]),
164+ ], exclude = ["**/tests/* " ]),
153165 config = ":conf.py" ,
154166 extra_opts = [
155167 "-W" ,
156168 "--keep-going" ,
157- # This is 'overwriting' the configuration parameter inside sphinx. As we only get this information during runtime
158- "--define=source_code_linker_file=$(location :score_source_code_parser)" ,
159- ],
169+ ] + [ext_needs_arg ],
160170 formats = [
161- "html" ,
171+ format ,
162172 ],
163- sphinx = ":sphinx_build" ,
173+ sphinx = "//src :sphinx_build" ,
164174 tags = [
165175 "manual" ,
166176 ],
167177 tools = [
168178 ":score_source_code_parser" ,
169- ":plantuml" ,
170- ],
179+ "//src:plantuml" ,
180+ ] + external_needs_deps ,
181+ visibility = ["//visibility:public" ],
171182 )
0 commit comments