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 ( |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 18 | "fmt" |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 1c92aef | 2021-08-23 16:10:00 +0000 | [diff] [blame] | 19 | "testing" |
| 20 | |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 21 | "android/soong/android" |
| 22 | "android/soong/cc" |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | const ( |
| 26 | // See cc/testing.go for more context |
| 27 | soongCcLibraryPreamble = ` |
| 28 | cc_defaults { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 29 | name: "linux_bionic_supported", |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 30 | }` |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 31 | |
| 32 | soongCcProtoLibraries = ` |
| 33 | cc_library { |
| 34 | name: "libprotobuf-cpp-lite", |
| 35 | bazel_module: { bp2build_available: false }, |
| 36 | } |
| 37 | |
| 38 | cc_library { |
| 39 | name: "libprotobuf-cpp-full", |
| 40 | bazel_module: { bp2build_available: false }, |
| 41 | }` |
| 42 | |
| 43 | soongCcProtoPreamble = soongCcLibraryPreamble + soongCcProtoLibraries |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 44 | ) |
| 45 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 46 | func runCcLibraryTestCase(t *testing.T, tc bp2buildTestCase) { |
Liz Kammer | e4982e8 | 2021-05-25 10:39:35 -0400 | [diff] [blame] | 47 | t.Helper() |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 48 | runBp2BuildTestCase(t, registerCcLibraryModuleTypes, tc) |
| 49 | } |
| 50 | |
| 51 | func registerCcLibraryModuleTypes(ctx android.RegistrationContext) { |
| 52 | cc.RegisterCCBuildComponents(ctx) |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 53 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 54 | ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 55 | ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 56 | ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) |
| 57 | } |
| 58 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 59 | func TestCcLibrarySimple(t *testing.T) { |
| 60 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 61 | description: "cc_library - simple example", |
| 62 | moduleTypeUnderTest: "cc_library", |
| 63 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 64 | filesystem: map[string]string{ |
| 65 | "android.cpp": "", |
Liz Kammer | 01a16e8 | 2021-07-16 16:33:47 -0400 | [diff] [blame] | 66 | "bionic.cpp": "", |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 67 | "darwin.cpp": "", |
| 68 | // Refer to cc.headerExts for the supported header extensions in Soong. |
| 69 | "header.h": "", |
| 70 | "header.hh": "", |
| 71 | "header.hpp": "", |
| 72 | "header.hxx": "", |
| 73 | "header.h++": "", |
| 74 | "header.inl": "", |
| 75 | "header.inc": "", |
| 76 | "header.ipp": "", |
| 77 | "header.h.generic": "", |
| 78 | "impl.cpp": "", |
| 79 | "linux.cpp": "", |
| 80 | "x86.cpp": "", |
| 81 | "x86_64.cpp": "", |
| 82 | "foo-dir/a.h": "", |
| 83 | }, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 84 | blueprint: soongCcLibraryPreamble + |
| 85 | simpleModuleDoNotConvertBp2build("cc_library_headers", "some-headers") + ` |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 86 | cc_library { |
| 87 | name: "foo-lib", |
| 88 | srcs: ["impl.cpp"], |
| 89 | cflags: ["-Wall"], |
| 90 | header_libs: ["some-headers"], |
| 91 | export_include_dirs: ["foo-dir"], |
| 92 | ldflags: ["-Wl,--exclude-libs=bar.a"], |
| 93 | arch: { |
| 94 | x86: { |
| 95 | ldflags: ["-Wl,--exclude-libs=baz.a"], |
| 96 | srcs: ["x86.cpp"], |
| 97 | }, |
| 98 | x86_64: { |
| 99 | ldflags: ["-Wl,--exclude-libs=qux.a"], |
| 100 | srcs: ["x86_64.cpp"], |
| 101 | }, |
| 102 | }, |
| 103 | target: { |
| 104 | android: { |
| 105 | srcs: ["android.cpp"], |
| 106 | }, |
| 107 | linux_glibc: { |
| 108 | srcs: ["linux.cpp"], |
| 109 | }, |
| 110 | darwin: { |
| 111 | srcs: ["darwin.cpp"], |
| 112 | }, |
Liz Kammer | 01a16e8 | 2021-07-16 16:33:47 -0400 | [diff] [blame] | 113 | bionic: { |
| 114 | srcs: ["bionic.cpp"] |
| 115 | }, |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 116 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 117 | include_build_directory: false, |
Yu Liu | fc60316 | 2022-03-01 15:44:08 -0800 | [diff] [blame] | 118 | sdk_version: "current", |
| 119 | min_sdk_version: "29", |
Yu Liu | a79c946 | 2022-03-22 16:35:22 -0700 | [diff] [blame] | 120 | use_version_lib: true, |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 121 | } |
| 122 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 123 | expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ |
| 124 | "copts": `["-Wall"]`, |
| 125 | "export_includes": `["foo-dir"]`, |
| 126 | "implementation_deps": `[":some-headers"]`, |
| 127 | "linkopts": `["-Wl,--exclude-libs=bar.a"] + select({ |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 128 | "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=baz.a"], |
| 129 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=qux.a"], |
| 130 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 131 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 132 | "srcs": `["impl.cpp"] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 133 | "//build/bazel/platforms/arch:x86": ["x86.cpp"], |
| 134 | "//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 135 | "//conditions:default": [], |
| 136 | }) + select({ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 137 | "//build/bazel/platforms/os:android": [ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 138 | "bionic.cpp", |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 139 | "android.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 140 | ], |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 141 | "//build/bazel/platforms/os:darwin": ["darwin.cpp"], |
| 142 | "//build/bazel/platforms/os:linux": ["linux.cpp"], |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 143 | "//build/bazel/platforms/os:linux_bionic": ["bionic.cpp"], |
Liz Kammer | 01a16e8 | 2021-07-16 16:33:47 -0400 | [diff] [blame] | 144 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 145 | })`, |
Yu Liu | a79c946 | 2022-03-22 16:35:22 -0700 | [diff] [blame] | 146 | "sdk_version": `"current"`, |
| 147 | "min_sdk_version": `"29"`, |
| 148 | "use_version_lib": `True`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 149 | }), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 150 | }) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | func TestCcLibraryTrimmedLdAndroid(t *testing.T) { |
| 154 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 155 | description: "cc_library - trimmed example of //bionic/linker:ld-android", |
| 156 | moduleTypeUnderTest: "cc_library", |
| 157 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 158 | filesystem: map[string]string{ |
| 159 | "ld-android.cpp": "", |
| 160 | "linked_list.h": "", |
| 161 | "linker.h": "", |
| 162 | "linker_block_allocator.h": "", |
| 163 | "linker_cfi.h": "", |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 164 | }, |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 165 | blueprint: soongCcLibraryPreamble + |
| 166 | simpleModuleDoNotConvertBp2build("cc_library_headers", "libc_headers") + ` |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 167 | cc_library { |
| 168 | name: "fake-ld-android", |
| 169 | srcs: ["ld_android.cpp"], |
| 170 | cflags: [ |
| 171 | "-Wall", |
| 172 | "-Wextra", |
| 173 | "-Wunused", |
| 174 | "-Werror", |
| 175 | ], |
| 176 | header_libs: ["libc_headers"], |
| 177 | ldflags: [ |
| 178 | "-Wl,--exclude-libs=libgcc.a", |
| 179 | "-Wl,--exclude-libs=libgcc_stripped.a", |
| 180 | "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a", |
| 181 | "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a", |
| 182 | "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a", |
| 183 | "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a", |
| 184 | ], |
| 185 | arch: { |
| 186 | x86: { |
| 187 | ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 188 | }, |
| 189 | x86_64: { |
| 190 | ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 191 | }, |
| 192 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 193 | include_build_directory: false, |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 194 | } |
| 195 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 196 | expectedBazelTargets: makeCcLibraryTargets("fake-ld-android", attrNameToString{ |
| 197 | "srcs": `["ld_android.cpp"]`, |
| 198 | "copts": `[ |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 199 | "-Wall", |
| 200 | "-Wextra", |
| 201 | "-Wunused", |
| 202 | "-Werror", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 203 | ]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 204 | "implementation_deps": `[":libc_headers"]`, |
| 205 | "linkopts": `[ |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 206 | "-Wl,--exclude-libs=libgcc.a", |
| 207 | "-Wl,--exclude-libs=libgcc_stripped.a", |
| 208 | "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a", |
| 209 | "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a", |
| 210 | "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a", |
| 211 | "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a", |
| 212 | ] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 213 | "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 214 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=libgcc_eh.a"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 215 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 216 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 217 | }), |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 218 | }) |
| 219 | } |
| 220 | |
| 221 | func TestCcLibraryExcludeSrcs(t *testing.T) { |
| 222 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 223 | description: "cc_library exclude_srcs - trimmed example of //external/arm-optimized-routines:libarm-optimized-routines-math", |
| 224 | moduleTypeUnderTest: "cc_library", |
| 225 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 226 | dir: "external", |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 227 | filesystem: map[string]string{ |
| 228 | "external/math/cosf.c": "", |
| 229 | "external/math/erf.c": "", |
| 230 | "external/math/erf_data.c": "", |
| 231 | "external/math/erff.c": "", |
| 232 | "external/math/erff_data.c": "", |
| 233 | "external/Android.bp": ` |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 234 | cc_library { |
| 235 | name: "fake-libarm-optimized-routines-math", |
| 236 | exclude_srcs: [ |
| 237 | // Provided by: |
| 238 | // bionic/libm/upstream-freebsd/lib/msun/src/s_erf.c |
| 239 | // bionic/libm/upstream-freebsd/lib/msun/src/s_erff.c |
| 240 | "math/erf.c", |
| 241 | "math/erf_data.c", |
| 242 | "math/erff.c", |
| 243 | "math/erff_data.c", |
| 244 | ], |
| 245 | srcs: [ |
| 246 | "math/*.c", |
| 247 | ], |
| 248 | // arch-specific settings |
| 249 | arch: { |
| 250 | arm64: { |
| 251 | cflags: [ |
| 252 | "-DHAVE_FAST_FMA=1", |
| 253 | ], |
| 254 | }, |
| 255 | }, |
| 256 | bazel_module: { bp2build_available: true }, |
| 257 | } |
| 258 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 259 | }, |
| 260 | blueprint: soongCcLibraryPreamble, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 261 | expectedBazelTargets: makeCcLibraryTargets("fake-libarm-optimized-routines-math", attrNameToString{ |
| 262 | "copts": `select({ |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 263 | "//build/bazel/platforms/arch:arm64": ["-DHAVE_FAST_FMA=1"], |
| 264 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 265 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 266 | "local_includes": `["."]`, |
| 267 | "srcs_c": `["math/cosf.c"]`, |
| 268 | }), |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 269 | }) |
| 270 | } |
| 271 | |
| 272 | func TestCcLibrarySharedStaticProps(t *testing.T) { |
| 273 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 274 | description: "cc_library shared/static props", |
| 275 | moduleTypeUnderTest: "cc_library", |
| 276 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 277 | filesystem: map[string]string{ |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 278 | "both.cpp": "", |
| 279 | "sharedonly.cpp": "", |
| 280 | "staticonly.cpp": "", |
| 281 | }, |
| 282 | blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 283 | cc_library { |
| 284 | name: "a", |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 285 | srcs: ["both.cpp"], |
| 286 | cflags: ["bothflag"], |
| 287 | shared_libs: ["shared_dep_for_both"], |
Liz Kammer | cc2c1ef | 2022-03-21 09:03:29 -0400 | [diff] [blame] | 288 | static_libs: ["static_dep_for_both", "whole_and_static_lib_for_both"], |
| 289 | whole_static_libs: ["whole_static_lib_for_both", "whole_and_static_lib_for_both"], |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 290 | static: { |
| 291 | srcs: ["staticonly.cpp"], |
| 292 | cflags: ["staticflag"], |
| 293 | shared_libs: ["shared_dep_for_static"], |
| 294 | static_libs: ["static_dep_for_static"], |
| 295 | whole_static_libs: ["whole_static_lib_for_static"], |
| 296 | }, |
| 297 | shared: { |
| 298 | srcs: ["sharedonly.cpp"], |
| 299 | cflags: ["sharedflag"], |
| 300 | shared_libs: ["shared_dep_for_shared"], |
| 301 | static_libs: ["static_dep_for_shared"], |
| 302 | whole_static_libs: ["whole_static_lib_for_shared"], |
| 303 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 304 | include_build_directory: false, |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 307 | cc_library_static { |
| 308 | name: "static_dep_for_shared", |
| 309 | bazel_module: { bp2build_available: false }, |
| 310 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 311 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 312 | cc_library_static { |
| 313 | name: "static_dep_for_static", |
| 314 | bazel_module: { bp2build_available: false }, |
| 315 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 316 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 317 | cc_library_static { |
| 318 | name: "static_dep_for_both", |
| 319 | bazel_module: { bp2build_available: false }, |
| 320 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 321 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 322 | cc_library_static { |
| 323 | name: "whole_static_lib_for_shared", |
| 324 | bazel_module: { bp2build_available: false }, |
| 325 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 326 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 327 | cc_library_static { |
| 328 | name: "whole_static_lib_for_static", |
| 329 | bazel_module: { bp2build_available: false }, |
| 330 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 331 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 332 | cc_library_static { |
| 333 | name: "whole_static_lib_for_both", |
| 334 | bazel_module: { bp2build_available: false }, |
| 335 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 336 | |
Liz Kammer | cc2c1ef | 2022-03-21 09:03:29 -0400 | [diff] [blame] | 337 | cc_library_static { |
| 338 | name: "whole_and_static_lib_for_both", |
| 339 | bazel_module: { bp2build_available: false }, |
| 340 | } |
| 341 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 342 | cc_library { |
| 343 | name: "shared_dep_for_shared", |
| 344 | bazel_module: { bp2build_available: false }, |
| 345 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 346 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 347 | cc_library { |
| 348 | name: "shared_dep_for_static", |
| 349 | bazel_module: { bp2build_available: false }, |
| 350 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 351 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 352 | cc_library { |
| 353 | name: "shared_dep_for_both", |
| 354 | bazel_module: { bp2build_available: false }, |
| 355 | } |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 356 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 357 | expectedBazelTargets: []string{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 358 | makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", attrNameToString{ |
| 359 | "copts": `[ |
| 360 | "bothflag", |
| 361 | "staticflag", |
| 362 | ]`, |
| 363 | "implementation_deps": `[ |
| 364 | ":static_dep_for_both", |
| 365 | ":static_dep_for_static", |
| 366 | ]`, |
| 367 | "implementation_dynamic_deps": `[ |
| 368 | ":shared_dep_for_both", |
| 369 | ":shared_dep_for_static", |
| 370 | ]`, |
| 371 | "srcs": `[ |
| 372 | "both.cpp", |
| 373 | "staticonly.cpp", |
| 374 | ]`, |
| 375 | "whole_archive_deps": `[ |
| 376 | ":whole_static_lib_for_both", |
Liz Kammer | cc2c1ef | 2022-03-21 09:03:29 -0400 | [diff] [blame] | 377 | ":whole_and_static_lib_for_both", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 378 | ":whole_static_lib_for_static", |
| 379 | ]`}), |
| 380 | makeBazelTarget("cc_library_shared", "a", attrNameToString{ |
| 381 | "copts": `[ |
| 382 | "bothflag", |
| 383 | "sharedflag", |
| 384 | ]`, |
| 385 | "implementation_deps": `[ |
| 386 | ":static_dep_for_both", |
| 387 | ":static_dep_for_shared", |
| 388 | ]`, |
| 389 | "implementation_dynamic_deps": `[ |
| 390 | ":shared_dep_for_both", |
| 391 | ":shared_dep_for_shared", |
| 392 | ]`, |
| 393 | "srcs": `[ |
| 394 | "both.cpp", |
| 395 | "sharedonly.cpp", |
| 396 | ]`, |
| 397 | "whole_archive_deps": `[ |
| 398 | ":whole_static_lib_for_both", |
Liz Kammer | cc2c1ef | 2022-03-21 09:03:29 -0400 | [diff] [blame] | 399 | ":whole_and_static_lib_for_both", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 400 | ":whole_static_lib_for_shared", |
| 401 | ]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 402 | }), |
| 403 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 404 | }) |
| 405 | } |
| 406 | |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 407 | func TestCcLibraryDeps(t *testing.T) { |
| 408 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 409 | description: "cc_library shared/static props", |
| 410 | moduleTypeUnderTest: "cc_library", |
| 411 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 412 | filesystem: map[string]string{ |
| 413 | "both.cpp": "", |
| 414 | "sharedonly.cpp": "", |
| 415 | "staticonly.cpp": "", |
| 416 | }, |
| 417 | blueprint: soongCcLibraryPreamble + ` |
| 418 | cc_library { |
| 419 | name: "a", |
| 420 | srcs: ["both.cpp"], |
| 421 | cflags: ["bothflag"], |
| 422 | shared_libs: ["implementation_shared_dep_for_both", "shared_dep_for_both"], |
| 423 | export_shared_lib_headers: ["shared_dep_for_both"], |
| 424 | static_libs: ["implementation_static_dep_for_both", "static_dep_for_both"], |
| 425 | export_static_lib_headers: ["static_dep_for_both", "whole_static_dep_for_both"], |
| 426 | whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_both", "whole_static_dep_for_both"], |
| 427 | static: { |
| 428 | srcs: ["staticonly.cpp"], |
| 429 | cflags: ["staticflag"], |
| 430 | shared_libs: ["implementation_shared_dep_for_static", "shared_dep_for_static"], |
| 431 | export_shared_lib_headers: ["shared_dep_for_static"], |
| 432 | static_libs: ["implementation_static_dep_for_static", "static_dep_for_static"], |
| 433 | export_static_lib_headers: ["static_dep_for_static", "whole_static_dep_for_static"], |
| 434 | whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_static", "whole_static_dep_for_static"], |
| 435 | }, |
| 436 | shared: { |
| 437 | srcs: ["sharedonly.cpp"], |
| 438 | cflags: ["sharedflag"], |
| 439 | shared_libs: ["implementation_shared_dep_for_shared", "shared_dep_for_shared"], |
| 440 | export_shared_lib_headers: ["shared_dep_for_shared"], |
| 441 | static_libs: ["implementation_static_dep_for_shared", "static_dep_for_shared"], |
| 442 | export_static_lib_headers: ["static_dep_for_shared", "whole_static_dep_for_shared"], |
| 443 | whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_shared", "whole_static_dep_for_shared"], |
| 444 | }, |
| 445 | include_build_directory: false, |
| 446 | } |
| 447 | ` + simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_shared") + |
| 448 | simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_shared") + |
| 449 | simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_static") + |
| 450 | simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_static") + |
| 451 | simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_both") + |
| 452 | simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_both") + |
| 453 | simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_shared") + |
| 454 | simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_shared") + |
| 455 | simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_static") + |
| 456 | simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_static") + |
| 457 | simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_both") + |
| 458 | simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_both") + |
| 459 | simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_shared") + |
| 460 | simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_shared") + |
| 461 | simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_static") + |
| 462 | simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_static") + |
| 463 | simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_both") + |
| 464 | simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_both"), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 465 | expectedBazelTargets: []string{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 466 | makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", attrNameToString{ |
| 467 | "copts": `[ |
| 468 | "bothflag", |
| 469 | "staticflag", |
| 470 | ]`, |
| 471 | "deps": `[ |
| 472 | ":static_dep_for_both", |
| 473 | ":static_dep_for_static", |
| 474 | ]`, |
| 475 | "dynamic_deps": `[ |
| 476 | ":shared_dep_for_both", |
| 477 | ":shared_dep_for_static", |
| 478 | ]`, |
| 479 | "implementation_deps": `[ |
| 480 | ":implementation_static_dep_for_both", |
| 481 | ":implementation_static_dep_for_static", |
| 482 | ]`, |
| 483 | "implementation_dynamic_deps": `[ |
| 484 | ":implementation_shared_dep_for_both", |
| 485 | ":implementation_shared_dep_for_static", |
| 486 | ]`, |
| 487 | "srcs": `[ |
| 488 | "both.cpp", |
| 489 | "staticonly.cpp", |
| 490 | ]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 491 | "whole_archive_deps": `[ |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 492 | ":not_explicitly_exported_whole_static_dep_for_both", |
| 493 | ":whole_static_dep_for_both", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 494 | ":not_explicitly_exported_whole_static_dep_for_static", |
| 495 | ":whole_static_dep_for_static", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 496 | ]`, |
| 497 | }), |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 498 | makeBazelTarget("cc_library_shared", "a", attrNameToString{ |
| 499 | "copts": `[ |
| 500 | "bothflag", |
| 501 | "sharedflag", |
| 502 | ]`, |
| 503 | "deps": `[ |
| 504 | ":static_dep_for_both", |
| 505 | ":static_dep_for_shared", |
| 506 | ]`, |
| 507 | "dynamic_deps": `[ |
| 508 | ":shared_dep_for_both", |
| 509 | ":shared_dep_for_shared", |
| 510 | ]`, |
| 511 | "implementation_deps": `[ |
| 512 | ":implementation_static_dep_for_both", |
| 513 | ":implementation_static_dep_for_shared", |
| 514 | ]`, |
| 515 | "implementation_dynamic_deps": `[ |
| 516 | ":implementation_shared_dep_for_both", |
| 517 | ":implementation_shared_dep_for_shared", |
| 518 | ]`, |
| 519 | "srcs": `[ |
| 520 | "both.cpp", |
| 521 | "sharedonly.cpp", |
| 522 | ]`, |
| 523 | "whole_archive_deps": `[ |
| 524 | ":not_explicitly_exported_whole_static_dep_for_both", |
| 525 | ":whole_static_dep_for_both", |
| 526 | ":not_explicitly_exported_whole_static_dep_for_shared", |
| 527 | ":whole_static_dep_for_shared", |
| 528 | ]`, |
| 529 | })}, |
| 530 | }, |
| 531 | ) |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 532 | } |
| 533 | |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 534 | func TestCcLibraryWholeStaticLibsAlwaysLink(t *testing.T) { |
| 535 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 536 | moduleTypeUnderTest: "cc_library", |
| 537 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 538 | dir: "foo/bar", |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 539 | filesystem: map[string]string{ |
| 540 | "foo/bar/Android.bp": ` |
| 541 | cc_library { |
| 542 | name: "a", |
| 543 | whole_static_libs: ["whole_static_lib_for_both"], |
| 544 | static: { |
| 545 | whole_static_libs: ["whole_static_lib_for_static"], |
| 546 | }, |
| 547 | shared: { |
| 548 | whole_static_libs: ["whole_static_lib_for_shared"], |
| 549 | }, |
| 550 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 551 | include_build_directory: false, |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | cc_prebuilt_library_static { name: "whole_static_lib_for_shared" } |
| 555 | |
| 556 | cc_prebuilt_library_static { name: "whole_static_lib_for_static" } |
| 557 | |
| 558 | cc_prebuilt_library_static { name: "whole_static_lib_for_both" } |
| 559 | `, |
| 560 | }, |
| 561 | blueprint: soongCcLibraryPreamble, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 562 | expectedBazelTargets: []string{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 563 | makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", attrNameToString{ |
| 564 | "whole_archive_deps": `[ |
| 565 | ":whole_static_lib_for_both_alwayslink", |
| 566 | ":whole_static_lib_for_static_alwayslink", |
| 567 | ]`, |
| 568 | }), |
| 569 | makeBazelTarget("cc_library_shared", "a", attrNameToString{ |
| 570 | "whole_archive_deps": `[ |
| 571 | ":whole_static_lib_for_both_alwayslink", |
| 572 | ":whole_static_lib_for_shared_alwayslink", |
| 573 | ]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 574 | }), |
| 575 | }, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 576 | }, |
| 577 | ) |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 578 | } |
| 579 | |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 580 | func TestCcLibrarySharedStaticPropsInArch(t *testing.T) { |
| 581 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 582 | description: "cc_library shared/static props in arch", |
| 583 | moduleTypeUnderTest: "cc_library", |
| 584 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 585 | dir: "foo/bar", |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 586 | filesystem: map[string]string{ |
| 587 | "foo/bar/arm.cpp": "", |
| 588 | "foo/bar/x86.cpp": "", |
| 589 | "foo/bar/sharedonly.cpp": "", |
| 590 | "foo/bar/staticonly.cpp": "", |
| 591 | "foo/bar/Android.bp": ` |
| 592 | cc_library { |
| 593 | name: "a", |
| 594 | arch: { |
| 595 | arm: { |
| 596 | shared: { |
| 597 | srcs: ["arm_shared.cpp"], |
| 598 | cflags: ["-DARM_SHARED"], |
| 599 | static_libs: ["arm_static_dep_for_shared"], |
| 600 | whole_static_libs: ["arm_whole_static_dep_for_shared"], |
| 601 | shared_libs: ["arm_shared_dep_for_shared"], |
| 602 | }, |
| 603 | }, |
| 604 | x86: { |
| 605 | static: { |
| 606 | srcs: ["x86_static.cpp"], |
| 607 | cflags: ["-DX86_STATIC"], |
| 608 | static_libs: ["x86_dep_for_static"], |
| 609 | }, |
| 610 | }, |
| 611 | }, |
| 612 | target: { |
| 613 | android: { |
| 614 | shared: { |
| 615 | srcs: ["android_shared.cpp"], |
| 616 | cflags: ["-DANDROID_SHARED"], |
| 617 | static_libs: ["android_dep_for_shared"], |
| 618 | }, |
| 619 | }, |
| 620 | android_arm: { |
| 621 | shared: { |
| 622 | cflags: ["-DANDROID_ARM_SHARED"], |
| 623 | }, |
| 624 | }, |
| 625 | }, |
| 626 | srcs: ["both.cpp"], |
| 627 | cflags: ["bothflag"], |
| 628 | static_libs: ["static_dep_for_both"], |
| 629 | static: { |
| 630 | srcs: ["staticonly.cpp"], |
| 631 | cflags: ["staticflag"], |
| 632 | static_libs: ["static_dep_for_static"], |
| 633 | }, |
| 634 | shared: { |
| 635 | srcs: ["sharedonly.cpp"], |
| 636 | cflags: ["sharedflag"], |
| 637 | static_libs: ["static_dep_for_shared"], |
| 638 | }, |
| 639 | bazel_module: { bp2build_available: true }, |
| 640 | } |
| 641 | |
| 642 | cc_library_static { name: "static_dep_for_shared" } |
| 643 | cc_library_static { name: "static_dep_for_static" } |
| 644 | cc_library_static { name: "static_dep_for_both" } |
| 645 | |
| 646 | cc_library_static { name: "arm_static_dep_for_shared" } |
| 647 | cc_library_static { name: "arm_whole_static_dep_for_shared" } |
| 648 | cc_library_static { name: "arm_shared_dep_for_shared" } |
| 649 | |
| 650 | cc_library_static { name: "x86_dep_for_static" } |
| 651 | |
| 652 | cc_library_static { name: "android_dep_for_shared" } |
| 653 | `, |
| 654 | }, |
| 655 | blueprint: soongCcLibraryPreamble, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 656 | expectedBazelTargets: []string{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 657 | makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", attrNameToString{ |
| 658 | "copts": `[ |
| 659 | "bothflag", |
| 660 | "staticflag", |
| 661 | ] + select({ |
| 662 | "//build/bazel/platforms/arch:x86": ["-DX86_STATIC"], |
| 663 | "//conditions:default": [], |
| 664 | })`, |
| 665 | "implementation_deps": `[ |
| 666 | ":static_dep_for_both", |
| 667 | ":static_dep_for_static", |
| 668 | ] + select({ |
| 669 | "//build/bazel/platforms/arch:x86": [":x86_dep_for_static"], |
| 670 | "//conditions:default": [], |
| 671 | })`, |
| 672 | "local_includes": `["."]`, |
| 673 | "srcs": `[ |
| 674 | "both.cpp", |
| 675 | "staticonly.cpp", |
| 676 | ] + select({ |
| 677 | "//build/bazel/platforms/arch:x86": ["x86_static.cpp"], |
| 678 | "//conditions:default": [], |
| 679 | })`, |
| 680 | }), |
| 681 | makeBazelTarget("cc_library_shared", "a", attrNameToString{ |
| 682 | "copts": `[ |
| 683 | "bothflag", |
| 684 | "sharedflag", |
| 685 | ] + select({ |
| 686 | "//build/bazel/platforms/arch:arm": ["-DARM_SHARED"], |
| 687 | "//conditions:default": [], |
| 688 | }) + select({ |
| 689 | "//build/bazel/platforms/os:android": ["-DANDROID_SHARED"], |
| 690 | "//conditions:default": [], |
| 691 | }) + select({ |
| 692 | "//build/bazel/platforms/os_arch:android_arm": ["-DANDROID_ARM_SHARED"], |
| 693 | "//conditions:default": [], |
| 694 | })`, |
| 695 | "implementation_deps": `[ |
| 696 | ":static_dep_for_both", |
| 697 | ":static_dep_for_shared", |
| 698 | ] + select({ |
| 699 | "//build/bazel/platforms/arch:arm": [":arm_static_dep_for_shared"], |
| 700 | "//conditions:default": [], |
| 701 | }) + select({ |
| 702 | "//build/bazel/platforms/os:android": [":android_dep_for_shared"], |
| 703 | "//conditions:default": [], |
| 704 | })`, |
| 705 | "implementation_dynamic_deps": `select({ |
| 706 | "//build/bazel/platforms/arch:arm": [":arm_shared_dep_for_shared"], |
| 707 | "//conditions:default": [], |
| 708 | })`, |
| 709 | "local_includes": `["."]`, |
| 710 | "srcs": `[ |
| 711 | "both.cpp", |
| 712 | "sharedonly.cpp", |
| 713 | ] + select({ |
| 714 | "//build/bazel/platforms/arch:arm": ["arm_shared.cpp"], |
| 715 | "//conditions:default": [], |
| 716 | }) + select({ |
| 717 | "//build/bazel/platforms/os:android": ["android_shared.cpp"], |
| 718 | "//conditions:default": [], |
| 719 | })`, |
| 720 | "whole_archive_deps": `select({ |
| 721 | "//build/bazel/platforms/arch:arm": [":arm_whole_static_dep_for_shared"], |
| 722 | "//conditions:default": [], |
| 723 | })`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 724 | }), |
| 725 | }, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 726 | }, |
| 727 | ) |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 728 | } |
| 729 | |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 730 | func TestCcLibrarySharedStaticPropsWithMixedSources(t *testing.T) { |
| 731 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 732 | description: "cc_library shared/static props with c/cpp/s mixed sources", |
| 733 | moduleTypeUnderTest: "cc_library", |
| 734 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 735 | dir: "foo/bar", |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 736 | filesystem: map[string]string{ |
| 737 | "foo/bar/both_source.cpp": "", |
| 738 | "foo/bar/both_source.cc": "", |
| 739 | "foo/bar/both_source.c": "", |
| 740 | "foo/bar/both_source.s": "", |
| 741 | "foo/bar/both_source.S": "", |
| 742 | "foo/bar/shared_source.cpp": "", |
| 743 | "foo/bar/shared_source.cc": "", |
| 744 | "foo/bar/shared_source.c": "", |
| 745 | "foo/bar/shared_source.s": "", |
| 746 | "foo/bar/shared_source.S": "", |
| 747 | "foo/bar/static_source.cpp": "", |
| 748 | "foo/bar/static_source.cc": "", |
| 749 | "foo/bar/static_source.c": "", |
| 750 | "foo/bar/static_source.s": "", |
| 751 | "foo/bar/static_source.S": "", |
| 752 | "foo/bar/Android.bp": ` |
| 753 | cc_library { |
| 754 | name: "a", |
| 755 | srcs: [ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 756 | "both_source.cpp", |
| 757 | "both_source.cc", |
| 758 | "both_source.c", |
| 759 | "both_source.s", |
| 760 | "both_source.S", |
Liz Kammer | 57e2e7a | 2021-09-20 12:55:02 -0400 | [diff] [blame] | 761 | ":both_filegroup", |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 762 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 763 | static: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 764 | srcs: [ |
| 765 | "static_source.cpp", |
| 766 | "static_source.cc", |
| 767 | "static_source.c", |
| 768 | "static_source.s", |
| 769 | "static_source.S", |
| 770 | ":static_filegroup", |
| 771 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 772 | }, |
| 773 | shared: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 774 | srcs: [ |
| 775 | "shared_source.cpp", |
| 776 | "shared_source.cc", |
| 777 | "shared_source.c", |
| 778 | "shared_source.s", |
| 779 | "shared_source.S", |
| 780 | ":shared_filegroup", |
| 781 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 782 | }, |
| 783 | bazel_module: { bp2build_available: true }, |
| 784 | } |
| 785 | |
| 786 | filegroup { |
| 787 | name: "both_filegroup", |
| 788 | srcs: [ |
| 789 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 790 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | filegroup { |
| 794 | name: "shared_filegroup", |
| 795 | srcs: [ |
| 796 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 797 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | filegroup { |
| 801 | name: "static_filegroup", |
| 802 | srcs: [ |
| 803 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 804 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 805 | } |
| 806 | `, |
| 807 | }, |
| 808 | blueprint: soongCcLibraryPreamble, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 809 | expectedBazelTargets: []string{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 810 | makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", attrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 811 | "local_includes": `["."]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 812 | "srcs": `[ |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 813 | "both_source.cpp", |
Liz Kammer | 57e2e7a | 2021-09-20 12:55:02 -0400 | [diff] [blame] | 814 | "both_source.cc", |
| 815 | ":both_filegroup_cpp_srcs", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 816 | "static_source.cpp", |
| 817 | "static_source.cc", |
| 818 | ":static_filegroup_cpp_srcs", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 819 | ]`, |
| 820 | "srcs_as": `[ |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 821 | "both_source.s", |
| 822 | "both_source.S", |
| 823 | ":both_filegroup_as_srcs", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 824 | "static_source.s", |
| 825 | "static_source.S", |
| 826 | ":static_filegroup_as_srcs", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 827 | ]`, |
| 828 | "srcs_c": `[ |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 829 | "both_source.c", |
| 830 | ":both_filegroup_c_srcs", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 831 | "static_source.c", |
| 832 | ":static_filegroup_c_srcs", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 833 | ]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 834 | }), |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 835 | makeBazelTarget("cc_library_shared", "a", attrNameToString{ |
| 836 | "local_includes": `["."]`, |
| 837 | "srcs": `[ |
| 838 | "both_source.cpp", |
| 839 | "both_source.cc", |
| 840 | ":both_filegroup_cpp_srcs", |
| 841 | "shared_source.cpp", |
| 842 | "shared_source.cc", |
| 843 | ":shared_filegroup_cpp_srcs", |
| 844 | ]`, |
| 845 | "srcs_as": `[ |
| 846 | "both_source.s", |
| 847 | "both_source.S", |
| 848 | ":both_filegroup_as_srcs", |
| 849 | "shared_source.s", |
| 850 | "shared_source.S", |
| 851 | ":shared_filegroup_as_srcs", |
| 852 | ]`, |
| 853 | "srcs_c": `[ |
| 854 | "both_source.c", |
| 855 | ":both_filegroup_c_srcs", |
| 856 | "shared_source.c", |
| 857 | ":shared_filegroup_c_srcs", |
| 858 | ]`, |
| 859 | })}}) |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 860 | } |
| 861 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 862 | func TestCcLibraryNonConfiguredVersionScript(t *testing.T) { |
| 863 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 864 | description: "cc_library non-configured version script", |
| 865 | moduleTypeUnderTest: "cc_library", |
| 866 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 867 | dir: "foo/bar", |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 868 | filesystem: map[string]string{ |
| 869 | "foo/bar/Android.bp": ` |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 870 | cc_library { |
| 871 | name: "a", |
| 872 | srcs: ["a.cpp"], |
| 873 | version_script: "v.map", |
| 874 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 875 | include_build_directory: false, |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 876 | } |
| 877 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 878 | }, |
| 879 | blueprint: soongCcLibraryPreamble, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 880 | expectedBazelTargets: makeCcLibraryTargets("a", attrNameToString{ |
| 881 | "additional_linker_inputs": `["v.map"]`, |
| 882 | "linkopts": `["-Wl,--version-script,$(location v.map)"]`, |
| 883 | "srcs": `["a.cpp"]`, |
| 884 | }), |
| 885 | }, |
| 886 | ) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | func TestCcLibraryConfiguredVersionScript(t *testing.T) { |
| 890 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 891 | description: "cc_library configured version script", |
| 892 | moduleTypeUnderTest: "cc_library", |
| 893 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 894 | dir: "foo/bar", |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 895 | filesystem: map[string]string{ |
| 896 | "foo/bar/Android.bp": ` |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 897 | cc_library { |
| 898 | name: "a", |
| 899 | srcs: ["a.cpp"], |
| 900 | arch: { |
| 901 | arm: { |
| 902 | version_script: "arm.map", |
| 903 | }, |
| 904 | arm64: { |
| 905 | version_script: "arm64.map", |
| 906 | }, |
| 907 | }, |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 908 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 909 | bazel_module: { bp2build_available: true }, |
| 910 | include_build_directory: false, |
| 911 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 912 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 913 | }, |
| 914 | blueprint: soongCcLibraryPreamble, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 915 | expectedBazelTargets: makeCcLibraryTargets("a", attrNameToString{ |
| 916 | "additional_linker_inputs": `select({ |
Liz Kammer | d287118 | 2021-10-04 13:54:37 -0400 | [diff] [blame] | 917 | "//build/bazel/platforms/arch:arm": ["arm.map"], |
| 918 | "//build/bazel/platforms/arch:arm64": ["arm64.map"], |
| 919 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 920 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 921 | "linkopts": `select({ |
Liz Kammer | d287118 | 2021-10-04 13:54:37 -0400 | [diff] [blame] | 922 | "//build/bazel/platforms/arch:arm": ["-Wl,--version-script,$(location arm.map)"], |
| 923 | "//build/bazel/platforms/arch:arm64": ["-Wl,--version-script,$(location arm64.map)"], |
| 924 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 925 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 926 | "srcs": `["a.cpp"]`, |
| 927 | }), |
| 928 | }, |
| 929 | ) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | func TestCcLibrarySharedLibs(t *testing.T) { |
| 933 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 934 | description: "cc_library shared_libs", |
| 935 | moduleTypeUnderTest: "cc_library", |
| 936 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 937 | blueprint: soongCcLibraryPreamble + ` |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 938 | cc_library { |
| 939 | name: "mylib", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 940 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | cc_library { |
| 944 | name: "a", |
| 945 | shared_libs: ["mylib",], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 946 | include_build_directory: false, |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 947 | } |
| 948 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 949 | expectedBazelTargets: makeCcLibraryTargets("a", attrNameToString{ |
| 950 | "implementation_dynamic_deps": `[":mylib"]`, |
| 951 | }), |
| 952 | }, |
| 953 | ) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 954 | } |
| 955 | |
Liz Kammer | 0eae52e | 2021-10-06 10:32:26 -0400 | [diff] [blame] | 956 | func TestCcLibraryFeatures(t *testing.T) { |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 957 | expected_targets := []string{} |
| 958 | expected_targets = append(expected_targets, makeCcLibraryTargets("a", attrNameToString{ |
| 959 | "features": `[ |
| 960 | "disable_pack_relocations", |
| 961 | "-no_undefined_symbols", |
Yu Liu | 8d82ac5 | 2022-05-17 15:13:28 -0700 | [diff] [blame^] | 962 | "-coverage", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 963 | ]`, |
| 964 | "srcs": `["a.cpp"]`, |
| 965 | })...) |
| 966 | expected_targets = append(expected_targets, makeCcLibraryTargets("b", attrNameToString{ |
Yu Liu | 8d82ac5 | 2022-05-17 15:13:28 -0700 | [diff] [blame^] | 967 | "features": `["-coverage"] + select({ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 968 | "//build/bazel/platforms/arch:x86_64": [ |
| 969 | "disable_pack_relocations", |
| 970 | "-no_undefined_symbols", |
| 971 | ], |
| 972 | "//conditions:default": [], |
| 973 | })`, |
| 974 | "srcs": `["b.cpp"]`, |
| 975 | })...) |
| 976 | expected_targets = append(expected_targets, makeCcLibraryTargets("c", attrNameToString{ |
| 977 | "features": `select({ |
| 978 | "//build/bazel/platforms/os:darwin": [ |
| 979 | "disable_pack_relocations", |
| 980 | "-no_undefined_symbols", |
| 981 | ], |
| 982 | "//conditions:default": [], |
| 983 | })`, |
| 984 | "srcs": `["c.cpp"]`, |
| 985 | })...) |
| 986 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 987 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 988 | description: "cc_library pack_relocations test", |
| 989 | moduleTypeUnderTest: "cc_library", |
| 990 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 991 | blueprint: soongCcLibraryPreamble + ` |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 992 | cc_library { |
| 993 | name: "a", |
| 994 | srcs: ["a.cpp"], |
| 995 | pack_relocations: false, |
Liz Kammer | 0eae52e | 2021-10-06 10:32:26 -0400 | [diff] [blame] | 996 | allow_undefined_symbols: true, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 997 | include_build_directory: false, |
Yu Liu | 8d82ac5 | 2022-05-17 15:13:28 -0700 | [diff] [blame^] | 998 | native_coverage: false, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | cc_library { |
| 1002 | name: "b", |
| 1003 | srcs: ["b.cpp"], |
| 1004 | arch: { |
| 1005 | x86_64: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1006 | pack_relocations: false, |
Liz Kammer | 0eae52e | 2021-10-06 10:32:26 -0400 | [diff] [blame] | 1007 | allow_undefined_symbols: true, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1008 | }, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1009 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1010 | include_build_directory: false, |
Yu Liu | 8d82ac5 | 2022-05-17 15:13:28 -0700 | [diff] [blame^] | 1011 | native_coverage: false, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | cc_library { |
| 1015 | name: "c", |
| 1016 | srcs: ["c.cpp"], |
| 1017 | target: { |
| 1018 | darwin: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1019 | pack_relocations: false, |
Liz Kammer | 0eae52e | 2021-10-06 10:32:26 -0400 | [diff] [blame] | 1020 | allow_undefined_symbols: true, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1021 | }, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1022 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1023 | include_build_directory: false, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1024 | }`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1025 | expectedBazelTargets: expected_targets, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1026 | }) |
| 1027 | } |
| 1028 | |
| 1029 | func TestCcLibrarySpacesInCopts(t *testing.T) { |
| 1030 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1031 | description: "cc_library spaces in copts", |
| 1032 | moduleTypeUnderTest: "cc_library", |
| 1033 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1034 | blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 1035 | cc_library { |
| 1036 | name: "a", |
| 1037 | cflags: ["-include header.h",], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1038 | include_build_directory: false, |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 1039 | } |
| 1040 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1041 | expectedBazelTargets: makeCcLibraryTargets("a", attrNameToString{ |
| 1042 | "copts": `[ |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 1043 | "-include", |
| 1044 | "header.h", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1045 | ]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1046 | }), |
| 1047 | }, |
| 1048 | ) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { |
| 1052 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1053 | description: "cc_library cppflags usage", |
| 1054 | moduleTypeUnderTest: "cc_library", |
| 1055 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1056 | blueprint: soongCcLibraryPreamble + `cc_library { |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1057 | name: "a", |
| 1058 | srcs: ["a.cpp"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1059 | cflags: ["-Wall"], |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1060 | cppflags: [ |
| 1061 | "-fsigned-char", |
| 1062 | "-pedantic", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1063 | ], |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1064 | arch: { |
| 1065 | arm64: { |
| 1066 | cppflags: ["-DARM64=1"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1067 | }, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1068 | }, |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1069 | target: { |
| 1070 | android: { |
| 1071 | cppflags: ["-DANDROID=1"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1072 | }, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1073 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1074 | include_build_directory: false, |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1075 | } |
| 1076 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1077 | expectedBazelTargets: makeCcLibraryTargets("a", attrNameToString{ |
| 1078 | "copts": `["-Wall"]`, |
| 1079 | "cppflags": `[ |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 1080 | "-fsigned-char", |
| 1081 | "-pedantic", |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1082 | ] + select({ |
| 1083 | "//build/bazel/platforms/arch:arm64": ["-DARM64=1"], |
| 1084 | "//conditions:default": [], |
| 1085 | }) + select({ |
| 1086 | "//build/bazel/platforms/os:android": ["-DANDROID=1"], |
| 1087 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1088 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1089 | "srcs": `["a.cpp"]`, |
| 1090 | }), |
| 1091 | }, |
| 1092 | ) |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 1093 | } |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 1094 | |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1095 | func TestCcLibraryExcludeLibs(t *testing.T) { |
| 1096 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1097 | moduleTypeUnderTest: "cc_library", |
| 1098 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1099 | filesystem: map[string]string{}, |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1100 | blueprint: soongCcLibraryStaticPreamble + ` |
| 1101 | cc_library { |
| 1102 | name: "foo_static", |
| 1103 | srcs: ["common.c"], |
| 1104 | whole_static_libs: [ |
| 1105 | "arm_whole_static_lib_excludes", |
| 1106 | "malloc_not_svelte_whole_static_lib_excludes" |
| 1107 | ], |
| 1108 | static_libs: [ |
| 1109 | "arm_static_lib_excludes", |
| 1110 | "malloc_not_svelte_static_lib_excludes" |
| 1111 | ], |
| 1112 | shared_libs: [ |
| 1113 | "arm_shared_lib_excludes", |
| 1114 | ], |
| 1115 | arch: { |
| 1116 | arm: { |
| 1117 | exclude_shared_libs: [ |
| 1118 | "arm_shared_lib_excludes", |
| 1119 | ], |
| 1120 | exclude_static_libs: [ |
| 1121 | "arm_static_lib_excludes", |
| 1122 | "arm_whole_static_lib_excludes", |
| 1123 | ], |
| 1124 | }, |
| 1125 | }, |
| 1126 | product_variables: { |
| 1127 | malloc_not_svelte: { |
| 1128 | shared_libs: ["malloc_not_svelte_shared_lib"], |
| 1129 | whole_static_libs: ["malloc_not_svelte_whole_static_lib"], |
| 1130 | exclude_static_libs: [ |
| 1131 | "malloc_not_svelte_static_lib_excludes", |
| 1132 | "malloc_not_svelte_whole_static_lib_excludes", |
| 1133 | ], |
| 1134 | }, |
| 1135 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1136 | include_build_directory: false, |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | cc_library { |
| 1140 | name: "arm_whole_static_lib_excludes", |
| 1141 | bazel_module: { bp2build_available: false }, |
| 1142 | } |
| 1143 | |
| 1144 | cc_library { |
| 1145 | name: "malloc_not_svelte_whole_static_lib", |
| 1146 | bazel_module: { bp2build_available: false }, |
| 1147 | } |
| 1148 | |
| 1149 | cc_library { |
| 1150 | name: "malloc_not_svelte_whole_static_lib_excludes", |
| 1151 | bazel_module: { bp2build_available: false }, |
| 1152 | } |
| 1153 | |
| 1154 | cc_library { |
| 1155 | name: "arm_static_lib_excludes", |
| 1156 | bazel_module: { bp2build_available: false }, |
| 1157 | } |
| 1158 | |
| 1159 | cc_library { |
| 1160 | name: "malloc_not_svelte_static_lib_excludes", |
| 1161 | bazel_module: { bp2build_available: false }, |
| 1162 | } |
| 1163 | |
| 1164 | cc_library { |
| 1165 | name: "arm_shared_lib_excludes", |
| 1166 | bazel_module: { bp2build_available: false }, |
| 1167 | } |
| 1168 | |
| 1169 | cc_library { |
| 1170 | name: "malloc_not_svelte_shared_lib", |
| 1171 | bazel_module: { bp2build_available: false }, |
| 1172 | } |
| 1173 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1174 | expectedBazelTargets: makeCcLibraryTargets("foo_static", attrNameToString{ |
| 1175 | "implementation_deps": `select({ |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1176 | "//build/bazel/platforms/arch:arm": [], |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1177 | "//conditions:default": [":arm_static_lib_excludes_bp2build_cc_library_static"], |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1178 | }) + select({ |
| 1179 | "//build/bazel/product_variables:malloc_not_svelte": [], |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1180 | "//conditions:default": [":malloc_not_svelte_static_lib_excludes_bp2build_cc_library_static"], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1181 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1182 | "implementation_dynamic_deps": `select({ |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 1183 | "//build/bazel/platforms/arch:arm": [], |
| 1184 | "//conditions:default": [":arm_shared_lib_excludes"], |
| 1185 | }) + select({ |
| 1186 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_shared_lib"], |
| 1187 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1188 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1189 | "srcs_c": `["common.c"]`, |
| 1190 | "whole_archive_deps": `select({ |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1191 | "//build/bazel/platforms/arch:arm": [], |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1192 | "//conditions:default": [":arm_whole_static_lib_excludes_bp2build_cc_library_static"], |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1193 | }) + select({ |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1194 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_whole_static_lib_bp2build_cc_library_static"], |
| 1195 | "//conditions:default": [":malloc_not_svelte_whole_static_lib_excludes_bp2build_cc_library_static"], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1196 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1197 | }), |
| 1198 | }, |
| 1199 | ) |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1200 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1201 | |
| 1202 | func TestCCLibraryNoCrtTrue(t *testing.T) { |
| 1203 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1204 | description: "cc_library - nocrt: true emits attribute", |
| 1205 | moduleTypeUnderTest: "cc_library", |
| 1206 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1207 | filesystem: map[string]string{ |
| 1208 | "impl.cpp": "", |
| 1209 | }, |
| 1210 | blueprint: soongCcLibraryPreamble + ` |
| 1211 | cc_library { |
| 1212 | name: "foo-lib", |
| 1213 | srcs: ["impl.cpp"], |
| 1214 | nocrt: true, |
| 1215 | include_build_directory: false, |
| 1216 | } |
| 1217 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1218 | expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ |
| 1219 | "link_crt": `False`, |
| 1220 | "srcs": `["impl.cpp"]`, |
| 1221 | }), |
| 1222 | }, |
| 1223 | ) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | func TestCCLibraryNoCrtFalse(t *testing.T) { |
| 1227 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1228 | description: "cc_library - nocrt: false - does not emit attribute", |
| 1229 | moduleTypeUnderTest: "cc_library", |
| 1230 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1231 | filesystem: map[string]string{ |
| 1232 | "impl.cpp": "", |
| 1233 | }, |
| 1234 | blueprint: soongCcLibraryPreamble + ` |
| 1235 | cc_library { |
| 1236 | name: "foo-lib", |
| 1237 | srcs: ["impl.cpp"], |
| 1238 | nocrt: false, |
| 1239 | include_build_directory: false, |
| 1240 | } |
| 1241 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1242 | expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ |
| 1243 | "srcs": `["impl.cpp"]`, |
| 1244 | }), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1245 | }) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | func TestCCLibraryNoCrtArchVariant(t *testing.T) { |
| 1249 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1250 | description: "cc_library - nocrt in select", |
| 1251 | moduleTypeUnderTest: "cc_library", |
| 1252 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1253 | filesystem: map[string]string{ |
| 1254 | "impl.cpp": "", |
| 1255 | }, |
| 1256 | blueprint: soongCcLibraryPreamble + ` |
| 1257 | cc_library { |
| 1258 | name: "foo-lib", |
| 1259 | srcs: ["impl.cpp"], |
| 1260 | arch: { |
| 1261 | arm: { |
| 1262 | nocrt: true, |
| 1263 | }, |
| 1264 | x86: { |
| 1265 | nocrt: false, |
| 1266 | }, |
| 1267 | }, |
| 1268 | include_build_directory: false, |
| 1269 | } |
| 1270 | `, |
Liz Kammer | 718eb27 | 2022-01-07 10:53:37 -0500 | [diff] [blame] | 1271 | expectedErr: fmt.Errorf("module \"foo-lib\": nocrt is not supported for arch variants"), |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1272 | }) |
| 1273 | } |
| 1274 | |
| 1275 | func TestCCLibraryNoLibCrtTrue(t *testing.T) { |
| 1276 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1277 | moduleTypeUnderTest: "cc_library", |
| 1278 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1279 | filesystem: map[string]string{ |
| 1280 | "impl.cpp": "", |
| 1281 | }, |
| 1282 | blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1283 | cc_library { |
| 1284 | name: "foo-lib", |
| 1285 | srcs: ["impl.cpp"], |
| 1286 | no_libcrt: true, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1287 | include_build_directory: false, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1288 | } |
| 1289 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1290 | expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ |
| 1291 | "srcs": `["impl.cpp"]`, |
| 1292 | "use_libcrt": `False`, |
| 1293 | }), |
| 1294 | }) |
| 1295 | } |
| 1296 | |
| 1297 | func makeCcLibraryTargets(name string, attrs attrNameToString) []string { |
| 1298 | STATIC_ONLY_ATTRS := map[string]bool{} |
| 1299 | SHARED_ONLY_ATTRS := map[string]bool{ |
| 1300 | "link_crt": true, |
| 1301 | "additional_linker_inputs": true, |
| 1302 | "linkopts": true, |
| 1303 | "strip": true, |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 1304 | "stubs_symbol_file": true, |
| 1305 | "stubs_versions": true, |
Yu Liu | 75be7b9 | 2022-02-01 09:54:09 -0800 | [diff] [blame] | 1306 | "inject_bssl_hash": true, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1307 | } |
| 1308 | sharedAttrs := attrNameToString{} |
| 1309 | staticAttrs := attrNameToString{} |
| 1310 | for key, val := range attrs { |
| 1311 | if _, staticOnly := STATIC_ONLY_ATTRS[key]; !staticOnly { |
| 1312 | sharedAttrs[key] = val |
| 1313 | } |
| 1314 | if _, sharedOnly := SHARED_ONLY_ATTRS[key]; !sharedOnly { |
| 1315 | staticAttrs[key] = val |
| 1316 | } |
| 1317 | } |
| 1318 | sharedTarget := makeBazelTarget("cc_library_shared", name, sharedAttrs) |
| 1319 | staticTarget := makeBazelTarget("cc_library_static", name+"_bp2build_cc_library_static", staticAttrs) |
| 1320 | |
| 1321 | return []string{staticTarget, sharedTarget} |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1322 | } |
| 1323 | |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1324 | func TestCCLibraryNoLibCrtFalse(t *testing.T) { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1325 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1326 | moduleTypeUnderTest: "cc_library", |
| 1327 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1328 | filesystem: map[string]string{ |
| 1329 | "impl.cpp": "", |
| 1330 | }, |
| 1331 | blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1332 | cc_library { |
| 1333 | name: "foo-lib", |
| 1334 | srcs: ["impl.cpp"], |
| 1335 | no_libcrt: false, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1336 | include_build_directory: false, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1337 | } |
| 1338 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1339 | expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ |
| 1340 | "srcs": `["impl.cpp"]`, |
| 1341 | "use_libcrt": `True`, |
| 1342 | }), |
| 1343 | }) |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1344 | } |
| 1345 | |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1346 | func TestCCLibraryNoLibCrtArchVariant(t *testing.T) { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1347 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1348 | moduleTypeUnderTest: "cc_library", |
| 1349 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1350 | filesystem: map[string]string{ |
| 1351 | "impl.cpp": "", |
| 1352 | }, |
| 1353 | blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1354 | cc_library { |
| 1355 | name: "foo-lib", |
| 1356 | srcs: ["impl.cpp"], |
| 1357 | arch: { |
| 1358 | arm: { |
| 1359 | no_libcrt: true, |
| 1360 | }, |
| 1361 | x86: { |
| 1362 | no_libcrt: true, |
| 1363 | }, |
| 1364 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1365 | include_build_directory: false, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1366 | } |
| 1367 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1368 | expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ |
| 1369 | "srcs": `["impl.cpp"]`, |
| 1370 | "use_libcrt": `select({ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1371 | "//build/bazel/platforms/arch:arm": False, |
| 1372 | "//build/bazel/platforms/arch:x86": False, |
| 1373 | "//conditions:default": None, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1374 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1375 | }), |
| 1376 | }) |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1377 | } |
| 1378 | |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1379 | func TestCCLibraryNoLibCrtArchAndTargetVariant(t *testing.T) { |
| 1380 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1381 | moduleTypeUnderTest: "cc_library", |
| 1382 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1383 | filesystem: map[string]string{ |
| 1384 | "impl.cpp": "", |
| 1385 | }, |
| 1386 | blueprint: soongCcLibraryPreamble + ` |
| 1387 | cc_library { |
| 1388 | name: "foo-lib", |
| 1389 | srcs: ["impl.cpp"], |
| 1390 | arch: { |
| 1391 | arm: { |
| 1392 | no_libcrt: true, |
| 1393 | }, |
| 1394 | x86: { |
| 1395 | no_libcrt: true, |
| 1396 | }, |
| 1397 | }, |
| 1398 | target: { |
| 1399 | darwin: { |
| 1400 | no_libcrt: true, |
| 1401 | } |
| 1402 | }, |
| 1403 | include_build_directory: false, |
| 1404 | } |
| 1405 | `, |
| 1406 | expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ |
| 1407 | "srcs": `["impl.cpp"]`, |
| 1408 | "use_libcrt": `select({ |
| 1409 | "//build/bazel/platforms/os_arch:android_arm": False, |
| 1410 | "//build/bazel/platforms/os_arch:android_x86": False, |
| 1411 | "//build/bazel/platforms/os_arch:darwin_arm64": False, |
| 1412 | "//build/bazel/platforms/os_arch:darwin_x86_64": False, |
| 1413 | "//build/bazel/platforms/os_arch:linux_glibc_x86": False, |
| 1414 | "//build/bazel/platforms/os_arch:linux_musl_x86": False, |
| 1415 | "//build/bazel/platforms/os_arch:windows_x86": False, |
| 1416 | "//conditions:default": None, |
| 1417 | })`, |
| 1418 | }), |
| 1419 | }) |
| 1420 | } |
| 1421 | |
| 1422 | func TestCCLibraryNoLibCrtArchAndTargetVariantConflict(t *testing.T) { |
| 1423 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1424 | moduleTypeUnderTest: "cc_library", |
| 1425 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1426 | filesystem: map[string]string{ |
| 1427 | "impl.cpp": "", |
| 1428 | }, |
| 1429 | blueprint: soongCcLibraryPreamble + ` |
| 1430 | cc_library { |
| 1431 | name: "foo-lib", |
| 1432 | srcs: ["impl.cpp"], |
| 1433 | arch: { |
| 1434 | arm: { |
| 1435 | no_libcrt: true, |
| 1436 | }, |
| 1437 | // This is expected to override the value for darwin_x86_64. |
| 1438 | x86_64: { |
| 1439 | no_libcrt: true, |
| 1440 | }, |
| 1441 | }, |
| 1442 | target: { |
| 1443 | darwin: { |
| 1444 | no_libcrt: false, |
| 1445 | } |
| 1446 | }, |
| 1447 | include_build_directory: false, |
| 1448 | } |
| 1449 | `, |
| 1450 | expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ |
| 1451 | "srcs": `["impl.cpp"]`, |
| 1452 | "use_libcrt": `select({ |
| 1453 | "//build/bazel/platforms/os_arch:android_arm": False, |
| 1454 | "//build/bazel/platforms/os_arch:android_x86_64": False, |
| 1455 | "//build/bazel/platforms/os_arch:darwin_arm64": True, |
| 1456 | "//build/bazel/platforms/os_arch:darwin_x86_64": False, |
| 1457 | "//build/bazel/platforms/os_arch:linux_bionic_x86_64": False, |
| 1458 | "//build/bazel/platforms/os_arch:linux_glibc_x86_64": False, |
| 1459 | "//build/bazel/platforms/os_arch:linux_musl_x86_64": False, |
| 1460 | "//build/bazel/platforms/os_arch:windows_x86_64": False, |
| 1461 | "//conditions:default": None, |
| 1462 | })`, |
| 1463 | }), |
| 1464 | }) |
| 1465 | } |
| 1466 | |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1467 | func TestCcLibraryStrip(t *testing.T) { |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1468 | expectedTargets := []string{} |
| 1469 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("all", attrNameToString{ |
| 1470 | "strip": `{ |
| 1471 | "all": True, |
| 1472 | }`, |
| 1473 | })...) |
| 1474 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols", attrNameToString{ |
| 1475 | "strip": `{ |
| 1476 | "keep_symbols": True, |
| 1477 | }`, |
| 1478 | })...) |
| 1479 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols_and_debug_frame", attrNameToString{ |
| 1480 | "strip": `{ |
| 1481 | "keep_symbols_and_debug_frame": True, |
| 1482 | }`, |
| 1483 | })...) |
| 1484 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols_list", attrNameToString{ |
| 1485 | "strip": `{ |
| 1486 | "keep_symbols_list": ["symbol"], |
| 1487 | }`, |
| 1488 | })...) |
| 1489 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("none", attrNameToString{ |
| 1490 | "strip": `{ |
| 1491 | "none": True, |
| 1492 | }`, |
| 1493 | })...) |
| 1494 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("nothing", attrNameToString{})...) |
| 1495 | |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1496 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1497 | description: "cc_library strip args", |
| 1498 | moduleTypeUnderTest: "cc_library", |
| 1499 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1500 | blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1501 | cc_library { |
| 1502 | name: "nothing", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1503 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1504 | } |
| 1505 | cc_library { |
| 1506 | name: "keep_symbols", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1507 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1508 | keep_symbols: true, |
| 1509 | }, |
| 1510 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1511 | } |
| 1512 | cc_library { |
| 1513 | name: "keep_symbols_and_debug_frame", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1514 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1515 | keep_symbols_and_debug_frame: true, |
| 1516 | }, |
| 1517 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1518 | } |
| 1519 | cc_library { |
| 1520 | name: "none", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1521 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1522 | none: true, |
| 1523 | }, |
| 1524 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1525 | } |
| 1526 | cc_library { |
| 1527 | name: "keep_symbols_list", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1528 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1529 | keep_symbols_list: ["symbol"], |
| 1530 | }, |
| 1531 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1532 | } |
| 1533 | cc_library { |
| 1534 | name: "all", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1535 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1536 | all: true, |
| 1537 | }, |
| 1538 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1539 | } |
| 1540 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1541 | expectedBazelTargets: expectedTargets, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1542 | }) |
| 1543 | } |
| 1544 | |
| 1545 | func TestCcLibraryStripWithArch(t *testing.T) { |
| 1546 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1547 | description: "cc_library strip args", |
| 1548 | moduleTypeUnderTest: "cc_library", |
| 1549 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1550 | blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1551 | cc_library { |
| 1552 | name: "multi-arch", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1553 | target: { |
| 1554 | darwin: { |
| 1555 | strip: { |
| 1556 | keep_symbols_list: ["foo", "bar"] |
| 1557 | } |
| 1558 | }, |
| 1559 | }, |
| 1560 | arch: { |
| 1561 | arm: { |
| 1562 | strip: { |
| 1563 | keep_symbols_and_debug_frame: true, |
| 1564 | }, |
| 1565 | }, |
| 1566 | arm64: { |
| 1567 | strip: { |
| 1568 | keep_symbols: true, |
| 1569 | }, |
| 1570 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1571 | }, |
| 1572 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1573 | } |
| 1574 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1575 | expectedBazelTargets: makeCcLibraryTargets("multi-arch", attrNameToString{ |
| 1576 | "strip": `{ |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1577 | "keep_symbols": select({ |
| 1578 | "//build/bazel/platforms/arch:arm64": True, |
| 1579 | "//conditions:default": None, |
| 1580 | }), |
| 1581 | "keep_symbols_and_debug_frame": select({ |
| 1582 | "//build/bazel/platforms/arch:arm": True, |
| 1583 | "//conditions:default": None, |
| 1584 | }), |
| 1585 | "keep_symbols_list": select({ |
| 1586 | "//build/bazel/platforms/os:darwin": [ |
| 1587 | "foo", |
| 1588 | "bar", |
| 1589 | ], |
| 1590 | "//conditions:default": [], |
| 1591 | }), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1592 | }`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1593 | }), |
| 1594 | }, |
| 1595 | ) |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1596 | } |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1597 | |
| 1598 | func TestCcLibrary_SystemSharedLibsRootEmpty(t *testing.T) { |
| 1599 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1600 | description: "cc_library system_shared_libs empty at root", |
| 1601 | moduleTypeUnderTest: "cc_library", |
| 1602 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1603 | blueprint: soongCcLibraryPreamble + ` |
| 1604 | cc_library { |
| 1605 | name: "root_empty", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1606 | system_shared_libs: [], |
| 1607 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1608 | } |
| 1609 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1610 | expectedBazelTargets: makeCcLibraryTargets("root_empty", attrNameToString{ |
| 1611 | "system_dynamic_deps": `[]`, |
| 1612 | }), |
| 1613 | }, |
| 1614 | ) |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | func TestCcLibrary_SystemSharedLibsStaticEmpty(t *testing.T) { |
| 1618 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1619 | description: "cc_library system_shared_libs empty for static variant", |
| 1620 | moduleTypeUnderTest: "cc_library", |
| 1621 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1622 | blueprint: soongCcLibraryPreamble + ` |
| 1623 | cc_library { |
| 1624 | name: "static_empty", |
| 1625 | static: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1626 | system_shared_libs: [], |
| 1627 | }, |
| 1628 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1629 | } |
| 1630 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1631 | expectedBazelTargets: []string{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1632 | makeBazelTarget("cc_library_static", "static_empty_bp2build_cc_library_static", attrNameToString{ |
| 1633 | "system_dynamic_deps": "[]", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1634 | }), |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1635 | makeBazelTarget("cc_library_shared", "static_empty", attrNameToString{}), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1636 | }, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1637 | }) |
| 1638 | } |
| 1639 | |
| 1640 | func TestCcLibrary_SystemSharedLibsSharedEmpty(t *testing.T) { |
| 1641 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1642 | description: "cc_library system_shared_libs empty for shared variant", |
| 1643 | moduleTypeUnderTest: "cc_library", |
| 1644 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1645 | blueprint: soongCcLibraryPreamble + ` |
| 1646 | cc_library { |
| 1647 | name: "shared_empty", |
| 1648 | shared: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1649 | system_shared_libs: [], |
| 1650 | }, |
| 1651 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1652 | } |
| 1653 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1654 | expectedBazelTargets: []string{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1655 | makeBazelTarget("cc_library_static", "shared_empty_bp2build_cc_library_static", attrNameToString{}), |
| 1656 | makeBazelTarget("cc_library_shared", "shared_empty", attrNameToString{ |
| 1657 | "system_dynamic_deps": "[]", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1658 | }), |
| 1659 | }, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1660 | }) |
| 1661 | } |
| 1662 | |
| 1663 | func TestCcLibrary_SystemSharedLibsSharedBionicEmpty(t *testing.T) { |
| 1664 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1665 | description: "cc_library system_shared_libs empty for shared, bionic variant", |
| 1666 | moduleTypeUnderTest: "cc_library", |
| 1667 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1668 | blueprint: soongCcLibraryPreamble + ` |
| 1669 | cc_library { |
| 1670 | name: "shared_empty", |
| 1671 | target: { |
| 1672 | bionic: { |
| 1673 | shared: { |
| 1674 | system_shared_libs: [], |
| 1675 | } |
| 1676 | } |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1677 | }, |
| 1678 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1679 | } |
| 1680 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1681 | expectedBazelTargets: []string{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1682 | makeBazelTarget("cc_library_static", "shared_empty_bp2build_cc_library_static", attrNameToString{}), |
| 1683 | makeBazelTarget("cc_library_shared", "shared_empty", attrNameToString{ |
| 1684 | "system_dynamic_deps": "[]", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1685 | }), |
| 1686 | }, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1687 | }) |
| 1688 | } |
| 1689 | |
| 1690 | func TestCcLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) { |
| 1691 | // Note that this behavior is technically incorrect (it's a simplification). |
| 1692 | // The correct behavior would be if bp2build wrote `system_dynamic_deps = []` |
| 1693 | // only for linux_bionic, but `android` had `["libc", "libdl", "libm"]. |
| 1694 | // b/195791252 tracks the fix. |
| 1695 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1696 | description: "cc_library system_shared_libs empty for linux_bionic variant", |
| 1697 | moduleTypeUnderTest: "cc_library", |
| 1698 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1699 | blueprint: soongCcLibraryPreamble + ` |
| 1700 | cc_library { |
| 1701 | name: "target_linux_bionic_empty", |
| 1702 | target: { |
| 1703 | linux_bionic: { |
| 1704 | system_shared_libs: [], |
| 1705 | }, |
| 1706 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1707 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1708 | } |
| 1709 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1710 | expectedBazelTargets: makeCcLibraryTargets("target_linux_bionic_empty", attrNameToString{ |
| 1711 | "system_dynamic_deps": `[]`, |
| 1712 | }), |
| 1713 | }, |
| 1714 | ) |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | func TestCcLibrary_SystemSharedLibsBionicEmpty(t *testing.T) { |
| 1718 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1719 | description: "cc_library system_shared_libs empty for bionic variant", |
| 1720 | moduleTypeUnderTest: "cc_library", |
| 1721 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1722 | blueprint: soongCcLibraryPreamble + ` |
| 1723 | cc_library { |
| 1724 | name: "target_bionic_empty", |
| 1725 | target: { |
| 1726 | bionic: { |
| 1727 | system_shared_libs: [], |
| 1728 | }, |
| 1729 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1730 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1731 | } |
| 1732 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1733 | expectedBazelTargets: makeCcLibraryTargets("target_bionic_empty", attrNameToString{ |
| 1734 | "system_dynamic_deps": `[]`, |
| 1735 | }), |
| 1736 | }, |
| 1737 | ) |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | func TestCcLibrary_SystemSharedLibsSharedAndRoot(t *testing.T) { |
| 1741 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1742 | description: "cc_library system_shared_libs set for shared and root", |
| 1743 | moduleTypeUnderTest: "cc_library", |
| 1744 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1745 | blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1746 | cc_library { |
| 1747 | name: "libc", |
| 1748 | bazel_module: { bp2build_available: false }, |
| 1749 | } |
| 1750 | cc_library { |
| 1751 | name: "libm", |
| 1752 | bazel_module: { bp2build_available: false }, |
| 1753 | } |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1754 | |
| 1755 | cc_library { |
| 1756 | name: "foo", |
| 1757 | system_shared_libs: ["libc"], |
| 1758 | shared: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1759 | system_shared_libs: ["libm"], |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1760 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1761 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1762 | } |
| 1763 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1764 | expectedBazelTargets: []string{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1765 | makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1766 | "system_dynamic_deps": `[":libc"]`, |
| 1767 | }), |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1768 | makeBazelTarget("cc_library_shared", "foo", attrNameToString{ |
| 1769 | "system_dynamic_deps": `[ |
| 1770 | ":libc", |
| 1771 | ":libm", |
| 1772 | ]`, |
| 1773 | }), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1774 | }, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1775 | }) |
| 1776 | } |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1777 | |
| 1778 | func TestCcLibraryOsSelects(t *testing.T) { |
| 1779 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1780 | description: "cc_library - selects for all os targets", |
| 1781 | moduleTypeUnderTest: "cc_library", |
| 1782 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1783 | filesystem: map[string]string{}, |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1784 | blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1785 | cc_library { |
| 1786 | name: "foo-lib", |
| 1787 | srcs: ["base.cpp"], |
| 1788 | target: { |
| 1789 | android: { |
| 1790 | srcs: ["android.cpp"], |
| 1791 | }, |
| 1792 | linux: { |
| 1793 | srcs: ["linux.cpp"], |
| 1794 | }, |
| 1795 | linux_glibc: { |
| 1796 | srcs: ["linux_glibc.cpp"], |
| 1797 | }, |
| 1798 | darwin: { |
| 1799 | srcs: ["darwin.cpp"], |
| 1800 | }, |
| 1801 | bionic: { |
| 1802 | srcs: ["bionic.cpp"], |
| 1803 | }, |
| 1804 | linux_musl: { |
| 1805 | srcs: ["linux_musl.cpp"], |
| 1806 | }, |
| 1807 | windows: { |
| 1808 | srcs: ["windows.cpp"], |
| 1809 | }, |
| 1810 | }, |
| 1811 | include_build_directory: false, |
| 1812 | } |
| 1813 | `, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1814 | expectedBazelTargets: makeCcLibraryTargets("foo-lib", attrNameToString{ |
| 1815 | "srcs": `["base.cpp"] + select({ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1816 | "//build/bazel/platforms/os:android": [ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1817 | "linux.cpp", |
Liz Kammer | 9bad9d6 | 2021-10-11 15:40:35 -0400 | [diff] [blame] | 1818 | "bionic.cpp", |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 1819 | "android.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1820 | ], |
| 1821 | "//build/bazel/platforms/os:darwin": ["darwin.cpp"], |
| 1822 | "//build/bazel/platforms/os:linux": [ |
Liz Kammer | 9bad9d6 | 2021-10-11 15:40:35 -0400 | [diff] [blame] | 1823 | "linux.cpp", |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 1824 | "linux_glibc.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1825 | ], |
| 1826 | "//build/bazel/platforms/os:linux_bionic": [ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1827 | "linux.cpp", |
Liz Kammer | 9bad9d6 | 2021-10-11 15:40:35 -0400 | [diff] [blame] | 1828 | "bionic.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1829 | ], |
| 1830 | "//build/bazel/platforms/os:linux_musl": [ |
Liz Kammer | 9bad9d6 | 2021-10-11 15:40:35 -0400 | [diff] [blame] | 1831 | "linux.cpp", |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 1832 | "linux_musl.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1833 | ], |
| 1834 | "//build/bazel/platforms/os:windows": ["windows.cpp"], |
| 1835 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1836 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1837 | }), |
| 1838 | }, |
| 1839 | ) |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
Yu Liu | 75be7b9 | 2022-02-01 09:54:09 -0800 | [diff] [blame] | 1842 | func TestLibcryptoHashInjection(t *testing.T) { |
| 1843 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1844 | description: "cc_library - libcrypto hash injection", |
| 1845 | moduleTypeUnderTest: "cc_library", |
| 1846 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 1847 | filesystem: map[string]string{}, |
| 1848 | blueprint: soongCcLibraryPreamble + ` |
| 1849 | cc_library { |
| 1850 | name: "libcrypto", |
| 1851 | target: { |
| 1852 | android: { |
| 1853 | inject_bssl_hash: true, |
| 1854 | }, |
| 1855 | }, |
| 1856 | include_build_directory: false, |
| 1857 | } |
| 1858 | `, |
| 1859 | expectedBazelTargets: makeCcLibraryTargets("libcrypto", attrNameToString{ |
| 1860 | "inject_bssl_hash": `select({ |
| 1861 | "//build/bazel/platforms/os:android": True, |
| 1862 | "//conditions:default": None, |
| 1863 | })`, |
| 1864 | }), |
| 1865 | }, |
| 1866 | ) |
| 1867 | } |
| 1868 | |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 1869 | func TestCcLibraryCppStdWithGnuExtensions_ConvertsToFeatureAttr(t *testing.T) { |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1870 | type testCase struct { |
| 1871 | cpp_std string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1872 | c_std string |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1873 | gnu_extensions string |
| 1874 | bazel_cpp_std string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1875 | bazel_c_std string |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | testCases := []testCase{ |
| 1879 | // Existing usages of cpp_std in AOSP are: |
| 1880 | // experimental, c++11, c++17, c++2a, c++98, gnu++11, gnu++17 |
| 1881 | // |
| 1882 | // not set, only emit if gnu_extensions is disabled. the default (gnu+17 |
| 1883 | // is set in the toolchain.) |
| 1884 | {cpp_std: "", gnu_extensions: "", bazel_cpp_std: ""}, |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1885 | {cpp_std: "", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c99"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1886 | {cpp_std: "", gnu_extensions: "true", bazel_cpp_std: ""}, |
| 1887 | // experimental defaults to gnu++2a |
| 1888 | {cpp_std: "experimental", gnu_extensions: "", bazel_cpp_std: "gnu++2a"}, |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1889 | {cpp_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "c++2a", bazel_c_std: "c99"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1890 | {cpp_std: "experimental", gnu_extensions: "true", bazel_cpp_std: "gnu++2a"}, |
| 1891 | // Explicitly setting a c++ std does not use replace gnu++ std even if |
| 1892 | // gnu_extensions is true. |
| 1893 | // "c++11", |
| 1894 | {cpp_std: "c++11", gnu_extensions: "", bazel_cpp_std: "c++11"}, |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1895 | {cpp_std: "c++11", gnu_extensions: "false", bazel_cpp_std: "c++11", bazel_c_std: "c99"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1896 | {cpp_std: "c++11", gnu_extensions: "true", bazel_cpp_std: "c++11"}, |
| 1897 | // "c++17", |
| 1898 | {cpp_std: "c++17", gnu_extensions: "", bazel_cpp_std: "c++17"}, |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1899 | {cpp_std: "c++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c99"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1900 | {cpp_std: "c++17", gnu_extensions: "true", bazel_cpp_std: "c++17"}, |
| 1901 | // "c++2a", |
| 1902 | {cpp_std: "c++2a", gnu_extensions: "", bazel_cpp_std: "c++2a"}, |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1903 | {cpp_std: "c++2a", gnu_extensions: "false", bazel_cpp_std: "c++2a", bazel_c_std: "c99"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1904 | {cpp_std: "c++2a", gnu_extensions: "true", bazel_cpp_std: "c++2a"}, |
| 1905 | // "c++98", |
| 1906 | {cpp_std: "c++98", gnu_extensions: "", bazel_cpp_std: "c++98"}, |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1907 | {cpp_std: "c++98", gnu_extensions: "false", bazel_cpp_std: "c++98", bazel_c_std: "c99"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1908 | {cpp_std: "c++98", gnu_extensions: "true", bazel_cpp_std: "c++98"}, |
| 1909 | // gnu++ is replaced with c++ if gnu_extensions is explicitly false. |
| 1910 | // "gnu++11", |
| 1911 | {cpp_std: "gnu++11", gnu_extensions: "", bazel_cpp_std: "gnu++11"}, |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1912 | {cpp_std: "gnu++11", gnu_extensions: "false", bazel_cpp_std: "c++11", bazel_c_std: "c99"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1913 | {cpp_std: "gnu++11", gnu_extensions: "true", bazel_cpp_std: "gnu++11"}, |
| 1914 | // "gnu++17", |
| 1915 | {cpp_std: "gnu++17", gnu_extensions: "", bazel_cpp_std: "gnu++17"}, |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1916 | {cpp_std: "gnu++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c99"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1917 | {cpp_std: "gnu++17", gnu_extensions: "true", bazel_cpp_std: "gnu++17"}, |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1918 | |
| 1919 | // some c_std test cases |
Elliott Hughes | 6741d0e | 2022-05-12 09:53:11 -0700 | [diff] [blame] | 1920 | {c_std: "experimental", gnu_extensions: "", bazel_c_std: "gnu17"}, |
| 1921 | {c_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c17"}, |
| 1922 | {c_std: "experimental", gnu_extensions: "true", bazel_c_std: "gnu17"}, |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1923 | {c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "", bazel_cpp_std: "gnu++17", bazel_c_std: "gnu11"}, |
| 1924 | {c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c11"}, |
| 1925 | {c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "true", bazel_cpp_std: "gnu++17", bazel_c_std: "gnu11"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1926 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1927 | for i, tc := range testCases { |
| 1928 | name_prefix := fmt.Sprintf("a_%v", i) |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1929 | cppStdProp := "" |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1930 | if tc.cpp_std != "" { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1931 | cppStdProp = fmt.Sprintf(" cpp_std: \"%s\",", tc.cpp_std) |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1932 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1933 | cStdProp := "" |
| 1934 | if tc.c_std != "" { |
| 1935 | cStdProp = fmt.Sprintf(" c_std: \"%s\",", tc.c_std) |
| 1936 | } |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1937 | gnuExtensionsProp := "" |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1938 | if tc.gnu_extensions != "" { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1939 | gnuExtensionsProp = fmt.Sprintf(" gnu_extensions: %s,", tc.gnu_extensions) |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1940 | } |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1941 | attrs := attrNameToString{} |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1942 | if tc.bazel_cpp_std != "" { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1943 | attrs["cpp_std"] = fmt.Sprintf(`"%s"`, tc.bazel_cpp_std) |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1944 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1945 | if tc.bazel_c_std != "" { |
| 1946 | attrs["c_std"] = fmt.Sprintf(`"%s"`, tc.bazel_c_std) |
| 1947 | } |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1948 | |
| 1949 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 1950 | description: fmt.Sprintf( |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1951 | "cc_library with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions), |
| 1952 | moduleTypeUnderTest: "cc_library", |
| 1953 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1954 | blueprint: soongCcLibraryPreamble + fmt.Sprintf(` |
| 1955 | cc_library { |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1956 | name: "%s_full", |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1957 | %s // cpp_std: *string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1958 | %s // c_std: *string |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1959 | %s // gnu_extensions: *bool |
| 1960 | include_build_directory: false, |
| 1961 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1962 | `, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp), |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1963 | expectedBazelTargets: makeCcLibraryTargets(name_prefix+"_full", attrs), |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1964 | }) |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 1965 | |
| 1966 | runCcLibraryStaticTestCase(t, bp2buildTestCase{ |
| 1967 | description: fmt.Sprintf( |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1968 | "cc_library_static with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions), |
| 1969 | moduleTypeUnderTest: "cc_library_static", |
| 1970 | moduleTypeUnderTestFactory: cc.LibraryStaticFactory, |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 1971 | blueprint: soongCcLibraryPreamble + fmt.Sprintf(` |
| 1972 | cc_library_static { |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1973 | name: "%s_static", |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 1974 | %s // cpp_std: *string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1975 | %s // c_std: *string |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 1976 | %s // gnu_extensions: *bool |
| 1977 | include_build_directory: false, |
| 1978 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1979 | `, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1980 | expectedBazelTargets: []string{ |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1981 | makeBazelTarget("cc_library_static", name_prefix+"_static", attrs), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1982 | }, |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 1983 | }) |
| 1984 | |
| 1985 | runCcLibrarySharedTestCase(t, bp2buildTestCase{ |
| 1986 | description: fmt.Sprintf( |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1987 | "cc_library_shared with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions), |
| 1988 | moduleTypeUnderTest: "cc_library_shared", |
| 1989 | moduleTypeUnderTestFactory: cc.LibrarySharedFactory, |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 1990 | blueprint: soongCcLibraryPreamble + fmt.Sprintf(` |
| 1991 | cc_library_shared { |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1992 | name: "%s_shared", |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 1993 | %s // cpp_std: *string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1994 | %s // c_std: *string |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 1995 | %s // gnu_extensions: *bool |
| 1996 | include_build_directory: false, |
| 1997 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1998 | `, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1999 | expectedBazelTargets: []string{ |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2000 | makeBazelTarget("cc_library_shared", name_prefix+"_shared", attrs), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 2001 | }, |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2002 | }) |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2003 | } |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 2004 | } |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2005 | |
| 2006 | func TestCcLibraryProtoSimple(t *testing.T) { |
| 2007 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 2008 | moduleTypeUnderTest: "cc_library", |
| 2009 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2010 | blueprint: soongCcProtoPreamble + `cc_library { |
| 2011 | name: "foo", |
| 2012 | srcs: ["foo.proto"], |
| 2013 | include_build_directory: false, |
| 2014 | }`, |
| 2015 | expectedBazelTargets: []string{ |
| 2016 | makeBazelTarget("proto_library", "foo_proto", attrNameToString{ |
Liz Kammer | 7756c8f | 2022-02-14 20:49:15 -0500 | [diff] [blame] | 2017 | "srcs": `["foo.proto"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2018 | }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ |
| 2019 | "deps": `[":foo_proto"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2020 | }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2021 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2022 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2023 | }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ |
| 2024 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2025 | }), |
| 2026 | }, |
| 2027 | }) |
| 2028 | } |
| 2029 | |
| 2030 | func TestCcLibraryProtoNoCanonicalPathFromRoot(t *testing.T) { |
| 2031 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 2032 | moduleTypeUnderTest: "cc_library", |
| 2033 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2034 | blueprint: soongCcProtoPreamble + `cc_library { |
| 2035 | name: "foo", |
| 2036 | srcs: ["foo.proto"], |
| 2037 | proto: { canonical_path_from_root: false}, |
| 2038 | include_build_directory: false, |
| 2039 | }`, |
| 2040 | expectedBazelTargets: []string{ |
| 2041 | makeBazelTarget("proto_library", "foo_proto", attrNameToString{ |
Liz Kammer | 7756c8f | 2022-02-14 20:49:15 -0500 | [diff] [blame] | 2042 | "srcs": `["foo.proto"]`, |
| 2043 | "strip_import_prefix": `""`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2044 | }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ |
| 2045 | "deps": `[":foo_proto"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2046 | }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2047 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2048 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2049 | }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ |
| 2050 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2051 | }), |
| 2052 | }, |
| 2053 | }) |
| 2054 | } |
| 2055 | |
| 2056 | func TestCcLibraryProtoExplicitCanonicalPathFromRoot(t *testing.T) { |
| 2057 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 2058 | moduleTypeUnderTest: "cc_library", |
| 2059 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2060 | blueprint: soongCcProtoPreamble + `cc_library { |
| 2061 | name: "foo", |
| 2062 | srcs: ["foo.proto"], |
| 2063 | proto: { canonical_path_from_root: true}, |
| 2064 | include_build_directory: false, |
| 2065 | }`, |
| 2066 | expectedBazelTargets: []string{ |
| 2067 | makeBazelTarget("proto_library", "foo_proto", attrNameToString{ |
Liz Kammer | 7756c8f | 2022-02-14 20:49:15 -0500 | [diff] [blame] | 2068 | "srcs": `["foo.proto"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2069 | }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ |
| 2070 | "deps": `[":foo_proto"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2071 | }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2072 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2073 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2074 | }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ |
| 2075 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2076 | }), |
| 2077 | }, |
| 2078 | }) |
| 2079 | } |
| 2080 | |
| 2081 | func TestCcLibraryProtoFull(t *testing.T) { |
| 2082 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 2083 | moduleTypeUnderTest: "cc_library", |
| 2084 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2085 | blueprint: soongCcProtoPreamble + `cc_library { |
| 2086 | name: "foo", |
| 2087 | srcs: ["foo.proto"], |
| 2088 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2089 | type: "full", |
| 2090 | }, |
| 2091 | include_build_directory: false, |
| 2092 | }`, |
| 2093 | expectedBazelTargets: []string{ |
| 2094 | makeBazelTarget("proto_library", "foo_proto", attrNameToString{ |
| 2095 | "srcs": `["foo.proto"]`, |
| 2096 | }), makeBazelTarget("cc_proto_library", "foo_cc_proto", attrNameToString{ |
| 2097 | "deps": `[":foo_proto"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2098 | }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2099 | "implementation_whole_archive_deps": `[":foo_cc_proto"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2100 | "deps": `[":libprotobuf-cpp-full"]`, |
| 2101 | }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ |
| 2102 | "dynamic_deps": `[":libprotobuf-cpp-full"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2103 | }), |
| 2104 | }, |
| 2105 | }) |
| 2106 | } |
| 2107 | |
| 2108 | func TestCcLibraryProtoLite(t *testing.T) { |
| 2109 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 2110 | moduleTypeUnderTest: "cc_library", |
| 2111 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2112 | blueprint: soongCcProtoPreamble + `cc_library { |
| 2113 | name: "foo", |
| 2114 | srcs: ["foo.proto"], |
| 2115 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2116 | type: "lite", |
| 2117 | }, |
| 2118 | include_build_directory: false, |
| 2119 | }`, |
| 2120 | expectedBazelTargets: []string{ |
| 2121 | makeBazelTarget("proto_library", "foo_proto", attrNameToString{ |
| 2122 | "srcs": `["foo.proto"]`, |
| 2123 | }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ |
| 2124 | "deps": `[":foo_proto"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2125 | }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2126 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2127 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2128 | }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ |
| 2129 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2130 | }), |
| 2131 | }, |
| 2132 | }) |
| 2133 | } |
| 2134 | |
| 2135 | func TestCcLibraryProtoExportHeaders(t *testing.T) { |
| 2136 | runCcLibraryTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 2137 | moduleTypeUnderTest: "cc_library", |
| 2138 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2139 | blueprint: soongCcProtoPreamble + `cc_library { |
| 2140 | name: "foo", |
| 2141 | srcs: ["foo.proto"], |
| 2142 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2143 | export_proto_headers: true, |
| 2144 | }, |
| 2145 | include_build_directory: false, |
| 2146 | }`, |
| 2147 | expectedBazelTargets: []string{ |
| 2148 | makeBazelTarget("proto_library", "foo_proto", attrNameToString{ |
| 2149 | "srcs": `["foo.proto"]`, |
| 2150 | }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ |
| 2151 | "deps": `[":foo_proto"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2152 | }), makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ |
| 2153 | "deps": `[":libprotobuf-cpp-lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2154 | "whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2155 | }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ |
| 2156 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2157 | "whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2158 | }), |
| 2159 | }, |
| 2160 | }) |
| 2161 | } |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2162 | |
| 2163 | func TestCcLibraryProtoFilegroups(t *testing.T) { |
| 2164 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 2165 | moduleTypeUnderTest: "cc_library", |
| 2166 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 2167 | blueprint: soongCcProtoPreamble + |
| 2168 | simpleModuleDoNotConvertBp2build("filegroup", "a_fg_proto") + |
| 2169 | simpleModuleDoNotConvertBp2build("filegroup", "b_protos") + |
| 2170 | simpleModuleDoNotConvertBp2build("filegroup", "c-proto-srcs") + |
| 2171 | simpleModuleDoNotConvertBp2build("filegroup", "proto-srcs-d") + ` |
| 2172 | cc_library { |
| 2173 | name: "a", |
| 2174 | srcs: [":a_fg_proto"], |
| 2175 | proto: { |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2176 | export_proto_headers: true, |
| 2177 | }, |
| 2178 | include_build_directory: false, |
| 2179 | } |
| 2180 | |
| 2181 | cc_library { |
| 2182 | name: "b", |
| 2183 | srcs: [":b_protos"], |
| 2184 | proto: { |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2185 | export_proto_headers: true, |
| 2186 | }, |
| 2187 | include_build_directory: false, |
| 2188 | } |
| 2189 | |
| 2190 | cc_library { |
| 2191 | name: "c", |
| 2192 | srcs: [":c-proto-srcs"], |
| 2193 | proto: { |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2194 | export_proto_headers: true, |
| 2195 | }, |
| 2196 | include_build_directory: false, |
| 2197 | } |
| 2198 | |
| 2199 | cc_library { |
| 2200 | name: "d", |
| 2201 | srcs: [":proto-srcs-d"], |
| 2202 | proto: { |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2203 | export_proto_headers: true, |
| 2204 | }, |
| 2205 | include_build_directory: false, |
| 2206 | }`, |
| 2207 | expectedBazelTargets: []string{ |
| 2208 | makeBazelTarget("proto_library", "a_proto", attrNameToString{ |
| 2209 | "srcs": `[":a_fg_proto"]`, |
| 2210 | }), makeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", attrNameToString{ |
| 2211 | "deps": `[":a_proto"]`, |
| 2212 | }), makeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", attrNameToString{ |
| 2213 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2214 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2215 | "srcs": `[":a_fg_proto_cpp_srcs"]`, |
| 2216 | "srcs_as": `[":a_fg_proto_as_srcs"]`, |
| 2217 | "srcs_c": `[":a_fg_proto_c_srcs"]`, |
| 2218 | }), makeBazelTarget("cc_library_shared", "a", attrNameToString{ |
| 2219 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2220 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2221 | "srcs": `[":a_fg_proto_cpp_srcs"]`, |
| 2222 | "srcs_as": `[":a_fg_proto_as_srcs"]`, |
| 2223 | "srcs_c": `[":a_fg_proto_c_srcs"]`, |
| 2224 | }), makeBazelTarget("proto_library", "b_proto", attrNameToString{ |
| 2225 | "srcs": `[":b_protos"]`, |
| 2226 | }), makeBazelTarget("cc_lite_proto_library", "b_cc_proto_lite", attrNameToString{ |
| 2227 | "deps": `[":b_proto"]`, |
| 2228 | }), makeBazelTarget("cc_library_static", "b_bp2build_cc_library_static", attrNameToString{ |
| 2229 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2230 | "whole_archive_deps": `[":b_cc_proto_lite"]`, |
| 2231 | "srcs": `[":b_protos_cpp_srcs"]`, |
| 2232 | "srcs_as": `[":b_protos_as_srcs"]`, |
| 2233 | "srcs_c": `[":b_protos_c_srcs"]`, |
| 2234 | }), makeBazelTarget("cc_library_shared", "b", attrNameToString{ |
| 2235 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2236 | "whole_archive_deps": `[":b_cc_proto_lite"]`, |
| 2237 | "srcs": `[":b_protos_cpp_srcs"]`, |
| 2238 | "srcs_as": `[":b_protos_as_srcs"]`, |
| 2239 | "srcs_c": `[":b_protos_c_srcs"]`, |
| 2240 | }), makeBazelTarget("proto_library", "c_proto", attrNameToString{ |
| 2241 | "srcs": `[":c-proto-srcs"]`, |
| 2242 | }), makeBazelTarget("cc_lite_proto_library", "c_cc_proto_lite", attrNameToString{ |
| 2243 | "deps": `[":c_proto"]`, |
| 2244 | }), makeBazelTarget("cc_library_static", "c_bp2build_cc_library_static", attrNameToString{ |
| 2245 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2246 | "whole_archive_deps": `[":c_cc_proto_lite"]`, |
| 2247 | "srcs": `[":c-proto-srcs_cpp_srcs"]`, |
| 2248 | "srcs_as": `[":c-proto-srcs_as_srcs"]`, |
| 2249 | "srcs_c": `[":c-proto-srcs_c_srcs"]`, |
| 2250 | }), makeBazelTarget("cc_library_shared", "c", attrNameToString{ |
| 2251 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2252 | "whole_archive_deps": `[":c_cc_proto_lite"]`, |
| 2253 | "srcs": `[":c-proto-srcs_cpp_srcs"]`, |
| 2254 | "srcs_as": `[":c-proto-srcs_as_srcs"]`, |
| 2255 | "srcs_c": `[":c-proto-srcs_c_srcs"]`, |
| 2256 | }), makeBazelTarget("proto_library", "d_proto", attrNameToString{ |
| 2257 | "srcs": `[":proto-srcs-d"]`, |
| 2258 | }), makeBazelTarget("cc_lite_proto_library", "d_cc_proto_lite", attrNameToString{ |
| 2259 | "deps": `[":d_proto"]`, |
| 2260 | }), makeBazelTarget("cc_library_static", "d_bp2build_cc_library_static", attrNameToString{ |
| 2261 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2262 | "whole_archive_deps": `[":d_cc_proto_lite"]`, |
| 2263 | "srcs": `[":proto-srcs-d_cpp_srcs"]`, |
| 2264 | "srcs_as": `[":proto-srcs-d_as_srcs"]`, |
| 2265 | "srcs_c": `[":proto-srcs-d_c_srcs"]`, |
| 2266 | }), makeBazelTarget("cc_library_shared", "d", attrNameToString{ |
| 2267 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2268 | "whole_archive_deps": `[":d_cc_proto_lite"]`, |
| 2269 | "srcs": `[":proto-srcs-d_cpp_srcs"]`, |
| 2270 | "srcs_as": `[":proto-srcs-d_as_srcs"]`, |
| 2271 | "srcs_c": `[":proto-srcs-d_c_srcs"]`, |
| 2272 | }), |
| 2273 | }, |
| 2274 | }) |
| 2275 | } |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2276 | |
| 2277 | func TestCcLibraryDisabledArchAndTarget(t *testing.T) { |
| 2278 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 2279 | moduleTypeUnderTest: "cc_library", |
| 2280 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 2281 | blueprint: soongCcProtoPreamble + `cc_library { |
| 2282 | name: "foo", |
| 2283 | srcs: ["foo.cpp"], |
| 2284 | target: { |
| 2285 | darwin: { |
| 2286 | enabled: false, |
| 2287 | }, |
| 2288 | windows: { |
| 2289 | enabled: false, |
| 2290 | }, |
| 2291 | linux_glibc_x86: { |
| 2292 | enabled: false, |
| 2293 | }, |
| 2294 | }, |
| 2295 | include_build_directory: false, |
| 2296 | }`, |
| 2297 | expectedBazelTargets: makeCcLibraryTargets("foo", attrNameToString{ |
| 2298 | "srcs": `["foo.cpp"]`, |
| 2299 | "target_compatible_with": `select({ |
| 2300 | "//build/bazel/platforms/os_arch:darwin_arm64": ["@platforms//:incompatible"], |
| 2301 | "//build/bazel/platforms/os_arch:darwin_x86_64": ["@platforms//:incompatible"], |
| 2302 | "//build/bazel/platforms/os_arch:linux_glibc_x86": ["@platforms//:incompatible"], |
| 2303 | "//build/bazel/platforms/os_arch:windows_x86": ["@platforms//:incompatible"], |
| 2304 | "//build/bazel/platforms/os_arch:windows_x86_64": ["@platforms//:incompatible"], |
| 2305 | "//conditions:default": [], |
| 2306 | })`, |
| 2307 | }), |
| 2308 | }) |
| 2309 | } |
| 2310 | |
| 2311 | func TestCcLibraryDisabledArchAndTargetWithDefault(t *testing.T) { |
| 2312 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 2313 | moduleTypeUnderTest: "cc_library", |
| 2314 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 2315 | blueprint: soongCcProtoPreamble + `cc_library { |
| 2316 | name: "foo", |
| 2317 | srcs: ["foo.cpp"], |
| 2318 | enabled: false, |
| 2319 | target: { |
| 2320 | darwin: { |
| 2321 | enabled: true, |
| 2322 | }, |
| 2323 | windows: { |
| 2324 | enabled: false, |
| 2325 | }, |
| 2326 | linux_glibc_x86: { |
| 2327 | enabled: false, |
| 2328 | }, |
| 2329 | }, |
| 2330 | include_build_directory: false, |
| 2331 | }`, |
| 2332 | expectedBazelTargets: makeCcLibraryTargets("foo", attrNameToString{ |
| 2333 | "srcs": `["foo.cpp"]`, |
| 2334 | "target_compatible_with": `select({ |
| 2335 | "//build/bazel/platforms/os_arch:darwin_arm64": [], |
| 2336 | "//build/bazel/platforms/os_arch:darwin_x86_64": [], |
| 2337 | "//conditions:default": ["@platforms//:incompatible"], |
| 2338 | })`, |
| 2339 | }), |
| 2340 | }) |
| 2341 | } |
| 2342 | |
| 2343 | func TestCcLibrarySharedDisabled(t *testing.T) { |
| 2344 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 2345 | moduleTypeUnderTest: "cc_library", |
| 2346 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 2347 | blueprint: soongCcProtoPreamble + `cc_library { |
| 2348 | name: "foo", |
| 2349 | srcs: ["foo.cpp"], |
| 2350 | enabled: false, |
| 2351 | shared: { |
| 2352 | enabled: true, |
| 2353 | }, |
| 2354 | target: { |
| 2355 | android: { |
| 2356 | shared: { |
| 2357 | enabled: false, |
| 2358 | }, |
| 2359 | } |
| 2360 | }, |
| 2361 | include_build_directory: false, |
| 2362 | }`, |
| 2363 | expectedBazelTargets: []string{makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ |
| 2364 | "srcs": `["foo.cpp"]`, |
| 2365 | "target_compatible_with": `["@platforms//:incompatible"]`, |
| 2366 | }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ |
| 2367 | "srcs": `["foo.cpp"]`, |
| 2368 | "target_compatible_with": `select({ |
| 2369 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 2370 | "//conditions:default": [], |
| 2371 | })`, |
| 2372 | }), |
| 2373 | }, |
| 2374 | }) |
| 2375 | } |
| 2376 | |
| 2377 | func TestCcLibraryStaticDisabledForSomeArch(t *testing.T) { |
| 2378 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 2379 | moduleTypeUnderTest: "cc_library", |
| 2380 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 2381 | blueprint: soongCcProtoPreamble + `cc_library { |
| 2382 | name: "foo", |
| 2383 | srcs: ["foo.cpp"], |
| 2384 | shared: { |
| 2385 | enabled: false |
| 2386 | }, |
| 2387 | target: { |
| 2388 | darwin: { |
| 2389 | enabled: true, |
| 2390 | }, |
| 2391 | windows: { |
| 2392 | enabled: false, |
| 2393 | }, |
| 2394 | linux_glibc_x86: { |
| 2395 | shared: { |
| 2396 | enabled: true, |
| 2397 | }, |
| 2398 | }, |
| 2399 | }, |
| 2400 | include_build_directory: false, |
| 2401 | }`, |
| 2402 | expectedBazelTargets: []string{makeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", attrNameToString{ |
| 2403 | "srcs": `["foo.cpp"]`, |
| 2404 | "target_compatible_with": `select({ |
| 2405 | "//build/bazel/platforms/os:windows": ["@platforms//:incompatible"], |
| 2406 | "//conditions:default": [], |
| 2407 | })`, |
| 2408 | }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ |
| 2409 | "srcs": `["foo.cpp"]`, |
| 2410 | "target_compatible_with": `select({ |
| 2411 | "//build/bazel/platforms/os_arch:darwin_arm64": [], |
| 2412 | "//build/bazel/platforms/os_arch:darwin_x86_64": [], |
| 2413 | "//build/bazel/platforms/os_arch:linux_glibc_x86": [], |
| 2414 | "//conditions:default": ["@platforms//:incompatible"], |
| 2415 | })`, |
| 2416 | }), |
| 2417 | }}) |
| 2418 | } |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 2419 | |
| 2420 | func TestCcLibraryStubs(t *testing.T) { |
| 2421 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 2422 | description: "cc_library stubs", |
| 2423 | moduleTypeUnderTest: "cc_library", |
| 2424 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 2425 | dir: "foo/bar", |
| 2426 | filesystem: map[string]string{ |
| 2427 | "foo/bar/Android.bp": ` |
| 2428 | cc_library { |
| 2429 | name: "a", |
| 2430 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 2431 | bazel_module: { bp2build_available: true }, |
| 2432 | include_build_directory: false, |
| 2433 | } |
| 2434 | `, |
| 2435 | }, |
| 2436 | blueprint: soongCcLibraryPreamble, |
| 2437 | expectedBazelTargets: makeCcLibraryTargets("a", attrNameToString{ |
| 2438 | "stubs_symbol_file": `"a.map.txt"`, |
| 2439 | "stubs_versions": `[ |
| 2440 | "28", |
| 2441 | "29", |
| 2442 | "current", |
| 2443 | ]`, |
| 2444 | }), |
| 2445 | }, |
| 2446 | ) |
| 2447 | } |
Liz Kammer | f38a837 | 2022-02-04 15:39:00 -0500 | [diff] [blame] | 2448 | |
| 2449 | func TestCcLibraryEscapeLdflags(t *testing.T) { |
| 2450 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 2451 | moduleTypeUnderTest: "cc_library", |
| 2452 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 2453 | blueprint: soongCcProtoPreamble + `cc_library { |
| 2454 | name: "foo", |
| 2455 | ldflags: ["-Wl,--rpath,${ORIGIN}"], |
| 2456 | include_build_directory: false, |
| 2457 | }`, |
| 2458 | expectedBazelTargets: makeCcLibraryTargets("foo", attrNameToString{ |
| 2459 | "linkopts": `["-Wl,--rpath,$${ORIGIN}"]`, |
| 2460 | }), |
| 2461 | }) |
| 2462 | } |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 2463 | |
| 2464 | func TestCcLibraryConvertLex(t *testing.T) { |
| 2465 | runCcLibraryTestCase(t, bp2buildTestCase{ |
| 2466 | moduleTypeUnderTest: "cc_library", |
| 2467 | moduleTypeUnderTestFactory: cc.LibraryFactory, |
| 2468 | filesystem: map[string]string{ |
| 2469 | "foo.c": "", |
| 2470 | "bar.cc": "", |
| 2471 | "foo1.l": "", |
| 2472 | "bar1.ll": "", |
| 2473 | "foo2.l": "", |
| 2474 | "bar2.ll": "", |
| 2475 | }, |
| 2476 | blueprint: `cc_library { |
| 2477 | name: "foo_lib", |
| 2478 | srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"], |
| 2479 | lex: { flags: ["--foo_flags"] }, |
| 2480 | include_build_directory: false, |
| 2481 | bazel_module: { bp2build_available: true }, |
| 2482 | }`, |
| 2483 | expectedBazelTargets: append([]string{ |
| 2484 | makeBazelTarget("genlex", "foo_lib_genlex_l", attrNameToString{ |
| 2485 | "srcs": `[ |
| 2486 | "foo1.l", |
| 2487 | "foo2.l", |
| 2488 | ]`, |
| 2489 | "lexopts": `["--foo_flags"]`, |
| 2490 | }), |
| 2491 | makeBazelTarget("genlex", "foo_lib_genlex_ll", attrNameToString{ |
| 2492 | "srcs": `[ |
| 2493 | "bar1.ll", |
| 2494 | "bar2.ll", |
| 2495 | ]`, |
| 2496 | "lexopts": `["--foo_flags"]`, |
| 2497 | }), |
| 2498 | }, |
| 2499 | makeCcLibraryTargets("foo_lib", attrNameToString{ |
| 2500 | "srcs": `[ |
| 2501 | "bar.cc", |
| 2502 | ":foo_lib_genlex_ll", |
| 2503 | ]`, |
| 2504 | "srcs_c": `[ |
| 2505 | "foo.c", |
| 2506 | ":foo_lib_genlex_l", |
| 2507 | ]`, |
| 2508 | })...), |
| 2509 | }) |
| 2510 | } |