| # Copyright 2024 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import("//build/components.gni") |
| import("//build/rust/rustc_library.gni") |
| import("//build/test.gni") |
| |
| template("rust_storage_trace") { |
| rustc_library(target_name) { |
| name = invoker.name |
| edition = "2021" |
| sources = [ "src/lib.rs" ] |
| visibility = invoker.visibility |
| with_unit_tests = true |
| test_deps = [ "//src/lib/fuchsia" ] |
| testonly = invoker.testonly |
| |
| if (invoker.enable_tracing) { |
| deps = [ "//src/lib/trace/rust:trace" ] |
| features = [ "tracing" ] |
| sources += [ "src/fuchsia.rs" ] |
| } else { |
| sources += [ "src/noop.rs" ] |
| } |
| } |
| } |
| |
| rust_storage_trace("trace") { |
| name = "storage_trace" |
| enable_tracing = is_fuchsia |
| visibility = [ "//src/storage/*" ] |
| testonly = false |
| } |
| |
| rust_storage_trace("storage_trace_enabled_rust") { |
| name = "storage_trace_enabled_rust" |
| enable_tracing = true |
| visibility = [ ":*" ] |
| testonly = true |
| } |
| |
| rust_storage_trace("storage_trace_disabled_rust") { |
| name = "storage_trace_disabled_rust" |
| enable_tracing = false |
| visibility = [ ":*" ] |
| testonly = true |
| } |
| |
| fuchsia_unittest_component("storage_trace_enabled_rust_test_component") { |
| deps = [ ":storage_trace_enabled_rust_test" ] |
| } |
| |
| fuchsia_unittest_component("storage_trace_disabled_rust_test_component") { |
| deps = [ ":storage_trace_disabled_rust_test" ] |
| } |
| |
| config("enable_tracing") { |
| visibility = [ ":*" ] |
| defines = [ "STORAGE_ENABLE_TRACING" ] |
| } |
| |
| template("cpp_storage_trace") { |
| lib_name = target_name |
| source_set(lib_name) { |
| public = [ "trace.h" ] |
| public_configs = [] |
| public_deps = [] |
| if (invoker.enable_tracing) { |
| public_configs += [ ":enable_tracing" ] |
| public_deps += [ ":storage_trace_enabled_cpp" ] |
| } else { |
| public_deps += [ ":storage_trace_disabled_cpp" ] |
| } |
| visibility = invoker.visibility |
| testonly = invoker.testonly |
| } |
| |
| test(invoker.test_name) { |
| visibility = [ ":*" ] |
| sources = [ "trace_test.cc" ] |
| deps = [ |
| ":${lib_name}", |
| "//src/lib/fxl/test:gtest_main", |
| "//third_party/googletest:gtest", |
| "//zircon/system/ulib/fbl", |
| ] |
| } |
| } |
| |
| source_set("storage_trace_enabled_cpp") { |
| public = [ "trace_enabled.h" ] |
| sources = [ "trace_enabled.cc" ] |
| public_deps = [ "//zircon/system/ulib/trace" ] |
| visibility = [ ":*" ] |
| } |
| |
| source_set("storage_trace_disabled_cpp") { |
| public = [ "trace_disabled.h" ] |
| sources = [] |
| public_deps = [ "//zircon/system/ulib/fbl" ] |
| visibility = [ ":*" ] |
| } |
| |
| # Generates the main c++ tracing target and a test that depends on it. The test is run on host to |
| # ensure that the :cpp target can compile for host builds. |
| cpp_storage_trace("cpp") { |
| enable_tracing = is_fuchsia |
| visibility = [ "//src/storage/*" ] |
| testonly = false |
| test_name = "storage_trace_cpp_test" |
| } |
| |
| # Generates a target with tracing enabled and a test that depends on it. The test ensures that |
| # standard tracing macro usage compiles when tracing is enabled. |
| cpp_storage_trace("storage_trace_force_enabled_cpp") { |
| enable_tracing = true |
| visibility = [ ":*" ] |
| testonly = true |
| test_name = "storage_trace_enabled_cpp_test" |
| } |
| |
| # Generates a target with tracing disabled and a test that depends on it. The test ensures that |
| # standard tracing macro usage compiles when tracing is disabled. |
| cpp_storage_trace("storage_trace_force_disabled_cpp") { |
| enable_tracing = false |
| visibility = [ ":*" ] |
| testonly = true |
| test_name = "storage_trace_disabled_cpp_test" |
| } |
| |
| fuchsia_unittest_component("storage_trace_enabled_cpp_test_component") { |
| component_name = "storage_trace_enabled_cpp_test" |
| deps = [ ":storage_trace_enabled_cpp_test" ] |
| } |
| |
| fuchsia_unittest_component("storage_trace_disabled_cpp_test_component") { |
| component_name = "storage_trace_disabled_cpp_test" |
| deps = [ ":storage_trace_disabled_cpp_test" ] |
| } |
| |
| fuchsia_test_package("storage_trace_tests") { |
| test_components = [ |
| ":storage_trace_enabled_rust_test_component", |
| ":storage_trace_disabled_rust_test_component", |
| ":storage_trace_enabled_cpp_test_component", |
| ":storage_trace_disabled_cpp_test_component", |
| ] |
| } |
| |
| group("tests") { |
| testonly = true |
| deps = [ |
| ":storage_trace_cpp_test($host_toolchain)", |
| ":storage_trace_tests", |
| ":trace_test($host_toolchain)", # storage_trace_lib_test |
| ] |
| } |