Skip to content

Commit ec68cb9

Browse files
authored
Merge pull request #24 from oxidase/feat/transitive-sources
feat: collect transitive sources
2 parents 548fa1a + 4c668ed commit ec68cb9

File tree

17 files changed

+477
-60
lines changed

17 files changed

+477
-60
lines changed

.bcr/presubmit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ bcr_test_module:
1717
- "//awesome:doxygen"
1818
- "//kwargs:doxygen"
1919
- "//substitutions:doxygen"
20+
- "//dependencies:doxygen"

.github/workflows/ci.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
custom,
2626
awesome,
2727
substitutions,
28+
dependencies,
2829
]
2930
exclude:
3031
# In substitution example we use `string_keyed_label_dict`, which is not supported in bazel 7.0.0
@@ -54,17 +55,7 @@ jobs:
5455
strategy:
5556
matrix:
5657
os: [ubuntu-latest, windows-latest, macos-latest]
57-
subdir:
58-
[
59-
base,
60-
kwargs,
61-
doxyfile,
62-
latex,
63-
nested,
64-
custom,
65-
awesome,
66-
substitutions,
67-
]
58+
subdir: [base]
6859
runs-on: ${{ matrix.os }}
6960

7061
steps:

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.2.3]
9+
10+
### Added
11+
12+
- Support for dependency inclusion in the `doxygen` rule [#24](https://github.com/TendTo/rules_doxygen/pull/24) (thanks to @oxidase)
13+
14+
### Changed
15+
16+
- `srcs` attribute in the `doxygen` macro is now optional, as it defaults to `[]`
17+
- Updated documentation
18+
819
## [2.2.2]
920

1021
### Added
@@ -155,4 +166,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
155166
[2.2.0]: https://github.com/TendTo/rules_doxygen/compare/2.1.0...2.2.0
156167
[2.2.1]: https://github.com/TendTo/rules_doxygen/compare/2.2.0...2.2.1
157168
[2.2.2]: https://github.com/TendTo/rules_doxygen/compare/2.2.1...2.2.2
158-
[NEXT.VERSION]: https://github.com/TendTo/rules_doxygen/compare/2.2.2...HEAD
169+
[2.2.3]: https://github.com/TendTo/rules_doxygen/compare/2.2.2...2.2.3
170+
[NEXT.VERSION]: https://github.com/TendTo/rules_doxygen/compare/2.2.3...HEAD

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ 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
154+
# and automatically include all of the files in its `srcs`, `hdrs`, and `data` attributes,
155+
# along with all of its transitive dependencies.
156+
# deps = [":my_cc_target"],
153157
project_brief = DESCRIPTION, # Brief description of the project
154158
project_name = NAME, # Name of the project
155159
generate_html = True, # Whether to generate HTML output
@@ -173,6 +177,73 @@ They will simply be appended at the end of the file, overriding the default valu
173177
> [!Note]
174178
> See the [documentation](docs/doxygen_doc.md) for more information or the [examples](examples) directory for examples of how to use the rules.
175179
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+
176247
## Build
177248

178249
To build the documentation, run the following command:

docs/doxygen_doc.md

Lines changed: 79 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,49 @@
22

33
Doxygen rule for Bazel.
44

5+
<a id="TransitiveSourcesInfo"></a>
6+
7+
## TransitiveSourcesInfo
8+
9+
<pre>
10+
load("@rules_doxygen//doxygen:doxygen.bzl", "TransitiveSourcesInfo")
11+
12+
TransitiveSourcesInfo(<a href="#TransitiveSourcesInfo-srcs">srcs</a>)
13+
</pre>
14+
15+
A provider to collect source files transitively from the target and its dependencies
16+
17+
**FIELDS**
18+
19+
| Name | Description |
20+
| :------------- | :------------- |
21+
| <a id="TransitiveSourcesInfo-srcs"></a>srcs | depset of source files collected from the target and its dependencies |
22+
23+
524
<a id="doxygen"></a>
625

726
## doxygen
827

928
<pre>
1029
load("@doxygen//:doxygen.bzl", "doxygen")
1130

12-
doxygen(<a href="#doxygen-name">name</a>, <a href="#doxygen-srcs">srcs</a>, <a href="#doxygen-dot_executable">dot_executable</a>, <a href="#doxygen-configurations">configurations</a>, <a href="#doxygen-doxyfile_template">doxyfile_template</a>, <a href="#doxygen-doxygen_extra_args">doxygen_extra_args</a>, <a href="#doxygen-outs">outs</a>,
13-
<a href="#doxygen-doxyfile_encoding">doxyfile_encoding</a>, <a href="#doxygen-project_name">project_name</a>, <a href="#doxygen-project_number">project_number</a>, <a href="#doxygen-project_brief">project_brief</a>, <a href="#doxygen-project_logo">project_logo</a>, <a href="#doxygen-project_icon">project_icon</a>,
14-
<a href="#doxygen-create_subdirs">create_subdirs</a>, <a href="#doxygen-create_subdirs_level">create_subdirs_level</a>, <a href="#doxygen-allow_unicode_names">allow_unicode_names</a>, <a href="#doxygen-output_language">output_language</a>, <a href="#doxygen-brief_member_desc">brief_member_desc</a>,
15-
<a href="#doxygen-repeat_brief">repeat_brief</a>, <a href="#doxygen-abbreviate_brief">abbreviate_brief</a>, <a href="#doxygen-always_detailed_sec">always_detailed_sec</a>, <a href="#doxygen-inline_inherited_memb">inline_inherited_memb</a>, <a href="#doxygen-full_path_names">full_path_names</a>,
16-
<a href="#doxygen-strip_from_path">strip_from_path</a>, <a href="#doxygen-strip_from_inc_path">strip_from_inc_path</a>, <a href="#doxygen-short_names">short_names</a>, <a href="#doxygen-javadoc_autobrief">javadoc_autobrief</a>, <a href="#doxygen-javadoc_banner">javadoc_banner</a>,
17-
<a href="#doxygen-qt_autobrief">qt_autobrief</a>, <a href="#doxygen-multiline_cpp_is_brief">multiline_cpp_is_brief</a>, <a href="#doxygen-python_docstring">python_docstring</a>, <a href="#doxygen-inherit_docs">inherit_docs</a>, <a href="#doxygen-separate_member_pages">separate_member_pages</a>,
18-
<a href="#doxygen-tab_size">tab_size</a>, <a href="#doxygen-aliases">aliases</a>, <a href="#doxygen-optimize_output_for_c">optimize_output_for_c</a>, <a href="#doxygen-optimize_output_java">optimize_output_java</a>, <a href="#doxygen-optimize_for_fortran">optimize_for_fortran</a>,
19-
<a href="#doxygen-optimize_output_vhdl">optimize_output_vhdl</a>, <a href="#doxygen-optimize_output_slice">optimize_output_slice</a>, <a href="#doxygen-extension_mapping">extension_mapping</a>, <a href="#doxygen-markdown_support">markdown_support</a>,
20-
<a href="#doxygen-toc_include_headings">toc_include_headings</a>, <a href="#doxygen-markdown_id_style">markdown_id_style</a>, <a href="#doxygen-autolink_support">autolink_support</a>, <a href="#doxygen-autolink_ignore_words">autolink_ignore_words</a>,
21-
<a href="#doxygen-builtin_stl_support">builtin_stl_support</a>, <a href="#doxygen-cpp_cli_support">cpp_cli_support</a>, <a href="#doxygen-sip_support">sip_support</a>, <a href="#doxygen-idl_property_support">idl_property_support</a>, <a href="#doxygen-distribute_group_doc">distribute_group_doc</a>,
22-
<a href="#doxygen-group_nested_compounds">group_nested_compounds</a>, <a href="#doxygen-subgrouping">subgrouping</a>, <a href="#doxygen-inline_grouped_classes">inline_grouped_classes</a>, <a href="#doxygen-inline_simple_structs">inline_simple_structs</a>,
23-
<a href="#doxygen-typedef_hides_struct">typedef_hides_struct</a>, <a href="#doxygen-lookup_cache_size">lookup_cache_size</a>, <a href="#doxygen-num_proc_threads">num_proc_threads</a>, <a href="#doxygen-timestamp">timestamp</a>, <a href="#doxygen-extract_all">extract_all</a>,
24-
<a href="#doxygen-extract_private">extract_private</a>, <a href="#doxygen-extract_priv_virtual">extract_priv_virtual</a>, <a href="#doxygen-extract_package">extract_package</a>, <a href="#doxygen-extract_static">extract_static</a>, <a href="#doxygen-extract_local_classes">extract_local_classes</a>,
25-
<a href="#doxygen-extract_local_methods">extract_local_methods</a>, <a href="#doxygen-extract_anon_nspaces">extract_anon_nspaces</a>, <a href="#doxygen-resolve_unnamed_params">resolve_unnamed_params</a>, <a href="#doxygen-hide_undoc_members">hide_undoc_members</a>,
26-
<a href="#doxygen-hide_undoc_classes">hide_undoc_classes</a>, <a href="#doxygen-hide_undoc_namespaces">hide_undoc_namespaces</a>, <a href="#doxygen-hide_friend_compounds">hide_friend_compounds</a>, <a href="#doxygen-hide_in_body_docs">hide_in_body_docs</a>,
27-
<a href="#doxygen-internal_docs">internal_docs</a>, <a href="#doxygen-case_sense_names">case_sense_names</a>, <a href="#doxygen-hide_scope_names">hide_scope_names</a>, <a href="#doxygen-hide_compound_reference">hide_compound_reference</a>, <a href="#doxygen-show_headerfile">show_headerfile</a>,
31+
doxygen(<a href="#doxygen-name">name</a>, <a href="#doxygen-srcs">srcs</a>, <a href="#doxygen-deps">deps</a>, <a href="#doxygen-dot_executable">dot_executable</a>, <a href="#doxygen-configurations">configurations</a>, <a href="#doxygen-doxyfile_template">doxyfile_template</a>, <a href="#doxygen-doxygen_extra_args">doxygen_extra_args</a>,
32+
<a href="#doxygen-outs">outs</a>, <a href="#doxygen-doxyfile_encoding">doxyfile_encoding</a>, <a href="#doxygen-project_name">project_name</a>, <a href="#doxygen-project_number">project_number</a>, <a href="#doxygen-project_brief">project_brief</a>, <a href="#doxygen-project_logo">project_logo</a>,
33+
<a href="#doxygen-project_icon">project_icon</a>, <a href="#doxygen-create_subdirs">create_subdirs</a>, <a href="#doxygen-create_subdirs_level">create_subdirs_level</a>, <a href="#doxygen-allow_unicode_names">allow_unicode_names</a>, <a href="#doxygen-output_language">output_language</a>,
34+
<a href="#doxygen-brief_member_desc">brief_member_desc</a>, <a href="#doxygen-repeat_brief">repeat_brief</a>, <a href="#doxygen-abbreviate_brief">abbreviate_brief</a>, <a href="#doxygen-always_detailed_sec">always_detailed_sec</a>, <a href="#doxygen-inline_inherited_memb">inline_inherited_memb</a>,
35+
<a href="#doxygen-full_path_names">full_path_names</a>, <a href="#doxygen-strip_from_path">strip_from_path</a>, <a href="#doxygen-strip_from_inc_path">strip_from_inc_path</a>, <a href="#doxygen-short_names">short_names</a>, <a href="#doxygen-javadoc_autobrief">javadoc_autobrief</a>,
36+
<a href="#doxygen-javadoc_banner">javadoc_banner</a>, <a href="#doxygen-qt_autobrief">qt_autobrief</a>, <a href="#doxygen-multiline_cpp_is_brief">multiline_cpp_is_brief</a>, <a href="#doxygen-python_docstring">python_docstring</a>, <a href="#doxygen-inherit_docs">inherit_docs</a>,
37+
<a href="#doxygen-separate_member_pages">separate_member_pages</a>, <a href="#doxygen-tab_size">tab_size</a>, <a href="#doxygen-aliases">aliases</a>, <a href="#doxygen-optimize_output_for_c">optimize_output_for_c</a>, <a href="#doxygen-optimize_output_java">optimize_output_java</a>,
38+
<a href="#doxygen-optimize_for_fortran">optimize_for_fortran</a>, <a href="#doxygen-optimize_output_vhdl">optimize_output_vhdl</a>, <a href="#doxygen-optimize_output_slice">optimize_output_slice</a>, <a href="#doxygen-extension_mapping">extension_mapping</a>,
39+
<a href="#doxygen-markdown_support">markdown_support</a>, <a href="#doxygen-toc_include_headings">toc_include_headings</a>, <a href="#doxygen-markdown_id_style">markdown_id_style</a>, <a href="#doxygen-autolink_support">autolink_support</a>,
40+
<a href="#doxygen-autolink_ignore_words">autolink_ignore_words</a>, <a href="#doxygen-builtin_stl_support">builtin_stl_support</a>, <a href="#doxygen-cpp_cli_support">cpp_cli_support</a>, <a href="#doxygen-sip_support">sip_support</a>,
41+
<a href="#doxygen-idl_property_support">idl_property_support</a>, <a href="#doxygen-distribute_group_doc">distribute_group_doc</a>, <a href="#doxygen-group_nested_compounds">group_nested_compounds</a>, <a href="#doxygen-subgrouping">subgrouping</a>,
42+
<a href="#doxygen-inline_grouped_classes">inline_grouped_classes</a>, <a href="#doxygen-inline_simple_structs">inline_simple_structs</a>, <a href="#doxygen-typedef_hides_struct">typedef_hides_struct</a>, <a href="#doxygen-lookup_cache_size">lookup_cache_size</a>,
43+
<a href="#doxygen-num_proc_threads">num_proc_threads</a>, <a href="#doxygen-timestamp">timestamp</a>, <a href="#doxygen-extract_all">extract_all</a>, <a href="#doxygen-extract_private">extract_private</a>, <a href="#doxygen-extract_priv_virtual">extract_priv_virtual</a>,
44+
<a href="#doxygen-extract_package">extract_package</a>, <a href="#doxygen-extract_static">extract_static</a>, <a href="#doxygen-extract_local_classes">extract_local_classes</a>, <a href="#doxygen-extract_local_methods">extract_local_methods</a>,
45+
<a href="#doxygen-extract_anon_nspaces">extract_anon_nspaces</a>, <a href="#doxygen-resolve_unnamed_params">resolve_unnamed_params</a>, <a href="#doxygen-hide_undoc_members">hide_undoc_members</a>, <a href="#doxygen-hide_undoc_classes">hide_undoc_classes</a>,
46+
<a href="#doxygen-hide_undoc_namespaces">hide_undoc_namespaces</a>, <a href="#doxygen-hide_friend_compounds">hide_friend_compounds</a>, <a href="#doxygen-hide_in_body_docs">hide_in_body_docs</a>, <a href="#doxygen-internal_docs">internal_docs</a>,
47+
<a href="#doxygen-case_sense_names">case_sense_names</a>, <a href="#doxygen-hide_scope_names">hide_scope_names</a>, <a href="#doxygen-hide_compound_reference">hide_compound_reference</a>, <a href="#doxygen-show_headerfile">show_headerfile</a>,
2848
<a href="#doxygen-show_include_files">show_include_files</a>, <a href="#doxygen-show_grouped_memb_inc">show_grouped_memb_inc</a>, <a href="#doxygen-force_local_includes">force_local_includes</a>, <a href="#doxygen-inline_info">inline_info</a>,
2949
<a href="#doxygen-sort_member_docs">sort_member_docs</a>, <a href="#doxygen-sort_brief_docs">sort_brief_docs</a>, <a href="#doxygen-sort_members_ctors_1st">sort_members_ctors_1st</a>, <a href="#doxygen-sort_group_names">sort_group_names</a>,
3050
<a href="#doxygen-sort_by_scope_name">sort_by_scope_name</a>, <a href="#doxygen-strict_proto_matching">strict_proto_matching</a>, <a href="#doxygen-generate_todolist">generate_todolist</a>, <a href="#doxygen-generate_testlist">generate_testlist</a>,
@@ -85,25 +105,40 @@ Depending on the type of the attribute, the macro will convert it to the appropr
85105
- list: the value of the attribute is a string with the elements separated by spaces and enclosed in double quotes
86106
- str: the value of the attribute is will be set to the string, unchanged. You may need to provide proper quoting if the value contains spaces
87107

108+
For the complete list of Doxygen configuration options, please refer to the [Doxygen documentation](https://www.doxygen.nl/manual/config.html).
109+
88110
### Example
89111

90-
```starlark
112+
```bzl
91113
# MODULE.bazel file
92114
bazel_dep(name = "rules_doxygen", dev_dependency = True)
93115
doxygen_extension = use_extension("@rules_doxygen//:extensions.bzl", "doxygen_extension")
94116
use_repo(doxygen_extension, "doxygen")
95117
```
96118

97-
```starlark
119+
```bzl
98120
# BUILD.bazel file
99121
load("@doxygen//:doxygen.bzl", "doxygen")
122+
load("@rules_cc//cc:defs.bzl", "cc_library")
123+
124+
cc_library(
125+
name = "lib",
126+
srcs = ["add.cpp", "sub.cpp"],
127+
hdrs = ["add.h", "sub.h"],
128+
)
129+
130+
cc_library(
131+
name = "main",
132+
srcs = ["main.cpp"],
133+
deps = [":lib"],
134+
)
100135

101136
doxygen(
102137
name = "doxygen",
103138
srcs = glob([
104-
"*.h",
105-
"*.cpp",
139+
"*.md",
106140
]),
141+
deps = [":main"]
107142
aliases = [
108143
"licence=@par Licence:^^",
109144
"verb{1}=@verbatim \\1 @endverbatim",
@@ -121,7 +156,8 @@ doxygen(
121156
| Name | Description | Default Value |
122157
| :------------- | :------------- | :------------- |
123158
| <a id="doxygen-name"></a>name | A name for the target. | none |
124-
| <a id="doxygen-srcs"></a>srcs | A list of source files to generate documentation for. | none |
159+
| <a id="doxygen-srcs"></a>srcs | A list of source files to generate documentation for. | `[]` |
160+
| <a id="doxygen-deps"></a>deps | A list of dependencies whose source, header and data files, and those or the transitive dependencies, will be included in the documentation. | `[]` |
125161
| <a id="doxygen-dot_executable"></a>dot_executable | Label of the doxygen executable. Make sure it is also added to the `srcs` of the macro | `None` |
126162
| <a id="doxygen-configurations"></a>configurations | A list of additional configuration parameters to pass to Doxygen. | `None` |
127163
| <a id="doxygen-doxyfile_template"></a>doxyfile_template | The template file to use to generate the Doxyfile. The following substitutions are available:<br> - `# {{INPUT}}`: Subpackage directory in the sandbox.<br> - `# {{ADDITIONAL PARAMETERS}}`: Additional parameters given in the `configurations` attribute.<br> - `# {{OUTPUT DIRECTORY}}`: The directory provided in the `outs` attribute. | `None` |
@@ -435,3 +471,25 @@ doxygen(
435471
| <a id="doxygen-kwargs"></a>kwargs | Additional arguments to pass to the rule (e.g. `visibility = ["//visibility:public"], tags = ["manual"]`) | none |
436472

437473

474+
<a id="collect_files_aspect"></a>
475+
476+
## collect_files_aspect
477+
478+
<pre>
479+
load("@rules_doxygen//doxygen:doxygen.bzl", "collect_files_aspect")
480+
481+
collect_files_aspect()
482+
</pre>
483+
484+
When applied to a target, this aspect collects the source files from the target and its dependencies, and makes them available in the TransitiveSourcesInfo provider.
485+
486+
**ASPECT ATTRIBUTES**
487+
488+
489+
| Name | Type |
490+
| :------------- | :------------- |
491+
| deps| String |
492+
493+
494+
495+

docs/extensions_doc.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ You can further customize the repository by specifying the `doxygen_bzl`, `build
7272

7373
### Example
7474

75-
```starlark
75+
```bzl
7676
# Download the os specific version 1.12.0 of doxygen supporting all the indicated platforms
7777
doxygen_repository(
7878
name = "doxygen",
@@ -180,7 +180,7 @@ No download will be performed, and the file indicated by the label will be used
180180
181181
### Examples
182182

183-
```starlark
183+
```bzl
184184
# MODULE.bazel file
185185

186186
bazel_dep(name = "rules_doxygen", version = "...", dev_dependency = True)
@@ -198,7 +198,7 @@ doxygen_extension.configuration(
198198
use_repo(doxygen_extension, "doxygen")
199199
```
200200

201-
```starlark
201+
```bzl
202202
# MODULE.bazel file
203203

204204
bazel_dep(name = "rules_doxygen", version = "...", dev_dependency = True)

0 commit comments

Comments
 (0)