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) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 37 | 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] | 38 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 39 | (&tc).ModuleTypeUnderTest = "cc_library_shared" |
| 40 | (&tc).ModuleTypeUnderTestFactory = cc.LibrarySharedFactory |
| 41 | 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] | 42 | } |
| 43 | |
| 44 | func TestCcLibrarySharedSimple(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 45 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 46 | Description: "cc_library_shared simple overall test", |
| 47 | 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] | 48 | // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?) |
| 49 | "include_dir_1/include_dir_1_a.h": "", |
| 50 | "include_dir_1/include_dir_1_b.h": "", |
| 51 | "include_dir_2/include_dir_2_a.h": "", |
| 52 | "include_dir_2/include_dir_2_b.h": "", |
| 53 | // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?) |
| 54 | "local_include_dir_1/local_include_dir_1_a.h": "", |
| 55 | "local_include_dir_1/local_include_dir_1_b.h": "", |
| 56 | "local_include_dir_2/local_include_dir_2_a.h": "", |
| 57 | "local_include_dir_2/local_include_dir_2_b.h": "", |
| 58 | // NOTE: export_include_dir headers *should* appear in Bazel hdrs later |
| 59 | "export_include_dir_1/export_include_dir_1_a.h": "", |
| 60 | "export_include_dir_1/export_include_dir_1_b.h": "", |
| 61 | "export_include_dir_2/export_include_dir_2_a.h": "", |
| 62 | "export_include_dir_2/export_include_dir_2_b.h": "", |
| 63 | // NOTE: Soong implicitly includes headers in the current directory |
| 64 | "implicit_include_1.h": "", |
| 65 | "implicit_include_2.h": "", |
| 66 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 67 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 68 | cc_library_headers { |
| 69 | name: "header_lib_1", |
| 70 | export_include_dirs: ["header_lib_1"], |
| 71 | bazel_module: { bp2build_available: false }, |
| 72 | } |
| 73 | |
| 74 | cc_library_headers { |
| 75 | name: "header_lib_2", |
| 76 | export_include_dirs: ["header_lib_2"], |
| 77 | bazel_module: { bp2build_available: false }, |
| 78 | } |
| 79 | |
| 80 | cc_library_shared { |
| 81 | name: "shared_lib_1", |
| 82 | srcs: ["shared_lib_1.cc"], |
| 83 | bazel_module: { bp2build_available: false }, |
| 84 | } |
| 85 | |
| 86 | cc_library_shared { |
| 87 | name: "shared_lib_2", |
| 88 | srcs: ["shared_lib_2.cc"], |
| 89 | bazel_module: { bp2build_available: false }, |
| 90 | } |
| 91 | |
| 92 | cc_library_static { |
| 93 | name: "whole_static_lib_1", |
| 94 | srcs: ["whole_static_lib_1.cc"], |
| 95 | bazel_module: { bp2build_available: false }, |
| 96 | } |
| 97 | |
| 98 | cc_library_static { |
| 99 | name: "whole_static_lib_2", |
| 100 | srcs: ["whole_static_lib_2.cc"], |
| 101 | bazel_module: { bp2build_available: false }, |
| 102 | } |
| 103 | |
| 104 | cc_library_shared { |
| 105 | name: "foo_shared", |
| 106 | srcs: [ |
| 107 | "foo_shared1.cc", |
| 108 | "foo_shared2.cc", |
| 109 | ], |
| 110 | cflags: [ |
| 111 | "-Dflag1", |
| 112 | "-Dflag2" |
| 113 | ], |
| 114 | shared_libs: [ |
| 115 | "shared_lib_1", |
| 116 | "shared_lib_2" |
| 117 | ], |
| 118 | whole_static_libs: [ |
| 119 | "whole_static_lib_1", |
| 120 | "whole_static_lib_2" |
| 121 | ], |
| 122 | include_dirs: [ |
| 123 | "include_dir_1", |
| 124 | "include_dir_2", |
| 125 | ], |
| 126 | local_include_dirs: [ |
| 127 | "local_include_dir_1", |
| 128 | "local_include_dir_2", |
| 129 | ], |
| 130 | export_include_dirs: [ |
| 131 | "export_include_dir_1", |
| 132 | "export_include_dir_2" |
| 133 | ], |
| 134 | header_libs: [ |
| 135 | "header_lib_1", |
| 136 | "header_lib_2" |
| 137 | ], |
Yu Liu | fc60316 | 2022-03-01 15:44:08 -0800 | [diff] [blame] | 138 | sdk_version: "current", |
| 139 | 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] | 140 | |
| 141 | // TODO: Also support export_header_lib_headers |
| 142 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 143 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 144 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 145 | "absolute_includes": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 146 | "include_dir_1", |
| 147 | "include_dir_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 148 | ]`, |
| 149 | "copts": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 150 | "-Dflag1", |
| 151 | "-Dflag2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 152 | ]`, |
| 153 | "export_includes": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 154 | "export_include_dir_1", |
| 155 | "export_include_dir_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 156 | ]`, |
| 157 | "implementation_deps": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 158 | ":header_lib_1", |
| 159 | ":header_lib_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 160 | ]`, |
| 161 | "implementation_dynamic_deps": `[ |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 162 | ":shared_lib_1", |
| 163 | ":shared_lib_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 164 | ]`, |
| 165 | "local_includes": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 166 | "local_include_dir_1", |
| 167 | "local_include_dir_2", |
| 168 | ".", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 169 | ]`, |
| 170 | "srcs": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 171 | "foo_shared1.cc", |
| 172 | "foo_shared2.cc", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 173 | ]`, |
| 174 | "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] | 175 | ":whole_static_lib_1", |
| 176 | ":whole_static_lib_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 177 | ]`, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 126bd58 | 2022-04-21 15:19:27 +0000 | [diff] [blame] | 178 | "sdk_version": `"current"`, |
| 179 | "min_sdk_version": `"29"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 180 | }), |
| 181 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 182 | }) |
| 183 | } |
| 184 | |
| 185 | func TestCcLibrarySharedArchSpecificSharedLib(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 186 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 187 | Description: "cc_library_shared arch-specific shared_libs with whole_static_libs", |
| 188 | Filesystem: map[string]string{}, |
| 189 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 190 | cc_library_static { |
| 191 | name: "static_dep", |
| 192 | bazel_module: { bp2build_available: false }, |
| 193 | } |
| 194 | cc_library_shared { |
| 195 | name: "shared_dep", |
| 196 | bazel_module: { bp2build_available: false }, |
| 197 | } |
| 198 | cc_library_shared { |
| 199 | name: "foo_shared", |
| 200 | arch: { arm64: { shared_libs: ["shared_dep"], whole_static_libs: ["static_dep"] } }, |
| 201 | include_build_directory: false, |
| 202 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 203 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 204 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 205 | "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] | 206 | "//build/bazel/platforms/arch:arm64": [":shared_dep"], |
| 207 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 208 | })`, |
| 209 | "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] | 210 | "//build/bazel/platforms/arch:arm64": [":static_dep"], |
| 211 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 212 | })`, |
| 213 | }), |
| 214 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 215 | }) |
| 216 | } |
| 217 | |
| 218 | func TestCcLibrarySharedOsSpecificSharedLib(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 219 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 220 | Description: "cc_library_shared os-specific shared_libs", |
| 221 | Filesystem: map[string]string{}, |
| 222 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 223 | cc_library_shared { |
| 224 | name: "shared_dep", |
| 225 | bazel_module: { bp2build_available: false }, |
| 226 | } |
| 227 | cc_library_shared { |
| 228 | name: "foo_shared", |
| 229 | target: { android: { shared_libs: ["shared_dep"], } }, |
| 230 | include_build_directory: false, |
| 231 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 232 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 233 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 234 | "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] | 235 | "//build/bazel/platforms/os:android": [":shared_dep"], |
| 236 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 237 | })`, |
| 238 | }), |
| 239 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 240 | }) |
| 241 | } |
| 242 | |
| 243 | func TestCcLibrarySharedBaseArchOsSpecificSharedLib(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 244 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 245 | Description: "cc_library_shared base, arch, and os-specific shared_libs", |
| 246 | Filesystem: map[string]string{}, |
| 247 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 248 | cc_library_shared { |
| 249 | name: "shared_dep", |
| 250 | bazel_module: { bp2build_available: false }, |
| 251 | } |
| 252 | cc_library_shared { |
| 253 | name: "shared_dep2", |
| 254 | bazel_module: { bp2build_available: false }, |
| 255 | } |
| 256 | cc_library_shared { |
| 257 | name: "shared_dep3", |
| 258 | bazel_module: { bp2build_available: false }, |
| 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 | ]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 364 | }), |
| 365 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 366 | }) |
| 367 | } |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 368 | |
Trevor Radcliffe | ea6a45d | 2022-09-20 18:58:01 +0000 | [diff] [blame] | 369 | func TestCcLibraryLdflagsSplitBySpaceSoongAdded(t *testing.T) { |
| 370 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 371 | Description: "ldflags are split by spaces except for the ones added by soong (version script and dynamic list)", |
| 372 | Filesystem: map[string]string{ |
| 373 | "version_script": "", |
| 374 | "dynamic.list": "", |
| 375 | }, |
| 376 | Blueprint: ` |
| 377 | cc_library_shared { |
| 378 | name: "foo", |
| 379 | ldflags: [ |
| 380 | "--nospace_flag", |
| 381 | "-z spaceflag", |
| 382 | ], |
| 383 | version_script: "version_script", |
| 384 | dynamic_list: "dynamic.list", |
| 385 | include_build_directory: false, |
| 386 | }`, |
| 387 | ExpectedBazelTargets: []string{ |
| 388 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 389 | "additional_linker_inputs": `[ |
| 390 | "version_script", |
| 391 | "dynamic.list", |
| 392 | ]`, |
| 393 | "linkopts": `[ |
| 394 | "--nospace_flag", |
| 395 | "-z", |
| 396 | "spaceflag", |
| 397 | "-Wl,--version-script,$(location version_script)", |
| 398 | "-Wl,--dynamic-list,$(location dynamic.list)", |
| 399 | ]`, |
| 400 | }), |
| 401 | }, |
| 402 | }) |
| 403 | } |
| 404 | |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 405 | func TestCcLibrarySharedNoCrtTrue(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 406 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 407 | Description: "cc_library_shared - nocrt: true disables feature", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 408 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 409 | "impl.cpp": "", |
| 410 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 411 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 412 | cc_library_shared { |
| 413 | name: "foo_shared", |
| 414 | srcs: ["impl.cpp"], |
| 415 | nocrt: true, |
| 416 | include_build_directory: false, |
| 417 | } |
| 418 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 419 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 420 | 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] | 421 | "features": `["-link_crt"]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 422 | "srcs": `["impl.cpp"]`, |
| 423 | }), |
| 424 | }, |
| 425 | }) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | func TestCcLibrarySharedNoCrtFalse(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 429 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 430 | Description: "cc_library_shared - nocrt: false doesn't disable feature", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 431 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 432 | "impl.cpp": "", |
| 433 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 434 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 435 | cc_library_shared { |
| 436 | name: "foo_shared", |
| 437 | srcs: ["impl.cpp"], |
| 438 | nocrt: false, |
| 439 | include_build_directory: false, |
| 440 | } |
| 441 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 442 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 443 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 444 | "srcs": `["impl.cpp"]`, |
| 445 | }), |
| 446 | }, |
| 447 | }) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | func TestCcLibrarySharedNoCrtArchVariant(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 451 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 452 | Description: "cc_library_shared - nocrt in select", |
| 453 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 454 | "impl.cpp": "", |
| 455 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 456 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 457 | cc_library_shared { |
| 458 | name: "foo_shared", |
| 459 | srcs: ["impl.cpp"], |
| 460 | arch: { |
| 461 | arm: { |
| 462 | nocrt: true, |
| 463 | }, |
| 464 | x86: { |
| 465 | nocrt: false, |
| 466 | }, |
| 467 | }, |
| 468 | include_build_directory: false, |
| 469 | } |
| 470 | `, |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 471 | ExpectedBazelTargets: []string{ |
| 472 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
| 473 | "features": `select({ |
| 474 | "//build/bazel/platforms/arch:arm": ["-link_crt"], |
| 475 | "//conditions:default": [], |
| 476 | })`, |
| 477 | "srcs": `["impl.cpp"]`, |
| 478 | }), |
| 479 | }, |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 480 | }) |
| 481 | } |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 482 | |
| 483 | func TestCcLibrarySharedProto(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 484 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 485 | Blueprint: soongCcProtoPreamble + `cc_library_shared { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 486 | name: "foo", |
| 487 | srcs: ["foo.proto"], |
| 488 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 489 | export_proto_headers: true, |
| 490 | }, |
| 491 | include_build_directory: false, |
| 492 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 493 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 494 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 495 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 496 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 497 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 498 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 499 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 500 | "whole_archive_deps": `[":foo_cc_proto_lite"]`, |
| 501 | }), |
| 502 | }, |
| 503 | }) |
| 504 | } |
Rupert Shuttleworth | 484aa25 | 2021-12-10 07:22:53 -0500 | [diff] [blame] | 505 | |
| 506 | func TestCcLibrarySharedUseVersionLib(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 507 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 508 | Filesystem: map[string]string{ |
| 509 | soongCcVersionLibBpPath: soongCcVersionLibBp, |
| 510 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 511 | Blueprint: soongCcProtoPreamble + `cc_library_shared { |
Rupert Shuttleworth | 484aa25 | 2021-12-10 07:22:53 -0500 | [diff] [blame] | 512 | name: "foo", |
| 513 | use_version_lib: true, |
| 514 | include_build_directory: false, |
| 515 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 516 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 517 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 518 | "use_version_lib": "True", |
| 519 | "implementation_whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`, |
Rupert Shuttleworth | 484aa25 | 2021-12-10 07:22:53 -0500 | [diff] [blame] | 520 | }), |
| 521 | }, |
| 522 | }) |
| 523 | } |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 524 | |
| 525 | func TestCcLibrarySharedStubs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 526 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 527 | Description: "cc_library_shared stubs", |
| 528 | ModuleTypeUnderTest: "cc_library_shared", |
| 529 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 530 | Dir: "foo/bar", |
| 531 | Filesystem: map[string]string{ |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 532 | "foo/bar/Android.bp": ` |
| 533 | cc_library_shared { |
| 534 | name: "a", |
| 535 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 536 | bazel_module: { bp2build_available: true }, |
| 537 | include_build_directory: false, |
| 538 | } |
| 539 | `, |
| 540 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 541 | Blueprint: soongCcLibraryPreamble, |
Trevor Radcliffe | f19d8a7 | 2022-09-20 23:04:39 +0000 | [diff] [blame] | 542 | ExpectedBazelTargets: []string{makeCcStubSuiteTargets("a", AttrNameToString{ |
Sam Delmerico | 5f90649 | 2023-03-15 18:06:18 -0400 | [diff] [blame] | 543 | "soname": `"a.so"`, |
| 544 | "source_library_label": `"//foo/bar:a"`, |
| 545 | "stubs_symbol_file": `"a.map.txt"`, |
Trevor Radcliffe | f19d8a7 | 2022-09-20 23:04:39 +0000 | [diff] [blame] | 546 | "stubs_versions": `[ |
Trevor Radcliffe | 087af54 | 2022-09-16 15:36:10 +0000 | [diff] [blame] | 547 | "28", |
| 548 | "29", |
| 549 | "current", |
| 550 | ]`, |
Trevor Radcliffe | f19d8a7 | 2022-09-20 23:04:39 +0000 | [diff] [blame] | 551 | }), |
| 552 | MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
Yu Liu | 56ccb1a | 2022-11-12 10:47:07 -0800 | [diff] [blame] | 553 | "stubs_symbol_file": `"a.map.txt"`, |
Trevor Radcliffe | 087af54 | 2022-09-16 15:36:10 +0000 | [diff] [blame] | 554 | }), |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 555 | }, |
Trevor Radcliffe | f19d8a7 | 2022-09-20 23:04:39 +0000 | [diff] [blame] | 556 | }) |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 557 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 126bd58 | 2022-04-21 15:19:27 +0000 | [diff] [blame] | 558 | |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 559 | func TestCcLibrarySharedStubs_UseImplementationInSameApex(t *testing.T) { |
| 560 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 561 | Description: "cc_library_shared stubs", |
| 562 | ModuleTypeUnderTest: "cc_library_shared", |
| 563 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 564 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 565 | cc_library_shared { |
| 566 | name: "a", |
| 567 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 568 | bazel_module: { bp2build_available: false }, |
| 569 | include_build_directory: false, |
| 570 | apex_available: ["made_up_apex"], |
| 571 | } |
| 572 | cc_library_shared { |
| 573 | name: "b", |
| 574 | shared_libs: [":a"], |
| 575 | include_build_directory: false, |
| 576 | apex_available: ["made_up_apex"], |
| 577 | } |
| 578 | `, |
| 579 | ExpectedBazelTargets: []string{ |
| 580 | MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ |
| 581 | "implementation_dynamic_deps": `[":a"]`, |
| 582 | "tags": `["apex_available=made_up_apex"]`, |
| 583 | }), |
| 584 | }, |
| 585 | }) |
| 586 | } |
| 587 | |
| 588 | func TestCcLibrarySharedStubs_UseStubsInDifferentApex(t *testing.T) { |
| 589 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 590 | Description: "cc_library_shared stubs", |
| 591 | ModuleTypeUnderTest: "cc_library_shared", |
| 592 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 593 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 594 | cc_library_shared { |
| 595 | name: "a", |
| 596 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 597 | bazel_module: { bp2build_available: false }, |
| 598 | include_build_directory: false, |
| 599 | apex_available: ["apex_a"], |
| 600 | } |
| 601 | cc_library_shared { |
| 602 | name: "b", |
| 603 | shared_libs: [":a"], |
| 604 | include_build_directory: false, |
| 605 | apex_available: ["apex_b"], |
| 606 | } |
| 607 | `, |
| 608 | ExpectedBazelTargets: []string{ |
| 609 | MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ |
| 610 | "implementation_dynamic_deps": `select({ |
| 611 | "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:a"], |
| 612 | "//conditions:default": [":a"], |
| 613 | })`, |
| 614 | "tags": `["apex_available=apex_b"]`, |
| 615 | }), |
| 616 | }, |
| 617 | }) |
| 618 | } |
| 619 | |
| 620 | func TestCcLibrarySharedStubs_IgnorePlatformAvailable(t *testing.T) { |
| 621 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 622 | Description: "cc_library_shared stubs", |
| 623 | ModuleTypeUnderTest: "cc_library_shared", |
| 624 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 625 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 626 | cc_library_shared { |
| 627 | name: "a", |
| 628 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 629 | bazel_module: { bp2build_available: false }, |
| 630 | include_build_directory: false, |
| 631 | apex_available: ["//apex_available:platform", "apex_a"], |
| 632 | } |
| 633 | cc_library_shared { |
| 634 | name: "b", |
| 635 | shared_libs: [":a"], |
| 636 | include_build_directory: false, |
| 637 | apex_available: ["//apex_available:platform", "apex_b"], |
| 638 | } |
| 639 | `, |
| 640 | ExpectedBazelTargets: []string{ |
| 641 | MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ |
| 642 | "implementation_dynamic_deps": `select({ |
| 643 | "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:a"], |
| 644 | "//conditions:default": [":a"], |
| 645 | })`, |
| 646 | "tags": `[ |
| 647 | "apex_available=//apex_available:platform", |
| 648 | "apex_available=apex_b", |
| 649 | ]`, |
| 650 | }), |
| 651 | }, |
| 652 | }) |
| 653 | } |
| 654 | |
| 655 | func TestCcLibrarySharedStubs_MultipleApexAvailable(t *testing.T) { |
| 656 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 657 | ModuleTypeUnderTest: "cc_library_shared", |
| 658 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 659 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 660 | cc_library_shared { |
| 661 | name: "a", |
| 662 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 663 | bazel_module: { bp2build_available: false }, |
| 664 | include_build_directory: false, |
| 665 | apex_available: ["//apex_available:platform", "apex_a", "apex_b"], |
| 666 | } |
| 667 | cc_library_shared { |
| 668 | name: "b", |
| 669 | shared_libs: [":a"], |
| 670 | include_build_directory: false, |
| 671 | apex_available: ["//apex_available:platform", "apex_b"], |
| 672 | } |
| 673 | |
| 674 | cc_library_shared { |
| 675 | name: "c", |
| 676 | shared_libs: [":a"], |
| 677 | include_build_directory: false, |
| 678 | apex_available: ["//apex_available:platform", "apex_a", "apex_b"], |
| 679 | } |
| 680 | `, |
| 681 | ExpectedBazelTargets: []string{ |
| 682 | MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ |
| 683 | "implementation_dynamic_deps": `select({ |
| 684 | "//build/bazel/rules/apex:android-in_apex": ["@api_surfaces//module-libapi/current:a"], |
| 685 | "//conditions:default": [":a"], |
| 686 | })`, |
| 687 | "tags": `[ |
| 688 | "apex_available=//apex_available:platform", |
| 689 | "apex_available=apex_b", |
| 690 | ]`, |
| 691 | }), |
| 692 | MakeBazelTarget("cc_library_shared", "c", AttrNameToString{ |
| 693 | "implementation_dynamic_deps": `[":a"]`, |
| 694 | "tags": `[ |
| 695 | "apex_available=//apex_available:platform", |
| 696 | "apex_available=apex_a", |
| 697 | "apex_available=apex_b", |
| 698 | ]`, |
| 699 | }), |
| 700 | }, |
| 701 | }) |
| 702 | } |
| 703 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 126bd58 | 2022-04-21 15:19:27 +0000 | [diff] [blame] | 704 | func TestCcLibrarySharedSystemSharedLibsSharedEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 705 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 706 | Description: "cc_library_shared system_shared_libs empty shared default", |
| 707 | ModuleTypeUnderTest: "cc_library_shared", |
| 708 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 709 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 126bd58 | 2022-04-21 15:19:27 +0000 | [diff] [blame] | 710 | cc_defaults { |
| 711 | name: "empty_defaults", |
| 712 | shared: { |
| 713 | system_shared_libs: [], |
| 714 | }, |
| 715 | include_build_directory: false, |
| 716 | } |
| 717 | cc_library_shared { |
| 718 | name: "empty", |
| 719 | defaults: ["empty_defaults"], |
| 720 | } |
| 721 | `, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 722 | 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] | 723 | "system_dynamic_deps": "[]", |
| 724 | })}, |
| 725 | }) |
| 726 | } |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 727 | |
| 728 | func TestCcLibrarySharedConvertLex(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 729 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 730 | Description: "cc_library_shared with lex files", |
| 731 | ModuleTypeUnderTest: "cc_library_shared", |
| 732 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 733 | Filesystem: map[string]string{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 734 | "foo.c": "", |
| 735 | "bar.cc": "", |
| 736 | "foo1.l": "", |
| 737 | "bar1.ll": "", |
| 738 | "foo2.l": "", |
| 739 | "bar2.ll": "", |
| 740 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 741 | Blueprint: `cc_library_shared { |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 742 | name: "foo_lib", |
| 743 | srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"], |
| 744 | lex: { flags: ["--foo_flags"] }, |
| 745 | include_build_directory: false, |
| 746 | bazel_module: { bp2build_available: true }, |
| 747 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 748 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 749 | MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 750 | "srcs": `[ |
| 751 | "foo1.l", |
| 752 | "foo2.l", |
| 753 | ]`, |
| 754 | "lexopts": `["--foo_flags"]`, |
| 755 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 756 | MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 757 | "srcs": `[ |
| 758 | "bar1.ll", |
| 759 | "bar2.ll", |
| 760 | ]`, |
| 761 | "lexopts": `["--foo_flags"]`, |
| 762 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 763 | MakeBazelTarget("cc_library_shared", "foo_lib", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 764 | "srcs": `[ |
| 765 | "bar.cc", |
| 766 | ":foo_lib_genlex_ll", |
| 767 | ]`, |
| 768 | "srcs_c": `[ |
| 769 | "foo.c", |
| 770 | ":foo_lib_genlex_l", |
| 771 | ]`, |
| 772 | }), |
| 773 | }, |
| 774 | }) |
| 775 | } |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 776 | |
| 777 | func TestCcLibrarySharedClangUnknownFlags(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 778 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 779 | Blueprint: soongCcProtoPreamble + `cc_library_shared { |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 780 | name: "foo", |
| 781 | conlyflags: ["-a", "-finline-functions"], |
| 782 | cflags: ["-b","-finline-functions"], |
| 783 | cppflags: ["-c", "-finline-functions"], |
| 784 | ldflags: ["-d","-finline-functions", "-e"], |
| 785 | include_build_directory: false, |
| 786 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 787 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 788 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 789 | "conlyflags": `["-a"]`, |
| 790 | "copts": `["-b"]`, |
| 791 | "cppflags": `["-c"]`, |
| 792 | "linkopts": `[ |
| 793 | "-d", |
| 794 | "-e", |
| 795 | ]`, |
| 796 | }), |
| 797 | }, |
| 798 | }) |
| 799 | } |
| 800 | |
| 801 | func TestCCLibraryFlagSpaceSplitting(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 802 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 803 | Blueprint: soongCcProtoPreamble + `cc_library_shared { |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 804 | name: "foo", |
| 805 | conlyflags: [ "-include header.h"], |
| 806 | cflags: ["-include header.h"], |
| 807 | cppflags: ["-include header.h"], |
| 808 | version_script: "version_script", |
| 809 | include_build_directory: false, |
| 810 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 811 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 812 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 813 | "additional_linker_inputs": `["version_script"]`, |
| 814 | "conlyflags": `[ |
| 815 | "-include", |
| 816 | "header.h", |
| 817 | ]`, |
| 818 | "copts": `[ |
| 819 | "-include", |
| 820 | "header.h", |
| 821 | ]`, |
| 822 | "cppflags": `[ |
| 823 | "-include", |
| 824 | "header.h", |
| 825 | ]`, |
| 826 | "linkopts": `["-Wl,--version-script,$(location version_script)"]`, |
| 827 | }), |
| 828 | }, |
| 829 | }) |
| 830 | } |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 831 | |
| 832 | func TestCCLibrarySharedRuntimeDeps(t *testing.T) { |
| 833 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 834 | Blueprint: `cc_library_shared { |
| 835 | name: "bar", |
| 836 | } |
| 837 | |
| 838 | cc_library_shared { |
| 839 | name: "foo", |
| 840 | runtime_libs: ["foo"], |
| 841 | }`, |
| 842 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 843 | MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{ |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 844 | "local_includes": `["."]`, |
| 845 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 846 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 847 | "runtime_deps": `[":foo"]`, |
| 848 | "local_includes": `["."]`, |
| 849 | }), |
| 850 | }, |
| 851 | }) |
| 852 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 853 | |
| 854 | func TestCcLibrarySharedEmptySuffix(t *testing.T) { |
| 855 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 856 | Description: "cc_library_shared with empty suffix", |
| 857 | Filesystem: map[string]string{ |
| 858 | "foo.c": "", |
| 859 | }, |
| 860 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 861 | cc_library_shared { |
| 862 | name: "foo_shared", |
| 863 | suffix: "", |
| 864 | srcs: ["foo.c"], |
| 865 | include_build_directory: false, |
| 866 | }`, |
| 867 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 868 | 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] | 869 | "srcs_c": `["foo.c"]`, |
| 870 | "suffix": `""`, |
| 871 | }), |
| 872 | }, |
| 873 | }) |
| 874 | } |
| 875 | |
| 876 | func TestCcLibrarySharedSuffix(t *testing.T) { |
| 877 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 878 | Description: "cc_library_shared with suffix", |
| 879 | Filesystem: map[string]string{ |
| 880 | "foo.c": "", |
| 881 | }, |
| 882 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 883 | cc_library_shared { |
| 884 | name: "foo_shared", |
| 885 | suffix: "-suf", |
| 886 | srcs: ["foo.c"], |
| 887 | include_build_directory: false, |
| 888 | }`, |
| 889 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 890 | 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] | 891 | "srcs_c": `["foo.c"]`, |
| 892 | "suffix": `"-suf"`, |
| 893 | }), |
| 894 | }, |
| 895 | }) |
| 896 | } |
| 897 | |
| 898 | func TestCcLibrarySharedArchVariantSuffix(t *testing.T) { |
| 899 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 900 | Description: "cc_library_shared with arch-variant suffix", |
| 901 | Filesystem: map[string]string{ |
| 902 | "foo.c": "", |
| 903 | }, |
| 904 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 905 | cc_library_shared { |
| 906 | name: "foo_shared", |
| 907 | arch: { |
| 908 | arm64: { suffix: "-64" }, |
| 909 | arm: { suffix: "-32" }, |
| 910 | }, |
| 911 | srcs: ["foo.c"], |
| 912 | include_build_directory: false, |
| 913 | }`, |
| 914 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 915 | 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] | 916 | "srcs_c": `["foo.c"]`, |
| 917 | "suffix": `select({ |
| 918 | "//build/bazel/platforms/arch:arm": "-32", |
| 919 | "//build/bazel/platforms/arch:arm64": "-64", |
| 920 | "//conditions:default": None, |
| 921 | })`, |
| 922 | }), |
| 923 | }, |
| 924 | }) |
| 925 | } |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 926 | |
| 927 | func TestCcLibrarySharedWithSyspropSrcs(t *testing.T) { |
| 928 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 929 | Description: "cc_library_shared with sysprop sources", |
| 930 | Blueprint: ` |
| 931 | cc_library_shared { |
| 932 | name: "foo", |
| 933 | srcs: [ |
| 934 | "bar.sysprop", |
| 935 | "baz.sysprop", |
| 936 | "blah.cpp", |
| 937 | ], |
| 938 | min_sdk_version: "5", |
| 939 | }`, |
| 940 | ExpectedBazelTargets: []string{ |
| 941 | MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{ |
| 942 | "srcs": `[ |
| 943 | "bar.sysprop", |
| 944 | "baz.sysprop", |
| 945 | ]`, |
| 946 | }), |
| 947 | MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{ |
| 948 | "dep": `":foo_sysprop_library"`, |
| 949 | "min_sdk_version": `"5"`, |
| 950 | }), |
| 951 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 952 | "srcs": `["blah.cpp"]`, |
| 953 | "local_includes": `["."]`, |
| 954 | "min_sdk_version": `"5"`, |
| 955 | "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`, |
| 956 | }), |
| 957 | }, |
| 958 | }) |
| 959 | } |
| 960 | |
| 961 | func TestCcLibrarySharedWithSyspropSrcsSomeConfigs(t *testing.T) { |
| 962 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 963 | Description: "cc_library_shared with sysprop sources in some configs but not others", |
| 964 | Blueprint: ` |
| 965 | cc_library_shared { |
| 966 | name: "foo", |
| 967 | srcs: [ |
| 968 | "blah.cpp", |
| 969 | ], |
| 970 | target: { |
| 971 | android: { |
| 972 | srcs: ["bar.sysprop"], |
| 973 | }, |
| 974 | }, |
| 975 | min_sdk_version: "5", |
| 976 | }`, |
| 977 | ExpectedBazelTargets: []string{ |
| 978 | MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{ |
| 979 | "srcs": `select({ |
| 980 | "//build/bazel/platforms/os:android": ["bar.sysprop"], |
| 981 | "//conditions:default": [], |
| 982 | })`, |
| 983 | }), |
| 984 | MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{ |
| 985 | "dep": `":foo_sysprop_library"`, |
| 986 | "min_sdk_version": `"5"`, |
| 987 | }), |
| 988 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 989 | "srcs": `["blah.cpp"]`, |
| 990 | "local_includes": `["."]`, |
| 991 | "min_sdk_version": `"5"`, |
| 992 | "whole_archive_deps": `select({ |
| 993 | "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"], |
| 994 | "//conditions:default": [], |
| 995 | })`, |
| 996 | }), |
| 997 | }, |
| 998 | }) |
| 999 | } |
Yu Liu | 56ccb1a | 2022-11-12 10:47:07 -0800 | [diff] [blame] | 1000 | |
| 1001 | func TestCcLibrarySharedHeaderAbiChecker(t *testing.T) { |
| 1002 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1003 | Description: "cc_library_shared with header abi checker", |
| 1004 | Blueprint: `cc_library_shared { |
| 1005 | name: "foo", |
| 1006 | header_abi_checker: { |
| 1007 | enabled: true, |
| 1008 | symbol_file: "a.map.txt", |
| 1009 | exclude_symbol_versions: [ |
| 1010 | "29", |
| 1011 | "30", |
| 1012 | ], |
| 1013 | exclude_symbol_tags: [ |
| 1014 | "tag1", |
| 1015 | "tag2", |
| 1016 | ], |
| 1017 | check_all_apis: true, |
| 1018 | diff_flags: ["-allow-adding-removing-weak-symbols"], |
| 1019 | }, |
| 1020 | include_build_directory: false, |
| 1021 | }`, |
| 1022 | ExpectedBazelTargets: []string{ |
| 1023 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1024 | "abi_checker_enabled": `True`, |
| 1025 | "abi_checker_symbol_file": `"a.map.txt"`, |
| 1026 | "abi_checker_exclude_symbol_versions": `[ |
| 1027 | "29", |
| 1028 | "30", |
| 1029 | ]`, |
| 1030 | "abi_checker_exclude_symbol_tags": `[ |
| 1031 | "tag1", |
| 1032 | "tag2", |
| 1033 | ]`, |
| 1034 | "abi_checker_check_all_apis": `True`, |
| 1035 | "abi_checker_diff_flags": `["-allow-adding-removing-weak-symbols"]`, |
| 1036 | }), |
| 1037 | }, |
| 1038 | }) |
| 1039 | } |
Trevor Radcliffe | db7e026 | 2022-10-28 16:48:18 +0000 | [diff] [blame] | 1040 | |
| 1041 | func TestCcLibrarySharedWithIntegerOverflowProperty(t *testing.T) { |
| 1042 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1043 | Description: "cc_library_shared has correct features when integer_overflow property is provided", |
| 1044 | Blueprint: ` |
| 1045 | cc_library_shared { |
| 1046 | name: "foo", |
| 1047 | sanitize: { |
| 1048 | integer_overflow: true, |
| 1049 | }, |
| 1050 | } |
| 1051 | `, |
| 1052 | ExpectedBazelTargets: []string{ |
| 1053 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1054 | "features": `["ubsan_integer_overflow"]`, |
| 1055 | "local_includes": `["."]`, |
| 1056 | }), |
| 1057 | }, |
| 1058 | }) |
| 1059 | } |
| 1060 | |
| 1061 | func TestCcLibrarySharedWithMiscUndefinedProperty(t *testing.T) { |
| 1062 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1063 | Description: "cc_library_shared has correct features when misc_undefined property is provided", |
| 1064 | Blueprint: ` |
| 1065 | cc_library_shared { |
| 1066 | name: "foo", |
| 1067 | sanitize: { |
| 1068 | misc_undefined: ["undefined", "nullability"], |
| 1069 | }, |
| 1070 | } |
| 1071 | `, |
| 1072 | ExpectedBazelTargets: []string{ |
| 1073 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1074 | "features": `[ |
| 1075 | "ubsan_undefined", |
| 1076 | "ubsan_nullability", |
| 1077 | ]`, |
| 1078 | "local_includes": `["."]`, |
| 1079 | }), |
| 1080 | }, |
| 1081 | }) |
| 1082 | } |
| 1083 | |
| 1084 | func TestCcLibrarySharedWithUBSanPropertiesArchSpecific(t *testing.T) { |
| 1085 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1086 | Description: "cc_library_shared has correct feature select when UBSan props are specified in arch specific blocks", |
| 1087 | Blueprint: ` |
| 1088 | cc_library_shared { |
| 1089 | name: "foo", |
| 1090 | sanitize: { |
| 1091 | misc_undefined: ["undefined", "nullability"], |
| 1092 | }, |
| 1093 | target: { |
| 1094 | android: { |
| 1095 | sanitize: { |
| 1096 | misc_undefined: ["alignment"], |
| 1097 | }, |
| 1098 | }, |
| 1099 | linux_glibc: { |
| 1100 | sanitize: { |
| 1101 | integer_overflow: true, |
| 1102 | }, |
| 1103 | }, |
| 1104 | }, |
| 1105 | } |
| 1106 | `, |
| 1107 | ExpectedBazelTargets: []string{ |
| 1108 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1109 | "features": `[ |
| 1110 | "ubsan_undefined", |
| 1111 | "ubsan_nullability", |
| 1112 | ] + select({ |
| 1113 | "//build/bazel/platforms/os:android": ["ubsan_alignment"], |
| 1114 | "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"], |
| 1115 | "//conditions:default": [], |
| 1116 | })`, |
| 1117 | "local_includes": `["."]`, |
| 1118 | }), |
| 1119 | }, |
| 1120 | }) |
| 1121 | } |
Trevor Radcliffe | 56b1a2b | 2023-02-06 21:58:30 +0000 | [diff] [blame] | 1122 | |
| 1123 | func TestCcLibrarySharedWithThinLto(t *testing.T) { |
| 1124 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1125 | Description: "cc_library_shared has correct features when thin lto is enabled", |
| 1126 | Blueprint: ` |
| 1127 | cc_library_shared { |
| 1128 | name: "foo", |
| 1129 | lto: { |
| 1130 | thin: true, |
| 1131 | }, |
| 1132 | } |
| 1133 | `, |
| 1134 | ExpectedBazelTargets: []string{ |
| 1135 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1136 | "features": `["android_thin_lto"]`, |
| 1137 | "local_includes": `["."]`, |
| 1138 | }), |
| 1139 | }, |
| 1140 | }) |
| 1141 | } |
| 1142 | |
| 1143 | func TestCcLibrarySharedWithLtoNever(t *testing.T) { |
| 1144 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1145 | Description: "cc_library_shared has correct features when thin lto is enabled", |
| 1146 | Blueprint: ` |
| 1147 | cc_library_shared { |
| 1148 | name: "foo", |
| 1149 | lto: { |
| 1150 | never: true, |
| 1151 | }, |
| 1152 | } |
| 1153 | `, |
| 1154 | ExpectedBazelTargets: []string{ |
| 1155 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1156 | "features": `["-android_thin_lto"]`, |
| 1157 | "local_includes": `["."]`, |
| 1158 | }), |
| 1159 | }, |
| 1160 | }) |
| 1161 | } |
| 1162 | |
| 1163 | func TestCcLibrarySharedWithThinLtoArchSpecific(t *testing.T) { |
| 1164 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1165 | Description: "cc_library_shared has correct features when LTO differs across arch and os variants", |
| 1166 | Blueprint: ` |
| 1167 | cc_library_shared { |
| 1168 | name: "foo", |
| 1169 | target: { |
| 1170 | android: { |
| 1171 | lto: { |
| 1172 | thin: true, |
| 1173 | }, |
| 1174 | }, |
| 1175 | }, |
| 1176 | arch: { |
| 1177 | riscv64: { |
| 1178 | lto: { |
| 1179 | thin: false, |
| 1180 | }, |
| 1181 | }, |
| 1182 | }, |
| 1183 | }`, |
| 1184 | ExpectedBazelTargets: []string{ |
| 1185 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1186 | "local_includes": `["."]`, |
| 1187 | "features": `select({ |
| 1188 | "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"], |
| 1189 | "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"], |
| 1190 | "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"], |
| 1191 | "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"], |
| 1192 | "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"], |
| 1193 | "//conditions:default": [], |
| 1194 | })`}), |
| 1195 | }, |
| 1196 | }) |
| 1197 | } |
| 1198 | |
| 1199 | func TestCcLibrarySharedWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) { |
| 1200 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1201 | Description: "cc_library_shared with thin lto disabled by default but enabled on a particular variant", |
| 1202 | Blueprint: ` |
| 1203 | cc_library_shared { |
| 1204 | name: "foo", |
| 1205 | lto: { |
| 1206 | never: true, |
| 1207 | }, |
| 1208 | target: { |
| 1209 | android: { |
| 1210 | lto: { |
| 1211 | thin: true, |
| 1212 | never: false, |
| 1213 | }, |
| 1214 | }, |
| 1215 | }, |
| 1216 | }`, |
| 1217 | ExpectedBazelTargets: []string{ |
| 1218 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1219 | "local_includes": `["."]`, |
| 1220 | "features": `select({ |
| 1221 | "//build/bazel/platforms/os:android": ["android_thin_lto"], |
| 1222 | "//conditions:default": ["-android_thin_lto"], |
| 1223 | })`, |
| 1224 | }), |
| 1225 | }, |
| 1226 | }) |
| 1227 | } |
| 1228 | |
| 1229 | func TestCcLibrarySharedWithThinLtoAndWholeProgramVtables(t *testing.T) { |
| 1230 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 1231 | Description: "cc_library_shared has correct features when thin LTO is enabled with whole_program_vtables", |
| 1232 | Blueprint: ` |
| 1233 | cc_library_shared { |
| 1234 | name: "foo", |
| 1235 | lto: { |
| 1236 | thin: true, |
| 1237 | }, |
| 1238 | whole_program_vtables: true, |
| 1239 | } |
| 1240 | `, |
| 1241 | ExpectedBazelTargets: []string{ |
| 1242 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 1243 | "features": `[ |
| 1244 | "android_thin_lto", |
| 1245 | "android_thin_lto_whole_program_vtables", |
| 1246 | ]`, |
| 1247 | "local_includes": `["."]`, |
| 1248 | }), |
| 1249 | }, |
| 1250 | }) |
| 1251 | } |