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 in two steps:
You add a special comment in your source code that references the need ID.
Scan for those comments and provide needs links to your documentation.
For an example result, look at the attribute source_code_link
of Enforces title wording rules (tool_req__docs_common_attr_title).
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.
1load("//:docs.bzl", "docs", "sourcelinks_json")
2
3filegroup(
4 name = "some_sources",
5 srcs = [
6 "foo.py",
7 "bar.cpp",
8 "data.yaml",
9 ] + glob(["subdir/**/.py"]),
10)
11
12sourcelinks_json(
13 name = "my_source_links",
14 srcs = [
15 ":some_sources",
16 "//src:all_sources",
17 # whatever
18 ],
19)
20
21docs(
22 data = [
23 "@score_process//:needs_json",
24 ],
25 source_dir = "docs",
26 sourcelinks = [":my_source_links"],
27)
Since the source links are Bazel targets, you can easily reference other modules as well.
Comments in Source Code#
Use a comment and start with
req-Id:orreq-traceability:followed by the need ID.For other languages (C++, Rust, etc.), use the appropriate comment syntax.