123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587 |
- // Copyright 2021 Google Inc. All rights reserved.
- //
- // 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 bp2build
- import (
- "testing"
- "android/soong/android"
- "android/soong/cc"
- )
- const (
- // See cc/testing.go for more context
- // TODO(alexmarquez): Split out the preamble into common code?
- soongCcLibrarySharedPreamble = soongCcLibraryStaticPreamble
- )
- func registerCcLibrarySharedModuleTypes(ctx android.RegistrationContext) {
- cc.RegisterCCBuildComponents(ctx)
- ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
- ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
- ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
- }
- func runCcLibrarySharedTestCase(t *testing.T, tc Bp2buildTestCase) {
- t.Helper()
- t.Parallel()
- (&tc).ModuleTypeUnderTest = "cc_library_shared"
- (&tc).ModuleTypeUnderTestFactory = cc.LibrarySharedFactory
- RunBp2BuildTestCase(t, registerCcLibrarySharedModuleTypes, tc)
- }
- func TestCcLibrarySharedSimple(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared simple overall test",
- Filesystem: map[string]string{
- // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?)
- "include_dir_1/include_dir_1_a.h": "",
- "include_dir_1/include_dir_1_b.h": "",
- "include_dir_2/include_dir_2_a.h": "",
- "include_dir_2/include_dir_2_b.h": "",
- // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?)
- "local_include_dir_1/local_include_dir_1_a.h": "",
- "local_include_dir_1/local_include_dir_1_b.h": "",
- "local_include_dir_2/local_include_dir_2_a.h": "",
- "local_include_dir_2/local_include_dir_2_b.h": "",
- // NOTE: export_include_dir headers *should* appear in Bazel hdrs later
- "export_include_dir_1/export_include_dir_1_a.h": "",
- "export_include_dir_1/export_include_dir_1_b.h": "",
- "export_include_dir_2/export_include_dir_2_a.h": "",
- "export_include_dir_2/export_include_dir_2_b.h": "",
- // NOTE: Soong implicitly includes headers in the current directory
- "implicit_include_1.h": "",
- "implicit_include_2.h": "",
- },
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_library_headers {
- name: "header_lib_1",
- export_include_dirs: ["header_lib_1"],
- bazel_module: { bp2build_available: false },
- }
- cc_library_headers {
- name: "header_lib_2",
- export_include_dirs: ["header_lib_2"],
- bazel_module: { bp2build_available: false },
- }
- cc_library_shared {
- name: "shared_lib_1",
- srcs: ["shared_lib_1.cc"],
- bazel_module: { bp2build_available: false },
- }
- cc_library_shared {
- name: "shared_lib_2",
- srcs: ["shared_lib_2.cc"],
- bazel_module: { bp2build_available: false },
- }
- cc_library_static {
- name: "whole_static_lib_1",
- srcs: ["whole_static_lib_1.cc"],
- bazel_module: { bp2build_available: false },
- }
- cc_library_static {
- name: "whole_static_lib_2",
- srcs: ["whole_static_lib_2.cc"],
- bazel_module: { bp2build_available: false },
- }
- cc_library_shared {
- name: "foo_shared",
- srcs: [
- "foo_shared1.cc",
- "foo_shared2.cc",
- ],
- cflags: [
- "-Dflag1",
- "-Dflag2"
- ],
- shared_libs: [
- "shared_lib_1",
- "shared_lib_2"
- ],
- whole_static_libs: [
- "whole_static_lib_1",
- "whole_static_lib_2"
- ],
- include_dirs: [
- "include_dir_1",
- "include_dir_2",
- ],
- local_include_dirs: [
- "local_include_dir_1",
- "local_include_dir_2",
- ],
- export_include_dirs: [
- "export_include_dir_1",
- "export_include_dir_2"
- ],
- header_libs: [
- "header_lib_1",
- "header_lib_2"
- ],
- sdk_version: "current",
- min_sdk_version: "29",
- // TODO: Also support export_header_lib_headers
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
- "absolute_includes": `[
- "include_dir_1",
- "include_dir_2",
- ]`,
- "copts": `[
- "-Dflag1",
- "-Dflag2",
- ]`,
- "export_includes": `[
- "export_include_dir_1",
- "export_include_dir_2",
- ]`,
- "implementation_deps": `[
- ":header_lib_1",
- ":header_lib_2",
- ]`,
- "implementation_dynamic_deps": `[
- ":shared_lib_1",
- ":shared_lib_2",
- ]`,
- "local_includes": `[
- "local_include_dir_1",
- "local_include_dir_2",
- ".",
- ]`,
- "srcs": `[
- "foo_shared1.cc",
- "foo_shared2.cc",
- ]`,
- "whole_archive_deps": `[
- ":whole_static_lib_1",
- ":whole_static_lib_2",
- ]`,
- "sdk_version": `"current"`,
- "min_sdk_version": `"29"`,
- }),
- },
- })
- }
- func TestCcLibrarySharedArchSpecificSharedLib(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared arch-specific shared_libs with whole_static_libs",
- Filesystem: map[string]string{},
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_library_static {
- name: "static_dep",
- bazel_module: { bp2build_available: false },
- }
- cc_library_shared {
- name: "shared_dep",
- bazel_module: { bp2build_available: false },
- }
- cc_library_shared {
- name: "foo_shared",
- arch: { arm64: { shared_libs: ["shared_dep"], whole_static_libs: ["static_dep"] } },
- include_build_directory: false,
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
- "implementation_dynamic_deps": `select({
- "//build/bazel/platforms/arch:arm64": [":shared_dep"],
- "//conditions:default": [],
- })`,
- "whole_archive_deps": `select({
- "//build/bazel/platforms/arch:arm64": [":static_dep"],
- "//conditions:default": [],
- })`,
- }),
- },
- })
- }
- func TestCcLibrarySharedOsSpecificSharedLib(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared os-specific shared_libs",
- Filesystem: map[string]string{},
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_library_shared {
- name: "shared_dep",
- bazel_module: { bp2build_available: false },
- }
- cc_library_shared {
- name: "foo_shared",
- target: { android: { shared_libs: ["shared_dep"], } },
- include_build_directory: false,
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
- "implementation_dynamic_deps": `select({
- "//build/bazel/platforms/os:android": [":shared_dep"],
- "//conditions:default": [],
- })`,
- }),
- },
- })
- }
- func TestCcLibrarySharedBaseArchOsSpecificSharedLib(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared base, arch, and os-specific shared_libs",
- Filesystem: map[string]string{},
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_library_shared {
- name: "shared_dep",
- bazel_module: { bp2build_available: false },
- }
- cc_library_shared {
- name: "shared_dep2",
- bazel_module: { bp2build_available: false },
- }
- cc_library_shared {
- name: "shared_dep3",
- bazel_module: { bp2build_available: false },
- }
- cc_library_shared {
- name: "foo_shared",
- shared_libs: ["shared_dep"],
- target: { android: { shared_libs: ["shared_dep2"] } },
- arch: { arm64: { shared_libs: ["shared_dep3"] } },
- include_build_directory: false,
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
- "implementation_dynamic_deps": `[":shared_dep"] + select({
- "//build/bazel/platforms/arch:arm64": [":shared_dep3"],
- "//conditions:default": [],
- }) + select({
- "//build/bazel/platforms/os:android": [":shared_dep2"],
- "//conditions:default": [],
- })`,
- }),
- },
- })
- }
- func TestCcLibrarySharedSimpleExcludeSrcs(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared simple exclude_srcs",
- Filesystem: map[string]string{
- "common.c": "",
- "foo-a.c": "",
- "foo-excluded.c": "",
- },
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_library_shared {
- name: "foo_shared",
- srcs: ["common.c", "foo-*.c"],
- exclude_srcs: ["foo-excluded.c"],
- include_build_directory: false,
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
- "srcs_c": `[
- "common.c",
- "foo-a.c",
- ]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedStrip(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared stripping",
- Filesystem: map[string]string{},
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_library_shared {
- name: "foo_shared",
- strip: {
- keep_symbols: false,
- keep_symbols_and_debug_frame: true,
- keep_symbols_list: ["sym", "sym2"],
- all: true,
- none: false,
- },
- include_build_directory: false,
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
- "strip": `{
- "all": True,
- "keep_symbols": False,
- "keep_symbols_and_debug_frame": True,
- "keep_symbols_list": [
- "sym",
- "sym2",
- ],
- "none": False,
- }`,
- }),
- },
- })
- }
- func TestCcLibrarySharedVersionScriptAndDynamicList(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared version script and dynamic list",
- Filesystem: map[string]string{
- "version_script": "",
- "dynamic.list": "",
- },
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_library_shared {
- name: "foo_shared",
- version_script: "version_script",
- dynamic_list: "dynamic.list",
- include_build_directory: false,
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
- "additional_linker_inputs": `[
- "version_script",
- "dynamic.list",
- ]`,
- "linkopts": `[
- "-Wl,--version-script,$(location version_script)",
- "-Wl,--dynamic-list,$(location dynamic.list)",
- ]`,
- "features": `["android_cfi_exports_map"]`,
- }),
- },
- })
- }
- func TestCcLibraryLdflagsSplitBySpaceSoongAdded(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "ldflags are split by spaces except for the ones added by soong (version script and dynamic list)",
- Filesystem: map[string]string{
- "version_script": "",
- "dynamic.list": "",
- },
- Blueprint: `
- cc_library_shared {
- name: "foo",
- ldflags: [
- "--nospace_flag",
- "-z spaceflag",
- ],
- version_script: "version_script",
- dynamic_list: "dynamic.list",
- include_build_directory: false,
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "additional_linker_inputs": `[
- "version_script",
- "dynamic.list",
- ]`,
- "linkopts": `[
- "--nospace_flag",
- "-z",
- "spaceflag",
- "-Wl,--version-script,$(location version_script)",
- "-Wl,--dynamic-list,$(location dynamic.list)",
- ]`,
- "features": `["android_cfi_exports_map"]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedNoCrtTrue(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared - nocrt: true disables feature",
- Filesystem: map[string]string{
- "impl.cpp": "",
- },
- Blueprint: soongCcLibraryPreamble + `
- cc_library_shared {
- name: "foo_shared",
- srcs: ["impl.cpp"],
- nocrt: true,
- include_build_directory: false,
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
- "features": `["-link_crt"]`,
- "srcs": `["impl.cpp"]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedNoCrtFalse(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared - nocrt: false doesn't disable feature",
- Filesystem: map[string]string{
- "impl.cpp": "",
- },
- Blueprint: soongCcLibraryPreamble + `
- cc_library_shared {
- name: "foo_shared",
- srcs: ["impl.cpp"],
- nocrt: false,
- include_build_directory: false,
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
- "srcs": `["impl.cpp"]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedNoCrtArchVariant(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared - nocrt in select",
- Filesystem: map[string]string{
- "impl.cpp": "",
- },
- Blueprint: soongCcLibraryPreamble + `
- cc_library_shared {
- name: "foo_shared",
- srcs: ["impl.cpp"],
- arch: {
- arm: {
- nocrt: true,
- },
- x86: {
- nocrt: false,
- },
- },
- include_build_directory: false,
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
- "features": `select({
- "//build/bazel/platforms/arch:arm": ["-link_crt"],
- "//conditions:default": [],
- })`,
- "srcs": `["impl.cpp"]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedProto(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Blueprint: soongCcProtoPreamble + `cc_library_shared {
- name: "foo",
- srcs: ["foo.proto"],
- proto: {
- export_proto_headers: true,
- },
- include_build_directory: false,
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
- "srcs": `["foo.proto"]`,
- }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
- "deps": `[":foo_proto"]`,
- }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "dynamic_deps": `[":libprotobuf-cpp-lite"]`,
- "whole_archive_deps": `[":foo_cc_proto_lite"]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedUseVersionLib(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Filesystem: map[string]string{
- soongCcVersionLibBpPath: soongCcVersionLibBp,
- },
- Blueprint: soongCcProtoPreamble + `cc_library_shared {
- name: "foo",
- use_version_lib: true,
- include_build_directory: false,
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "use_version_lib": "True",
- "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedStubs(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared stubs",
- ModuleTypeUnderTest: "cc_library_shared",
- ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
- Dir: "foo/bar",
- Filesystem: map[string]string{
- "foo/bar/Android.bp": `
- cc_library_shared {
- name: "a",
- stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
- bazel_module: { bp2build_available: true },
- include_build_directory: false,
- }
- `,
- },
- Blueprint: soongCcLibraryPreamble,
- ExpectedBazelTargets: []string{makeCcStubSuiteTargets("a", AttrNameToString{
- "soname": `"a.so"`,
- "source_library_label": `"//foo/bar:a"`,
- "stubs_symbol_file": `"a.map.txt"`,
- "stubs_versions": `[
- "28",
- "29",
- "current",
- ]`,
- }),
- MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
- "stubs_symbol_file": `"a.map.txt"`,
- }),
- },
- })
- }
- func TestCcLibrarySharedStubs_UseImplementationInSameApex(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared stubs",
- ModuleTypeUnderTest: "cc_library_shared",
- ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_library_shared {
- name: "a",
- stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
- bazel_module: { bp2build_available: false },
- include_build_directory: false,
- apex_available: ["made_up_apex"],
- }
- cc_library_shared {
- name: "b",
- shared_libs: [":a"],
- include_build_directory: false,
- apex_available: ["made_up_apex"],
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
- "implementation_dynamic_deps": `[":a"]`,
- "tags": `["apex_available=made_up_apex"]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedStubs_UseStubsInDifferentApex(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared stubs",
- ModuleTypeUnderTest: "cc_library_shared",
- ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_library_shared {
- name: "a",
- stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
- bazel_module: { bp2build_available: false },
- include_build_directory: false,
- apex_available: ["apex_a"],
- }
- cc_library_shared {
- name: "b",
- shared_libs: [":a"],
- include_build_directory: false,
- apex_available: ["apex_b"],
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
- "implementation_dynamic_deps": `select({
- "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
- "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
- "//conditions:default": [":a"],
- })`,
- "tags": `["apex_available=apex_b"]`,
- }),
- },
- })
- }
- // Tests that library in apexfoo links against stubs of platform_lib and otherapex_lib
- func TestCcLibrarySharedStubs_UseStubsFromMultipleApiDomains(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared stubs",
- ModuleTypeUnderTest: "cc_library_shared",
- ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_library_shared {
- name: "libplatform_stable",
- stubs: { symbol_file: "libplatform_stable.map.txt", versions: ["28", "29", "current"] },
- apex_available: ["//apex_available:platform"],
- bazel_module: { bp2build_available: false },
- include_build_directory: false,
- }
- cc_library_shared {
- name: "libapexfoo_stable",
- stubs: { symbol_file: "libapexfoo_stable.map.txt", versions: ["28", "29", "current"] },
- apex_available: ["apexfoo"],
- bazel_module: { bp2build_available: false },
- include_build_directory: false,
- }
- cc_library_shared {
- name: "libutils",
- shared_libs: ["libplatform_stable", "libapexfoo_stable",],
- apex_available: ["//apex_available:platform", "apexfoo", "apexbar"],
- include_build_directory: false,
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "libutils", AttrNameToString{
- "implementation_dynamic_deps": `select({
- "//build/bazel/rules/apex:apexbar": [
- "@api_surfaces//module-libapi/current:libplatform_stable",
- "@api_surfaces//module-libapi/current:libapexfoo_stable",
- ],
- "//build/bazel/rules/apex:apexfoo": [
- "@api_surfaces//module-libapi/current:libplatform_stable",
- ":libapexfoo_stable",
- ],
- "//build/bazel/rules/apex:system": [
- "@api_surfaces//module-libapi/current:libplatform_stable",
- "@api_surfaces//module-libapi/current:libapexfoo_stable",
- ],
- "//conditions:default": [
- ":libplatform_stable",
- ":libapexfoo_stable",
- ],
- })`,
- "tags": `[
- "apex_available=//apex_available:platform",
- "apex_available=apexfoo",
- "apex_available=apexbar",
- ]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedStubs_IgnorePlatformAvailable(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared stubs",
- ModuleTypeUnderTest: "cc_library_shared",
- ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_library_shared {
- name: "a",
- stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
- bazel_module: { bp2build_available: false },
- include_build_directory: false,
- apex_available: ["//apex_available:platform", "apex_a"],
- }
- cc_library_shared {
- name: "b",
- shared_libs: [":a"],
- include_build_directory: false,
- apex_available: ["//apex_available:platform", "apex_b"],
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
- "implementation_dynamic_deps": `select({
- "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"],
- "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
- "//conditions:default": [":a"],
- })`,
- "tags": `[
- "apex_available=//apex_available:platform",
- "apex_available=apex_b",
- ]`,
- }),
- },
- })
- }
- func TestCcLibraryDoesNotDropStubDepIfNoVariationAcrossAxis(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library depeends on impl for all configurations",
- ModuleTypeUnderTest: "cc_library_shared",
- ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_library_shared {
- name: "a",
- stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
- bazel_module: { bp2build_available: false },
- apex_available: ["//apex_available:platform"],
- }
- cc_library_shared {
- name: "b",
- shared_libs: [":a"],
- include_build_directory: false,
- apex_available: ["//apex_available:platform"],
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
- "implementation_dynamic_deps": `[":a"]`,
- "tags": `["apex_available=//apex_available:platform"]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedStubs_MultipleApexAvailable(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- ModuleTypeUnderTest: "cc_library_shared",
- ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_library_shared {
- name: "a",
- stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] },
- bazel_module: { bp2build_available: false },
- include_build_directory: false,
- apex_available: ["//apex_available:platform", "apex_a", "apex_b"],
- }
- cc_library_shared {
- name: "b",
- shared_libs: [":a"],
- include_build_directory: false,
- apex_available: ["//apex_available:platform", "apex_b"],
- }
- cc_library_shared {
- name: "c",
- shared_libs: [":a"],
- include_build_directory: false,
- apex_available: ["//apex_available:platform", "apex_a", "apex_b"],
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
- "implementation_dynamic_deps": `select({
- "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"],
- "//conditions:default": [":a"],
- })`,
- "tags": `[
- "apex_available=//apex_available:platform",
- "apex_available=apex_b",
- ]`,
- }),
- MakeBazelTarget("cc_library_shared", "c", AttrNameToString{
- "implementation_dynamic_deps": `[":a"]`,
- "tags": `[
- "apex_available=//apex_available:platform",
- "apex_available=apex_a",
- "apex_available=apex_b",
- ]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedSystemSharedLibsSharedEmpty(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared system_shared_libs empty shared default",
- ModuleTypeUnderTest: "cc_library_shared",
- ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_defaults {
- name: "empty_defaults",
- shared: {
- system_shared_libs: [],
- },
- include_build_directory: false,
- }
- cc_library_shared {
- name: "empty",
- defaults: ["empty_defaults"],
- }
- `,
- ExpectedBazelTargets: []string{MakeBazelTarget("cc_library_shared", "empty", AttrNameToString{
- "system_dynamic_deps": "[]",
- })},
- })
- }
- func TestCcLibrarySharedConvertLex(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared with lex files",
- ModuleTypeUnderTest: "cc_library_shared",
- ModuleTypeUnderTestFactory: cc.LibrarySharedFactory,
- Filesystem: map[string]string{
- "foo.c": "",
- "bar.cc": "",
- "foo1.l": "",
- "bar1.ll": "",
- "foo2.l": "",
- "bar2.ll": "",
- },
- Blueprint: `cc_library_shared {
- name: "foo_lib",
- srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
- lex: { flags: ["--foo_flags"] },
- include_build_directory: false,
- bazel_module: { bp2build_available: true },
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{
- "srcs": `[
- "foo1.l",
- "foo2.l",
- ]`,
- "lexopts": `["--foo_flags"]`,
- }),
- MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{
- "srcs": `[
- "bar1.ll",
- "bar2.ll",
- ]`,
- "lexopts": `["--foo_flags"]`,
- }),
- MakeBazelTarget("cc_library_shared", "foo_lib", AttrNameToString{
- "srcs": `[
- "bar.cc",
- ":foo_lib_genlex_ll",
- ]`,
- "srcs_c": `[
- "foo.c",
- ":foo_lib_genlex_l",
- ]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedClangUnknownFlags(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Blueprint: soongCcProtoPreamble + `cc_library_shared {
- name: "foo",
- conlyflags: ["-a", "-finline-functions"],
- cflags: ["-b","-finline-functions"],
- cppflags: ["-c", "-finline-functions"],
- ldflags: ["-d","-finline-functions", "-e"],
- include_build_directory: false,
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "conlyflags": `["-a"]`,
- "copts": `["-b"]`,
- "cppflags": `["-c"]`,
- "linkopts": `[
- "-d",
- "-e",
- ]`,
- }),
- },
- })
- }
- func TestCCLibraryFlagSpaceSplitting(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Blueprint: soongCcProtoPreamble + `cc_library_shared {
- name: "foo",
- conlyflags: [ "-include header.h"],
- cflags: ["-include header.h"],
- cppflags: ["-include header.h"],
- version_script: "version_script",
- include_build_directory: false,
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "additional_linker_inputs": `["version_script"]`,
- "conlyflags": `[
- "-include",
- "header.h",
- ]`,
- "copts": `[
- "-include",
- "header.h",
- ]`,
- "cppflags": `[
- "-include",
- "header.h",
- ]`,
- "linkopts": `["-Wl,--version-script,$(location version_script)"]`,
- "features": `["android_cfi_exports_map"]`,
- }),
- },
- })
- }
- func TestCCLibrarySharedRuntimeDeps(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Blueprint: `cc_library_shared {
- name: "bar",
- }
- cc_library_shared {
- name: "foo",
- runtime_libs: ["foo"],
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{
- "local_includes": `["."]`,
- }),
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "runtime_deps": `[":foo"]`,
- "local_includes": `["."]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedEmptySuffix(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared with empty suffix",
- Filesystem: map[string]string{
- "foo.c": "",
- },
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_library_shared {
- name: "foo_shared",
- suffix: "",
- srcs: ["foo.c"],
- include_build_directory: false,
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
- "srcs_c": `["foo.c"]`,
- "suffix": `""`,
- }),
- },
- })
- }
- func TestCcLibrarySharedSuffix(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared with suffix",
- Filesystem: map[string]string{
- "foo.c": "",
- },
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_library_shared {
- name: "foo_shared",
- suffix: "-suf",
- srcs: ["foo.c"],
- include_build_directory: false,
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
- "srcs_c": `["foo.c"]`,
- "suffix": `"-suf"`,
- }),
- },
- })
- }
- func TestCcLibrarySharedArchVariantSuffix(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared with arch-variant suffix",
- Filesystem: map[string]string{
- "foo.c": "",
- },
- Blueprint: soongCcLibrarySharedPreamble + `
- cc_library_shared {
- name: "foo_shared",
- arch: {
- arm64: { suffix: "-64" },
- arm: { suffix: "-32" },
- },
- srcs: ["foo.c"],
- include_build_directory: false,
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{
- "srcs_c": `["foo.c"]`,
- "suffix": `select({
- "//build/bazel/platforms/arch:arm": "-32",
- "//build/bazel/platforms/arch:arm64": "-64",
- "//conditions:default": None,
- })`,
- }),
- },
- })
- }
- func TestCcLibrarySharedWithSyspropSrcs(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared with sysprop sources",
- Blueprint: `
- cc_library_shared {
- name: "foo",
- srcs: [
- "bar.sysprop",
- "baz.sysprop",
- "blah.cpp",
- ],
- min_sdk_version: "5",
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
- "srcs": `[
- "bar.sysprop",
- "baz.sysprop",
- ]`,
- }),
- MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
- "dep": `":foo_sysprop_library"`,
- "min_sdk_version": `"5"`,
- }),
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "srcs": `["blah.cpp"]`,
- "local_includes": `["."]`,
- "min_sdk_version": `"5"`,
- "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedWithSyspropSrcsSomeConfigs(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared with sysprop sources in some configs but not others",
- Blueprint: `
- cc_library_shared {
- name: "foo",
- srcs: [
- "blah.cpp",
- ],
- target: {
- android: {
- srcs: ["bar.sysprop"],
- },
- },
- min_sdk_version: "5",
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
- "srcs": `select({
- "//build/bazel/platforms/os:android": ["bar.sysprop"],
- "//conditions:default": [],
- })`,
- }),
- MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
- "dep": `":foo_sysprop_library"`,
- "min_sdk_version": `"5"`,
- }),
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "srcs": `["blah.cpp"]`,
- "local_includes": `["."]`,
- "min_sdk_version": `"5"`,
- "whole_archive_deps": `select({
- "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"],
- "//conditions:default": [],
- })`,
- }),
- },
- })
- }
- func TestCcLibrarySharedHeaderAbiChecker(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared with header abi checker",
- Blueprint: `cc_library_shared {
- name: "foo",
- header_abi_checker: {
- enabled: true,
- symbol_file: "a.map.txt",
- exclude_symbol_versions: [
- "29",
- "30",
- ],
- exclude_symbol_tags: [
- "tag1",
- "tag2",
- ],
- check_all_apis: true,
- diff_flags: ["-allow-adding-removing-weak-symbols"],
- },
- include_build_directory: false,
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "abi_checker_enabled": `True`,
- "abi_checker_symbol_file": `"a.map.txt"`,
- "abi_checker_exclude_symbol_versions": `[
- "29",
- "30",
- ]`,
- "abi_checker_exclude_symbol_tags": `[
- "tag1",
- "tag2",
- ]`,
- "abi_checker_check_all_apis": `True`,
- "abi_checker_diff_flags": `["-allow-adding-removing-weak-symbols"]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedWithIntegerOverflowProperty(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared has correct features when integer_overflow property is provided",
- Blueprint: `
- cc_library_shared {
- name: "foo",
- sanitize: {
- integer_overflow: true,
- },
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "features": `["ubsan_integer_overflow"]`,
- "local_includes": `["."]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedWithMiscUndefinedProperty(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared has correct features when misc_undefined property is provided",
- Blueprint: `
- cc_library_shared {
- name: "foo",
- sanitize: {
- misc_undefined: ["undefined", "nullability"],
- },
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "features": `[
- "ubsan_undefined",
- "ubsan_nullability",
- ]`,
- "local_includes": `["."]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedWithUBSanPropertiesArchSpecific(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared has correct feature select when UBSan props are specified in arch specific blocks",
- Blueprint: `
- cc_library_shared {
- name: "foo",
- sanitize: {
- misc_undefined: ["undefined", "nullability"],
- },
- target: {
- android: {
- sanitize: {
- misc_undefined: ["alignment"],
- },
- },
- linux_glibc: {
- sanitize: {
- integer_overflow: true,
- },
- },
- },
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "features": `[
- "ubsan_undefined",
- "ubsan_nullability",
- ] + select({
- "//build/bazel/platforms/os:android": ["ubsan_alignment"],
- "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
- "//conditions:default": [],
- })`,
- "local_includes": `["."]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedWithSanitizerBlocklist(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared has correct features when sanitize.blocklist is provided",
- Blueprint: `
- cc_library_shared {
- name: "foo",
- sanitize: {
- blocklist: "foo_blocklist.txt",
- },
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "features": `["ubsan_blocklist_foo_blocklist_txt"]`,
- "local_includes": `["."]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedWithThinLto(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared has correct features when thin lto is enabled",
- Blueprint: `
- cc_library_shared {
- name: "foo",
- lto: {
- thin: true,
- },
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "features": `["android_thin_lto"]`,
- "local_includes": `["."]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedWithLtoNever(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared has correct features when thin lto is enabled",
- Blueprint: `
- cc_library_shared {
- name: "foo",
- lto: {
- never: true,
- },
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "features": `["-android_thin_lto"]`,
- "local_includes": `["."]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedWithThinLtoArchSpecific(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared has correct features when LTO differs across arch and os variants",
- Blueprint: `
- cc_library_shared {
- name: "foo",
- target: {
- android: {
- lto: {
- thin: true,
- },
- },
- },
- arch: {
- riscv64: {
- lto: {
- thin: false,
- },
- },
- },
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "local_includes": `["."]`,
- "features": `select({
- "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"],
- "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"],
- "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"],
- "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"],
- "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"],
- "//conditions:default": [],
- })`}),
- },
- })
- }
- func TestCcLibrarySharedWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared with thin lto disabled by default but enabled on a particular variant",
- Blueprint: `
- cc_library_shared {
- name: "foo",
- lto: {
- never: true,
- },
- target: {
- android: {
- lto: {
- thin: true,
- never: false,
- },
- },
- },
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "local_includes": `["."]`,
- "features": `select({
- "//build/bazel/platforms/os:android": ["android_thin_lto"],
- "//conditions:default": ["-android_thin_lto"],
- })`,
- }),
- },
- })
- }
- func TestCcLibrarySharedWithThinLtoAndWholeProgramVtables(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared has correct features when thin LTO is enabled with whole_program_vtables",
- Blueprint: `
- cc_library_shared {
- name: "foo",
- lto: {
- thin: true,
- },
- whole_program_vtables: true,
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "features": `[
- "android_thin_lto",
- "android_thin_lto_whole_program_vtables",
- ]`,
- "local_includes": `["."]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedHiddenVisibilityConvertedToFeature(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared changes hidden visibility flag to feature",
- Blueprint: `
- cc_library_shared{
- name: "foo",
- cflags: ["-fvisibility=hidden"],
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "features": `["visibility_hidden"]`,
- "local_includes": `["."]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared changes hidden visibility flag to feature for specific os",
- Blueprint: `
- cc_library_shared{
- name: "foo",
- target: {
- android: {
- cflags: ["-fvisibility=hidden"],
- },
- },
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "features": `select({
- "//build/bazel/platforms/os:android": ["visibility_hidden"],
- "//conditions:default": [],
- })`,
- "local_includes": `["."]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedStubsDessertVersionConversion(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared converts dessert codename versions to numerical versions",
- Blueprint: `
- cc_library_shared {
- name: "a",
- include_build_directory: false,
- stubs: {
- symbol_file: "a.map.txt",
- versions: [
- "Q",
- "R",
- "31",
- ],
- },
- }
- cc_library_shared {
- name: "b",
- include_build_directory: false,
- stubs: {
- symbol_file: "b.map.txt",
- versions: [
- "Q",
- "R",
- "31",
- "current",
- ],
- },
- }
- `,
- ExpectedBazelTargets: []string{
- makeCcStubSuiteTargets("a", AttrNameToString{
- "soname": `"a.so"`,
- "source_library_label": `"//:a"`,
- "stubs_symbol_file": `"a.map.txt"`,
- "stubs_versions": `[
- "29",
- "30",
- "31",
- "current",
- ]`,
- }),
- MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
- "stubs_symbol_file": `"a.map.txt"`,
- }),
- makeCcStubSuiteTargets("b", AttrNameToString{
- "soname": `"b.so"`,
- "source_library_label": `"//:b"`,
- "stubs_symbol_file": `"b.map.txt"`,
- "stubs_versions": `[
- "29",
- "30",
- "31",
- "current",
- ]`,
- }),
- MakeBazelTarget("cc_library_shared", "b", AttrNameToString{
- "stubs_symbol_file": `"b.map.txt"`,
- }),
- },
- })
- }
- func TestCcLibrarySharedWithCfi(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared has correct features when cfi is enabled for specific variants",
- Blueprint: `
- cc_library_shared {
- name: "foo",
- sanitize: {
- cfi: true,
- },
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "features": `["android_cfi"]`,
- "local_includes": `["."]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedWithCfiOsSpecific(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared has correct features when cfi is enabled",
- Blueprint: `
- cc_library_shared {
- name: "foo",
- target: {
- android: {
- sanitize: {
- cfi: true,
- },
- },
- },
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "features": `select({
- "//build/bazel/platforms/os:android": ["android_cfi"],
- "//conditions:default": [],
- })`,
- "local_includes": `["."]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedWithCfiAndCfiAssemblySupport(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared has correct features when cfi is enabled with cfi assembly support",
- Blueprint: `
- cc_library_static {
- name: "foo",
- sanitize: {
- cfi: true,
- config: {
- cfi_assembly_support: true,
- },
- },
- }`,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
- "features": `[
- "android_cfi",
- "android_cfi_assembly_support",
- ]`,
- "local_includes": `["."]`,
- }),
- },
- })
- }
- func TestCcLibrarySharedExplicitlyDisablesCfiWhenFalse(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: "cc_library_shared disables cfi when explciitly set to false in the bp",
- Blueprint: `
- cc_library_shared {
- name: "foo",
- sanitize: {
- cfi: false,
- },
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "features": `["-android_cfi"]`,
- "local_includes": `["."]`,
- }),
- },
- })
- }
- func TestCCLibrarySharedRscriptSrc(t *testing.T) {
- runCcLibrarySharedTestCase(t, Bp2buildTestCase{
- Description: ``,
- Blueprint: `
- cc_library_shared{
- name : "foo",
- srcs : [
- "ccSrc.cc",
- "rsSrc.rscript",
- ],
- include_build_directory: false,
- }
- `,
- ExpectedBazelTargets: []string{
- MakeBazelTarget("rscript_to_cpp", "foo_renderscript", AttrNameToString{
- "srcs": `["rsSrc.rscript"]`,
- }),
- MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "absolute_includes": `[
- "frameworks/rs",
- "frameworks/rs/cpp",
- ]`,
- "local_includes": `["."]`,
- "srcs": `[
- "ccSrc.cc",
- "foo_renderscript",
- ]`,
- })}})
- }
|