1//
2// Copyright (C) 2013 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
16package {
17    default_team: "trendy_team_native_tools_libraries",
18    default_applicable_licenses: ["Android-Apache-2.0"],
19}
20
21cc_defaults {
22    name: "libziparchive_flags",
23    cpp_std: "c++2a",
24    cflags: [
25        // ZLIB_CONST turns on const for input buffers, which is pretty standard.
26        "-DZLIB_CONST",
27        "-Werror",
28        "-D_FILE_OFFSET_BITS=64",
29    ],
30    cppflags: [
31        // Incorrectly warns when C++11 empty brace {} initializer is used.
32        // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61489
33        "-Wno-missing-field-initializers",
34        "-Wconversion",
35        "-Wno-sign-conversion",
36    ],
37
38    // Enable -Wold-style-cast only for non-Windows targets.  _islower_l,
39    // _isupper_l etc. in MinGW locale_win32.h (included from
40    // libcxx/include/__locale) has an old-style-cast.
41    target: {
42        not_windows: {
43            cppflags: [
44                "-Wold-style-cast",
45            ],
46        },
47    },
48    sanitize: {
49        misc_undefined: [
50            "signed-integer-overflow",
51            "unsigned-integer-overflow",
52            "shift",
53            "integer-divide-by-zero",
54            "implicit-signed-integer-truncation",
55            // TODO: Fix crash when we enable this option
56            // "implicit-unsigned-integer-truncation",
57            // TODO: not tested yet.
58            // "implicit-integer-sign-change",
59        ],
60    },
61}
62
63cc_defaults {
64    name: "libziparchive_defaults",
65    local_include_dirs: ["incfs_support/include/"],
66    srcs: [
67        "zip_archive.cc",
68        "zip_archive_stream_entry.cc",
69        "zip_cd_entry_map.cc",
70        "zip_error.cpp",
71        "zip_writer.cc",
72    ],
73
74    target: {
75        windows: {
76            cflags: ["-mno-ms-bitfields"],
77
78            enabled: true,
79        },
80    },
81
82    shared_libs: [
83        "libbase",
84        "liblog",
85    ],
86
87    // for FRIEND_TEST
88    header_libs: ["libgtest_prod_headers"],
89    export_header_lib_headers: ["libgtest_prod_headers"],
90
91    export_include_dirs: ["include"],
92}
93
94cc_defaults {
95    name: "incfs_support_defaults",
96    cflags: ["-DZIPARCHIVE_DISABLE_CALLBACK_API=1"],
97    export_include_dirs: ["incfs_support/include/"],
98    tidy: true,
99    tidy_checks: [
100        "android-*",
101        "cert-*",
102        "clang-analyzer-security*",
103        "-cert-err34-c",
104        "clang-analyzer-security*",
105        // Disabling due to many unavoidable warnings from POSIX API usage.
106        "-google-runtime-int",
107        "-google-explicit-constructor",
108        // do not call 'longjmp'; consider using exception handling instead - library relies on it
109        "-cert-err52-cpp",
110        // typedef pointer used with const: all Zip* typedefs generate this when declared as const
111        "-misc-misplaced-const",
112    ],
113}
114
115cc_defaults {
116    name: "libziparchive_lib_defaults",
117    host_supported: true,
118    vendor_available: true,
119    product_available: true,
120    recovery_available: true,
121    vendor_ramdisk_available: true,
122    native_bridge_supported: true,
123    double_loadable: true,
124    export_shared_lib_headers: ["libbase"],
125
126    defaults: [
127        "libziparchive_defaults",
128        "libziparchive_flags",
129    ],
130    shared_libs: [
131        "liblog",
132        "libbase",
133        "libz",
134    ],
135    target: {
136        linux_bionic: {
137            enabled: true,
138        },
139    },
140
141    apex_available: [
142        "//apex_available:platform",
143        "com.android.art",
144        "com.android.art.debug",
145        "com.android.virt",
146    ],
147    min_sdk_version: "apex_inherit",
148}
149
150cc_library {
151    name: "libziparchive",
152    defaults: ["libziparchive_lib_defaults"],
153    cflags: [
154        // Disable incfs hardending code for the default library
155        "-DINCFS_SUPPORT_DISABLED=1",
156    ],
157    apex_available: ["com.android.runtime"],
158}
159
160cc_library_static {
161    name: "libziparchive_for_incfs",
162    defaults: [
163        "libziparchive_lib_defaults",
164        "incfs_support_defaults",
165    ],
166    srcs: [
167        "incfs_support/signal_handling.cpp",
168    ],
169}
170
171// Tests.
172cc_test {
173    name: "ziparchive-tests",
174    host_supported: true,
175    defaults: ["libziparchive_flags"],
176
177    data: [
178        "testdata/**/*",
179    ],
180
181    srcs: [
182        "entry_name_utils_test.cc",
183        "zip_archive_test.cc",
184        "zip_writer_test.cc",
185    ],
186    shared_libs: [
187        "libbase",
188        "liblog",
189    ],
190
191    static_libs: [
192        "libziparchive",
193        "libz",
194        "libutils",
195    ],
196
197    target: {
198        host: {
199            cppflags: ["-Wno-unnamed-type-template-args"],
200        },
201        windows: {
202            enabled: true,
203        },
204    },
205    test_suites: ["device-tests"],
206}
207
208// Performance benchmarks.
209cc_benchmark {
210    name: "ziparchive-benchmarks",
211    defaults: ["libziparchive_flags"],
212
213    srcs: [
214        "zip_archive_benchmark.cpp",
215    ],
216    shared_libs: [
217        "libbase",
218        "liblog",
219    ],
220
221    static_libs: [
222        "libziparchive",
223        "libz",
224        "libutils",
225    ],
226
227    target: {
228        host: {
229            cppflags: ["-Wno-unnamed-type-template-args"],
230        },
231    },
232}
233
234cc_binary {
235    name: "ziptool",
236    defaults: ["libziparchive_flags"],
237    srcs: ["ziptool.cpp"],
238    shared_libs: [
239        "libbase",
240        "libziparchive",
241        "libz",
242    ],
243    recovery_available: true,
244    host_supported: true,
245    target: {
246        android: {
247            symlinks: [
248                "unzip",
249                "zipinfo",
250            ],
251        },
252    },
253}
254
255cc_fuzz {
256    name: "libziparchive_fuzzer",
257    srcs: ["libziparchive_fuzzer.cpp"],
258    static_libs: [
259        "libziparchive",
260        "libbase",
261        "libz",
262        "liblog",
263    ],
264    host_supported: true,
265    corpus: ["testdata/*"],
266}
267
268cc_fuzz {
269    name: "libziparchive_for_incfs_fuzzer",
270    srcs: ["libziparchive_fuzzer.cpp"],
271    static_libs: [
272        "libziparchive_for_incfs",
273        "libbase",
274        "libz",
275        "liblog",
276    ],
277    host_supported: true,
278    corpus: ["testdata/*"],
279}
280
281cc_fuzz {
282    name: "libziparchive_writer_fuzzer",
283    srcs: ["libziparchive_writer_fuzzer.cpp"],
284    static_libs: [
285        "libziparchive",
286        "libbase",
287        "libz",
288        "liblog",
289    ],
290    host_supported: true,
291    corpus: ["testdata/*"],
292}
293
294sh_test {
295    name: "ziptool-tests",
296    src: "run-ziptool-tests-on-android.sh",
297    filename: "run-ziptool-tests-on-android.sh",
298    test_suites: ["general-tests"],
299    host_supported: true,
300    device_supported: false,
301    data: ["cli-tests/**/*"],
302    target_required: [
303        "cli-test",
304        "ziptool",
305    ],
306    data_device_bins: ["cli-test"],
307}
308
309python_test_host {
310    name: "ziparchive_tests_large",
311    srcs: ["test_ziparchive_large.py"],
312    main: "test_ziparchive_large.py",
313    test_suites: ["general-tests"],
314    test_options: {
315        unit_test: false,
316    },
317}
318