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//:needs_json",
17 ],
18 source_dir = "docs",
19 code_targets = [":some_application"],
20)
The older scan_code parameter remains available for existing configurations
that explicitly provide files or filegroups, but it is deprecated. Prefer
code_targets for new configurations.
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.