Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [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 | "android/soong/android" |
| 19 | "android/soong/cc" |
| 20 | "strings" |
| 21 | "testing" |
| 22 | ) |
| 23 | |
| 24 | const ( |
| 25 | // See cc/testing.go for more context |
| 26 | soongCcLibraryPreamble = ` |
| 27 | cc_defaults { |
| 28 | name: "linux_bionic_supported", |
| 29 | } |
| 30 | |
| 31 | toolchain_library { |
| 32 | name: "libclang_rt.builtins-x86_64-android", |
| 33 | defaults: ["linux_bionic_supported"], |
| 34 | vendor_available: true, |
| 35 | vendor_ramdisk_available: true, |
| 36 | product_available: true, |
| 37 | recovery_available: true, |
| 38 | native_bridge_supported: true, |
| 39 | src: "", |
| 40 | }` |
| 41 | ) |
| 42 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 43 | func runCcLibraryTestCase(t *testing.T, tc bp2buildTestCase) { |
Liz Kammer | e4982e8 | 2021-05-25 10:39:35 -0400 | [diff] [blame] | 44 | t.Helper() |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 45 | runBp2BuildTestCase(t, registerCcLibraryModuleTypes, tc) |
| 46 | } |
| 47 | |
| 48 | func registerCcLibraryModuleTypes(ctx android.RegistrationContext) { |
| 49 | cc.RegisterCCBuildComponents(ctx) |
| 50 | ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) |
| 51 | ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) |
| 52 | ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) |
| 53 | } |
| 54 | |
| 55 | func runBp2BuildTestCase(t *testing.T, registerModuleTypes func(ctx android.RegistrationContext), tc bp2buildTestCase) { |
Liz Kammer | e4982e8 | 2021-05-25 10:39:35 -0400 | [diff] [blame] | 56 | t.Helper() |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 57 | dir := "." |
| 58 | filesystem := make(map[string][]byte) |
| 59 | toParse := []string{ |
| 60 | "Android.bp", |
| 61 | } |
| 62 | for f, content := range tc.filesystem { |
| 63 | if strings.HasSuffix(f, "Android.bp") { |
| 64 | toParse = append(toParse, f) |
| 65 | } |
| 66 | filesystem[f] = []byte(content) |
| 67 | } |
| 68 | config := android.TestConfig(buildDir, nil, tc.blueprint, filesystem) |
| 69 | ctx := android.NewTestContext(config) |
| 70 | |
| 71 | registerModuleTypes(ctx) |
| 72 | ctx.RegisterModuleType(tc.moduleTypeUnderTest, tc.moduleTypeUnderTestFactory) |
| 73 | ctx.RegisterBp2BuildConfig(bp2buildConfig) |
| 74 | for _, m := range tc.depsMutators { |
| 75 | ctx.DepsBp2BuildMutators(m) |
| 76 | } |
| 77 | ctx.RegisterBp2BuildMutator(tc.moduleTypeUnderTest, tc.moduleTypeUnderTestBp2BuildMutator) |
| 78 | ctx.RegisterForBazelConversion() |
| 79 | |
| 80 | _, errs := ctx.ParseFileList(dir, toParse) |
| 81 | if errored(t, tc.description, errs) { |
| 82 | return |
| 83 | } |
| 84 | _, errs = ctx.ResolveDependencies(config) |
| 85 | if errored(t, tc.description, errs) { |
| 86 | return |
| 87 | } |
| 88 | |
| 89 | checkDir := dir |
| 90 | if tc.dir != "" { |
| 91 | checkDir = tc.dir |
| 92 | } |
| 93 | codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) |
| 94 | bazelTargets := generateBazelTargetsForDir(codegenCtx, checkDir) |
| 95 | if actualCount, expectedCount := len(bazelTargets), len(tc.expectedBazelTargets); actualCount != expectedCount { |
| 96 | t.Errorf("%s: Expected %d bazel target, got %d", tc.description, expectedCount, actualCount) |
| 97 | } else { |
| 98 | for i, target := range bazelTargets { |
| 99 | if w, g := tc.expectedBazelTargets[i], target.content; w != g { |
| 100 | t.Errorf( |
| 101 | "%s: Expected generated Bazel target to be '%s', got '%s'", |
| 102 | tc.description, |
| 103 | w, |
| 104 | g, |
| 105 | ) |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | func TestCcLibrarySimple(t *testing.T) { |
| 112 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 113 | description: "cc_library - simple example", |
| 114 | moduleTypeUnderTest: "cc_library", |
| 115 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 116 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 117 | filesystem: map[string]string{ |
| 118 | "android.cpp": "", |
| 119 | "darwin.cpp": "", |
| 120 | // Refer to cc.headerExts for the supported header extensions in Soong. |
| 121 | "header.h": "", |
| 122 | "header.hh": "", |
| 123 | "header.hpp": "", |
| 124 | "header.hxx": "", |
| 125 | "header.h++": "", |
| 126 | "header.inl": "", |
| 127 | "header.inc": "", |
| 128 | "header.ipp": "", |
| 129 | "header.h.generic": "", |
| 130 | "impl.cpp": "", |
| 131 | "linux.cpp": "", |
| 132 | "x86.cpp": "", |
| 133 | "x86_64.cpp": "", |
| 134 | "foo-dir/a.h": "", |
| 135 | }, |
| 136 | blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 137 | cc_library_headers { name: "some-headers" } |
| 138 | cc_library { |
| 139 | name: "foo-lib", |
| 140 | srcs: ["impl.cpp"], |
| 141 | cflags: ["-Wall"], |
| 142 | header_libs: ["some-headers"], |
| 143 | export_include_dirs: ["foo-dir"], |
| 144 | ldflags: ["-Wl,--exclude-libs=bar.a"], |
| 145 | arch: { |
| 146 | x86: { |
| 147 | ldflags: ["-Wl,--exclude-libs=baz.a"], |
| 148 | srcs: ["x86.cpp"], |
| 149 | }, |
| 150 | x86_64: { |
| 151 | ldflags: ["-Wl,--exclude-libs=qux.a"], |
| 152 | srcs: ["x86_64.cpp"], |
| 153 | }, |
| 154 | }, |
| 155 | target: { |
| 156 | android: { |
| 157 | srcs: ["android.cpp"], |
| 158 | }, |
| 159 | linux_glibc: { |
| 160 | srcs: ["linux.cpp"], |
| 161 | }, |
| 162 | darwin: { |
| 163 | srcs: ["darwin.cpp"], |
| 164 | }, |
| 165 | }, |
| 166 | } |
| 167 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 168 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 169 | name = "foo-lib", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 170 | copts = [ |
| 171 | "-Wall", |
| 172 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 173 | "-I$(BINDIR)/.", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 174 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 175 | implementation_deps = [":some-headers"], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 176 | includes = ["foo-dir"], |
| 177 | linkopts = ["-Wl,--exclude-libs=bar.a"] + select({ |
| 178 | "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=baz.a"], |
| 179 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=qux.a"], |
| 180 | "//conditions:default": [], |
| 181 | }), |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 182 | srcs = ["impl.cpp"] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 183 | "//build/bazel/platforms/arch:x86": ["x86.cpp"], |
| 184 | "//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 185 | "//conditions:default": [], |
| 186 | }) + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 187 | "//build/bazel/platforms/os:android": ["android.cpp"], |
| 188 | "//build/bazel/platforms/os:darwin": ["darwin.cpp"], |
| 189 | "//build/bazel/platforms/os:linux": ["linux.cpp"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 190 | "//conditions:default": [], |
| 191 | }), |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 192 | )`}}) |
| 193 | } |
| 194 | |
| 195 | func TestCcLibraryTrimmedLdAndroid(t *testing.T) { |
| 196 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 197 | description: "cc_library - trimmed example of //bionic/linker:ld-android", |
| 198 | moduleTypeUnderTest: "cc_library", |
| 199 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 200 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 201 | filesystem: map[string]string{ |
| 202 | "ld-android.cpp": "", |
| 203 | "linked_list.h": "", |
| 204 | "linker.h": "", |
| 205 | "linker_block_allocator.h": "", |
| 206 | "linker_cfi.h": "", |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 207 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 208 | blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 209 | cc_library_headers { name: "libc_headers" } |
| 210 | cc_library { |
| 211 | name: "fake-ld-android", |
| 212 | srcs: ["ld_android.cpp"], |
| 213 | cflags: [ |
| 214 | "-Wall", |
| 215 | "-Wextra", |
| 216 | "-Wunused", |
| 217 | "-Werror", |
| 218 | ], |
| 219 | header_libs: ["libc_headers"], |
| 220 | ldflags: [ |
| 221 | "-Wl,--exclude-libs=libgcc.a", |
| 222 | "-Wl,--exclude-libs=libgcc_stripped.a", |
| 223 | "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a", |
| 224 | "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a", |
| 225 | "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a", |
| 226 | "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a", |
| 227 | ], |
| 228 | arch: { |
| 229 | x86: { |
| 230 | ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 231 | }, |
| 232 | x86_64: { |
| 233 | ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 234 | }, |
| 235 | }, |
| 236 | } |
| 237 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 238 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 239 | name = "fake-ld-android", |
| 240 | copts = [ |
| 241 | "-Wall", |
| 242 | "-Wextra", |
| 243 | "-Wunused", |
| 244 | "-Werror", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 245 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 246 | "-I$(BINDIR)/.", |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 247 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 248 | implementation_deps = [":libc_headers"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 249 | linkopts = [ |
| 250 | "-Wl,--exclude-libs=libgcc.a", |
| 251 | "-Wl,--exclude-libs=libgcc_stripped.a", |
| 252 | "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a", |
| 253 | "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a", |
| 254 | "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a", |
| 255 | "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a", |
| 256 | ] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 257 | "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 258 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=libgcc_eh.a"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 259 | "//conditions:default": [], |
| 260 | }), |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 261 | srcs = ["ld_android.cpp"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 262 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 263 | }) |
| 264 | } |
| 265 | |
| 266 | func TestCcLibraryExcludeSrcs(t *testing.T) { |
| 267 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 268 | description: "cc_library exclude_srcs - trimmed example of //external/arm-optimized-routines:libarm-optimized-routines-math", |
| 269 | moduleTypeUnderTest: "cc_library", |
| 270 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 271 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 272 | dir: "external", |
| 273 | filesystem: map[string]string{ |
| 274 | "external/math/cosf.c": "", |
| 275 | "external/math/erf.c": "", |
| 276 | "external/math/erf_data.c": "", |
| 277 | "external/math/erff.c": "", |
| 278 | "external/math/erff_data.c": "", |
| 279 | "external/Android.bp": ` |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 280 | cc_library { |
| 281 | name: "fake-libarm-optimized-routines-math", |
| 282 | exclude_srcs: [ |
| 283 | // Provided by: |
| 284 | // bionic/libm/upstream-freebsd/lib/msun/src/s_erf.c |
| 285 | // bionic/libm/upstream-freebsd/lib/msun/src/s_erff.c |
| 286 | "math/erf.c", |
| 287 | "math/erf_data.c", |
| 288 | "math/erff.c", |
| 289 | "math/erff_data.c", |
| 290 | ], |
| 291 | srcs: [ |
| 292 | "math/*.c", |
| 293 | ], |
| 294 | // arch-specific settings |
| 295 | arch: { |
| 296 | arm64: { |
| 297 | cflags: [ |
| 298 | "-DHAVE_FAST_FMA=1", |
| 299 | ], |
| 300 | }, |
| 301 | }, |
| 302 | bazel_module: { bp2build_available: true }, |
| 303 | } |
| 304 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 305 | }, |
| 306 | blueprint: soongCcLibraryPreamble, |
| 307 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 308 | name = "fake-libarm-optimized-routines-math", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 309 | copts = [ |
| 310 | "-Iexternal", |
| 311 | "-I$(BINDIR)/external", |
| 312 | ] + select({ |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 313 | "//build/bazel/platforms/arch:arm64": ["-DHAVE_FAST_FMA=1"], |
| 314 | "//conditions:default": [], |
| 315 | }), |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 316 | srcs_c = ["math/cosf.c"], |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 317 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 318 | }) |
| 319 | } |
| 320 | |
| 321 | func TestCcLibrarySharedStaticProps(t *testing.T) { |
| 322 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 323 | description: "cc_library shared/static props", |
| 324 | moduleTypeUnderTest: "cc_library", |
| 325 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 326 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 327 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 328 | dir: "foo/bar", |
| 329 | filesystem: map[string]string{ |
| 330 | "foo/bar/both.cpp": "", |
| 331 | "foo/bar/sharedonly.cpp": "", |
| 332 | "foo/bar/staticonly.cpp": "", |
| 333 | "foo/bar/Android.bp": ` |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 334 | cc_library { |
| 335 | name: "a", |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 336 | srcs: ["both.cpp"], |
| 337 | cflags: ["bothflag"], |
| 338 | shared_libs: ["shared_dep_for_both"], |
| 339 | static_libs: ["static_dep_for_both"], |
| 340 | whole_static_libs: ["whole_static_lib_for_both"], |
| 341 | static: { |
| 342 | srcs: ["staticonly.cpp"], |
| 343 | cflags: ["staticflag"], |
| 344 | shared_libs: ["shared_dep_for_static"], |
| 345 | static_libs: ["static_dep_for_static"], |
| 346 | whole_static_libs: ["whole_static_lib_for_static"], |
| 347 | }, |
| 348 | shared: { |
| 349 | srcs: ["sharedonly.cpp"], |
| 350 | cflags: ["sharedflag"], |
| 351 | shared_libs: ["shared_dep_for_shared"], |
| 352 | static_libs: ["static_dep_for_shared"], |
| 353 | whole_static_libs: ["whole_static_lib_for_shared"], |
| 354 | }, |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 355 | bazel_module: { bp2build_available: true }, |
| 356 | } |
| 357 | |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 358 | cc_library_static { name: "static_dep_for_shared" } |
| 359 | |
| 360 | cc_library_static { name: "static_dep_for_static" } |
| 361 | |
| 362 | cc_library_static { name: "static_dep_for_both" } |
| 363 | |
| 364 | cc_library_static { name: "whole_static_lib_for_shared" } |
| 365 | |
| 366 | cc_library_static { name: "whole_static_lib_for_static" } |
| 367 | |
| 368 | cc_library_static { name: "whole_static_lib_for_both" } |
| 369 | |
| 370 | cc_library { name: "shared_dep_for_shared" } |
| 371 | |
| 372 | cc_library { name: "shared_dep_for_static" } |
| 373 | |
| 374 | cc_library { name: "shared_dep_for_both" } |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 375 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 376 | }, |
| 377 | blueprint: soongCcLibraryPreamble, |
| 378 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 379 | name = "a", |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 380 | copts = [ |
| 381 | "bothflag", |
| 382 | "-Ifoo/bar", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 383 | "-I$(BINDIR)/foo/bar", |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 384 | ], |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 385 | dynamic_deps = [":shared_dep_for_both"], |
| 386 | dynamic_deps_for_shared = [":shared_dep_for_shared"], |
| 387 | dynamic_deps_for_static = [":shared_dep_for_static"], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 388 | implementation_deps = [":static_dep_for_both"], |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 389 | shared_copts = ["sharedflag"], |
| 390 | shared_srcs = ["sharedonly.cpp"], |
| 391 | srcs = ["both.cpp"], |
| 392 | static_copts = ["staticflag"], |
| 393 | static_deps_for_shared = [":static_dep_for_shared"], |
| 394 | static_deps_for_static = [":static_dep_for_static"], |
| 395 | static_srcs = ["staticonly.cpp"], |
| 396 | whole_archive_deps = [":whole_static_lib_for_both"], |
| 397 | whole_archive_deps_for_shared = [":whole_static_lib_for_shared"], |
| 398 | whole_archive_deps_for_static = [":whole_static_lib_for_static"], |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 399 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 400 | }) |
| 401 | } |
| 402 | |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 403 | func TestCcLibrarySharedStaticPropsInArch(t *testing.T) { |
| 404 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 405 | description: "cc_library shared/static props in arch", |
| 406 | moduleTypeUnderTest: "cc_library", |
| 407 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 408 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 409 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 410 | dir: "foo/bar", |
| 411 | filesystem: map[string]string{ |
| 412 | "foo/bar/arm.cpp": "", |
| 413 | "foo/bar/x86.cpp": "", |
| 414 | "foo/bar/sharedonly.cpp": "", |
| 415 | "foo/bar/staticonly.cpp": "", |
| 416 | "foo/bar/Android.bp": ` |
| 417 | cc_library { |
| 418 | name: "a", |
| 419 | arch: { |
| 420 | arm: { |
| 421 | shared: { |
| 422 | srcs: ["arm_shared.cpp"], |
| 423 | cflags: ["-DARM_SHARED"], |
| 424 | static_libs: ["arm_static_dep_for_shared"], |
| 425 | whole_static_libs: ["arm_whole_static_dep_for_shared"], |
| 426 | shared_libs: ["arm_shared_dep_for_shared"], |
| 427 | }, |
| 428 | }, |
| 429 | x86: { |
| 430 | static: { |
| 431 | srcs: ["x86_static.cpp"], |
| 432 | cflags: ["-DX86_STATIC"], |
| 433 | static_libs: ["x86_dep_for_static"], |
| 434 | }, |
| 435 | }, |
| 436 | }, |
| 437 | target: { |
| 438 | android: { |
| 439 | shared: { |
| 440 | srcs: ["android_shared.cpp"], |
| 441 | cflags: ["-DANDROID_SHARED"], |
| 442 | static_libs: ["android_dep_for_shared"], |
| 443 | }, |
| 444 | }, |
| 445 | android_arm: { |
| 446 | shared: { |
| 447 | cflags: ["-DANDROID_ARM_SHARED"], |
| 448 | }, |
| 449 | }, |
| 450 | }, |
| 451 | srcs: ["both.cpp"], |
| 452 | cflags: ["bothflag"], |
| 453 | static_libs: ["static_dep_for_both"], |
| 454 | static: { |
| 455 | srcs: ["staticonly.cpp"], |
| 456 | cflags: ["staticflag"], |
| 457 | static_libs: ["static_dep_for_static"], |
| 458 | }, |
| 459 | shared: { |
| 460 | srcs: ["sharedonly.cpp"], |
| 461 | cflags: ["sharedflag"], |
| 462 | static_libs: ["static_dep_for_shared"], |
| 463 | }, |
| 464 | bazel_module: { bp2build_available: true }, |
| 465 | } |
| 466 | |
| 467 | cc_library_static { name: "static_dep_for_shared" } |
| 468 | cc_library_static { name: "static_dep_for_static" } |
| 469 | cc_library_static { name: "static_dep_for_both" } |
| 470 | |
| 471 | cc_library_static { name: "arm_static_dep_for_shared" } |
| 472 | cc_library_static { name: "arm_whole_static_dep_for_shared" } |
| 473 | cc_library_static { name: "arm_shared_dep_for_shared" } |
| 474 | |
| 475 | cc_library_static { name: "x86_dep_for_static" } |
| 476 | |
| 477 | cc_library_static { name: "android_dep_for_shared" } |
| 478 | `, |
| 479 | }, |
| 480 | blueprint: soongCcLibraryPreamble, |
| 481 | expectedBazelTargets: []string{`cc_library( |
| 482 | name = "a", |
| 483 | copts = [ |
| 484 | "bothflag", |
| 485 | "-Ifoo/bar", |
| 486 | "-I$(BINDIR)/foo/bar", |
| 487 | ], |
| 488 | dynamic_deps_for_shared = select({ |
| 489 | "//build/bazel/platforms/arch:arm": [":arm_shared_dep_for_shared"], |
| 490 | "//conditions:default": [], |
| 491 | }), |
| 492 | implementation_deps = [":static_dep_for_both"], |
| 493 | shared_copts = ["sharedflag"] + select({ |
| 494 | "//build/bazel/platforms/arch:arm": ["-DARM_SHARED"], |
| 495 | "//conditions:default": [], |
| 496 | }) + select({ |
| 497 | "//build/bazel/platforms/os:android": ["-DANDROID_SHARED"], |
| 498 | "//conditions:default": [], |
| 499 | }) + select({ |
| 500 | "//build/bazel/platforms:android_arm": ["-DANDROID_ARM_SHARED"], |
| 501 | "//conditions:default": [], |
| 502 | }), |
| 503 | shared_srcs = ["sharedonly.cpp"] + select({ |
| 504 | "//build/bazel/platforms/arch:arm": ["arm_shared.cpp"], |
| 505 | "//conditions:default": [], |
| 506 | }) + select({ |
| 507 | "//build/bazel/platforms/os:android": ["android_shared.cpp"], |
| 508 | "//conditions:default": [], |
| 509 | }), |
| 510 | srcs = ["both.cpp"], |
| 511 | static_copts = ["staticflag"] + select({ |
| 512 | "//build/bazel/platforms/arch:x86": ["-DX86_STATIC"], |
| 513 | "//conditions:default": [], |
| 514 | }), |
| 515 | static_deps_for_shared = [":static_dep_for_shared"] + select({ |
| 516 | "//build/bazel/platforms/arch:arm": [":arm_static_dep_for_shared"], |
| 517 | "//conditions:default": [], |
| 518 | }) + select({ |
| 519 | "//build/bazel/platforms/os:android": [":android_dep_for_shared"], |
| 520 | "//conditions:default": [], |
| 521 | }), |
| 522 | static_deps_for_static = [":static_dep_for_static"] + select({ |
| 523 | "//build/bazel/platforms/arch:x86": [":x86_dep_for_static"], |
| 524 | "//conditions:default": [], |
| 525 | }), |
| 526 | static_srcs = ["staticonly.cpp"] + select({ |
| 527 | "//build/bazel/platforms/arch:x86": ["x86_static.cpp"], |
| 528 | "//conditions:default": [], |
| 529 | }), |
| 530 | whole_archive_deps_for_shared = select({ |
| 531 | "//build/bazel/platforms/arch:arm": [":arm_whole_static_dep_for_shared"], |
| 532 | "//conditions:default": [], |
| 533 | }), |
| 534 | )`}, |
| 535 | }) |
| 536 | } |
| 537 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 538 | func TestCcLibraryNonConfiguredVersionScript(t *testing.T) { |
| 539 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 540 | description: "cc_library non-configured version script", |
| 541 | moduleTypeUnderTest: "cc_library", |
| 542 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 543 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 544 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 545 | dir: "foo/bar", |
| 546 | filesystem: map[string]string{ |
| 547 | "foo/bar/Android.bp": ` |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 548 | cc_library { |
| 549 | name: "a", |
| 550 | srcs: ["a.cpp"], |
| 551 | version_script: "v.map", |
| 552 | bazel_module: { bp2build_available: true }, |
| 553 | } |
| 554 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 555 | }, |
| 556 | blueprint: soongCcLibraryPreamble, |
| 557 | expectedBazelTargets: []string{`cc_library( |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 558 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 559 | copts = [ |
| 560 | "-Ifoo/bar", |
| 561 | "-I$(BINDIR)/foo/bar", |
| 562 | ], |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 563 | srcs = ["a.cpp"], |
| 564 | version_script = "v.map", |
| 565 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 566 | }) |
| 567 | } |
| 568 | |
| 569 | func TestCcLibraryConfiguredVersionScript(t *testing.T) { |
| 570 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 571 | description: "cc_library configured version script", |
| 572 | moduleTypeUnderTest: "cc_library", |
| 573 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 574 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 575 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 576 | dir: "foo/bar", |
| 577 | filesystem: map[string]string{ |
| 578 | "foo/bar/Android.bp": ` |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 579 | cc_library { |
| 580 | name: "a", |
| 581 | srcs: ["a.cpp"], |
| 582 | arch: { |
| 583 | arm: { |
| 584 | version_script: "arm.map", |
| 585 | }, |
| 586 | arm64: { |
| 587 | version_script: "arm64.map", |
| 588 | }, |
| 589 | }, |
| 590 | |
| 591 | bazel_module: { bp2build_available: true }, |
| 592 | } |
| 593 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 594 | }, |
| 595 | blueprint: soongCcLibraryPreamble, |
| 596 | expectedBazelTargets: []string{`cc_library( |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 597 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 598 | copts = [ |
| 599 | "-Ifoo/bar", |
| 600 | "-I$(BINDIR)/foo/bar", |
| 601 | ], |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 602 | srcs = ["a.cpp"], |
| 603 | version_script = select({ |
| 604 | "//build/bazel/platforms/arch:arm": "arm.map", |
| 605 | "//build/bazel/platforms/arch:arm64": "arm64.map", |
| 606 | "//conditions:default": None, |
| 607 | }), |
| 608 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 609 | }) |
| 610 | } |
| 611 | |
| 612 | func TestCcLibrarySharedLibs(t *testing.T) { |
| 613 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 614 | description: "cc_library shared_libs", |
| 615 | moduleTypeUnderTest: "cc_library", |
| 616 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 617 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 618 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 619 | dir: "foo/bar", |
| 620 | filesystem: map[string]string{ |
| 621 | "foo/bar/Android.bp": ` |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 622 | cc_library { |
| 623 | name: "mylib", |
| 624 | bazel_module: { bp2build_available: true }, |
| 625 | } |
| 626 | |
| 627 | cc_library { |
| 628 | name: "a", |
| 629 | shared_libs: ["mylib",], |
| 630 | bazel_module: { bp2build_available: true }, |
| 631 | } |
| 632 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 633 | }, |
| 634 | blueprint: soongCcLibraryPreamble, |
| 635 | expectedBazelTargets: []string{`cc_library( |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 636 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 637 | copts = [ |
| 638 | "-Ifoo/bar", |
| 639 | "-I$(BINDIR)/foo/bar", |
| 640 | ], |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 641 | dynamic_deps = [":mylib"], |
| 642 | )`, `cc_library( |
| 643 | name = "mylib", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 644 | copts = [ |
| 645 | "-Ifoo/bar", |
| 646 | "-I$(BINDIR)/foo/bar", |
| 647 | ], |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 648 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 649 | }) |
| 650 | } |
| 651 | |
| 652 | func TestCcLibraryPackRelocations(t *testing.T) { |
| 653 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 654 | description: "cc_library pack_relocations test", |
| 655 | moduleTypeUnderTest: "cc_library", |
| 656 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 657 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 658 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 659 | dir: "foo/bar", |
| 660 | filesystem: map[string]string{ |
| 661 | "foo/bar/Android.bp": ` |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 662 | cc_library { |
| 663 | name: "a", |
| 664 | srcs: ["a.cpp"], |
| 665 | pack_relocations: false, |
| 666 | bazel_module: { bp2build_available: true }, |
| 667 | } |
| 668 | |
| 669 | cc_library { |
| 670 | name: "b", |
| 671 | srcs: ["b.cpp"], |
| 672 | arch: { |
| 673 | x86_64: { |
| 674 | pack_relocations: false, |
| 675 | }, |
| 676 | }, |
| 677 | bazel_module: { bp2build_available: true }, |
| 678 | } |
| 679 | |
| 680 | cc_library { |
| 681 | name: "c", |
| 682 | srcs: ["c.cpp"], |
| 683 | target: { |
| 684 | darwin: { |
| 685 | pack_relocations: false, |
| 686 | }, |
| 687 | }, |
| 688 | bazel_module: { bp2build_available: true }, |
| 689 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 690 | }, |
| 691 | blueprint: soongCcLibraryPreamble, |
| 692 | expectedBazelTargets: []string{`cc_library( |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 693 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 694 | copts = [ |
| 695 | "-Ifoo/bar", |
| 696 | "-I$(BINDIR)/foo/bar", |
| 697 | ], |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 698 | linkopts = ["-Wl,--pack-dyn-relocs=none"], |
| 699 | srcs = ["a.cpp"], |
| 700 | )`, `cc_library( |
| 701 | name = "b", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 702 | copts = [ |
| 703 | "-Ifoo/bar", |
| 704 | "-I$(BINDIR)/foo/bar", |
| 705 | ], |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 706 | linkopts = select({ |
| 707 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--pack-dyn-relocs=none"], |
| 708 | "//conditions:default": [], |
| 709 | }), |
| 710 | srcs = ["b.cpp"], |
| 711 | )`, `cc_library( |
| 712 | name = "c", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 713 | copts = [ |
| 714 | "-Ifoo/bar", |
| 715 | "-I$(BINDIR)/foo/bar", |
| 716 | ], |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 717 | linkopts = select({ |
| 718 | "//build/bazel/platforms/os:darwin": ["-Wl,--pack-dyn-relocs=none"], |
| 719 | "//conditions:default": [], |
| 720 | }), |
| 721 | srcs = ["c.cpp"], |
| 722 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 723 | }) |
| 724 | } |
| 725 | |
| 726 | func TestCcLibrarySpacesInCopts(t *testing.T) { |
| 727 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 728 | description: "cc_library spaces in copts", |
| 729 | moduleTypeUnderTest: "cc_library", |
| 730 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 731 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 732 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 733 | dir: "foo/bar", |
| 734 | filesystem: map[string]string{ |
| 735 | "foo/bar/Android.bp": ` |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 736 | cc_library { |
| 737 | name: "a", |
| 738 | cflags: ["-include header.h",], |
| 739 | bazel_module: { bp2build_available: true }, |
| 740 | } |
| 741 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 742 | }, |
| 743 | blueprint: soongCcLibraryPreamble, |
| 744 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 745 | name = "a", |
| 746 | copts = [ |
| 747 | "-include", |
| 748 | "header.h", |
| 749 | "-Ifoo/bar", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 750 | "-I$(BINDIR)/foo/bar", |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 751 | ], |
| 752 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 753 | }) |
| 754 | } |
| 755 | |
| 756 | func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { |
| 757 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 758 | description: "cc_library cppflags usage", |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 759 | moduleTypeUnderTest: "cc_library", |
| 760 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 761 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 762 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 763 | dir: "foo/bar", |
| 764 | filesystem: map[string]string{ |
| 765 | "foo/bar/Android.bp": `cc_library { |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 766 | name: "a", |
| 767 | srcs: ["a.cpp"], |
| 768 | cflags: [ |
| 769 | "-Wall", |
| 770 | ], |
| 771 | cppflags: [ |
| 772 | "-fsigned-char", |
| 773 | "-pedantic", |
| 774 | ], |
| 775 | arch: { |
| 776 | arm64: { |
| 777 | cppflags: ["-DARM64=1"], |
| 778 | }, |
| 779 | }, |
| 780 | target: { |
| 781 | android: { |
| 782 | cppflags: ["-DANDROID=1"], |
| 783 | }, |
| 784 | }, |
| 785 | bazel_module: { bp2build_available: true }, |
| 786 | } |
| 787 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 788 | }, |
| 789 | blueprint: soongCcLibraryPreamble, |
| 790 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 791 | name = "a", |
| 792 | copts = [ |
| 793 | "-Wall", |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 794 | "-Ifoo/bar", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 795 | "-I$(BINDIR)/foo/bar", |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 796 | ], |
| 797 | cppflags = [ |
| 798 | "-fsigned-char", |
| 799 | "-pedantic", |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 800 | ] + select({ |
| 801 | "//build/bazel/platforms/arch:arm64": ["-DARM64=1"], |
| 802 | "//conditions:default": [], |
| 803 | }) + select({ |
| 804 | "//build/bazel/platforms/os:android": ["-DANDROID=1"], |
| 805 | "//conditions:default": [], |
| 806 | }), |
| 807 | srcs = ["a.cpp"], |
| 808 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 809 | }) |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 810 | } |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame^] | 811 | |
| 812 | func TestCcLibraryLabelAttributeGetTargetProperties(t *testing.T) { |
| 813 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 814 | description: "cc_library GetTargetProperties on a LabelAttribute", |
| 815 | moduleTypeUnderTest: "cc_library", |
| 816 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 817 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 818 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 819 | dir: "foo/bar", |
| 820 | filesystem: map[string]string{ |
| 821 | "foo/bar/Android.bp": ` |
| 822 | cc_library { |
| 823 | name: "a", |
| 824 | srcs: ["a.cpp"], |
| 825 | target: { |
| 826 | android_arm: { |
| 827 | version_script: "android_arm.map", |
| 828 | }, |
| 829 | linux_bionic_arm64: { |
| 830 | version_script: "linux_bionic_arm64.map", |
| 831 | }, |
| 832 | }, |
| 833 | |
| 834 | bazel_module: { bp2build_available: true }, |
| 835 | } |
| 836 | `, |
| 837 | }, |
| 838 | blueprint: soongCcLibraryPreamble, |
| 839 | expectedBazelTargets: []string{`cc_library( |
| 840 | name = "a", |
| 841 | copts = [ |
| 842 | "-Ifoo/bar", |
| 843 | "-I$(BINDIR)/foo/bar", |
| 844 | ], |
| 845 | srcs = ["a.cpp"], |
| 846 | version_script = select({ |
| 847 | "//build/bazel/platforms:android_arm": "android_arm.map", |
| 848 | "//build/bazel/platforms:linux_bionic_arm64": "linux_bionic_arm64.map", |
| 849 | "//conditions:default": None, |
| 850 | }), |
| 851 | )`}, |
| 852 | }) |
| 853 | } |