1# Copyright 2019 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import("//build/config/python.gni") 6import("//components/metrics/structured/buildflags/buildflags.gni") 7import("//testing/test.gni") 8import("//third_party/protobuf/proto_library.gni") 9 10# Structured metrics is subcomponent of UMA that gathers and reports structured 11# events with several attached metrics. 12static_library("structured") { 13 sources = [ 14 "key_data_prefs_delegate.cc", 15 "key_data_prefs_delegate.h", 16 "key_data_provider_file.cc", 17 "key_data_provider_file.h", 18 "key_data_provider_prefs.cc", 19 "key_data_provider_prefs.h", 20 "reporting/structured_metrics_log_metrics.cc", 21 "reporting/structured_metrics_log_metrics.h", 22 "reporting/structured_metrics_reporting_service.cc", 23 "reporting/structured_metrics_reporting_service.h", 24 "structured_metrics_prefs.cc", 25 "structured_metrics_prefs.h", 26 "structured_metrics_recorder.cc", 27 "structured_metrics_recorder.h", 28 "structured_metrics_scheduler.cc", 29 "structured_metrics_scheduler.h", 30 "structured_metrics_service.cc", 31 "structured_metrics_service.h", 32 ] 33 34 public_deps = [ 35 ":common", 36 ":events", 37 ":proto", 38 "//components/metrics/structured/buildflags", 39 "//components/metrics/structured/lib:proto", 40 "//third_party/metrics_proto", 41 ] 42 43 deps = [ 44 ":structured_events", 45 ":structured_metrics_validator", 46 "//base", 47 "//components/metrics", 48 "//components/metrics/structured/lib", 49 "//components/metrics/structured/lib:proto", 50 "//components/metrics/structured/mojom", 51 "//components/prefs", 52 "//crypto", 53 "//third_party/protobuf:protobuf_lite", 54 ] 55} 56 57if (is_chromeos_ash) { 58 static_library("external_metrics") { 59 sources = [ 60 "external_metrics.cc", 61 "external_metrics.h", 62 ] 63 deps = [ 64 ":common", 65 ":proto", 66 ":structured_events", 67 "//base", 68 ] 69 } 70} 71 72static_library("events") { 73 sources = [ 74 "enums.h", 75 "event.cc", 76 "event.h", 77 "structured_metrics_client.cc", 78 "structured_metrics_client.h", 79 ] 80 deps = [ "//base" ] 81} 82 83proto_library("proto") { 84 # These protos are only used internally, so make them visible only to 85 # subdirectories. 86 visibility = [ "./*" ] 87 proto_in_dir = "//" 88 generate_python = false 89 sources = [ "proto/event_storage.proto" ] 90 91 # This is required because metrics_proto/BUILD.gn sets proto_in_dir as ".", 92 # which means protos can't be referred to by absolute paths from within other 93 # protos. 94 import_dirs = [ "//third_party/metrics_proto" ] 95 proto_deps = [ "//third_party/metrics_proto" ] 96 link_deps = [ "//third_party/metrics_proto" ] 97} 98 99# Sources used by all static libraries in this BUILD file. 100source_set("common") { 101 sources = [ 102 "delegating_events_processor.cc", 103 "delegating_events_processor.h", 104 "events_processor_interface.h", 105 "histogram_util.cc", 106 "histogram_util.h", 107 "recorder.cc", 108 "recorder.h", 109 ] 110 111 public_deps = [ 112 ":events", 113 ":structured_metrics_features", 114 ] 115 116 deps = [ 117 ":proto", 118 ":structured_metrics_validator", 119 "//base", 120 "//components/metrics/structured/lib", 121 "//components/prefs", 122 "//third_party/metrics_proto", 123 ] 124} 125 126static_library("structured_metrics_features") { 127 sources = [ 128 "structured_metrics_features.cc", 129 "structured_metrics_features.h", 130 ] 131 132 public_deps = [ "//base" ] 133} 134 135action("gen_structured_events") { 136 script = "//tools/metrics/structured/gen_events.py" 137 138 # Re-generate the outputs if the codegen code changes: 139 inputs = [ 140 "//tools/metrics/structured/codegen.py", 141 "//tools/metrics/structured/gen_events.py", 142 "//tools/metrics/structured/sync/model.py", 143 "//tools/metrics/structured/sync/model_util.py", 144 "//tools/metrics/structured/templates_events.py", 145 ] 146 sources = [ "//tools/metrics/structured/sync/structured.xml" ] 147 148 outdir = "$target_gen_dir" 149 150 outputs = [ 151 outdir + "/structured_events.cc", 152 outdir + "/structured_events.h", 153 ] 154 155 args = [ 156 "--input", 157 rebase_path(sources[0], root_build_dir), 158 "--output", 159 rebase_path(outdir, root_build_dir), 160 ] 161} 162 163# TODO(b/309122738): Generate the events by platform. 164static_library("structured_events") { 165 sources = get_target_outputs(":gen_structured_events") 166 167 public_deps = [ 168 ":events", 169 "//components/metrics/structured/buildflags", 170 ] 171 172 deps = [ 173 ":gen_structured_events", 174 "//base", 175 ] 176} 177 178action("gen_structured_metrics_validator") { 179 script = "//tools/metrics/structured/gen_validator.py" 180 181 # Re-generate the outputs if the codegen code changes: 182 inputs = [ 183 "//tools/metrics/structured/codegen.py", 184 "//tools/metrics/structured/gen_validator.py", 185 "//tools/metrics/structured/sync/model.py", 186 "//tools/metrics/structured/sync/model_util.py", 187 "//tools/metrics/structured/templates_validator.py", 188 ] 189 sources = [ "//tools/metrics/structured/sync/structured.xml" ] 190 191 outdir = "$target_gen_dir" 192 193 outputs = [ 194 outdir + "/structured_metrics_validator.cc", 195 outdir + "/structured_metrics_validator.h", 196 ] 197 198 args = [ 199 "--input", 200 rebase_path(sources[0], root_build_dir), 201 "--output", 202 rebase_path(outdir, root_build_dir), 203 ] 204 205 if (is_chromeos_ash) { 206 sources += [ "//tools/metrics/structured/sync/structured_chromiumos.xml" ] 207 208 args += [ 209 "--cros_input", 210 rebase_path(sources[1], root_build_dir), 211 ] 212 } 213} 214 215static_library("structured_metrics_validator") { 216 sources = get_target_outputs(":gen_structured_metrics_validator") + [ 217 "event_validator.cc", 218 "event_validator.h", 219 "project_validator.cc", 220 "project_validator.h", 221 ] 222 223 deps = [ 224 ":events", 225 ":gen_structured_metrics_validator", 226 "//base", 227 "//third_party/metrics_proto", 228 ] 229} 230 231static_library("test_support") { 232 testonly = true 233 sources = [ 234 "test/test_event_storage.cc", 235 "test/test_event_storage.h", 236 "test/test_key_data_provider.cc", 237 "test/test_key_data_provider.h", 238 "test/test_structured_metrics_provider.cc", 239 "test/test_structured_metrics_provider.h", 240 "test/test_structured_metrics_recorder.cc", 241 "test/test_structured_metrics_recorder.h", 242 ] 243 deps = [ 244 ":structured", 245 ":structured_metrics_validator", 246 "//base", 247 "//base/test:test_support", 248 "//components/metrics:metrics", 249 "//components/metrics/structured/lib", 250 ] 251} 252 253source_set("unit_tests") { 254 testonly = true 255 sources = [ 256 "key_data_prefs_delegate_unittest.cc", 257 "structured_metrics_recorder_unittest.cc", 258 "structured_metrics_service_unittest.cc", 259 ] 260 261 deps = [ 262 ":events", 263 ":proto", 264 ":structured", 265 ":structured_events", 266 ":structured_metrics_validator", 267 ":test_support", 268 "//base", 269 "//base/test:test_support", 270 "//components/metrics", 271 "//components/metrics:test_support", 272 "//components/metrics/structured/lib", 273 "//components/metrics/structured/lib:proto", 274 "//components/prefs", 275 "//components/prefs:test_support", 276 "//testing/gtest", 277 ] 278 279 if (is_chromeos_ash) { 280 sources += [ "external_metrics_unittest.cc" ] 281 282 deps += [ ":external_metrics" ] 283 } 284} 285 286# Convenience testing target 287test("structured_metrics_unittests") { 288 deps = [ 289 ":unit_tests", 290 "//components/metrics/structured/lib:unit_tests", 291 "//components/metrics/structured/mojom:unit_tests", 292 "//components/test:run_all_unittests", 293 ] 294} 295