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