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 | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 352 | dynamic_deps = [":shared_dep_for_both"], |
Chris Parsons | d635877 | 2021-05-18 18:35:24 -0400 | [diff] [blame] | 353 | implementation_deps = [":static_dep_for_both"], |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 354 | shared = { |
| 355 | "copts": ["sharedflag"], |
| 356 | "dynamic_deps": [":shared_dep_for_shared"], |
| 357 | "srcs": ["sharedonly.cpp"], |
| 358 | "static_deps": [":static_dep_for_shared"], |
| 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"], |
| 364 | "dynamic_deps": [":shared_dep_for_static"], |
| 365 | "srcs": ["staticonly.cpp"], |
| 366 | "static_deps": [":static_dep_for_static"], |
| 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 | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 374 | func TestCcLibraryWholeStaticLibsAlwaysLink(t *testing.T) { |
| 375 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 376 | moduleTypeUnderTest: "cc_library", |
| 377 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 378 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 379 | dir: "foo/bar", |
| 380 | filesystem: map[string]string{ |
| 381 | "foo/bar/Android.bp": ` |
| 382 | cc_library { |
| 383 | name: "a", |
| 384 | whole_static_libs: ["whole_static_lib_for_both"], |
| 385 | static: { |
| 386 | whole_static_libs: ["whole_static_lib_for_static"], |
| 387 | }, |
| 388 | shared: { |
| 389 | whole_static_libs: ["whole_static_lib_for_shared"], |
| 390 | }, |
| 391 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 392 | include_build_directory: false, |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | cc_prebuilt_library_static { name: "whole_static_lib_for_shared" } |
| 396 | |
| 397 | cc_prebuilt_library_static { name: "whole_static_lib_for_static" } |
| 398 | |
| 399 | cc_prebuilt_library_static { name: "whole_static_lib_for_both" } |
| 400 | `, |
| 401 | }, |
| 402 | blueprint: soongCcLibraryPreamble, |
| 403 | expectedBazelTargets: []string{`cc_library( |
| 404 | name = "a", |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 405 | shared = { |
| 406 | "whole_archive_deps": [":whole_static_lib_for_shared_alwayslink"], |
| 407 | }, |
| 408 | static = { |
| 409 | "whole_archive_deps": [":whole_static_lib_for_static_alwayslink"], |
| 410 | }, |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 411 | whole_archive_deps = [":whole_static_lib_for_both_alwayslink"], |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 412 | )`}, |
| 413 | }) |
| 414 | } |
| 415 | |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 416 | func TestCcLibrarySharedStaticPropsInArch(t *testing.T) { |
| 417 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 418 | description: "cc_library shared/static props in arch", |
| 419 | moduleTypeUnderTest: "cc_library", |
| 420 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 421 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 422 | dir: "foo/bar", |
| 423 | filesystem: map[string]string{ |
| 424 | "foo/bar/arm.cpp": "", |
| 425 | "foo/bar/x86.cpp": "", |
| 426 | "foo/bar/sharedonly.cpp": "", |
| 427 | "foo/bar/staticonly.cpp": "", |
| 428 | "foo/bar/Android.bp": ` |
| 429 | cc_library { |
| 430 | name: "a", |
| 431 | arch: { |
| 432 | arm: { |
| 433 | shared: { |
| 434 | srcs: ["arm_shared.cpp"], |
| 435 | cflags: ["-DARM_SHARED"], |
| 436 | static_libs: ["arm_static_dep_for_shared"], |
| 437 | whole_static_libs: ["arm_whole_static_dep_for_shared"], |
| 438 | shared_libs: ["arm_shared_dep_for_shared"], |
| 439 | }, |
| 440 | }, |
| 441 | x86: { |
| 442 | static: { |
| 443 | srcs: ["x86_static.cpp"], |
| 444 | cflags: ["-DX86_STATIC"], |
| 445 | static_libs: ["x86_dep_for_static"], |
| 446 | }, |
| 447 | }, |
| 448 | }, |
| 449 | target: { |
| 450 | android: { |
| 451 | shared: { |
| 452 | srcs: ["android_shared.cpp"], |
| 453 | cflags: ["-DANDROID_SHARED"], |
| 454 | static_libs: ["android_dep_for_shared"], |
| 455 | }, |
| 456 | }, |
| 457 | android_arm: { |
| 458 | shared: { |
| 459 | cflags: ["-DANDROID_ARM_SHARED"], |
| 460 | }, |
| 461 | }, |
| 462 | }, |
| 463 | srcs: ["both.cpp"], |
| 464 | cflags: ["bothflag"], |
| 465 | static_libs: ["static_dep_for_both"], |
| 466 | static: { |
| 467 | srcs: ["staticonly.cpp"], |
| 468 | cflags: ["staticflag"], |
| 469 | static_libs: ["static_dep_for_static"], |
| 470 | }, |
| 471 | shared: { |
| 472 | srcs: ["sharedonly.cpp"], |
| 473 | cflags: ["sharedflag"], |
| 474 | static_libs: ["static_dep_for_shared"], |
| 475 | }, |
| 476 | bazel_module: { bp2build_available: true }, |
| 477 | } |
| 478 | |
| 479 | cc_library_static { name: "static_dep_for_shared" } |
| 480 | cc_library_static { name: "static_dep_for_static" } |
| 481 | cc_library_static { name: "static_dep_for_both" } |
| 482 | |
| 483 | cc_library_static { name: "arm_static_dep_for_shared" } |
| 484 | cc_library_static { name: "arm_whole_static_dep_for_shared" } |
| 485 | cc_library_static { name: "arm_shared_dep_for_shared" } |
| 486 | |
| 487 | cc_library_static { name: "x86_dep_for_static" } |
| 488 | |
| 489 | cc_library_static { name: "android_dep_for_shared" } |
| 490 | `, |
| 491 | }, |
| 492 | blueprint: soongCcLibraryPreamble, |
| 493 | expectedBazelTargets: []string{`cc_library( |
| 494 | name = "a", |
Liz Kammer | 35687bc | 2021-09-10 10:07:07 -0400 | [diff] [blame] | 495 | copts = ["bothflag"], |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 496 | implementation_deps = [":static_dep_for_both"], |
Liz Kammer | 35687bc | 2021-09-10 10:07:07 -0400 | [diff] [blame] | 497 | local_includes = ["."], |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 498 | shared = { |
| 499 | "copts": ["sharedflag"] + select({ |
| 500 | "//build/bazel/platforms/arch:arm": ["-DARM_SHARED"], |
| 501 | "//conditions:default": [], |
| 502 | }) + select({ |
| 503 | "//build/bazel/platforms/os:android": ["-DANDROID_SHARED"], |
| 504 | "//conditions:default": [], |
| 505 | }) + select({ |
| 506 | "//build/bazel/platforms/os_arch:android_arm": ["-DANDROID_ARM_SHARED"], |
| 507 | "//conditions:default": [], |
| 508 | }), |
| 509 | "dynamic_deps": select({ |
| 510 | "//build/bazel/platforms/arch:arm": [":arm_shared_dep_for_shared"], |
| 511 | "//conditions:default": [], |
| 512 | }), |
| 513 | "srcs": ["sharedonly.cpp"] + select({ |
| 514 | "//build/bazel/platforms/arch:arm": ["arm_shared.cpp"], |
| 515 | "//conditions:default": [], |
| 516 | }) + select({ |
| 517 | "//build/bazel/platforms/os:android": ["android_shared.cpp"], |
| 518 | "//conditions:default": [], |
| 519 | }), |
| 520 | "static_deps": [":static_dep_for_shared"] + select({ |
| 521 | "//build/bazel/platforms/arch:arm": [":arm_static_dep_for_shared"], |
| 522 | "//conditions:default": [], |
| 523 | }) + select({ |
| 524 | "//build/bazel/platforms/os:android": [":android_dep_for_shared"], |
| 525 | "//conditions:default": [], |
| 526 | }), |
| 527 | "whole_archive_deps": select({ |
| 528 | "//build/bazel/platforms/arch:arm": [":arm_whole_static_dep_for_shared"], |
| 529 | "//conditions:default": [], |
| 530 | }), |
| 531 | }, |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 532 | srcs = ["both.cpp"], |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 533 | static = { |
| 534 | "copts": ["staticflag"] + select({ |
| 535 | "//build/bazel/platforms/arch:x86": ["-DX86_STATIC"], |
| 536 | "//conditions:default": [], |
| 537 | }), |
| 538 | "srcs": ["staticonly.cpp"] + select({ |
| 539 | "//build/bazel/platforms/arch:x86": ["x86_static.cpp"], |
| 540 | "//conditions:default": [], |
| 541 | }), |
| 542 | "static_deps": [":static_dep_for_static"] + select({ |
| 543 | "//build/bazel/platforms/arch:x86": [":x86_dep_for_static"], |
| 544 | "//conditions:default": [], |
| 545 | }), |
| 546 | }, |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 547 | )`}, |
| 548 | }) |
| 549 | } |
| 550 | |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 551 | func TestCcLibrarySharedStaticPropsWithMixedSources(t *testing.T) { |
| 552 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 553 | description: "cc_library shared/static props with c/cpp/s mixed sources", |
| 554 | moduleTypeUnderTest: "cc_library", |
| 555 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 556 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 557 | dir: "foo/bar", |
| 558 | filesystem: map[string]string{ |
| 559 | "foo/bar/both_source.cpp": "", |
| 560 | "foo/bar/both_source.cc": "", |
| 561 | "foo/bar/both_source.c": "", |
| 562 | "foo/bar/both_source.s": "", |
| 563 | "foo/bar/both_source.S": "", |
| 564 | "foo/bar/shared_source.cpp": "", |
| 565 | "foo/bar/shared_source.cc": "", |
| 566 | "foo/bar/shared_source.c": "", |
| 567 | "foo/bar/shared_source.s": "", |
| 568 | "foo/bar/shared_source.S": "", |
| 569 | "foo/bar/static_source.cpp": "", |
| 570 | "foo/bar/static_source.cc": "", |
| 571 | "foo/bar/static_source.c": "", |
| 572 | "foo/bar/static_source.s": "", |
| 573 | "foo/bar/static_source.S": "", |
| 574 | "foo/bar/Android.bp": ` |
| 575 | cc_library { |
| 576 | name: "a", |
| 577 | srcs: [ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 578 | "both_source.cpp", |
| 579 | "both_source.cc", |
| 580 | "both_source.c", |
| 581 | "both_source.s", |
| 582 | "both_source.S", |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 583 | ":both_filegroup", |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 584 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 585 | static: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 586 | srcs: [ |
| 587 | "static_source.cpp", |
| 588 | "static_source.cc", |
| 589 | "static_source.c", |
| 590 | "static_source.s", |
| 591 | "static_source.S", |
| 592 | ":static_filegroup", |
| 593 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 594 | }, |
| 595 | shared: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 596 | srcs: [ |
| 597 | "shared_source.cpp", |
| 598 | "shared_source.cc", |
| 599 | "shared_source.c", |
| 600 | "shared_source.s", |
| 601 | "shared_source.S", |
| 602 | ":shared_filegroup", |
| 603 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 604 | }, |
| 605 | bazel_module: { bp2build_available: true }, |
| 606 | } |
| 607 | |
| 608 | filegroup { |
| 609 | name: "both_filegroup", |
| 610 | srcs: [ |
| 611 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 612 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | filegroup { |
| 616 | name: "shared_filegroup", |
| 617 | srcs: [ |
| 618 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 619 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | filegroup { |
| 623 | name: "static_filegroup", |
| 624 | srcs: [ |
| 625 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 626 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 627 | } |
| 628 | `, |
| 629 | }, |
| 630 | blueprint: soongCcLibraryPreamble, |
| 631 | expectedBazelTargets: []string{`cc_library( |
| 632 | name = "a", |
Liz Kammer | 35687bc | 2021-09-10 10:07:07 -0400 | [diff] [blame] | 633 | local_includes = ["."], |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 634 | shared = { |
| 635 | "srcs": [ |
| 636 | ":shared_filegroup_cpp_srcs", |
| 637 | "shared_source.cc", |
| 638 | "shared_source.cpp", |
| 639 | ], |
| 640 | "srcs_as": [ |
| 641 | "shared_source.s", |
| 642 | "shared_source.S", |
| 643 | ":shared_filegroup_as_srcs", |
| 644 | ], |
| 645 | "srcs_c": [ |
| 646 | "shared_source.c", |
| 647 | ":shared_filegroup_c_srcs", |
| 648 | ], |
| 649 | }, |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 650 | srcs = [ |
| 651 | ":both_filegroup_cpp_srcs", |
| 652 | "both_source.cc", |
| 653 | "both_source.cpp", |
| 654 | ], |
| 655 | srcs_as = [ |
| 656 | "both_source.s", |
| 657 | "both_source.S", |
| 658 | ":both_filegroup_as_srcs", |
| 659 | ], |
| 660 | srcs_c = [ |
| 661 | "both_source.c", |
| 662 | ":both_filegroup_c_srcs", |
| 663 | ], |
Jingwen Chen | c4dc9b4 | 2021-06-11 12:51:48 +0000 | [diff] [blame] | 664 | static = { |
| 665 | "srcs": [ |
| 666 | ":static_filegroup_cpp_srcs", |
| 667 | "static_source.cc", |
| 668 | "static_source.cpp", |
| 669 | ], |
| 670 | "srcs_as": [ |
| 671 | "static_source.s", |
| 672 | "static_source.S", |
| 673 | ":static_filegroup_as_srcs", |
| 674 | ], |
| 675 | "srcs_c": [ |
| 676 | "static_source.c", |
| 677 | ":static_filegroup_c_srcs", |
| 678 | ], |
| 679 | }, |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 680 | )`}, |
| 681 | }) |
| 682 | } |
| 683 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 684 | func TestCcLibraryNonConfiguredVersionScript(t *testing.T) { |
| 685 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 686 | description: "cc_library non-configured version script", |
| 687 | moduleTypeUnderTest: "cc_library", |
| 688 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 689 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 690 | dir: "foo/bar", |
| 691 | filesystem: map[string]string{ |
| 692 | "foo/bar/Android.bp": ` |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 693 | cc_library { |
| 694 | name: "a", |
| 695 | srcs: ["a.cpp"], |
| 696 | version_script: "v.map", |
| 697 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 698 | include_build_directory: false, |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 699 | } |
| 700 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 701 | }, |
| 702 | blueprint: soongCcLibraryPreamble, |
| 703 | expectedBazelTargets: []string{`cc_library( |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 704 | name = "a", |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 705 | srcs = ["a.cpp"], |
| 706 | version_script = "v.map", |
| 707 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 708 | }) |
| 709 | } |
| 710 | |
| 711 | func TestCcLibraryConfiguredVersionScript(t *testing.T) { |
| 712 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 713 | description: "cc_library configured version script", |
| 714 | moduleTypeUnderTest: "cc_library", |
| 715 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 716 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 717 | dir: "foo/bar", |
| 718 | filesystem: map[string]string{ |
| 719 | "foo/bar/Android.bp": ` |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 720 | cc_library { |
| 721 | name: "a", |
| 722 | srcs: ["a.cpp"], |
| 723 | arch: { |
| 724 | arm: { |
| 725 | version_script: "arm.map", |
| 726 | }, |
| 727 | arm64: { |
| 728 | version_script: "arm64.map", |
| 729 | }, |
| 730 | }, |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 731 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 732 | bazel_module: { bp2build_available: true }, |
| 733 | include_build_directory: false, |
| 734 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 735 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 736 | }, |
| 737 | blueprint: soongCcLibraryPreamble, |
| 738 | expectedBazelTargets: []string{`cc_library( |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 739 | name = "a", |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 740 | srcs = ["a.cpp"], |
| 741 | version_script = select({ |
| 742 | "//build/bazel/platforms/arch:arm": "arm.map", |
| 743 | "//build/bazel/platforms/arch:arm64": "arm64.map", |
| 744 | "//conditions:default": None, |
| 745 | }), |
| 746 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 747 | }) |
| 748 | } |
| 749 | |
| 750 | func TestCcLibrarySharedLibs(t *testing.T) { |
| 751 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 752 | description: "cc_library shared_libs", |
| 753 | moduleTypeUnderTest: "cc_library", |
| 754 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 755 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 756 | blueprint: soongCcLibraryPreamble + ` |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 757 | cc_library { |
| 758 | name: "mylib", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 759 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | cc_library { |
| 763 | name: "a", |
| 764 | shared_libs: ["mylib",], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 765 | include_build_directory: false, |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 766 | } |
| 767 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 768 | expectedBazelTargets: []string{`cc_library( |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 769 | name = "a", |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 770 | dynamic_deps = [":mylib"], |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 771 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 772 | }) |
| 773 | } |
| 774 | |
| 775 | func TestCcLibraryPackRelocations(t *testing.T) { |
| 776 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 777 | description: "cc_library pack_relocations test", |
| 778 | moduleTypeUnderTest: "cc_library", |
| 779 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 780 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 781 | blueprint: soongCcLibraryPreamble + ` |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 782 | cc_library { |
| 783 | name: "a", |
| 784 | srcs: ["a.cpp"], |
| 785 | pack_relocations: false, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 786 | include_build_directory: false, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | cc_library { |
| 790 | name: "b", |
| 791 | srcs: ["b.cpp"], |
| 792 | arch: { |
| 793 | x86_64: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 794 | pack_relocations: false, |
| 795 | }, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 796 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 797 | include_build_directory: false, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | cc_library { |
| 801 | name: "c", |
| 802 | srcs: ["c.cpp"], |
| 803 | target: { |
| 804 | darwin: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 805 | pack_relocations: false, |
| 806 | }, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 807 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 808 | include_build_directory: false, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 809 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 810 | expectedBazelTargets: []string{`cc_library( |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 811 | name = "a", |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 812 | linkopts = ["-Wl,--pack-dyn-relocs=none"], |
| 813 | srcs = ["a.cpp"], |
| 814 | )`, `cc_library( |
| 815 | name = "b", |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 816 | linkopts = select({ |
| 817 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--pack-dyn-relocs=none"], |
| 818 | "//conditions:default": [], |
| 819 | }), |
| 820 | srcs = ["b.cpp"], |
| 821 | )`, `cc_library( |
| 822 | name = "c", |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 823 | linkopts = select({ |
| 824 | "//build/bazel/platforms/os:darwin": ["-Wl,--pack-dyn-relocs=none"], |
| 825 | "//conditions:default": [], |
| 826 | }), |
| 827 | srcs = ["c.cpp"], |
| 828 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 829 | }) |
| 830 | } |
| 831 | |
| 832 | func TestCcLibrarySpacesInCopts(t *testing.T) { |
| 833 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 834 | description: "cc_library spaces in copts", |
| 835 | moduleTypeUnderTest: "cc_library", |
| 836 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 837 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 838 | blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 839 | cc_library { |
| 840 | name: "a", |
| 841 | cflags: ["-include header.h",], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 842 | include_build_directory: false, |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 843 | } |
| 844 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 845 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 846 | name = "a", |
| 847 | copts = [ |
| 848 | "-include", |
| 849 | "header.h", |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 850 | ], |
| 851 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 852 | }) |
| 853 | } |
| 854 | |
| 855 | func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { |
| 856 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 857 | description: "cc_library cppflags usage", |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 858 | moduleTypeUnderTest: "cc_library", |
| 859 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 860 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 861 | blueprint: soongCcLibraryPreamble + `cc_library { |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 862 | name: "a", |
| 863 | srcs: ["a.cpp"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 864 | cflags: ["-Wall"], |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 865 | cppflags: [ |
| 866 | "-fsigned-char", |
| 867 | "-pedantic", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 868 | ], |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 869 | arch: { |
| 870 | arm64: { |
| 871 | cppflags: ["-DARM64=1"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 872 | }, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 873 | }, |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 874 | target: { |
| 875 | android: { |
| 876 | cppflags: ["-DANDROID=1"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 877 | }, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 878 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 879 | include_build_directory: false, |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 880 | } |
| 881 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 882 | expectedBazelTargets: []string{`cc_library( |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 883 | name = "a", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 884 | copts = ["-Wall"], |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 885 | cppflags = [ |
| 886 | "-fsigned-char", |
| 887 | "-pedantic", |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 888 | ] + select({ |
| 889 | "//build/bazel/platforms/arch:arm64": ["-DARM64=1"], |
| 890 | "//conditions:default": [], |
| 891 | }) + select({ |
| 892 | "//build/bazel/platforms/os:android": ["-DANDROID=1"], |
| 893 | "//conditions:default": [], |
| 894 | }), |
| 895 | srcs = ["a.cpp"], |
| 896 | )`}, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 897 | }) |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 898 | } |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 899 | |
| 900 | func TestCcLibraryLabelAttributeGetTargetProperties(t *testing.T) { |
| 901 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 902 | description: "cc_library GetTargetProperties on a LabelAttribute", |
| 903 | moduleTypeUnderTest: "cc_library", |
| 904 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 905 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 906 | blueprint: soongCcLibraryPreamble + ` |
| 907 | cc_library { |
| 908 | name: "a", |
| 909 | srcs: ["a.cpp"], |
| 910 | target: { |
| 911 | android_arm: { |
| 912 | version_script: "android_arm.map", |
| 913 | }, |
| 914 | linux_bionic_arm64: { |
| 915 | version_script: "linux_bionic_arm64.map", |
| 916 | }, |
| 917 | }, |
| 918 | include_build_directory: false, |
| 919 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 920 | `, |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 921 | expectedBazelTargets: []string{`cc_library( |
| 922 | name = "a", |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 923 | srcs = ["a.cpp"], |
| 924 | version_script = select({ |
Rupert Shuttleworth | ffd4582 | 2021-05-14 03:02:34 -0400 | [diff] [blame] | 925 | "//build/bazel/platforms/os_arch:android_arm": "android_arm.map", |
| 926 | "//build/bazel/platforms/os_arch:linux_bionic_arm64": "linux_bionic_arm64.map", |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 927 | "//conditions:default": None, |
| 928 | }), |
| 929 | )`}, |
| 930 | }) |
| 931 | } |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 932 | |
| 933 | func TestCcLibraryExcludeLibs(t *testing.T) { |
| 934 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 935 | moduleTypeUnderTest: "cc_library", |
| 936 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 937 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 938 | filesystem: map[string]string{}, |
| 939 | blueprint: soongCcLibraryStaticPreamble + ` |
| 940 | cc_library { |
| 941 | name: "foo_static", |
| 942 | srcs: ["common.c"], |
| 943 | whole_static_libs: [ |
| 944 | "arm_whole_static_lib_excludes", |
| 945 | "malloc_not_svelte_whole_static_lib_excludes" |
| 946 | ], |
| 947 | static_libs: [ |
| 948 | "arm_static_lib_excludes", |
| 949 | "malloc_not_svelte_static_lib_excludes" |
| 950 | ], |
| 951 | shared_libs: [ |
| 952 | "arm_shared_lib_excludes", |
| 953 | ], |
| 954 | arch: { |
| 955 | arm: { |
| 956 | exclude_shared_libs: [ |
| 957 | "arm_shared_lib_excludes", |
| 958 | ], |
| 959 | exclude_static_libs: [ |
| 960 | "arm_static_lib_excludes", |
| 961 | "arm_whole_static_lib_excludes", |
| 962 | ], |
| 963 | }, |
| 964 | }, |
| 965 | product_variables: { |
| 966 | malloc_not_svelte: { |
| 967 | shared_libs: ["malloc_not_svelte_shared_lib"], |
| 968 | whole_static_libs: ["malloc_not_svelte_whole_static_lib"], |
| 969 | exclude_static_libs: [ |
| 970 | "malloc_not_svelte_static_lib_excludes", |
| 971 | "malloc_not_svelte_whole_static_lib_excludes", |
| 972 | ], |
| 973 | }, |
| 974 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 975 | include_build_directory: false, |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | cc_library { |
| 979 | name: "arm_whole_static_lib_excludes", |
| 980 | bazel_module: { bp2build_available: false }, |
| 981 | } |
| 982 | |
| 983 | cc_library { |
| 984 | name: "malloc_not_svelte_whole_static_lib", |
| 985 | bazel_module: { bp2build_available: false }, |
| 986 | } |
| 987 | |
| 988 | cc_library { |
| 989 | name: "malloc_not_svelte_whole_static_lib_excludes", |
| 990 | bazel_module: { bp2build_available: false }, |
| 991 | } |
| 992 | |
| 993 | cc_library { |
| 994 | name: "arm_static_lib_excludes", |
| 995 | bazel_module: { bp2build_available: false }, |
| 996 | } |
| 997 | |
| 998 | cc_library { |
| 999 | name: "malloc_not_svelte_static_lib_excludes", |
| 1000 | bazel_module: { bp2build_available: false }, |
| 1001 | } |
| 1002 | |
| 1003 | cc_library { |
| 1004 | name: "arm_shared_lib_excludes", |
| 1005 | bazel_module: { bp2build_available: false }, |
| 1006 | } |
| 1007 | |
| 1008 | cc_library { |
| 1009 | name: "malloc_not_svelte_shared_lib", |
| 1010 | bazel_module: { bp2build_available: false }, |
| 1011 | } |
| 1012 | `, |
| 1013 | expectedBazelTargets: []string{ |
| 1014 | `cc_library( |
| 1015 | name = "foo_static", |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1016 | dynamic_deps = select({ |
| 1017 | "//build/bazel/platforms/arch:arm": [], |
| 1018 | "//conditions:default": [":arm_shared_lib_excludes"], |
| 1019 | }) + select({ |
| 1020 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_shared_lib"], |
| 1021 | "//conditions:default": [], |
| 1022 | }), |
| 1023 | implementation_deps = select({ |
| 1024 | "//build/bazel/platforms/arch:arm": [], |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1025 | "//conditions:default": [":arm_static_lib_excludes_bp2build_cc_library_static"], |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1026 | }) + select({ |
| 1027 | "//build/bazel/product_variables:malloc_not_svelte": [], |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1028 | "//conditions:default": [":malloc_not_svelte_static_lib_excludes_bp2build_cc_library_static"], |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1029 | }), |
| 1030 | srcs_c = ["common.c"], |
| 1031 | whole_archive_deps = select({ |
| 1032 | "//build/bazel/platforms/arch:arm": [], |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1033 | "//conditions:default": [":arm_whole_static_lib_excludes_bp2build_cc_library_static"], |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1034 | }) + select({ |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1035 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_whole_static_lib_bp2build_cc_library_static"], |
| 1036 | "//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] | 1037 | }), |
| 1038 | )`, |
| 1039 | }, |
| 1040 | }) |
| 1041 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1042 | |
| 1043 | func TestCCLibraryNoCrtTrue(t *testing.T) { |
| 1044 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1045 | description: "cc_library - simple example", |
| 1046 | moduleTypeUnderTest: "cc_library", |
| 1047 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1048 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1049 | filesystem: map[string]string{ |
| 1050 | "impl.cpp": "", |
| 1051 | }, |
| 1052 | blueprint: soongCcLibraryPreamble + ` |
| 1053 | cc_library_headers { name: "some-headers" } |
| 1054 | cc_library { |
| 1055 | name: "foo-lib", |
| 1056 | srcs: ["impl.cpp"], |
| 1057 | no_libcrt: true, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1058 | include_build_directory: false, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1059 | } |
| 1060 | `, |
| 1061 | expectedBazelTargets: []string{`cc_library( |
| 1062 | name = "foo-lib", |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1063 | srcs = ["impl.cpp"], |
| 1064 | use_libcrt = False, |
| 1065 | )`}}) |
| 1066 | } |
| 1067 | |
| 1068 | func TestCCLibraryNoCrtFalse(t *testing.T) { |
| 1069 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1070 | moduleTypeUnderTest: "cc_library", |
| 1071 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1072 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1073 | filesystem: map[string]string{ |
| 1074 | "impl.cpp": "", |
| 1075 | }, |
| 1076 | blueprint: soongCcLibraryPreamble + ` |
| 1077 | cc_library_headers { name: "some-headers" } |
| 1078 | cc_library { |
| 1079 | name: "foo-lib", |
| 1080 | srcs: ["impl.cpp"], |
| 1081 | no_libcrt: false, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1082 | include_build_directory: false, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1083 | } |
| 1084 | `, |
| 1085 | expectedBazelTargets: []string{`cc_library( |
| 1086 | name = "foo-lib", |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1087 | srcs = ["impl.cpp"], |
| 1088 | use_libcrt = True, |
| 1089 | )`}}) |
| 1090 | } |
| 1091 | |
| 1092 | func TestCCLibraryNoCrtArchVariant(t *testing.T) { |
| 1093 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1094 | moduleTypeUnderTest: "cc_library", |
| 1095 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1096 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1097 | filesystem: map[string]string{ |
| 1098 | "impl.cpp": "", |
| 1099 | }, |
| 1100 | blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1101 | cc_library { |
| 1102 | name: "foo-lib", |
| 1103 | srcs: ["impl.cpp"], |
| 1104 | arch: { |
| 1105 | arm: { |
| 1106 | no_libcrt: true, |
| 1107 | }, |
| 1108 | x86: { |
| 1109 | no_libcrt: true, |
| 1110 | }, |
| 1111 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1112 | include_build_directory: false, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1113 | } |
| 1114 | `, |
| 1115 | expectedBazelTargets: []string{`cc_library( |
| 1116 | name = "foo-lib", |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1117 | srcs = ["impl.cpp"], |
| 1118 | use_libcrt = select({ |
| 1119 | "//build/bazel/platforms/arch:arm": False, |
| 1120 | "//build/bazel/platforms/arch:x86": False, |
| 1121 | "//conditions:default": None, |
| 1122 | }), |
| 1123 | )`}}) |
| 1124 | } |
| 1125 | |
| 1126 | func TestCCLibraryNoCrtArchVariantWithDefault(t *testing.T) { |
| 1127 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1128 | moduleTypeUnderTest: "cc_library", |
| 1129 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1130 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1131 | filesystem: map[string]string{ |
| 1132 | "impl.cpp": "", |
| 1133 | }, |
| 1134 | blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1135 | cc_library { |
| 1136 | name: "foo-lib", |
| 1137 | srcs: ["impl.cpp"], |
| 1138 | no_libcrt: false, |
| 1139 | arch: { |
| 1140 | arm: { |
| 1141 | no_libcrt: true, |
| 1142 | }, |
| 1143 | x86: { |
| 1144 | no_libcrt: true, |
| 1145 | }, |
| 1146 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1147 | include_build_directory: false, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1148 | } |
| 1149 | `, |
| 1150 | expectedBazelTargets: []string{`cc_library( |
| 1151 | name = "foo-lib", |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1152 | srcs = ["impl.cpp"], |
| 1153 | use_libcrt = select({ |
| 1154 | "//build/bazel/platforms/arch:arm": False, |
| 1155 | "//build/bazel/platforms/arch:x86": False, |
| 1156 | "//conditions:default": True, |
| 1157 | }), |
| 1158 | )`}}) |
| 1159 | } |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1160 | |
| 1161 | func TestCcLibraryStrip(t *testing.T) { |
| 1162 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1163 | description: "cc_library strip args", |
| 1164 | moduleTypeUnderTest: "cc_library", |
| 1165 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1166 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1167 | blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1168 | cc_library { |
| 1169 | name: "nothing", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1170 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1171 | } |
| 1172 | cc_library { |
| 1173 | name: "keep_symbols", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1174 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1175 | keep_symbols: true, |
| 1176 | }, |
| 1177 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1178 | } |
| 1179 | cc_library { |
| 1180 | name: "keep_symbols_and_debug_frame", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1181 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1182 | keep_symbols_and_debug_frame: true, |
| 1183 | }, |
| 1184 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1185 | } |
| 1186 | cc_library { |
| 1187 | name: "none", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1188 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1189 | none: true, |
| 1190 | }, |
| 1191 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1192 | } |
| 1193 | cc_library { |
| 1194 | name: "keep_symbols_list", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1195 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1196 | keep_symbols_list: ["symbol"], |
| 1197 | }, |
| 1198 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1199 | } |
| 1200 | cc_library { |
| 1201 | name: "all", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1202 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1203 | all: true, |
| 1204 | }, |
| 1205 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1206 | } |
| 1207 | `, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1208 | expectedBazelTargets: []string{`cc_library( |
| 1209 | name = "all", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1210 | strip = { |
| 1211 | "all": True, |
| 1212 | }, |
| 1213 | )`, `cc_library( |
| 1214 | name = "keep_symbols", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1215 | strip = { |
| 1216 | "keep_symbols": True, |
| 1217 | }, |
| 1218 | )`, `cc_library( |
| 1219 | name = "keep_symbols_and_debug_frame", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1220 | strip = { |
| 1221 | "keep_symbols_and_debug_frame": True, |
| 1222 | }, |
| 1223 | )`, `cc_library( |
| 1224 | name = "keep_symbols_list", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1225 | strip = { |
| 1226 | "keep_symbols_list": ["symbol"], |
| 1227 | }, |
| 1228 | )`, `cc_library( |
| 1229 | name = "none", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1230 | strip = { |
| 1231 | "none": True, |
| 1232 | }, |
| 1233 | )`, `cc_library( |
| 1234 | name = "nothing", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1235 | )`}, |
| 1236 | }) |
| 1237 | } |
| 1238 | |
| 1239 | func TestCcLibraryStripWithArch(t *testing.T) { |
| 1240 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1241 | description: "cc_library strip args", |
| 1242 | moduleTypeUnderTest: "cc_library", |
| 1243 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1244 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1245 | blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1246 | cc_library { |
| 1247 | name: "multi-arch", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1248 | target: { |
| 1249 | darwin: { |
| 1250 | strip: { |
| 1251 | keep_symbols_list: ["foo", "bar"] |
| 1252 | } |
| 1253 | }, |
| 1254 | }, |
| 1255 | arch: { |
| 1256 | arm: { |
| 1257 | strip: { |
| 1258 | keep_symbols_and_debug_frame: true, |
| 1259 | }, |
| 1260 | }, |
| 1261 | arm64: { |
| 1262 | strip: { |
| 1263 | keep_symbols: true, |
| 1264 | }, |
| 1265 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1266 | }, |
| 1267 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1268 | } |
| 1269 | `, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1270 | expectedBazelTargets: []string{`cc_library( |
| 1271 | name = "multi-arch", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1272 | strip = { |
| 1273 | "keep_symbols": select({ |
| 1274 | "//build/bazel/platforms/arch:arm64": True, |
| 1275 | "//conditions:default": None, |
| 1276 | }), |
| 1277 | "keep_symbols_and_debug_frame": select({ |
| 1278 | "//build/bazel/platforms/arch:arm": True, |
| 1279 | "//conditions:default": None, |
| 1280 | }), |
| 1281 | "keep_symbols_list": select({ |
| 1282 | "//build/bazel/platforms/os:darwin": [ |
| 1283 | "foo", |
| 1284 | "bar", |
| 1285 | ], |
| 1286 | "//conditions:default": [], |
| 1287 | }), |
| 1288 | }, |
| 1289 | )`}, |
| 1290 | }) |
| 1291 | } |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1292 | |
| 1293 | func TestCcLibrary_SystemSharedLibsRootEmpty(t *testing.T) { |
| 1294 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1295 | description: "cc_library system_shared_libs empty at root", |
| 1296 | moduleTypeUnderTest: "cc_library", |
| 1297 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1298 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1299 | blueprint: soongCcLibraryPreamble + ` |
| 1300 | cc_library { |
| 1301 | name: "root_empty", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1302 | system_shared_libs: [], |
| 1303 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1304 | } |
| 1305 | `, |
| 1306 | expectedBazelTargets: []string{`cc_library( |
| 1307 | name = "root_empty", |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1308 | system_dynamic_deps = [], |
| 1309 | )`}, |
| 1310 | }) |
| 1311 | } |
| 1312 | |
| 1313 | func TestCcLibrary_SystemSharedLibsStaticEmpty(t *testing.T) { |
| 1314 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1315 | description: "cc_library system_shared_libs empty for static variant", |
| 1316 | moduleTypeUnderTest: "cc_library", |
| 1317 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1318 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1319 | blueprint: soongCcLibraryPreamble + ` |
| 1320 | cc_library { |
| 1321 | name: "static_empty", |
| 1322 | static: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1323 | system_shared_libs: [], |
| 1324 | }, |
| 1325 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1326 | } |
| 1327 | `, |
| 1328 | expectedBazelTargets: []string{`cc_library( |
| 1329 | name = "static_empty", |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1330 | static = { |
| 1331 | "system_dynamic_deps": [], |
| 1332 | }, |
| 1333 | )`}, |
| 1334 | }) |
| 1335 | } |
| 1336 | |
| 1337 | func TestCcLibrary_SystemSharedLibsSharedEmpty(t *testing.T) { |
| 1338 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1339 | description: "cc_library system_shared_libs empty for shared variant", |
| 1340 | moduleTypeUnderTest: "cc_library", |
| 1341 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1342 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1343 | blueprint: soongCcLibraryPreamble + ` |
| 1344 | cc_library { |
| 1345 | name: "shared_empty", |
| 1346 | shared: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1347 | system_shared_libs: [], |
| 1348 | }, |
| 1349 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1350 | } |
| 1351 | `, |
| 1352 | expectedBazelTargets: []string{`cc_library( |
| 1353 | name = "shared_empty", |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1354 | shared = { |
| 1355 | "system_dynamic_deps": [], |
| 1356 | }, |
| 1357 | )`}, |
| 1358 | }) |
| 1359 | } |
| 1360 | |
| 1361 | func TestCcLibrary_SystemSharedLibsSharedBionicEmpty(t *testing.T) { |
| 1362 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1363 | description: "cc_library system_shared_libs empty for shared, bionic variant", |
| 1364 | moduleTypeUnderTest: "cc_library", |
| 1365 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1366 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1367 | blueprint: soongCcLibraryPreamble + ` |
| 1368 | cc_library { |
| 1369 | name: "shared_empty", |
| 1370 | target: { |
| 1371 | bionic: { |
| 1372 | shared: { |
| 1373 | system_shared_libs: [], |
| 1374 | } |
| 1375 | } |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1376 | }, |
| 1377 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1378 | } |
| 1379 | `, |
| 1380 | expectedBazelTargets: []string{`cc_library( |
| 1381 | name = "shared_empty", |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1382 | shared = { |
| 1383 | "system_dynamic_deps": [], |
| 1384 | }, |
| 1385 | )`}, |
| 1386 | }) |
| 1387 | } |
| 1388 | |
| 1389 | func TestCcLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) { |
| 1390 | // Note that this behavior is technically incorrect (it's a simplification). |
| 1391 | // The correct behavior would be if bp2build wrote `system_dynamic_deps = []` |
| 1392 | // only for linux_bionic, but `android` had `["libc", "libdl", "libm"]. |
| 1393 | // b/195791252 tracks the fix. |
| 1394 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1395 | description: "cc_library system_shared_libs empty for linux_bionic variant", |
| 1396 | moduleTypeUnderTest: "cc_library", |
| 1397 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1398 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1399 | blueprint: soongCcLibraryPreamble + ` |
| 1400 | cc_library { |
| 1401 | name: "target_linux_bionic_empty", |
| 1402 | target: { |
| 1403 | linux_bionic: { |
| 1404 | system_shared_libs: [], |
| 1405 | }, |
| 1406 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1407 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1408 | } |
| 1409 | `, |
| 1410 | expectedBazelTargets: []string{`cc_library( |
| 1411 | name = "target_linux_bionic_empty", |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1412 | system_dynamic_deps = [], |
| 1413 | )`}, |
| 1414 | }) |
| 1415 | } |
| 1416 | |
| 1417 | func TestCcLibrary_SystemSharedLibsBionicEmpty(t *testing.T) { |
| 1418 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1419 | description: "cc_library system_shared_libs empty for bionic variant", |
| 1420 | moduleTypeUnderTest: "cc_library", |
| 1421 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1422 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1423 | blueprint: soongCcLibraryPreamble + ` |
| 1424 | cc_library { |
| 1425 | name: "target_bionic_empty", |
| 1426 | target: { |
| 1427 | bionic: { |
| 1428 | system_shared_libs: [], |
| 1429 | }, |
| 1430 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1431 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1432 | } |
| 1433 | `, |
| 1434 | expectedBazelTargets: []string{`cc_library( |
| 1435 | name = "target_bionic_empty", |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1436 | system_dynamic_deps = [], |
| 1437 | )`}, |
| 1438 | }) |
| 1439 | } |
| 1440 | |
| 1441 | func TestCcLibrary_SystemSharedLibsSharedAndRoot(t *testing.T) { |
| 1442 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1443 | description: "cc_library system_shared_libs set for shared and root", |
| 1444 | moduleTypeUnderTest: "cc_library", |
| 1445 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1446 | moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, |
| 1447 | blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1448 | cc_library { |
| 1449 | name: "libc", |
| 1450 | bazel_module: { bp2build_available: false }, |
| 1451 | } |
| 1452 | cc_library { |
| 1453 | name: "libm", |
| 1454 | bazel_module: { bp2build_available: false }, |
| 1455 | } |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1456 | |
| 1457 | cc_library { |
| 1458 | name: "foo", |
| 1459 | system_shared_libs: ["libc"], |
| 1460 | shared: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1461 | system_shared_libs: ["libm"], |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1462 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1463 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1464 | } |
| 1465 | `, |
| 1466 | expectedBazelTargets: []string{`cc_library( |
| 1467 | name = "foo", |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1468 | shared = { |
| 1469 | "system_dynamic_deps": [":libm"], |
| 1470 | }, |
| 1471 | system_dynamic_deps = [":libc"], |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1472 | )`}, |
| 1473 | }) |
| 1474 | } |