# Copyright 2019 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import("//build/config/python.gni") import("//components/metrics/structured/buildflags/buildflags.gni") import("//testing/test.gni") import("//third_party/protobuf/proto_library.gni") # Structured metrics is subcomponent of UMA that gathers and reports structured # events with several attached metrics. static_library("structured") { sources = [ "key_data_prefs_delegate.cc", "key_data_prefs_delegate.h", "key_data_provider_file.cc", "key_data_provider_file.h", "key_data_provider_prefs.cc", "key_data_provider_prefs.h", "reporting/structured_metrics_log_metrics.cc", "reporting/structured_metrics_log_metrics.h", "reporting/structured_metrics_reporting_service.cc", "reporting/structured_metrics_reporting_service.h", "structured_metrics_prefs.cc", "structured_metrics_prefs.h", "structured_metrics_recorder.cc", "structured_metrics_recorder.h", "structured_metrics_scheduler.cc", "structured_metrics_scheduler.h", "structured_metrics_service.cc", "structured_metrics_service.h", ] public_deps = [ ":common", ":events", ":proto", "//components/metrics/structured/buildflags", "//components/metrics/structured/lib:proto", "//third_party/metrics_proto", ] deps = [ ":structured_events", ":structured_metrics_validator", "//base", "//components/metrics", "//components/metrics/structured/lib", "//components/metrics/structured/lib:proto", "//components/metrics/structured/mojom", "//components/prefs", "//crypto", "//third_party/protobuf:protobuf_lite", ] } if (is_chromeos_ash) { static_library("external_metrics") { sources = [ "external_metrics.cc", "external_metrics.h", ] deps = [ ":common", ":proto", ":structured_events", "//base", ] } } static_library("events") { sources = [ "enums.h", "event.cc", "event.h", "structured_metrics_client.cc", "structured_metrics_client.h", ] deps = [ "//base" ] } proto_library("proto") { # These protos are only used internally, so make them visible only to # subdirectories. visibility = [ "./*" ] proto_in_dir = "//" generate_python = false sources = [ "proto/event_storage.proto" ] # This is required because metrics_proto/BUILD.gn sets proto_in_dir as ".", # which means protos can't be referred to by absolute paths from within other # protos. import_dirs = [ "//third_party/metrics_proto" ] proto_deps = [ "//third_party/metrics_proto" ] link_deps = [ "//third_party/metrics_proto" ] } # Sources used by all static libraries in this BUILD file. source_set("common") { sources = [ "delegating_events_processor.cc", "delegating_events_processor.h", "events_processor_interface.h", "histogram_util.cc", "histogram_util.h", "recorder.cc", "recorder.h", ] public_deps = [ ":events", ":structured_metrics_features", ] deps = [ ":proto", ":structured_metrics_validator", "//base", "//components/metrics/structured/lib", "//components/prefs", "//third_party/metrics_proto", ] } static_library("structured_metrics_features") { sources = [ "structured_metrics_features.cc", "structured_metrics_features.h", ] public_deps = [ "//base" ] } action("gen_structured_events") { script = "//tools/metrics/structured/gen_events.py" # Re-generate the outputs if the codegen code changes: inputs = [ "//tools/metrics/structured/codegen.py", "//tools/metrics/structured/gen_events.py", "//tools/metrics/structured/sync/model.py", "//tools/metrics/structured/sync/model_util.py", "//tools/metrics/structured/templates_events.py", ] sources = [ "//tools/metrics/structured/sync/structured.xml" ] outdir = "$target_gen_dir" outputs = [ outdir + "/structured_events.cc", outdir + "/structured_events.h", ] args = [ "--input", rebase_path(sources[0], root_build_dir), "--output", rebase_path(outdir, root_build_dir), ] } # TODO(b/309122738): Generate the events by platform. static_library("structured_events") { sources = get_target_outputs(":gen_structured_events") public_deps = [ ":events", "//components/metrics/structured/buildflags", ] deps = [ ":gen_structured_events", "//base", ] } action("gen_structured_metrics_validator") { script = "//tools/metrics/structured/gen_validator.py" # Re-generate the outputs if the codegen code changes: inputs = [ "//tools/metrics/structured/codegen.py", "//tools/metrics/structured/gen_validator.py", "//tools/metrics/structured/sync/model.py", "//tools/metrics/structured/sync/model_util.py", "//tools/metrics/structured/templates_validator.py", ] sources = [ "//tools/metrics/structured/sync/structured.xml" ] outdir = "$target_gen_dir" outputs = [ outdir + "/structured_metrics_validator.cc", outdir + "/structured_metrics_validator.h", ] args = [ "--input", rebase_path(sources[0], root_build_dir), "--output", rebase_path(outdir, root_build_dir), ] if (is_chromeos_ash) { sources += [ "//tools/metrics/structured/sync/structured_chromiumos.xml" ] args += [ "--cros_input", rebase_path(sources[1], root_build_dir), ] } } static_library("structured_metrics_validator") { sources = get_target_outputs(":gen_structured_metrics_validator") + [ "event_validator.cc", "event_validator.h", "project_validator.cc", "project_validator.h", ] deps = [ ":events", ":gen_structured_metrics_validator", "//base", "//third_party/metrics_proto", ] } static_library("test_support") { testonly = true sources = [ "test/test_event_storage.cc", "test/test_event_storage.h", "test/test_key_data_provider.cc", "test/test_key_data_provider.h", "test/test_structured_metrics_provider.cc", "test/test_structured_metrics_provider.h", "test/test_structured_metrics_recorder.cc", "test/test_structured_metrics_recorder.h", ] deps = [ ":structured", ":structured_metrics_validator", "//base", "//base/test:test_support", "//components/metrics:metrics", "//components/metrics/structured/lib", ] } source_set("unit_tests") { testonly = true sources = [ "key_data_prefs_delegate_unittest.cc", "structured_metrics_recorder_unittest.cc", "structured_metrics_service_unittest.cc", ] deps = [ ":events", ":proto", ":structured", ":structured_events", ":structured_metrics_validator", ":test_support", "//base", "//base/test:test_support", "//components/metrics", "//components/metrics:test_support", "//components/metrics/structured/lib", "//components/metrics/structured/lib:proto", "//components/prefs", "//components/prefs:test_support", "//testing/gtest", ] if (is_chromeos_ash) { sources += [ "external_metrics_unittest.cc" ] deps += [ ":external_metrics" ] } } # Convenience testing target test("structured_metrics_unittests") { deps = [ ":unit_tests", "//components/metrics/structured/lib:unit_tests", "//components/metrics/structured/mojom:unit_tests", "//components/test:run_all_unittests", ] }