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", |
| 677 | copts = [ |
| 678 | "-Ifoo/bar", |
| 679 | "-I$(BINDIR)/foo/bar", |
| 680 | ], |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame^] | 681 | shared = { |
| 682 | "srcs": [ |
| 683 | ":shared_filegroup_cpp_srcs", |
| 684 | "shared_source.cc", |
| 685 | "shared_source.cpp", |
| 686 | ], |
| 687 | "srcs_as": [ |
| 688 | "shared_source.s", |
| 689 | "shared_source.S", |
| 690 | ":shared_filegroup_as_srcs", |
| 691 | ], |
| 692 | "srcs_c": [ |
| 693 | "shared_source.c", |
| 694 | ":shared_filegroup_c_srcs", |
| 695 | ], |
| 696 | }, |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 697 | srcs = [ |
| 698 | ":both_filegroup_cpp_srcs", |
| 699 | "both_source.cc", |
| 700 | "both_source.cpp", |
| 701 | ], |
| 702 | srcs_as = [ |
| 703 | "both_source.s", |
| 704 | "both_source.S", |
| 705 | ":both_filegroup_as_srcs", |
| 706 | ], |
| 707 | srcs_c = [ |
| 708 | "both_source.c", |
| 709 | ":both_filegroup_c_srcs", |
| 710 | ], |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame^] | 711 | static = { |
| 712 | "srcs": [ |
| 713 | ":static_filegroup_cpp_srcs", |
| 714 | "static_source.cc", |
| 715 | "static_source.cpp", |
| 716 | ], |
| 717 | "srcs_as": [ |
| 718 | "static_source.s", |
| 719 | "static_source.S", |
| 720 | ":static_filegroup_as_srcs", |
| 721 | ], |
| 722 | "srcs_c": [ |
| 723 | "static_source.c", |
| 724 | ":static_filegroup_c_srcs", |
| 725 | ], |
| 726 | }, |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 727 | )`}, |
| 728 | }) |
| 729 | } |
| 730 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 731 | func TestCcLibraryNonConfiguredVersionScript(t *testing.T) { |
| 732 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 733 | description: "cc_library non-configured version script", |
| 734 | moduleTypeUnderTest: "cc_library", |
| 735 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 736 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 737 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 738 | dir: "foo/bar", |
| 739 | filesystem: map[string]string{ |
| 740 | "foo/bar/Android.bp": ` |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 741 | cc_library { |
| 742 | name: "a", |
| 743 | srcs: ["a.cpp"], |
| 744 | version_script: "v.map", |
| 745 | bazel_module: { bp2build_available: true }, |
| 746 | } |
| 747 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 748 | }, |
| 749 | blueprint: soongCcLibraryPreamble, |
| 750 | expectedBazelTargets: []string{`cc_library( |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 751 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 752 | copts = [ |
| 753 | "-Ifoo/bar", |
| 754 | "-I$(BINDIR)/foo/bar", |
| 755 | ], |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 756 | srcs = ["a.cpp"], |
| 757 | version_script = "v.map", |
| 758 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 759 | }) |
| 760 | } |
| 761 | |
| 762 | func TestCcLibraryConfiguredVersionScript(t *testing.T) { |
| 763 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 764 | description: "cc_library configured version script", |
| 765 | moduleTypeUnderTest: "cc_library", |
| 766 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 767 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 768 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 769 | dir: "foo/bar", |
| 770 | filesystem: map[string]string{ |
| 771 | "foo/bar/Android.bp": ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 772 | cc_library { |
| 773 | name: "a", |
| 774 | srcs: ["a.cpp"], |
| 775 | arch: { |
| 776 | arm: { |
| 777 | version_script: "arm.map", |
| 778 | }, |
| 779 | arm64: { |
| 780 | version_script: "arm64.map", |
| 781 | }, |
| 782 | }, |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 783 | |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 784 | bazel_module: { bp2build_available: true }, |
| 785 | } |
| 786 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 787 | }, |
| 788 | blueprint: soongCcLibraryPreamble, |
| 789 | expectedBazelTargets: []string{`cc_library( |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 790 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 791 | copts = [ |
| 792 | "-Ifoo/bar", |
| 793 | "-I$(BINDIR)/foo/bar", |
| 794 | ], |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 795 | srcs = ["a.cpp"], |
| 796 | version_script = select({ |
| 797 | "//build/bazel/platforms/arch:arm": "arm.map", |
| 798 | "//build/bazel/platforms/arch:arm64": "arm64.map", |
| 799 | "//conditions:default": None, |
| 800 | }), |
| 801 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 802 | }) |
| 803 | } |
| 804 | |
| 805 | func TestCcLibrarySharedLibs(t *testing.T) { |
| 806 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 807 | description: "cc_library shared_libs", |
| 808 | moduleTypeUnderTest: "cc_library", |
| 809 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 810 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 811 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 812 | dir: "foo/bar", |
| 813 | filesystem: map[string]string{ |
| 814 | "foo/bar/Android.bp": ` |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 815 | cc_library { |
| 816 | name: "mylib", |
| 817 | bazel_module: { bp2build_available: true }, |
| 818 | } |
| 819 | |
| 820 | cc_library { |
| 821 | name: "a", |
| 822 | shared_libs: ["mylib",], |
| 823 | bazel_module: { bp2build_available: true }, |
| 824 | } |
| 825 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 826 | }, |
| 827 | blueprint: soongCcLibraryPreamble, |
| 828 | expectedBazelTargets: []string{`cc_library( |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 829 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 830 | copts = [ |
| 831 | "-Ifoo/bar", |
| 832 | "-I$(BINDIR)/foo/bar", |
| 833 | ], |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 834 | dynamic_deps = [":mylib"], |
| 835 | )`, `cc_library( |
| 836 | name = "mylib", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 837 | copts = [ |
| 838 | "-Ifoo/bar", |
| 839 | "-I$(BINDIR)/foo/bar", |
| 840 | ], |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 841 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 842 | }) |
| 843 | } |
| 844 | |
| 845 | func TestCcLibraryPackRelocations(t *testing.T) { |
| 846 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 847 | description: "cc_library pack_relocations test", |
| 848 | moduleTypeUnderTest: "cc_library", |
| 849 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 850 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 851 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 852 | dir: "foo/bar", |
| 853 | filesystem: map[string]string{ |
| 854 | "foo/bar/Android.bp": ` |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 855 | cc_library { |
| 856 | name: "a", |
| 857 | srcs: ["a.cpp"], |
| 858 | pack_relocations: false, |
| 859 | bazel_module: { bp2build_available: true }, |
| 860 | } |
| 861 | |
| 862 | cc_library { |
| 863 | name: "b", |
| 864 | srcs: ["b.cpp"], |
| 865 | arch: { |
| 866 | x86_64: { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 867 | pack_relocations: false, |
| 868 | }, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 869 | }, |
| 870 | bazel_module: { bp2build_available: true }, |
| 871 | } |
| 872 | |
| 873 | cc_library { |
| 874 | name: "c", |
| 875 | srcs: ["c.cpp"], |
| 876 | target: { |
| 877 | darwin: { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 878 | pack_relocations: false, |
| 879 | }, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 880 | }, |
| 881 | bazel_module: { bp2build_available: true }, |
| 882 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 883 | }, |
| 884 | blueprint: soongCcLibraryPreamble, |
| 885 | expectedBazelTargets: []string{`cc_library( |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 886 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 887 | copts = [ |
| 888 | "-Ifoo/bar", |
| 889 | "-I$(BINDIR)/foo/bar", |
| 890 | ], |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 891 | linkopts = ["-Wl,--pack-dyn-relocs=none"], |
| 892 | srcs = ["a.cpp"], |
| 893 | )`, `cc_library( |
| 894 | name = "b", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 895 | copts = [ |
| 896 | "-Ifoo/bar", |
| 897 | "-I$(BINDIR)/foo/bar", |
| 898 | ], |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 899 | linkopts = select({ |
| 900 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--pack-dyn-relocs=none"], |
| 901 | "//conditions:default": [], |
| 902 | }), |
| 903 | srcs = ["b.cpp"], |
| 904 | )`, `cc_library( |
| 905 | name = "c", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 906 | copts = [ |
| 907 | "-Ifoo/bar", |
| 908 | "-I$(BINDIR)/foo/bar", |
| 909 | ], |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 910 | linkopts = select({ |
| 911 | "//build/bazel/platforms/os:darwin": ["-Wl,--pack-dyn-relocs=none"], |
| 912 | "//conditions:default": [], |
| 913 | }), |
| 914 | srcs = ["c.cpp"], |
| 915 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 916 | }) |
| 917 | } |
| 918 | |
| 919 | func TestCcLibrarySpacesInCopts(t *testing.T) { |
| 920 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 921 | description: "cc_library spaces in copts", |
| 922 | moduleTypeUnderTest: "cc_library", |
| 923 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 924 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 925 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 926 | dir: "foo/bar", |
| 927 | filesystem: map[string]string{ |
| 928 | "foo/bar/Android.bp": ` |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 929 | cc_library { |
| 930 | name: "a", |
| 931 | cflags: ["-include header.h",], |
| 932 | bazel_module: { bp2build_available: true }, |
| 933 | } |
| 934 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 935 | }, |
| 936 | blueprint: soongCcLibraryPreamble, |
| 937 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 938 | name = "a", |
| 939 | copts = [ |
| 940 | "-include", |
| 941 | "header.h", |
| 942 | "-Ifoo/bar", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 943 | "-I$(BINDIR)/foo/bar", |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 944 | ], |
| 945 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 946 | }) |
| 947 | } |
| 948 | |
| 949 | func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { |
| 950 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 951 | description: "cc_library cppflags usage", |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 952 | moduleTypeUnderTest: "cc_library", |
| 953 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 954 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 955 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 956 | dir: "foo/bar", |
| 957 | filesystem: map[string]string{ |
| 958 | "foo/bar/Android.bp": `cc_library { |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 959 | name: "a", |
| 960 | srcs: ["a.cpp"], |
| 961 | cflags: [ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 962 | "-Wall", |
| 963 | ], |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 964 | cppflags: [ |
| 965 | "-fsigned-char", |
| 966 | "-pedantic", |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 967 | ], |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 968 | arch: { |
| 969 | arm64: { |
| 970 | cppflags: ["-DARM64=1"], |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 971 | }, |
| 972 | }, |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 973 | target: { |
| 974 | android: { |
| 975 | cppflags: ["-DANDROID=1"], |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 976 | }, |
| 977 | }, |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 978 | bazel_module: { bp2build_available: true }, |
| 979 | } |
| 980 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 981 | }, |
| 982 | blueprint: soongCcLibraryPreamble, |
| 983 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 984 | name = "a", |
| 985 | copts = [ |
| 986 | "-Wall", |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 987 | "-Ifoo/bar", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 988 | "-I$(BINDIR)/foo/bar", |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 989 | ], |
| 990 | cppflags = [ |
| 991 | "-fsigned-char", |
| 992 | "-pedantic", |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 993 | ] + select({ |
| 994 | "//build/bazel/platforms/arch:arm64": ["-DARM64=1"], |
| 995 | "//conditions:default": [], |
| 996 | }) + select({ |
| 997 | "//build/bazel/platforms/os:android": ["-DANDROID=1"], |
| 998 | "//conditions:default": [], |
| 999 | }), |
| 1000 | srcs = ["a.cpp"], |
| 1001 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1002 | }) |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 1003 | } |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 1004 | |
| 1005 | func TestCcLibraryLabelAttributeGetTargetProperties(t *testing.T) { |
| 1006 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1007 | description: "cc_library GetTargetProperties on a LabelAttribute", |
| 1008 | moduleTypeUnderTest: "cc_library", |
| 1009 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1010 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1011 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 1012 | dir: "foo/bar", |
| 1013 | filesystem: map[string]string{ |
| 1014 | "foo/bar/Android.bp": ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1015 | cc_library { |
| 1016 | name: "a", |
| 1017 | srcs: ["a.cpp"], |
| 1018 | target: { |
| 1019 | android_arm: { |
| 1020 | version_script: "android_arm.map", |
| 1021 | }, |
| 1022 | linux_bionic_arm64: { |
| 1023 | version_script: "linux_bionic_arm64.map", |
| 1024 | }, |
| 1025 | }, |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 1026 | |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1027 | bazel_module: { bp2build_available: true }, |
| 1028 | } |
| 1029 | `, |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 1030 | }, |
| 1031 | blueprint: soongCcLibraryPreamble, |
| 1032 | expectedBazelTargets: []string{`cc_library( |
| 1033 | name = "a", |
| 1034 | copts = [ |
| 1035 | "-Ifoo/bar", |
| 1036 | "-I$(BINDIR)/foo/bar", |
| 1037 | ], |
| 1038 | srcs = ["a.cpp"], |
| 1039 | version_script = select({ |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 1040 | "//build/bazel/platforms/os_arch:android_arm": "android_arm.map", |
| 1041 | "//build/bazel/platforms/os_arch:linux_bionic_arm64": "linux_bionic_arm64.map", |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 1042 | "//conditions:default": None, |
| 1043 | }), |
| 1044 | )`}, |
| 1045 | }) |
| 1046 | } |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1047 | |
| 1048 | func TestCcLibraryExcludeLibs(t *testing.T) { |
| 1049 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1050 | moduleTypeUnderTest: "cc_library", |
| 1051 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1052 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1053 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 1054 | filesystem: map[string]string{}, |
| 1055 | blueprint: soongCcLibraryStaticPreamble + ` |
| 1056 | cc_library { |
| 1057 | name: "foo_static", |
| 1058 | srcs: ["common.c"], |
| 1059 | whole_static_libs: [ |
| 1060 | "arm_whole_static_lib_excludes", |
| 1061 | "malloc_not_svelte_whole_static_lib_excludes" |
| 1062 | ], |
| 1063 | static_libs: [ |
| 1064 | "arm_static_lib_excludes", |
| 1065 | "malloc_not_svelte_static_lib_excludes" |
| 1066 | ], |
| 1067 | shared_libs: [ |
| 1068 | "arm_shared_lib_excludes", |
| 1069 | ], |
| 1070 | arch: { |
| 1071 | arm: { |
| 1072 | exclude_shared_libs: [ |
| 1073 | "arm_shared_lib_excludes", |
| 1074 | ], |
| 1075 | exclude_static_libs: [ |
| 1076 | "arm_static_lib_excludes", |
| 1077 | "arm_whole_static_lib_excludes", |
| 1078 | ], |
| 1079 | }, |
| 1080 | }, |
| 1081 | product_variables: { |
| 1082 | malloc_not_svelte: { |
| 1083 | shared_libs: ["malloc_not_svelte_shared_lib"], |
| 1084 | whole_static_libs: ["malloc_not_svelte_whole_static_lib"], |
| 1085 | exclude_static_libs: [ |
| 1086 | "malloc_not_svelte_static_lib_excludes", |
| 1087 | "malloc_not_svelte_whole_static_lib_excludes", |
| 1088 | ], |
| 1089 | }, |
| 1090 | }, |
| 1091 | } |
| 1092 | |
| 1093 | cc_library { |
| 1094 | name: "arm_whole_static_lib_excludes", |
| 1095 | bazel_module: { bp2build_available: false }, |
| 1096 | } |
| 1097 | |
| 1098 | cc_library { |
| 1099 | name: "malloc_not_svelte_whole_static_lib", |
| 1100 | bazel_module: { bp2build_available: false }, |
| 1101 | } |
| 1102 | |
| 1103 | cc_library { |
| 1104 | name: "malloc_not_svelte_whole_static_lib_excludes", |
| 1105 | bazel_module: { bp2build_available: false }, |
| 1106 | } |
| 1107 | |
| 1108 | cc_library { |
| 1109 | name: "arm_static_lib_excludes", |
| 1110 | bazel_module: { bp2build_available: false }, |
| 1111 | } |
| 1112 | |
| 1113 | cc_library { |
| 1114 | name: "malloc_not_svelte_static_lib_excludes", |
| 1115 | bazel_module: { bp2build_available: false }, |
| 1116 | } |
| 1117 | |
| 1118 | cc_library { |
| 1119 | name: "arm_shared_lib_excludes", |
| 1120 | bazel_module: { bp2build_available: false }, |
| 1121 | } |
| 1122 | |
| 1123 | cc_library { |
| 1124 | name: "malloc_not_svelte_shared_lib", |
| 1125 | bazel_module: { bp2build_available: false }, |
| 1126 | } |
| 1127 | `, |
| 1128 | expectedBazelTargets: []string{ |
| 1129 | `cc_library( |
| 1130 | name = "foo_static", |
| 1131 | copts = [ |
| 1132 | "-I.", |
| 1133 | "-I$(BINDIR)/.", |
| 1134 | ], |
| 1135 | dynamic_deps = select({ |
| 1136 | "//build/bazel/platforms/arch:arm": [], |
| 1137 | "//conditions:default": [":arm_shared_lib_excludes"], |
| 1138 | }) + select({ |
| 1139 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_shared_lib"], |
| 1140 | "//conditions:default": [], |
| 1141 | }), |
| 1142 | implementation_deps = select({ |
| 1143 | "//build/bazel/platforms/arch:arm": [], |
| 1144 | "//conditions:default": [":arm_static_lib_excludes"], |
| 1145 | }) + select({ |
| 1146 | "//build/bazel/product_variables:malloc_not_svelte": [], |
| 1147 | "//conditions:default": [":malloc_not_svelte_static_lib_excludes"], |
| 1148 | }), |
| 1149 | srcs_c = ["common.c"], |
| 1150 | whole_archive_deps = select({ |
| 1151 | "//build/bazel/platforms/arch:arm": [], |
| 1152 | "//conditions:default": [":arm_whole_static_lib_excludes"], |
| 1153 | }) + select({ |
| 1154 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_whole_static_lib"], |
| 1155 | "//conditions:default": [":malloc_not_svelte_whole_static_lib_excludes"], |
| 1156 | }), |
| 1157 | )`, |
| 1158 | }, |
| 1159 | }) |
| 1160 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1161 | |
| 1162 | func TestCCLibraryNoCrtTrue(t *testing.T) { |
| 1163 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1164 | description: "cc_library - simple example", |
| 1165 | moduleTypeUnderTest: "cc_library", |
| 1166 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1167 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1168 | filesystem: map[string]string{ |
| 1169 | "impl.cpp": "", |
| 1170 | }, |
| 1171 | blueprint: soongCcLibraryPreamble + ` |
| 1172 | cc_library_headers { name: "some-headers" } |
| 1173 | cc_library { |
| 1174 | name: "foo-lib", |
| 1175 | srcs: ["impl.cpp"], |
| 1176 | no_libcrt: true, |
| 1177 | } |
| 1178 | `, |
| 1179 | expectedBazelTargets: []string{`cc_library( |
| 1180 | name = "foo-lib", |
| 1181 | copts = [ |
| 1182 | "-I.", |
| 1183 | "-I$(BINDIR)/.", |
| 1184 | ], |
| 1185 | srcs = ["impl.cpp"], |
| 1186 | use_libcrt = False, |
| 1187 | )`}}) |
| 1188 | } |
| 1189 | |
| 1190 | func TestCCLibraryNoCrtFalse(t *testing.T) { |
| 1191 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1192 | moduleTypeUnderTest: "cc_library", |
| 1193 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1194 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1195 | filesystem: map[string]string{ |
| 1196 | "impl.cpp": "", |
| 1197 | }, |
| 1198 | blueprint: soongCcLibraryPreamble + ` |
| 1199 | cc_library_headers { name: "some-headers" } |
| 1200 | cc_library { |
| 1201 | name: "foo-lib", |
| 1202 | srcs: ["impl.cpp"], |
| 1203 | no_libcrt: false, |
| 1204 | } |
| 1205 | `, |
| 1206 | expectedBazelTargets: []string{`cc_library( |
| 1207 | name = "foo-lib", |
| 1208 | copts = [ |
| 1209 | "-I.", |
| 1210 | "-I$(BINDIR)/.", |
| 1211 | ], |
| 1212 | srcs = ["impl.cpp"], |
| 1213 | use_libcrt = True, |
| 1214 | )`}}) |
| 1215 | } |
| 1216 | |
| 1217 | func TestCCLibraryNoCrtArchVariant(t *testing.T) { |
| 1218 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1219 | moduleTypeUnderTest: "cc_library", |
| 1220 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1221 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1222 | filesystem: map[string]string{ |
| 1223 | "impl.cpp": "", |
| 1224 | }, |
| 1225 | blueprint: soongCcLibraryPreamble + ` |
| 1226 | cc_library_headers { name: "some-headers" } |
| 1227 | cc_library { |
| 1228 | name: "foo-lib", |
| 1229 | srcs: ["impl.cpp"], |
| 1230 | arch: { |
| 1231 | arm: { |
| 1232 | no_libcrt: true, |
| 1233 | }, |
| 1234 | x86: { |
| 1235 | no_libcrt: true, |
| 1236 | }, |
| 1237 | }, |
| 1238 | } |
| 1239 | `, |
| 1240 | expectedBazelTargets: []string{`cc_library( |
| 1241 | name = "foo-lib", |
| 1242 | copts = [ |
| 1243 | "-I.", |
| 1244 | "-I$(BINDIR)/.", |
| 1245 | ], |
| 1246 | srcs = ["impl.cpp"], |
| 1247 | use_libcrt = select({ |
| 1248 | "//build/bazel/platforms/arch:arm": False, |
| 1249 | "//build/bazel/platforms/arch:x86": False, |
| 1250 | "//conditions:default": None, |
| 1251 | }), |
| 1252 | )`}}) |
| 1253 | } |
| 1254 | |
| 1255 | func TestCCLibraryNoCrtArchVariantWithDefault(t *testing.T) { |
| 1256 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1257 | moduleTypeUnderTest: "cc_library", |
| 1258 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1259 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1260 | filesystem: map[string]string{ |
| 1261 | "impl.cpp": "", |
| 1262 | }, |
| 1263 | blueprint: soongCcLibraryPreamble + ` |
| 1264 | cc_library_headers { name: "some-headers" } |
| 1265 | cc_library { |
| 1266 | name: "foo-lib", |
| 1267 | srcs: ["impl.cpp"], |
| 1268 | no_libcrt: false, |
| 1269 | arch: { |
| 1270 | arm: { |
| 1271 | no_libcrt: true, |
| 1272 | }, |
| 1273 | x86: { |
| 1274 | no_libcrt: true, |
| 1275 | }, |
| 1276 | }, |
| 1277 | } |
| 1278 | `, |
| 1279 | expectedBazelTargets: []string{`cc_library( |
| 1280 | name = "foo-lib", |
| 1281 | copts = [ |
| 1282 | "-I.", |
| 1283 | "-I$(BINDIR)/.", |
| 1284 | ], |
| 1285 | srcs = ["impl.cpp"], |
| 1286 | use_libcrt = select({ |
| 1287 | "//build/bazel/platforms/arch:arm": False, |
| 1288 | "//build/bazel/platforms/arch:x86": False, |
| 1289 | "//conditions:default": True, |
| 1290 | }), |
| 1291 | )`}}) |
| 1292 | } |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1293 | |
| 1294 | func TestCcLibraryStrip(t *testing.T) { |
| 1295 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1296 | description: "cc_library strip args", |
| 1297 | moduleTypeUnderTest: "cc_library", |
| 1298 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1299 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1300 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 1301 | dir: "foo/bar", |
| 1302 | filesystem: map[string]string{ |
| 1303 | "foo/bar/Android.bp": ` |
| 1304 | cc_library { |
| 1305 | name: "nothing", |
| 1306 | bazel_module: { bp2build_available: true }, |
| 1307 | } |
| 1308 | cc_library { |
| 1309 | name: "keep_symbols", |
| 1310 | bazel_module: { bp2build_available: true }, |
| 1311 | strip: { |
| 1312 | keep_symbols: true, |
| 1313 | } |
| 1314 | } |
| 1315 | cc_library { |
| 1316 | name: "keep_symbols_and_debug_frame", |
| 1317 | bazel_module: { bp2build_available: true }, |
| 1318 | strip: { |
| 1319 | keep_symbols_and_debug_frame: true, |
| 1320 | } |
| 1321 | } |
| 1322 | cc_library { |
| 1323 | name: "none", |
| 1324 | bazel_module: { bp2build_available: true }, |
| 1325 | strip: { |
| 1326 | none: true, |
| 1327 | } |
| 1328 | } |
| 1329 | cc_library { |
| 1330 | name: "keep_symbols_list", |
| 1331 | bazel_module: { bp2build_available: true }, |
| 1332 | strip: { |
| 1333 | keep_symbols_list: ["symbol"], |
| 1334 | } |
| 1335 | } |
| 1336 | cc_library { |
| 1337 | name: "all", |
| 1338 | bazel_module: { bp2build_available: true }, |
| 1339 | strip: { |
| 1340 | all: true, |
| 1341 | } |
| 1342 | } |
| 1343 | `, |
| 1344 | }, |
| 1345 | blueprint: soongCcLibraryPreamble, |
| 1346 | expectedBazelTargets: []string{`cc_library( |
| 1347 | name = "all", |
| 1348 | copts = [ |
| 1349 | "-Ifoo/bar", |
| 1350 | "-I$(BINDIR)/foo/bar", |
| 1351 | ], |
| 1352 | strip = { |
| 1353 | "all": True, |
| 1354 | }, |
| 1355 | )`, `cc_library( |
| 1356 | name = "keep_symbols", |
| 1357 | copts = [ |
| 1358 | "-Ifoo/bar", |
| 1359 | "-I$(BINDIR)/foo/bar", |
| 1360 | ], |
| 1361 | strip = { |
| 1362 | "keep_symbols": True, |
| 1363 | }, |
| 1364 | )`, `cc_library( |
| 1365 | name = "keep_symbols_and_debug_frame", |
| 1366 | copts = [ |
| 1367 | "-Ifoo/bar", |
| 1368 | "-I$(BINDIR)/foo/bar", |
| 1369 | ], |
| 1370 | strip = { |
| 1371 | "keep_symbols_and_debug_frame": True, |
| 1372 | }, |
| 1373 | )`, `cc_library( |
| 1374 | name = "keep_symbols_list", |
| 1375 | copts = [ |
| 1376 | "-Ifoo/bar", |
| 1377 | "-I$(BINDIR)/foo/bar", |
| 1378 | ], |
| 1379 | strip = { |
| 1380 | "keep_symbols_list": ["symbol"], |
| 1381 | }, |
| 1382 | )`, `cc_library( |
| 1383 | name = "none", |
| 1384 | copts = [ |
| 1385 | "-Ifoo/bar", |
| 1386 | "-I$(BINDIR)/foo/bar", |
| 1387 | ], |
| 1388 | strip = { |
| 1389 | "none": True, |
| 1390 | }, |
| 1391 | )`, `cc_library( |
| 1392 | name = "nothing", |
| 1393 | copts = [ |
| 1394 | "-Ifoo/bar", |
| 1395 | "-I$(BINDIR)/foo/bar", |
| 1396 | ], |
| 1397 | )`}, |
| 1398 | }) |
| 1399 | } |
| 1400 | |
| 1401 | func TestCcLibraryStripWithArch(t *testing.T) { |
| 1402 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1403 | description: "cc_library strip args", |
| 1404 | moduleTypeUnderTest: "cc_library", |
| 1405 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1406 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1407 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 1408 | dir: "foo/bar", |
| 1409 | filesystem: map[string]string{ |
| 1410 | "foo/bar/Android.bp": ` |
| 1411 | cc_library { |
| 1412 | name: "multi-arch", |
| 1413 | bazel_module: { bp2build_available: true }, |
| 1414 | target: { |
| 1415 | darwin: { |
| 1416 | strip: { |
| 1417 | keep_symbols_list: ["foo", "bar"] |
| 1418 | } |
| 1419 | }, |
| 1420 | }, |
| 1421 | arch: { |
| 1422 | arm: { |
| 1423 | strip: { |
| 1424 | keep_symbols_and_debug_frame: true, |
| 1425 | }, |
| 1426 | }, |
| 1427 | arm64: { |
| 1428 | strip: { |
| 1429 | keep_symbols: true, |
| 1430 | }, |
| 1431 | }, |
| 1432 | } |
| 1433 | } |
| 1434 | `, |
| 1435 | }, |
| 1436 | blueprint: soongCcLibraryPreamble, |
| 1437 | expectedBazelTargets: []string{`cc_library( |
| 1438 | name = "multi-arch", |
| 1439 | copts = [ |
| 1440 | "-Ifoo/bar", |
| 1441 | "-I$(BINDIR)/foo/bar", |
| 1442 | ], |
| 1443 | strip = { |
| 1444 | "keep_symbols": select({ |
| 1445 | "//build/bazel/platforms/arch:arm64": True, |
| 1446 | "//conditions:default": None, |
| 1447 | }), |
| 1448 | "keep_symbols_and_debug_frame": select({ |
| 1449 | "//build/bazel/platforms/arch:arm": True, |
| 1450 | "//conditions:default": None, |
| 1451 | }), |
| 1452 | "keep_symbols_list": select({ |
| 1453 | "//build/bazel/platforms/os:darwin": [ |
| 1454 | "foo", |
| 1455 | "bar", |
| 1456 | ], |
| 1457 | "//conditions:default": [], |
| 1458 | }), |
| 1459 | }, |
| 1460 | )`}, |
| 1461 | }) |
| 1462 | } |