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