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) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 33 | ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) |
| 34 | ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 35 | 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] | 36 | } |
| 37 | |
| 38 | func runCcLibrarySharedTestCase(t *testing.T, tc bp2buildTestCase) { |
| 39 | t.Helper() |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 40 | (&tc).moduleTypeUnderTest = "cc_library_shared" |
| 41 | (&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] | 42 | runBp2BuildTestCase(t, registerCcLibrarySharedModuleTypes, tc) |
| 43 | } |
| 44 | |
| 45 | func TestCcLibrarySharedSimple(t *testing.T) { |
| 46 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 47 | 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] | 48 | filesystem: map[string]string{ |
| 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 | }, |
| 68 | blueprint: soongCcLibrarySharedPreamble + ` |
| 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 | ], |
| 139 | |
| 140 | // TODO: Also support export_header_lib_headers |
| 141 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 142 | expectedBazelTargets: []string{ |
| 143 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 144 | "absolute_includes": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 145 | "include_dir_1", |
| 146 | "include_dir_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 147 | ]`, |
| 148 | "copts": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 149 | "-Dflag1", |
| 150 | "-Dflag2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 151 | ]`, |
| 152 | "export_includes": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 153 | "export_include_dir_1", |
| 154 | "export_include_dir_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 155 | ]`, |
| 156 | "implementation_deps": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 157 | ":header_lib_1", |
| 158 | ":header_lib_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 159 | ]`, |
| 160 | "implementation_dynamic_deps": `[ |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 161 | ":shared_lib_1", |
| 162 | ":shared_lib_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 163 | ]`, |
| 164 | "local_includes": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 165 | "local_include_dir_1", |
| 166 | "local_include_dir_2", |
| 167 | ".", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 168 | ]`, |
| 169 | "srcs": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 170 | "foo_shared1.cc", |
| 171 | "foo_shared2.cc", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 172 | ]`, |
| 173 | "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] | 174 | ":whole_static_lib_1", |
| 175 | ":whole_static_lib_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 176 | ]`, |
| 177 | }), |
| 178 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 179 | }) |
| 180 | } |
| 181 | |
| 182 | func TestCcLibrarySharedArchSpecificSharedLib(t *testing.T) { |
| 183 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 184 | description: "cc_library_shared arch-specific shared_libs with whole_static_libs", |
| 185 | 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] | 186 | blueprint: soongCcLibrarySharedPreamble + ` |
| 187 | cc_library_static { |
| 188 | name: "static_dep", |
| 189 | bazel_module: { bp2build_available: false }, |
| 190 | } |
| 191 | cc_library_shared { |
| 192 | name: "shared_dep", |
| 193 | bazel_module: { bp2build_available: false }, |
| 194 | } |
| 195 | cc_library_shared { |
| 196 | name: "foo_shared", |
| 197 | arch: { arm64: { shared_libs: ["shared_dep"], whole_static_libs: ["static_dep"] } }, |
| 198 | include_build_directory: false, |
| 199 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 200 | expectedBazelTargets: []string{ |
| 201 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 202 | "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] | 203 | "//build/bazel/platforms/arch:arm64": [":shared_dep"], |
| 204 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 205 | })`, |
| 206 | "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] | 207 | "//build/bazel/platforms/arch:arm64": [":static_dep"], |
| 208 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 209 | })`, |
| 210 | }), |
| 211 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 212 | }) |
| 213 | } |
| 214 | |
| 215 | func TestCcLibrarySharedOsSpecificSharedLib(t *testing.T) { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 216 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
| 217 | description: "cc_library_shared os-specific shared_libs", |
| 218 | 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] | 219 | blueprint: soongCcLibrarySharedPreamble + ` |
| 220 | cc_library_shared { |
| 221 | name: "shared_dep", |
| 222 | bazel_module: { bp2build_available: false }, |
| 223 | } |
| 224 | cc_library_shared { |
| 225 | name: "foo_shared", |
| 226 | target: { android: { shared_libs: ["shared_dep"], } }, |
| 227 | include_build_directory: false, |
| 228 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 229 | expectedBazelTargets: []string{ |
| 230 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 231 | "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] | 232 | "//build/bazel/platforms/os:android": [":shared_dep"], |
| 233 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 234 | })`, |
| 235 | }), |
| 236 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 237 | }) |
| 238 | } |
| 239 | |
| 240 | func TestCcLibrarySharedBaseArchOsSpecificSharedLib(t *testing.T) { |
| 241 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 242 | description: "cc_library_shared base, arch, and os-specific shared_libs", |
| 243 | 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] | 244 | blueprint: soongCcLibrarySharedPreamble + ` |
| 245 | cc_library_shared { |
| 246 | name: "shared_dep", |
| 247 | bazel_module: { bp2build_available: false }, |
| 248 | } |
| 249 | cc_library_shared { |
| 250 | name: "shared_dep2", |
| 251 | bazel_module: { bp2build_available: false }, |
| 252 | } |
| 253 | cc_library_shared { |
| 254 | name: "shared_dep3", |
| 255 | bazel_module: { bp2build_available: false }, |
| 256 | } |
| 257 | cc_library_shared { |
| 258 | name: "foo_shared", |
| 259 | shared_libs: ["shared_dep"], |
| 260 | target: { android: { shared_libs: ["shared_dep2"] } }, |
| 261 | arch: { arm64: { shared_libs: ["shared_dep3"] } }, |
| 262 | include_build_directory: false, |
| 263 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 264 | expectedBazelTargets: []string{ |
| 265 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 266 | "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] | 267 | "//build/bazel/platforms/arch:arm64": [":shared_dep3"], |
| 268 | "//conditions:default": [], |
| 269 | }) + select({ |
| 270 | "//build/bazel/platforms/os:android": [":shared_dep2"], |
| 271 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 272 | })`, |
| 273 | }), |
| 274 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 275 | }) |
| 276 | } |
| 277 | |
| 278 | func TestCcLibrarySharedSimpleExcludeSrcs(t *testing.T) { |
| 279 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 280 | 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] | 281 | filesystem: map[string]string{ |
| 282 | "common.c": "", |
| 283 | "foo-a.c": "", |
| 284 | "foo-excluded.c": "", |
| 285 | }, |
| 286 | blueprint: soongCcLibrarySharedPreamble + ` |
| 287 | cc_library_shared { |
| 288 | name: "foo_shared", |
| 289 | srcs: ["common.c", "foo-*.c"], |
| 290 | exclude_srcs: ["foo-excluded.c"], |
| 291 | include_build_directory: false, |
| 292 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 293 | expectedBazelTargets: []string{ |
| 294 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 295 | "srcs_c": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 296 | "common.c", |
| 297 | "foo-a.c", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 298 | ]`, |
| 299 | }), |
| 300 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 301 | }) |
| 302 | } |
| 303 | |
| 304 | func TestCcLibrarySharedStrip(t *testing.T) { |
| 305 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 306 | description: "cc_library_shared stripping", |
| 307 | 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] | 308 | blueprint: soongCcLibrarySharedPreamble + ` |
| 309 | cc_library_shared { |
| 310 | name: "foo_shared", |
| 311 | strip: { |
| 312 | keep_symbols: false, |
| 313 | keep_symbols_and_debug_frame: true, |
| 314 | keep_symbols_list: ["sym", "sym2"], |
| 315 | all: true, |
| 316 | none: false, |
| 317 | }, |
| 318 | include_build_directory: false, |
| 319 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 320 | expectedBazelTargets: []string{ |
| 321 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 322 | "strip": `{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 323 | "all": True, |
| 324 | "keep_symbols": False, |
| 325 | "keep_symbols_and_debug_frame": True, |
| 326 | "keep_symbols_list": [ |
| 327 | "sym", |
| 328 | "sym2", |
| 329 | ], |
| 330 | "none": False, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 331 | }`, |
| 332 | }), |
| 333 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 334 | }) |
| 335 | } |
| 336 | |
| 337 | func TestCcLibrarySharedVersionScript(t *testing.T) { |
| 338 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 339 | 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] | 340 | filesystem: map[string]string{ |
| 341 | "version_script": "", |
| 342 | }, |
| 343 | blueprint: soongCcLibrarySharedPreamble + ` |
| 344 | cc_library_shared { |
| 345 | name: "foo_shared", |
| 346 | version_script: "version_script", |
| 347 | include_build_directory: false, |
| 348 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 349 | expectedBazelTargets: []string{ |
| 350 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 351 | "additional_linker_inputs": `["version_script"]`, |
| 352 | "linkopts": `["-Wl,--version-script,$(location version_script)"]`, |
| 353 | }), |
| 354 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 355 | }) |
| 356 | } |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 357 | |
| 358 | func TestCcLibrarySharedNoCrtTrue(t *testing.T) { |
| 359 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 360 | description: "cc_library_shared - nocrt: true emits attribute", |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 361 | filesystem: map[string]string{ |
| 362 | "impl.cpp": "", |
| 363 | }, |
| 364 | blueprint: soongCcLibraryPreamble + ` |
| 365 | cc_library_shared { |
| 366 | name: "foo_shared", |
| 367 | srcs: ["impl.cpp"], |
| 368 | nocrt: true, |
| 369 | include_build_directory: false, |
| 370 | } |
| 371 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 372 | expectedBazelTargets: []string{ |
| 373 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 374 | "link_crt": `False`, |
| 375 | "srcs": `["impl.cpp"]`, |
| 376 | }), |
| 377 | }, |
| 378 | }) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | func TestCcLibrarySharedNoCrtFalse(t *testing.T) { |
| 382 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 383 | description: "cc_library_shared - nocrt: false doesn't emit attribute", |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 384 | filesystem: map[string]string{ |
| 385 | "impl.cpp": "", |
| 386 | }, |
| 387 | blueprint: soongCcLibraryPreamble + ` |
| 388 | cc_library_shared { |
| 389 | name: "foo_shared", |
| 390 | srcs: ["impl.cpp"], |
| 391 | nocrt: false, |
| 392 | include_build_directory: false, |
| 393 | } |
| 394 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 395 | expectedBazelTargets: []string{ |
| 396 | makeBazelTarget("cc_library_shared", "foo_shared", attrNameToString{ |
| 397 | "srcs": `["impl.cpp"]`, |
| 398 | }), |
| 399 | }, |
| 400 | }) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | func TestCcLibrarySharedNoCrtArchVariant(t *testing.T) { |
| 404 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 405 | description: "cc_library_shared - nocrt in select", |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 406 | filesystem: map[string]string{ |
| 407 | "impl.cpp": "", |
| 408 | }, |
| 409 | blueprint: soongCcLibraryPreamble + ` |
| 410 | cc_library_shared { |
| 411 | name: "foo_shared", |
| 412 | srcs: ["impl.cpp"], |
| 413 | arch: { |
| 414 | arm: { |
| 415 | nocrt: true, |
| 416 | }, |
| 417 | x86: { |
| 418 | nocrt: false, |
| 419 | }, |
| 420 | }, |
| 421 | include_build_directory: false, |
| 422 | } |
| 423 | `, |
Liz Kammer | 718eb27 | 2022-01-07 10:53:37 -0500 | [diff] [blame] | 424 | expectedErr: fmt.Errorf("module \"foo_shared\": nocrt is not supported for arch variants"), |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 425 | }) |
| 426 | } |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 427 | |
| 428 | func TestCcLibrarySharedProto(t *testing.T) { |
| 429 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
| 430 | blueprint: soongCcProtoPreamble + `cc_library_shared { |
| 431 | name: "foo", |
| 432 | srcs: ["foo.proto"], |
| 433 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 434 | export_proto_headers: true, |
| 435 | }, |
| 436 | include_build_directory: false, |
| 437 | }`, |
| 438 | expectedBazelTargets: []string{ |
| 439 | makeBazelTarget("proto_library", "foo_proto", attrNameToString{ |
| 440 | "srcs": `["foo.proto"]`, |
| 441 | }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ |
| 442 | "deps": `[":foo_proto"]`, |
| 443 | }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ |
| 444 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 445 | "whole_archive_deps": `[":foo_cc_proto_lite"]`, |
| 446 | }), |
| 447 | }, |
| 448 | }) |
| 449 | } |
Rupert Shuttleworth | 484aa25 | 2021-12-10 07:22:53 -0500 | [diff] [blame] | 450 | |
| 451 | func TestCcLibrarySharedUseVersionLib(t *testing.T) { |
| 452 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
| 453 | blueprint: soongCcProtoPreamble + `cc_library_shared { |
| 454 | name: "foo", |
| 455 | use_version_lib: true, |
| 456 | include_build_directory: false, |
| 457 | }`, |
| 458 | expectedBazelTargets: []string{ |
| 459 | makeBazelTarget("cc_library_shared", "foo", attrNameToString{ |
| 460 | "use_version_lib": "True", |
| 461 | }), |
| 462 | }, |
| 463 | }) |
| 464 | } |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 465 | |
| 466 | func TestCcLibrarySharedStubs(t *testing.T) { |
| 467 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
| 468 | description: "cc_library_shared stubs", |
| 469 | moduleTypeUnderTest: "cc_library_shared", |
| 470 | moduleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 471 | dir: "foo/bar", |
| 472 | filesystem: map[string]string{ |
| 473 | "foo/bar/Android.bp": ` |
| 474 | cc_library_shared { |
| 475 | name: "a", |
| 476 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 477 | bazel_module: { bp2build_available: true }, |
| 478 | include_build_directory: false, |
| 479 | } |
| 480 | `, |
| 481 | }, |
| 482 | blueprint: soongCcLibraryPreamble, |
| 483 | expectedBazelTargets: []string{makeBazelTarget("cc_library_shared", "a", attrNameToString{ |
| 484 | "stubs_symbol_file": `"a.map.txt"`, |
| 485 | "stubs_versions": `[ |
| 486 | "28", |
| 487 | "29", |
| 488 | "current", |
| 489 | ]`, |
| 490 | }), |
| 491 | }, |
| 492 | }, |
| 493 | ) |
| 494 | } |