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 your BUILD files, pass the implementation targets to the docs rule
as code_targets. Their srcs, hdrs, and textual_hdrs are scanned,
including those of their deps recursively. This means that a
cc_executable also covers source files from the cc_library targets it
uses. You may also pass filegroups; their files are scanned directly.
1cc_library(
2 name = "some_library",
3 srcs = [
4 "bar.cpp",
5 ],
6)
7
8cc_executable(
9 name = "some_application",
10 srcs = ["main.cpp"],
11 deps = [":some_library"],
12)
13
14docs(
15 data = [
16 "@score_process_description//:needs_json",
17 ],
18 source_dir = "docs",
19 code_targets = [":some_application"],
20 primary_need_id = "comp__some_component",
21)
primary_need_id is optional and identifies the single Need representing
the bundle’s primary subject. A bundle can contain many other Needs; target
metadata is attached only to this explicitly selected Need. The ID is never
derived from the Bazel bundle name.
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.