Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 1 | // Copyright 2021 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package bp2build |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | "android/soong/cc" |
| 22 | ) |
| 23 | |
| 24 | const ( |
| 25 | // See cc/testing.go for more context |
| 26 | // TODO(alexmarquez): Split out the preamble into common code? |
| 27 | soongCcLibrarySharedPreamble = soongCcLibraryStaticPreamble |
| 28 | ) |
| 29 | |
| 30 | func registerCcLibrarySharedModuleTypes(ctx android.RegistrationContext) { |
| 31 | cc.RegisterCCBuildComponents(ctx) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 32 | ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) |
| 33 | ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 34 | ctx.RegisterModuleType("cc_library", cc.LibraryFactory) |
Spandan Das | 1f65f9e | 2023-09-15 01:08:23 +0000 | [diff] [blame] | 35 | ctx.RegisterModuleType("ndk_library", cc.NdkLibraryFactory) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 38 | func runCcLibrarySharedTestCase(t *testing.T, tc Bp2buildTestCase) { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 39 | t.Helper() |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | c641cc4 | 2023-03-16 17:03:43 +0000 | [diff] [blame] | 40 | t.Parallel() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 41 | (&tc).ModuleTypeUnderTest = "cc_library_shared" |
| 42 | (&tc).ModuleTypeUnderTestFactory = cc.LibrarySharedFactory |
| 43 | RunBp2BuildTestCase(t, registerCcLibrarySharedModuleTypes, tc) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | func TestCcLibrarySharedSimple(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 47 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 48 | Description: "cc_library_shared simple overall test", |
| 49 | Filesystem: map[string]string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 50 | // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?) |
| 51 | "include_dir_1/include_dir_1_a.h": "", |
| 52 | "include_dir_1/include_dir_1_b.h": "", |
| 53 | "include_dir_2/include_dir_2_a.h": "", |
| 54 | "include_dir_2/include_dir_2_b.h": "", |
| 55 | // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?) |
| 56 | "local_include_dir_1/local_include_dir_1_a.h": "", |
| 57 | "local_include_dir_1/local_include_dir_1_b.h": "", |
| 58 | "local_include_dir_2/local_include_dir_2_a.h": "", |
| 59 | "local_include_dir_2/local_include_dir_2_b.h": "", |
| 60 | // NOTE: export_include_dir headers *should* appear in Bazel hdrs later |
| 61 | "export_include_dir_1/export_include_dir_1_a.h": "", |
| 62 | "export_include_dir_1/export_include_dir_1_b.h": "", |
| 63 | "export_include_dir_2/export_include_dir_2_a.h": "", |
| 64 | "export_include_dir_2/export_include_dir_2_b.h": "", |
| 65 | // NOTE: Soong implicitly includes headers in the current directory |
| 66 | "implicit_include_1.h": "", |
| 67 | "implicit_include_2.h": "", |
| 68 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 69 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 70 | cc_library_headers { |
| 71 | name: "header_lib_1", |
| 72 | export_include_dirs: ["header_lib_1"], |
| 73 | bazel_module: { bp2build_available: false }, |
| 74 | } |
| 75 | |
| 76 | cc_library_headers { |
| 77 | name: "header_lib_2", |
| 78 | export_include_dirs: ["header_lib_2"], |
| 79 | bazel_module: { bp2build_available: false }, |
| 80 | } |
| 81 | |
| 82 | cc_library_shared { |
| 83 | name: "shared_lib_1", |
| 84 | srcs: ["shared_lib_1.cc"], |
| 85 | bazel_module: { bp2build_available: false }, |
| 86 | } |
| 87 | |
| 88 | cc_library_shared { |
| 89 | name: "shared_lib_2", |
| 90 | srcs: ["shared_lib_2.cc"], |
| 91 | bazel_module: { bp2build_available: false }, |
| 92 | } |
| 93 | |
| 94 | cc_library_static { |
| 95 | name: "whole_static_lib_1", |
| 96 | srcs: ["whole_static_lib_1.cc"], |
| 97 | bazel_module: { bp2build_available: false }, |
| 98 | } |
| 99 | |
| 100 | cc_library_static { |
| 101 | name: "whole_static_lib_2", |
| 102 | srcs: ["whole_static_lib_2.cc"], |
| 103 | bazel_module: { bp2build_available: false }, |
| 104 | } |
| 105 | |
| 106 | cc_library_shared { |
| 107 | name: "foo_shared", |
| 108 | srcs: [ |
| 109 | "foo_shared1.cc", |
| 110 | "foo_shared2.cc", |
| 111 | ], |
| 112 | cflags: [ |
| 113 | "-Dflag1", |
| 114 | "-Dflag2" |
| 115 | ], |
| 116 | shared_libs: [ |
| 117 | "shared_lib_1", |
| 118 | "shared_lib_2" |
| 119 | ], |
| 120 | whole_static_libs: [ |
| 121 | "whole_static_lib_1", |
| 122 | "whole_static_lib_2" |
| 123 | ], |
| 124 | include_dirs: [ |
| 125 | "include_dir_1", |
| 126 | "include_dir_2", |
| 127 | ], |
| 128 | local_include_dirs: [ |
| 129 | "local_include_dir_1", |
| 130 | "local_include_dir_2", |
| 131 | ], |
| 132 | export_include_dirs: [ |
| 133 | "export_include_dir_1", |
| 134 | "export_include_dir_2" |
| 135 | ], |
| 136 | header_libs: [ |
| 137 | "header_lib_1", |
| 138 | "header_lib_2" |
| 139 | ], |
Yu Liu | fc60316 | 2022-03-01 15:44:08 -0800 | [diff] [blame] | 140 | sdk_version: "current", |
| 141 | min_sdk_version: "29", |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 142 | |
| 143 | // TODO: Also support export_header_lib_headers |
| 144 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 145 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 146 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 147 | "absolute_includes": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 148 | "include_dir_1", |
| 149 | "include_dir_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 150 | ]`, |
| 151 | "copts": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 152 | "-Dflag1", |
| 153 | "-Dflag2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 154 | ]`, |
| 155 | "export_includes": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 156 | "export_include_dir_1", |
| 157 | "export_include_dir_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 158 | ]`, |
| 159 | "implementation_deps": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 160 | ":header_lib_1", |
| 161 | ":header_lib_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 162 | ]`, |
| 163 | "implementation_dynamic_deps": `[ |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 164 | ":shared_lib_1", |
| 165 | ":shared_lib_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 166 | ]`, |
| 167 | "local_includes": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 168 | "local_include_dir_1", |
| 169 | "local_include_dir_2", |
| 170 | ".", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 171 | ]`, |
| 172 | "srcs": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 173 | "foo_shared1.cc", |
| 174 | "foo_shared2.cc", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 175 | ]`, |
| 176 | "whole_archive_deps": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 177 | ":whole_static_lib_1", |
| 178 | ":whole_static_lib_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 179 | ]`, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 126bd58 | 2022-04-21 15:19:27 +0000 | [diff] [blame] | 180 | "sdk_version": `"current"`, |
| 181 | "min_sdk_version": `"29"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 182 | }), |
| 183 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 184 | }) |
| 185 | } |
| 186 | |
| 187 | func TestCcLibrarySharedArchSpecificSharedLib(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 188 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 189 | Description: "cc_library_shared arch-specific shared_libs with whole_static_libs", |
| 190 | Filesystem: map[string]string{}, |
| 191 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 192 | cc_library_static { |
| 193 | name: "static_dep", |
| 194 | bazel_module: { bp2build_available: false }, |
| 195 | } |
| 196 | cc_library_shared { |
| 197 | name: "shared_dep", |
| 198 | bazel_module: { bp2build_available: false }, |
| 199 | } |
| 200 | cc_library_shared { |
| 201 | name: "foo_shared", |
| 202 | arch: { arm64: { shared_libs: ["shared_dep"], whole_static_libs: ["static_dep"] } }, |
| 203 | include_build_directory: false, |
| 204 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 205 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 206 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 207 | "implementation_dynamic_deps": `select({ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 208 | "//build/bazel/platforms/arch:arm64": [":shared_dep"], |
| 209 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 210 | })`, |
| 211 | "whole_archive_deps": `select({ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 212 | "//build/bazel/platforms/arch:arm64": [":static_dep"], |
| 213 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 214 | })`, |
| 215 | }), |
| 216 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 217 | }) |
| 218 | } |
| 219 | |
| 220 | func TestCcLibrarySharedOsSpecificSharedLib(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 221 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
Chris Parsons | 5011e61 | 2023-09-13 23:33:20 +0000 | [diff] [blame] | 222 | StubbedBuildDefinitions: []string{"shared_dep"}, |
| 223 | Description: "cc_library_shared os-specific shared_libs", |
| 224 | Filesystem: map[string]string{}, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 225 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 226 | cc_library_shared { |
| 227 | name: "shared_dep", |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 228 | } |
| 229 | cc_library_shared { |
| 230 | name: "foo_shared", |
| 231 | target: { android: { shared_libs: ["shared_dep"], } }, |
| 232 | include_build_directory: false, |
| 233 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 234 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 235 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 236 | "implementation_dynamic_deps": `select({ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 237 | "//build/bazel/platforms/os:android": [":shared_dep"], |
| 238 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 239 | })`, |
| 240 | }), |
| 241 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 242 | }) |
| 243 | } |
| 244 | |
| 245 | func TestCcLibrarySharedBaseArchOsSpecificSharedLib(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 246 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
Chris Parsons | 5011e61 | 2023-09-13 23:33:20 +0000 | [diff] [blame] | 247 | StubbedBuildDefinitions: []string{"shared_dep", "shared_dep2", "shared_dep3"}, |
| 248 | Description: "cc_library_shared base, arch, and os-specific shared_libs", |
| 249 | Filesystem: map[string]string{}, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 250 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 251 | cc_library_shared { |
| 252 | name: "shared_dep", |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 253 | } |
| 254 | cc_library_shared { |
| 255 | name: "shared_dep2", |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 256 | } |
| 257 | cc_library_shared { |
| 258 | name: "shared_dep3", |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 259 | } |
| 260 | cc_library_shared { |
| 261 | name: "foo_shared", |
| 262 | shared_libs: ["shared_dep"], |
| 263 | target: { android: { shared_libs: ["shared_dep2"] } }, |
| 264 | arch: { arm64: { shared_libs: ["shared_dep3"] } }, |
| 265 | include_build_directory: false, |
| 266 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 267 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 268 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 269 | "implementation_dynamic_deps": `[":shared_dep"] + select({ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 270 | "//build/bazel/platforms/arch:arm64": [":shared_dep3"], |
| 271 | "//conditions:default": [], |
| 272 | }) + select({ |
| 273 | "//build/bazel/platforms/os:android": [":shared_dep2"], |
| 274 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 275 | })`, |
| 276 | }), |
| 277 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 278 | }) |
| 279 | } |
| 280 | |
| 281 | func TestCcLibrarySharedSimpleExcludeSrcs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 282 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 283 | Description: "cc_library_shared simple exclude_srcs", |
| 284 | Filesystem: map[string]string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 285 | "common.c": "", |
| 286 | "foo-a.c": "", |
| 287 | "foo-excluded.c": "", |
| 288 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 289 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 290 | cc_library_shared { |
| 291 | name: "foo_shared", |
| 292 | srcs: ["common.c", "foo-*.c"], |
| 293 | exclude_srcs: ["foo-excluded.c"], |
| 294 | include_build_directory: false, |
| 295 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 296 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 297 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 298 | "srcs_c": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 299 | "common.c", |
| 300 | "foo-a.c", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 301 | ]`, |
| 302 | }), |
| 303 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 304 | }) |
| 305 | } |
| 306 | |
| 307 | func TestCcLibrarySharedStrip(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 308 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 309 | Description: "cc_library_shared stripping", |
| 310 | Filesystem: map[string]string{}, |
| 311 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 312 | cc_library_shared { |
| 313 | name: "foo_shared", |
| 314 | strip: { |
| 315 | keep_symbols: false, |
| 316 | keep_symbols_and_debug_frame: true, |
| 317 | keep_symbols_list: ["sym", "sym2"], |
| 318 | all: true, |
| 319 | none: false, |
| 320 | }, |
| 321 | include_build_directory: false, |
| 322 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 323 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 324 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 325 | "strip": `{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 326 | "all": True, |
| 327 | "keep_symbols": False, |
| 328 | "keep_symbols_and_debug_frame": True, |
| 329 | "keep_symbols_list": [ |
| 330 | "sym", |
| 331 | "sym2", |
| 332 | ], |
| 333 | "none": False, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 334 | }`, |
| 335 | }), |
| 336 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 337 | }) |
| 338 | } |
| 339 | |
Trevor Radcliffe | 37ec2f7 | 2022-09-27 01:46:01 +0000 | [diff] [blame] | 340 | func TestCcLibrarySharedVersionScriptAndDynamicList(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 341 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
Trevor Radcliffe | 37ec2f7 | 2022-09-27 01:46:01 +0000 | [diff] [blame] | 342 | Description: "cc_library_shared version script and dynamic list", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 343 | Filesystem: map[string]string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 344 | "version_script": "", |
Trevor Radcliffe | 37ec2f7 | 2022-09-27 01:46:01 +0000 | [diff] [blame] | 345 | "dynamic.list": "", |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 346 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 347 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 348 | cc_library_shared { |
| 349 | name: "foo_shared", |
| 350 | version_script: "version_script", |
Trevor Radcliffe | 37ec2f7 | 2022-09-27 01:46:01 +0000 | [diff] [blame] | 351 | dynamic_list: "dynamic.list", |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 352 | include_build_directory: false, |
| 353 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 354 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 355 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Trevor Radcliffe | 37ec2f7 | 2022-09-27 01:46:01 +0000 | [diff] [blame] | 356 | "additional_linker_inputs": `[ |
| 357 | "version_script", |
| 358 | "dynamic.list", |
| 359 | ]`, |
| 360 | "linkopts": `[ |
| 361 | "-Wl,--version-script,$(location version_script)", |
| 362 | "-Wl,--dynamic-list,$(location dynamic.list)", |
| 363 | ]`, |
Trevor Radcliffe | f06dd91 | 2023-05-19 14:51:41 +0000 | [diff] [blame] | 364 | "features": `["android_cfi_exports_map"]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 365 | }), |
| 366 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 367 | }) |
| 368 | } |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 369 | |
Trevor Radcliffe | ea6a45d | 2022-09-20 18:58:01 +0000 | [diff] [blame] | 370 | func TestCcLibraryLdflagsSplitBySpaceSoongAdded(t *testing.T) { |
| 371 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 372 | Description: "ldflags are split by spaces except for the ones added by soong (version script and dynamic list)", |
| 373 | Filesystem: map[string]string{ |
| 374 | "version_script": "", |
| 375 | "dynamic.list": "", |
| 376 | }, |
| 377 | Blueprint: ` |
| 378 | cc_library_shared { |
| 379 | name: "foo", |
| 380 | ldflags: [ |
| 381 | "--nospace_flag", |
| 382 | "-z spaceflag", |
| 383 | ], |
| 384 | version_script: "version_script", |
| 385 | dynamic_list: "dynamic.list", |
| 386 | include_build_directory: false, |
| 387 | }`, |
| 388 | ExpectedBazelTargets: []string{ |
| 389 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 390 | "additional_linker_inputs": `[ |
| 391 | "version_script", |
| 392 | "dynamic.list", |
| 393 | ]`, |
| 394 | "linkopts": `[ |
| 395 | "--nospace_flag", |
| 396 | "-z", |
| 397 | "spaceflag", |
| 398 | "-Wl,--version-script,$(location version_script)", |
| 399 | "-Wl,--dynamic-list,$(location dynamic.list)", |
| 400 | ]`, |
Trevor Radcliffe | f06dd91 | 2023-05-19 14:51:41 +0000 | [diff] [blame] | 401 | "features": `["android_cfi_exports_map"]`, |
Trevor Radcliffe | ea6a45d | 2022-09-20 18:58:01 +0000 | [diff] [blame] | 402 | }), |
| 403 | }, |
| 404 | }) |
| 405 | } |
| 406 | |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 407 | func TestCcLibrarySharedNoCrtTrue(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 408 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 409 | Description: "cc_library_shared - nocrt: true disables feature", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 410 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 411 | "impl.cpp": "", |
| 412 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 413 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 414 | cc_library_shared { |
| 415 | name: "foo_shared", |
| 416 | srcs: ["impl.cpp"], |
| 417 | nocrt: true, |
| 418 | include_build_directory: false, |
| 419 | } |
| 420 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 421 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 422 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 423 | "features": `["-link_crt"]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 424 | "srcs": `["impl.cpp"]`, |
| 425 | }), |
| 426 | }, |
| 427 | }) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | func TestCcLibrarySharedNoCrtFalse(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 431 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 432 | Description: "cc_library_shared - nocrt: false doesn't disable feature", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 433 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 434 | "impl.cpp": "", |
| 435 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 436 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 437 | cc_library_shared { |
| 438 | name: "foo_shared", |
| 439 | srcs: ["impl.cpp"], |
| 440 | nocrt: false, |
| 441 | include_build_directory: false, |
| 442 | } |
| 443 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 444 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 445 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 446 | "srcs": `["impl.cpp"]`, |
| 447 | }), |
| 448 | }, |
| 449 | }) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | func TestCcLibrarySharedNoCrtArchVariant(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 453 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 454 | Description: "cc_library_shared - nocrt in select", |
| 455 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 456 | "impl.cpp": "", |
| 457 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 458 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 459 | cc_library_shared { |
| 460 | name: "foo_shared", |
| 461 | srcs: ["impl.cpp"], |
| 462 | arch: { |
| 463 | arm: { |
| 464 | nocrt: true, |
| 465 | }, |
| 466 | x86: { |
| 467 | nocrt: false, |
| 468 | }, |
| 469 | }, |
| 470 | include_build_directory: false, |
| 471 | } |
| 472 | `, |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 473 | ExpectedBazelTargets: []string{ |
| 474 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
| 475 | "features": `select({ |
| 476 | "//build/bazel/platforms/arch:arm": ["-link_crt"], |
| 477 | "//conditions:default": [], |
| 478 | })`, |
| 479 | "srcs": `["impl.cpp"]`, |
| 480 | }), |
| 481 | }, |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 482 | }) |
| 483 | } |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 484 | |
| 485 | func TestCcLibrarySharedProto(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 486 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 487 | Blueprint: soongCcProtoPreamble + `cc_library_shared { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 488 | name: "foo", |
| 489 | srcs: ["foo.proto"], |
| 490 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 491 | export_proto_headers: true, |
| 492 | }, |
| 493 | include_build_directory: false, |
| 494 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 495 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 496 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 497 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 498 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 499 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 500 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 501 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 502 | "whole_archive_deps": `[":foo_cc_proto_lite"]`, |
| 503 | }), |
| 504 | }, |
| 505 | }) |
| 506 | } |
Rupert Shuttleworth | 484aa25 | 2021-12-10 07:22:53 -0500 | [diff] [blame] | 507 | |
| 508 | func TestCcLibrarySharedUseVersionLib(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 509 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 510 | Filesystem: map[string]string{ |
| 511 | soongCcVersionLibBpPath: soongCcVersionLibBp, |
| 512 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 513 | Blueprint: soongCcProtoPreamble + `cc_library_shared { |
Rupert Shuttleworth | 484aa25 | 2021-12-10 07:22:53 -0500 | [diff] [blame] | 514 | name: "foo", |
| 515 | use_version_lib: true, |
| 516 | include_build_directory: false, |
| 517 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 518 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 519 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Yu Liu | fe978fd | 2023-04-24 16:37:18 -0700 | [diff] [blame] | 520 | "use_version_lib": "True", |
| 521 | "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`, |
Rupert Shuttleworth | 484aa25 | 2021-12-10 07:22:53 -0500 | [diff] [blame] | 522 | }), |
| 523 | }, |
| 524 | }) |
| 525 | } |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 526 | |
| 527 | func TestCcLibrarySharedStubs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 528 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 529 | Description: "cc_library_shared stubs", |
| 530 | ModuleTypeUnderTest: "cc_library_shared", |
| 531 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 532 | Dir: "foo/bar", |
| 533 | Filesystem: map[string]string{ |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 534 | "foo/bar/Android.bp": ` |
| 535 | cc_library_shared { |
| 536 | name: "a", |
| 537 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 538 | bazel_module: { bp2build_available: true }, |
| 539 | include_build_directory: false, |
| 540 | } |
| 541 | `, |
| 542 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 543 | Blueprint: soongCcLibraryPreamble, |
Trevor Radcliffe | f19d8a7 | 2022-09-20 23:04:39 +0000 | [diff] [blame] | 544 | ExpectedBazelTargets: []string{makeCcStubSuiteTargets("a", AttrNameToString{ |
Spandan Das | 04f9f4c | 2023-09-13 23:59:05 +0000 | [diff] [blame] | 545 | "api_surface": `"module-libapi"`, |
Sam Delmerico | 5f90649 | 2023-03-15 18:06:18 -0400 | [diff] [blame] | 546 | "soname": `"a.so"`, |
| 547 | "source_library_label": `"//foo/bar:a"`, |
| 548 | "stubs_symbol_file": `"a.map.txt"`, |
Trevor Radcliffe | f19d8a7 | 2022-09-20 23:04:39 +0000 | [diff] [blame] | 549 | "stubs_versions": `[ |
Trevor Radcliffe | 087af54 | 2022-09-16 15:36:10 +0000 | [diff] [blame] | 550 | "28", |
| 551 | "29", |
| 552 | "current", |
| 553 | ]`, |
Trevor Radcliffe | f19d8a7 | 2022-09-20 23:04:39 +0000 | [diff] [blame] | 554 | }), |
| 555 | MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
Yu Liu | 56ccb1a | 2022-11-12 10:47:07 -0800 | [diff] [blame] | 556 | "stubs_symbol_file": `"a.map.txt"`, |
Trevor Radcliffe | 087af54 | 2022-09-16 15:36:10 +0000 | [diff] [blame] | 557 | }), |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 558 | }, |
Trevor Radcliffe | f19d8a7 | 2022-09-20 23:04:39 +0000 | [diff] [blame] | 559 | }) |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 560 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 126bd58 | 2022-04-21 15:19:27 +0000 | [diff] [blame] | 561 | |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 562 | func TestCcLibrarySharedStubs_UseImplementationInSameApex(t *testing.T) { |
| 563 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 564 | Description: "cc_library_shared stubs", |
| 565 | ModuleTypeUnderTest: "cc_library_shared", |
| 566 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 567 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 568 | cc_library_shared { |
| 569 | name: "a", |
| 570 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 571 | bazel_module: { bp2build_available: false }, |
| 572 | include_build_directory: false, |
| 573 | apex_available: ["made_up_apex"], |
| 574 | } |
| 575 | cc_library_shared { |
| 576 | name: "b", |
| 577 | shared_libs: [":a"], |
| 578 | include_build_directory: false, |
| 579 | apex_available: ["made_up_apex"], |
| 580 | } |
| 581 | `, |
| 582 | ExpectedBazelTargets: []string{ |
| 583 | MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ |
| 584 | "implementation_dynamic_deps": `[":a"]`, |
| 585 | "tags": `["apex_available=made_up_apex"]`, |
| 586 | }), |
| 587 | }, |
| 588 | }) |
| 589 | } |
| 590 | |
| 591 | func TestCcLibrarySharedStubs_UseStubsInDifferentApex(t *testing.T) { |
| 592 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 593 | Description: "cc_library_shared stubs", |
| 594 | ModuleTypeUnderTest: "cc_library_shared", |
| 595 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 596 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 597 | cc_library_shared { |
| 598 | name: "a", |
| 599 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 600 | bazel_module: { bp2build_available: false }, |
| 601 | include_build_directory: false, |
| 602 | apex_available: ["apex_a"], |
| 603 | } |
| 604 | cc_library_shared { |
| 605 | name: "b", |
| 606 | shared_libs: [":a"], |
| 607 | include_build_directory: false, |
| 608 | apex_available: ["apex_b"], |
| 609 | } |
| 610 | `, |
| 611 | ExpectedBazelTargets: []string{ |
| 612 | MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ |
| 613 | "implementation_dynamic_deps": `select({ |
Spandan Das | 6d4d9da | 2023-04-18 06:20:40 +0000 | [diff] [blame] | 614 | "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"], |
| 615 | "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"], |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 616 | "//conditions:default": [":a"], |
| 617 | })`, |
| 618 | "tags": `["apex_available=apex_b"]`, |
| 619 | }), |
| 620 | }, |
| 621 | }) |
| 622 | } |
| 623 | |
Spandan Das | 6d4d9da | 2023-04-18 06:20:40 +0000 | [diff] [blame] | 624 | // Tests that library in apexfoo links against stubs of platform_lib and otherapex_lib |
| 625 | func TestCcLibrarySharedStubs_UseStubsFromMultipleApiDomains(t *testing.T) { |
| 626 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 627 | Description: "cc_library_shared stubs", |
| 628 | ModuleTypeUnderTest: "cc_library_shared", |
| 629 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 630 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 631 | cc_library_shared { |
| 632 | name: "libplatform_stable", |
| 633 | stubs: { symbol_file: "libplatform_stable.map.txt", versions: ["28", "29", "current"] }, |
| 634 | apex_available: ["//apex_available:platform"], |
| 635 | bazel_module: { bp2build_available: false }, |
| 636 | include_build_directory: false, |
| 637 | } |
| 638 | cc_library_shared { |
| 639 | name: "libapexfoo_stable", |
| 640 | stubs: { symbol_file: "libapexfoo_stable.map.txt", versions: ["28", "29", "current"] }, |
| 641 | apex_available: ["apexfoo"], |
| 642 | bazel_module: { bp2build_available: false }, |
| 643 | include_build_directory: false, |
| 644 | } |
| 645 | cc_library_shared { |
| 646 | name: "libutils", |
| 647 | shared_libs: ["libplatform_stable", "libapexfoo_stable",], |
| 648 | apex_available: ["//apex_available:platform", "apexfoo", "apexbar"], |
| 649 | include_build_directory: false, |
| 650 | } |
| 651 | `, |
| 652 | ExpectedBazelTargets: []string{ |
| 653 | MakeBazelTarget("cc_library_shared", "libutils", AttrNameToString{ |
| 654 | "implementation_dynamic_deps": `select({ |
| 655 | "//build/bazel/rules/apex:apexbar": [ |
| 656 | "@api_surfaces//module-libapi/current:libplatform_stable", |
| 657 | "@api_surfaces//module-libapi/current:libapexfoo_stable", |
| 658 | ], |
| 659 | "//build/bazel/rules/apex:apexfoo": [ |
| 660 | "@api_surfaces//module-libapi/current:libplatform_stable", |
| 661 | ":libapexfoo_stable", |
| 662 | ], |
| 663 | "//build/bazel/rules/apex:system": [ |
Spandan Das | f7bae9a | 2023-09-06 22:07:15 +0000 | [diff] [blame] | 664 | ":libplatform_stable", |
Spandan Das | 6d4d9da | 2023-04-18 06:20:40 +0000 | [diff] [blame] | 665 | "@api_surfaces//module-libapi/current:libapexfoo_stable", |
| 666 | ], |
| 667 | "//conditions:default": [ |
| 668 | ":libplatform_stable", |
| 669 | ":libapexfoo_stable", |
| 670 | ], |
| 671 | })`, |
| 672 | "tags": `[ |
| 673 | "apex_available=//apex_available:platform", |
| 674 | "apex_available=apexfoo", |
| 675 | "apex_available=apexbar", |
| 676 | ]`, |
| 677 | }), |
| 678 | }, |
| 679 | }) |
| 680 | } |
| 681 | |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 682 | func TestCcLibrarySharedStubs_IgnorePlatformAvailable(t *testing.T) { |
| 683 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 684 | Description: "cc_library_shared stubs", |
| 685 | ModuleTypeUnderTest: "cc_library_shared", |
| 686 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 687 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 688 | cc_library_shared { |
| 689 | name: "a", |
| 690 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 691 | bazel_module: { bp2build_available: false }, |
| 692 | include_build_directory: false, |
| 693 | apex_available: ["//apex_available:platform", "apex_a"], |
| 694 | } |
| 695 | cc_library_shared { |
| 696 | name: "b", |
| 697 | shared_libs: [":a"], |
| 698 | include_build_directory: false, |
| 699 | apex_available: ["//apex_available:platform", "apex_b"], |
| 700 | } |
| 701 | `, |
| 702 | ExpectedBazelTargets: []string{ |
| 703 | MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ |
| 704 | "implementation_dynamic_deps": `select({ |
Spandan Das | 6d4d9da | 2023-04-18 06:20:40 +0000 | [diff] [blame] | 705 | "//build/bazel/rules/apex:apex_b": ["@api_surfaces//module-libapi/current:a"], |
| 706 | "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"], |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 707 | "//conditions:default": [":a"], |
| 708 | })`, |
| 709 | "tags": `[ |
| 710 | "apex_available=//apex_available:platform", |
| 711 | "apex_available=apex_b", |
| 712 | ]`, |
| 713 | }), |
| 714 | }, |
| 715 | }) |
| 716 | } |
| 717 | |
Spandan Das | 6d4d9da | 2023-04-18 06:20:40 +0000 | [diff] [blame] | 718 | func TestCcLibraryDoesNotDropStubDepIfNoVariationAcrossAxis(t *testing.T) { |
| 719 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 720 | Description: "cc_library depeends on impl for all configurations", |
| 721 | ModuleTypeUnderTest: "cc_library_shared", |
| 722 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 723 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 724 | cc_library_shared { |
| 725 | name: "a", |
| 726 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 727 | bazel_module: { bp2build_available: false }, |
| 728 | apex_available: ["//apex_available:platform"], |
| 729 | } |
| 730 | cc_library_shared { |
| 731 | name: "b", |
| 732 | shared_libs: [":a"], |
| 733 | include_build_directory: false, |
| 734 | apex_available: ["//apex_available:platform"], |
| 735 | } |
| 736 | `, |
| 737 | ExpectedBazelTargets: []string{ |
| 738 | MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ |
| 739 | "implementation_dynamic_deps": `[":a"]`, |
| 740 | "tags": `["apex_available=//apex_available:platform"]`, |
| 741 | }), |
| 742 | }, |
| 743 | }) |
| 744 | } |
| 745 | |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 746 | func TestCcLibrarySharedStubs_MultipleApexAvailable(t *testing.T) { |
| 747 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 748 | ModuleTypeUnderTest: "cc_library_shared", |
| 749 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 750 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 751 | cc_library_shared { |
| 752 | name: "a", |
| 753 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 754 | bazel_module: { bp2build_available: false }, |
| 755 | include_build_directory: false, |
| 756 | apex_available: ["//apex_available:platform", "apex_a", "apex_b"], |
| 757 | } |
| 758 | cc_library_shared { |
| 759 | name: "b", |
| 760 | shared_libs: [":a"], |
| 761 | include_build_directory: false, |
| 762 | apex_available: ["//apex_available:platform", "apex_b"], |
| 763 | } |
| 764 | |
| 765 | cc_library_shared { |
| 766 | name: "c", |
| 767 | shared_libs: [":a"], |
| 768 | include_build_directory: false, |
| 769 | apex_available: ["//apex_available:platform", "apex_a", "apex_b"], |
| 770 | } |
| 771 | `, |
| 772 | ExpectedBazelTargets: []string{ |
| 773 | MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ |
| 774 | "implementation_dynamic_deps": `select({ |
Spandan Das | 6d4d9da | 2023-04-18 06:20:40 +0000 | [diff] [blame] | 775 | "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:a"], |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 776 | "//conditions:default": [":a"], |
| 777 | })`, |
| 778 | "tags": `[ |
| 779 | "apex_available=//apex_available:platform", |
| 780 | "apex_available=apex_b", |
| 781 | ]`, |
| 782 | }), |
| 783 | MakeBazelTarget("cc_library_shared", "c", AttrNameToString{ |
| 784 | "implementation_dynamic_deps": `[":a"]`, |
| 785 | "tags": `[ |
| 786 | "apex_available=//apex_available:platform", |
| 787 | "apex_available=apex_a", |
| 788 | "apex_available=apex_b", |
| 789 | ]`, |
| 790 | }), |
| 791 | }, |
| 792 | }) |
| 793 | } |
| 794 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 126bd58 | 2022-04-21 15:19:27 +0000 | [diff] [blame] | 795 | func TestCcLibrarySharedSystemSharedLibsSharedEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 796 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 797 | Description: "cc_library_shared system_shared_libs empty shared default", |
| 798 | ModuleTypeUnderTest: "cc_library_shared", |
| 799 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 800 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 126bd58 | 2022-04-21 15:19:27 +0000 | [diff] [blame] | 801 | cc_defaults { |
| 802 | name: "empty_defaults", |
| 803 | shared: { |
| 804 | system_shared_libs: [], |
| 805 | }, |
| 806 | include_build_directory: false, |
| 807 | } |
| 808 | cc_library_shared { |
| 809 | name: "empty", |
| 810 | defaults: ["empty_defaults"], |
| 811 | } |
| 812 | `, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 813 | ExpectedBazelTargets: []string{MakeBazelTarget("cc_library_shared", "empty", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 126bd58 | 2022-04-21 15:19:27 +0000 | [diff] [blame] | 814 | "system_dynamic_deps": "[]", |
| 815 | })}, |
| 816 | }) |
| 817 | } |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 818 | |
| 819 | func TestCcLibrarySharedConvertLex(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 820 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 821 | Description: "cc_library_shared with lex files", |
| 822 | ModuleTypeUnderTest: "cc_library_shared", |
| 823 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 824 | Filesystem: map[string]string{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 825 | "foo.c": "", |
| 826 | "bar.cc": "", |
| 827 | "foo1.l": "", |
| 828 | "bar1.ll": "", |
| 829 | "foo2.l": "", |
| 830 | "bar2.ll": "", |
| 831 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 832 | Blueprint: `cc_library_shared { |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 833 | name: "foo_lib", |
| 834 | srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"], |
| 835 | lex: { flags: ["--foo_flags"] }, |
| 836 | include_build_directory: false, |
| 837 | bazel_module: { bp2build_available: true }, |
| 838 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 839 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 840 | MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 841 | "srcs": `[ |
| 842 | "foo1.l", |
| 843 | "foo2.l", |
| 844 | ]`, |
| 845 | "lexopts": `["--foo_flags"]`, |
| 846 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 847 | MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 848 | "srcs": `[ |
| 849 | "bar1.ll", |
| 850 | "bar2.ll", |
| 851 | ]`, |
| 852 | "lexopts": `["--foo_flags"]`, |
| 853 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 854 | MakeBazelTarget("cc_library_shared", "foo_lib", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 855 | "srcs": `[ |
| 856 | "bar.cc", |
| 857 | ":foo_lib_genlex_ll", |
| 858 | ]`, |
| 859 | "srcs_c": `[ |
| 860 | "foo.c", |
| 861 | ":foo_lib_genlex_l", |
| 862 | ]`, |
| 863 | }), |
| 864 | }, |
| 865 | }) |
| 866 | } |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 867 | |
| 868 | func TestCcLibrarySharedClangUnknownFlags(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 869 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 870 | Blueprint: soongCcProtoPreamble + `cc_library_shared { |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 871 | name: "foo", |
| 872 | conlyflags: ["-a", "-finline-functions"], |
| 873 | cflags: ["-b","-finline-functions"], |
| 874 | cppflags: ["-c", "-finline-functions"], |
| 875 | ldflags: ["-d","-finline-functions", "-e"], |
| 876 | include_build_directory: false, |
| 877 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 878 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 879 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 880 | "conlyflags": `["-a"]`, |
| 881 | "copts": `["-b"]`, |
| 882 | "cppflags": `["-c"]`, |
| 883 | "linkopts": `[ |
| 884 | "-d", |
| 885 | "-e", |
| 886 | ]`, |
| 887 | }), |
| 888 | }, |
| 889 | }) |
| 890 | } |
| 891 | |
| 892 | func TestCCLibraryFlagSpaceSplitting(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 893 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 894 | Blueprint: soongCcProtoPreamble + `cc_library_shared { |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 895 | name: "foo", |
| 896 | conlyflags: [ "-include header.h"], |
| 897 | cflags: ["-include header.h"], |
| 898 | cppflags: ["-include header.h"], |
| 899 | version_script: "version_script", |
| 900 | include_build_directory: false, |
| 901 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 902 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 903 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 904 | "additional_linker_inputs": `["version_script"]`, |
| 905 | "conlyflags": `[ |
| 906 | "-include", |
| 907 | "header.h", |
| 908 | ]`, |
| 909 | "copts": `[ |
| 910 | "-include", |
| 911 | "header.h", |
| 912 | ]`, |
| 913 | "cppflags": `[ |
| 914 | "-include", |
| 915 | "header.h", |
| 916 | ]`, |
| 917 | "linkopts": `["-Wl,--version-script,$(location version_script)"]`, |
Trevor Radcliffe | f06dd91 | 2023-05-19 14:51:41 +0000 | [diff] [blame] | 918 | "features": `["android_cfi_exports_map"]`, |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 919 | }), |
| 920 | }, |
| 921 | }) |
| 922 | } |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 923 | |
| 924 | func TestCCLibrarySharedRuntimeDeps(t *testing.T) { |
| 925 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 926 | Blueprint: `cc_library_shared { |
| 927 | name: "bar", |
| 928 | } |
| 929 | |
| 930 | cc_library_shared { |
| 931 | name: "foo", |
| 932 | runtime_libs: ["foo"], |
| 933 | }`, |
| 934 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 935 | MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{ |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 936 | "local_includes": `["."]`, |
| 937 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 938 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 939 | "runtime_deps": `[":foo"]`, |
| 940 | "local_includes": `["."]`, |
| 941 | }), |
| 942 | }, |
| 943 | }) |
| 944 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 945 | |
| 946 | func TestCcLibrarySharedEmptySuffix(t *testing.T) { |
| 947 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 948 | Description: "cc_library_shared with empty suffix", |
| 949 | Filesystem: map[string]string{ |
| 950 | "foo.c": "", |
| 951 | }, |
| 952 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 953 | cc_library_shared { |
| 954 | name: "foo_shared", |
| 955 | suffix: "", |
| 956 | srcs: ["foo.c"], |
| 957 | include_build_directory: false, |
| 958 | }`, |
| 959 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 960 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 961 | "srcs_c": `["foo.c"]`, |
| 962 | "suffix": `""`, |
| 963 | }), |
| 964 | }, |
| 965 | }) |
| 966 | } |
| 967 | |
| 968 | func TestCcLibrarySharedSuffix(t *testing.T) { |
| 969 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 970 | Description: "cc_library_shared with suffix", |
| 971 | Filesystem: map[string]string{ |
| 972 | "foo.c": "", |
| 973 | }, |
| 974 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 975 | cc_library_shared { |
| 976 | name: "foo_shared", |
| 977 | suffix: "-suf", |
| 978 | srcs: ["foo.c"], |
| 979 | include_build_directory: false, |
| 980 | }`, |
| 981 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 982 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 983 | "srcs_c": `["foo.c"]`, |
| 984 | "suffix": `"-suf"`, |
| 985 | }), |
| 986 | }, |
| 987 | }) |
| 988 | } |
| 989 | |
| 990 | func TestCcLibrarySharedArchVariantSuffix(t *testing.T) { |
| 991 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 992 | Description: "cc_library_shared with arch-variant suffix", |
| 993 | Filesystem: map[string]string{ |
| 994 | "foo.c": "", |
| 995 | }, |
| 996 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 997 | cc_library_shared { |
| 998 | name: "foo_shared", |
| 999 | arch: { |
| 1000 | arm64: { suffix: "-64" }, |
| 1001 | arm: { suffix: "-32" }, |
| 1002 | }, |
| 1003 | srcs: ["foo.c"], |
| 1004 | include_build_directory: false, |
| 1005 | }`, |
| 1006 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1007 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 1008 | "srcs_c": `["foo.c"]`, |
| 1009 | "suffix": `select({ |
| 1010 | "//build/bazel/platforms/arch:arm": "-32", |
| 1011 | "//build/bazel/platforms/arch:arm64": "-64", |
| 1012 | "//conditions:default": None, |
| 1013 | })`, |
| 1014 | }), |
| 1015 | }, |
| 1016 | }) |
| 1017 | } |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 1018 | |
| 1019 | func TestCcLibrarySharedWithSyspropSrcs(t *testing.T) { |
| 1020 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1021 | Description: "cc_library_shared with sysprop sources", |
| 1022 | Blueprint: ` |
| 1023 | cc_library_shared { |
| 1024 | name: "foo", |
| 1025 | srcs: [ |
| 1026 | "bar.sysprop", |
| 1027 | "baz.sysprop", |
| 1028 | "blah.cpp", |
| 1029 | ], |
| 1030 | min_sdk_version: "5", |
| 1031 | }`, |
| 1032 | ExpectedBazelTargets: []string{ |
| 1033 | MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{ |
| 1034 | "srcs": `[ |
| 1035 | "bar.sysprop", |
| 1036 | "baz.sysprop", |
| 1037 | ]`, |
| 1038 | }), |
| 1039 | MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{ |
| 1040 | "dep": `":foo_sysprop_library"`, |
| 1041 | "min_sdk_version": `"5"`, |
| 1042 | }), |
| 1043 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1044 | "srcs": `["blah.cpp"]`, |
| 1045 | "local_includes": `["."]`, |
| 1046 | "min_sdk_version": `"5"`, |
| 1047 | "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`, |
| 1048 | }), |
| 1049 | }, |
| 1050 | }) |
| 1051 | } |
| 1052 | |
| 1053 | func TestCcLibrarySharedWithSyspropSrcsSomeConfigs(t *testing.T) { |
| 1054 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1055 | Description: "cc_library_shared with sysprop sources in some configs but not others", |
| 1056 | Blueprint: ` |
| 1057 | cc_library_shared { |
| 1058 | name: "foo", |
| 1059 | srcs: [ |
| 1060 | "blah.cpp", |
| 1061 | ], |
| 1062 | target: { |
| 1063 | android: { |
| 1064 | srcs: ["bar.sysprop"], |
| 1065 | }, |
| 1066 | }, |
| 1067 | min_sdk_version: "5", |
| 1068 | }`, |
| 1069 | ExpectedBazelTargets: []string{ |
| 1070 | MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{ |
| 1071 | "srcs": `select({ |
| 1072 | "//build/bazel/platforms/os:android": ["bar.sysprop"], |
| 1073 | "//conditions:default": [], |
| 1074 | })`, |
| 1075 | }), |
| 1076 | MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{ |
| 1077 | "dep": `":foo_sysprop_library"`, |
| 1078 | "min_sdk_version": `"5"`, |
| 1079 | }), |
| 1080 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1081 | "srcs": `["blah.cpp"]`, |
| 1082 | "local_includes": `["."]`, |
| 1083 | "min_sdk_version": `"5"`, |
| 1084 | "whole_archive_deps": `select({ |
| 1085 | "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"], |
| 1086 | "//conditions:default": [], |
| 1087 | })`, |
| 1088 | }), |
| 1089 | }, |
| 1090 | }) |
| 1091 | } |
Yu Liu | 56ccb1a | 2022-11-12 10:47:07 -0800 | [diff] [blame] | 1092 | |
| 1093 | func TestCcLibrarySharedHeaderAbiChecker(t *testing.T) { |
| 1094 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1095 | Description: "cc_library_shared with header abi checker", |
| 1096 | Blueprint: `cc_library_shared { |
| 1097 | name: "foo", |
| 1098 | header_abi_checker: { |
| 1099 | enabled: true, |
| 1100 | symbol_file: "a.map.txt", |
| 1101 | exclude_symbol_versions: [ |
| 1102 | "29", |
| 1103 | "30", |
| 1104 | ], |
| 1105 | exclude_symbol_tags: [ |
| 1106 | "tag1", |
| 1107 | "tag2", |
| 1108 | ], |
| 1109 | check_all_apis: true, |
| 1110 | diff_flags: ["-allow-adding-removing-weak-symbols"], |
| 1111 | }, |
| 1112 | include_build_directory: false, |
| 1113 | }`, |
| 1114 | ExpectedBazelTargets: []string{ |
| 1115 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1116 | "abi_checker_enabled": `True`, |
| 1117 | "abi_checker_symbol_file": `"a.map.txt"`, |
| 1118 | "abi_checker_exclude_symbol_versions": `[ |
| 1119 | "29", |
| 1120 | "30", |
| 1121 | ]`, |
| 1122 | "abi_checker_exclude_symbol_tags": `[ |
| 1123 | "tag1", |
| 1124 | "tag2", |
| 1125 | ]`, |
| 1126 | "abi_checker_check_all_apis": `True`, |
| 1127 | "abi_checker_diff_flags": `["-allow-adding-removing-weak-symbols"]`, |
| 1128 | }), |
| 1129 | }, |
| 1130 | }) |
| 1131 | } |
Trevor Radcliffe | db7e026 | 2022-10-28 16:48:18 +0000 | [diff] [blame] | 1132 | |
| 1133 | func TestCcLibrarySharedWithIntegerOverflowProperty(t *testing.T) { |
| 1134 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1135 | Description: "cc_library_shared has correct features when integer_overflow property is provided", |
| 1136 | Blueprint: ` |
| 1137 | cc_library_shared { |
| 1138 | name: "foo", |
| 1139 | sanitize: { |
| 1140 | integer_overflow: true, |
| 1141 | }, |
| 1142 | } |
| 1143 | `, |
| 1144 | ExpectedBazelTargets: []string{ |
| 1145 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1146 | "features": `["ubsan_integer_overflow"]`, |
| 1147 | "local_includes": `["."]`, |
| 1148 | }), |
| 1149 | }, |
| 1150 | }) |
| 1151 | } |
| 1152 | |
| 1153 | func TestCcLibrarySharedWithMiscUndefinedProperty(t *testing.T) { |
| 1154 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1155 | Description: "cc_library_shared has correct features when misc_undefined property is provided", |
| 1156 | Blueprint: ` |
| 1157 | cc_library_shared { |
| 1158 | name: "foo", |
| 1159 | sanitize: { |
| 1160 | misc_undefined: ["undefined", "nullability"], |
| 1161 | }, |
| 1162 | } |
| 1163 | `, |
| 1164 | ExpectedBazelTargets: []string{ |
| 1165 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1166 | "features": `[ |
| 1167 | "ubsan_undefined", |
| 1168 | "ubsan_nullability", |
| 1169 | ]`, |
| 1170 | "local_includes": `["."]`, |
| 1171 | }), |
| 1172 | }, |
| 1173 | }) |
| 1174 | } |
| 1175 | |
| 1176 | func TestCcLibrarySharedWithUBSanPropertiesArchSpecific(t *testing.T) { |
| 1177 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1178 | Description: "cc_library_shared has correct feature select when UBSan props are specified in arch specific blocks", |
| 1179 | Blueprint: ` |
| 1180 | cc_library_shared { |
| 1181 | name: "foo", |
| 1182 | sanitize: { |
| 1183 | misc_undefined: ["undefined", "nullability"], |
| 1184 | }, |
| 1185 | target: { |
| 1186 | android: { |
| 1187 | sanitize: { |
| 1188 | misc_undefined: ["alignment"], |
| 1189 | }, |
| 1190 | }, |
| 1191 | linux_glibc: { |
| 1192 | sanitize: { |
| 1193 | integer_overflow: true, |
| 1194 | }, |
| 1195 | }, |
| 1196 | }, |
| 1197 | } |
| 1198 | `, |
| 1199 | ExpectedBazelTargets: []string{ |
| 1200 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1201 | "features": `[ |
| 1202 | "ubsan_undefined", |
| 1203 | "ubsan_nullability", |
| 1204 | ] + select({ |
| 1205 | "//build/bazel/platforms/os:android": ["ubsan_alignment"], |
| 1206 | "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"], |
| 1207 | "//conditions:default": [], |
| 1208 | })`, |
| 1209 | "local_includes": `["."]`, |
| 1210 | }), |
| 1211 | }, |
| 1212 | }) |
| 1213 | } |
Trevor Radcliffe | 56b1a2b | 2023-02-06 21:58:30 +0000 | [diff] [blame] | 1214 | |
Trevor Radcliffe | ded095c | 2023-06-12 19:18:28 +0000 | [diff] [blame] | 1215 | func TestCcLibrarySharedWithSanitizerBlocklist(t *testing.T) { |
| 1216 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1217 | Description: "cc_library_shared has correct features when sanitize.blocklist is provided", |
| 1218 | Blueprint: ` |
| 1219 | cc_library_shared { |
| 1220 | name: "foo", |
| 1221 | sanitize: { |
| 1222 | blocklist: "foo_blocklist.txt", |
| 1223 | }, |
| 1224 | } |
| 1225 | `, |
| 1226 | ExpectedBazelTargets: []string{ |
| 1227 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Trevor Radcliffe | d9b7f17 | 2023-08-09 22:21:38 +0000 | [diff] [blame] | 1228 | "copts": `select({ |
| 1229 | "//build/bazel/rules/cc:sanitizers_enabled": ["-fsanitize-ignorelist=$(location foo_blocklist.txt)"], |
| 1230 | "//conditions:default": [], |
| 1231 | })`, |
| 1232 | "additional_compiler_inputs": `select({ |
| 1233 | "//build/bazel/rules/cc:sanitizers_enabled": [":foo_blocklist.txt"], |
| 1234 | "//conditions:default": [], |
| 1235 | })`, |
Trevor Radcliffe | ded095c | 2023-06-12 19:18:28 +0000 | [diff] [blame] | 1236 | "local_includes": `["."]`, |
| 1237 | }), |
| 1238 | }, |
| 1239 | }) |
| 1240 | } |
| 1241 | |
Trevor Radcliffe | 56b1a2b | 2023-02-06 21:58:30 +0000 | [diff] [blame] | 1242 | func TestCcLibrarySharedWithThinLto(t *testing.T) { |
| 1243 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1244 | Description: "cc_library_shared has correct features when thin lto is enabled", |
| 1245 | Blueprint: ` |
| 1246 | cc_library_shared { |
| 1247 | name: "foo", |
| 1248 | lto: { |
| 1249 | thin: true, |
| 1250 | }, |
| 1251 | } |
| 1252 | `, |
| 1253 | ExpectedBazelTargets: []string{ |
| 1254 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1255 | "features": `["android_thin_lto"]`, |
| 1256 | "local_includes": `["."]`, |
| 1257 | }), |
| 1258 | }, |
| 1259 | }) |
| 1260 | } |
| 1261 | |
| 1262 | func TestCcLibrarySharedWithLtoNever(t *testing.T) { |
| 1263 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1264 | Description: "cc_library_shared has correct features when thin lto is enabled", |
| 1265 | Blueprint: ` |
| 1266 | cc_library_shared { |
| 1267 | name: "foo", |
| 1268 | lto: { |
| 1269 | never: true, |
| 1270 | }, |
| 1271 | } |
| 1272 | `, |
| 1273 | ExpectedBazelTargets: []string{ |
| 1274 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1275 | "features": `["-android_thin_lto"]`, |
| 1276 | "local_includes": `["."]`, |
| 1277 | }), |
| 1278 | }, |
| 1279 | }) |
| 1280 | } |
| 1281 | |
| 1282 | func TestCcLibrarySharedWithThinLtoArchSpecific(t *testing.T) { |
| 1283 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1284 | Description: "cc_library_shared has correct features when LTO differs across arch and os variants", |
| 1285 | Blueprint: ` |
| 1286 | cc_library_shared { |
| 1287 | name: "foo", |
| 1288 | target: { |
| 1289 | android: { |
| 1290 | lto: { |
| 1291 | thin: true, |
| 1292 | }, |
| 1293 | }, |
| 1294 | }, |
| 1295 | arch: { |
| 1296 | riscv64: { |
| 1297 | lto: { |
| 1298 | thin: false, |
| 1299 | }, |
| 1300 | }, |
| 1301 | }, |
| 1302 | }`, |
| 1303 | ExpectedBazelTargets: []string{ |
| 1304 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1305 | "local_includes": `["."]`, |
| 1306 | "features": `select({ |
| 1307 | "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"], |
| 1308 | "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"], |
| 1309 | "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"], |
| 1310 | "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"], |
| 1311 | "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"], |
| 1312 | "//conditions:default": [], |
| 1313 | })`}), |
| 1314 | }, |
| 1315 | }) |
| 1316 | } |
| 1317 | |
| 1318 | func TestCcLibrarySharedWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) { |
| 1319 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1320 | Description: "cc_library_shared with thin lto disabled by default but enabled on a particular variant", |
| 1321 | Blueprint: ` |
| 1322 | cc_library_shared { |
| 1323 | name: "foo", |
| 1324 | lto: { |
| 1325 | never: true, |
| 1326 | }, |
| 1327 | target: { |
| 1328 | android: { |
| 1329 | lto: { |
| 1330 | thin: true, |
| 1331 | never: false, |
| 1332 | }, |
| 1333 | }, |
| 1334 | }, |
| 1335 | }`, |
| 1336 | ExpectedBazelTargets: []string{ |
| 1337 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1338 | "local_includes": `["."]`, |
| 1339 | "features": `select({ |
| 1340 | "//build/bazel/platforms/os:android": ["android_thin_lto"], |
| 1341 | "//conditions:default": ["-android_thin_lto"], |
| 1342 | })`, |
| 1343 | }), |
| 1344 | }, |
| 1345 | }) |
| 1346 | } |
| 1347 | |
| 1348 | func TestCcLibrarySharedWithThinLtoAndWholeProgramVtables(t *testing.T) { |
| 1349 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1350 | Description: "cc_library_shared has correct features when thin LTO is enabled with whole_program_vtables", |
| 1351 | Blueprint: ` |
| 1352 | cc_library_shared { |
| 1353 | name: "foo", |
| 1354 | lto: { |
| 1355 | thin: true, |
| 1356 | }, |
| 1357 | whole_program_vtables: true, |
| 1358 | } |
| 1359 | `, |
| 1360 | ExpectedBazelTargets: []string{ |
| 1361 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1362 | "features": `[ |
| 1363 | "android_thin_lto", |
| 1364 | "android_thin_lto_whole_program_vtables", |
| 1365 | ]`, |
| 1366 | "local_includes": `["."]`, |
| 1367 | }), |
| 1368 | }, |
| 1369 | }) |
| 1370 | } |
Trevor Radcliffe | a8b4416 | 2023-04-14 18:25:24 +0000 | [diff] [blame] | 1371 | |
| 1372 | func TestCcLibrarySharedHiddenVisibilityConvertedToFeature(t *testing.T) { |
| 1373 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1374 | Description: "cc_library_shared changes hidden visibility flag to feature", |
| 1375 | Blueprint: ` |
| 1376 | cc_library_shared{ |
| 1377 | name: "foo", |
| 1378 | cflags: ["-fvisibility=hidden"], |
| 1379 | }`, |
| 1380 | ExpectedBazelTargets: []string{ |
| 1381 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1382 | "features": `["visibility_hidden"]`, |
| 1383 | "local_includes": `["."]`, |
| 1384 | }), |
| 1385 | }, |
| 1386 | }) |
| 1387 | } |
| 1388 | |
| 1389 | func TestCcLibrarySharedHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) { |
| 1390 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1391 | Description: "cc_library_shared changes hidden visibility flag to feature for specific os", |
| 1392 | Blueprint: ` |
| 1393 | cc_library_shared{ |
| 1394 | name: "foo", |
| 1395 | target: { |
| 1396 | android: { |
| 1397 | cflags: ["-fvisibility=hidden"], |
| 1398 | }, |
| 1399 | }, |
| 1400 | }`, |
| 1401 | ExpectedBazelTargets: []string{ |
| 1402 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1403 | "features": `select({ |
| 1404 | "//build/bazel/platforms/os:android": ["visibility_hidden"], |
| 1405 | "//conditions:default": [], |
| 1406 | })`, |
| 1407 | "local_includes": `["."]`, |
| 1408 | }), |
| 1409 | }, |
| 1410 | }) |
| 1411 | } |
Sam Delmerico | 75dbca2 | 2023-04-20 13:13:25 +0000 | [diff] [blame] | 1412 | |
| 1413 | func TestCcLibrarySharedStubsDessertVersionConversion(t *testing.T) { |
| 1414 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1415 | Description: "cc_library_shared converts dessert codename versions to numerical versions", |
| 1416 | Blueprint: ` |
| 1417 | cc_library_shared { |
| 1418 | name: "a", |
| 1419 | include_build_directory: false, |
| 1420 | stubs: { |
| 1421 | symbol_file: "a.map.txt", |
| 1422 | versions: [ |
| 1423 | "Q", |
| 1424 | "R", |
| 1425 | "31", |
| 1426 | ], |
| 1427 | }, |
| 1428 | } |
| 1429 | cc_library_shared { |
| 1430 | name: "b", |
| 1431 | include_build_directory: false, |
| 1432 | stubs: { |
| 1433 | symbol_file: "b.map.txt", |
| 1434 | versions: [ |
| 1435 | "Q", |
| 1436 | "R", |
| 1437 | "31", |
| 1438 | "current", |
| 1439 | ], |
| 1440 | }, |
| 1441 | } |
| 1442 | `, |
| 1443 | ExpectedBazelTargets: []string{ |
| 1444 | makeCcStubSuiteTargets("a", AttrNameToString{ |
Spandan Das | 04f9f4c | 2023-09-13 23:59:05 +0000 | [diff] [blame] | 1445 | "api_surface": `"module-libapi"`, |
Sam Delmerico | 75dbca2 | 2023-04-20 13:13:25 +0000 | [diff] [blame] | 1446 | "soname": `"a.so"`, |
| 1447 | "source_library_label": `"//:a"`, |
| 1448 | "stubs_symbol_file": `"a.map.txt"`, |
| 1449 | "stubs_versions": `[ |
| 1450 | "29", |
| 1451 | "30", |
| 1452 | "31", |
| 1453 | "current", |
| 1454 | ]`, |
| 1455 | }), |
| 1456 | MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
| 1457 | "stubs_symbol_file": `"a.map.txt"`, |
| 1458 | }), |
| 1459 | makeCcStubSuiteTargets("b", AttrNameToString{ |
Spandan Das | 04f9f4c | 2023-09-13 23:59:05 +0000 | [diff] [blame] | 1460 | "api_surface": `"module-libapi"`, |
Sam Delmerico | 75dbca2 | 2023-04-20 13:13:25 +0000 | [diff] [blame] | 1461 | "soname": `"b.so"`, |
| 1462 | "source_library_label": `"//:b"`, |
| 1463 | "stubs_symbol_file": `"b.map.txt"`, |
| 1464 | "stubs_versions": `[ |
| 1465 | "29", |
| 1466 | "30", |
| 1467 | "31", |
| 1468 | "current", |
| 1469 | ]`, |
| 1470 | }), |
| 1471 | MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ |
| 1472 | "stubs_symbol_file": `"b.map.txt"`, |
| 1473 | }), |
| 1474 | }, |
| 1475 | }) |
| 1476 | } |
Trevor Radcliffe | 27669c0 | 2023-03-28 20:47:10 +0000 | [diff] [blame] | 1477 | |
| 1478 | func TestCcLibrarySharedWithCfi(t *testing.T) { |
| 1479 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1480 | Description: "cc_library_shared has correct features when cfi is enabled for specific variants", |
| 1481 | Blueprint: ` |
| 1482 | cc_library_shared { |
| 1483 | name: "foo", |
| 1484 | sanitize: { |
| 1485 | cfi: true, |
| 1486 | }, |
| 1487 | }`, |
| 1488 | ExpectedBazelTargets: []string{ |
| 1489 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1490 | "features": `["android_cfi"]`, |
| 1491 | "local_includes": `["."]`, |
| 1492 | }), |
| 1493 | }, |
| 1494 | }) |
| 1495 | } |
| 1496 | |
| 1497 | func TestCcLibrarySharedWithCfiOsSpecific(t *testing.T) { |
| 1498 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1499 | Description: "cc_library_shared has correct features when cfi is enabled", |
| 1500 | Blueprint: ` |
| 1501 | cc_library_shared { |
| 1502 | name: "foo", |
| 1503 | target: { |
| 1504 | android: { |
| 1505 | sanitize: { |
| 1506 | cfi: true, |
| 1507 | }, |
| 1508 | }, |
| 1509 | }, |
| 1510 | }`, |
| 1511 | ExpectedBazelTargets: []string{ |
| 1512 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1513 | "features": `select({ |
| 1514 | "//build/bazel/platforms/os:android": ["android_cfi"], |
| 1515 | "//conditions:default": [], |
| 1516 | })`, |
| 1517 | "local_includes": `["."]`, |
| 1518 | }), |
| 1519 | }, |
| 1520 | }) |
| 1521 | } |
| 1522 | |
| 1523 | func TestCcLibrarySharedWithCfiAndCfiAssemblySupport(t *testing.T) { |
| 1524 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1525 | Description: "cc_library_shared has correct features when cfi is enabled with cfi assembly support", |
| 1526 | Blueprint: ` |
| 1527 | cc_library_static { |
| 1528 | name: "foo", |
| 1529 | sanitize: { |
| 1530 | cfi: true, |
| 1531 | config: { |
| 1532 | cfi_assembly_support: true, |
| 1533 | }, |
| 1534 | }, |
| 1535 | }`, |
| 1536 | ExpectedBazelTargets: []string{ |
| 1537 | MakeBazelTarget("cc_library_static", "foo", AttrNameToString{ |
| 1538 | "features": `[ |
| 1539 | "android_cfi", |
| 1540 | "android_cfi_assembly_support", |
| 1541 | ]`, |
| 1542 | "local_includes": `["."]`, |
| 1543 | }), |
| 1544 | }, |
| 1545 | }) |
| 1546 | } |
Trevor Radcliffe | 523c5c6 | 2023-06-16 20:15:45 +0000 | [diff] [blame] | 1547 | |
| 1548 | func TestCcLibrarySharedExplicitlyDisablesCfiWhenFalse(t *testing.T) { |
| 1549 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1550 | Description: "cc_library_shared disables cfi when explciitly set to false in the bp", |
| 1551 | Blueprint: ` |
| 1552 | cc_library_shared { |
| 1553 | name: "foo", |
| 1554 | sanitize: { |
| 1555 | cfi: false, |
| 1556 | }, |
| 1557 | } |
| 1558 | `, |
| 1559 | ExpectedBazelTargets: []string{ |
| 1560 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1561 | "features": `["-android_cfi"]`, |
| 1562 | "local_includes": `["."]`, |
| 1563 | }), |
| 1564 | }, |
| 1565 | }) |
| 1566 | } |
Alix | e266787 | 2023-04-24 14:57:32 +0000 | [diff] [blame] | 1567 | |
| 1568 | func TestCCLibrarySharedRscriptSrc(t *testing.T) { |
| 1569 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1570 | Description: ``, |
| 1571 | Blueprint: ` |
| 1572 | cc_library_shared{ |
| 1573 | name : "foo", |
| 1574 | srcs : [ |
| 1575 | "ccSrc.cc", |
| 1576 | "rsSrc.rscript", |
| 1577 | ], |
| 1578 | include_build_directory: false, |
| 1579 | } |
| 1580 | `, |
| 1581 | ExpectedBazelTargets: []string{ |
| 1582 | MakeBazelTarget("rscript_to_cpp", "foo_renderscript", AttrNameToString{ |
| 1583 | "srcs": `["rsSrc.rscript"]`, |
| 1584 | }), |
| 1585 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1586 | "absolute_includes": `[ |
| 1587 | "frameworks/rs", |
| 1588 | "frameworks/rs/cpp", |
| 1589 | ]`, |
| 1590 | "local_includes": `["."]`, |
| 1591 | "srcs": `[ |
| 1592 | "ccSrc.cc", |
| 1593 | "foo_renderscript", |
| 1594 | ]`, |
| 1595 | })}}) |
| 1596 | } |
Spandan Das | 1f65f9e | 2023-09-15 01:08:23 +0000 | [diff] [blame] | 1597 | |
| 1598 | func TestCcLibrarySdkVariantUsesStubs(t *testing.T) { |
| 1599 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1600 | Description: "cc_library_shared stubs", |
| 1601 | ModuleTypeUnderTest: "cc_library_shared", |
| 1602 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 1603 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 1604 | cc_library_shared { |
| 1605 | name: "libUsesSdk", |
| 1606 | sdk_version: "current", |
| 1607 | shared_libs: [ |
| 1608 | "libNoStubs", |
| 1609 | "libHasApexStubs", |
| 1610 | "libHasApexAndNdkStubs", |
| 1611 | ] |
| 1612 | } |
| 1613 | cc_library_shared { |
| 1614 | name: "libNoStubs", |
| 1615 | bazel_module: { bp2build_available: false }, |
| 1616 | } |
| 1617 | cc_library_shared { |
| 1618 | name: "libHasApexStubs", |
| 1619 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 1620 | bazel_module: { bp2build_available: false }, |
| 1621 | apex_available: ["apex_a"], |
| 1622 | } |
| 1623 | cc_library_shared { |
| 1624 | name: "libHasApexAndNdkStubs", |
| 1625 | stubs: { symbol_file: "b.map.txt", versions: ["28", "29", "current"] }, |
| 1626 | bazel_module: { bp2build_available: false }, |
| 1627 | apex_available: ["apex_b"], |
| 1628 | } |
| 1629 | ndk_library { |
| 1630 | name: "libHasApexAndNdkStubs", |
| 1631 | bazel_module: { bp2build_available: false }, |
| 1632 | } |
| 1633 | `, |
| 1634 | ExpectedBazelTargets: []string{ |
| 1635 | MakeBazelTarget("cc_library_shared", "libUsesSdk", AttrNameToString{ |
| 1636 | "implementation_dynamic_deps": `[":libNoStubs"] + select({ |
| 1637 | "//build/bazel/rules/apex:system": [ |
| 1638 | "@api_surfaces//module-libapi/current:libHasApexStubs", |
| 1639 | "@api_surfaces//module-libapi/current:libHasApexAndNdkStubs", |
| 1640 | ], |
| 1641 | "//build/bazel/rules/apex:unbundled_app": [ |
| 1642 | ":libHasApexStubs", |
| 1643 | "//.:libHasApexAndNdkStubs.ndk_stub_libs", |
| 1644 | ], |
| 1645 | "//conditions:default": [ |
| 1646 | ":libHasApexStubs", |
| 1647 | ":libHasApexAndNdkStubs", |
| 1648 | ], |
| 1649 | })`, |
| 1650 | "local_includes": `["."]`, |
| 1651 | "sdk_version": `"current"`, |
| 1652 | }), |
| 1653 | }, |
| 1654 | }) |
| 1655 | } |