1//
2// Copyright (C) 2015 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
17package {
18    default_team: "trendy_team_native_tools_libraries",
19    default_applicable_licenses: ["system_libbase_license"],
20}
21
22license {
23    name: "system_libbase_license",
24    visibility: [":__subpackages__"],
25    license_kinds: [
26        "SPDX-license-identifier-Apache-2.0",
27        "SPDX-license-identifier-BSD",
28    ],
29    license_text: [
30        "NOTICE",
31    ],
32}
33
34cc_defaults {
35    name: "libbase_cflags_defaults",
36    cflags: [
37        "-Wall",
38        "-Werror",
39        "-Wextra",
40    ],
41    target: {
42        android: {
43            cflags: [
44                "-D_FILE_OFFSET_BITS=64",
45            ],
46        },
47        windows: {
48            cflags: [
49                "-D_POSIX_THREAD_SAFE_FUNCTIONS",
50            ],
51        },
52    },
53}
54
55cc_library_headers {
56    name: "libbase_headers",
57    vendor_available: true,
58    product_available: true,
59    ramdisk_available: true,
60    vendor_ramdisk_available: true,
61    recovery_available: true,
62    host_supported: true,
63    native_bridge_supported: true,
64    export_include_dirs: ["include"],
65
66    header_libs: ["fmtlib_headers"],
67    export_header_lib_headers: ["fmtlib_headers"],
68
69    target: {
70        linux_bionic: {
71            enabled: true,
72        },
73        windows: {
74            enabled: true,
75        },
76    },
77    apex_available: [
78        "//apex_available:anyapex",
79        "//apex_available:platform",
80    ],
81    min_sdk_version: "29",
82    sdk_version: "current",
83}
84
85cc_defaults {
86    name: "libbase_defaults",
87    defaults: ["libbase_cflags_defaults"],
88    srcs: [
89        "abi_compatibility.cpp",
90        "chrono_utils.cpp",
91        "cmsg.cpp",
92        "file.cpp",
93        "hex.cpp",
94        "logging.cpp",
95        "mapped_file.cpp",
96        "parsebool.cpp",
97        "parsenetaddress.cpp",
98        "posix_strerror_r.cpp",
99        "process.cpp",
100        "properties.cpp",
101        "result.cpp",
102        "stringprintf.cpp",
103        "strings.cpp",
104        "threads.cpp",
105        "test_utils.cpp",
106    ],
107
108    cppflags: ["-Wexit-time-destructors"],
109    shared_libs: ["liblog"],
110    target: {
111        android: {
112            sanitize: {
113                misc_undefined: ["integer"],
114            },
115
116        },
117        linux: {
118            srcs: [
119                "errors_unix.cpp",
120            ],
121        },
122        darwin: {
123            srcs: [
124                "errors_unix.cpp",
125            ],
126        },
127        linux_bionic: {
128            enabled: true,
129        },
130        windows: {
131            srcs: [
132                "errors_windows.cpp",
133                "utf8.cpp",
134            ],
135            exclude_srcs: [
136                "cmsg.cpp",
137            ],
138            enabled: true,
139        },
140    },
141    min_sdk_version: "29",
142}
143
144cc_library {
145    name: "libbase",
146    defaults: ["libbase_defaults"],
147    vendor_available: true,
148    product_available: true,
149    ramdisk_available: true,
150    vendor_ramdisk_available: true,
151    recovery_available: true,
152    host_supported: true,
153    native_bridge_supported: true,
154    double_loadable: true,
155    header_libs: [
156        "libbase_headers",
157    ],
158    export_header_lib_headers: ["libbase_headers"],
159    whole_static_libs: ["fmtlib"],
160    export_static_lib_headers: ["fmtlib"],
161    apex_available: [
162        "//apex_available:anyapex",
163        "//apex_available:platform",
164    ],
165}
166
167cc_library_static {
168    name: "libbase_ndk",
169    defaults: ["libbase_defaults"],
170    sdk_version: "current",
171    stl: "c++_static",
172    export_include_dirs: ["include"],
173    whole_static_libs: ["fmtlib_ndk"],
174    apex_available: [
175        "//apex_available:platform",
176        "com.android.mediaprovider",
177    ],
178}
179
180// Tests
181// ------------------------------------------------------------------------------
182cc_test {
183    name: "libbase_test",
184    defaults: ["libbase_cflags_defaults"],
185    host_supported: true,
186    require_root: true,
187    srcs: [
188        "cmsg_test.cpp",
189        "endian_test.cpp",
190        "errors_test.cpp",
191        "expected_test.cpp",
192        "file_test.cpp",
193        "function_ref_test.cpp",
194        "hex_test.cpp",
195        "logging_splitters_test.cpp",
196        "logging_test.cpp",
197        "macros_test.cpp",
198        "mapped_file_test.cpp",
199        "no_destructor_test.cpp",
200        "parsedouble_test.cpp",
201        "parsebool_test.cpp",
202        "parseint_test.cpp",
203        "parsenetaddress_test.cpp",
204        "process_test.cpp",
205        "properties_test.cpp",
206        "result_test.cpp",
207        "scopeguard_test.cpp",
208        "stringprintf_test.cpp",
209        "strings_test.cpp",
210        "test_main.cpp",
211        "test_utils_test.cpp",
212    ],
213    target: {
214        android: {
215            sanitize: {
216                misc_undefined: ["integer"],
217            },
218        },
219        linux: {
220            srcs: ["chrono_utils_test.cpp"],
221        },
222        windows: {
223            srcs: ["utf8_test.cpp"],
224            cflags: ["-Wno-unused-parameter"],
225            enabled: true,
226        },
227    },
228    local_include_dirs: ["."],
229    shared_libs: ["libbase"],
230    static_libs: ["libgmock"],
231    compile_multilib: "both",
232    multilib: {
233        lib32: {
234            suffix: "32",
235        },
236        lib64: {
237            suffix: "64",
238        },
239    },
240    test_suites: ["device-tests"],
241}
242
243cc_test {
244    name: "libbase_tidy_test",
245    defaults: ["libbase_cflags_defaults"],
246    host_supported: true,
247
248    tidy: true,
249    tidy_checks_as_errors: ["bugprone-use-after-move"],
250
251    srcs: [
252        "tidy/unique_fd_test.cpp",
253        "tidy/unique_fd_test2.cpp",
254    ],
255
256    shared_libs: ["libbase"],
257    test_suites: ["device_tests"],
258}
259
260// Can be removed when we move to c++20
261cc_test {
262    name: "libbase_result_constraint_test",
263    defaults: ["libbase_cflags_defaults"],
264    host_supported: true,
265    srcs: [
266        "result_test_constraint.cpp",
267    ],
268    target: {
269        android: {
270            sanitize: {
271                misc_undefined: ["integer"],
272            },
273        },
274    },
275    cpp_std: "gnu++20",
276    local_include_dirs: ["."],
277    shared_libs: ["libbase"],
278    static_libs: ["libgmock"],
279    compile_multilib: "both",
280    multilib: {
281        lib32: {
282            suffix: "32",
283        },
284        lib64: {
285            suffix: "64",
286        },
287    },
288    test_suites: ["device-tests"],
289}
290
291cc_benchmark {
292    name: "libbase_benchmark",
293    defaults: ["libbase_cflags_defaults"],
294
295    srcs: [
296        "file_benchmark.cpp",
297        "format_benchmark.cpp",
298        "function_ref_benchmark.cpp",
299    ],
300    shared_libs: ["libbase"],
301
302    compile_multilib: "both",
303    multilib: {
304        lib32: {
305            suffix: "32",
306        },
307        lib64: {
308            suffix: "64",
309        },
310    },
311}
312
313cc_fuzz {
314    name: "libbase_parsenetaddress_fuzzer",
315    shared_libs: ["libbase"],
316    host_supported: true,
317    srcs: ["parsenetaddress_fuzzer.cpp"],
318    dictionary: "parsenetaddress_fuzzer.dict",
319
320    fuzz_config: {
321        cc: [
322            "android-bionic@google.com",
323        ],
324        componentid: 128577,
325    },
326}
327