Skip to content

Commit 7a8eed5

Browse files
authored
Merge pull request #3 from TendTo/feat/hermetic-dot
Feat/hermetic dot
2 parents 0409ca2 + 9f1475c commit 7a8eed5

File tree

12 files changed

+155
-18
lines changed

12 files changed

+155
-18
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4646

4747
- Updated documentation
4848

49+
## [1.1.3]
50+
51+
### Added
52+
53+
- `dot_executable` parameter in the macro
54+
- Example of how to use the `doxygen` alongside `graphviz` in hermetic builds
55+
4956
## [NEXT.VERSION]
5057

5158
[1.0.0]: https://github.com/TendTo/rules_doxygen/tree/1.0.0
5259
[1.1.0]: https://github.com/TendTo/rules_doxygen/compare/1.0.0...1.1.0
5360
[1.1.1]: https://github.com/TendTo/rules_doxygen/compare/1.1.0...1.1.1
5461
[1.1.2]: https://github.com/TendTo/rules_doxygen/compare/1.1.1...1.1.2
55-
[NEXT.VERSION]: https://github.com/TendTo/rules_doxygen/compare/1.1.2...HEAD
62+
[1.1.3]: https://github.com/TendTo/rules_doxygen/compare/1.1.2...1.1.3
63+
[NEXT.VERSION]: https://github.com/TendTo/rules_doxygen/compare/1.1.3...HEAD

Doxyfile.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,6 +2903,8 @@ MSCFILE_DIRS =
29032903

29042904
# {{INPUT}}
29052905

2906+
# {{DOT_PATH}}
2907+
29062908
# {{ADDITIONAL PARAMETERS}}
29072909

29082910
# {{OUTPUT DIRECTORY}}

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""rules_doxygen module"""
2-
module(name = "rules_doxygen", version = "1.1.2", compatibility_level = 1)
2+
module(name = "rules_doxygen", version = "1.1.3", compatibility_level = 1)
33

44
bazel_dep(name = "platforms", version = "0.0.5")
55
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ This repository contains a Starlark implementation of Doxygen rules in Bazel.
99
Add the following to your _MODULE.bazel_:
1010

1111
```bzl
12-
bazel_dep(name = "rules_doxygen", version = "1.1.2", dev_dependency = True)
12+
bazel_dep(name = "rules_doxygen", version = "1.1.3", dev_dependency = True)
1313
```
1414

1515
If you don't want to depend on the [Bazel package registry](https://bazel.build/external/bazelbuild/rules_pkg) or you want to use a not-yet-published version of this module, you can use an archive override by adding the following lines below the `bazel_dep` rule in your _MODULE.bazel_ file:
1616

1717
```bzl
18-
bazel_dep(name = "rules_doxygen", version = "1.1.2", dev_dependency = True)
18+
bazel_dep(name = "rules_doxygen", version = "1.1.3", dev_dependency = True)
1919
archive_override(
2020
module_name = "rules_doxygen",
2121
urls = "https://github.com/TendTo/rules_doxygen/archive/refs/heads/main.tar.gz",

docs/doxygen_doc.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ doxygen(<a href="#doxygen-name">name</a>, <a href="#doxygen-srcs">srcs</a>, <a h
1212
<a href="#doxygen-use_mathjax">use_mathjax</a>, <a href="#doxygen-html_extra_stylesheet">html_extra_stylesheet</a>, <a href="#doxygen-html_extra_files">html_extra_files</a>, <a href="#doxygen-html_colorstyle">html_colorstyle</a>, <a href="#doxygen-aliases">aliases</a>, <a href="#doxygen-have_dot">have_dot</a>,
1313
<a href="#doxygen-dot_image_format">dot_image_format</a>, <a href="#doxygen-dot_transparent">dot_transparent</a>, <a href="#doxygen-disable_index">disable_index</a>, <a href="#doxygen-full_sidebar">full_sidebar</a>, <a href="#doxygen-generate_treeview">generate_treeview</a>,
1414
<a href="#doxygen-javadoc_autobrief">javadoc_autobrief</a>, <a href="#doxygen-builtin_stl_support">builtin_stl_support</a>, <a href="#doxygen-hide_undoc_members">hide_undoc_members</a>, <a href="#doxygen-hide_in_body_docs">hide_in_body_docs</a>,
15-
<a href="#doxygen-exclude_symbols">exclude_symbols</a>, <a href="#doxygen-example_path">example_path</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>,
16-
<a href="#doxygen-kwargs">kwargs</a>)
15+
<a href="#doxygen-exclude_symbols">exclude_symbols</a>, <a href="#doxygen-example_path">example_path</a>, <a href="#doxygen-dot_executable">dot_executable</a>, <a href="#doxygen-configurations">configurations</a>, <a href="#doxygen-doxyfile_template">doxyfile_template</a>,
16+
<a href="#doxygen-doxygen_extra_args">doxygen_extra_args</a>, <a href="#doxygen-outs">outs</a>, <a href="#doxygen-kwargs">kwargs</a>)
1717
</pre>
1818

1919
Generates documentation using Doxygen.
@@ -77,6 +77,7 @@ doxygen(
7777
| <a id="doxygen-hide_in_body_docs"></a>hide_in_body_docs | Whether to hide in body docs. | `None` |
7878
| <a id="doxygen-exclude_symbols"></a>exclude_symbols | A list of symbols to exclude. | `[]` |
7979
| <a id="doxygen-example_path"></a>example_path | The path to the examples. They must be added to the source files. | `None` |
80+
| <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` |
8081
| <a id="doxygen-configurations"></a>configurations | A list of additional configuration parameters to pass to Doxygen. | `[]` |
8182
| <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. | `"@doxygen//:Doxyfile.template"` |
8283
| <a id="doxygen-doxygen_extra_args"></a>doxygen_extra_args | Extra arguments to pass to the doxygen executable. | `[]` |

doxygen.bzl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def _doxygen_impl(ctx):
1313
output = doxyfile,
1414
substitutions = {
1515
"# {{INPUT}}": "INPUT = %s" % " ".join(input_dirs.keys()),
16+
"# {{DOT_PATH}}": ("DOT_PATH = %s" % ctx.executable.dot_executable.dirname) if ctx.executable.dot_executable else "",
1617
"# {{ADDITIONAL PARAMETERS}}": "\n".join(ctx.attr.configurations),
1718
"# {{OUTPUT DIRECTORY}}": "OUTPUT_DIRECTORY = %s" % doxyfile.dirname,
1819
},
@@ -67,17 +68,24 @@ doxygen(
6768
doc = """The template file to use to generate the Doxyfile. You can provide your own or use the default one.
6869
The following substitutions are available:
6970
- `# {{INPUT}}`: Subpackage directory in the sandbox.
71+
- `# {{DOT_PATH}}`: Indicate to doxygen the location of the `dot_executable`
7072
- `# {{ADDITIONAL PARAMETERS}}`: Additional parameters given in the `configurations` attribute.
7173
- `# {{OUTPUT DIRECTORY}}`: The directory provided in the `outs` attribute.
7274
""",
7375
),
76+
"dot_executable": attr.label(
77+
executable = True,
78+
cfg = "exec",
79+
allow_single_file = True,
80+
doc = "The dot executable to use. Must refer to an executable file.",
81+
),
7482
"doxygen_extra_args": attr.string_list(default = [], doc = "Extra arguments to pass to the doxygen executable."),
7583
"_executable": attr.label(
7684
executable = True,
7785
cfg = "exec",
78-
allow_files = True,
86+
allow_single_file = True,
7987
default = Label("@doxygen//:executable"),
80-
doc = "The doxygen executable to use.",
88+
doc = "The doxygen executable to use. Must refer to an executable file.",
8189
),
8290
},
8391
)
@@ -112,6 +120,7 @@ def doxygen(
112120
hide_in_body_docs = None,
113121
exclude_symbols = [],
114122
example_path = None,
123+
dot_executable = None,
115124
configurations = [],
116125
doxyfile_template = "@doxygen//:Doxyfile.template",
117126
doxygen_extra_args = [],
@@ -174,6 +183,7 @@ def doxygen(
174183
hide_in_body_docs: Whether to hide in body docs.
175184
exclude_symbols: A list of symbols to exclude.
176185
example_path: The path to the examples. They must be added to the source files.
186+
dot_executable: Label of the doxygen executable. Make sure it is also added to the `srcs` of the macro
177187
configurations: A list of additional configuration parameters to pass to Doxygen.
178188
doxyfile_template: The template file to use to generate the Doxyfile.
179189
The following substitutions are available:<br>
@@ -271,5 +281,6 @@ def doxygen(
271281
configurations = configurations,
272282
doxyfile_template = doxyfile_template,
273283
doxygen_extra_args = doxygen_extra_args,
284+
dot_executable = dot_executable,
274285
**kwargs
275286
)

examples/awesome/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,3 @@ graph TD;
3434
B-->D;
3535
C-->D;
3636
</pre>
37-
38-
<pre class="mermaid">
39-
graph TD;
40-
A-->B;
41-
A-->C;
42-
B-->D;
43-
C-->D;
44-
</pre>

examples/graphviz/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("@doxygen//:doxygen.bzl", "doxygen")
2+
3+
# WARNINING: this assume the existence of a repository @graphviz exposing the target :executable
4+
doxygen(
5+
name = "doxygen",
6+
srcs = glob([
7+
"*.h",
8+
"*.cpp",
9+
"*.sh",
10+
]) + ["@graphviz//:executable"],
11+
dot_executable = "@graphviz//:executable",
12+
have_dot = True,
13+
project_brief = "Example project for doxygen",
14+
project_name = "graphviz",
15+
)

examples/graphviz/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Graphiz path example
2+
3+
This is an example of how to use the `doxygen` alongside `graphviz` to generate inheritance diagrams for C++ classes.
4+
By default, `doxygen` looks for the `dot` executable in the system path, meaning that a system installation of `graphviz` will work out of the box.
5+
If you want to make the build fully hermetic, you can specify the path to the `dot` executable in the `doxygen` rule, making it point to a `dot` binary of your choosing.
6+
7+
```bash
8+
bazel build //doxyfile:doxygen
9+
```
10+
11+
## Custom dot binary
12+
13+
To ensure the `dot` binary is available to the rule, make sure to add it to the sources of the macro.
14+
Also, remember to add the `have_dot = True` parameter, otherwise no graphs will be produced.
15+
16+
```bzl
17+
load("@doxygen//:doxygen.bzl", "doxygen")
18+
19+
# Assuming the binary is located in the same folder
20+
21+
filegroup(
22+
name = "dot_executable",
23+
srcs = select(
24+
{
25+
"@platforms//os:linux": ["dot"],
26+
"@platforms//os:macos": ["dot"],
27+
"@platforms//os:windows": ["dot"],
28+
},
29+
"Unsupported platform",
30+
),
31+
)
32+
33+
# Ideally, instead of using a local filegroup, you would want and external module, like "@graphviz//:bin/dot"
34+
35+
doxygen(
36+
name = "doxygen",
37+
srcs = glob([
38+
"*.h",
39+
"*.cpp",
40+
"*.sh",
41+
]) + [":dot_executable"],
42+
dot_executable = ":dot_executable",
43+
have_dot = True,
44+
project_name = "graphviz",
45+
)
46+
```

examples/graphviz/lib.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @file lib.cpp
3+
* @author Ernesto Casablanca (casablancaernesto@gmail.com)
4+
* @copyright 2024
5+
*/
6+
7+
#include "lib.h"
8+
9+
int Adder::op(int a, int b) { return a + b; }
10+
int Subtractor::op(int a, int b) { return a - b; }

0 commit comments

Comments
 (0)