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 { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 28 | name: "linux_bionic_supported", |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | toolchain_library { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 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: "", |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 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) |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 50 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 51 | ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 52 | ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 53 | ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) |
| 54 | ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) |
| 55 | } |
| 56 | |
| 57 | func runBp2BuildTestCase(t *testing.T, registerModuleTypes func(ctx android.RegistrationContext), tc bp2buildTestCase) { |
Liz Kammer | e4982e8 | 2021-05-25 10:39:35 -0400 | [diff] [blame] | 58 | t.Helper() |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 59 | dir := "." |
| 60 | filesystem := make(map[string][]byte) |
| 61 | toParse := []string{ |
| 62 | "Android.bp", |
| 63 | } |
| 64 | for f, content := range tc.filesystem { |
| 65 | if strings.HasSuffix(f, "Android.bp") { |
| 66 | toParse = append(toParse, f) |
| 67 | } |
| 68 | filesystem[f] = []byte(content) |
| 69 | } |
| 70 | config := android.TestConfig(buildDir, nil, tc.blueprint, filesystem) |
| 71 | ctx := android.NewTestContext(config) |
| 72 | |
| 73 | registerModuleTypes(ctx) |
| 74 | ctx.RegisterModuleType(tc.moduleTypeUnderTest, tc.moduleTypeUnderTestFactory) |
| 75 | ctx.RegisterBp2BuildConfig(bp2buildConfig) |
| 76 | for _, m := range tc.depsMutators { |
| 77 | ctx.DepsBp2BuildMutators(m) |
| 78 | } |
| 79 | ctx.RegisterBp2BuildMutator(tc.moduleTypeUnderTest, tc.moduleTypeUnderTestBp2BuildMutator) |
| 80 | ctx.RegisterForBazelConversion() |
| 81 | |
| 82 | _, errs := ctx.ParseFileList(dir, toParse) |
| 83 | if errored(t, tc.description, errs) { |
| 84 | return |
| 85 | } |
| 86 | _, errs = ctx.ResolveDependencies(config) |
| 87 | if errored(t, tc.description, errs) { |
| 88 | return |
| 89 | } |
| 90 | |
| 91 | checkDir := dir |
| 92 | if tc.dir != "" { |
| 93 | checkDir = tc.dir |
| 94 | } |
| 95 | codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) |
| 96 | bazelTargets := generateBazelTargetsForDir(codegenCtx, checkDir) |
| 97 | if actualCount, expectedCount := len(bazelTargets), len(tc.expectedBazelTargets); actualCount != expectedCount { |
| 98 | t.Errorf("%s: Expected %d bazel target, got %d", tc.description, expectedCount, actualCount) |
| 99 | } else { |
| 100 | for i, target := range bazelTargets { |
| 101 | if w, g := tc.expectedBazelTargets[i], target.content; w != g { |
| 102 | t.Errorf( |
| 103 | "%s: Expected generated Bazel target to be '%s', got '%s'", |
| 104 | tc.description, |
| 105 | w, |
| 106 | g, |
| 107 | ) |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | func TestCcLibrarySimple(t *testing.T) { |
| 114 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 115 | description: "cc_library - simple example", |
| 116 | moduleTypeUnderTest: "cc_library", |
| 117 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 118 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 119 | filesystem: map[string]string{ |
| 120 | "android.cpp": "", |
| 121 | "darwin.cpp": "", |
| 122 | // Refer to cc.headerExts for the supported header extensions in Soong. |
| 123 | "header.h": "", |
| 124 | "header.hh": "", |
| 125 | "header.hpp": "", |
| 126 | "header.hxx": "", |
| 127 | "header.h++": "", |
| 128 | "header.inl": "", |
| 129 | "header.inc": "", |
| 130 | "header.ipp": "", |
| 131 | "header.h.generic": "", |
| 132 | "impl.cpp": "", |
| 133 | "linux.cpp": "", |
| 134 | "x86.cpp": "", |
| 135 | "x86_64.cpp": "", |
| 136 | "foo-dir/a.h": "", |
| 137 | }, |
| 138 | blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 139 | cc_library_headers { name: "some-headers" } |
| 140 | cc_library { |
| 141 | name: "foo-lib", |
| 142 | srcs: ["impl.cpp"], |
| 143 | cflags: ["-Wall"], |
| 144 | header_libs: ["some-headers"], |
| 145 | export_include_dirs: ["foo-dir"], |
| 146 | ldflags: ["-Wl,--exclude-libs=bar.a"], |
| 147 | arch: { |
| 148 | x86: { |
| 149 | ldflags: ["-Wl,--exclude-libs=baz.a"], |
| 150 | srcs: ["x86.cpp"], |
| 151 | }, |
| 152 | x86_64: { |
| 153 | ldflags: ["-Wl,--exclude-libs=qux.a"], |
| 154 | srcs: ["x86_64.cpp"], |
| 155 | }, |
| 156 | }, |
| 157 | target: { |
| 158 | android: { |
| 159 | srcs: ["android.cpp"], |
| 160 | }, |
| 161 | linux_glibc: { |
| 162 | srcs: ["linux.cpp"], |
| 163 | }, |
| 164 | darwin: { |
| 165 | srcs: ["darwin.cpp"], |
| 166 | }, |
| 167 | }, |
| 168 | } |
| 169 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 170 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 171 | name = "foo-lib", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 172 | copts = [ |
| 173 | "-Wall", |
| 174 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 175 | "-I$(BINDIR)/.", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 176 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 177 | implementation_deps = [":some-headers"], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 178 | includes = ["foo-dir"], |
| 179 | linkopts = ["-Wl,--exclude-libs=bar.a"] + select({ |
| 180 | "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=baz.a"], |
| 181 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=qux.a"], |
| 182 | "//conditions:default": [], |
| 183 | }), |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 184 | srcs = ["impl.cpp"] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 185 | "//build/bazel/platforms/arch:x86": ["x86.cpp"], |
| 186 | "//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 187 | "//conditions:default": [], |
| 188 | }) + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 189 | "//build/bazel/platforms/os:android": ["android.cpp"], |
| 190 | "//build/bazel/platforms/os:darwin": ["darwin.cpp"], |
| 191 | "//build/bazel/platforms/os:linux": ["linux.cpp"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 192 | "//conditions:default": [], |
| 193 | }), |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 194 | )`}}) |
| 195 | } |
| 196 | |
| 197 | func TestCcLibraryTrimmedLdAndroid(t *testing.T) { |
| 198 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 199 | description: "cc_library - trimmed example of //bionic/linker:ld-android", |
| 200 | moduleTypeUnderTest: "cc_library", |
| 201 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 202 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 203 | filesystem: map[string]string{ |
| 204 | "ld-android.cpp": "", |
| 205 | "linked_list.h": "", |
| 206 | "linker.h": "", |
| 207 | "linker_block_allocator.h": "", |
| 208 | "linker_cfi.h": "", |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 209 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 210 | blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 211 | cc_library_headers { name: "libc_headers" } |
| 212 | cc_library { |
| 213 | name: "fake-ld-android", |
| 214 | srcs: ["ld_android.cpp"], |
| 215 | cflags: [ |
| 216 | "-Wall", |
| 217 | "-Wextra", |
| 218 | "-Wunused", |
| 219 | "-Werror", |
| 220 | ], |
| 221 | header_libs: ["libc_headers"], |
| 222 | ldflags: [ |
| 223 | "-Wl,--exclude-libs=libgcc.a", |
| 224 | "-Wl,--exclude-libs=libgcc_stripped.a", |
| 225 | "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a", |
| 226 | "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a", |
| 227 | "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a", |
| 228 | "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a", |
| 229 | ], |
| 230 | arch: { |
| 231 | x86: { |
| 232 | ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 233 | }, |
| 234 | x86_64: { |
| 235 | ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 236 | }, |
| 237 | }, |
| 238 | } |
| 239 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 240 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 241 | name = "fake-ld-android", |
| 242 | copts = [ |
| 243 | "-Wall", |
| 244 | "-Wextra", |
| 245 | "-Wunused", |
| 246 | "-Werror", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 247 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 248 | "-I$(BINDIR)/.", |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 249 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 250 | implementation_deps = [":libc_headers"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 251 | linkopts = [ |
| 252 | "-Wl,--exclude-libs=libgcc.a", |
| 253 | "-Wl,--exclude-libs=libgcc_stripped.a", |
| 254 | "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a", |
| 255 | "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a", |
| 256 | "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a", |
| 257 | "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a", |
| 258 | ] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 259 | "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 260 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=libgcc_eh.a"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 261 | "//conditions:default": [], |
| 262 | }), |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 263 | srcs = ["ld_android.cpp"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 264 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 265 | }) |
| 266 | } |
| 267 | |
| 268 | func TestCcLibraryExcludeSrcs(t *testing.T) { |
| 269 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 270 | description: "cc_library exclude_srcs - trimmed example of //external/arm-optimized-routines:libarm-optimized-routines-math", |
| 271 | moduleTypeUnderTest: "cc_library", |
| 272 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 273 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 274 | dir: "external", |
| 275 | filesystem: map[string]string{ |
| 276 | "external/math/cosf.c": "", |
| 277 | "external/math/erf.c": "", |
| 278 | "external/math/erf_data.c": "", |
| 279 | "external/math/erff.c": "", |
| 280 | "external/math/erff_data.c": "", |
| 281 | "external/Android.bp": ` |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 282 | cc_library { |
| 283 | name: "fake-libarm-optimized-routines-math", |
| 284 | exclude_srcs: [ |
| 285 | // Provided by: |
| 286 | // bionic/libm/upstream-freebsd/lib/msun/src/s_erf.c |
| 287 | // bionic/libm/upstream-freebsd/lib/msun/src/s_erff.c |
| 288 | "math/erf.c", |
| 289 | "math/erf_data.c", |
| 290 | "math/erff.c", |
| 291 | "math/erff_data.c", |
| 292 | ], |
| 293 | srcs: [ |
| 294 | "math/*.c", |
| 295 | ], |
| 296 | // arch-specific settings |
| 297 | arch: { |
| 298 | arm64: { |
| 299 | cflags: [ |
| 300 | "-DHAVE_FAST_FMA=1", |
| 301 | ], |
| 302 | }, |
| 303 | }, |
| 304 | bazel_module: { bp2build_available: true }, |
| 305 | } |
| 306 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 307 | }, |
| 308 | blueprint: soongCcLibraryPreamble, |
| 309 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 310 | name = "fake-libarm-optimized-routines-math", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 311 | copts = [ |
| 312 | "-Iexternal", |
| 313 | "-I$(BINDIR)/external", |
| 314 | ] + select({ |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 315 | "//build/bazel/platforms/arch:arm64": ["-DHAVE_FAST_FMA=1"], |
| 316 | "//conditions:default": [], |
| 317 | }), |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 318 | srcs_c = ["math/cosf.c"], |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 319 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 320 | }) |
| 321 | } |
| 322 | |
| 323 | func TestCcLibrarySharedStaticProps(t *testing.T) { |
| 324 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 325 | description: "cc_library shared/static props", |
| 326 | moduleTypeUnderTest: "cc_library", |
| 327 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 328 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 329 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 330 | dir: "foo/bar", |
| 331 | filesystem: map[string]string{ |
| 332 | "foo/bar/both.cpp": "", |
| 333 | "foo/bar/sharedonly.cpp": "", |
| 334 | "foo/bar/staticonly.cpp": "", |
| 335 | "foo/bar/Android.bp": ` |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 336 | cc_library { |
| 337 | name: "a", |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 338 | srcs: ["both.cpp"], |
| 339 | cflags: ["bothflag"], |
| 340 | shared_libs: ["shared_dep_for_both"], |
| 341 | static_libs: ["static_dep_for_both"], |
| 342 | whole_static_libs: ["whole_static_lib_for_both"], |
| 343 | static: { |
| 344 | srcs: ["staticonly.cpp"], |
| 345 | cflags: ["staticflag"], |
| 346 | shared_libs: ["shared_dep_for_static"], |
| 347 | static_libs: ["static_dep_for_static"], |
| 348 | whole_static_libs: ["whole_static_lib_for_static"], |
| 349 | }, |
| 350 | shared: { |
| 351 | srcs: ["sharedonly.cpp"], |
| 352 | cflags: ["sharedflag"], |
| 353 | shared_libs: ["shared_dep_for_shared"], |
| 354 | static_libs: ["static_dep_for_shared"], |
| 355 | whole_static_libs: ["whole_static_lib_for_shared"], |
| 356 | }, |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 357 | bazel_module: { bp2build_available: true }, |
| 358 | } |
| 359 | |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 360 | cc_library_static { name: "static_dep_for_shared" } |
| 361 | |
| 362 | cc_library_static { name: "static_dep_for_static" } |
| 363 | |
| 364 | cc_library_static { name: "static_dep_for_both" } |
| 365 | |
| 366 | cc_library_static { name: "whole_static_lib_for_shared" } |
| 367 | |
| 368 | cc_library_static { name: "whole_static_lib_for_static" } |
| 369 | |
| 370 | cc_library_static { name: "whole_static_lib_for_both" } |
| 371 | |
| 372 | cc_library { name: "shared_dep_for_shared" } |
| 373 | |
| 374 | cc_library { name: "shared_dep_for_static" } |
| 375 | |
| 376 | cc_library { name: "shared_dep_for_both" } |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 377 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 378 | }, |
| 379 | blueprint: soongCcLibraryPreamble, |
| 380 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 381 | name = "a", |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 382 | copts = [ |
| 383 | "bothflag", |
| 384 | "-Ifoo/bar", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 385 | "-I$(BINDIR)/foo/bar", |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 386 | ], |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 387 | dynamic_deps = [":shared_dep_for_both"], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 388 | implementation_deps = [":static_dep_for_both"], |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 389 | shared = { |
| 390 | "copts": ["sharedflag"], |
| 391 | "dynamic_deps": [":shared_dep_for_shared"], |
| 392 | "srcs": ["sharedonly.cpp"], |
| 393 | "static_deps": [":static_dep_for_shared"], |
| 394 | "whole_archive_deps": [":whole_static_lib_for_shared"], |
| 395 | }, |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 396 | srcs = ["both.cpp"], |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 397 | static = { |
| 398 | "copts": ["staticflag"], |
| 399 | "dynamic_deps": [":shared_dep_for_static"], |
| 400 | "srcs": ["staticonly.cpp"], |
| 401 | "static_deps": [":static_dep_for_static"], |
| 402 | "whole_archive_deps": [":whole_static_lib_for_static"], |
| 403 | }, |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 404 | whole_archive_deps = [":whole_static_lib_for_both"], |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 405 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 406 | }) |
| 407 | } |
| 408 | |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 409 | func TestCcLibraryWholeStaticLibsAlwaysLink(t *testing.T) { |
| 410 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 411 | moduleTypeUnderTest: "cc_library", |
| 412 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 413 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 414 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 415 | dir: "foo/bar", |
| 416 | filesystem: map[string]string{ |
| 417 | "foo/bar/Android.bp": ` |
| 418 | cc_library { |
| 419 | name: "a", |
| 420 | whole_static_libs: ["whole_static_lib_for_both"], |
| 421 | static: { |
| 422 | whole_static_libs: ["whole_static_lib_for_static"], |
| 423 | }, |
| 424 | shared: { |
| 425 | whole_static_libs: ["whole_static_lib_for_shared"], |
| 426 | }, |
| 427 | bazel_module: { bp2build_available: true }, |
| 428 | } |
| 429 | |
| 430 | cc_prebuilt_library_static { name: "whole_static_lib_for_shared" } |
| 431 | |
| 432 | cc_prebuilt_library_static { name: "whole_static_lib_for_static" } |
| 433 | |
| 434 | cc_prebuilt_library_static { name: "whole_static_lib_for_both" } |
| 435 | `, |
| 436 | }, |
| 437 | blueprint: soongCcLibraryPreamble, |
| 438 | expectedBazelTargets: []string{`cc_library( |
| 439 | name = "a", |
| 440 | copts = [ |
| 441 | "-Ifoo/bar", |
| 442 | "-I$(BINDIR)/foo/bar", |
| 443 | ], |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 444 | shared = { |
| 445 | "whole_archive_deps": [":whole_static_lib_for_shared_alwayslink"], |
| 446 | }, |
| 447 | static = { |
| 448 | "whole_archive_deps": [":whole_static_lib_for_static_alwayslink"], |
| 449 | }, |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 450 | whole_archive_deps = [":whole_static_lib_for_both_alwayslink"], |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 451 | )`}, |
| 452 | }) |
| 453 | } |
| 454 | |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 455 | func TestCcLibrarySharedStaticPropsInArch(t *testing.T) { |
| 456 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 457 | description: "cc_library shared/static props in arch", |
| 458 | moduleTypeUnderTest: "cc_library", |
| 459 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 460 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 461 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 462 | dir: "foo/bar", |
| 463 | filesystem: map[string]string{ |
| 464 | "foo/bar/arm.cpp": "", |
| 465 | "foo/bar/x86.cpp": "", |
| 466 | "foo/bar/sharedonly.cpp": "", |
| 467 | "foo/bar/staticonly.cpp": "", |
| 468 | "foo/bar/Android.bp": ` |
| 469 | cc_library { |
| 470 | name: "a", |
| 471 | arch: { |
| 472 | arm: { |
| 473 | shared: { |
| 474 | srcs: ["arm_shared.cpp"], |
| 475 | cflags: ["-DARM_SHARED"], |
| 476 | static_libs: ["arm_static_dep_for_shared"], |
| 477 | whole_static_libs: ["arm_whole_static_dep_for_shared"], |
| 478 | shared_libs: ["arm_shared_dep_for_shared"], |
| 479 | }, |
| 480 | }, |
| 481 | x86: { |
| 482 | static: { |
| 483 | srcs: ["x86_static.cpp"], |
| 484 | cflags: ["-DX86_STATIC"], |
| 485 | static_libs: ["x86_dep_for_static"], |
| 486 | }, |
| 487 | }, |
| 488 | }, |
| 489 | target: { |
| 490 | android: { |
| 491 | shared: { |
| 492 | srcs: ["android_shared.cpp"], |
| 493 | cflags: ["-DANDROID_SHARED"], |
| 494 | static_libs: ["android_dep_for_shared"], |
| 495 | }, |
| 496 | }, |
| 497 | android_arm: { |
| 498 | shared: { |
| 499 | cflags: ["-DANDROID_ARM_SHARED"], |
| 500 | }, |
| 501 | }, |
| 502 | }, |
| 503 | srcs: ["both.cpp"], |
| 504 | cflags: ["bothflag"], |
| 505 | static_libs: ["static_dep_for_both"], |
| 506 | static: { |
| 507 | srcs: ["staticonly.cpp"], |
| 508 | cflags: ["staticflag"], |
| 509 | static_libs: ["static_dep_for_static"], |
| 510 | }, |
| 511 | shared: { |
| 512 | srcs: ["sharedonly.cpp"], |
| 513 | cflags: ["sharedflag"], |
| 514 | static_libs: ["static_dep_for_shared"], |
| 515 | }, |
| 516 | bazel_module: { bp2build_available: true }, |
| 517 | } |
| 518 | |
| 519 | cc_library_static { name: "static_dep_for_shared" } |
| 520 | cc_library_static { name: "static_dep_for_static" } |
| 521 | cc_library_static { name: "static_dep_for_both" } |
| 522 | |
| 523 | cc_library_static { name: "arm_static_dep_for_shared" } |
| 524 | cc_library_static { name: "arm_whole_static_dep_for_shared" } |
| 525 | cc_library_static { name: "arm_shared_dep_for_shared" } |
| 526 | |
| 527 | cc_library_static { name: "x86_dep_for_static" } |
| 528 | |
| 529 | cc_library_static { name: "android_dep_for_shared" } |
| 530 | `, |
| 531 | }, |
| 532 | blueprint: soongCcLibraryPreamble, |
| 533 | expectedBazelTargets: []string{`cc_library( |
| 534 | name = "a", |
| 535 | copts = [ |
| 536 | "bothflag", |
| 537 | "-Ifoo/bar", |
| 538 | "-I$(BINDIR)/foo/bar", |
| 539 | ], |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 540 | implementation_deps = [":static_dep_for_both"], |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 541 | shared = { |
| 542 | "copts": ["sharedflag"] + select({ |
| 543 | "//build/bazel/platforms/arch:arm": ["-DARM_SHARED"], |
| 544 | "//conditions:default": [], |
| 545 | }) + select({ |
| 546 | "//build/bazel/platforms/os:android": ["-DANDROID_SHARED"], |
| 547 | "//conditions:default": [], |
| 548 | }) + select({ |
| 549 | "//build/bazel/platforms/os_arch:android_arm": ["-DANDROID_ARM_SHARED"], |
| 550 | "//conditions:default": [], |
| 551 | }), |
| 552 | "dynamic_deps": select({ |
| 553 | "//build/bazel/platforms/arch:arm": [":arm_shared_dep_for_shared"], |
| 554 | "//conditions:default": [], |
| 555 | }), |
| 556 | "srcs": ["sharedonly.cpp"] + select({ |
| 557 | "//build/bazel/platforms/arch:arm": ["arm_shared.cpp"], |
| 558 | "//conditions:default": [], |
| 559 | }) + select({ |
| 560 | "//build/bazel/platforms/os:android": ["android_shared.cpp"], |
| 561 | "//conditions:default": [], |
| 562 | }), |
| 563 | "static_deps": [":static_dep_for_shared"] + select({ |
| 564 | "//build/bazel/platforms/arch:arm": [":arm_static_dep_for_shared"], |
| 565 | "//conditions:default": [], |
| 566 | }) + select({ |
| 567 | "//build/bazel/platforms/os:android": [":android_dep_for_shared"], |
| 568 | "//conditions:default": [], |
| 569 | }), |
| 570 | "whole_archive_deps": select({ |
| 571 | "//build/bazel/platforms/arch:arm": [":arm_whole_static_dep_for_shared"], |
| 572 | "//conditions:default": [], |
| 573 | }), |
| 574 | }, |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 575 | srcs = ["both.cpp"], |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 576 | static = { |
| 577 | "copts": ["staticflag"] + select({ |
| 578 | "//build/bazel/platforms/arch:x86": ["-DX86_STATIC"], |
| 579 | "//conditions:default": [], |
| 580 | }), |
| 581 | "srcs": ["staticonly.cpp"] + select({ |
| 582 | "//build/bazel/platforms/arch:x86": ["x86_static.cpp"], |
| 583 | "//conditions:default": [], |
| 584 | }), |
| 585 | "static_deps": [":static_dep_for_static"] + select({ |
| 586 | "//build/bazel/platforms/arch:x86": [":x86_dep_for_static"], |
| 587 | "//conditions:default": [], |
| 588 | }), |
| 589 | }, |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 590 | )`}, |
| 591 | }) |
| 592 | } |
| 593 | |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 594 | func TestCcLibrarySharedStaticPropsWithMixedSources(t *testing.T) { |
| 595 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 596 | description: "cc_library shared/static props with c/cpp/s mixed sources", |
| 597 | moduleTypeUnderTest: "cc_library", |
| 598 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 599 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 600 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 601 | dir: "foo/bar", |
| 602 | filesystem: map[string]string{ |
| 603 | "foo/bar/both_source.cpp": "", |
| 604 | "foo/bar/both_source.cc": "", |
| 605 | "foo/bar/both_source.c": "", |
| 606 | "foo/bar/both_source.s": "", |
| 607 | "foo/bar/both_source.S": "", |
| 608 | "foo/bar/shared_source.cpp": "", |
| 609 | "foo/bar/shared_source.cc": "", |
| 610 | "foo/bar/shared_source.c": "", |
| 611 | "foo/bar/shared_source.s": "", |
| 612 | "foo/bar/shared_source.S": "", |
| 613 | "foo/bar/static_source.cpp": "", |
| 614 | "foo/bar/static_source.cc": "", |
| 615 | "foo/bar/static_source.c": "", |
| 616 | "foo/bar/static_source.s": "", |
| 617 | "foo/bar/static_source.S": "", |
| 618 | "foo/bar/Android.bp": ` |
| 619 | cc_library { |
| 620 | name: "a", |
| 621 | srcs: [ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 622 | "both_source.cpp", |
| 623 | "both_source.cc", |
| 624 | "both_source.c", |
| 625 | "both_source.s", |
| 626 | "both_source.S", |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 627 | ":both_filegroup", |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 628 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 629 | static: { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 630 | srcs: [ |
| 631 | "static_source.cpp", |
| 632 | "static_source.cc", |
| 633 | "static_source.c", |
| 634 | "static_source.s", |
| 635 | "static_source.S", |
| 636 | ":static_filegroup", |
| 637 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 638 | }, |
| 639 | shared: { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 640 | srcs: [ |
| 641 | "shared_source.cpp", |
| 642 | "shared_source.cc", |
| 643 | "shared_source.c", |
| 644 | "shared_source.s", |
| 645 | "shared_source.S", |
| 646 | ":shared_filegroup", |
| 647 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 648 | }, |
| 649 | bazel_module: { bp2build_available: true }, |
| 650 | } |
| 651 | |
| 652 | filegroup { |
| 653 | name: "both_filegroup", |
| 654 | srcs: [ |
| 655 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 656 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | filegroup { |
| 660 | name: "shared_filegroup", |
| 661 | srcs: [ |
| 662 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 663 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | filegroup { |
| 667 | name: "static_filegroup", |
| 668 | srcs: [ |
| 669 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 670 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 671 | } |
| 672 | `, |
| 673 | }, |
| 674 | blueprint: soongCcLibraryPreamble, |
| 675 | expectedBazelTargets: []string{`cc_library( |
| 676 | name = "a", |
Chris Parsons | 69fa9f9 | 2021-07-13 11:47:44 -0400 | [diff] [blame^] | 677 | asflags = [ |
| 678 | "-Ifoo/bar", |
| 679 | "-I$(BINDIR)/foo/bar", |
| 680 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 681 | copts = [ |
| 682 | "-Ifoo/bar", |
| 683 | "-I$(BINDIR)/foo/bar", |
| 684 | ], |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 685 | shared = { |
| 686 | "srcs": [ |
| 687 | ":shared_filegroup_cpp_srcs", |
| 688 | "shared_source.cc", |
| 689 | "shared_source.cpp", |
| 690 | ], |
| 691 | "srcs_as": [ |
| 692 | "shared_source.s", |
| 693 | "shared_source.S", |
| 694 | ":shared_filegroup_as_srcs", |
| 695 | ], |
| 696 | "srcs_c": [ |
| 697 | "shared_source.c", |
| 698 | ":shared_filegroup_c_srcs", |
| 699 | ], |
| 700 | }, |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 701 | srcs = [ |
| 702 | ":both_filegroup_cpp_srcs", |
| 703 | "both_source.cc", |
| 704 | "both_source.cpp", |
| 705 | ], |
| 706 | srcs_as = [ |
| 707 | "both_source.s", |
| 708 | "both_source.S", |
| 709 | ":both_filegroup_as_srcs", |
| 710 | ], |
| 711 | srcs_c = [ |
| 712 | "both_source.c", |
| 713 | ":both_filegroup_c_srcs", |
| 714 | ], |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 715 | static = { |
| 716 | "srcs": [ |
| 717 | ":static_filegroup_cpp_srcs", |
| 718 | "static_source.cc", |
| 719 | "static_source.cpp", |
| 720 | ], |
| 721 | "srcs_as": [ |
| 722 | "static_source.s", |
| 723 | "static_source.S", |
| 724 | ":static_filegroup_as_srcs", |
| 725 | ], |
| 726 | "srcs_c": [ |
| 727 | "static_source.c", |
| 728 | ":static_filegroup_c_srcs", |
| 729 | ], |
| 730 | }, |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 731 | )`}, |
| 732 | }) |
| 733 | } |
| 734 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 735 | func TestCcLibraryNonConfiguredVersionScript(t *testing.T) { |
| 736 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 737 | description: "cc_library non-configured version script", |
| 738 | moduleTypeUnderTest: "cc_library", |
| 739 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 740 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 741 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 742 | dir: "foo/bar", |
| 743 | filesystem: map[string]string{ |
| 744 | "foo/bar/Android.bp": ` |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 745 | cc_library { |
| 746 | name: "a", |
| 747 | srcs: ["a.cpp"], |
| 748 | version_script: "v.map", |
| 749 | bazel_module: { bp2build_available: true }, |
| 750 | } |
| 751 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 752 | }, |
| 753 | blueprint: soongCcLibraryPreamble, |
| 754 | expectedBazelTargets: []string{`cc_library( |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 755 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 756 | copts = [ |
| 757 | "-Ifoo/bar", |
| 758 | "-I$(BINDIR)/foo/bar", |
| 759 | ], |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 760 | srcs = ["a.cpp"], |
| 761 | version_script = "v.map", |
| 762 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 763 | }) |
| 764 | } |
| 765 | |
| 766 | func TestCcLibraryConfiguredVersionScript(t *testing.T) { |
| 767 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 768 | description: "cc_library configured version script", |
| 769 | moduleTypeUnderTest: "cc_library", |
| 770 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 771 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 772 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 773 | dir: "foo/bar", |
| 774 | filesystem: map[string]string{ |
| 775 | "foo/bar/Android.bp": ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 776 | cc_library { |
| 777 | name: "a", |
| 778 | srcs: ["a.cpp"], |
| 779 | arch: { |
| 780 | arm: { |
| 781 | version_script: "arm.map", |
| 782 | }, |
| 783 | arm64: { |
| 784 | version_script: "arm64.map", |
| 785 | }, |
| 786 | }, |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 787 | |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 788 | bazel_module: { bp2build_available: true }, |
| 789 | } |
| 790 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 791 | }, |
| 792 | blueprint: soongCcLibraryPreamble, |
| 793 | expectedBazelTargets: []string{`cc_library( |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 794 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 795 | copts = [ |
| 796 | "-Ifoo/bar", |
| 797 | "-I$(BINDIR)/foo/bar", |
| 798 | ], |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 799 | srcs = ["a.cpp"], |
| 800 | version_script = select({ |
| 801 | "//build/bazel/platforms/arch:arm": "arm.map", |
| 802 | "//build/bazel/platforms/arch:arm64": "arm64.map", |
| 803 | "//conditions:default": None, |
| 804 | }), |
| 805 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 806 | }) |
| 807 | } |
| 808 | |
| 809 | func TestCcLibrarySharedLibs(t *testing.T) { |
| 810 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 811 | description: "cc_library shared_libs", |
| 812 | moduleTypeUnderTest: "cc_library", |
| 813 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 814 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 815 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 816 | dir: "foo/bar", |
| 817 | filesystem: map[string]string{ |
| 818 | "foo/bar/Android.bp": ` |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 819 | cc_library { |
| 820 | name: "mylib", |
| 821 | bazel_module: { bp2build_available: true }, |
| 822 | } |
| 823 | |
| 824 | cc_library { |
| 825 | name: "a", |
| 826 | shared_libs: ["mylib",], |
| 827 | bazel_module: { bp2build_available: true }, |
| 828 | } |
| 829 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 830 | }, |
| 831 | blueprint: soongCcLibraryPreamble, |
| 832 | expectedBazelTargets: []string{`cc_library( |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 833 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 834 | copts = [ |
| 835 | "-Ifoo/bar", |
| 836 | "-I$(BINDIR)/foo/bar", |
| 837 | ], |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 838 | dynamic_deps = [":mylib"], |
| 839 | )`, `cc_library( |
| 840 | name = "mylib", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 841 | copts = [ |
| 842 | "-Ifoo/bar", |
| 843 | "-I$(BINDIR)/foo/bar", |
| 844 | ], |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 845 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 846 | }) |
| 847 | } |
| 848 | |
| 849 | func TestCcLibraryPackRelocations(t *testing.T) { |
| 850 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 851 | description: "cc_library pack_relocations test", |
| 852 | moduleTypeUnderTest: "cc_library", |
| 853 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 854 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 855 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 856 | dir: "foo/bar", |
| 857 | filesystem: map[string]string{ |
| 858 | "foo/bar/Android.bp": ` |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 859 | cc_library { |
| 860 | name: "a", |
| 861 | srcs: ["a.cpp"], |
| 862 | pack_relocations: false, |
| 863 | bazel_module: { bp2build_available: true }, |
| 864 | } |
| 865 | |
| 866 | cc_library { |
| 867 | name: "b", |
| 868 | srcs: ["b.cpp"], |
| 869 | arch: { |
| 870 | x86_64: { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 871 | pack_relocations: false, |
| 872 | }, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 873 | }, |
| 874 | bazel_module: { bp2build_available: true }, |
| 875 | } |
| 876 | |
| 877 | cc_library { |
| 878 | name: "c", |
| 879 | srcs: ["c.cpp"], |
| 880 | target: { |
| 881 | darwin: { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 882 | pack_relocations: false, |
| 883 | }, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 884 | }, |
| 885 | bazel_module: { bp2build_available: true }, |
| 886 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 887 | }, |
| 888 | blueprint: soongCcLibraryPreamble, |
| 889 | expectedBazelTargets: []string{`cc_library( |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 890 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 891 | copts = [ |
| 892 | "-Ifoo/bar", |
| 893 | "-I$(BINDIR)/foo/bar", |
| 894 | ], |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 895 | linkopts = ["-Wl,--pack-dyn-relocs=none"], |
| 896 | srcs = ["a.cpp"], |
| 897 | )`, `cc_library( |
| 898 | name = "b", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 899 | copts = [ |
| 900 | "-Ifoo/bar", |
| 901 | "-I$(BINDIR)/foo/bar", |
| 902 | ], |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 903 | linkopts = select({ |
| 904 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--pack-dyn-relocs=none"], |
| 905 | "//conditions:default": [], |
| 906 | }), |
| 907 | srcs = ["b.cpp"], |
| 908 | )`, `cc_library( |
| 909 | name = "c", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 910 | copts = [ |
| 911 | "-Ifoo/bar", |
| 912 | "-I$(BINDIR)/foo/bar", |
| 913 | ], |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 914 | linkopts = select({ |
| 915 | "//build/bazel/platforms/os:darwin": ["-Wl,--pack-dyn-relocs=none"], |
| 916 | "//conditions:default": [], |
| 917 | }), |
| 918 | srcs = ["c.cpp"], |
| 919 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 920 | }) |
| 921 | } |
| 922 | |
| 923 | func TestCcLibrarySpacesInCopts(t *testing.T) { |
| 924 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 925 | description: "cc_library spaces in copts", |
| 926 | moduleTypeUnderTest: "cc_library", |
| 927 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 928 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 929 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 930 | dir: "foo/bar", |
| 931 | filesystem: map[string]string{ |
| 932 | "foo/bar/Android.bp": ` |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 933 | cc_library { |
| 934 | name: "a", |
| 935 | cflags: ["-include header.h",], |
| 936 | bazel_module: { bp2build_available: true }, |
| 937 | } |
| 938 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 939 | }, |
| 940 | blueprint: soongCcLibraryPreamble, |
| 941 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 942 | name = "a", |
| 943 | copts = [ |
| 944 | "-include", |
| 945 | "header.h", |
| 946 | "-Ifoo/bar", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 947 | "-I$(BINDIR)/foo/bar", |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 948 | ], |
| 949 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 950 | }) |
| 951 | } |
| 952 | |
| 953 | func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { |
| 954 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 955 | description: "cc_library cppflags usage", |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 956 | moduleTypeUnderTest: "cc_library", |
| 957 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 958 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 959 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 960 | dir: "foo/bar", |
| 961 | filesystem: map[string]string{ |
| 962 | "foo/bar/Android.bp": `cc_library { |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 963 | name: "a", |
| 964 | srcs: ["a.cpp"], |
| 965 | cflags: [ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 966 | "-Wall", |
| 967 | ], |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 968 | cppflags: [ |
| 969 | "-fsigned-char", |
| 970 | "-pedantic", |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 971 | ], |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 972 | arch: { |
| 973 | arm64: { |
| 974 | cppflags: ["-DARM64=1"], |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 975 | }, |
| 976 | }, |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 977 | target: { |
| 978 | android: { |
| 979 | cppflags: ["-DANDROID=1"], |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 980 | }, |
| 981 | }, |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 982 | bazel_module: { bp2build_available: true }, |
| 983 | } |
| 984 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 985 | }, |
| 986 | blueprint: soongCcLibraryPreamble, |
| 987 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 988 | name = "a", |
| 989 | copts = [ |
| 990 | "-Wall", |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 991 | "-Ifoo/bar", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 992 | "-I$(BINDIR)/foo/bar", |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 993 | ], |
| 994 | cppflags = [ |
| 995 | "-fsigned-char", |
| 996 | "-pedantic", |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 997 | ] + select({ |
| 998 | "//build/bazel/platforms/arch:arm64": ["-DARM64=1"], |
| 999 | "//conditions:default": [], |
| 1000 | }) + select({ |
| 1001 | "//build/bazel/platforms/os:android": ["-DANDROID=1"], |
| 1002 | "//conditions:default": [], |
| 1003 | }), |
| 1004 | srcs = ["a.cpp"], |
| 1005 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1006 | }) |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 1007 | } |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 1008 | |
| 1009 | func TestCcLibraryLabelAttributeGetTargetProperties(t *testing.T) { |
| 1010 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1011 | description: "cc_library GetTargetProperties on a LabelAttribute", |
| 1012 | moduleTypeUnderTest: "cc_library", |
| 1013 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1014 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1015 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 1016 | dir: "foo/bar", |
| 1017 | filesystem: map[string]string{ |
| 1018 | "foo/bar/Android.bp": ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1019 | cc_library { |
| 1020 | name: "a", |
| 1021 | srcs: ["a.cpp"], |
| 1022 | target: { |
| 1023 | android_arm: { |
| 1024 | version_script: "android_arm.map", |
| 1025 | }, |
| 1026 | linux_bionic_arm64: { |
| 1027 | version_script: "linux_bionic_arm64.map", |
| 1028 | }, |
| 1029 | }, |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 1030 | |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1031 | bazel_module: { bp2build_available: true }, |
| 1032 | } |
| 1033 | `, |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 1034 | }, |
| 1035 | blueprint: soongCcLibraryPreamble, |
| 1036 | expectedBazelTargets: []string{`cc_library( |
| 1037 | name = "a", |
| 1038 | copts = [ |
| 1039 | "-Ifoo/bar", |
| 1040 | "-I$(BINDIR)/foo/bar", |
| 1041 | ], |
| 1042 | srcs = ["a.cpp"], |
| 1043 | version_script = select({ |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 1044 | "//build/bazel/platforms/os_arch:android_arm": "android_arm.map", |
| 1045 | "//build/bazel/platforms/os_arch:linux_bionic_arm64": "linux_bionic_arm64.map", |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 1046 | "//conditions:default": None, |
| 1047 | }), |
| 1048 | )`}, |
| 1049 | }) |
| 1050 | } |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1051 | |
| 1052 | func TestCcLibraryExcludeLibs(t *testing.T) { |
| 1053 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1054 | moduleTypeUnderTest: "cc_library", |
| 1055 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1056 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1057 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 1058 | filesystem: map[string]string{}, |
| 1059 | blueprint: soongCcLibraryStaticPreamble + ` |
| 1060 | cc_library { |
| 1061 | name: "foo_static", |
| 1062 | srcs: ["common.c"], |
| 1063 | whole_static_libs: [ |
| 1064 | "arm_whole_static_lib_excludes", |
| 1065 | "malloc_not_svelte_whole_static_lib_excludes" |
| 1066 | ], |
| 1067 | static_libs: [ |
| 1068 | "arm_static_lib_excludes", |
| 1069 | "malloc_not_svelte_static_lib_excludes" |
| 1070 | ], |
| 1071 | shared_libs: [ |
| 1072 | "arm_shared_lib_excludes", |
| 1073 | ], |
| 1074 | arch: { |
| 1075 | arm: { |
| 1076 | exclude_shared_libs: [ |
| 1077 | "arm_shared_lib_excludes", |
| 1078 | ], |
| 1079 | exclude_static_libs: [ |
| 1080 | "arm_static_lib_excludes", |
| 1081 | "arm_whole_static_lib_excludes", |
| 1082 | ], |
| 1083 | }, |
| 1084 | }, |
| 1085 | product_variables: { |
| 1086 | malloc_not_svelte: { |
| 1087 | shared_libs: ["malloc_not_svelte_shared_lib"], |
| 1088 | whole_static_libs: ["malloc_not_svelte_whole_static_lib"], |
| 1089 | exclude_static_libs: [ |
| 1090 | "malloc_not_svelte_static_lib_excludes", |
| 1091 | "malloc_not_svelte_whole_static_lib_excludes", |
| 1092 | ], |
| 1093 | }, |
| 1094 | }, |
| 1095 | } |
| 1096 | |
| 1097 | cc_library { |
| 1098 | name: "arm_whole_static_lib_excludes", |
| 1099 | bazel_module: { bp2build_available: false }, |
| 1100 | } |
| 1101 | |
| 1102 | cc_library { |
| 1103 | name: "malloc_not_svelte_whole_static_lib", |
| 1104 | bazel_module: { bp2build_available: false }, |
| 1105 | } |
| 1106 | |
| 1107 | cc_library { |
| 1108 | name: "malloc_not_svelte_whole_static_lib_excludes", |
| 1109 | bazel_module: { bp2build_available: false }, |
| 1110 | } |
| 1111 | |
| 1112 | cc_library { |
| 1113 | name: "arm_static_lib_excludes", |
| 1114 | bazel_module: { bp2build_available: false }, |
| 1115 | } |
| 1116 | |
| 1117 | cc_library { |
| 1118 | name: "malloc_not_svelte_static_lib_excludes", |
| 1119 | bazel_module: { bp2build_available: false }, |
| 1120 | } |
| 1121 | |
| 1122 | cc_library { |
| 1123 | name: "arm_shared_lib_excludes", |
| 1124 | bazel_module: { bp2build_available: false }, |
| 1125 | } |
| 1126 | |
| 1127 | cc_library { |
| 1128 | name: "malloc_not_svelte_shared_lib", |
| 1129 | bazel_module: { bp2build_available: false }, |
| 1130 | } |
| 1131 | `, |
| 1132 | expectedBazelTargets: []string{ |
| 1133 | `cc_library( |
| 1134 | name = "foo_static", |
| 1135 | copts = [ |
| 1136 | "-I.", |
| 1137 | "-I$(BINDIR)/.", |
| 1138 | ], |
| 1139 | dynamic_deps = select({ |
| 1140 | "//build/bazel/platforms/arch:arm": [], |
| 1141 | "//conditions:default": [":arm_shared_lib_excludes"], |
| 1142 | }) + select({ |
| 1143 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_shared_lib"], |
| 1144 | "//conditions:default": [], |
| 1145 | }), |
| 1146 | implementation_deps = select({ |
| 1147 | "//build/bazel/platforms/arch:arm": [], |
| 1148 | "//conditions:default": [":arm_static_lib_excludes"], |
| 1149 | }) + select({ |
| 1150 | "//build/bazel/product_variables:malloc_not_svelte": [], |
| 1151 | "//conditions:default": [":malloc_not_svelte_static_lib_excludes"], |
| 1152 | }), |
| 1153 | srcs_c = ["common.c"], |
| 1154 | whole_archive_deps = select({ |
| 1155 | "//build/bazel/platforms/arch:arm": [], |
| 1156 | "//conditions:default": [":arm_whole_static_lib_excludes"], |
| 1157 | }) + select({ |
| 1158 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_whole_static_lib"], |
| 1159 | "//conditions:default": [":malloc_not_svelte_whole_static_lib_excludes"], |
| 1160 | }), |
| 1161 | )`, |
| 1162 | }, |
| 1163 | }) |
| 1164 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1165 | |
| 1166 | func TestCCLibraryNoCrtTrue(t *testing.T) { |
| 1167 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1168 | description: "cc_library - simple example", |
| 1169 | moduleTypeUnderTest: "cc_library", |
| 1170 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1171 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1172 | filesystem: map[string]string{ |
| 1173 | "impl.cpp": "", |
| 1174 | }, |
| 1175 | blueprint: soongCcLibraryPreamble + ` |
| 1176 | cc_library_headers { name: "some-headers" } |
| 1177 | cc_library { |
| 1178 | name: "foo-lib", |
| 1179 | srcs: ["impl.cpp"], |
| 1180 | no_libcrt: true, |
| 1181 | } |
| 1182 | `, |
| 1183 | expectedBazelTargets: []string{`cc_library( |
| 1184 | name = "foo-lib", |
| 1185 | copts = [ |
| 1186 | "-I.", |
| 1187 | "-I$(BINDIR)/.", |
| 1188 | ], |
| 1189 | srcs = ["impl.cpp"], |
| 1190 | use_libcrt = False, |
| 1191 | )`}}) |
| 1192 | } |
| 1193 | |
| 1194 | func TestCCLibraryNoCrtFalse(t *testing.T) { |
| 1195 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1196 | moduleTypeUnderTest: "cc_library", |
| 1197 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1198 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1199 | filesystem: map[string]string{ |
| 1200 | "impl.cpp": "", |
| 1201 | }, |
| 1202 | blueprint: soongCcLibraryPreamble + ` |
| 1203 | cc_library_headers { name: "some-headers" } |
| 1204 | cc_library { |
| 1205 | name: "foo-lib", |
| 1206 | srcs: ["impl.cpp"], |
| 1207 | no_libcrt: false, |
| 1208 | } |
| 1209 | `, |
| 1210 | expectedBazelTargets: []string{`cc_library( |
| 1211 | name = "foo-lib", |
| 1212 | copts = [ |
| 1213 | "-I.", |
| 1214 | "-I$(BINDIR)/.", |
| 1215 | ], |
| 1216 | srcs = ["impl.cpp"], |
| 1217 | use_libcrt = True, |
| 1218 | )`}}) |
| 1219 | } |
| 1220 | |
| 1221 | func TestCCLibraryNoCrtArchVariant(t *testing.T) { |
| 1222 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1223 | moduleTypeUnderTest: "cc_library", |
| 1224 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1225 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1226 | filesystem: map[string]string{ |
| 1227 | "impl.cpp": "", |
| 1228 | }, |
| 1229 | blueprint: soongCcLibraryPreamble + ` |
| 1230 | cc_library_headers { name: "some-headers" } |
| 1231 | cc_library { |
| 1232 | name: "foo-lib", |
| 1233 | srcs: ["impl.cpp"], |
| 1234 | arch: { |
| 1235 | arm: { |
| 1236 | no_libcrt: true, |
| 1237 | }, |
| 1238 | x86: { |
| 1239 | no_libcrt: true, |
| 1240 | }, |
| 1241 | }, |
| 1242 | } |
| 1243 | `, |
| 1244 | expectedBazelTargets: []string{`cc_library( |
| 1245 | name = "foo-lib", |
| 1246 | copts = [ |
| 1247 | "-I.", |
| 1248 | "-I$(BINDIR)/.", |
| 1249 | ], |
| 1250 | srcs = ["impl.cpp"], |
| 1251 | use_libcrt = select({ |
| 1252 | "//build/bazel/platforms/arch:arm": False, |
| 1253 | "//build/bazel/platforms/arch:x86": False, |
| 1254 | "//conditions:default": None, |
| 1255 | }), |
| 1256 | )`}}) |
| 1257 | } |
| 1258 | |
| 1259 | func TestCCLibraryNoCrtArchVariantWithDefault(t *testing.T) { |
| 1260 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1261 | moduleTypeUnderTest: "cc_library", |
| 1262 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1263 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1264 | filesystem: map[string]string{ |
| 1265 | "impl.cpp": "", |
| 1266 | }, |
| 1267 | blueprint: soongCcLibraryPreamble + ` |
| 1268 | cc_library_headers { name: "some-headers" } |
| 1269 | cc_library { |
| 1270 | name: "foo-lib", |
| 1271 | srcs: ["impl.cpp"], |
| 1272 | no_libcrt: false, |
| 1273 | arch: { |
| 1274 | arm: { |
| 1275 | no_libcrt: true, |
| 1276 | }, |
| 1277 | x86: { |
| 1278 | no_libcrt: true, |
| 1279 | }, |
| 1280 | }, |
| 1281 | } |
| 1282 | `, |
| 1283 | expectedBazelTargets: []string{`cc_library( |
| 1284 | name = "foo-lib", |
| 1285 | copts = [ |
| 1286 | "-I.", |
| 1287 | "-I$(BINDIR)/.", |
| 1288 | ], |
| 1289 | srcs = ["impl.cpp"], |
| 1290 | use_libcrt = select({ |
| 1291 | "//build/bazel/platforms/arch:arm": False, |
| 1292 | "//build/bazel/platforms/arch:x86": False, |
| 1293 | "//conditions:default": True, |
| 1294 | }), |
| 1295 | )`}}) |
| 1296 | } |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1297 | |
| 1298 | func TestCcLibraryStrip(t *testing.T) { |
| 1299 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1300 | description: "cc_library strip args", |
| 1301 | moduleTypeUnderTest: "cc_library", |
| 1302 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1303 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1304 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 1305 | dir: "foo/bar", |
| 1306 | filesystem: map[string]string{ |
| 1307 | "foo/bar/Android.bp": ` |
| 1308 | cc_library { |
| 1309 | name: "nothing", |
| 1310 | bazel_module: { bp2build_available: true }, |
| 1311 | } |
| 1312 | cc_library { |
| 1313 | name: "keep_symbols", |
| 1314 | bazel_module: { bp2build_available: true }, |
| 1315 | strip: { |
| 1316 | keep_symbols: true, |
| 1317 | } |
| 1318 | } |
| 1319 | cc_library { |
| 1320 | name: "keep_symbols_and_debug_frame", |
| 1321 | bazel_module: { bp2build_available: true }, |
| 1322 | strip: { |
| 1323 | keep_symbols_and_debug_frame: true, |
| 1324 | } |
| 1325 | } |
| 1326 | cc_library { |
| 1327 | name: "none", |
| 1328 | bazel_module: { bp2build_available: true }, |
| 1329 | strip: { |
| 1330 | none: true, |
| 1331 | } |
| 1332 | } |
| 1333 | cc_library { |
| 1334 | name: "keep_symbols_list", |
| 1335 | bazel_module: { bp2build_available: true }, |
| 1336 | strip: { |
| 1337 | keep_symbols_list: ["symbol"], |
| 1338 | } |
| 1339 | } |
| 1340 | cc_library { |
| 1341 | name: "all", |
| 1342 | bazel_module: { bp2build_available: true }, |
| 1343 | strip: { |
| 1344 | all: true, |
| 1345 | } |
| 1346 | } |
| 1347 | `, |
| 1348 | }, |
| 1349 | blueprint: soongCcLibraryPreamble, |
| 1350 | expectedBazelTargets: []string{`cc_library( |
| 1351 | name = "all", |
| 1352 | copts = [ |
| 1353 | "-Ifoo/bar", |
| 1354 | "-I$(BINDIR)/foo/bar", |
| 1355 | ], |
| 1356 | strip = { |
| 1357 | "all": True, |
| 1358 | }, |
| 1359 | )`, `cc_library( |
| 1360 | name = "keep_symbols", |
| 1361 | copts = [ |
| 1362 | "-Ifoo/bar", |
| 1363 | "-I$(BINDIR)/foo/bar", |
| 1364 | ], |
| 1365 | strip = { |
| 1366 | "keep_symbols": True, |
| 1367 | }, |
| 1368 | )`, `cc_library( |
| 1369 | name = "keep_symbols_and_debug_frame", |
| 1370 | copts = [ |
| 1371 | "-Ifoo/bar", |
| 1372 | "-I$(BINDIR)/foo/bar", |
| 1373 | ], |
| 1374 | strip = { |
| 1375 | "keep_symbols_and_debug_frame": True, |
| 1376 | }, |
| 1377 | )`, `cc_library( |
| 1378 | name = "keep_symbols_list", |
| 1379 | copts = [ |
| 1380 | "-Ifoo/bar", |
| 1381 | "-I$(BINDIR)/foo/bar", |
| 1382 | ], |
| 1383 | strip = { |
| 1384 | "keep_symbols_list": ["symbol"], |
| 1385 | }, |
| 1386 | )`, `cc_library( |
| 1387 | name = "none", |
| 1388 | copts = [ |
| 1389 | "-Ifoo/bar", |
| 1390 | "-I$(BINDIR)/foo/bar", |
| 1391 | ], |
| 1392 | strip = { |
| 1393 | "none": True, |
| 1394 | }, |
| 1395 | )`, `cc_library( |
| 1396 | name = "nothing", |
| 1397 | copts = [ |
| 1398 | "-Ifoo/bar", |
| 1399 | "-I$(BINDIR)/foo/bar", |
| 1400 | ], |
| 1401 | )`}, |
| 1402 | }) |
| 1403 | } |
| 1404 | |
| 1405 | func TestCcLibraryStripWithArch(t *testing.T) { |
| 1406 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1407 | description: "cc_library strip args", |
| 1408 | moduleTypeUnderTest: "cc_library", |
| 1409 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1410 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1411 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 1412 | dir: "foo/bar", |
| 1413 | filesystem: map[string]string{ |
| 1414 | "foo/bar/Android.bp": ` |
| 1415 | cc_library { |
| 1416 | name: "multi-arch", |
| 1417 | bazel_module: { bp2build_available: true }, |
| 1418 | target: { |
| 1419 | darwin: { |
| 1420 | strip: { |
| 1421 | keep_symbols_list: ["foo", "bar"] |
| 1422 | } |
| 1423 | }, |
| 1424 | }, |
| 1425 | arch: { |
| 1426 | arm: { |
| 1427 | strip: { |
| 1428 | keep_symbols_and_debug_frame: true, |
| 1429 | }, |
| 1430 | }, |
| 1431 | arm64: { |
| 1432 | strip: { |
| 1433 | keep_symbols: true, |
| 1434 | }, |
| 1435 | }, |
| 1436 | } |
| 1437 | } |
| 1438 | `, |
| 1439 | }, |
| 1440 | blueprint: soongCcLibraryPreamble, |
| 1441 | expectedBazelTargets: []string{`cc_library( |
| 1442 | name = "multi-arch", |
| 1443 | copts = [ |
| 1444 | "-Ifoo/bar", |
| 1445 | "-I$(BINDIR)/foo/bar", |
| 1446 | ], |
| 1447 | strip = { |
| 1448 | "keep_symbols": select({ |
| 1449 | "//build/bazel/platforms/arch:arm64": True, |
| 1450 | "//conditions:default": None, |
| 1451 | }), |
| 1452 | "keep_symbols_and_debug_frame": select({ |
| 1453 | "//build/bazel/platforms/arch:arm": True, |
| 1454 | "//conditions:default": None, |
| 1455 | }), |
| 1456 | "keep_symbols_list": select({ |
| 1457 | "//build/bazel/platforms/os:darwin": [ |
| 1458 | "foo", |
| 1459 | "bar", |
| 1460 | ], |
| 1461 | "//conditions:default": [], |
| 1462 | }), |
| 1463 | }, |
| 1464 | )`}, |
| 1465 | }) |
| 1466 | } |