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