1// 2// Copyright (C) 2017 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// Build the host executable: stats-log-api-gen 19// ========================================================== 20package { 21 default_team: "trendy_team_android_telemetry_client_infra", 22 default_applicable_licenses: ["Android-Apache-2.0"], 23} 24 25cc_defaults { 26 name: "stats-log-api-gen-defaults", 27 srcs: [ 28 "Collation.cpp", 29 "settings_provider.cpp", 30 "utils.cpp", 31 ], 32 cflags: [ 33 "-Wall", 34 "-Werror", 35 "-Wno-deprecated-declarations", 36 ], 37 shared_libs: [ 38 "libstats_proto_host", 39 "libprotobuf-cpp-full", 40 ], 41 proto: { 42 type: "full", 43 }, 44} 45 46cc_binary_host { 47 name: "stats-log-api-gen", 48 defaults: ["stats-log-api-gen-defaults"], 49 srcs: [ 50 "java_writer.cpp", 51 "java_writer_q.cpp", 52 "java_writer_vendor.cpp", 53 "main.cpp", 54 "native_writer.cpp", 55 "native_writer_vendor.cpp", 56 "rust_writer.cpp", 57 ], 58 cflags: [ 59 "-DWITH_VENDOR", 60 "-DJAVA_INCLUDE_SRCS_DIR=\"java/\"", 61 "-DCC_INCLUDE_HDRS_DIR=\"cc_hdrs/\"", 62 "-DCC_INCLUDE_SRCS_DIR=\"cc_srcs/\"", 63 64 ], 65 66 shared_libs: [ 67 "libbase", 68 ], 69 70 required: [ 71 "stats-log-api-gen-copy-java-srcs", 72 "stats-log-api-gen-copy-cc-hdrs", 73 "stats-log-api-gen-copy-cc-srcs", 74 ], 75 76 tidy: true, 77 78 tidy_checks: [ 79 "android-*", 80 "bugprone-*", 81 "cert-*", 82 "clang-analyzer-security*", 83 "google-*", 84 "misc-*", 85 "performance-*", 86 "-bugprone-narrowing-conversions", // lots of unsigned -> int conversions 87 "-cert-err34-c", 88 "-cert-msc30-c", // warning: rand() has limited randomness; use C++11 random library 89 "-cert-msc50-cpp", // warning: rand() has limited randomness; use C++11 random library 90 ], 91 92 tidy_checks_as_errors: [ 93 "android-*", 94 "bugprone-*", 95 "cert-*", 96 "clang-analyzer-security*", 97 "google-*", 98 "misc-*", 99 "performance-*", 100 ], 101} 102 103prebuilt_etc_host { 104 name: "stats-log-api-gen-copy-java-srcs", 105 srcs: [":stats-log-api-gen-java-srcs"], 106 sub_dir: "stats-log-api-gen/java", 107} 108 109prebuilt_etc_host { 110 name: "stats-log-api-gen-copy-cc-hdrs", 111 srcs: ["include_cc_hdrs/*.h"], 112 sub_dir: "stats-log-api-gen/cc_hdrs", 113} 114 115prebuilt_etc_host { 116 name: "stats-log-api-gen-copy-cc-srcs", 117 srcs: ["include_cc_srcs/*.cpp"], 118 sub_dir: "stats-log-api-gen/cc_srcs", 119} 120 121filegroup { 122 name: "stats-log-api-gen-java-srcs", 123 srcs: ["include_java/*.java"], 124 path: "include_java", 125} 126 127cc_test_library { 128 name: "stats-log-api-gen-cc-lib", 129 srcs: ["include_cc_srcs/StatsHistogram.cpp"], 130 export_include_dirs: ["include_cc_hdrs"], 131 host_supported: true, 132 device_supported: false, 133} 134 135// ========================================================== 136// Build the host test executable: stats-log-api-gen-test 137// ========================================================== 138cc_test_host { 139 name: "stats-log-api-gen-test", 140 defaults: ["stats-log-api-gen-defaults"], 141 test_suites: [ 142 "general-tests", 143 ], 144 cflags: [ 145 "-Wextra", 146 "-g", 147 "-DUNIT_TEST", 148 ], 149 srcs: [ 150 "test_api_gen.cpp", 151 "test_api_gen_vendor.cpp", 152 "test_collation.cpp", 153 "test.proto", 154 "test_feature_atoms.proto", 155 "test_vendor_atoms.proto", 156 ], 157 158 static_libs: [ 159 "libgmock_host", 160 "libtestvendoratoms", 161 ], 162 163 shared_libs: [ 164 "android.frameworks.stats-V2-ndk", 165 "libstatslog", 166 ], 167 168 proto: { 169 include_dirs: [ 170 "external/protobuf/src", 171 ], 172 }, 173 174 data: [ 175 ":libprotobuf-internal-protos", 176 ":libstats_internal_protos", 177 "test_external.proto", 178 ], 179 180 test_options: { 181 unit_test: true, 182 }, 183} 184 185// Filegroup for stats-log-api-gen test proto. 186filegroup { 187 name: "stats_log_api_gen_test_protos", 188 srcs: [ 189 "test.proto", 190 "test_external.proto", 191 "test_feature_atoms.proto", 192 "test_vendor_atoms.proto", 193 ], 194} 195 196genrule { 197 name: "test_vendor_atoms.h", 198 tools: ["stats-log-api-gen"], 199 cmd: "$(location stats-log-api-gen) --header $(out)" + 200 " --module test" + 201 " --namespace android,VendorAtoms" + 202 " --vendor-proto frameworks/proto_logging/stats/stats_log_api_gen/test_vendor_atoms.proto", 203 out: [ 204 "test_vendor_atoms.h", 205 ], 206 srcs: [ 207 "test_vendor_atoms.proto", 208 ":libprotobuf-internal-descriptor-proto", 209 ":libstats_atom_options_protos", 210 ], 211} 212 213genrule { 214 name: "test_vendor_atoms.cpp", 215 tools: ["stats-log-api-gen"], 216 cmd: "$(location stats-log-api-gen) --cpp $(out)" + 217 " --module test" + 218 " --importHeader test_vendor_atoms.h" + 219 " --namespace android,VendorAtoms" + 220 " --vendor-proto frameworks/proto_logging/stats/stats_log_api_gen/test_vendor_atoms.proto", 221 out: [ 222 "test_vendor_atoms.cpp", 223 ], 224 srcs: [ 225 "test_vendor_atoms.proto", 226 ":libprotobuf-internal-descriptor-proto", 227 ":libstats_atom_options_protos", 228 ], 229} 230 231cc_library_static { 232 name: "libtestvendoratoms", 233 host_supported: true, 234 generated_headers: [ 235 "test_vendor_atoms.h", 236 ], 237 generated_sources: [ 238 "test_vendor_atoms.cpp", 239 ], 240 export_generated_headers: [ 241 "test_vendor_atoms.h", 242 ], 243 shared_libs: [ 244 "android.frameworks.stats-V2-ndk", 245 ], 246} 247 248// ========================================================== 249// Native library 250// ========================================================== 251genrule { 252 name: "statslog.h", 253 tools: ["stats-log-api-gen"], 254 cmd: "$(location stats-log-api-gen) --header $(genDir)/statslog.h", 255 out: [ 256 "statslog.h", 257 ], 258} 259 260genrule { 261 name: "statslog.cpp", 262 tools: ["stats-log-api-gen"], 263 cmd: "$(location stats-log-api-gen) --cpp $(genDir)/statslog.cpp", 264 out: [ 265 "statslog.cpp", 266 ], 267} 268 269cc_library { 270 name: "libstatslog", 271 host_supported: true, 272 generated_sources: [ 273 "statslog.cpp", 274 ], 275 generated_headers: [ 276 "statslog.h", 277 ], 278 cflags: [ 279 "-Wall", 280 "-Werror", 281 ], 282 export_generated_headers: [ 283 "statslog.h", 284 ], 285 shared_libs: [ 286 "liblog", 287 "libcutils", 288 "libstatssocket", 289 "libstatspull", 290 ], 291 export_shared_lib_headers: [ 292 "libstatssocket", 293 "libstatspull", 294 ], 295 target: { 296 host: { 297 static_libs: [ 298 "libbase", 299 "statsd-aidl-ndk", 300 ], 301 shared_libs: ["libbinder_ndk"], 302 }, 303 darwin: { 304 enabled: false, 305 }, 306 }, 307} 308 309// ========================================================== 310// Rust library 311// ========================================================== 312 313genrule { 314 name: "statslog_header.rs", 315 tools: ["stats-log-api-gen"], 316 cmd: "$(location stats-log-api-gen) --rustHeader $(genDir)/statslog_header.rs --rustHeaderCrate statslog_rust_header", 317 out: [ 318 "statslog_header.rs", 319 ], 320} 321 322rust_library { 323 name: "libstatslog_rust_header", 324 crate_name: "statslog_rust_header", 325 srcs: [ 326 "rust_header_wrapper.rs", 327 ":statslog_header.rs", 328 ], 329 rustlibs: [ 330 "libstatspull_bindgen", 331 "libthiserror", 332 ], 333 apex_available: [ 334 "//apex_available:platform", 335 "com.android.resolv", 336 "com.android.virt", 337 ], 338 min_sdk_version: "29", 339} 340 341genrule { 342 name: "statslog.rs", 343 tools: ["stats-log-api-gen"], 344 cmd: "$(location stats-log-api-gen) --rust $(genDir)/statslog.rs --rustHeaderCrate statslog_rust_header", 345 out: [ 346 "statslog.rs", 347 ], 348} 349 350// libstatslog_rust is available from "//apex_available:platform" only. 351// If you want to support libstatslog from Rust in other apex, you should create 352// a new libstatslog_<module>_rust library (e.g. libstatslog_dns_resolver_rust). 353rust_library { 354 name: "libstatslog_rust", 355 crate_name: "statslog_rust", 356 srcs: [ 357 "rust_wrapper.rs", 358 ":statslog.rs", 359 ], 360 rustlibs: [ 361 "libstatslog_rust_header", 362 "libstatspull_bindgen", 363 ], 364 flags: [ 365 "-A clippy::needless-lifetimes", 366 ], 367} 368