You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+68-1Lines changed: 68 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -150,7 +150,7 @@ doxygen(
150
150
"*.h", # Usually includes the source files and the markdown files.
151
151
"*.cpp",
152
152
]) + ["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
154
154
# and automatically include all of the files in its `srcs`, `hdrs`, and `data` attributes,
155
155
# along with all of its transitive dependencies.
156
156
# deps = [":my_cc_target"],
@@ -177,6 +177,73 @@ They will simply be appended at the end of the file, overriding the default valu
177
177
> [!Note]
178
178
> See the [documentation](docs/doxygen_doc.md) for more information or the [examples](examples) directory for examples of how to use the rules.
179
179
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
+
180
247
## Build
181
248
182
249
To build the documentation, run the following command:
Copy file name to clipboardExpand all lines: doxygen/doxygen.bzl
+15-11Lines changed: 15 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -123,14 +123,14 @@ doxygen(
123
123
""",
124
124
implementation=_doxygen_impl,
125
125
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"),
128
128
"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"]`)."""),
130
130
"doxyfile_template": attr.label(
131
131
allow_single_file=True,
132
132
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.
134
134
The following substitutions are available:
135
135
- `# {{INPUT}}`: Subpackage directory in the sandbox.
136
136
- `# {{DOT_PATH}}`: Indicate to doxygen the location of the `dot_executable`
@@ -142,15 +142,15 @@ The following substitutions are available:
142
142
executable=True,
143
143
cfg="exec",
144
144
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.",
146
146
),
147
147
"doxygen_extra_args": attr.string_list(default= [], doc="Extra arguments to pass to the doxygen executable."),
148
148
"_executable": attr.label(
149
149
executable=True,
150
150
cfg="exec",
151
151
allow_single_file=True,
152
152
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.",
154
154
),
155
155
},
156
156
)
@@ -539,18 +539,22 @@ def doxygen(
539
539
```
540
540
541
541
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.
545
549
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.
547
551
doxyfile_template: The template file to use to generate the Doxyfile.
548
552
The following substitutions are available:<br>
549
553
- `# {{INPUT}}`: Subpackage directory in the sandbox.<br>
550
554
- `# {{ADDITIONAL PARAMETERS}}`: Additional parameters given in the `configurations` attribute.<br>
551
555
- `# {{OUTPUT DIRECTORY}}`: The directory provided in the `outs` attribute.
552
556
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.
554
558
otherwise, a list of folders to keep is expected (e.g. ["html", "latex"]).
555
559
Note that the rule will also generate an output group for each folder in the outs list having the same name.
0 commit comments