Skip to content

Commit 4c668ed

Browse files
committed
docs: update the documentation
1 parent 99abf9b commit 4c668ed

File tree

3 files changed

+99
-13
lines changed

3 files changed

+99
-13
lines changed

README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ doxygen(
150150
"*.h", # Usually includes the source files and the markdown files.
151151
"*.cpp",
152152
]) + ["README.md"],
153-
# Additionally, you can use the `deps` attribute to select a target
153+
# Additionally, you can use the `deps` attribute to select a target
154154
# and automatically include all of the files in its `srcs`, `hdrs`, and `data` attributes,
155155
# along with all of its transitive dependencies.
156156
# deps = [":my_cc_target"],
@@ -177,6 +177,73 @@ They will simply be appended at the end of the file, overriding the default valu
177177
> [!Note]
178178
> See the [documentation](docs/doxygen_doc.md) for more information or the [examples](examples) directory for examples of how to use the rules.
179179
180+
### Differences between `srcs` and `deps`
181+
182+
The `srcs` and `deps` attributes work differently, and are not interchangeable.
183+
184+
`srcs` is a list of files that will be passed to Doxygen for documentation generation.
185+
You can use `glob` to include a collection of multiple files.
186+
On the other hand, if you indicate a target (e.g., `:my_genrule`), it will include all the files produced by that target.
187+
More precisely, the files in the DefaultInfo provider the target returns.
188+
Hence, when the documentation is generated, all rules in the `srcs` attribute **will** be built, and the files they output will be passed to Doxygen.
189+
190+
On the other hand, `deps` is a list of targets whose sources will be included in the documentation generation.
191+
It will automatically include all the files in the `srcs`, `hdrs`, and `data` attributes of the target, and the same applies to all of its transitive dependencies, recursively.
192+
Since we are only interested in the source files, the `deps` targets **will not** be built when the documentation is generated.
193+
194+
```bzl
195+
# My BUILD.bazel file
196+
load("@doxygen//:doxygen.bzl", "doxygen")
197+
load("@rules_cc//cc:defs.bzl", "cc_library")
198+
199+
cc_library(
200+
name = "lib",
201+
hdrs = ["add.h", "sub.h"],
202+
srcs = ["add.cpp", "sub.cpp"],
203+
)
204+
205+
cc_library(
206+
name = "main",
207+
srcs = ["main.cpp"],
208+
deps = [":lib"],
209+
)
210+
211+
212+
genrule(
213+
name = "section",
214+
outs = ["Section.md"],
215+
cmd = """
216+
echo "# Section " > $@
217+
echo "This is some amazing documentation with section!! " >> $@
218+
echo "Incredible." >> $@
219+
""",
220+
)
221+
222+
doxygen(
223+
name = "doxygen",
224+
project_name = "dependencies",
225+
226+
# The output of the genrule will be included in the documentation.
227+
# The genrule will be executed when the documentation is generated.
228+
srcs = [
229+
"README.md", # file
230+
":section", # genrule
231+
232+
# WARNING: By adding this, the main target will be built
233+
# and only the output file `main.o` will be passed to Doxygen,
234+
# which is likely not what you want.
235+
# ":main"
236+
],
237+
238+
# The sources of the main target and its dependencies will be included.
239+
# No compilation will be performed, so compile error won't be reported.
240+
deps = [":main"], # cc_library
241+
242+
# Always starts at the root folder
243+
use_mdfile_as_mainpage = "dependencies/README.md",
244+
)
245+
```
246+
180247
## Build
181248

182249
To build the documentation, run the following command:

doxygen/doxygen.bzl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ doxygen(
123123
""",
124124
implementation = _doxygen_impl,
125125
attrs = {
126-
"srcs": attr.label_list(allow_files = True, doc = "The source files to generate documentation for. Can include header files, source files, and any other file Doxygen can parse."),
127-
"deps": attr.label_list(aspects = [collect_files_aspect], doc = "The dependencies targets whose files in their 'src', 'hdrs' and 'data' attributes will be collected to generate the documentation. Transitive dependencies are also taken into account."),
126+
"srcs": attr.label_list(allow_files = True, doc = "List of source files to generate documentation for. Can include any file that Doxygen can parse, as well as targets that return a DefaultInfo provider (usually genrules). Since we are only considering the outputs files and not the sources, these targets **will** be built if necessary."),
127+
"deps": attr.label_list(aspects = [collect_files_aspect], doc = "List of dependencies targets whose files present in the 'src', 'hdrs' and 'data' attributes will be collected to generate the documentation. Transitive dependencies are also taken into account. Since we are only considering the source files and not the outputs, these targets **will not** be built"),
128128
"configurations": attr.string_list(doc = "Additional configuration parameters to append to the Doxyfile. For example, to set the project name, use `PROJECT_NAME = example`."),
129-
"outs": attr.string_list(default = ["html"], allow_empty = False, doc = """The output folders to keep. If only the html outputs is of interest, the default value will do. Otherwise, a list of folders to keep is expected (e.g. `["html", "latex"]`)."""),
129+
"outs": attr.string_list(default = ["html"], allow_empty = False, doc = """Output folders to keep. If only the html outputs is of interest, the default value will do. Otherwise, a list of folders to keep is expected (e.g. `["html", "latex"]`)."""),
130130
"doxyfile_template": attr.label(
131131
allow_single_file = True,
132132
default = Label(":Doxyfile.template"),
133-
doc = """The template file to use to generate the Doxyfile. You can provide your own or use the default one.
133+
doc = """Template file to use to generate the Doxyfile. You can provide your own or use the default one.
134134
The following substitutions are available:
135135
- `# {{INPUT}}`: Subpackage directory in the sandbox.
136136
- `# {{DOT_PATH}}`: Indicate to doxygen the location of the `dot_executable`
@@ -142,15 +142,15 @@ The following substitutions are available:
142142
executable = True,
143143
cfg = "exec",
144144
allow_single_file = True,
145-
doc = "The dot executable to use. Must refer to an executable file.",
145+
doc = "dot executable to use. Must refer to an executable file.",
146146
),
147147
"doxygen_extra_args": attr.string_list(default = [], doc = "Extra arguments to pass to the doxygen executable."),
148148
"_executable": attr.label(
149149
executable = True,
150150
cfg = "exec",
151151
allow_single_file = True,
152152
default = Label(":executable"),
153-
doc = "The doxygen executable to use. Must refer to an executable file.",
153+
doc = "doxygen executable to use. Must refer to an executable file.",
154154
),
155155
},
156156
)
@@ -539,18 +539,22 @@ def doxygen(
539539
```
540540
541541
Args:
542-
name: A name for the target.
543-
srcs: A list of source files to generate documentation for.
544-
deps: A list of dependencies whose source, header and data files, and those or the transitive dependencies, will be included in the documentation.
542+
name: Name for the target.
543+
srcs: List of source files to generate documentation for.
544+
Can include any file that Doxygen can parse, as well as targets that return a DefaultInfo provider (usually genrules).
545+
Since we are only considering the outputs files and not the sources, these targets **will** be built if necessary.
546+
deps: List of dependencies targets whose files present in the 'src', 'hdrs' and 'data' attributes will be collected to generate the documentation.
547+
Transitive dependencies are also taken into account.
548+
Since we are only considering the source files and not the outputs, these targets **will not** be built.
545549
dot_executable: Label of the doxygen executable. Make sure it is also added to the `srcs` of the macro
546-
configurations: A list of additional configuration parameters to pass to Doxygen.
550+
configurations: List of additional configuration parameters to pass to Doxygen.
547551
doxyfile_template: The template file to use to generate the Doxyfile.
548552
The following substitutions are available:<br>
549553
- `# {{INPUT}}`: Subpackage directory in the sandbox.<br>
550554
- `# {{ADDITIONAL PARAMETERS}}`: Additional parameters given in the `configurations` attribute.<br>
551555
- `# {{OUTPUT DIRECTORY}}`: The directory provided in the `outs` attribute.
552556
doxygen_extra_args: Extra arguments to pass to the doxygen executable.
553-
outs: The output folders bazel will keep. If only the html outputs is of interest, the default value will do.
557+
outs: Output folders bazel will keep. If only the html outputs is of interest, the default value will do.
554558
otherwise, a list of folders to keep is expected (e.g. ["html", "latex"]).
555559
Note that the rule will also generate an output group for each folder in the outs list having the same name.
556560

examples/dependencies/BUILD.bazel

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,24 @@ cc_library(
2828
deps = [":lib"],
2929
)
3030

31+
genrule(
32+
name = "section",
33+
outs = ["Section.md"],
34+
cmd = """
35+
echo "# Section " > $@
36+
echo "This is some amazing documentation with section!! " >> $@
37+
echo "Incredible." >> $@
38+
""",
39+
)
40+
3141
doxygen(
3242
name = "doxygen",
43+
srcs = [
44+
"README.md", # file
45+
":section", # genrule
46+
],
3347
project_brief = "Example project for doxygen",
3448
project_name = "dependencies",
35-
deps = [":main"],
49+
use_mdfile_as_mainpage = "dependencies/README.md",
50+
deps = [":main"], # cc_library
3651
)

0 commit comments

Comments
 (0)