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