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