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 ( |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 18 | "fmt" |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 19 | "testing" |
| 20 | |
| 21 | "android/soong/android" |
| 22 | "android/soong/cc" |
| 23 | ) |
| 24 | |
| 25 | const ( |
| 26 | // See cc/testing.go for more context |
| 27 | // TODO(alexmarquez): Split out the preamble into common code? |
| 28 | soongCcLibrarySharedPreamble = soongCcLibraryStaticPreamble |
| 29 | ) |
| 30 | |
| 31 | func registerCcLibrarySharedModuleTypes(ctx android.RegistrationContext) { |
| 32 | cc.RegisterCCBuildComponents(ctx) |
| 33 | ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) |
| 34 | ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) |
| 35 | ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 36 | 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] | 37 | } |
| 38 | |
| 39 | func runCcLibrarySharedTestCase(t *testing.T, tc bp2buildTestCase) { |
| 40 | t.Helper() |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 41 | (&tc).moduleTypeUnderTest = "cc_library_shared" |
| 42 | (&tc).moduleTypeUnderTestFactory = cc.LibrarySharedFactory |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 43 | runBp2BuildTestCase(t, registerCcLibrarySharedModuleTypes, tc) |
| 44 | } |
| 45 | |
| 46 | func TestCcLibrarySharedSimple(t *testing.T) { |
| 47 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 48 | description: "cc_library_shared simple overall test", |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 49 | filesystem: map[string]string{ |
| 50 | // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?) |
| 51 | "include_dir_1/include_dir_1_a.h": "", |
| 52 | "include_dir_1/include_dir_1_b.h": "", |
| 53 | "include_dir_2/include_dir_2_a.h": "", |
| 54 | "include_dir_2/include_dir_2_b.h": "", |
| 55 | // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?) |
| 56 | "local_include_dir_1/local_include_dir_1_a.h": "", |
| 57 | "local_include_dir_1/local_include_dir_1_b.h": "", |
| 58 | "local_include_dir_2/local_include_dir_2_a.h": "", |
| 59 | "local_include_dir_2/local_include_dir_2_b.h": "", |
| 60 | // NOTE: export_include_dir headers *should* appear in Bazel hdrs later |
| 61 | "export_include_dir_1/export_include_dir_1_a.h": "", |
| 62 | "export_include_dir_1/export_include_dir_1_b.h": "", |
| 63 | "export_include_dir_2/export_include_dir_2_a.h": "", |
| 64 | "export_include_dir_2/export_include_dir_2_b.h": "", |
| 65 | // NOTE: Soong implicitly includes headers in the current directory |
| 66 | "implicit_include_1.h": "", |
| 67 | "implicit_include_2.h": "", |
| 68 | }, |
| 69 | blueprint: soongCcLibrarySharedPreamble + ` |
| 70 | cc_library_headers { |
| 71 | name: "header_lib_1", |
| 72 | export_include_dirs: ["header_lib_1"], |
| 73 | bazel_module: { bp2build_available: false }, |
| 74 | } |
| 75 | |
| 76 | cc_library_headers { |
| 77 | name: "header_lib_2", |
| 78 | export_include_dirs: ["header_lib_2"], |
| 79 | bazel_module: { bp2build_available: false }, |
| 80 | } |
| 81 | |
| 82 | cc_library_shared { |
| 83 | name: "shared_lib_1", |
| 84 | srcs: ["shared_lib_1.cc"], |
| 85 | bazel_module: { bp2build_available: false }, |
| 86 | } |
| 87 | |
| 88 | cc_library_shared { |
| 89 | name: "shared_lib_2", |
| 90 | srcs: ["shared_lib_2.cc"], |
| 91 | bazel_module: { bp2build_available: false }, |
| 92 | } |
| 93 | |
| 94 | cc_library_static { |
| 95 | name: "whole_static_lib_1", |
| 96 | srcs: ["whole_static_lib_1.cc"], |
| 97 | bazel_module: { bp2build_available: false }, |
| 98 | } |
| 99 | |
| 100 | cc_library_static { |
| 101 | name: "whole_static_lib_2", |
| 102 | srcs: ["whole_static_lib_2.cc"], |
| 103 | bazel_module: { bp2build_available: false }, |
| 104 | } |
| 105 | |
| 106 | cc_library_shared { |
| 107 | name: "foo_shared", |
| 108 | srcs: [ |
| 109 | "foo_shared1.cc", |
| 110 | "foo_shared2.cc", |
| 111 | ], |
| 112 | cflags: [ |
| 113 | "-Dflag1", |
| 114 | "-Dflag2" |
| 115 | ], |
| 116 | shared_libs: [ |
| 117 | "shared_lib_1", |
| 118 | "shared_lib_2" |
| 119 | ], |
| 120 | whole_static_libs: [ |
| 121 | "whole_static_lib_1", |
| 122 | "whole_static_lib_2" |
| 123 | ], |
| 124 | include_dirs: [ |
| 125 | "include_dir_1", |
| 126 | "include_dir_2", |
| 127 | ], |
| 128 | local_include_dirs: [ |
| 129 | "local_include_dir_1", |
| 130 | "local_include_dir_2", |
| 131 | ], |
| 132 | export_include_dirs: [ |
| 133 | "export_include_dir_1", |
| 134 | "export_include_dir_2" |
| 135 | ], |
| 136 | header_libs: [ |
| 137 | "header_lib_1", |
| 138 | "header_lib_2" |
| 139 | ], |
| 140 | |
| 141 | // TODO: Also support export_header_lib_headers |
| 142 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 143 | expectedBazelTargets: []string{ |
| 144 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 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 | ]`, |
| 178 | }), |
| 179 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 180 | }) |
| 181 | } |
| 182 | |
| 183 | func TestCcLibrarySharedArchSpecificSharedLib(t *testing.T) { |
| 184 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 185 | description: "cc_library_shared arch-specific shared_libs with whole_static_libs", |
| 186 | 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] | 187 | blueprint: soongCcLibrarySharedPreamble + ` |
| 188 | cc_library_static { |
| 189 | name: "static_dep", |
| 190 | bazel_module: { bp2build_available: false }, |
| 191 | } |
| 192 | cc_library_shared { |
| 193 | name: "shared_dep", |
| 194 | bazel_module: { bp2build_available: false }, |
| 195 | } |
| 196 | cc_library_shared { |
| 197 | name: "foo_shared", |
| 198 | arch: { arm64: { shared_libs: ["shared_dep"], whole_static_libs: ["static_dep"] } }, |
| 199 | include_build_directory: false, |
| 200 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 201 | expectedBazelTargets: []string{ |
| 202 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 203 | "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] | 204 | "//build/bazel/platforms/arch:arm64": [":shared_dep"], |
| 205 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 206 | })`, |
| 207 | "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] | 208 | "//build/bazel/platforms/arch:arm64": [":static_dep"], |
| 209 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 210 | })`, |
| 211 | }), |
| 212 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 213 | }) |
| 214 | } |
| 215 | |
| 216 | func TestCcLibrarySharedOsSpecificSharedLib(t *testing.T) { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 217 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
| 218 | description: "cc_library_shared os-specific shared_libs", |
| 219 | 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] | 220 | blueprint: soongCcLibrarySharedPreamble + ` |
| 221 | cc_library_shared { |
| 222 | name: "shared_dep", |
| 223 | bazel_module: { bp2build_available: false }, |
| 224 | } |
| 225 | cc_library_shared { |
| 226 | name: "foo_shared", |
| 227 | target: { android: { shared_libs: ["shared_dep"], } }, |
| 228 | include_build_directory: false, |
| 229 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 230 | expectedBazelTargets: []string{ |
| 231 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 232 | "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] | 233 | "//build/bazel/platforms/os:android": [":shared_dep"], |
| 234 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 235 | })`, |
| 236 | }), |
| 237 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 238 | }) |
| 239 | } |
| 240 | |
| 241 | func TestCcLibrarySharedBaseArchOsSpecificSharedLib(t *testing.T) { |
| 242 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 243 | description: "cc_library_shared base, arch, and os-specific shared_libs", |
| 244 | 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] | 245 | blueprint: soongCcLibrarySharedPreamble + ` |
| 246 | cc_library_shared { |
| 247 | name: "shared_dep", |
| 248 | bazel_module: { bp2build_available: false }, |
| 249 | } |
| 250 | cc_library_shared { |
| 251 | name: "shared_dep2", |
| 252 | bazel_module: { bp2build_available: false }, |
| 253 | } |
| 254 | cc_library_shared { |
| 255 | name: "shared_dep3", |
| 256 | bazel_module: { bp2build_available: false }, |
| 257 | } |
| 258 | cc_library_shared { |
| 259 | name: "foo_shared", |
| 260 | shared_libs: ["shared_dep"], |
| 261 | target: { android: { shared_libs: ["shared_dep2"] } }, |
| 262 | arch: { arm64: { shared_libs: ["shared_dep3"] } }, |
| 263 | include_build_directory: false, |
| 264 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 265 | expectedBazelTargets: []string{ |
| 266 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 267 | "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] | 268 | "//build/bazel/platforms/arch:arm64": [":shared_dep3"], |
| 269 | "//conditions:default": [], |
| 270 | }) + select({ |
| 271 | "//build/bazel/platforms/os:android": [":shared_dep2"], |
| 272 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 273 | })`, |
| 274 | }), |
| 275 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 276 | }) |
| 277 | } |
| 278 | |
| 279 | func TestCcLibrarySharedSimpleExcludeSrcs(t *testing.T) { |
| 280 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 281 | description: "cc_library_shared simple exclude_srcs", |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 282 | filesystem: map[string]string{ |
| 283 | "common.c": "", |
| 284 | "foo-a.c": "", |
| 285 | "foo-excluded.c": "", |
| 286 | }, |
| 287 | blueprint: soongCcLibrarySharedPreamble + ` |
| 288 | cc_library_shared { |
| 289 | name: "foo_shared", |
| 290 | srcs: ["common.c", "foo-*.c"], |
| 291 | exclude_srcs: ["foo-excluded.c"], |
| 292 | include_build_directory: false, |
| 293 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 294 | expectedBazelTargets: []string{ |
| 295 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 296 | "srcs_c": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 297 | "common.c", |
| 298 | "foo-a.c", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 299 | ]`, |
| 300 | }), |
| 301 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 302 | }) |
| 303 | } |
| 304 | |
| 305 | func TestCcLibrarySharedStrip(t *testing.T) { |
| 306 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 307 | description: "cc_library_shared stripping", |
| 308 | 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] | 309 | blueprint: soongCcLibrarySharedPreamble + ` |
| 310 | cc_library_shared { |
| 311 | name: "foo_shared", |
| 312 | strip: { |
| 313 | keep_symbols: false, |
| 314 | keep_symbols_and_debug_frame: true, |
| 315 | keep_symbols_list: ["sym", "sym2"], |
| 316 | all: true, |
| 317 | none: false, |
| 318 | }, |
| 319 | include_build_directory: false, |
| 320 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 321 | expectedBazelTargets: []string{ |
| 322 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 323 | "strip": `{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 324 | "all": True, |
| 325 | "keep_symbols": False, |
| 326 | "keep_symbols_and_debug_frame": True, |
| 327 | "keep_symbols_list": [ |
| 328 | "sym", |
| 329 | "sym2", |
| 330 | ], |
| 331 | "none": False, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 332 | }`, |
| 333 | }), |
| 334 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 335 | }) |
| 336 | } |
| 337 | |
| 338 | func TestCcLibrarySharedVersionScript(t *testing.T) { |
| 339 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 340 | description: "cc_library_shared version script", |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 341 | filesystem: map[string]string{ |
| 342 | "version_script": "", |
| 343 | }, |
| 344 | blueprint: soongCcLibrarySharedPreamble + ` |
| 345 | cc_library_shared { |
| 346 | name: "foo_shared", |
| 347 | version_script: "version_script", |
| 348 | include_build_directory: false, |
| 349 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 350 | expectedBazelTargets: []string{ |
| 351 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 352 | "additional_linker_inputs": `["version_script"]`, |
| 353 | "linkopts": `["-Wl,--version-script,$(location version_script)"]`, |
| 354 | }), |
| 355 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 356 | }) |
| 357 | } |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 358 | |
| 359 | func TestCcLibrarySharedNoCrtTrue(t *testing.T) { |
| 360 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 361 | description: "cc_library_shared - nocrt: true emits attribute", |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 362 | filesystem: map[string]string{ |
| 363 | "impl.cpp": "", |
| 364 | }, |
| 365 | blueprint: soongCcLibraryPreamble + ` |
| 366 | cc_library_shared { |
| 367 | name: "foo_shared", |
| 368 | srcs: ["impl.cpp"], |
| 369 | nocrt: true, |
| 370 | include_build_directory: false, |
| 371 | } |
| 372 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 373 | expectedBazelTargets: []string{ |
| 374 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 375 | "link_crt": `False`, |
| 376 | "srcs": `["impl.cpp"]`, |
| 377 | }), |
| 378 | }, |
| 379 | }) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | func TestCcLibrarySharedNoCrtFalse(t *testing.T) { |
| 383 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 384 | description: "cc_library_shared - nocrt: false doesn't emit attribute", |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 385 | filesystem: map[string]string{ |
| 386 | "impl.cpp": "", |
| 387 | }, |
| 388 | blueprint: soongCcLibraryPreamble + ` |
| 389 | cc_library_shared { |
| 390 | name: "foo_shared", |
| 391 | srcs: ["impl.cpp"], |
| 392 | nocrt: false, |
| 393 | include_build_directory: false, |
| 394 | } |
| 395 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 396 | expectedBazelTargets: []string{ |
| 397 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 398 | "srcs": `["impl.cpp"]`, |
| 399 | }), |
| 400 | }, |
| 401 | }) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | func TestCcLibrarySharedNoCrtArchVariant(t *testing.T) { |
| 405 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 406 | description: "cc_library_shared - nocrt in select", |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 407 | filesystem: map[string]string{ |
| 408 | "impl.cpp": "", |
| 409 | }, |
| 410 | blueprint: soongCcLibraryPreamble + ` |
| 411 | cc_library_shared { |
| 412 | name: "foo_shared", |
| 413 | srcs: ["impl.cpp"], |
| 414 | arch: { |
| 415 | arm: { |
| 416 | nocrt: true, |
| 417 | }, |
| 418 | x86: { |
| 419 | nocrt: false, |
| 420 | }, |
| 421 | }, |
| 422 | include_build_directory: false, |
| 423 | } |
| 424 | `, |
| 425 | expectedErr: fmt.Errorf("Android.bp:16:1: module \"foo_shared\": nocrt is not supported for arch variants"), |
| 426 | }) |
| 427 | } |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 428 | |
| 429 | func TestCcLibrarySharedProto(t *testing.T) { |
| 430 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
| 431 | blueprint: soongCcProtoPreamble + `cc_library_shared { |
| 432 | name: "foo", |
| 433 | srcs: ["foo.proto"], |
| 434 | proto: { |
| 435 | canonical_path_from_root: false, |
| 436 | export_proto_headers: true, |
| 437 | }, |
| 438 | include_build_directory: false, |
| 439 | }`, |
| 440 | expectedBazelTargets: []string{ |
| 441 | makeBazelTarget("proto_library", "foo_proto", attrNameToString{ |
| 442 | "srcs": `["foo.proto"]`, |
| 443 | }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ |
| 444 | "deps": `[":foo_proto"]`, |
| 445 | }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ |
| 446 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 447 | "whole_archive_deps": `[":foo_cc_proto_lite"]`, |
| 448 | }), |
| 449 | }, |
| 450 | }) |
| 451 | } |
Rupert Shuttleworth | 484aa25 | 2021-12-10 07:22:53 -0500 | [diff] [blame] | 452 | |
| 453 | func TestCcLibrarySharedUseVersionLib(t *testing.T) { |
| 454 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
| 455 | blueprint: soongCcProtoPreamble + `cc_library_shared { |
| 456 | name: "foo", |
| 457 | use_version_lib: true, |
| 458 | include_build_directory: false, |
| 459 | }`, |
| 460 | expectedBazelTargets: []string{ |
| 461 | makeBazelTarget("cc_library_shared", "foo", attrNameToString{ |
| 462 | "use_version_lib": "True", |
| 463 | }), |
| 464 | }, |
| 465 | }) |
| 466 | } |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame^] | 467 | |
| 468 | func TestCcLibrarySharedStubs(t *testing.T) { |
| 469 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
| 470 | description: "cc_library_shared stubs", |
| 471 | moduleTypeUnderTest: "cc_library_shared", |
| 472 | moduleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 473 | dir: "foo/bar", |
| 474 | filesystem: map[string]string{ |
| 475 | "foo/bar/Android.bp": ` |
| 476 | cc_library_shared { |
| 477 | name: "a", |
| 478 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 479 | bazel_module: { bp2build_available: true }, |
| 480 | include_build_directory: false, |
| 481 | } |
| 482 | `, |
| 483 | }, |
| 484 | blueprint: soongCcLibraryPreamble, |
| 485 | expectedBazelTargets: []string{makeBazelTarget("cc_library_shared", "a", attrNameToString{ |
| 486 | "stubs_symbol_file": `"a.map.txt"`, |
| 487 | "stubs_versions": `[ |
| 488 | "28", |
| 489 | "29", |
| 490 | "current", |
| 491 | ]`, |
| 492 | }), |
| 493 | }, |
| 494 | }, |
| 495 | ) |
| 496 | } |