Skip to content

Commit fdb8b30

Browse files
committed
doc: extensions: Navigate to DTS entries from supported hardware list
Update the gen_board_catalog.py logic to also capture lineno for each devicetree node. Use that info in the supported hardware list to create clickable elements that directly take the user to the corresponding line in the devicetree file on Github. Signed-off-by: Benjamin Cabé <[email protected]>
1 parent 235fabb commit fdb8b30

File tree

3 files changed

+55
-28
lines changed

3 files changed

+55
-28
lines changed

doc/_extensions/zephyr/domain/__init__.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
from anytree import ChildResolverError, Node, PreOrderIter, Resolver, search
3838
from docutils import nodes
39-
from docutils.parsers.rst import directives
39+
from docutils.parsers.rst import directives, roles
4040
from docutils.statemachine import StringList
4141
from sphinx import addnodes
4242
from sphinx.application import Sphinx
@@ -811,7 +811,8 @@ def run(self):
811811
<span class="count disabled-count">2</span>
812812
</dt>
813813
<dd>
814-
Number of instances that are enabled / disabled.
814+
Number of instances that are enabled / disabled. <br/>
815+
Click on the label to see the first instance of this feature in the board/SoC DTS files.
815816
</dd>
816817
<dt>
817818
<code class="docutils literal notranslate"><span class="pre">vnd,foo</span></code>
@@ -870,7 +871,7 @@ def feature_sort_key(feature):
870871

871872
for i, (key, value) in enumerate(items):
872873
row = nodes.row()
873-
if value.get("disabled_count", 0) > 0 and value.get("okay_count", 0) == 0:
874+
if value.get("disabled_nodes", []) and not value.get("okay_nodes", []):
874875
row["classes"].append("disabled")
875876

876877
# TYPE column
@@ -911,22 +912,39 @@ def feature_sort_key(feature):
911912
desc_para += nodes.Text(value["description"])
912913

913914
# Add count indicators for okay and not-okay instances
914-
okay_count = value.get("okay_count", 0)
915-
disabled_count = value.get("disabled_count", 0)
915+
okay_nodes = value.get("okay_nodes", [])
916+
disabled_nodes = value.get("disabled_nodes", [])
916917

917-
if okay_count > 0:
918-
okay_count_indicator = nodes.inline(
919-
classes=["count", "okay-count"],
920-
text=str(okay_count),
921-
)
922-
desc_para += okay_count_indicator
918+
role_fn, _ = roles.role(
919+
"zephyr_file", self.state_machine.language, self.lineno, self.state.reporter
920+
)
921+
922+
def create_count_indicator(nodes_list, class_type, role_function=role_fn):
923+
if not nodes_list:
924+
return None
925+
926+
count = len(nodes_list)
927+
928+
if role_function is None:
929+
return nodes.inline(
930+
classes=["count", f"{class_type}-count"], text=str(count)
931+
)
923932

924-
if disabled_count > 0:
925-
disabled_count_indicator = nodes.inline(
926-
classes=["count", "disabled-count"],
927-
text=str(disabled_count),
933+
# Create a reference to the first node in the list
934+
first_node = nodes_list[0]
935+
file_ref = f"{count} <{first_node['filename']}#L{first_node['lineno']}>"
936+
937+
role_nodes, _ = role_function(
938+
"zephyr_file", file_ref, file_ref, self.lineno, self.state.inliner
928939
)
929-
desc_para += disabled_count_indicator
940+
941+
count_node = role_nodes[0]
942+
count_node["classes"] = ["count", f"{class_type}-count"]
943+
944+
return count_node
945+
946+
desc_para += create_count_indicator(okay_nodes, "okay")
947+
desc_para += create_count_indicator(disabled_nodes, "disabled")
930948

931949
desc_entry += desc_para
932950
row += desc_entry

doc/_extensions/zephyr/domain/static/css/board.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
font-size: 0.7em;
179179
font-weight: 600;
180180
margin-left: 4px;
181+
padding-right: 6px !important;
181182

182183
&::before {
183184
content: "×";

doc/_scripts/gen_boards_catalog.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def get_catalog(generate_hw_features=False):
254254
# Use pre-gathered build info and DTS files
255255
if board.name in board_devicetrees:
256256
for board_target, edt in board_devicetrees[board.name].items():
257-
target_features = {}
257+
features = {}
258258
for node in edt.nodes:
259259
if node.binding_path is None:
260260
continue
@@ -271,6 +271,7 @@ def get_catalog(generate_hw_features=False):
271271

272272
description = DeviceTreeUtils.get_cached_description(node)
273273
filename = node.filename
274+
lineno = node.lineno
274275
locations = set()
275276
if Path(filename).is_relative_to(ZEPHYR_BASE):
276277
filename = Path(filename).relative_to(ZEPHYR_BASE)
@@ -279,23 +280,30 @@ def get_catalog(generate_hw_features=False):
279280
else:
280281
locations.add("soc")
281282

282-
existing_feature = target_features.get(binding_type, {}).get(
283+
existing_feature = features.get(binding_type, {}).get(
283284
node.matching_compat
284285
)
286+
287+
node_info = {"filename": str(filename), "lineno": lineno}
288+
node_list_key = "okay_nodes" if node.status == "okay" else "disabled_nodes"
289+
285290
if existing_feature:
286291
locations.update(existing_feature["locations"])
287-
key = "okay_count" if node.status == "okay" else "disabled_count"
288-
existing_feature[key] = existing_feature.get(key, 0) + 1
289-
else:
290-
key = "okay_count" if node.status == "okay" else "disabled_count"
291-
target_features.setdefault(binding_type, {})[node.matching_compat] = {
292-
"description": description,
293-
"locations": locations,
294-
key: 1
295-
}
292+
existing_feature.setdefault(node_list_key, []).append(node_info)
293+
continue
294+
295+
feature_data = {
296+
"description": description,
297+
"locations": locations,
298+
"okay_nodes": [],
299+
"disabled_nodes": [],
300+
}
301+
feature_data[node_list_key].append(node_info)
302+
303+
features.setdefault(binding_type, {})[node.matching_compat] = feature_data
296304

297305
# Store features for this specific target
298-
supported_features[board_target] = target_features
306+
supported_features[board_target] = features
299307

300308
# Grab all the twister files for this board and use them to figure out all the archs it
301309
# supports.

0 commit comments

Comments
 (0)