summaryrefslogtreecommitdiff
path: root/libdexfile/Android.bp
blob: ad528c1dd26f1e6eb222ce400e0d71d6aaeb936b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
//
// Copyright (C) 2011 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "art_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["art_license"],
}

cc_defaults {
    name: "libdexfile_defaults",
    defaults: ["art_defaults"],
    host_supported: true,
    tidy_timeout_srcs: [
        "dex/dex_file_verifier.cc",
    ],
    srcs: [
        "dex/art_dex_file_loader.cc",
        "dex/compact_dex_file.cc",
        "dex/compact_offset_table.cc",
        "dex/descriptors_names.cc",
        "dex/dex_file.cc",
        "dex/dex_file_exception_helpers.cc",
        "dex/dex_file_layout.cc",
        "dex/dex_file_loader.cc",
        "dex/dex_file_tracking_registrar.cc",
        "dex/dex_file_verifier.cc",
        "dex/dex_instruction.cc",
        "dex/modifiers.cc",
        "dex/primitive.cc",
        "dex/signature.cc",
        "dex/standard_dex_file.cc",
        "dex/type_lookup_table.cc",
        "dex/utf.cc",
    ],
    header_libs: [
        "jni_headers",
        "libdexfile_external_headers",
    ],
    export_header_lib_headers: [
        "jni_headers",
        "libdexfile_external_headers",
    ],
    static: {
        cflags: ["-DSTATIC_LIB"],
    },
    target: {
        android: {
            srcs: [
                "external/dex_file_ext.cc",
            ],
            static_libs: [
                "libziparchive",
            ],
            shared_libs: [
                // libz provides a stub from platform, shouldn't be statically linked
                "libz",
                // For MemMap.
                "libartpalette",
                "liblog",
                // For common macros.
                "libbase",
            ],
            export_shared_lib_headers: [
                "libbase",
            ],
        },
        not_windows: {
            srcs: [
                "external/dex_file_ext.cc",
            ],
            shared_libs: [
                "libziparchive",
                "libz",
                // For MemMap.
                "libartpalette",
                "liblog",
                // For common macros.
                "libbase",
            ],
            export_shared_lib_headers: [
                "libbase",
            ],
        },
        windows: {
            static_libs: [
                "libziparchive",
                "libz",
                // For MemMap.
                "libartpalette",
                "liblog",
                // For common macros.
                "libbase",
            ],
            export_static_lib_headers: [
                "libbase",
            ],
            cflags: ["-Wno-thread-safety"],
        },
        darwin: {
            enabled: true,
        },
    },
    generated_sources: ["dexfile_operator_srcs"],
    export_include_dirs: ["."],
}

cc_defaults {
    name: "libdexfile_static_base_defaults",
    whole_static_libs: [
        "libbase",
        "liblog",
        "libz",
        "libziparchive",
    ],
}

cc_defaults {
    name: "libdexfile_static_defaults",
    defaults: [
        "libartbase_static_defaults",
        "libdexfile_static_base_defaults",
    ],
    defaults_visibility: [
        "//art:__subpackages__",
    ],
    whole_static_libs: ["libdexfile"],
}

cc_defaults {
    name: "libdexfiled_static_defaults",
    defaults: [
        "libartbased_static_defaults",
        "libdexfile_static_base_defaults",
    ],
    whole_static_libs: ["libdexfiled"],
}

gensrcs {
    name: "dexfile_operator_srcs",
    cmd: "$(location generate_operator_out) art/libdexfile $(in) > $(out)",
    tools: ["generate_operator_out"],
    srcs: [
        "dex/dex_file.h",
        "dex/dex_file_layout.h",
        "dex/dex_instruction.h",
        "dex/dex_instruction_utils.h",
        "dex/invoke_type.h",
    ],
    output_extension: "operator_out.cc",
}

art_cc_library {
    name: "libdexfile",
    visibility: [
        // Allow libdexfile_support users to list this as a runtime_libs
        // dependency - see comment for libdexfile_support. It shouldn't be used
        // for any other purpose.
        "//external/perfetto",
        "//frameworks/base/services/core/jni",
        "//system/core/debuggerd",
        "//system/extras/simpleperf",
        "//system/unwinding/libunwindstack",
    ],
    defaults: [
        "libdexfile_defaults",
        "libart_nativeunwind_defaults",
    ],
    target: {
        android: {
            shared_libs: [
                "libartbase",
            ],
            export_shared_lib_headers: [
                "libartbase",
            ],
        },
        not_windows: {
            shared_libs: [
                "libartbase",
            ],
            export_shared_lib_headers: [
                "libartbase",
            ],
        },
        windows: {
            enabled: true,
            shared: {
                enabled: false,
            },
            static_libs: [
                "libartbase",
            ],
            export_static_lib_headers: [
                "libartbase",
            ],
        },
    },
    apex_available: [
        "com.android.art",
        "com.android.art.debug",
        "test_broken_com.android.art",
    ],

    // This library is exported in stub form by art-module-sdk, and it brings
    // with it all the exported headers from libartbase and libbase, many of
    // which are transitive dependencies outside ART. Those may conflict with
    // other versions of the headers that the caller is using in their build,
    // but in this case it's fine since external users only depend on this
    // through runtime_libs (see comment for libdexfile_support), which doesn't
    // propagate include dirs.
    stubs: {
        symbol_file: "libdexfile.map.txt",
        versions: ["1"],
    },
}

art_cc_library {
    name: "libdexfiled",
    defaults: [
        "art_debug_defaults",
        "libdexfile_defaults",
    ],
    target: {
        android: {
            shared_libs: [
                "libartbased",
            ],
            export_shared_lib_headers: [
                "libartbased",
            ],
        },
        not_windows: {
            shared_libs: [
                "libartbased",
            ],
            export_shared_lib_headers: [
                "libartbased",
            ],
        },
        windows: {
            enabled: true,
            shared: {
                enabled: false,
            },
            static_libs: [
                "libartbased",
            ],
            export_static_lib_headers: [
                "libartbased",
            ],
        },
    },
    apex_available: [
        "com.android.art.debug",
        // TODO(b/183882457): This lib doesn't go into com.android.art, but
        // apex_available lists need to be the same for internal libs to avoid
        // stubs, and libartd depends on this.
        "com.android.art",
    ],
}

art_cc_defaults {
    name: "art_libdexfile_tests_defaults",
    tidy_timeout_srcs: [
        "dex/dex_file_verifier_test.cc",
    ],
    srcs: [
        "dex/art_dex_file_loader_test.cc",
        "dex/class_accessor_test.cc",
        "dex/code_item_accessors_test.cc",
        "dex/compact_dex_file_test.cc",
        "dex/compact_offset_table_test.cc",
        "dex/descriptors_names_test.cc",
        "dex/dex_file_loader_test.cc",
        "dex/dex_file_verifier_test.cc",
        "dex/dex_instruction_test.cc",
        "dex/fuzzer_corpus_test.cc",
        "dex/primitive_test.cc",
        "dex/proto_reference_test.cc",
        "dex/string_reference_test.cc",
        "dex/test_dex_file_builder_test.cc",
        "dex/type_lookup_table_test.cc",
        "dex/utf_test.cc",
    ],
    data: [
        ":art-gtest-jars-GetMethodSignature",
        ":art-gtest-jars-Lookup",
        ":art-gtest-jars-DexFuzzerFolder",
        ":art-gtest-jars-Main",
        ":art-gtest-jars-MainEmptyUncompressed",
        ":art-gtest-jars-MultiDex",
        ":art-gtest-jars-Nested",
        ":art-gtest-jars-VerifierDeps",
    ],
    header_libs: ["jni_headers"],
    shared_libs: [
        "libunwindstack",
    ],
}

// Version of ART gtest `art_libdexfile_tests` bundled with the ART APEX on target.
// TODO(b/192274705): Remove this module when the migration to standalone ART gtests is complete.
art_cc_test {
    name: "art_libdexfile_tests",
    defaults: [
        "art_gtest_defaults",
        "art_libdexfile_tests_defaults",
    ],
}

// Standalone version of ART gtest `art_libdexfile_tests`, not bundled with the ART APEX on target.
art_cc_test {
    name: "art_standalone_libdexfile_tests",
    defaults: [
        "art_standalone_gtest_defaults",
        "art_libdexfile_tests_defaults",
    ],
    test_config: "art_standalone_libdexfile_tests.xml",
}

cc_library_headers {
    name: "libdexfile_external_headers",
    defaults: ["art_defaults"],
    visibility: ["//visibility:public"],
    host_supported: true,
    export_include_dirs: ["external/include"],

    target: {
        windows: {
            enabled: true,
        },
        darwin: {
            enabled: true,
        },
    },

    apex_available: [
        "//apex_available:platform",
        "com.android.art",
        "com.android.art.debug",
        "com.android.media",
        "com.android.runtime",
    ],
}

// Make dex_instruction_list.h available for tools/jvmti-agents/titrace
cc_library_headers {
    name: "libdexfile_all_headers",
    defaults: ["art_defaults"],
    visibility: ["//art:__subpackages__"],
    host_supported: true,
    export_include_dirs: ["."],

    apex_available: [
        "com.android.art",
        "com.android.art.debug",
    ],
}

art_cc_defaults {
    name: "art_libdexfile_external_tests_defaults",
    defaults: [
        "art_module_source_build_defaults",
    ],
    test_suites: ["general-tests"],
    srcs: [
        "external/dex_file_ext_c_test.c",
        "external/dex_file_ext_test.cc",
    ],
    shared_libs: [
        "libartbase",
        "libdexfile",
    ],
    header_libs: [
        "jni_headers",
        "libdexfile_external_headers",
    ],
}

// Version of ART gtest `art_libdexfile_external_tests` bundled with the ART APEX on target.
// TODO(b/192274705): Remove this module when the migration to standalone ART gtests is complete.
art_cc_test {
    name: "art_libdexfile_external_tests",
    defaults: [
        "art_test_defaults",
        "art_libdexfile_external_tests_defaults",
    ],
}

// Standalone version of ART gtest `art_libdexfile_external_tests`, not bundled with the ART APEX on
// target.
art_cc_test {
    name: "art_standalone_libdexfile_external_tests",
    defaults: [
        "art_standalone_test_defaults",
        "art_libdexfile_external_tests_defaults",
    ],

    test_config_template: ":art-gtests-target-standalone-cts-template",
    test_suites: ["cts"], // For backed-by API coverage.
}

// Support library with a C++ API for accessing the libdexfile API for external
// (non-ART) users.
//
// This library dlopens libdexfile(d).so on first use, so there is no build time
// dependency on dex file logic. It is therefore safe to use from binaries
// compiled without dex file support, given they won't encounter any dex file
// stack frames.
//
// IMPORTANT: When adding a static_libs dependency on this library, please
// remember to also add a corresponding
//
//     runtime_libs: ["libdexfile"],
//
// That is necessary since Soong doesn't propagate dependencies transitively for
// static libraries (b/169779783).
art_cc_library_static {
    name: "libdexfile_support",
    defaults: ["art_defaults"],
    visibility: ["//visibility:public"],
    host_supported: true,
    srcs: [
        "external/dex_file_supp.cc",
    ],
    runtime_libs: ["libdexfile"],
    // Only NDK libs may be dynamic, because this becomes a prebuilt that must work on S+.
    shared_libs: ["liblog"],
    header_libs: ["libdexfile_external_headers"],
    // Do not export any headers outside the ART module - they get included in
    // the prebuilt SDK and may conflict with different versions of themselves
    // in the build that the SDK user is using.
    export_header_lib_headers: ["libdexfile_external_headers"],

    apex_available: [
        "//apex_available:platform",
        "com.android.art",
        "com.android.art.debug",
        "com.android.runtime",
    ],
}

art_cc_defaults {
    name: "art_libdexfile_support_tests_defaults",
    defaults: [
        "art_module_source_build_defaults",
    ],
    test_suites: ["general-tests"],
    srcs: [
        "external/dex_file_supp_test.cc",
    ],
    shared_libs: [
        "libartbase",
        "libbase",
        "libdexfile",
        "liblog",
    ],
    static_libs: [
        "libdexfile_support",
    ],
}

// Version of ART gtest `art_libdexfile_support_tests` bundled with the ART APEX on target.
// TODO(b/192274705): Remove this module when the migration to standalone ART gtests is complete.
art_cc_test {
    name: "art_libdexfile_support_tests",
    host_supported: true,
    defaults: [
        "art_test_defaults",
        "art_libdexfile_support_tests_defaults",
    ],
}

// Standalone version of ART gtest `art_libdexfile_support_tests`, not bundled with the ART APEX on
// target.
art_cc_test {
    name: "art_standalone_libdexfile_support_tests",
    defaults: [
        "art_standalone_test_defaults",
        "art_libdexfile_support_tests_defaults",
    ],
    test_suites: [
        "mts-art",
    ],
}

cc_library_static {
    name: "libdexfile_support_static",
    defaults: ["art_defaults"],
    host_supported: true,
    srcs: [
        "external/dex_file_supp.cc",
    ],
    cflags: ["-DSTATIC_LIB"],
    header_libs: ["libdexfile_external_headers"],
    export_header_lib_headers: ["libdexfile_external_headers"],
}

cc_defaults {
    name: "libdexfile_support_static_defaults",
    defaults: [
        "libdexfile_static_defaults",
    ],
    whole_static_libs: [
        "libdexfile",
        "libdexfile_support_static",
    ],
}

cc_defaults {
    name: "libdexfiled_support_static_defaults",
    defaults: [
        "libdexfiled_static_defaults",
    ],
    whole_static_libs: [
        "libdexfiled",
        "libdexfile_support_static",
    ],
}

art_cc_test {
    name: "art_libdexfile_support_static_tests",
    test_suites: ["general-tests"],
    defaults: [
        "art_module_source_build_defaults",
        "art_test_defaults",
        "libdexfile_support_static_defaults",
    ],
    srcs: [
        "external/dex_file_supp_test.cc",
    ],
}

// For use by external packages allowed to link in static libdexfile_support.
// This is not allowed in any module that may end up in an APEX or platform
// image, so visibility is restrictive.
//
// TODO(b/169885605): This library brings with it all the exported headers from
// libdexfile_support_static_defaults into the prebuilt SDK created by
// art-module-sdk, many of which are transitive dependencies outside ART. Those
// may conflict with other versions that the caller is using in their build. One
// way to deal with that is to provide minimal headers without any transitive
// dependencies on other headers.
cc_library_static {
    name: "libdexfile_static",
    host_supported: true,
    visibility: [
        // Required for simpleperf, libsimpleperf_record, and libsimpleperf_report
        // in the NDK.
        "//system/extras/simpleperf",
        "//cts/tests/tests/simpleperf",
    ],
    // Using libdexfile_support_static_defaults will link in external libs like
    // libbase and libz statically as well, which are likely to cause duplicate
    // copies in the depending module.
    // TODO(b/169885605): Avoid exposing symbols from those libs.
    defaults: [
        "art_defaults",
        "libdexfile_support_static_defaults",
    ],
}

art_cc_test {
    name: "art_libdexfile_static_tests",
    defaults: ["art_test_defaults"],
    test_suites: ["general-tests"],
    srcs: [
        "external/dex_file_supp_test.cc",
    ],
    static_libs: [
        "libdexfile_static",
    ],
    enabled: false,
    target: {
        android: {
            // Build static test binary on device, to make sure libdexfile_static can be used in
            // static simpleperf binary in ndk.
            static_executable: true,
            static_libs: [
                "libc",
            ],
        },
        linux: {
            enabled: true,
        },
    },
    // TODO(b/181740144): Enable a ubsan check to create a dependency on
    // ubsan_minimal. It's needed to be able to link with the prebuilt
    // libdexfile_static.a, which contains libziparchive.a, which is
    // built with some ubsan checks
    // (https://cs.android.com/android/platform/superproject/+/master:system/libziparchive/Android.bp;l=47-59;drc=c7b498fdf2002194709e40ea58ce39f43684fc14)
    // that the SDK snapshots currently don't propagate properly for static
    // libs.
    sanitize: {
        misc_undefined: ["shift"],
    },
}

filegroup {
    name: "art_libdexfile_dex_instruction_list_header",
    srcs: ["dex/dex_instruction_list.h"],
}