Skip to content

Commit 9ecf0ce

Browse files
authored
Add doxygen rule [BUILD-450] (#42)
* Add doxygen rule [BUILD-450] * Fix * Add tag manual * Small fix * Fix * Add support for plantuml * Add .srcs and .hdrs targets and remove doxygen_output_directory * Move doxygen rule to doxygen directory * Fix typo * Get visibility for .srcs and .hdrs from swift_cc_library * Add comment * Introduce defaults in configure_file_impl
1 parent cf291a9 commit 9ecf0ce

File tree

3 files changed

+98
-10
lines changed

3 files changed

+98
-10
lines changed

cc/defs.bzl

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ def _test_compatible_with():
8989
"//conditions:default": [],
9090
})
9191

92+
def _create_srcs(**kwargs):
93+
native.filegroup(
94+
name = kwargs.get("name") + ".srcs",
95+
srcs = kwargs.get("srcs", []),
96+
visibility = kwargs.get("visibility", ["//visibility:private"]),
97+
)
98+
99+
def _create_hdrs(**kwargs):
100+
native.filegroup(
101+
name = kwargs.get("name") + ".hdrs",
102+
srcs = kwargs.get("hdrs", []),
103+
visibility = kwargs.get("visibility", ["//visibility:private"]),
104+
)
105+
92106
def cc_stamped_library(name, out, template, hdrs, includes, defaults, visibility = None):
93107
"""Creates a cc_library stamped with non-hermetic build metadata.
94108
@@ -138,7 +152,9 @@ def swift_c_library(**kwargs):
138152
"""Wraps cc_library to enforce standards for a production c library.
139153
140154
Primarily this consists of a default set of compiler options and
141-
language standards.
155+
language standards. This rule also creates 'target_name.srcs' and
156+
'target_name.hdrs' targets that contain sources and headers,
157+
respectively.
142158
143159
Production targets (swift_cc*), are compiled with the -pedantic flag.
144160
@@ -159,6 +175,9 @@ def swift_c_library(**kwargs):
159175
nocopts: List of flags to remove from the default compile
160176
options. Use judiciously.
161177
"""
178+
_create_srcs(**kwargs)
179+
_create_hdrs(**kwargs)
180+
162181
local_includes = _construct_local_includes(kwargs.pop("local_includes", []))
163182

164183
nocopts = kwargs.pop("nocopts", []) # pop because nocopts is a deprecated cc* attr.
@@ -183,7 +202,9 @@ def swift_cc_library(**kwargs):
183202
"""Wraps cc_library to enforce standards for a production c++ library.
184203
185204
Primarily this consists of a default set of compiler options and
186-
language standards.
205+
language standards. This rule also creates 'target_name.srcs' and
206+
'target_name.hdrs' targets that contain sources and headers,
207+
respectively.
187208
188209
Production targets (swift_cc*), are compiled with the -pedantic flag.
189210
@@ -206,6 +227,9 @@ def swift_cc_library(**kwargs):
206227
nocopts: List of flags to remove from the default compile
207228
options. Use judiciously.
208229
"""
230+
_create_srcs(**kwargs)
231+
_create_hdrs(**kwargs)
232+
209233
local_includes = _construct_local_includes(kwargs.pop("local_includes", []))
210234

211235
nocopts = kwargs.pop("nocopts", []) # pop because nocopts is a deprecated cc* attr.
@@ -524,7 +548,7 @@ def swift_cc_test(name, type, **kwargs):
524548
"""Wraps cc_test to enforce Swift testing conventions.
525549
526550
This rule creates a test target along with a target that contains the sources
527-
of the test. The name of the sources is created with the '_src' suffix.
551+
of the test. The name of the sources is created with the '.srcs' suffix.
528552
529553
Args:
530554
name: A unique name for this rule.
@@ -544,7 +568,7 @@ def swift_cc_test(name, type, **kwargs):
544568

545569
_ = kwargs.pop("nocopts", []) # To handle API compatibility.
546570

547-
srcs_name = name + "_srcs"
571+
srcs_name = name + ".srcs"
548572
srcs = kwargs.get("srcs", [])
549573

550574
native.filegroup(

doxygen/doxygen.bzl

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright (C) 2022 Swift Navigation Inc.
2+
# Contact: Swift Navigation <dev@swift-nav.com>
3+
#
4+
# This source is subject to the license found in the file 'LICENSE' which must
5+
# be be distributed together with this source. All other rights reserved.
6+
#
7+
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
8+
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
9+
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
10+
11+
load("//tools:configure_file.bzl", "configure_file_impl")
12+
13+
def _swift_doxygen_impl(ctx):
14+
vars = ctx.attr.vars | {} # copy dict instead of referencing it
15+
vars["DOXYGEN_SOURCE_DIRECTORIES"] = '" "'.join(ctx.attr.doxygen_source_directories)
16+
17+
doxygen_out = ctx.actions.declare_directory(ctx.attr.name + "_doxygen")
18+
vars["DOXYGEN_OUTPUT_DIRECTORY"] = doxygen_out.path
19+
20+
config = configure_file_impl(ctx, vars, ctx.attr.name + "_Doxyfile")[0].files.to_list()[0]
21+
22+
ctx.actions.run_shell(
23+
inputs = [config] + ctx.files.deps,
24+
outputs = [doxygen_out],
25+
command = """
26+
DOXYGEN_DOT_FOUND=NO
27+
DOXYGEN_DOT_PATH=
28+
29+
if command -v dot &> /dev/null
30+
then
31+
DOXYGEN_DOT_FOUND=YES
32+
DOXYGEN_DOT_PATH=$(which dot)
33+
fi
34+
35+
sed -i "s|@DOXYGEN_DOT_FOUND@|$DOXYGEN_DOT_FOUND|g" {config}
36+
sed -i "s|@DOXYGEN_DOT_PATH@|$DOXYGEN_DOT_PATH|g" {config}
37+
sed -i "s|@PLANTUML_JAR_PATH@|/usr/local/bin/plantuml.jar|g" {config}
38+
39+
doxygen {config}
40+
""".format(config = config.path),
41+
)
42+
43+
return [DefaultInfo(files = depset([doxygen_out, config]))]
44+
45+
_swift_doxygen = rule(
46+
implementation = _swift_doxygen_impl,
47+
attrs = {
48+
"vars": attr.string_dict(),
49+
"template": attr.label(
50+
allow_single_file = [".in"],
51+
mandatory = True,
52+
),
53+
"deps": attr.label_list(),
54+
"doxygen_source_directories": attr.string_list(),
55+
},
56+
)
57+
58+
def swift_doxygen(**kwargs):
59+
kwargs["tags"] = ["manual"] + kwargs.get("tags", [])
60+
61+
_swift_doxygen(**kwargs)

tools/configure_file.bzl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010

1111
CMAKE_FALSE_CONSTANTS = ["0", "OFF", "NO", "FALSE", "N", "IGNORE", "NOTFOUND"]
1212

13-
def configure_file_impl(ctx, vars):
13+
def configure_file_impl(ctx, vars = None, out = None):
14+
if vars == None:
15+
vars = ctx.attr.vars
16+
17+
if out == None:
18+
out = ctx.attr.out
19+
1420
subs = {}
1521
for (key, val) in vars.items():
1622
cmake_define_nl = "#cmakedefine {}\n".format(key)
@@ -31,19 +37,16 @@ def configure_file_impl(ctx, vars):
3137
subs["@{}@".format(key)] = val
3238
subs["${" + key + "}"] = val
3339

34-
out = ctx.actions.declare_file(ctx.attr.out)
40+
out = ctx.actions.declare_file(out)
3541
ctx.actions.expand_template(
3642
output = out,
3743
template = ctx.file.template,
3844
substitutions = subs,
3945
)
4046
return [DefaultInfo(files = depset([out]))]
4147

42-
def _configure_file_impl(ctx):
43-
return configure_file_impl(ctx, ctx.attr.vars)
44-
4548
configure_file = rule(
46-
implementation = _configure_file_impl,
49+
implementation = configure_file_impl,
4750
attrs = {
4851
"vars": attr.string_dict(),
4952
"out": attr.string(),

0 commit comments

Comments
 (0)