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"], |
| 388 | dynamic_deps_for_shared = [":shared_dep_for_shared"], |
| 389 | dynamic_deps_for_static = [":shared_dep_for_static"], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 390 | implementation_deps = [":static_dep_for_both"], |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 391 | shared_copts = ["sharedflag"], |
| 392 | shared_srcs = ["sharedonly.cpp"], |
| 393 | srcs = ["both.cpp"], |
| 394 | static_copts = ["staticflag"], |
| 395 | static_deps_for_shared = [":static_dep_for_shared"], |
| 396 | static_deps_for_static = [":static_dep_for_static"], |
| 397 | static_srcs = ["staticonly.cpp"], |
| 398 | whole_archive_deps = [":whole_static_lib_for_both"], |
| 399 | whole_archive_deps_for_shared = [":whole_static_lib_for_shared"], |
| 400 | whole_archive_deps_for_static = [":whole_static_lib_for_static"], |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 401 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 402 | }) |
| 403 | } |
| 404 | |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame^] | 405 | func TestCcLibraryWholeStaticLibsAlwaysLink(t *testing.T) { |
| 406 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 407 | moduleTypeUnderTest: "cc_library", |
| 408 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 409 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 410 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 411 | dir: "foo/bar", |
| 412 | filesystem: map[string]string{ |
| 413 | "foo/bar/Android.bp": ` |
| 414 | cc_library { |
| 415 | name: "a", |
| 416 | whole_static_libs: ["whole_static_lib_for_both"], |
| 417 | static: { |
| 418 | whole_static_libs: ["whole_static_lib_for_static"], |
| 419 | }, |
| 420 | shared: { |
| 421 | whole_static_libs: ["whole_static_lib_for_shared"], |
| 422 | }, |
| 423 | bazel_module: { bp2build_available: true }, |
| 424 | } |
| 425 | |
| 426 | cc_prebuilt_library_static { name: "whole_static_lib_for_shared" } |
| 427 | |
| 428 | cc_prebuilt_library_static { name: "whole_static_lib_for_static" } |
| 429 | |
| 430 | cc_prebuilt_library_static { name: "whole_static_lib_for_both" } |
| 431 | `, |
| 432 | }, |
| 433 | blueprint: soongCcLibraryPreamble, |
| 434 | expectedBazelTargets: []string{`cc_library( |
| 435 | name = "a", |
| 436 | copts = [ |
| 437 | "-Ifoo/bar", |
| 438 | "-I$(BINDIR)/foo/bar", |
| 439 | ], |
| 440 | whole_archive_deps = [":whole_static_lib_for_both_alwayslink"], |
| 441 | whole_archive_deps_for_shared = [":whole_static_lib_for_shared_alwayslink"], |
| 442 | whole_archive_deps_for_static = [":whole_static_lib_for_static_alwayslink"], |
| 443 | )`}, |
| 444 | }) |
| 445 | } |
| 446 | |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 447 | func TestCcLibrarySharedStaticPropsInArch(t *testing.T) { |
| 448 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 449 | description: "cc_library shared/static props in arch", |
| 450 | moduleTypeUnderTest: "cc_library", |
| 451 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 452 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 453 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 454 | dir: "foo/bar", |
| 455 | filesystem: map[string]string{ |
| 456 | "foo/bar/arm.cpp": "", |
| 457 | "foo/bar/x86.cpp": "", |
| 458 | "foo/bar/sharedonly.cpp": "", |
| 459 | "foo/bar/staticonly.cpp": "", |
| 460 | "foo/bar/Android.bp": ` |
| 461 | cc_library { |
| 462 | name: "a", |
| 463 | arch: { |
| 464 | arm: { |
| 465 | shared: { |
| 466 | srcs: ["arm_shared.cpp"], |
| 467 | cflags: ["-DARM_SHARED"], |
| 468 | static_libs: ["arm_static_dep_for_shared"], |
| 469 | whole_static_libs: ["arm_whole_static_dep_for_shared"], |
| 470 | shared_libs: ["arm_shared_dep_for_shared"], |
| 471 | }, |
| 472 | }, |
| 473 | x86: { |
| 474 | static: { |
| 475 | srcs: ["x86_static.cpp"], |
| 476 | cflags: ["-DX86_STATIC"], |
| 477 | static_libs: ["x86_dep_for_static"], |
| 478 | }, |
| 479 | }, |
| 480 | }, |
| 481 | target: { |
| 482 | android: { |
| 483 | shared: { |
| 484 | srcs: ["android_shared.cpp"], |
| 485 | cflags: ["-DANDROID_SHARED"], |
| 486 | static_libs: ["android_dep_for_shared"], |
| 487 | }, |
| 488 | }, |
| 489 | android_arm: { |
| 490 | shared: { |
| 491 | cflags: ["-DANDROID_ARM_SHARED"], |
| 492 | }, |
| 493 | }, |
| 494 | }, |
| 495 | srcs: ["both.cpp"], |
| 496 | cflags: ["bothflag"], |
| 497 | static_libs: ["static_dep_for_both"], |
| 498 | static: { |
| 499 | srcs: ["staticonly.cpp"], |
| 500 | cflags: ["staticflag"], |
| 501 | static_libs: ["static_dep_for_static"], |
| 502 | }, |
| 503 | shared: { |
| 504 | srcs: ["sharedonly.cpp"], |
| 505 | cflags: ["sharedflag"], |
| 506 | static_libs: ["static_dep_for_shared"], |
| 507 | }, |
| 508 | bazel_module: { bp2build_available: true }, |
| 509 | } |
| 510 | |
| 511 | cc_library_static { name: "static_dep_for_shared" } |
| 512 | cc_library_static { name: "static_dep_for_static" } |
| 513 | cc_library_static { name: "static_dep_for_both" } |
| 514 | |
| 515 | cc_library_static { name: "arm_static_dep_for_shared" } |
| 516 | cc_library_static { name: "arm_whole_static_dep_for_shared" } |
| 517 | cc_library_static { name: "arm_shared_dep_for_shared" } |
| 518 | |
| 519 | cc_library_static { name: "x86_dep_for_static" } |
| 520 | |
| 521 | cc_library_static { name: "android_dep_for_shared" } |
| 522 | `, |
| 523 | }, |
| 524 | blueprint: soongCcLibraryPreamble, |
| 525 | expectedBazelTargets: []string{`cc_library( |
| 526 | name = "a", |
| 527 | copts = [ |
| 528 | "bothflag", |
| 529 | "-Ifoo/bar", |
| 530 | "-I$(BINDIR)/foo/bar", |
| 531 | ], |
| 532 | dynamic_deps_for_shared = select({ |
| 533 | "//build/bazel/platforms/arch:arm": [":arm_shared_dep_for_shared"], |
| 534 | "//conditions:default": [], |
| 535 | }), |
| 536 | implementation_deps = [":static_dep_for_both"], |
| 537 | shared_copts = ["sharedflag"] + select({ |
| 538 | "//build/bazel/platforms/arch:arm": ["-DARM_SHARED"], |
| 539 | "//conditions:default": [], |
| 540 | }) + select({ |
| 541 | "//build/bazel/platforms/os:android": ["-DANDROID_SHARED"], |
| 542 | "//conditions:default": [], |
| 543 | }) + select({ |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 544 | "//build/bazel/platforms/os_arch:android_arm": ["-DANDROID_ARM_SHARED"], |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 545 | "//conditions:default": [], |
| 546 | }), |
| 547 | shared_srcs = ["sharedonly.cpp"] + select({ |
| 548 | "//build/bazel/platforms/arch:arm": ["arm_shared.cpp"], |
| 549 | "//conditions:default": [], |
| 550 | }) + select({ |
| 551 | "//build/bazel/platforms/os:android": ["android_shared.cpp"], |
| 552 | "//conditions:default": [], |
| 553 | }), |
| 554 | srcs = ["both.cpp"], |
| 555 | static_copts = ["staticflag"] + select({ |
| 556 | "//build/bazel/platforms/arch:x86": ["-DX86_STATIC"], |
| 557 | "//conditions:default": [], |
| 558 | }), |
| 559 | static_deps_for_shared = [":static_dep_for_shared"] + select({ |
| 560 | "//build/bazel/platforms/arch:arm": [":arm_static_dep_for_shared"], |
| 561 | "//conditions:default": [], |
| 562 | }) + select({ |
| 563 | "//build/bazel/platforms/os:android": [":android_dep_for_shared"], |
| 564 | "//conditions:default": [], |
| 565 | }), |
| 566 | static_deps_for_static = [":static_dep_for_static"] + select({ |
| 567 | "//build/bazel/platforms/arch:x86": [":x86_dep_for_static"], |
| 568 | "//conditions:default": [], |
| 569 | }), |
| 570 | static_srcs = ["staticonly.cpp"] + select({ |
| 571 | "//build/bazel/platforms/arch:x86": ["x86_static.cpp"], |
| 572 | "//conditions:default": [], |
| 573 | }), |
| 574 | whole_archive_deps_for_shared = select({ |
| 575 | "//build/bazel/platforms/arch:arm": [":arm_whole_static_dep_for_shared"], |
| 576 | "//conditions:default": [], |
| 577 | }), |
| 578 | )`}, |
| 579 | }) |
| 580 | } |
| 581 | |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 582 | func TestCcLibrarySharedStaticPropsWithMixedSources(t *testing.T) { |
| 583 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 584 | description: "cc_library shared/static props with c/cpp/s mixed sources", |
| 585 | moduleTypeUnderTest: "cc_library", |
| 586 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 587 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 588 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 589 | dir: "foo/bar", |
| 590 | filesystem: map[string]string{ |
| 591 | "foo/bar/both_source.cpp": "", |
| 592 | "foo/bar/both_source.cc": "", |
| 593 | "foo/bar/both_source.c": "", |
| 594 | "foo/bar/both_source.s": "", |
| 595 | "foo/bar/both_source.S": "", |
| 596 | "foo/bar/shared_source.cpp": "", |
| 597 | "foo/bar/shared_source.cc": "", |
| 598 | "foo/bar/shared_source.c": "", |
| 599 | "foo/bar/shared_source.s": "", |
| 600 | "foo/bar/shared_source.S": "", |
| 601 | "foo/bar/static_source.cpp": "", |
| 602 | "foo/bar/static_source.cc": "", |
| 603 | "foo/bar/static_source.c": "", |
| 604 | "foo/bar/static_source.s": "", |
| 605 | "foo/bar/static_source.S": "", |
| 606 | "foo/bar/Android.bp": ` |
| 607 | cc_library { |
| 608 | name: "a", |
| 609 | srcs: [ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 610 | "both_source.cpp", |
| 611 | "both_source.cc", |
| 612 | "both_source.c", |
| 613 | "both_source.s", |
| 614 | "both_source.S", |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 615 | ":both_filegroup", |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 616 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 617 | static: { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 618 | srcs: [ |
| 619 | "static_source.cpp", |
| 620 | "static_source.cc", |
| 621 | "static_source.c", |
| 622 | "static_source.s", |
| 623 | "static_source.S", |
| 624 | ":static_filegroup", |
| 625 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 626 | }, |
| 627 | shared: { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 628 | srcs: [ |
| 629 | "shared_source.cpp", |
| 630 | "shared_source.cc", |
| 631 | "shared_source.c", |
| 632 | "shared_source.s", |
| 633 | "shared_source.S", |
| 634 | ":shared_filegroup", |
| 635 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 636 | }, |
| 637 | bazel_module: { bp2build_available: true }, |
| 638 | } |
| 639 | |
| 640 | filegroup { |
| 641 | name: "both_filegroup", |
| 642 | srcs: [ |
| 643 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 644 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | filegroup { |
| 648 | name: "shared_filegroup", |
| 649 | srcs: [ |
| 650 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 651 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | filegroup { |
| 655 | name: "static_filegroup", |
| 656 | srcs: [ |
| 657 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 658 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 659 | } |
| 660 | `, |
| 661 | }, |
| 662 | blueprint: soongCcLibraryPreamble, |
| 663 | expectedBazelTargets: []string{`cc_library( |
| 664 | name = "a", |
| 665 | copts = [ |
| 666 | "-Ifoo/bar", |
| 667 | "-I$(BINDIR)/foo/bar", |
| 668 | ], |
| 669 | shared_srcs = [ |
| 670 | ":shared_filegroup_cpp_srcs", |
| 671 | "shared_source.cc", |
| 672 | "shared_source.cpp", |
| 673 | ], |
| 674 | shared_srcs_as = [ |
| 675 | "shared_source.s", |
| 676 | "shared_source.S", |
| 677 | ":shared_filegroup_as_srcs", |
| 678 | ], |
| 679 | shared_srcs_c = [ |
| 680 | "shared_source.c", |
| 681 | ":shared_filegroup_c_srcs", |
| 682 | ], |
| 683 | srcs = [ |
| 684 | ":both_filegroup_cpp_srcs", |
| 685 | "both_source.cc", |
| 686 | "both_source.cpp", |
| 687 | ], |
| 688 | srcs_as = [ |
| 689 | "both_source.s", |
| 690 | "both_source.S", |
| 691 | ":both_filegroup_as_srcs", |
| 692 | ], |
| 693 | srcs_c = [ |
| 694 | "both_source.c", |
| 695 | ":both_filegroup_c_srcs", |
| 696 | ], |
| 697 | static_srcs = [ |
| 698 | ":static_filegroup_cpp_srcs", |
| 699 | "static_source.cc", |
| 700 | "static_source.cpp", |
| 701 | ], |
| 702 | static_srcs_as = [ |
| 703 | "static_source.s", |
| 704 | "static_source.S", |
| 705 | ":static_filegroup_as_srcs", |
| 706 | ], |
| 707 | static_srcs_c = [ |
| 708 | "static_source.c", |
| 709 | ":static_filegroup_c_srcs", |
| 710 | ], |
| 711 | )`}, |
| 712 | }) |
| 713 | } |
| 714 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 715 | func TestCcLibraryNonConfiguredVersionScript(t *testing.T) { |
| 716 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 717 | description: "cc_library non-configured version script", |
| 718 | moduleTypeUnderTest: "cc_library", |
| 719 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 720 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 721 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 722 | dir: "foo/bar", |
| 723 | filesystem: map[string]string{ |
| 724 | "foo/bar/Android.bp": ` |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 725 | cc_library { |
| 726 | name: "a", |
| 727 | srcs: ["a.cpp"], |
| 728 | version_script: "v.map", |
| 729 | bazel_module: { bp2build_available: true }, |
| 730 | } |
| 731 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 732 | }, |
| 733 | blueprint: soongCcLibraryPreamble, |
| 734 | expectedBazelTargets: []string{`cc_library( |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 735 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 736 | copts = [ |
| 737 | "-Ifoo/bar", |
| 738 | "-I$(BINDIR)/foo/bar", |
| 739 | ], |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 740 | srcs = ["a.cpp"], |
| 741 | version_script = "v.map", |
| 742 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 743 | }) |
| 744 | } |
| 745 | |
| 746 | func TestCcLibraryConfiguredVersionScript(t *testing.T) { |
| 747 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 748 | description: "cc_library configured version script", |
| 749 | moduleTypeUnderTest: "cc_library", |
| 750 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 751 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 752 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 753 | dir: "foo/bar", |
| 754 | filesystem: map[string]string{ |
| 755 | "foo/bar/Android.bp": ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 756 | cc_library { |
| 757 | name: "a", |
| 758 | srcs: ["a.cpp"], |
| 759 | arch: { |
| 760 | arm: { |
| 761 | version_script: "arm.map", |
| 762 | }, |
| 763 | arm64: { |
| 764 | version_script: "arm64.map", |
| 765 | }, |
| 766 | }, |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 767 | |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 768 | bazel_module: { bp2build_available: true }, |
| 769 | } |
| 770 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 771 | }, |
| 772 | blueprint: soongCcLibraryPreamble, |
| 773 | expectedBazelTargets: []string{`cc_library( |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 774 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 775 | copts = [ |
| 776 | "-Ifoo/bar", |
| 777 | "-I$(BINDIR)/foo/bar", |
| 778 | ], |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 779 | srcs = ["a.cpp"], |
| 780 | version_script = select({ |
| 781 | "//build/bazel/platforms/arch:arm": "arm.map", |
| 782 | "//build/bazel/platforms/arch:arm64": "arm64.map", |
| 783 | "//conditions:default": None, |
| 784 | }), |
| 785 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 786 | }) |
| 787 | } |
| 788 | |
| 789 | func TestCcLibrarySharedLibs(t *testing.T) { |
| 790 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 791 | description: "cc_library shared_libs", |
| 792 | moduleTypeUnderTest: "cc_library", |
| 793 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 794 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 795 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 796 | dir: "foo/bar", |
| 797 | filesystem: map[string]string{ |
| 798 | "foo/bar/Android.bp": ` |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 799 | cc_library { |
| 800 | name: "mylib", |
| 801 | bazel_module: { bp2build_available: true }, |
| 802 | } |
| 803 | |
| 804 | cc_library { |
| 805 | name: "a", |
| 806 | shared_libs: ["mylib",], |
| 807 | bazel_module: { bp2build_available: true }, |
| 808 | } |
| 809 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 810 | }, |
| 811 | blueprint: soongCcLibraryPreamble, |
| 812 | expectedBazelTargets: []string{`cc_library( |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 813 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 814 | copts = [ |
| 815 | "-Ifoo/bar", |
| 816 | "-I$(BINDIR)/foo/bar", |
| 817 | ], |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 818 | dynamic_deps = [":mylib"], |
| 819 | )`, `cc_library( |
| 820 | name = "mylib", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 821 | copts = [ |
| 822 | "-Ifoo/bar", |
| 823 | "-I$(BINDIR)/foo/bar", |
| 824 | ], |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 825 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 826 | }) |
| 827 | } |
| 828 | |
| 829 | func TestCcLibraryPackRelocations(t *testing.T) { |
| 830 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 831 | description: "cc_library pack_relocations test", |
| 832 | moduleTypeUnderTest: "cc_library", |
| 833 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 834 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 835 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 836 | dir: "foo/bar", |
| 837 | filesystem: map[string]string{ |
| 838 | "foo/bar/Android.bp": ` |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 839 | cc_library { |
| 840 | name: "a", |
| 841 | srcs: ["a.cpp"], |
| 842 | pack_relocations: false, |
| 843 | bazel_module: { bp2build_available: true }, |
| 844 | } |
| 845 | |
| 846 | cc_library { |
| 847 | name: "b", |
| 848 | srcs: ["b.cpp"], |
| 849 | arch: { |
| 850 | x86_64: { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 851 | pack_relocations: false, |
| 852 | }, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 853 | }, |
| 854 | bazel_module: { bp2build_available: true }, |
| 855 | } |
| 856 | |
| 857 | cc_library { |
| 858 | name: "c", |
| 859 | srcs: ["c.cpp"], |
| 860 | target: { |
| 861 | darwin: { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 862 | pack_relocations: false, |
| 863 | }, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 864 | }, |
| 865 | bazel_module: { bp2build_available: true }, |
| 866 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 867 | }, |
| 868 | blueprint: soongCcLibraryPreamble, |
| 869 | expectedBazelTargets: []string{`cc_library( |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 870 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 871 | copts = [ |
| 872 | "-Ifoo/bar", |
| 873 | "-I$(BINDIR)/foo/bar", |
| 874 | ], |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 875 | linkopts = ["-Wl,--pack-dyn-relocs=none"], |
| 876 | srcs = ["a.cpp"], |
| 877 | )`, `cc_library( |
| 878 | name = "b", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 879 | copts = [ |
| 880 | "-Ifoo/bar", |
| 881 | "-I$(BINDIR)/foo/bar", |
| 882 | ], |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 883 | linkopts = select({ |
| 884 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--pack-dyn-relocs=none"], |
| 885 | "//conditions:default": [], |
| 886 | }), |
| 887 | srcs = ["b.cpp"], |
| 888 | )`, `cc_library( |
| 889 | name = "c", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 890 | copts = [ |
| 891 | "-Ifoo/bar", |
| 892 | "-I$(BINDIR)/foo/bar", |
| 893 | ], |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 894 | linkopts = select({ |
| 895 | "//build/bazel/platforms/os:darwin": ["-Wl,--pack-dyn-relocs=none"], |
| 896 | "//conditions:default": [], |
| 897 | }), |
| 898 | srcs = ["c.cpp"], |
| 899 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 900 | }) |
| 901 | } |
| 902 | |
| 903 | func TestCcLibrarySpacesInCopts(t *testing.T) { |
| 904 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 905 | description: "cc_library spaces in copts", |
| 906 | moduleTypeUnderTest: "cc_library", |
| 907 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 908 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 909 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 910 | dir: "foo/bar", |
| 911 | filesystem: map[string]string{ |
| 912 | "foo/bar/Android.bp": ` |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 913 | cc_library { |
| 914 | name: "a", |
| 915 | cflags: ["-include header.h",], |
| 916 | bazel_module: { bp2build_available: true }, |
| 917 | } |
| 918 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 919 | }, |
| 920 | blueprint: soongCcLibraryPreamble, |
| 921 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 922 | name = "a", |
| 923 | copts = [ |
| 924 | "-include", |
| 925 | "header.h", |
| 926 | "-Ifoo/bar", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 927 | "-I$(BINDIR)/foo/bar", |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 928 | ], |
| 929 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 930 | }) |
| 931 | } |
| 932 | |
| 933 | func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { |
| 934 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 935 | description: "cc_library cppflags usage", |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 936 | moduleTypeUnderTest: "cc_library", |
| 937 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 938 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 939 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 940 | dir: "foo/bar", |
| 941 | filesystem: map[string]string{ |
| 942 | "foo/bar/Android.bp": `cc_library { |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 943 | name: "a", |
| 944 | srcs: ["a.cpp"], |
| 945 | cflags: [ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 946 | "-Wall", |
| 947 | ], |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 948 | cppflags: [ |
| 949 | "-fsigned-char", |
| 950 | "-pedantic", |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 951 | ], |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 952 | arch: { |
| 953 | arm64: { |
| 954 | cppflags: ["-DARM64=1"], |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 955 | }, |
| 956 | }, |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 957 | target: { |
| 958 | android: { |
| 959 | cppflags: ["-DANDROID=1"], |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 960 | }, |
| 961 | }, |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 962 | bazel_module: { bp2build_available: true }, |
| 963 | } |
| 964 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 965 | }, |
| 966 | blueprint: soongCcLibraryPreamble, |
| 967 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 968 | name = "a", |
| 969 | copts = [ |
| 970 | "-Wall", |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 971 | "-Ifoo/bar", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 972 | "-I$(BINDIR)/foo/bar", |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 973 | ], |
| 974 | cppflags = [ |
| 975 | "-fsigned-char", |
| 976 | "-pedantic", |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 977 | ] + select({ |
| 978 | "//build/bazel/platforms/arch:arm64": ["-DARM64=1"], |
| 979 | "//conditions:default": [], |
| 980 | }) + select({ |
| 981 | "//build/bazel/platforms/os:android": ["-DANDROID=1"], |
| 982 | "//conditions:default": [], |
| 983 | }), |
| 984 | srcs = ["a.cpp"], |
| 985 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 986 | }) |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 987 | } |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 988 | |
| 989 | func TestCcLibraryLabelAttributeGetTargetProperties(t *testing.T) { |
| 990 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 991 | description: "cc_library GetTargetProperties on a LabelAttribute", |
| 992 | moduleTypeUnderTest: "cc_library", |
| 993 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 994 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 995 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 996 | dir: "foo/bar", |
| 997 | filesystem: map[string]string{ |
| 998 | "foo/bar/Android.bp": ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 999 | cc_library { |
| 1000 | name: "a", |
| 1001 | srcs: ["a.cpp"], |
| 1002 | target: { |
| 1003 | android_arm: { |
| 1004 | version_script: "android_arm.map", |
| 1005 | }, |
| 1006 | linux_bionic_arm64: { |
| 1007 | version_script: "linux_bionic_arm64.map", |
| 1008 | }, |
| 1009 | }, |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 1010 | |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1011 | bazel_module: { bp2build_available: true }, |
| 1012 | } |
| 1013 | `, |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 1014 | }, |
| 1015 | blueprint: soongCcLibraryPreamble, |
| 1016 | expectedBazelTargets: []string{`cc_library( |
| 1017 | name = "a", |
| 1018 | copts = [ |
| 1019 | "-Ifoo/bar", |
| 1020 | "-I$(BINDIR)/foo/bar", |
| 1021 | ], |
| 1022 | srcs = ["a.cpp"], |
| 1023 | version_script = select({ |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 1024 | "//build/bazel/platforms/os_arch:android_arm": "android_arm.map", |
| 1025 | "//build/bazel/platforms/os_arch:linux_bionic_arm64": "linux_bionic_arm64.map", |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 1026 | "//conditions:default": None, |
| 1027 | }), |
| 1028 | )`}, |
| 1029 | }) |
| 1030 | } |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1031 | |
| 1032 | func TestCcLibraryExcludeLibs(t *testing.T) { |
| 1033 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1034 | moduleTypeUnderTest: "cc_library", |
| 1035 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1036 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1037 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 1038 | filesystem: map[string]string{}, |
| 1039 | blueprint: soongCcLibraryStaticPreamble + ` |
| 1040 | cc_library { |
| 1041 | name: "foo_static", |
| 1042 | srcs: ["common.c"], |
| 1043 | whole_static_libs: [ |
| 1044 | "arm_whole_static_lib_excludes", |
| 1045 | "malloc_not_svelte_whole_static_lib_excludes" |
| 1046 | ], |
| 1047 | static_libs: [ |
| 1048 | "arm_static_lib_excludes", |
| 1049 | "malloc_not_svelte_static_lib_excludes" |
| 1050 | ], |
| 1051 | shared_libs: [ |
| 1052 | "arm_shared_lib_excludes", |
| 1053 | ], |
| 1054 | arch: { |
| 1055 | arm: { |
| 1056 | exclude_shared_libs: [ |
| 1057 | "arm_shared_lib_excludes", |
| 1058 | ], |
| 1059 | exclude_static_libs: [ |
| 1060 | "arm_static_lib_excludes", |
| 1061 | "arm_whole_static_lib_excludes", |
| 1062 | ], |
| 1063 | }, |
| 1064 | }, |
| 1065 | product_variables: { |
| 1066 | malloc_not_svelte: { |
| 1067 | shared_libs: ["malloc_not_svelte_shared_lib"], |
| 1068 | whole_static_libs: ["malloc_not_svelte_whole_static_lib"], |
| 1069 | exclude_static_libs: [ |
| 1070 | "malloc_not_svelte_static_lib_excludes", |
| 1071 | "malloc_not_svelte_whole_static_lib_excludes", |
| 1072 | ], |
| 1073 | }, |
| 1074 | }, |
| 1075 | } |
| 1076 | |
| 1077 | cc_library { |
| 1078 | name: "arm_whole_static_lib_excludes", |
| 1079 | bazel_module: { bp2build_available: false }, |
| 1080 | } |
| 1081 | |
| 1082 | cc_library { |
| 1083 | name: "malloc_not_svelte_whole_static_lib", |
| 1084 | bazel_module: { bp2build_available: false }, |
| 1085 | } |
| 1086 | |
| 1087 | cc_library { |
| 1088 | name: "malloc_not_svelte_whole_static_lib_excludes", |
| 1089 | bazel_module: { bp2build_available: false }, |
| 1090 | } |
| 1091 | |
| 1092 | cc_library { |
| 1093 | name: "arm_static_lib_excludes", |
| 1094 | bazel_module: { bp2build_available: false }, |
| 1095 | } |
| 1096 | |
| 1097 | cc_library { |
| 1098 | name: "malloc_not_svelte_static_lib_excludes", |
| 1099 | bazel_module: { bp2build_available: false }, |
| 1100 | } |
| 1101 | |
| 1102 | cc_library { |
| 1103 | name: "arm_shared_lib_excludes", |
| 1104 | bazel_module: { bp2build_available: false }, |
| 1105 | } |
| 1106 | |
| 1107 | cc_library { |
| 1108 | name: "malloc_not_svelte_shared_lib", |
| 1109 | bazel_module: { bp2build_available: false }, |
| 1110 | } |
| 1111 | `, |
| 1112 | expectedBazelTargets: []string{ |
| 1113 | `cc_library( |
| 1114 | name = "foo_static", |
| 1115 | copts = [ |
| 1116 | "-I.", |
| 1117 | "-I$(BINDIR)/.", |
| 1118 | ], |
| 1119 | dynamic_deps = select({ |
| 1120 | "//build/bazel/platforms/arch:arm": [], |
| 1121 | "//conditions:default": [":arm_shared_lib_excludes"], |
| 1122 | }) + select({ |
| 1123 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_shared_lib"], |
| 1124 | "//conditions:default": [], |
| 1125 | }), |
| 1126 | implementation_deps = select({ |
| 1127 | "//build/bazel/platforms/arch:arm": [], |
| 1128 | "//conditions:default": [":arm_static_lib_excludes"], |
| 1129 | }) + select({ |
| 1130 | "//build/bazel/product_variables:malloc_not_svelte": [], |
| 1131 | "//conditions:default": [":malloc_not_svelte_static_lib_excludes"], |
| 1132 | }), |
| 1133 | srcs_c = ["common.c"], |
| 1134 | whole_archive_deps = select({ |
| 1135 | "//build/bazel/platforms/arch:arm": [], |
| 1136 | "//conditions:default": [":arm_whole_static_lib_excludes"], |
| 1137 | }) + select({ |
| 1138 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_whole_static_lib"], |
| 1139 | "//conditions:default": [":malloc_not_svelte_whole_static_lib_excludes"], |
| 1140 | }), |
| 1141 | )`, |
| 1142 | }, |
| 1143 | }) |
| 1144 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1145 | |
| 1146 | func TestCCLibraryNoCrtTrue(t *testing.T) { |
| 1147 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1148 | description: "cc_library - simple example", |
| 1149 | moduleTypeUnderTest: "cc_library", |
| 1150 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1151 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1152 | filesystem: map[string]string{ |
| 1153 | "impl.cpp": "", |
| 1154 | }, |
| 1155 | blueprint: soongCcLibraryPreamble + ` |
| 1156 | cc_library_headers { name: "some-headers" } |
| 1157 | cc_library { |
| 1158 | name: "foo-lib", |
| 1159 | srcs: ["impl.cpp"], |
| 1160 | no_libcrt: true, |
| 1161 | } |
| 1162 | `, |
| 1163 | expectedBazelTargets: []string{`cc_library( |
| 1164 | name = "foo-lib", |
| 1165 | copts = [ |
| 1166 | "-I.", |
| 1167 | "-I$(BINDIR)/.", |
| 1168 | ], |
| 1169 | srcs = ["impl.cpp"], |
| 1170 | use_libcrt = False, |
| 1171 | )`}}) |
| 1172 | } |
| 1173 | |
| 1174 | func TestCCLibraryNoCrtFalse(t *testing.T) { |
| 1175 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1176 | moduleTypeUnderTest: "cc_library", |
| 1177 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1178 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1179 | filesystem: map[string]string{ |
| 1180 | "impl.cpp": "", |
| 1181 | }, |
| 1182 | blueprint: soongCcLibraryPreamble + ` |
| 1183 | cc_library_headers { name: "some-headers" } |
| 1184 | cc_library { |
| 1185 | name: "foo-lib", |
| 1186 | srcs: ["impl.cpp"], |
| 1187 | no_libcrt: false, |
| 1188 | } |
| 1189 | `, |
| 1190 | expectedBazelTargets: []string{`cc_library( |
| 1191 | name = "foo-lib", |
| 1192 | copts = [ |
| 1193 | "-I.", |
| 1194 | "-I$(BINDIR)/.", |
| 1195 | ], |
| 1196 | srcs = ["impl.cpp"], |
| 1197 | use_libcrt = True, |
| 1198 | )`}}) |
| 1199 | } |
| 1200 | |
| 1201 | func TestCCLibraryNoCrtArchVariant(t *testing.T) { |
| 1202 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1203 | moduleTypeUnderTest: "cc_library", |
| 1204 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1205 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1206 | filesystem: map[string]string{ |
| 1207 | "impl.cpp": "", |
| 1208 | }, |
| 1209 | blueprint: soongCcLibraryPreamble + ` |
| 1210 | cc_library_headers { name: "some-headers" } |
| 1211 | cc_library { |
| 1212 | name: "foo-lib", |
| 1213 | srcs: ["impl.cpp"], |
| 1214 | arch: { |
| 1215 | arm: { |
| 1216 | no_libcrt: true, |
| 1217 | }, |
| 1218 | x86: { |
| 1219 | no_libcrt: true, |
| 1220 | }, |
| 1221 | }, |
| 1222 | } |
| 1223 | `, |
| 1224 | expectedBazelTargets: []string{`cc_library( |
| 1225 | name = "foo-lib", |
| 1226 | copts = [ |
| 1227 | "-I.", |
| 1228 | "-I$(BINDIR)/.", |
| 1229 | ], |
| 1230 | srcs = ["impl.cpp"], |
| 1231 | use_libcrt = select({ |
| 1232 | "//build/bazel/platforms/arch:arm": False, |
| 1233 | "//build/bazel/platforms/arch:x86": False, |
| 1234 | "//conditions:default": None, |
| 1235 | }), |
| 1236 | )`}}) |
| 1237 | } |
| 1238 | |
| 1239 | func TestCCLibraryNoCrtArchVariantWithDefault(t *testing.T) { |
| 1240 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1241 | moduleTypeUnderTest: "cc_library", |
| 1242 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1243 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1244 | filesystem: map[string]string{ |
| 1245 | "impl.cpp": "", |
| 1246 | }, |
| 1247 | blueprint: soongCcLibraryPreamble + ` |
| 1248 | cc_library_headers { name: "some-headers" } |
| 1249 | cc_library { |
| 1250 | name: "foo-lib", |
| 1251 | srcs: ["impl.cpp"], |
| 1252 | no_libcrt: false, |
| 1253 | arch: { |
| 1254 | arm: { |
| 1255 | no_libcrt: true, |
| 1256 | }, |
| 1257 | x86: { |
| 1258 | no_libcrt: true, |
| 1259 | }, |
| 1260 | }, |
| 1261 | } |
| 1262 | `, |
| 1263 | expectedBazelTargets: []string{`cc_library( |
| 1264 | name = "foo-lib", |
| 1265 | copts = [ |
| 1266 | "-I.", |
| 1267 | "-I$(BINDIR)/.", |
| 1268 | ], |
| 1269 | srcs = ["impl.cpp"], |
| 1270 | use_libcrt = select({ |
| 1271 | "//build/bazel/platforms/arch:arm": False, |
| 1272 | "//build/bazel/platforms/arch:x86": False, |
| 1273 | "//conditions:default": True, |
| 1274 | }), |
| 1275 | )`}}) |
| 1276 | } |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1277 | |
| 1278 | func TestCcLibraryStrip(t *testing.T) { |
| 1279 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1280 | description: "cc_library strip args", |
| 1281 | moduleTypeUnderTest: "cc_library", |
| 1282 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1283 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1284 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 1285 | dir: "foo/bar", |
| 1286 | filesystem: map[string]string{ |
| 1287 | "foo/bar/Android.bp": ` |
| 1288 | cc_library { |
| 1289 | name: "nothing", |
| 1290 | bazel_module: { bp2build_available: true }, |
| 1291 | } |
| 1292 | cc_library { |
| 1293 | name: "keep_symbols", |
| 1294 | bazel_module: { bp2build_available: true }, |
| 1295 | strip: { |
| 1296 | keep_symbols: true, |
| 1297 | } |
| 1298 | } |
| 1299 | cc_library { |
| 1300 | name: "keep_symbols_and_debug_frame", |
| 1301 | bazel_module: { bp2build_available: true }, |
| 1302 | strip: { |
| 1303 | keep_symbols_and_debug_frame: true, |
| 1304 | } |
| 1305 | } |
| 1306 | cc_library { |
| 1307 | name: "none", |
| 1308 | bazel_module: { bp2build_available: true }, |
| 1309 | strip: { |
| 1310 | none: true, |
| 1311 | } |
| 1312 | } |
| 1313 | cc_library { |
| 1314 | name: "keep_symbols_list", |
| 1315 | bazel_module: { bp2build_available: true }, |
| 1316 | strip: { |
| 1317 | keep_symbols_list: ["symbol"], |
| 1318 | } |
| 1319 | } |
| 1320 | cc_library { |
| 1321 | name: "all", |
| 1322 | bazel_module: { bp2build_available: true }, |
| 1323 | strip: { |
| 1324 | all: true, |
| 1325 | } |
| 1326 | } |
| 1327 | `, |
| 1328 | }, |
| 1329 | blueprint: soongCcLibraryPreamble, |
| 1330 | expectedBazelTargets: []string{`cc_library( |
| 1331 | name = "all", |
| 1332 | copts = [ |
| 1333 | "-Ifoo/bar", |
| 1334 | "-I$(BINDIR)/foo/bar", |
| 1335 | ], |
| 1336 | strip = { |
| 1337 | "all": True, |
| 1338 | }, |
| 1339 | )`, `cc_library( |
| 1340 | name = "keep_symbols", |
| 1341 | copts = [ |
| 1342 | "-Ifoo/bar", |
| 1343 | "-I$(BINDIR)/foo/bar", |
| 1344 | ], |
| 1345 | strip = { |
| 1346 | "keep_symbols": True, |
| 1347 | }, |
| 1348 | )`, `cc_library( |
| 1349 | name = "keep_symbols_and_debug_frame", |
| 1350 | copts = [ |
| 1351 | "-Ifoo/bar", |
| 1352 | "-I$(BINDIR)/foo/bar", |
| 1353 | ], |
| 1354 | strip = { |
| 1355 | "keep_symbols_and_debug_frame": True, |
| 1356 | }, |
| 1357 | )`, `cc_library( |
| 1358 | name = "keep_symbols_list", |
| 1359 | copts = [ |
| 1360 | "-Ifoo/bar", |
| 1361 | "-I$(BINDIR)/foo/bar", |
| 1362 | ], |
| 1363 | strip = { |
| 1364 | "keep_symbols_list": ["symbol"], |
| 1365 | }, |
| 1366 | )`, `cc_library( |
| 1367 | name = "none", |
| 1368 | copts = [ |
| 1369 | "-Ifoo/bar", |
| 1370 | "-I$(BINDIR)/foo/bar", |
| 1371 | ], |
| 1372 | strip = { |
| 1373 | "none": True, |
| 1374 | }, |
| 1375 | )`, `cc_library( |
| 1376 | name = "nothing", |
| 1377 | copts = [ |
| 1378 | "-Ifoo/bar", |
| 1379 | "-I$(BINDIR)/foo/bar", |
| 1380 | ], |
| 1381 | )`}, |
| 1382 | }) |
| 1383 | } |
| 1384 | |
| 1385 | func TestCcLibraryStripWithArch(t *testing.T) { |
| 1386 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1387 | description: "cc_library strip args", |
| 1388 | moduleTypeUnderTest: "cc_library", |
| 1389 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1390 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1391 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 1392 | dir: "foo/bar", |
| 1393 | filesystem: map[string]string{ |
| 1394 | "foo/bar/Android.bp": ` |
| 1395 | cc_library { |
| 1396 | name: "multi-arch", |
| 1397 | bazel_module: { bp2build_available: true }, |
| 1398 | target: { |
| 1399 | darwin: { |
| 1400 | strip: { |
| 1401 | keep_symbols_list: ["foo", "bar"] |
| 1402 | } |
| 1403 | }, |
| 1404 | }, |
| 1405 | arch: { |
| 1406 | arm: { |
| 1407 | strip: { |
| 1408 | keep_symbols_and_debug_frame: true, |
| 1409 | }, |
| 1410 | }, |
| 1411 | arm64: { |
| 1412 | strip: { |
| 1413 | keep_symbols: true, |
| 1414 | }, |
| 1415 | }, |
| 1416 | } |
| 1417 | } |
| 1418 | `, |
| 1419 | }, |
| 1420 | blueprint: soongCcLibraryPreamble, |
| 1421 | expectedBazelTargets: []string{`cc_library( |
| 1422 | name = "multi-arch", |
| 1423 | copts = [ |
| 1424 | "-Ifoo/bar", |
| 1425 | "-I$(BINDIR)/foo/bar", |
| 1426 | ], |
| 1427 | strip = { |
| 1428 | "keep_symbols": select({ |
| 1429 | "//build/bazel/platforms/arch:arm64": True, |
| 1430 | "//conditions:default": None, |
| 1431 | }), |
| 1432 | "keep_symbols_and_debug_frame": select({ |
| 1433 | "//build/bazel/platforms/arch:arm": True, |
| 1434 | "//conditions:default": None, |
| 1435 | }), |
| 1436 | "keep_symbols_list": select({ |
| 1437 | "//build/bazel/platforms/os:darwin": [ |
| 1438 | "foo", |
| 1439 | "bar", |
| 1440 | ], |
| 1441 | "//conditions:default": [], |
| 1442 | }), |
| 1443 | }, |
| 1444 | )`}, |
| 1445 | }) |
| 1446 | } |