1
+ load ("@bazel_skylib//rules:common_settings.bzl" , "string_flag" )
1
2
load ("@rules_gazebo//gazebo:headers.bzl" , "gz_configure_header" , "gz_export_header" )
2
3
3
4
package (
@@ -36,56 +37,122 @@ gz_configure_header(
36
37
package_xml = "//:package.xml" ,
37
38
)
38
39
39
- public_headers_no_gen = [
40
- "include/gz/common/Profiler.hh" ,
41
- ]
42
-
43
- sources = [
44
- "src/Profiler.cc" ,
45
- "src/RemoteryProfilerImpl.cc" ,
46
- ]
47
-
48
40
gz_export_header (
49
41
name = "Export" ,
50
42
out = "include/gz/common/profiler/Export.hh" ,
51
43
export_base = "GZ_COMMON_PROFILER" ,
52
44
lib_name = "gz-common-profiler" ,
53
45
)
54
46
47
+ cc_library (
48
+ name = "ProfilerImplInterface" ,
49
+ hdrs = ["include/gz/common/ProfilerImpl.hh" ],
50
+ includes = ["include" ],
51
+ visibility = ["//visibility:public" ],
52
+ deps = [":Export" ],
53
+ )
54
+
55
+ cc_library (
56
+ name = "RemoteryProfilerImpl" ,
57
+ srcs = ["src/RemoteryProfilerImpl.cc" ],
58
+ hdrs = [
59
+ "include/RemoteryConfig.h" ,
60
+ "src/RemoteryProfilerImpl.hh" ,
61
+ ],
62
+ includes = ["include" ],
63
+ deps = [
64
+ ":ProfilerImplInterface" ,
65
+ "//:gz-common" ,
66
+ "@remotery" ,
67
+ ],
68
+ )
69
+
70
+ # Build flag to control how the Gz Profiler is configured.
71
+ # --//profiler:config="disabled" (default): Profiler will be disabled.
72
+ # --//profiler:config="remotery": Profiler will be enabled and the Remotery
73
+ # profiler implemenation will be used.
74
+ # --//profiler:config="custom": Profiler will be enabled and a custom profiler
75
+ # implementation can be set to be used. See Profiler class for details.
76
+ #
77
+ # Note to maintainers: This setup is different from what is used in CMake where
78
+ # the config is split into two parts to control whether Remotery is used or not
79
+ # separately from whether the profiler is enabled or disabled.
80
+ string_flag (
81
+ name = "config" ,
82
+ build_setting_default = "disabled" ,
83
+ values = [
84
+ "disabled" ,
85
+ "remotery" ,
86
+ "custom" ,
87
+ ],
88
+ )
89
+
90
+ config_setting (
91
+ name = "disabled" ,
92
+ flag_values = {
93
+ ":config" : "disabled" ,
94
+ },
95
+ )
96
+
97
+ config_setting (
98
+ name = "use_remotery" ,
99
+ flag_values = {
100
+ ":config" : "remotery" ,
101
+ },
102
+ )
103
+
104
+ config_setting (
105
+ name = "use_custom" ,
106
+ flag_values = {
107
+ ":config" : "custom" ,
108
+ },
109
+ )
110
+
111
+ public_headers_no_gen = ["include/gz/common/Profiler.hh" ]
112
+
55
113
public_headers = public_headers_no_gen + [
56
114
"include/gz/common/profiler/Export.hh" ,
57
115
]
58
116
59
- private_headers = [
60
- "src/ProfilerImpl.hh" ,
61
- "src/RemoteryProfilerImpl.hh" ,
62
- "include/RemoteryConfig.h" ,
63
- ]
117
+ sources = ["src/Profiler.cc" ]
64
118
65
119
cc_library (
66
120
name = "profiler" ,
67
121
srcs = sources ,
68
- hdrs = public_headers + private_headers ,
69
- defines = [
70
- "GZ_PROFILER_ENABLE=1" ,
71
- "GZ_PROFILER_REMOTERY=1" ,
72
- ],
122
+ hdrs = public_headers ,
123
+ defines = select ({
124
+ "disabled" : [
125
+ "GZ_PROFILER_ENABLE=0" ,
126
+ "GZ_PROFILER_REMOTERY=0" ,
127
+ ],
128
+ "use_remotery" : [
129
+ "GZ_PROFILER_ENABLE=1" ,
130
+ "GZ_PROFILER_REMOTERY=1" ,
131
+ ],
132
+ "use_custom" : [
133
+ "GZ_PROFILER_ENABLE=1" ,
134
+ "GZ_PROFILER_REMOTERY=0" ,
135
+ ],
136
+ }),
73
137
includes = ["include" ],
74
138
visibility = ["//visibility:public" ],
75
139
deps = [
140
+ ":ProfilerImplInterface" ,
76
141
"//:gz-common" ,
77
- "@remotery" ,
78
- ],
142
+ ] + select ({
143
+ "use_remotery" : [":RemoteryProfilerImpl" ],
144
+ "//conditions:default" : [],
145
+ }),
79
146
)
80
147
81
148
cc_test (
82
149
name = "Profiler_Disabled_TEST" ,
83
150
srcs = ["src/Profiler_Disabled_TEST.cc" ],
84
- copts = [ "-Wno-macro-redefined" ],
85
- defines = [
86
- "GZ_PROFILER_ENABLE=0" ,
87
- "GZ_PROFILER_REMOTERY=0" ,
88
- ] ,
151
+ # This test is only compatible with --//profiler:config="disabled"
152
+ defines = select ({
153
+ "disabled" : [] ,
154
+ "//conditions:default" : [ "BAZEL_SKIP_PROFILER_TEST=1" ] ,
155
+ }) ,
89
156
deps = [
90
157
":profiler" ,
91
158
"@googletest//:gtest" ,
@@ -96,9 +163,41 @@ cc_test(
96
163
cc_test (
97
164
name = "Profiler_Remotery_TEST" ,
98
165
srcs = ["src/Profiler_Remotery_TEST.cc" ],
166
+ # This test is only compatible with --//profiler:config="remotery"
167
+ defines = select ({
168
+ "use_remotery" : [],
169
+ "//conditions:default" : ["BAZEL_SKIP_PROFILER_TEST=1" ],
170
+ }),
171
+ deps = [
172
+ ":profiler" ,
173
+ "@googletest//:gtest" ,
174
+ "@googletest//:gtest_main" ,
175
+ ],
176
+ )
177
+
178
+ cc_test (
179
+ name = "Profiler_Custom_TEST" ,
180
+ srcs = ["src/Profiler_Custom_TEST.cc" ],
181
+ # This test is only compatible with --//profiler:config="custom"
182
+ defines = select ({
183
+ "use_custom" : [],
184
+ "//conditions:default" : ["BAZEL_SKIP_PROFILER_TEST=1" ],
185
+ }),
99
186
deps = [
100
187
":profiler" ,
101
188
"@googletest//:gtest" ,
102
189
"@googletest//:gtest_main" ,
103
190
],
104
191
)
192
+
193
+ cc_test (
194
+ name = "Profiler_Error_TEST" ,
195
+ srcs = ["src/Profiler_Error_TEST.cc" ],
196
+ deps = [
197
+ ":RemoteryProfilerImpl" ,
198
+ ":profiler" ,
199
+ "@googletest//:gtest" ,
200
+ "@googletest//:gtest_main" ,
201
+ "@remotery" ,
202
+ ],
203
+ )
0 commit comments