-
Notifications
You must be signed in to change notification settings - Fork 20
Source links as Bazel target #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f6991e9
61dad86
d31a8fc
ac852e5
69991f3
740c4e2
c4d8950
2842afb
502f550
c666155
e0405c4
e971a0f
4955337
470ecaf
4d7cab0
b6aecd4
d4661f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
|
|
||
| .. _docs_dependencies: | ||
|
|
||
| ========================== | ||
| Docs Dependencies | ||
| ========================== | ||
|
|
||
| When running ``bazel run :docs``, the documentation build system orchestrates multiple interconnected dependencies to produce HTML documentation. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be fixed in future PR: isn't it otherwise you might not get the right target. |
||
|
|
||
| 1. Gather inputs (Bazel may do this parallelized): | ||
|
|
||
| * Extract source code links from files via ``sourcelinks_json`` rule. | ||
|
|
||
| * Optionally, merge source links using the ``merge_sourcelinks`` rule. | ||
|
|
||
| * Needs (requirements) are gathered from various ``needs_json`` targets specified in the ``data`` attribute. | ||
|
|
||
| 2. Documentation sources are read from the specified source directory (default: ``docs/``). | ||
| Sphinx processes the documentation sources along with the merged data to generate the final HTML output. | ||
|
|
||
| .. plantuml:: | ||
|
|
||
| @startuml | ||
| left to right direction | ||
|
|
||
| collections "Documentation Sources" as DocsSource | ||
| collections "Needs JSON Targets" as NeedsTargets | ||
| collections "Source Code Links" as SourceLinks | ||
| artifact "Merge Data" as Merge | ||
| process "Sphinx Processing" as Sphinx | ||
| artifact "HTML Output" as HTMLOutput | ||
| collections "S-CORE extensions" as SCoreExt | ||
|
|
||
| DocsSource --> Sphinx | ||
| NeedsTargets --> Sphinx | ||
| SCoreExt --> Sphinx | ||
| SourceLinks --> Merge | ||
| Merge --> Sphinx | ||
| Sphinx --> HTMLOutput | ||
|
|
||
| @enduml | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,14 +2,65 @@ Reference Docs in Source Code | |||||||||||||||||
| ============================= | ||||||||||||||||||
|
|
||||||||||||||||||
| In your C++/Rust/Python source code, you want to reference requirements (needs). | ||||||||||||||||||
| The docs-as-code tool will create backlinks in the documentation. | ||||||||||||||||||
| The docs-as-code tool will create backlinks in the documentation in two steps: | ||||||||||||||||||
|
|
||||||||||||||||||
| 1. You add a special comment in your source code that references the need ID. | ||||||||||||||||||
| 2. Scan for those comments and provide needs links to your documentation. | ||||||||||||||||||
|
|
||||||||||||||||||
| For an example result, look at the attribute ``source_code_link`` | ||||||||||||||||||
| of :need:`tool_req__docs_common_attr_title`. | ||||||||||||||||||
|
|
||||||||||||||||||
| Comments in Source Code | ||||||||||||||||||
| ----------------------- | ||||||||||||||||||
|
|
||||||||||||||||||
| Use a comment and start with ``req-Id:`` or ``req-traceability:`` followed by the need ID. | ||||||||||||||||||
|
|
||||||||||||||||||
| .. code-block:: python | ||||||||||||||||||
|
|
||||||||||||||||||
| # req-Id: TOOL_REQ__EXAMPLE_ID | ||||||||||||||||||
| # req-traceability: TOOL_REQ__EXAMPLE_ID | ||||||||||||||||||
| # req-Id: TOOL_REQ__EXAMPLE_ID | ||||||||||||||||||
| # req-traceability: TOOL_REQ__EXAMPLE_ID | ||||||||||||||||||
|
|
||||||||||||||||||
| For an example, look at the attribute ``source_code_link`` | ||||||||||||||||||
| of :need:`tool_req__docs_common_attr_title`. | ||||||||||||||||||
| For other languages (C++, Rust, etc.), use the appropriate comment syntax. | ||||||||||||||||||
|
|
||||||||||||||||||
| Scanning Source Code for Links | ||||||||||||||||||
| ------------------------------ | ||||||||||||||||||
|
|
||||||||||||||||||
| In you ``BUILD`` files, you specify which source files to scan | ||||||||||||||||||
| with ``filegroup`` or ``glob`` or whatever Bazel mechanism you prefer. | ||||||||||||||||||
| Then, you use the ``sourcelinks_json`` rule to scan those files. | ||||||||||||||||||
| Finally, pass the scan results to the ``docs`` rule as ``sourcelinks`` attribute. | ||||||||||||||||||
|
Comment on lines
+28
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I remember correctly it was requested that we use non direct language (like you etc.) Here is a suggestion how that could look like:
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| .. code-block:: starlark | ||||||||||||||||||
| :emphasize-lines: 1, 12, 26 | ||||||||||||||||||
| :linenos: | ||||||||||||||||||
|
|
||||||||||||||||||
| load("//:docs.bzl", "docs", "sourcelinks_json") | ||||||||||||||||||
|
|
||||||||||||||||||
| filegroup( | ||||||||||||||||||
| name = "some_sources", | ||||||||||||||||||
| srcs = [ | ||||||||||||||||||
| "foo.py", | ||||||||||||||||||
| "bar.cpp", | ||||||||||||||||||
| "data.yaml", | ||||||||||||||||||
| ] + glob(["subdir/**/.py"]), | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| sourcelinks_json( | ||||||||||||||||||
| name = "my_source_links", | ||||||||||||||||||
| srcs = [ | ||||||||||||||||||
| ":some_sources", | ||||||||||||||||||
| "//src:all_sources", | ||||||||||||||||||
| # whatever | ||||||||||||||||||
| ], | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| docs( | ||||||||||||||||||
| data = [ | ||||||||||||||||||
| "@score_process//:needs_json", | ||||||||||||||||||
| ], | ||||||||||||||||||
| source_dir = "docs", | ||||||||||||||||||
| sourcelinks = [":my_source_links"], | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. up to now docs() is defining internal targets like needs_json itself. All in one command. Can we do the same with sourcelinks_json?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this the solution we had wayyy back when we first introduced scl? :D Oh the cyclical nature of things. |
||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| Since the source links are Bazel targets, you can easily reference other modules as well. | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Scripts | ||
|
|
||
| The scripts directory is only for local development (linters) so far. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
|
|
||
| load("@aspect_rules_py//py:defs.bzl", "py_binary") | ||
| load("@pip_process//:requirements.bzl", "all_requirements") | ||
|
|
||
| filegroup( | ||
| name = "sources", | ||
| srcs = glob(["**/*.py"]), | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| py_binary( | ||
| name = "generate_sourcelinks", | ||
| srcs = ["generate_sourcelinks_cli.py"], | ||
| main = "generate_sourcelinks_cli.py", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//src/extensions/score_source_code_linker", | ||
| ] + all_requirements, | ||
| ) | ||
|
|
||
| py_binary( | ||
| name = "merge_sourcelinks", | ||
| srcs = ["merge_sourcelinks.py"], | ||
| main = "merge_sourcelinks.py", | ||
| visibility = ["//visibility:public"], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Scripts Bazel | ||
|
|
||
| This folder contains executables to be used within Bazel rules. |
Uh oh!
There was an error while loading. Please reload this page.