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 { |
| 28 | name: "linux_bionic_supported", |
| 29 | } |
| 30 | |
| 31 | toolchain_library { |
| 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: "", |
| 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) |
| 52 | ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) |
| 53 | ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) |
| 54 | } |
| 55 | |
| 56 | func runBp2BuildTestCase(t *testing.T, registerModuleTypes func(ctx android.RegistrationContext), tc bp2buildTestCase) { |
Liz Kammer | e4982e8 | 2021-05-25 10:39:35 -0400 | [diff] [blame] | 57 | t.Helper() |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 58 | dir := "." |
| 59 | filesystem := make(map[string][]byte) |
| 60 | toParse := []string{ |
| 61 | "Android.bp", |
| 62 | } |
| 63 | for f, content := range tc.filesystem { |
| 64 | if strings.HasSuffix(f, "Android.bp") { |
| 65 | toParse = append(toParse, f) |
| 66 | } |
| 67 | filesystem[f] = []byte(content) |
| 68 | } |
| 69 | config := android.TestConfig(buildDir, nil, tc.blueprint, filesystem) |
| 70 | ctx := android.NewTestContext(config) |
| 71 | |
| 72 | registerModuleTypes(ctx) |
| 73 | ctx.RegisterModuleType(tc.moduleTypeUnderTest, tc.moduleTypeUnderTestFactory) |
| 74 | ctx.RegisterBp2BuildConfig(bp2buildConfig) |
| 75 | for _, m := range tc.depsMutators { |
| 76 | ctx.DepsBp2BuildMutators(m) |
| 77 | } |
| 78 | ctx.RegisterBp2BuildMutator(tc.moduleTypeUnderTest, tc.moduleTypeUnderTestBp2BuildMutator) |
| 79 | ctx.RegisterForBazelConversion() |
| 80 | |
| 81 | _, errs := ctx.ParseFileList(dir, toParse) |
| 82 | if errored(t, tc.description, errs) { |
| 83 | return |
| 84 | } |
| 85 | _, errs = ctx.ResolveDependencies(config) |
| 86 | if errored(t, tc.description, errs) { |
| 87 | return |
| 88 | } |
| 89 | |
| 90 | checkDir := dir |
| 91 | if tc.dir != "" { |
| 92 | checkDir = tc.dir |
| 93 | } |
| 94 | codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) |
| 95 | bazelTargets := generateBazelTargetsForDir(codegenCtx, checkDir) |
| 96 | if actualCount, expectedCount := len(bazelTargets), len(tc.expectedBazelTargets); actualCount != expectedCount { |
| 97 | t.Errorf("%s: Expected %d bazel target, got %d", tc.description, expectedCount, actualCount) |
| 98 | } else { |
| 99 | for i, target := range bazelTargets { |
| 100 | if w, g := tc.expectedBazelTargets[i], target.content; w != g { |
| 101 | t.Errorf( |
| 102 | "%s: Expected generated Bazel target to be '%s', got '%s'", |
| 103 | tc.description, |
| 104 | w, |
| 105 | g, |
| 106 | ) |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | func TestCcLibrarySimple(t *testing.T) { |
| 113 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 114 | description: "cc_library - simple example", |
| 115 | moduleTypeUnderTest: "cc_library", |
| 116 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 117 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 118 | filesystem: map[string]string{ |
| 119 | "android.cpp": "", |
| 120 | "darwin.cpp": "", |
| 121 | // Refer to cc.headerExts for the supported header extensions in Soong. |
| 122 | "header.h": "", |
| 123 | "header.hh": "", |
| 124 | "header.hpp": "", |
| 125 | "header.hxx": "", |
| 126 | "header.h++": "", |
| 127 | "header.inl": "", |
| 128 | "header.inc": "", |
| 129 | "header.ipp": "", |
| 130 | "header.h.generic": "", |
| 131 | "impl.cpp": "", |
| 132 | "linux.cpp": "", |
| 133 | "x86.cpp": "", |
| 134 | "x86_64.cpp": "", |
| 135 | "foo-dir/a.h": "", |
| 136 | }, |
| 137 | blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 138 | cc_library_headers { name: "some-headers" } |
| 139 | cc_library { |
| 140 | name: "foo-lib", |
| 141 | srcs: ["impl.cpp"], |
| 142 | cflags: ["-Wall"], |
| 143 | header_libs: ["some-headers"], |
| 144 | export_include_dirs: ["foo-dir"], |
| 145 | ldflags: ["-Wl,--exclude-libs=bar.a"], |
| 146 | arch: { |
| 147 | x86: { |
| 148 | ldflags: ["-Wl,--exclude-libs=baz.a"], |
| 149 | srcs: ["x86.cpp"], |
| 150 | }, |
| 151 | x86_64: { |
| 152 | ldflags: ["-Wl,--exclude-libs=qux.a"], |
| 153 | srcs: ["x86_64.cpp"], |
| 154 | }, |
| 155 | }, |
| 156 | target: { |
| 157 | android: { |
| 158 | srcs: ["android.cpp"], |
| 159 | }, |
| 160 | linux_glibc: { |
| 161 | srcs: ["linux.cpp"], |
| 162 | }, |
| 163 | darwin: { |
| 164 | srcs: ["darwin.cpp"], |
| 165 | }, |
| 166 | }, |
| 167 | } |
| 168 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 169 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 170 | name = "foo-lib", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 171 | copts = [ |
| 172 | "-Wall", |
| 173 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 174 | "-I$(BINDIR)/.", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 175 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 176 | implementation_deps = [":some-headers"], |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 177 | includes = ["foo-dir"], |
| 178 | linkopts = ["-Wl,--exclude-libs=bar.a"] + select({ |
| 179 | "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=baz.a"], |
| 180 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=qux.a"], |
| 181 | "//conditions:default": [], |
| 182 | }), |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 183 | srcs = ["impl.cpp"] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 184 | "//build/bazel/platforms/arch:x86": ["x86.cpp"], |
| 185 | "//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 186 | "//conditions:default": [], |
| 187 | }) + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 188 | "//build/bazel/platforms/os:android": ["android.cpp"], |
| 189 | "//build/bazel/platforms/os:darwin": ["darwin.cpp"], |
| 190 | "//build/bazel/platforms/os:linux": ["linux.cpp"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 191 | "//conditions:default": [], |
| 192 | }), |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 193 | )`}}) |
| 194 | } |
| 195 | |
| 196 | func TestCcLibraryTrimmedLdAndroid(t *testing.T) { |
| 197 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 198 | description: "cc_library - trimmed example of //bionic/linker:ld-android", |
| 199 | moduleTypeUnderTest: "cc_library", |
| 200 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 201 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 202 | filesystem: map[string]string{ |
| 203 | "ld-android.cpp": "", |
| 204 | "linked_list.h": "", |
| 205 | "linker.h": "", |
| 206 | "linker_block_allocator.h": "", |
| 207 | "linker_cfi.h": "", |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 208 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 209 | blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 210 | cc_library_headers { name: "libc_headers" } |
| 211 | cc_library { |
| 212 | name: "fake-ld-android", |
| 213 | srcs: ["ld_android.cpp"], |
| 214 | cflags: [ |
| 215 | "-Wall", |
| 216 | "-Wextra", |
| 217 | "-Wunused", |
| 218 | "-Werror", |
| 219 | ], |
| 220 | header_libs: ["libc_headers"], |
| 221 | ldflags: [ |
| 222 | "-Wl,--exclude-libs=libgcc.a", |
| 223 | "-Wl,--exclude-libs=libgcc_stripped.a", |
| 224 | "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a", |
| 225 | "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a", |
| 226 | "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a", |
| 227 | "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a", |
| 228 | ], |
| 229 | arch: { |
| 230 | x86: { |
| 231 | ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 232 | }, |
| 233 | x86_64: { |
| 234 | ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 235 | }, |
| 236 | }, |
| 237 | } |
| 238 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 239 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 240 | name = "fake-ld-android", |
| 241 | copts = [ |
| 242 | "-Wall", |
| 243 | "-Wextra", |
| 244 | "-Wunused", |
| 245 | "-Werror", |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 246 | "-I.", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 247 | "-I$(BINDIR)/.", |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 248 | ], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 249 | implementation_deps = [":libc_headers"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 250 | linkopts = [ |
| 251 | "-Wl,--exclude-libs=libgcc.a", |
| 252 | "-Wl,--exclude-libs=libgcc_stripped.a", |
| 253 | "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a", |
| 254 | "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a", |
| 255 | "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a", |
| 256 | "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a", |
| 257 | ] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 258 | "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 259 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=libgcc_eh.a"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 260 | "//conditions:default": [], |
| 261 | }), |
Jingwen Chen | 882bcc1 | 2021-04-27 05:54:20 +0000 | [diff] [blame] | 262 | srcs = ["ld_android.cpp"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 263 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 264 | }) |
| 265 | } |
| 266 | |
| 267 | func TestCcLibraryExcludeSrcs(t *testing.T) { |
| 268 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 269 | description: "cc_library exclude_srcs - trimmed example of //external/arm-optimized-routines:libarm-optimized-routines-math", |
| 270 | moduleTypeUnderTest: "cc_library", |
| 271 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 272 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 273 | dir: "external", |
| 274 | filesystem: map[string]string{ |
| 275 | "external/math/cosf.c": "", |
| 276 | "external/math/erf.c": "", |
| 277 | "external/math/erf_data.c": "", |
| 278 | "external/math/erff.c": "", |
| 279 | "external/math/erff_data.c": "", |
| 280 | "external/Android.bp": ` |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 281 | cc_library { |
| 282 | name: "fake-libarm-optimized-routines-math", |
| 283 | exclude_srcs: [ |
| 284 | // Provided by: |
| 285 | // bionic/libm/upstream-freebsd/lib/msun/src/s_erf.c |
| 286 | // bionic/libm/upstream-freebsd/lib/msun/src/s_erff.c |
| 287 | "math/erf.c", |
| 288 | "math/erf_data.c", |
| 289 | "math/erff.c", |
| 290 | "math/erff_data.c", |
| 291 | ], |
| 292 | srcs: [ |
| 293 | "math/*.c", |
| 294 | ], |
| 295 | // arch-specific settings |
| 296 | arch: { |
| 297 | arm64: { |
| 298 | cflags: [ |
| 299 | "-DHAVE_FAST_FMA=1", |
| 300 | ], |
| 301 | }, |
| 302 | }, |
| 303 | bazel_module: { bp2build_available: true }, |
| 304 | } |
| 305 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 306 | }, |
| 307 | blueprint: soongCcLibraryPreamble, |
| 308 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 309 | name = "fake-libarm-optimized-routines-math", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 310 | copts = [ |
| 311 | "-Iexternal", |
| 312 | "-I$(BINDIR)/external", |
| 313 | ] + select({ |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 314 | "//build/bazel/platforms/arch:arm64": ["-DHAVE_FAST_FMA=1"], |
| 315 | "//conditions:default": [], |
| 316 | }), |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 317 | srcs_c = ["math/cosf.c"], |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 318 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 319 | }) |
| 320 | } |
| 321 | |
| 322 | func TestCcLibrarySharedStaticProps(t *testing.T) { |
| 323 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 324 | description: "cc_library shared/static props", |
| 325 | moduleTypeUnderTest: "cc_library", |
| 326 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 327 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 328 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 329 | dir: "foo/bar", |
| 330 | filesystem: map[string]string{ |
| 331 | "foo/bar/both.cpp": "", |
| 332 | "foo/bar/sharedonly.cpp": "", |
| 333 | "foo/bar/staticonly.cpp": "", |
| 334 | "foo/bar/Android.bp": ` |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 335 | cc_library { |
| 336 | name: "a", |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 337 | srcs: ["both.cpp"], |
| 338 | cflags: ["bothflag"], |
| 339 | shared_libs: ["shared_dep_for_both"], |
| 340 | static_libs: ["static_dep_for_both"], |
| 341 | whole_static_libs: ["whole_static_lib_for_both"], |
| 342 | static: { |
| 343 | srcs: ["staticonly.cpp"], |
| 344 | cflags: ["staticflag"], |
| 345 | shared_libs: ["shared_dep_for_static"], |
| 346 | static_libs: ["static_dep_for_static"], |
| 347 | whole_static_libs: ["whole_static_lib_for_static"], |
| 348 | }, |
| 349 | shared: { |
| 350 | srcs: ["sharedonly.cpp"], |
| 351 | cflags: ["sharedflag"], |
| 352 | shared_libs: ["shared_dep_for_shared"], |
| 353 | static_libs: ["static_dep_for_shared"], |
| 354 | whole_static_libs: ["whole_static_lib_for_shared"], |
| 355 | }, |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 356 | bazel_module: { bp2build_available: true }, |
| 357 | } |
| 358 | |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 359 | cc_library_static { name: "static_dep_for_shared" } |
| 360 | |
| 361 | cc_library_static { name: "static_dep_for_static" } |
| 362 | |
| 363 | cc_library_static { name: "static_dep_for_both" } |
| 364 | |
| 365 | cc_library_static { name: "whole_static_lib_for_shared" } |
| 366 | |
| 367 | cc_library_static { name: "whole_static_lib_for_static" } |
| 368 | |
| 369 | cc_library_static { name: "whole_static_lib_for_both" } |
| 370 | |
| 371 | cc_library { name: "shared_dep_for_shared" } |
| 372 | |
| 373 | cc_library { name: "shared_dep_for_static" } |
| 374 | |
| 375 | cc_library { name: "shared_dep_for_both" } |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 376 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 377 | }, |
| 378 | blueprint: soongCcLibraryPreamble, |
| 379 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 380 | name = "a", |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 381 | copts = [ |
| 382 | "bothflag", |
| 383 | "-Ifoo/bar", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 384 | "-I$(BINDIR)/foo/bar", |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 385 | ], |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 386 | dynamic_deps = [":shared_dep_for_both"], |
| 387 | dynamic_deps_for_shared = [":shared_dep_for_shared"], |
| 388 | dynamic_deps_for_static = [":shared_dep_for_static"], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 389 | implementation_deps = [":static_dep_for_both"], |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 390 | shared_copts = ["sharedflag"], |
| 391 | shared_srcs = ["sharedonly.cpp"], |
| 392 | srcs = ["both.cpp"], |
| 393 | static_copts = ["staticflag"], |
| 394 | static_deps_for_shared = [":static_dep_for_shared"], |
| 395 | static_deps_for_static = [":static_dep_for_static"], |
| 396 | static_srcs = ["staticonly.cpp"], |
| 397 | whole_archive_deps = [":whole_static_lib_for_both"], |
| 398 | whole_archive_deps_for_shared = [":whole_static_lib_for_shared"], |
| 399 | whole_archive_deps_for_static = [":whole_static_lib_for_static"], |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 400 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 401 | }) |
| 402 | } |
| 403 | |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 404 | func TestCcLibrarySharedStaticPropsInArch(t *testing.T) { |
| 405 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 406 | description: "cc_library shared/static props in arch", |
| 407 | moduleTypeUnderTest: "cc_library", |
| 408 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 409 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 410 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 411 | dir: "foo/bar", |
| 412 | filesystem: map[string]string{ |
| 413 | "foo/bar/arm.cpp": "", |
| 414 | "foo/bar/x86.cpp": "", |
| 415 | "foo/bar/sharedonly.cpp": "", |
| 416 | "foo/bar/staticonly.cpp": "", |
| 417 | "foo/bar/Android.bp": ` |
| 418 | cc_library { |
| 419 | name: "a", |
| 420 | arch: { |
| 421 | arm: { |
| 422 | shared: { |
| 423 | srcs: ["arm_shared.cpp"], |
| 424 | cflags: ["-DARM_SHARED"], |
| 425 | static_libs: ["arm_static_dep_for_shared"], |
| 426 | whole_static_libs: ["arm_whole_static_dep_for_shared"], |
| 427 | shared_libs: ["arm_shared_dep_for_shared"], |
| 428 | }, |
| 429 | }, |
| 430 | x86: { |
| 431 | static: { |
| 432 | srcs: ["x86_static.cpp"], |
| 433 | cflags: ["-DX86_STATIC"], |
| 434 | static_libs: ["x86_dep_for_static"], |
| 435 | }, |
| 436 | }, |
| 437 | }, |
| 438 | target: { |
| 439 | android: { |
| 440 | shared: { |
| 441 | srcs: ["android_shared.cpp"], |
| 442 | cflags: ["-DANDROID_SHARED"], |
| 443 | static_libs: ["android_dep_for_shared"], |
| 444 | }, |
| 445 | }, |
| 446 | android_arm: { |
| 447 | shared: { |
| 448 | cflags: ["-DANDROID_ARM_SHARED"], |
| 449 | }, |
| 450 | }, |
| 451 | }, |
| 452 | srcs: ["both.cpp"], |
| 453 | cflags: ["bothflag"], |
| 454 | static_libs: ["static_dep_for_both"], |
| 455 | static: { |
| 456 | srcs: ["staticonly.cpp"], |
| 457 | cflags: ["staticflag"], |
| 458 | static_libs: ["static_dep_for_static"], |
| 459 | }, |
| 460 | shared: { |
| 461 | srcs: ["sharedonly.cpp"], |
| 462 | cflags: ["sharedflag"], |
| 463 | static_libs: ["static_dep_for_shared"], |
| 464 | }, |
| 465 | bazel_module: { bp2build_available: true }, |
| 466 | } |
| 467 | |
| 468 | cc_library_static { name: "static_dep_for_shared" } |
| 469 | cc_library_static { name: "static_dep_for_static" } |
| 470 | cc_library_static { name: "static_dep_for_both" } |
| 471 | |
| 472 | cc_library_static { name: "arm_static_dep_for_shared" } |
| 473 | cc_library_static { name: "arm_whole_static_dep_for_shared" } |
| 474 | cc_library_static { name: "arm_shared_dep_for_shared" } |
| 475 | |
| 476 | cc_library_static { name: "x86_dep_for_static" } |
| 477 | |
| 478 | cc_library_static { name: "android_dep_for_shared" } |
| 479 | `, |
| 480 | }, |
| 481 | blueprint: soongCcLibraryPreamble, |
| 482 | expectedBazelTargets: []string{`cc_library( |
| 483 | name = "a", |
| 484 | copts = [ |
| 485 | "bothflag", |
| 486 | "-Ifoo/bar", |
| 487 | "-I$(BINDIR)/foo/bar", |
| 488 | ], |
| 489 | dynamic_deps_for_shared = select({ |
| 490 | "//build/bazel/platforms/arch:arm": [":arm_shared_dep_for_shared"], |
| 491 | "//conditions:default": [], |
| 492 | }), |
| 493 | implementation_deps = [":static_dep_for_both"], |
| 494 | shared_copts = ["sharedflag"] + select({ |
| 495 | "//build/bazel/platforms/arch:arm": ["-DARM_SHARED"], |
| 496 | "//conditions:default": [], |
| 497 | }) + select({ |
| 498 | "//build/bazel/platforms/os:android": ["-DANDROID_SHARED"], |
| 499 | "//conditions:default": [], |
| 500 | }) + select({ |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 501 | "//build/bazel/platforms/os_arch:android_arm": ["-DANDROID_ARM_SHARED"], |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 502 | "//conditions:default": [], |
| 503 | }), |
| 504 | shared_srcs = ["sharedonly.cpp"] + select({ |
| 505 | "//build/bazel/platforms/arch:arm": ["arm_shared.cpp"], |
| 506 | "//conditions:default": [], |
| 507 | }) + select({ |
| 508 | "//build/bazel/platforms/os:android": ["android_shared.cpp"], |
| 509 | "//conditions:default": [], |
| 510 | }), |
| 511 | srcs = ["both.cpp"], |
| 512 | static_copts = ["staticflag"] + select({ |
| 513 | "//build/bazel/platforms/arch:x86": ["-DX86_STATIC"], |
| 514 | "//conditions:default": [], |
| 515 | }), |
| 516 | static_deps_for_shared = [":static_dep_for_shared"] + select({ |
| 517 | "//build/bazel/platforms/arch:arm": [":arm_static_dep_for_shared"], |
| 518 | "//conditions:default": [], |
| 519 | }) + select({ |
| 520 | "//build/bazel/platforms/os:android": [":android_dep_for_shared"], |
| 521 | "//conditions:default": [], |
| 522 | }), |
| 523 | static_deps_for_static = [":static_dep_for_static"] + select({ |
| 524 | "//build/bazel/platforms/arch:x86": [":x86_dep_for_static"], |
| 525 | "//conditions:default": [], |
| 526 | }), |
| 527 | static_srcs = ["staticonly.cpp"] + select({ |
| 528 | "//build/bazel/platforms/arch:x86": ["x86_static.cpp"], |
| 529 | "//conditions:default": [], |
| 530 | }), |
| 531 | whole_archive_deps_for_shared = select({ |
| 532 | "//build/bazel/platforms/arch:arm": [":arm_whole_static_dep_for_shared"], |
| 533 | "//conditions:default": [], |
| 534 | }), |
| 535 | )`}, |
| 536 | }) |
| 537 | } |
| 538 | |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame^] | 539 | func TestCcLibrarySharedStaticPropsWithMixedSources(t *testing.T) { |
| 540 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 541 | description: "cc_library shared/static props with c/cpp/s mixed sources", |
| 542 | moduleTypeUnderTest: "cc_library", |
| 543 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 544 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 545 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 546 | dir: "foo/bar", |
| 547 | filesystem: map[string]string{ |
| 548 | "foo/bar/both_source.cpp": "", |
| 549 | "foo/bar/both_source.cc": "", |
| 550 | "foo/bar/both_source.c": "", |
| 551 | "foo/bar/both_source.s": "", |
| 552 | "foo/bar/both_source.S": "", |
| 553 | "foo/bar/shared_source.cpp": "", |
| 554 | "foo/bar/shared_source.cc": "", |
| 555 | "foo/bar/shared_source.c": "", |
| 556 | "foo/bar/shared_source.s": "", |
| 557 | "foo/bar/shared_source.S": "", |
| 558 | "foo/bar/static_source.cpp": "", |
| 559 | "foo/bar/static_source.cc": "", |
| 560 | "foo/bar/static_source.c": "", |
| 561 | "foo/bar/static_source.s": "", |
| 562 | "foo/bar/static_source.S": "", |
| 563 | "foo/bar/Android.bp": ` |
| 564 | cc_library { |
| 565 | name: "a", |
| 566 | srcs: [ |
| 567 | "both_source.cpp", |
| 568 | "both_source.cc", |
| 569 | "both_source.c", |
| 570 | "both_source.s", |
| 571 | "both_source.S", |
| 572 | ":both_filegroup", |
| 573 | ], |
| 574 | static: { |
| 575 | srcs: [ |
| 576 | "static_source.cpp", |
| 577 | "static_source.cc", |
| 578 | "static_source.c", |
| 579 | "static_source.s", |
| 580 | "static_source.S", |
| 581 | ":static_filegroup", |
| 582 | ], |
| 583 | }, |
| 584 | shared: { |
| 585 | srcs: [ |
| 586 | "shared_source.cpp", |
| 587 | "shared_source.cc", |
| 588 | "shared_source.c", |
| 589 | "shared_source.s", |
| 590 | "shared_source.S", |
| 591 | ":shared_filegroup", |
| 592 | ], |
| 593 | }, |
| 594 | bazel_module: { bp2build_available: true }, |
| 595 | } |
| 596 | |
| 597 | filegroup { |
| 598 | name: "both_filegroup", |
| 599 | srcs: [ |
| 600 | // Not relevant, handled by filegroup macro |
| 601 | ], |
| 602 | } |
| 603 | |
| 604 | filegroup { |
| 605 | name: "shared_filegroup", |
| 606 | srcs: [ |
| 607 | // Not relevant, handled by filegroup macro |
| 608 | ], |
| 609 | } |
| 610 | |
| 611 | filegroup { |
| 612 | name: "static_filegroup", |
| 613 | srcs: [ |
| 614 | // Not relevant, handled by filegroup macro |
| 615 | ], |
| 616 | } |
| 617 | `, |
| 618 | }, |
| 619 | blueprint: soongCcLibraryPreamble, |
| 620 | expectedBazelTargets: []string{`cc_library( |
| 621 | name = "a", |
| 622 | copts = [ |
| 623 | "-Ifoo/bar", |
| 624 | "-I$(BINDIR)/foo/bar", |
| 625 | ], |
| 626 | shared_srcs = [ |
| 627 | ":shared_filegroup_cpp_srcs", |
| 628 | "shared_source.cc", |
| 629 | "shared_source.cpp", |
| 630 | ], |
| 631 | shared_srcs_as = [ |
| 632 | "shared_source.s", |
| 633 | "shared_source.S", |
| 634 | ":shared_filegroup_as_srcs", |
| 635 | ], |
| 636 | shared_srcs_c = [ |
| 637 | "shared_source.c", |
| 638 | ":shared_filegroup_c_srcs", |
| 639 | ], |
| 640 | srcs = [ |
| 641 | ":both_filegroup_cpp_srcs", |
| 642 | "both_source.cc", |
| 643 | "both_source.cpp", |
| 644 | ], |
| 645 | srcs_as = [ |
| 646 | "both_source.s", |
| 647 | "both_source.S", |
| 648 | ":both_filegroup_as_srcs", |
| 649 | ], |
| 650 | srcs_c = [ |
| 651 | "both_source.c", |
| 652 | ":both_filegroup_c_srcs", |
| 653 | ], |
| 654 | static_srcs = [ |
| 655 | ":static_filegroup_cpp_srcs", |
| 656 | "static_source.cc", |
| 657 | "static_source.cpp", |
| 658 | ], |
| 659 | static_srcs_as = [ |
| 660 | "static_source.s", |
| 661 | "static_source.S", |
| 662 | ":static_filegroup_as_srcs", |
| 663 | ], |
| 664 | static_srcs_c = [ |
| 665 | "static_source.c", |
| 666 | ":static_filegroup_c_srcs", |
| 667 | ], |
| 668 | )`}, |
| 669 | }) |
| 670 | } |
| 671 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 672 | func TestCcLibraryNonConfiguredVersionScript(t *testing.T) { |
| 673 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 674 | description: "cc_library non-configured version script", |
| 675 | moduleTypeUnderTest: "cc_library", |
| 676 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 677 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 678 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 679 | dir: "foo/bar", |
| 680 | filesystem: map[string]string{ |
| 681 | "foo/bar/Android.bp": ` |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 682 | cc_library { |
| 683 | name: "a", |
| 684 | srcs: ["a.cpp"], |
| 685 | version_script: "v.map", |
| 686 | bazel_module: { bp2build_available: true }, |
| 687 | } |
| 688 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 689 | }, |
| 690 | blueprint: soongCcLibraryPreamble, |
| 691 | expectedBazelTargets: []string{`cc_library( |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 692 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 693 | copts = [ |
| 694 | "-Ifoo/bar", |
| 695 | "-I$(BINDIR)/foo/bar", |
| 696 | ], |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 697 | srcs = ["a.cpp"], |
| 698 | version_script = "v.map", |
| 699 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 700 | }) |
| 701 | } |
| 702 | |
| 703 | func TestCcLibraryConfiguredVersionScript(t *testing.T) { |
| 704 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 705 | description: "cc_library configured version script", |
| 706 | moduleTypeUnderTest: "cc_library", |
| 707 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 708 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 709 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 710 | dir: "foo/bar", |
| 711 | filesystem: map[string]string{ |
| 712 | "foo/bar/Android.bp": ` |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 713 | cc_library { |
| 714 | name: "a", |
| 715 | srcs: ["a.cpp"], |
| 716 | arch: { |
| 717 | arm: { |
| 718 | version_script: "arm.map", |
| 719 | }, |
| 720 | arm64: { |
| 721 | version_script: "arm64.map", |
| 722 | }, |
| 723 | }, |
| 724 | |
| 725 | bazel_module: { bp2build_available: true }, |
| 726 | } |
| 727 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 728 | }, |
| 729 | blueprint: soongCcLibraryPreamble, |
| 730 | expectedBazelTargets: []string{`cc_library( |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 731 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 732 | copts = [ |
| 733 | "-Ifoo/bar", |
| 734 | "-I$(BINDIR)/foo/bar", |
| 735 | ], |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 736 | srcs = ["a.cpp"], |
| 737 | version_script = select({ |
| 738 | "//build/bazel/platforms/arch:arm": "arm.map", |
| 739 | "//build/bazel/platforms/arch:arm64": "arm64.map", |
| 740 | "//conditions:default": None, |
| 741 | }), |
| 742 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 743 | }) |
| 744 | } |
| 745 | |
| 746 | func TestCcLibrarySharedLibs(t *testing.T) { |
| 747 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 748 | description: "cc_library shared_libs", |
| 749 | moduleTypeUnderTest: "cc_library", |
| 750 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 751 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 752 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 753 | dir: "foo/bar", |
| 754 | filesystem: map[string]string{ |
| 755 | "foo/bar/Android.bp": ` |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 756 | cc_library { |
| 757 | name: "mylib", |
| 758 | bazel_module: { bp2build_available: true }, |
| 759 | } |
| 760 | |
| 761 | cc_library { |
| 762 | name: "a", |
| 763 | shared_libs: ["mylib",], |
| 764 | bazel_module: { bp2build_available: true }, |
| 765 | } |
| 766 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 767 | }, |
| 768 | blueprint: soongCcLibraryPreamble, |
| 769 | expectedBazelTargets: []string{`cc_library( |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 770 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 771 | copts = [ |
| 772 | "-Ifoo/bar", |
| 773 | "-I$(BINDIR)/foo/bar", |
| 774 | ], |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 775 | dynamic_deps = [":mylib"], |
| 776 | )`, `cc_library( |
| 777 | name = "mylib", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 778 | copts = [ |
| 779 | "-Ifoo/bar", |
| 780 | "-I$(BINDIR)/foo/bar", |
| 781 | ], |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 782 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 783 | }) |
| 784 | } |
| 785 | |
| 786 | func TestCcLibraryPackRelocations(t *testing.T) { |
| 787 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 788 | description: "cc_library pack_relocations test", |
| 789 | moduleTypeUnderTest: "cc_library", |
| 790 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 791 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 792 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 793 | dir: "foo/bar", |
| 794 | filesystem: map[string]string{ |
| 795 | "foo/bar/Android.bp": ` |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 796 | cc_library { |
| 797 | name: "a", |
| 798 | srcs: ["a.cpp"], |
| 799 | pack_relocations: false, |
| 800 | bazel_module: { bp2build_available: true }, |
| 801 | } |
| 802 | |
| 803 | cc_library { |
| 804 | name: "b", |
| 805 | srcs: ["b.cpp"], |
| 806 | arch: { |
| 807 | x86_64: { |
| 808 | pack_relocations: false, |
| 809 | }, |
| 810 | }, |
| 811 | bazel_module: { bp2build_available: true }, |
| 812 | } |
| 813 | |
| 814 | cc_library { |
| 815 | name: "c", |
| 816 | srcs: ["c.cpp"], |
| 817 | target: { |
| 818 | darwin: { |
| 819 | pack_relocations: false, |
| 820 | }, |
| 821 | }, |
| 822 | bazel_module: { bp2build_available: true }, |
| 823 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 824 | }, |
| 825 | blueprint: soongCcLibraryPreamble, |
| 826 | expectedBazelTargets: []string{`cc_library( |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 827 | name = "a", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 828 | copts = [ |
| 829 | "-Ifoo/bar", |
| 830 | "-I$(BINDIR)/foo/bar", |
| 831 | ], |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 832 | linkopts = ["-Wl,--pack-dyn-relocs=none"], |
| 833 | srcs = ["a.cpp"], |
| 834 | )`, `cc_library( |
| 835 | name = "b", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 836 | copts = [ |
| 837 | "-Ifoo/bar", |
| 838 | "-I$(BINDIR)/foo/bar", |
| 839 | ], |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 840 | linkopts = select({ |
| 841 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--pack-dyn-relocs=none"], |
| 842 | "//conditions:default": [], |
| 843 | }), |
| 844 | srcs = ["b.cpp"], |
| 845 | )`, `cc_library( |
| 846 | name = "c", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 847 | copts = [ |
| 848 | "-Ifoo/bar", |
| 849 | "-I$(BINDIR)/foo/bar", |
| 850 | ], |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 851 | linkopts = select({ |
| 852 | "//build/bazel/platforms/os:darwin": ["-Wl,--pack-dyn-relocs=none"], |
| 853 | "//conditions:default": [], |
| 854 | }), |
| 855 | srcs = ["c.cpp"], |
| 856 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 857 | }) |
| 858 | } |
| 859 | |
| 860 | func TestCcLibrarySpacesInCopts(t *testing.T) { |
| 861 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 862 | description: "cc_library spaces in copts", |
| 863 | moduleTypeUnderTest: "cc_library", |
| 864 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 865 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 866 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 867 | dir: "foo/bar", |
| 868 | filesystem: map[string]string{ |
| 869 | "foo/bar/Android.bp": ` |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 870 | cc_library { |
| 871 | name: "a", |
| 872 | cflags: ["-include header.h",], |
| 873 | bazel_module: { bp2build_available: true }, |
| 874 | } |
| 875 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 876 | }, |
| 877 | blueprint: soongCcLibraryPreamble, |
| 878 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 879 | name = "a", |
| 880 | copts = [ |
| 881 | "-include", |
| 882 | "header.h", |
| 883 | "-Ifoo/bar", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 884 | "-I$(BINDIR)/foo/bar", |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 885 | ], |
| 886 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 887 | }) |
| 888 | } |
| 889 | |
| 890 | func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { |
| 891 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 892 | description: "cc_library cppflags usage", |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 893 | moduleTypeUnderTest: "cc_library", |
| 894 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 895 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 896 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 897 | dir: "foo/bar", |
| 898 | filesystem: map[string]string{ |
| 899 | "foo/bar/Android.bp": `cc_library { |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 900 | name: "a", |
| 901 | srcs: ["a.cpp"], |
| 902 | cflags: [ |
| 903 | "-Wall", |
| 904 | ], |
| 905 | cppflags: [ |
| 906 | "-fsigned-char", |
| 907 | "-pedantic", |
| 908 | ], |
| 909 | arch: { |
| 910 | arm64: { |
| 911 | cppflags: ["-DARM64=1"], |
| 912 | }, |
| 913 | }, |
| 914 | target: { |
| 915 | android: { |
| 916 | cppflags: ["-DANDROID=1"], |
| 917 | }, |
| 918 | }, |
| 919 | bazel_module: { bp2build_available: true }, |
| 920 | } |
| 921 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 922 | }, |
| 923 | blueprint: soongCcLibraryPreamble, |
| 924 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 925 | name = "a", |
| 926 | copts = [ |
| 927 | "-Wall", |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 928 | "-Ifoo/bar", |
Chris Parsons | 484e50a | 2021-05-13 15:13:04 -0400 | [diff] [blame] | 929 | "-I$(BINDIR)/foo/bar", |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 930 | ], |
| 931 | cppflags = [ |
| 932 | "-fsigned-char", |
| 933 | "-pedantic", |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 934 | ] + select({ |
| 935 | "//build/bazel/platforms/arch:arm64": ["-DARM64=1"], |
| 936 | "//conditions:default": [], |
| 937 | }) + select({ |
| 938 | "//build/bazel/platforms/os:android": ["-DANDROID=1"], |
| 939 | "//conditions:default": [], |
| 940 | }), |
| 941 | srcs = ["a.cpp"], |
| 942 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 943 | }) |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 944 | } |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 945 | |
| 946 | func TestCcLibraryLabelAttributeGetTargetProperties(t *testing.T) { |
| 947 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 948 | description: "cc_library GetTargetProperties on a LabelAttribute", |
| 949 | moduleTypeUnderTest: "cc_library", |
| 950 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 951 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 952 | depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, |
| 953 | dir: "foo/bar", |
| 954 | filesystem: map[string]string{ |
| 955 | "foo/bar/Android.bp": ` |
| 956 | cc_library { |
| 957 | name: "a", |
| 958 | srcs: ["a.cpp"], |
| 959 | target: { |
| 960 | android_arm: { |
| 961 | version_script: "android_arm.map", |
| 962 | }, |
| 963 | linux_bionic_arm64: { |
| 964 | version_script: "linux_bionic_arm64.map", |
| 965 | }, |
| 966 | }, |
| 967 | |
| 968 | bazel_module: { bp2build_available: true }, |
| 969 | } |
| 970 | `, |
| 971 | }, |
| 972 | blueprint: soongCcLibraryPreamble, |
| 973 | expectedBazelTargets: []string{`cc_library( |
| 974 | name = "a", |
| 975 | copts = [ |
| 976 | "-Ifoo/bar", |
| 977 | "-I$(BINDIR)/foo/bar", |
| 978 | ], |
| 979 | srcs = ["a.cpp"], |
| 980 | version_script = select({ |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 981 | "//build/bazel/platforms/os_arch:android_arm": "android_arm.map", |
| 982 | "//build/bazel/platforms/os_arch:linux_bionic_arm64": "linux_bionic_arm64.map", |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 983 | "//conditions:default": None, |
| 984 | }), |
| 985 | )`}, |
| 986 | }) |
| 987 | } |