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.c",
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    ],
56    min_sdk_version: "30",
57}
58
59cc_library_shared {
60    name: "libstatssocket",
61    defaults: [
62        "libstatssocket_defaults",
63    ],
64    host_supported: true,
65    stl: "libc++_static",
66    export_include_dirs: ["include"],
67    // enumerate stable entry points for APEX use
68    target: {
69        darwin: {
70            enabled: false,
71        },
72    },
73    version_script: "libstatssocket.map.txt",
74    stubs: {
75        symbol_file: "libstatssocket.map.txt",
76        versions: [
77            "30",
78        ],
79    },
80    apex_available: [
81        "com.android.os.statsd",
82        "test_com.android.os.statsd",
83    ],
84}
85
86cc_library_headers {
87    name: "libstatssocket_headers",
88    export_include_dirs: ["include"],
89    apex_available: [
90        "com.android.resolv",
91        "//apex_available:platform",
92    ],
93    min_sdk_version: "29",
94}
95
96filegroup {
97    name: "libstatssocket_test_default_map",
98    srcs: ["libstatssocket_test_default.map"],
99}
100
101cc_library_headers {
102    name: "libstatssocket_test_headers",
103    export_include_dirs: ["tests/include"],
104    min_sdk_version: "30",
105}
106
107cc_test {
108    name: "libstatssocket_test",
109    defaults: ["libstatssocket_defaults"],
110    srcs: [
111        "tests/stats_event_test.cpp",
112        "tests/stats_writer_test.cpp",
113        "tests/stats_buffer_writer_queue_test.cpp",
114        "tests/stats_socketlog_test.cpp",
115    ],
116    cflags: [
117        "-Wall",
118        "-Werror",
119        "-Wthread-safety",
120    ],
121
122    // These tests run on older platform versions, so many libraries (such as libbase and libc++)
123    // need to be linked statically. The tests also need to be linked with a version script to
124    // ensure that the statically-linked library isn't exported from the executable, where it
125    // would override the shared libraries that the platform itself uses.
126    // See http://b/333438055 for an example of what goes wrong when libc++ is partially exported
127    // from an executable.
128    version_script: ":libstatssocket_test_default_map",
129    stl: "c++_static",
130
131    static_libs: [
132        "libbase",
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            "[email protected]",
203            "[email protected]",
204        ],
205    },
206}
207