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