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