1// 2// Copyright (C) 2018 The Android Open Source Project 3// 4// Licensed under the Apache License, Version 2.0 (the "License"); 5// you may not use this file except in compliance with the License. 6// You may obtain a copy of the License at 7// 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// See the License for the specific language governing permissions and 14// limitations under the License. 15// 16 17// ========================================================================= 18// Native library to write stats log to statsd socket on Android R and later 19// ========================================================================= 20package { 21 default_applicable_licenses: ["Android-Apache-2.0"], 22 default_team: "trendy_team_android_telemetry_client_infra", 23} 24 25cc_defaults { 26 name: "libstatssocket_defaults", 27 srcs: [ 28 "stats_buffer_writer.cpp", 29 "stats_buffer_writer_queue.cpp", 30 "stats_event.c", 31 "stats_socket.c", 32 "statsd_writer.cpp", 33 "stats_socket_loss_reporter.cpp", 34 "utils.cpp", 35 ], 36 local_include_dirs: [ 37 "include", 38 ], 39 generated_sources: ["stats_statsdsocketlog.cpp"], 40 generated_headers: ["stats_statsdsocketlog.h"], 41 header_libs: [ 42 "libcutils_headers", 43 "liblog_headers", 44 ], 45 cflags: [ 46 "-Wall", 47 "-Werror", 48 "-Wthread-safety", 49 50 // for local testing & benchmarking with statsd_benchmark 51 // "-DENABLE_BENCHMARK_SUPPORT", 52 ], 53 static_libs: [ 54 "libbase", 55 "statsd_flags_c_lib", 56 ], 57 min_sdk_version: "30", 58} 59 60cc_library_shared { 61 name: "libstatssocket", 62 defaults: [ 63 "libstatssocket_defaults", 64 ], 65 host_supported: true, 66 stl: "libc++_static", 67 export_include_dirs: ["include"], 68 // enumerate stable entry points for APEX use 69 target: { 70 darwin: { 71 enabled: false, 72 }, 73 }, 74 version_script: "libstatssocket.map.txt", 75 stubs: { 76 symbol_file: "libstatssocket.map.txt", 77 versions: [ 78 "30", 79 ], 80 }, 81 apex_available: ["com.android.os.statsd"], 82} 83 84cc_library_headers { 85 name: "libstatssocket_headers", 86 export_include_dirs: ["include"], 87 apex_available: [ 88 "com.android.resolv", 89 "//apex_available:platform", 90 ], 91 min_sdk_version: "29", 92} 93 94filegroup { 95 name: "libstatssocket_test_default_map", 96 srcs: ["libstatssocket_test_default.map"], 97} 98 99cc_library_headers { 100 name: "libstatssocket_test_headers", 101 export_include_dirs: ["tests/include"], 102 min_sdk_version: "30", 103} 104 105cc_test { 106 name: "libstatssocket_test", 107 defaults: ["libstatssocket_defaults"], 108 srcs: [ 109 "tests/logging_rate_limiter_test.cpp", 110 "tests/stats_event_test.cpp", 111 "tests/stats_writer_test.cpp", 112 "tests/stats_buffer_writer_queue_test.cpp", 113 "tests/stats_socketlog_test.cpp", 114 ], 115 cflags: [ 116 "-Wall", 117 "-Werror", 118 "-Wthread-safety", 119 ], 120 121 // These tests run on older platform versions, so many libraries (such as libbase and libc++) 122 // need to be linked statically. The tests also need to be linked with a version script to 123 // ensure that the statically-linked library isn't exported from the executable, where it 124 // would override the shared libraries that the platform itself uses. 125 // See http://b/333438055 for an example of what goes wrong when libc++ is partially exported 126 // from an executable. 127 version_script: ":libstatssocket_test_default_map", 128 stl: "c++_static", 129 130 static_libs: [ 131 "libbase", 132 "libflagtest", 133 "libgmock", 134 ], 135 shared_libs: [ 136 "libutils", 137 ], 138 header_libs: [ 139 "libstatssocket_test_headers", 140 ], 141 test_suites: [ 142 "device-tests", 143 "mts-statsd", 144 ], 145 test_config: "libstatssocket_test.xml", 146 //TODO(b/153588990): Remove when the build system properly separates. 147 //32bit and 64bit architectures. 148 compile_multilib: "both", 149 multilib: { 150 lib64: { 151 suffix: "64", 152 }, 153 lib32: { 154 suffix: "32", 155 }, 156 }, 157 require_root: true, 158} 159 160genrule { 161 name: "stats_statsdsocketlog.h", 162 tools: ["stats-log-api-gen"], 163 cmd: "$(location stats-log-api-gen) " + 164 "--header $(genDir)/stats_statsdsocketlog.h " + 165 "--module statsdsocket " + 166 "--namespace android,os,statsdsocket", 167 out: [ 168 "stats_statsdsocketlog.h", 169 ], 170} 171 172genrule { 173 name: "stats_statsdsocketlog.cpp", 174 tools: ["stats-log-api-gen"], 175 cmd: "$(location stats-log-api-gen) " + 176 "--cpp $(genDir)/stats_statsdsocketlog.cpp " + 177 "--module statsdsocket " + 178 "--namespace android,os,statsdsocket " + 179 "--importHeader stats_statsdsocketlog.h", 180 out: [ 181 "stats_statsdsocketlog.cpp", 182 ], 183} 184 185cc_fuzz { 186 name: "statsevent_fuzzer", 187 defaults: [ 188 "libstatssocket_defaults", 189 ], 190 srcs: [ 191 "fuzzers/stats_event_fuzzer.cpp", 192 ], 193 host_supported: true, 194 cflags: [ 195 "-Wall", 196 "-Wextra", 197 "-Werror", 198 "-Wno-unused-parameter", 199 ], 200 fuzz_config: { 201 cc: [ 202 "singhtejinder@google.com", 203 "sharaienko@google.com", 204 ], 205 }, 206} 207