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", |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 30 | } |
| 31 | ` |
| 32 | |
| 33 | soongCcVersionLibBpPath = "build/soong/cc/libbuildversion/Android.bp" |
| 34 | soongCcVersionLibBp = ` |
| 35 | cc_library_static { |
| 36 | name: "libbuildversion", |
| 37 | bazel_module: { bp2build_available: false }, |
| 38 | } |
| 39 | ` |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 40 | |
| 41 | soongCcProtoLibraries = ` |
| 42 | cc_library { |
| 43 | name: "libprotobuf-cpp-lite", |
| 44 | bazel_module: { bp2build_available: false }, |
| 45 | } |
| 46 | |
| 47 | cc_library { |
| 48 | name: "libprotobuf-cpp-full", |
| 49 | bazel_module: { bp2build_available: false }, |
| 50 | }` |
| 51 | |
| 52 | soongCcProtoPreamble = soongCcLibraryPreamble + soongCcProtoLibraries |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 53 | ) |
| 54 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 55 | func runCcLibraryTestCase(t *testing.T, tc Bp2buildTestCase) { |
Liz Kammer | e4982e8 | 2021-05-25 10:39:35 -0400 | [diff] [blame] | 56 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 57 | RunBp2BuildTestCase(t, registerCcLibraryModuleTypes, tc) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | func registerCcLibraryModuleTypes(ctx android.RegistrationContext) { |
| 61 | cc.RegisterCCBuildComponents(ctx) |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 62 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 63 | ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 64 | ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 65 | ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) |
| 66 | } |
| 67 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 68 | func TestCcLibrarySimple(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 69 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 70 | Description: "cc_library - simple example", |
| 71 | ModuleTypeUnderTest: "cc_library", |
| 72 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 73 | Filesystem: map[string]string{ |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 74 | soongCcVersionLibBpPath: soongCcVersionLibBp, |
| 75 | "android.cpp": "", |
| 76 | "bionic.cpp": "", |
| 77 | "darwin.cpp": "", |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 78 | // Refer to cc.headerExts for the supported header extensions in Soong. |
| 79 | "header.h": "", |
| 80 | "header.hh": "", |
| 81 | "header.hpp": "", |
| 82 | "header.hxx": "", |
| 83 | "header.h++": "", |
| 84 | "header.inl": "", |
| 85 | "header.inc": "", |
| 86 | "header.ipp": "", |
| 87 | "header.h.generic": "", |
| 88 | "impl.cpp": "", |
| 89 | "linux.cpp": "", |
| 90 | "x86.cpp": "", |
| 91 | "x86_64.cpp": "", |
| 92 | "foo-dir/a.h": "", |
| 93 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 94 | Blueprint: soongCcLibraryPreamble + |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 95 | simpleModuleDoNotConvertBp2build("cc_library_headers", "some-headers") + ` |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 96 | cc_library { |
| 97 | name: "foo-lib", |
| 98 | srcs: ["impl.cpp"], |
| 99 | cflags: ["-Wall"], |
| 100 | header_libs: ["some-headers"], |
| 101 | export_include_dirs: ["foo-dir"], |
| 102 | ldflags: ["-Wl,--exclude-libs=bar.a"], |
| 103 | arch: { |
| 104 | x86: { |
| 105 | ldflags: ["-Wl,--exclude-libs=baz.a"], |
| 106 | srcs: ["x86.cpp"], |
| 107 | }, |
| 108 | x86_64: { |
| 109 | ldflags: ["-Wl,--exclude-libs=qux.a"], |
| 110 | srcs: ["x86_64.cpp"], |
| 111 | }, |
| 112 | }, |
| 113 | target: { |
| 114 | android: { |
| 115 | srcs: ["android.cpp"], |
| 116 | }, |
| 117 | linux_glibc: { |
| 118 | srcs: ["linux.cpp"], |
| 119 | }, |
| 120 | darwin: { |
| 121 | srcs: ["darwin.cpp"], |
| 122 | }, |
Liz Kammer | 01a16e8 | 2021-07-16 16:33:47 -0400 | [diff] [blame] | 123 | bionic: { |
| 124 | srcs: ["bionic.cpp"] |
| 125 | }, |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 126 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 127 | include_build_directory: false, |
Yu Liu | fc60316 | 2022-03-01 15:44:08 -0800 | [diff] [blame] | 128 | sdk_version: "current", |
| 129 | min_sdk_version: "29", |
Yu Liu | a79c946 | 2022-03-22 16:35:22 -0700 | [diff] [blame] | 130 | use_version_lib: true, |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 131 | } |
| 132 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 133 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 134 | "copts": `["-Wall"]`, |
| 135 | "export_includes": `["foo-dir"]`, |
| 136 | "implementation_deps": `[":some-headers"]`, |
| 137 | "linkopts": `["-Wl,--exclude-libs=bar.a"] + select({ |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 138 | "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=baz.a"], |
| 139 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=qux.a"], |
| 140 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 141 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 142 | "srcs": `["impl.cpp"] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 143 | "//build/bazel/platforms/arch:x86": ["x86.cpp"], |
| 144 | "//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 145 | "//conditions:default": [], |
| 146 | }) + select({ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 147 | "//build/bazel/platforms/os:android": [ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 148 | "bionic.cpp", |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 149 | "android.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 150 | ], |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 151 | "//build/bazel/platforms/os:darwin": ["darwin.cpp"], |
| 152 | "//build/bazel/platforms/os:linux": ["linux.cpp"], |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 153 | "//build/bazel/platforms/os:linux_bionic": ["bionic.cpp"], |
Liz Kammer | 01a16e8 | 2021-07-16 16:33:47 -0400 | [diff] [blame] | 154 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 155 | })`, |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 156 | "sdk_version": `"current"`, |
| 157 | "min_sdk_version": `"29"`, |
| 158 | "use_version_lib": `True`, |
| 159 | "implementation_whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 160 | }), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 161 | }) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | func TestCcLibraryTrimmedLdAndroid(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 165 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 166 | Description: "cc_library - trimmed example of //bionic/linker:ld-android", |
| 167 | ModuleTypeUnderTest: "cc_library", |
| 168 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 169 | Filesystem: map[string]string{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 170 | "ld-android.cpp": "", |
| 171 | "linked_list.h": "", |
| 172 | "linker.h": "", |
| 173 | "linker_block_allocator.h": "", |
| 174 | "linker_cfi.h": "", |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 175 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 176 | Blueprint: soongCcLibraryPreamble + |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 177 | simpleModuleDoNotConvertBp2build("cc_library_headers", "libc_headers") + ` |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 178 | cc_library { |
| 179 | name: "fake-ld-android", |
| 180 | srcs: ["ld_android.cpp"], |
| 181 | cflags: [ |
| 182 | "-Wall", |
| 183 | "-Wextra", |
| 184 | "-Wunused", |
| 185 | "-Werror", |
| 186 | ], |
| 187 | header_libs: ["libc_headers"], |
| 188 | ldflags: [ |
| 189 | "-Wl,--exclude-libs=libgcc.a", |
| 190 | "-Wl,--exclude-libs=libgcc_stripped.a", |
| 191 | "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a", |
| 192 | "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a", |
| 193 | "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a", |
| 194 | "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a", |
| 195 | ], |
| 196 | arch: { |
| 197 | x86: { |
| 198 | ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 199 | }, |
| 200 | x86_64: { |
| 201 | ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 202 | }, |
| 203 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 204 | include_build_directory: false, |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 205 | } |
| 206 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 207 | ExpectedBazelTargets: makeCcLibraryTargets("fake-ld-android", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 208 | "srcs": `["ld_android.cpp"]`, |
| 209 | "copts": `[ |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 210 | "-Wall", |
| 211 | "-Wextra", |
| 212 | "-Wunused", |
| 213 | "-Werror", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 214 | ]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 215 | "implementation_deps": `[":libc_headers"]`, |
| 216 | "linkopts": `[ |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 217 | "-Wl,--exclude-libs=libgcc.a", |
| 218 | "-Wl,--exclude-libs=libgcc_stripped.a", |
| 219 | "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a", |
| 220 | "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a", |
| 221 | "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a", |
| 222 | "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a", |
| 223 | ] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 224 | "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 225 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=libgcc_eh.a"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 226 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 227 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 228 | }), |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 229 | }) |
| 230 | } |
| 231 | |
| 232 | func TestCcLibraryExcludeSrcs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 233 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 234 | Description: "cc_library exclude_srcs - trimmed example of //external/arm-optimized-routines:libarm-optimized-routines-math", |
| 235 | ModuleTypeUnderTest: "cc_library", |
| 236 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 237 | Dir: "external", |
| 238 | Filesystem: map[string]string{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 239 | "external/math/cosf.c": "", |
| 240 | "external/math/erf.c": "", |
| 241 | "external/math/erf_data.c": "", |
| 242 | "external/math/erff.c": "", |
| 243 | "external/math/erff_data.c": "", |
| 244 | "external/Android.bp": ` |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 245 | cc_library { |
| 246 | name: "fake-libarm-optimized-routines-math", |
| 247 | exclude_srcs: [ |
| 248 | // Provided by: |
| 249 | // bionic/libm/upstream-freebsd/lib/msun/src/s_erf.c |
| 250 | // bionic/libm/upstream-freebsd/lib/msun/src/s_erff.c |
| 251 | "math/erf.c", |
| 252 | "math/erf_data.c", |
| 253 | "math/erff.c", |
| 254 | "math/erff_data.c", |
| 255 | ], |
| 256 | srcs: [ |
| 257 | "math/*.c", |
| 258 | ], |
| 259 | // arch-specific settings |
| 260 | arch: { |
| 261 | arm64: { |
| 262 | cflags: [ |
| 263 | "-DHAVE_FAST_FMA=1", |
| 264 | ], |
| 265 | }, |
| 266 | }, |
| 267 | bazel_module: { bp2build_available: true }, |
| 268 | } |
| 269 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 270 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 271 | Blueprint: soongCcLibraryPreamble, |
| 272 | ExpectedBazelTargets: makeCcLibraryTargets("fake-libarm-optimized-routines-math", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 273 | "copts": `select({ |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 274 | "//build/bazel/platforms/arch:arm64": ["-DHAVE_FAST_FMA=1"], |
| 275 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 276 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 277 | "local_includes": `["."]`, |
| 278 | "srcs_c": `["math/cosf.c"]`, |
| 279 | }), |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 280 | }) |
| 281 | } |
| 282 | |
| 283 | func TestCcLibrarySharedStaticProps(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 284 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 285 | Description: "cc_library shared/static props", |
| 286 | ModuleTypeUnderTest: "cc_library", |
| 287 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 288 | Filesystem: map[string]string{ |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 289 | "both.cpp": "", |
| 290 | "sharedonly.cpp": "", |
| 291 | "staticonly.cpp": "", |
| 292 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 293 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 294 | cc_library { |
| 295 | name: "a", |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 296 | srcs: ["both.cpp"], |
| 297 | cflags: ["bothflag"], |
| 298 | shared_libs: ["shared_dep_for_both"], |
Liz Kammer | cc2c1ef | 2022-03-21 09:03:29 -0400 | [diff] [blame] | 299 | static_libs: ["static_dep_for_both", "whole_and_static_lib_for_both"], |
| 300 | 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] | 301 | static: { |
| 302 | srcs: ["staticonly.cpp"], |
| 303 | cflags: ["staticflag"], |
| 304 | shared_libs: ["shared_dep_for_static"], |
| 305 | static_libs: ["static_dep_for_static"], |
| 306 | whole_static_libs: ["whole_static_lib_for_static"], |
| 307 | }, |
| 308 | shared: { |
| 309 | srcs: ["sharedonly.cpp"], |
| 310 | cflags: ["sharedflag"], |
| 311 | shared_libs: ["shared_dep_for_shared"], |
| 312 | static_libs: ["static_dep_for_shared"], |
| 313 | whole_static_libs: ["whole_static_lib_for_shared"], |
| 314 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 315 | include_build_directory: false, |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 318 | cc_library_static { |
| 319 | name: "static_dep_for_shared", |
| 320 | bazel_module: { bp2build_available: false }, |
| 321 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 322 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 323 | cc_library_static { |
| 324 | name: "static_dep_for_static", |
| 325 | bazel_module: { bp2build_available: false }, |
| 326 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 327 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 328 | cc_library_static { |
| 329 | name: "static_dep_for_both", |
| 330 | bazel_module: { bp2build_available: false }, |
| 331 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 332 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 333 | cc_library_static { |
| 334 | name: "whole_static_lib_for_shared", |
| 335 | bazel_module: { bp2build_available: false }, |
| 336 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 337 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 338 | cc_library_static { |
| 339 | name: "whole_static_lib_for_static", |
| 340 | bazel_module: { bp2build_available: false }, |
| 341 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 342 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 343 | cc_library_static { |
| 344 | name: "whole_static_lib_for_both", |
| 345 | bazel_module: { bp2build_available: false }, |
| 346 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 347 | |
Liz Kammer | cc2c1ef | 2022-03-21 09:03:29 -0400 | [diff] [blame] | 348 | cc_library_static { |
| 349 | name: "whole_and_static_lib_for_both", |
| 350 | bazel_module: { bp2build_available: false }, |
| 351 | } |
| 352 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 353 | cc_library { |
| 354 | name: "shared_dep_for_shared", |
| 355 | bazel_module: { bp2build_available: false }, |
| 356 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 357 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 358 | cc_library { |
| 359 | name: "shared_dep_for_static", |
| 360 | bazel_module: { bp2build_available: false }, |
| 361 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 362 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 363 | cc_library { |
| 364 | name: "shared_dep_for_both", |
| 365 | bazel_module: { bp2build_available: false }, |
| 366 | } |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 367 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 368 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 369 | MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 370 | "copts": `[ |
| 371 | "bothflag", |
| 372 | "staticflag", |
| 373 | ]`, |
| 374 | "implementation_deps": `[ |
| 375 | ":static_dep_for_both", |
| 376 | ":static_dep_for_static", |
| 377 | ]`, |
| 378 | "implementation_dynamic_deps": `[ |
| 379 | ":shared_dep_for_both", |
| 380 | ":shared_dep_for_static", |
| 381 | ]`, |
| 382 | "srcs": `[ |
| 383 | "both.cpp", |
| 384 | "staticonly.cpp", |
| 385 | ]`, |
| 386 | "whole_archive_deps": `[ |
| 387 | ":whole_static_lib_for_both", |
Liz Kammer | cc2c1ef | 2022-03-21 09:03:29 -0400 | [diff] [blame] | 388 | ":whole_and_static_lib_for_both", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 389 | ":whole_static_lib_for_static", |
| 390 | ]`}), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 391 | MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 392 | "copts": `[ |
| 393 | "bothflag", |
| 394 | "sharedflag", |
| 395 | ]`, |
| 396 | "implementation_deps": `[ |
| 397 | ":static_dep_for_both", |
| 398 | ":static_dep_for_shared", |
| 399 | ]`, |
| 400 | "implementation_dynamic_deps": `[ |
| 401 | ":shared_dep_for_both", |
| 402 | ":shared_dep_for_shared", |
| 403 | ]`, |
| 404 | "srcs": `[ |
| 405 | "both.cpp", |
| 406 | "sharedonly.cpp", |
| 407 | ]`, |
| 408 | "whole_archive_deps": `[ |
| 409 | ":whole_static_lib_for_both", |
Liz Kammer | cc2c1ef | 2022-03-21 09:03:29 -0400 | [diff] [blame] | 410 | ":whole_and_static_lib_for_both", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 411 | ":whole_static_lib_for_shared", |
| 412 | ]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 413 | }), |
| 414 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 415 | }) |
| 416 | } |
| 417 | |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 418 | func TestCcLibraryDeps(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 419 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 420 | Description: "cc_library shared/static props", |
| 421 | ModuleTypeUnderTest: "cc_library", |
| 422 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 423 | Filesystem: map[string]string{ |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 424 | "both.cpp": "", |
| 425 | "sharedonly.cpp": "", |
| 426 | "staticonly.cpp": "", |
| 427 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 428 | Blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 429 | cc_library { |
| 430 | name: "a", |
| 431 | srcs: ["both.cpp"], |
| 432 | cflags: ["bothflag"], |
| 433 | shared_libs: ["implementation_shared_dep_for_both", "shared_dep_for_both"], |
| 434 | export_shared_lib_headers: ["shared_dep_for_both"], |
| 435 | static_libs: ["implementation_static_dep_for_both", "static_dep_for_both"], |
| 436 | export_static_lib_headers: ["static_dep_for_both", "whole_static_dep_for_both"], |
| 437 | whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_both", "whole_static_dep_for_both"], |
| 438 | static: { |
| 439 | srcs: ["staticonly.cpp"], |
| 440 | cflags: ["staticflag"], |
| 441 | shared_libs: ["implementation_shared_dep_for_static", "shared_dep_for_static"], |
| 442 | export_shared_lib_headers: ["shared_dep_for_static"], |
| 443 | static_libs: ["implementation_static_dep_for_static", "static_dep_for_static"], |
| 444 | export_static_lib_headers: ["static_dep_for_static", "whole_static_dep_for_static"], |
| 445 | whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_static", "whole_static_dep_for_static"], |
| 446 | }, |
| 447 | shared: { |
| 448 | srcs: ["sharedonly.cpp"], |
| 449 | cflags: ["sharedflag"], |
| 450 | shared_libs: ["implementation_shared_dep_for_shared", "shared_dep_for_shared"], |
| 451 | export_shared_lib_headers: ["shared_dep_for_shared"], |
| 452 | static_libs: ["implementation_static_dep_for_shared", "static_dep_for_shared"], |
| 453 | export_static_lib_headers: ["static_dep_for_shared", "whole_static_dep_for_shared"], |
| 454 | whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_shared", "whole_static_dep_for_shared"], |
| 455 | }, |
| 456 | include_build_directory: false, |
| 457 | } |
| 458 | ` + simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_shared") + |
| 459 | simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_shared") + |
| 460 | simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_static") + |
| 461 | simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_static") + |
| 462 | simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_both") + |
| 463 | simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_both") + |
| 464 | simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_shared") + |
| 465 | simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_shared") + |
| 466 | simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_static") + |
| 467 | simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_static") + |
| 468 | simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_both") + |
| 469 | simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_both") + |
| 470 | simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_shared") + |
| 471 | simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_shared") + |
| 472 | simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_static") + |
| 473 | simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_static") + |
| 474 | simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_both") + |
| 475 | simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_both"), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 476 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 477 | MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 478 | "copts": `[ |
| 479 | "bothflag", |
| 480 | "staticflag", |
| 481 | ]`, |
| 482 | "deps": `[ |
| 483 | ":static_dep_for_both", |
| 484 | ":static_dep_for_static", |
| 485 | ]`, |
| 486 | "dynamic_deps": `[ |
| 487 | ":shared_dep_for_both", |
| 488 | ":shared_dep_for_static", |
| 489 | ]`, |
| 490 | "implementation_deps": `[ |
| 491 | ":implementation_static_dep_for_both", |
| 492 | ":implementation_static_dep_for_static", |
| 493 | ]`, |
| 494 | "implementation_dynamic_deps": `[ |
| 495 | ":implementation_shared_dep_for_both", |
| 496 | ":implementation_shared_dep_for_static", |
| 497 | ]`, |
| 498 | "srcs": `[ |
| 499 | "both.cpp", |
| 500 | "staticonly.cpp", |
| 501 | ]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 502 | "whole_archive_deps": `[ |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 503 | ":not_explicitly_exported_whole_static_dep_for_both", |
| 504 | ":whole_static_dep_for_both", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 505 | ":not_explicitly_exported_whole_static_dep_for_static", |
| 506 | ":whole_static_dep_for_static", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 507 | ]`, |
| 508 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 509 | MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 510 | "copts": `[ |
| 511 | "bothflag", |
| 512 | "sharedflag", |
| 513 | ]`, |
| 514 | "deps": `[ |
| 515 | ":static_dep_for_both", |
| 516 | ":static_dep_for_shared", |
| 517 | ]`, |
| 518 | "dynamic_deps": `[ |
| 519 | ":shared_dep_for_both", |
| 520 | ":shared_dep_for_shared", |
| 521 | ]`, |
| 522 | "implementation_deps": `[ |
| 523 | ":implementation_static_dep_for_both", |
| 524 | ":implementation_static_dep_for_shared", |
| 525 | ]`, |
| 526 | "implementation_dynamic_deps": `[ |
| 527 | ":implementation_shared_dep_for_both", |
| 528 | ":implementation_shared_dep_for_shared", |
| 529 | ]`, |
| 530 | "srcs": `[ |
| 531 | "both.cpp", |
| 532 | "sharedonly.cpp", |
| 533 | ]`, |
| 534 | "whole_archive_deps": `[ |
| 535 | ":not_explicitly_exported_whole_static_dep_for_both", |
| 536 | ":whole_static_dep_for_both", |
| 537 | ":not_explicitly_exported_whole_static_dep_for_shared", |
| 538 | ":whole_static_dep_for_shared", |
| 539 | ]`, |
| 540 | })}, |
| 541 | }, |
| 542 | ) |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 543 | } |
| 544 | |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 545 | func TestCcLibraryWholeStaticLibsAlwaysLink(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 546 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 547 | ModuleTypeUnderTest: "cc_library", |
| 548 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 549 | Dir: "foo/bar", |
| 550 | Filesystem: map[string]string{ |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 551 | "foo/bar/Android.bp": ` |
| 552 | cc_library { |
| 553 | name: "a", |
| 554 | whole_static_libs: ["whole_static_lib_for_both"], |
| 555 | static: { |
| 556 | whole_static_libs: ["whole_static_lib_for_static"], |
| 557 | }, |
| 558 | shared: { |
| 559 | whole_static_libs: ["whole_static_lib_for_shared"], |
| 560 | }, |
| 561 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 562 | include_build_directory: false, |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | cc_prebuilt_library_static { name: "whole_static_lib_for_shared" } |
| 566 | |
| 567 | cc_prebuilt_library_static { name: "whole_static_lib_for_static" } |
| 568 | |
| 569 | cc_prebuilt_library_static { name: "whole_static_lib_for_both" } |
| 570 | `, |
| 571 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 572 | Blueprint: soongCcLibraryPreamble, |
| 573 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 574 | MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 575 | "whole_archive_deps": `[ |
| 576 | ":whole_static_lib_for_both_alwayslink", |
| 577 | ":whole_static_lib_for_static_alwayslink", |
| 578 | ]`, |
| 579 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 580 | MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 581 | "whole_archive_deps": `[ |
| 582 | ":whole_static_lib_for_both_alwayslink", |
| 583 | ":whole_static_lib_for_shared_alwayslink", |
| 584 | ]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 585 | }), |
| 586 | }, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 587 | }, |
| 588 | ) |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 589 | } |
| 590 | |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 591 | func TestCcLibrarySharedStaticPropsInArch(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 592 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 593 | Description: "cc_library shared/static props in arch", |
| 594 | ModuleTypeUnderTest: "cc_library", |
| 595 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 596 | Dir: "foo/bar", |
| 597 | Filesystem: map[string]string{ |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 598 | "foo/bar/arm.cpp": "", |
| 599 | "foo/bar/x86.cpp": "", |
| 600 | "foo/bar/sharedonly.cpp": "", |
| 601 | "foo/bar/staticonly.cpp": "", |
| 602 | "foo/bar/Android.bp": ` |
| 603 | cc_library { |
| 604 | name: "a", |
| 605 | arch: { |
| 606 | arm: { |
| 607 | shared: { |
| 608 | srcs: ["arm_shared.cpp"], |
| 609 | cflags: ["-DARM_SHARED"], |
| 610 | static_libs: ["arm_static_dep_for_shared"], |
| 611 | whole_static_libs: ["arm_whole_static_dep_for_shared"], |
| 612 | shared_libs: ["arm_shared_dep_for_shared"], |
| 613 | }, |
| 614 | }, |
| 615 | x86: { |
| 616 | static: { |
| 617 | srcs: ["x86_static.cpp"], |
| 618 | cflags: ["-DX86_STATIC"], |
| 619 | static_libs: ["x86_dep_for_static"], |
| 620 | }, |
| 621 | }, |
| 622 | }, |
| 623 | target: { |
| 624 | android: { |
| 625 | shared: { |
| 626 | srcs: ["android_shared.cpp"], |
| 627 | cflags: ["-DANDROID_SHARED"], |
| 628 | static_libs: ["android_dep_for_shared"], |
| 629 | }, |
| 630 | }, |
| 631 | android_arm: { |
| 632 | shared: { |
| 633 | cflags: ["-DANDROID_ARM_SHARED"], |
| 634 | }, |
| 635 | }, |
| 636 | }, |
| 637 | srcs: ["both.cpp"], |
| 638 | cflags: ["bothflag"], |
| 639 | static_libs: ["static_dep_for_both"], |
| 640 | static: { |
| 641 | srcs: ["staticonly.cpp"], |
| 642 | cflags: ["staticflag"], |
| 643 | static_libs: ["static_dep_for_static"], |
| 644 | }, |
| 645 | shared: { |
| 646 | srcs: ["sharedonly.cpp"], |
| 647 | cflags: ["sharedflag"], |
| 648 | static_libs: ["static_dep_for_shared"], |
| 649 | }, |
| 650 | bazel_module: { bp2build_available: true }, |
| 651 | } |
| 652 | |
| 653 | cc_library_static { name: "static_dep_for_shared" } |
| 654 | cc_library_static { name: "static_dep_for_static" } |
| 655 | cc_library_static { name: "static_dep_for_both" } |
| 656 | |
| 657 | cc_library_static { name: "arm_static_dep_for_shared" } |
| 658 | cc_library_static { name: "arm_whole_static_dep_for_shared" } |
| 659 | cc_library_static { name: "arm_shared_dep_for_shared" } |
| 660 | |
| 661 | cc_library_static { name: "x86_dep_for_static" } |
| 662 | |
| 663 | cc_library_static { name: "android_dep_for_shared" } |
| 664 | `, |
| 665 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 666 | Blueprint: soongCcLibraryPreamble, |
| 667 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 668 | MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 669 | "copts": `[ |
| 670 | "bothflag", |
| 671 | "staticflag", |
| 672 | ] + select({ |
| 673 | "//build/bazel/platforms/arch:x86": ["-DX86_STATIC"], |
| 674 | "//conditions:default": [], |
| 675 | })`, |
| 676 | "implementation_deps": `[ |
| 677 | ":static_dep_for_both", |
| 678 | ":static_dep_for_static", |
| 679 | ] + select({ |
| 680 | "//build/bazel/platforms/arch:x86": [":x86_dep_for_static"], |
| 681 | "//conditions:default": [], |
| 682 | })`, |
| 683 | "local_includes": `["."]`, |
| 684 | "srcs": `[ |
| 685 | "both.cpp", |
| 686 | "staticonly.cpp", |
| 687 | ] + select({ |
| 688 | "//build/bazel/platforms/arch:x86": ["x86_static.cpp"], |
| 689 | "//conditions:default": [], |
| 690 | })`, |
| 691 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 692 | MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 693 | "copts": `[ |
| 694 | "bothflag", |
| 695 | "sharedflag", |
| 696 | ] + select({ |
| 697 | "//build/bazel/platforms/arch:arm": ["-DARM_SHARED"], |
| 698 | "//conditions:default": [], |
| 699 | }) + select({ |
| 700 | "//build/bazel/platforms/os:android": ["-DANDROID_SHARED"], |
| 701 | "//conditions:default": [], |
| 702 | }) + select({ |
| 703 | "//build/bazel/platforms/os_arch:android_arm": ["-DANDROID_ARM_SHARED"], |
| 704 | "//conditions:default": [], |
| 705 | })`, |
| 706 | "implementation_deps": `[ |
| 707 | ":static_dep_for_both", |
| 708 | ":static_dep_for_shared", |
| 709 | ] + select({ |
| 710 | "//build/bazel/platforms/arch:arm": [":arm_static_dep_for_shared"], |
| 711 | "//conditions:default": [], |
| 712 | }) + select({ |
| 713 | "//build/bazel/platforms/os:android": [":android_dep_for_shared"], |
| 714 | "//conditions:default": [], |
| 715 | })`, |
| 716 | "implementation_dynamic_deps": `select({ |
| 717 | "//build/bazel/platforms/arch:arm": [":arm_shared_dep_for_shared"], |
| 718 | "//conditions:default": [], |
| 719 | })`, |
| 720 | "local_includes": `["."]`, |
| 721 | "srcs": `[ |
| 722 | "both.cpp", |
| 723 | "sharedonly.cpp", |
| 724 | ] + select({ |
| 725 | "//build/bazel/platforms/arch:arm": ["arm_shared.cpp"], |
| 726 | "//conditions:default": [], |
| 727 | }) + select({ |
| 728 | "//build/bazel/platforms/os:android": ["android_shared.cpp"], |
| 729 | "//conditions:default": [], |
| 730 | })`, |
| 731 | "whole_archive_deps": `select({ |
| 732 | "//build/bazel/platforms/arch:arm": [":arm_whole_static_dep_for_shared"], |
| 733 | "//conditions:default": [], |
| 734 | })`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 735 | }), |
| 736 | }, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 737 | }, |
| 738 | ) |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 739 | } |
| 740 | |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 741 | func TestCcLibrarySharedStaticPropsWithMixedSources(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 742 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 743 | Description: "cc_library shared/static props with c/cpp/s mixed sources", |
| 744 | ModuleTypeUnderTest: "cc_library", |
| 745 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 746 | Dir: "foo/bar", |
| 747 | Filesystem: map[string]string{ |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 748 | "foo/bar/both_source.cpp": "", |
| 749 | "foo/bar/both_source.cc": "", |
| 750 | "foo/bar/both_source.c": "", |
| 751 | "foo/bar/both_source.s": "", |
| 752 | "foo/bar/both_source.S": "", |
| 753 | "foo/bar/shared_source.cpp": "", |
| 754 | "foo/bar/shared_source.cc": "", |
| 755 | "foo/bar/shared_source.c": "", |
| 756 | "foo/bar/shared_source.s": "", |
| 757 | "foo/bar/shared_source.S": "", |
| 758 | "foo/bar/static_source.cpp": "", |
| 759 | "foo/bar/static_source.cc": "", |
| 760 | "foo/bar/static_source.c": "", |
| 761 | "foo/bar/static_source.s": "", |
| 762 | "foo/bar/static_source.S": "", |
| 763 | "foo/bar/Android.bp": ` |
| 764 | cc_library { |
| 765 | name: "a", |
| 766 | srcs: [ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 767 | "both_source.cpp", |
| 768 | "both_source.cc", |
| 769 | "both_source.c", |
| 770 | "both_source.s", |
| 771 | "both_source.S", |
Liz Kammer | 57e2e7a | 2021-09-20 12:55:02 -0400 | [diff] [blame] | 772 | ":both_filegroup", |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 773 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 774 | static: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 775 | srcs: [ |
| 776 | "static_source.cpp", |
| 777 | "static_source.cc", |
| 778 | "static_source.c", |
| 779 | "static_source.s", |
| 780 | "static_source.S", |
| 781 | ":static_filegroup", |
| 782 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 783 | }, |
| 784 | shared: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 785 | srcs: [ |
| 786 | "shared_source.cpp", |
| 787 | "shared_source.cc", |
| 788 | "shared_source.c", |
| 789 | "shared_source.s", |
| 790 | "shared_source.S", |
| 791 | ":shared_filegroup", |
| 792 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 793 | }, |
| 794 | bazel_module: { bp2build_available: true }, |
| 795 | } |
| 796 | |
| 797 | filegroup { |
| 798 | name: "both_filegroup", |
| 799 | srcs: [ |
| 800 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 801 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | filegroup { |
| 805 | name: "shared_filegroup", |
| 806 | srcs: [ |
| 807 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 808 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | filegroup { |
| 812 | name: "static_filegroup", |
| 813 | srcs: [ |
| 814 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 815 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 816 | } |
| 817 | `, |
| 818 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 819 | Blueprint: soongCcLibraryPreamble, |
| 820 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 821 | MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 822 | "local_includes": `["."]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 823 | "srcs": `[ |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 824 | "both_source.cpp", |
Liz Kammer | 57e2e7a | 2021-09-20 12:55:02 -0400 | [diff] [blame] | 825 | "both_source.cc", |
| 826 | ":both_filegroup_cpp_srcs", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 827 | "static_source.cpp", |
| 828 | "static_source.cc", |
| 829 | ":static_filegroup_cpp_srcs", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 830 | ]`, |
| 831 | "srcs_as": `[ |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 832 | "both_source.s", |
| 833 | "both_source.S", |
| 834 | ":both_filegroup_as_srcs", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 835 | "static_source.s", |
| 836 | "static_source.S", |
| 837 | ":static_filegroup_as_srcs", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 838 | ]`, |
| 839 | "srcs_c": `[ |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 840 | "both_source.c", |
| 841 | ":both_filegroup_c_srcs", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 842 | "static_source.c", |
| 843 | ":static_filegroup_c_srcs", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 844 | ]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 845 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 846 | MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 847 | "local_includes": `["."]`, |
| 848 | "srcs": `[ |
| 849 | "both_source.cpp", |
| 850 | "both_source.cc", |
| 851 | ":both_filegroup_cpp_srcs", |
| 852 | "shared_source.cpp", |
| 853 | "shared_source.cc", |
| 854 | ":shared_filegroup_cpp_srcs", |
| 855 | ]`, |
| 856 | "srcs_as": `[ |
| 857 | "both_source.s", |
| 858 | "both_source.S", |
| 859 | ":both_filegroup_as_srcs", |
| 860 | "shared_source.s", |
| 861 | "shared_source.S", |
| 862 | ":shared_filegroup_as_srcs", |
| 863 | ]`, |
| 864 | "srcs_c": `[ |
| 865 | "both_source.c", |
| 866 | ":both_filegroup_c_srcs", |
| 867 | "shared_source.c", |
| 868 | ":shared_filegroup_c_srcs", |
| 869 | ]`, |
| 870 | })}}) |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 871 | } |
| 872 | |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 873 | func TestCcLibraryNonConfiguredVersionScriptAndDynamicList(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 874 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 875 | Description: "cc_library non-configured version script and dynamic list", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 876 | ModuleTypeUnderTest: "cc_library", |
| 877 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 878 | Dir: "foo/bar", |
| 879 | Filesystem: map[string]string{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 880 | "foo/bar/Android.bp": ` |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 881 | cc_library { |
| 882 | name: "a", |
| 883 | srcs: ["a.cpp"], |
| 884 | version_script: "v.map", |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 885 | dynamic_list: "dynamic.list", |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 886 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 887 | include_build_directory: false, |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 888 | } |
| 889 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 890 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 891 | Blueprint: soongCcLibraryPreamble, |
| 892 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 893 | "additional_linker_inputs": `[ |
| 894 | "v.map", |
| 895 | "dynamic.list", |
| 896 | ]`, |
| 897 | "linkopts": `[ |
| 898 | "-Wl,--version-script,$(location v.map)", |
| 899 | "-Wl,--dynamic-list,$(location dynamic.list)", |
| 900 | ]`, |
| 901 | "srcs": `["a.cpp"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 902 | }), |
| 903 | }, |
| 904 | ) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 905 | } |
| 906 | |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 907 | func TestCcLibraryConfiguredVersionScriptAndDynamicList(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 908 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 909 | Description: "cc_library configured version script and dynamic list", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 910 | ModuleTypeUnderTest: "cc_library", |
| 911 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 912 | Dir: "foo/bar", |
| 913 | Filesystem: map[string]string{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 914 | "foo/bar/Android.bp": ` |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 915 | cc_library { |
| 916 | name: "a", |
| 917 | srcs: ["a.cpp"], |
| 918 | arch: { |
| 919 | arm: { |
| 920 | version_script: "arm.map", |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 921 | dynamic_list: "dynamic_arm.list", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 922 | }, |
| 923 | arm64: { |
| 924 | version_script: "arm64.map", |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 925 | dynamic_list: "dynamic_arm64.list", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 926 | }, |
| 927 | }, |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 928 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 929 | bazel_module: { bp2build_available: true }, |
| 930 | include_build_directory: false, |
| 931 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 932 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 933 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 934 | Blueprint: soongCcLibraryPreamble, |
| 935 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 936 | "additional_linker_inputs": `select({ |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 937 | "//build/bazel/platforms/arch:arm": [ |
| 938 | "arm.map", |
| 939 | "dynamic_arm.list", |
| 940 | ], |
| 941 | "//build/bazel/platforms/arch:arm64": [ |
| 942 | "arm64.map", |
| 943 | "dynamic_arm64.list", |
| 944 | ], |
Liz Kammer | d287118 | 2021-10-04 13:54:37 -0400 | [diff] [blame] | 945 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 946 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 947 | "linkopts": `select({ |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 948 | "//build/bazel/platforms/arch:arm": [ |
| 949 | "-Wl,--version-script,$(location arm.map)", |
| 950 | "-Wl,--dynamic-list,$(location dynamic_arm.list)", |
| 951 | ], |
| 952 | "//build/bazel/platforms/arch:arm64": [ |
| 953 | "-Wl,--version-script,$(location arm64.map)", |
| 954 | "-Wl,--dynamic-list,$(location dynamic_arm64.list)", |
| 955 | ], |
Liz Kammer | d287118 | 2021-10-04 13:54:37 -0400 | [diff] [blame] | 956 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 957 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 958 | "srcs": `["a.cpp"]`, |
| 959 | }), |
| 960 | }, |
| 961 | ) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 962 | } |
| 963 | |
Trevor Radcliffe | ea6a45d | 2022-09-20 18:58:01 +0000 | [diff] [blame] | 964 | func TestCcLibraryLdflagsSplitBySpaceExceptSoongAdded(t *testing.T) { |
| 965 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 966 | Description: "ldflags are split by spaces except for the ones added by soong (version script and dynamic list)", |
| 967 | ModuleTypeUnderTest: "cc_library", |
| 968 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 969 | Filesystem: map[string]string{ |
| 970 | "version_script": "", |
| 971 | "dynamic.list": "", |
| 972 | }, |
| 973 | Blueprint: ` |
| 974 | cc_library { |
| 975 | name: "foo", |
| 976 | ldflags: [ |
| 977 | "--nospace_flag", |
| 978 | "-z spaceflag", |
| 979 | ], |
| 980 | version_script: "version_script", |
| 981 | dynamic_list: "dynamic.list", |
| 982 | include_build_directory: false, |
| 983 | } |
| 984 | `, |
| 985 | ExpectedBazelTargets: []string{ |
| 986 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), |
| 987 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 988 | "additional_linker_inputs": `[ |
| 989 | "version_script", |
| 990 | "dynamic.list", |
| 991 | ]`, |
| 992 | "linkopts": `[ |
| 993 | "--nospace_flag", |
| 994 | "-z", |
| 995 | "spaceflag", |
| 996 | "-Wl,--version-script,$(location version_script)", |
| 997 | "-Wl,--dynamic-list,$(location dynamic.list)", |
| 998 | ]`, |
| 999 | }), |
| 1000 | }, |
| 1001 | }) |
| 1002 | } |
| 1003 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1004 | func TestCcLibrarySharedLibs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1005 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1006 | Description: "cc_library shared_libs", |
| 1007 | ModuleTypeUnderTest: "cc_library", |
| 1008 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1009 | Blueprint: soongCcLibraryPreamble + ` |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 1010 | cc_library { |
| 1011 | name: "mylib", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1012 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | cc_library { |
| 1016 | name: "a", |
| 1017 | shared_libs: ["mylib",], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1018 | include_build_directory: false, |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 1019 | } |
| 1020 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1021 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1022 | "implementation_dynamic_deps": `[":mylib"]`, |
| 1023 | }), |
| 1024 | }, |
| 1025 | ) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1026 | } |
| 1027 | |
Liz Kammer | 0eae52e | 2021-10-06 10:32:26 -0400 | [diff] [blame] | 1028 | func TestCcLibraryFeatures(t *testing.T) { |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1029 | expected_targets := []string{} |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1030 | expected_targets = append(expected_targets, makeCcLibraryTargets("a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1031 | "features": `[ |
| 1032 | "disable_pack_relocations", |
| 1033 | "-no_undefined_symbols", |
Yu Liu | 8d82ac5 | 2022-05-17 15:13:28 -0700 | [diff] [blame] | 1034 | "-coverage", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1035 | ]`, |
| 1036 | "srcs": `["a.cpp"]`, |
| 1037 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1038 | expected_targets = append(expected_targets, makeCcLibraryTargets("b", AttrNameToString{ |
Yu Liu | 8d82ac5 | 2022-05-17 15:13:28 -0700 | [diff] [blame] | 1039 | "features": `["-coverage"] + select({ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1040 | "//build/bazel/platforms/arch:x86_64": [ |
| 1041 | "disable_pack_relocations", |
| 1042 | "-no_undefined_symbols", |
| 1043 | ], |
| 1044 | "//conditions:default": [], |
| 1045 | })`, |
| 1046 | "srcs": `["b.cpp"]`, |
| 1047 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1048 | expected_targets = append(expected_targets, makeCcLibraryTargets("c", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1049 | "features": `select({ |
| 1050 | "//build/bazel/platforms/os:darwin": [ |
| 1051 | "disable_pack_relocations", |
| 1052 | "-no_undefined_symbols", |
| 1053 | ], |
| 1054 | "//conditions:default": [], |
| 1055 | })`, |
| 1056 | "srcs": `["c.cpp"]`, |
| 1057 | })...) |
| 1058 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1059 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1060 | Description: "cc_library pack_relocations test", |
| 1061 | ModuleTypeUnderTest: "cc_library", |
| 1062 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1063 | Blueprint: soongCcLibraryPreamble + ` |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1064 | cc_library { |
| 1065 | name: "a", |
| 1066 | srcs: ["a.cpp"], |
| 1067 | pack_relocations: false, |
Liz Kammer | 0eae52e | 2021-10-06 10:32:26 -0400 | [diff] [blame] | 1068 | allow_undefined_symbols: true, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1069 | include_build_directory: false, |
Yu Liu | 8d82ac5 | 2022-05-17 15:13:28 -0700 | [diff] [blame] | 1070 | native_coverage: false, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | cc_library { |
| 1074 | name: "b", |
| 1075 | srcs: ["b.cpp"], |
| 1076 | arch: { |
| 1077 | x86_64: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1078 | pack_relocations: false, |
Liz Kammer | 0eae52e | 2021-10-06 10:32:26 -0400 | [diff] [blame] | 1079 | allow_undefined_symbols: true, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1080 | }, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1081 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1082 | include_build_directory: false, |
Yu Liu | 8d82ac5 | 2022-05-17 15:13:28 -0700 | [diff] [blame] | 1083 | native_coverage: false, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | cc_library { |
| 1087 | name: "c", |
| 1088 | srcs: ["c.cpp"], |
| 1089 | target: { |
| 1090 | darwin: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1091 | pack_relocations: false, |
Liz Kammer | 0eae52e | 2021-10-06 10:32:26 -0400 | [diff] [blame] | 1092 | allow_undefined_symbols: true, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1093 | }, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1094 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1095 | include_build_directory: false, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1096 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1097 | ExpectedBazelTargets: expected_targets, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1098 | }) |
| 1099 | } |
| 1100 | |
| 1101 | func TestCcLibrarySpacesInCopts(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1102 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1103 | Description: "cc_library spaces in copts", |
| 1104 | ModuleTypeUnderTest: "cc_library", |
| 1105 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1106 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 1107 | cc_library { |
| 1108 | name: "a", |
| 1109 | cflags: ["-include header.h",], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1110 | include_build_directory: false, |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 1111 | } |
| 1112 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1113 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1114 | "copts": `[ |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 1115 | "-include", |
| 1116 | "header.h", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1117 | ]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1118 | }), |
| 1119 | }, |
| 1120 | ) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1124 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1125 | Description: "cc_library cppflags usage", |
| 1126 | ModuleTypeUnderTest: "cc_library", |
| 1127 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1128 | Blueprint: soongCcLibraryPreamble + `cc_library { |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1129 | name: "a", |
| 1130 | srcs: ["a.cpp"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1131 | cflags: ["-Wall"], |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1132 | cppflags: [ |
| 1133 | "-fsigned-char", |
| 1134 | "-pedantic", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1135 | ], |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1136 | arch: { |
| 1137 | arm64: { |
| 1138 | cppflags: ["-DARM64=1"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1139 | }, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1140 | }, |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1141 | target: { |
| 1142 | android: { |
| 1143 | cppflags: ["-DANDROID=1"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1144 | }, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1145 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1146 | include_build_directory: false, |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1147 | } |
| 1148 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1149 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1150 | "copts": `["-Wall"]`, |
| 1151 | "cppflags": `[ |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 1152 | "-fsigned-char", |
| 1153 | "-pedantic", |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1154 | ] + select({ |
| 1155 | "//build/bazel/platforms/arch:arm64": ["-DARM64=1"], |
| 1156 | "//conditions:default": [], |
| 1157 | }) + select({ |
| 1158 | "//build/bazel/platforms/os:android": ["-DANDROID=1"], |
| 1159 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1160 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1161 | "srcs": `["a.cpp"]`, |
| 1162 | }), |
| 1163 | }, |
| 1164 | ) |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 1165 | } |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 1166 | |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1167 | func TestCcLibraryExcludeLibs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1168 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1169 | ModuleTypeUnderTest: "cc_library", |
| 1170 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1171 | Filesystem: map[string]string{}, |
| 1172 | Blueprint: soongCcLibraryStaticPreamble + ` |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1173 | cc_library { |
| 1174 | name: "foo_static", |
| 1175 | srcs: ["common.c"], |
| 1176 | whole_static_libs: [ |
| 1177 | "arm_whole_static_lib_excludes", |
| 1178 | "malloc_not_svelte_whole_static_lib_excludes" |
| 1179 | ], |
| 1180 | static_libs: [ |
| 1181 | "arm_static_lib_excludes", |
| 1182 | "malloc_not_svelte_static_lib_excludes" |
| 1183 | ], |
| 1184 | shared_libs: [ |
| 1185 | "arm_shared_lib_excludes", |
| 1186 | ], |
| 1187 | arch: { |
| 1188 | arm: { |
| 1189 | exclude_shared_libs: [ |
| 1190 | "arm_shared_lib_excludes", |
| 1191 | ], |
| 1192 | exclude_static_libs: [ |
| 1193 | "arm_static_lib_excludes", |
| 1194 | "arm_whole_static_lib_excludes", |
| 1195 | ], |
| 1196 | }, |
| 1197 | }, |
| 1198 | product_variables: { |
| 1199 | malloc_not_svelte: { |
| 1200 | shared_libs: ["malloc_not_svelte_shared_lib"], |
| 1201 | whole_static_libs: ["malloc_not_svelte_whole_static_lib"], |
| 1202 | exclude_static_libs: [ |
| 1203 | "malloc_not_svelte_static_lib_excludes", |
| 1204 | "malloc_not_svelte_whole_static_lib_excludes", |
| 1205 | ], |
| 1206 | }, |
| 1207 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1208 | include_build_directory: false, |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | cc_library { |
| 1212 | name: "arm_whole_static_lib_excludes", |
| 1213 | bazel_module: { bp2build_available: false }, |
| 1214 | } |
| 1215 | |
| 1216 | cc_library { |
| 1217 | name: "malloc_not_svelte_whole_static_lib", |
| 1218 | bazel_module: { bp2build_available: false }, |
| 1219 | } |
| 1220 | |
| 1221 | cc_library { |
| 1222 | name: "malloc_not_svelte_whole_static_lib_excludes", |
| 1223 | bazel_module: { bp2build_available: false }, |
| 1224 | } |
| 1225 | |
| 1226 | cc_library { |
| 1227 | name: "arm_static_lib_excludes", |
| 1228 | bazel_module: { bp2build_available: false }, |
| 1229 | } |
| 1230 | |
| 1231 | cc_library { |
| 1232 | name: "malloc_not_svelte_static_lib_excludes", |
| 1233 | bazel_module: { bp2build_available: false }, |
| 1234 | } |
| 1235 | |
| 1236 | cc_library { |
| 1237 | name: "arm_shared_lib_excludes", |
| 1238 | bazel_module: { bp2build_available: false }, |
| 1239 | } |
| 1240 | |
| 1241 | cc_library { |
| 1242 | name: "malloc_not_svelte_shared_lib", |
| 1243 | bazel_module: { bp2build_available: false }, |
| 1244 | } |
| 1245 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1246 | ExpectedBazelTargets: makeCcLibraryTargets("foo_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1247 | "implementation_deps": `select({ |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1248 | "//build/bazel/platforms/arch:arm": [], |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1249 | "//conditions:default": [":arm_static_lib_excludes_bp2build_cc_library_static"], |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1250 | }) + select({ |
| 1251 | "//build/bazel/product_variables:malloc_not_svelte": [], |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1252 | "//conditions:default": [":malloc_not_svelte_static_lib_excludes_bp2build_cc_library_static"], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1253 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1254 | "implementation_dynamic_deps": `select({ |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 1255 | "//build/bazel/platforms/arch:arm": [], |
| 1256 | "//conditions:default": [":arm_shared_lib_excludes"], |
| 1257 | }) + select({ |
| 1258 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_shared_lib"], |
| 1259 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1260 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1261 | "srcs_c": `["common.c"]`, |
| 1262 | "whole_archive_deps": `select({ |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1263 | "//build/bazel/platforms/arch:arm": [], |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1264 | "//conditions:default": [":arm_whole_static_lib_excludes_bp2build_cc_library_static"], |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1265 | }) + select({ |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1266 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_whole_static_lib_bp2build_cc_library_static"], |
| 1267 | "//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] | 1268 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1269 | }), |
| 1270 | }, |
| 1271 | ) |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1272 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1273 | |
Zi Wang | 0a8a129 | 2022-08-30 06:27:01 +0000 | [diff] [blame] | 1274 | func TestCcLibraryProductVariablesHeaderLibs(t *testing.T) { |
| 1275 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1276 | ModuleTypeUnderTest: "cc_library", |
| 1277 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1278 | Filesystem: map[string]string{}, |
| 1279 | Blueprint: soongCcLibraryStaticPreamble + ` |
| 1280 | cc_library { |
| 1281 | name: "foo_static", |
| 1282 | srcs: ["common.c"], |
| 1283 | product_variables: { |
| 1284 | malloc_not_svelte: { |
| 1285 | header_libs: ["malloc_not_svelte_header_lib"], |
| 1286 | }, |
| 1287 | }, |
| 1288 | include_build_directory: false, |
| 1289 | } |
| 1290 | |
| 1291 | cc_library { |
| 1292 | name: "malloc_not_svelte_header_lib", |
| 1293 | bazel_module: { bp2build_available: false }, |
| 1294 | } |
| 1295 | `, |
| 1296 | ExpectedBazelTargets: makeCcLibraryTargets("foo_static", AttrNameToString{ |
| 1297 | "implementation_deps": `select({ |
| 1298 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_header_lib"], |
| 1299 | "//conditions:default": [], |
| 1300 | })`, |
| 1301 | "srcs_c": `["common.c"]`, |
| 1302 | "target_compatible_with": `["//build/bazel/platforms/os:android"]`, |
| 1303 | }), |
| 1304 | }, |
| 1305 | ) |
| 1306 | } |
| 1307 | |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1308 | func TestCCLibraryNoCrtTrue(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1309 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1310 | Description: "cc_library - nocrt: true emits attribute", |
| 1311 | ModuleTypeUnderTest: "cc_library", |
| 1312 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1313 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1314 | "impl.cpp": "", |
| 1315 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1316 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1317 | cc_library { |
| 1318 | name: "foo-lib", |
| 1319 | srcs: ["impl.cpp"], |
| 1320 | nocrt: true, |
| 1321 | include_build_directory: false, |
| 1322 | } |
| 1323 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1324 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1325 | "link_crt": `False`, |
| 1326 | "srcs": `["impl.cpp"]`, |
| 1327 | }), |
| 1328 | }, |
| 1329 | ) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | func TestCCLibraryNoCrtFalse(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1333 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1334 | Description: "cc_library - nocrt: false - does not emit attribute", |
| 1335 | ModuleTypeUnderTest: "cc_library", |
| 1336 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1337 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1338 | "impl.cpp": "", |
| 1339 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1340 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1341 | cc_library { |
| 1342 | name: "foo-lib", |
| 1343 | srcs: ["impl.cpp"], |
| 1344 | nocrt: false, |
| 1345 | include_build_directory: false, |
| 1346 | } |
| 1347 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1348 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1349 | "srcs": `["impl.cpp"]`, |
| 1350 | }), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1351 | }) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | func TestCCLibraryNoCrtArchVariant(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1355 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1356 | Description: "cc_library - nocrt in select", |
| 1357 | ModuleTypeUnderTest: "cc_library", |
| 1358 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1359 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1360 | "impl.cpp": "", |
| 1361 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1362 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1363 | cc_library { |
| 1364 | name: "foo-lib", |
| 1365 | srcs: ["impl.cpp"], |
| 1366 | arch: { |
| 1367 | arm: { |
| 1368 | nocrt: true, |
| 1369 | }, |
| 1370 | x86: { |
| 1371 | nocrt: false, |
| 1372 | }, |
| 1373 | }, |
| 1374 | include_build_directory: false, |
| 1375 | } |
| 1376 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1377 | 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] | 1378 | }) |
| 1379 | } |
| 1380 | |
| 1381 | func TestCCLibraryNoLibCrtTrue(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1382 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1383 | ModuleTypeUnderTest: "cc_library", |
| 1384 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1385 | Filesystem: map[string]string{ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1386 | "impl.cpp": "", |
| 1387 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1388 | Blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1389 | cc_library { |
| 1390 | name: "foo-lib", |
| 1391 | srcs: ["impl.cpp"], |
| 1392 | no_libcrt: true, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1393 | include_build_directory: false, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1394 | } |
| 1395 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1396 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1397 | "srcs": `["impl.cpp"]`, |
| 1398 | "use_libcrt": `False`, |
| 1399 | }), |
| 1400 | }) |
| 1401 | } |
| 1402 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1403 | func makeCcLibraryTargets(name string, attrs AttrNameToString) []string { |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1404 | STATIC_ONLY_ATTRS := map[string]bool{} |
| 1405 | SHARED_ONLY_ATTRS := map[string]bool{ |
| 1406 | "link_crt": true, |
| 1407 | "additional_linker_inputs": true, |
| 1408 | "linkopts": true, |
| 1409 | "strip": true, |
Yu Liu | 75be7b9 | 2022-02-01 09:54:09 -0800 | [diff] [blame] | 1410 | "inject_bssl_hash": true, |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 1411 | "has_stubs": true, |
Yu Liu | 56ccb1a | 2022-11-12 10:47:07 -0800 | [diff] [blame^] | 1412 | "stubs_symbol_file": true, |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 1413 | "use_version_lib": true, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1414 | } |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 1415 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1416 | sharedAttrs := AttrNameToString{} |
| 1417 | staticAttrs := AttrNameToString{} |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1418 | for key, val := range attrs { |
| 1419 | if _, staticOnly := STATIC_ONLY_ATTRS[key]; !staticOnly { |
| 1420 | sharedAttrs[key] = val |
| 1421 | } |
| 1422 | if _, sharedOnly := SHARED_ONLY_ATTRS[key]; !sharedOnly { |
| 1423 | staticAttrs[key] = val |
| 1424 | } |
| 1425 | } |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1426 | sharedTarget := MakeBazelTarget("cc_library_shared", name, sharedAttrs) |
| 1427 | staticTarget := MakeBazelTarget("cc_library_static", name+"_bp2build_cc_library_static", staticAttrs) |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1428 | |
| 1429 | return []string{staticTarget, sharedTarget} |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1430 | } |
| 1431 | |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1432 | func TestCCLibraryNoLibCrtFalse(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1433 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1434 | ModuleTypeUnderTest: "cc_library", |
| 1435 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1436 | Filesystem: map[string]string{ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1437 | "impl.cpp": "", |
| 1438 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1439 | Blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1440 | cc_library { |
| 1441 | name: "foo-lib", |
| 1442 | srcs: ["impl.cpp"], |
| 1443 | no_libcrt: false, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1444 | include_build_directory: false, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1445 | } |
| 1446 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1447 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1448 | "srcs": `["impl.cpp"]`, |
| 1449 | "use_libcrt": `True`, |
| 1450 | }), |
| 1451 | }) |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1452 | } |
| 1453 | |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1454 | func TestCCLibraryNoLibCrtArchVariant(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1455 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1456 | ModuleTypeUnderTest: "cc_library", |
| 1457 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1458 | Filesystem: map[string]string{ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1459 | "impl.cpp": "", |
| 1460 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1461 | Blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1462 | cc_library { |
| 1463 | name: "foo-lib", |
| 1464 | srcs: ["impl.cpp"], |
| 1465 | arch: { |
| 1466 | arm: { |
| 1467 | no_libcrt: true, |
| 1468 | }, |
| 1469 | x86: { |
| 1470 | no_libcrt: true, |
| 1471 | }, |
| 1472 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1473 | include_build_directory: false, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1474 | } |
| 1475 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1476 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1477 | "srcs": `["impl.cpp"]`, |
| 1478 | "use_libcrt": `select({ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1479 | "//build/bazel/platforms/arch:arm": False, |
| 1480 | "//build/bazel/platforms/arch:x86": False, |
| 1481 | "//conditions:default": None, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1482 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1483 | }), |
| 1484 | }) |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1485 | } |
| 1486 | |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1487 | func TestCCLibraryNoLibCrtArchAndTargetVariant(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1488 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1489 | ModuleTypeUnderTest: "cc_library", |
| 1490 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1491 | Filesystem: map[string]string{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1492 | "impl.cpp": "", |
| 1493 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1494 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1495 | cc_library { |
| 1496 | name: "foo-lib", |
| 1497 | srcs: ["impl.cpp"], |
| 1498 | arch: { |
| 1499 | arm: { |
| 1500 | no_libcrt: true, |
| 1501 | }, |
| 1502 | x86: { |
| 1503 | no_libcrt: true, |
| 1504 | }, |
| 1505 | }, |
| 1506 | target: { |
| 1507 | darwin: { |
| 1508 | no_libcrt: true, |
| 1509 | } |
| 1510 | }, |
| 1511 | include_build_directory: false, |
| 1512 | } |
| 1513 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1514 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1515 | "srcs": `["impl.cpp"]`, |
| 1516 | "use_libcrt": `select({ |
| 1517 | "//build/bazel/platforms/os_arch:android_arm": False, |
| 1518 | "//build/bazel/platforms/os_arch:android_x86": False, |
| 1519 | "//build/bazel/platforms/os_arch:darwin_arm64": False, |
| 1520 | "//build/bazel/platforms/os_arch:darwin_x86_64": False, |
| 1521 | "//build/bazel/platforms/os_arch:linux_glibc_x86": False, |
| 1522 | "//build/bazel/platforms/os_arch:linux_musl_x86": False, |
| 1523 | "//build/bazel/platforms/os_arch:windows_x86": False, |
| 1524 | "//conditions:default": None, |
| 1525 | })`, |
| 1526 | }), |
| 1527 | }) |
| 1528 | } |
| 1529 | |
| 1530 | func TestCCLibraryNoLibCrtArchAndTargetVariantConflict(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1531 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1532 | ModuleTypeUnderTest: "cc_library", |
| 1533 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1534 | Filesystem: map[string]string{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1535 | "impl.cpp": "", |
| 1536 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1537 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1538 | cc_library { |
| 1539 | name: "foo-lib", |
| 1540 | srcs: ["impl.cpp"], |
| 1541 | arch: { |
| 1542 | arm: { |
| 1543 | no_libcrt: true, |
| 1544 | }, |
| 1545 | // This is expected to override the value for darwin_x86_64. |
| 1546 | x86_64: { |
| 1547 | no_libcrt: true, |
| 1548 | }, |
| 1549 | }, |
| 1550 | target: { |
| 1551 | darwin: { |
| 1552 | no_libcrt: false, |
| 1553 | } |
| 1554 | }, |
| 1555 | include_build_directory: false, |
| 1556 | } |
| 1557 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1558 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1559 | "srcs": `["impl.cpp"]`, |
| 1560 | "use_libcrt": `select({ |
| 1561 | "//build/bazel/platforms/os_arch:android_arm": False, |
| 1562 | "//build/bazel/platforms/os_arch:android_x86_64": False, |
| 1563 | "//build/bazel/platforms/os_arch:darwin_arm64": True, |
| 1564 | "//build/bazel/platforms/os_arch:darwin_x86_64": False, |
| 1565 | "//build/bazel/platforms/os_arch:linux_bionic_x86_64": False, |
| 1566 | "//build/bazel/platforms/os_arch:linux_glibc_x86_64": False, |
| 1567 | "//build/bazel/platforms/os_arch:linux_musl_x86_64": False, |
| 1568 | "//build/bazel/platforms/os_arch:windows_x86_64": False, |
| 1569 | "//conditions:default": None, |
| 1570 | })`, |
| 1571 | }), |
| 1572 | }) |
| 1573 | } |
| 1574 | |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1575 | func TestCcLibraryStrip(t *testing.T) { |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1576 | expectedTargets := []string{} |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1577 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("all", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1578 | "strip": `{ |
| 1579 | "all": True, |
| 1580 | }`, |
| 1581 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1582 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1583 | "strip": `{ |
| 1584 | "keep_symbols": True, |
| 1585 | }`, |
| 1586 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1587 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols_and_debug_frame", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1588 | "strip": `{ |
| 1589 | "keep_symbols_and_debug_frame": True, |
| 1590 | }`, |
| 1591 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1592 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols_list", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1593 | "strip": `{ |
| 1594 | "keep_symbols_list": ["symbol"], |
| 1595 | }`, |
| 1596 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1597 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("none", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1598 | "strip": `{ |
| 1599 | "none": True, |
| 1600 | }`, |
| 1601 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1602 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("nothing", AttrNameToString{})...) |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1603 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1604 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1605 | Description: "cc_library strip args", |
| 1606 | ModuleTypeUnderTest: "cc_library", |
| 1607 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1608 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1609 | cc_library { |
| 1610 | name: "nothing", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1611 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1612 | } |
| 1613 | cc_library { |
| 1614 | name: "keep_symbols", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1615 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1616 | keep_symbols: true, |
| 1617 | }, |
| 1618 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1619 | } |
| 1620 | cc_library { |
| 1621 | name: "keep_symbols_and_debug_frame", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1622 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1623 | keep_symbols_and_debug_frame: true, |
| 1624 | }, |
| 1625 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1626 | } |
| 1627 | cc_library { |
| 1628 | name: "none", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1629 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1630 | none: true, |
| 1631 | }, |
| 1632 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1633 | } |
| 1634 | cc_library { |
| 1635 | name: "keep_symbols_list", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1636 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1637 | keep_symbols_list: ["symbol"], |
| 1638 | }, |
| 1639 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1640 | } |
| 1641 | cc_library { |
| 1642 | name: "all", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1643 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1644 | all: true, |
| 1645 | }, |
| 1646 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1647 | } |
| 1648 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1649 | ExpectedBazelTargets: expectedTargets, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1650 | }) |
| 1651 | } |
| 1652 | |
| 1653 | func TestCcLibraryStripWithArch(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1654 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1655 | Description: "cc_library strip args", |
| 1656 | ModuleTypeUnderTest: "cc_library", |
| 1657 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1658 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1659 | cc_library { |
| 1660 | name: "multi-arch", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1661 | target: { |
| 1662 | darwin: { |
| 1663 | strip: { |
| 1664 | keep_symbols_list: ["foo", "bar"] |
| 1665 | } |
| 1666 | }, |
| 1667 | }, |
| 1668 | arch: { |
| 1669 | arm: { |
| 1670 | strip: { |
| 1671 | keep_symbols_and_debug_frame: true, |
| 1672 | }, |
| 1673 | }, |
| 1674 | arm64: { |
| 1675 | strip: { |
| 1676 | keep_symbols: true, |
| 1677 | }, |
| 1678 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1679 | }, |
| 1680 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1681 | } |
| 1682 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1683 | ExpectedBazelTargets: makeCcLibraryTargets("multi-arch", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1684 | "strip": `{ |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1685 | "keep_symbols": select({ |
| 1686 | "//build/bazel/platforms/arch:arm64": True, |
| 1687 | "//conditions:default": None, |
| 1688 | }), |
| 1689 | "keep_symbols_and_debug_frame": select({ |
| 1690 | "//build/bazel/platforms/arch:arm": True, |
| 1691 | "//conditions:default": None, |
| 1692 | }), |
| 1693 | "keep_symbols_list": select({ |
| 1694 | "//build/bazel/platforms/os:darwin": [ |
| 1695 | "foo", |
| 1696 | "bar", |
| 1697 | ], |
| 1698 | "//conditions:default": [], |
| 1699 | }), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1700 | }`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1701 | }), |
| 1702 | }, |
| 1703 | ) |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1704 | } |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1705 | |
| 1706 | func TestCcLibrary_SystemSharedLibsRootEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1707 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1708 | Description: "cc_library system_shared_libs empty at root", |
| 1709 | ModuleTypeUnderTest: "cc_library", |
| 1710 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1711 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1712 | cc_library { |
| 1713 | name: "root_empty", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1714 | system_shared_libs: [], |
| 1715 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1716 | } |
| 1717 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1718 | ExpectedBazelTargets: makeCcLibraryTargets("root_empty", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1719 | "system_dynamic_deps": `[]`, |
| 1720 | }), |
| 1721 | }, |
| 1722 | ) |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | func TestCcLibrary_SystemSharedLibsStaticEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1726 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1727 | Description: "cc_library system_shared_libs empty for static variant", |
| 1728 | ModuleTypeUnderTest: "cc_library", |
| 1729 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1730 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1731 | cc_library { |
| 1732 | name: "static_empty", |
| 1733 | static: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1734 | system_shared_libs: [], |
| 1735 | }, |
| 1736 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1737 | } |
| 1738 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1739 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1740 | MakeBazelTarget("cc_library_static", "static_empty_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1741 | "system_dynamic_deps": "[]", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1742 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1743 | MakeBazelTarget("cc_library_shared", "static_empty", AttrNameToString{}), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1744 | }, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1745 | }) |
| 1746 | } |
| 1747 | |
| 1748 | func TestCcLibrary_SystemSharedLibsSharedEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1749 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1750 | Description: "cc_library system_shared_libs empty for shared variant", |
| 1751 | ModuleTypeUnderTest: "cc_library", |
| 1752 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1753 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1754 | cc_library { |
| 1755 | name: "shared_empty", |
| 1756 | shared: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1757 | system_shared_libs: [], |
| 1758 | }, |
| 1759 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1760 | } |
| 1761 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1762 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1763 | MakeBazelTarget("cc_library_static", "shared_empty_bp2build_cc_library_static", AttrNameToString{}), |
| 1764 | MakeBazelTarget("cc_library_shared", "shared_empty", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1765 | "system_dynamic_deps": "[]", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1766 | }), |
| 1767 | }, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1768 | }) |
| 1769 | } |
| 1770 | |
| 1771 | func TestCcLibrary_SystemSharedLibsSharedBionicEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1772 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1773 | Description: "cc_library system_shared_libs empty for shared, bionic variant", |
| 1774 | ModuleTypeUnderTest: "cc_library", |
| 1775 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1776 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1777 | cc_library { |
| 1778 | name: "shared_empty", |
| 1779 | target: { |
| 1780 | bionic: { |
| 1781 | shared: { |
| 1782 | system_shared_libs: [], |
| 1783 | } |
| 1784 | } |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1785 | }, |
| 1786 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1787 | } |
| 1788 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1789 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1790 | MakeBazelTarget("cc_library_static", "shared_empty_bp2build_cc_library_static", AttrNameToString{}), |
| 1791 | MakeBazelTarget("cc_library_shared", "shared_empty", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1792 | "system_dynamic_deps": "[]", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1793 | }), |
| 1794 | }, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1795 | }) |
| 1796 | } |
| 1797 | |
| 1798 | func TestCcLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) { |
| 1799 | // Note that this behavior is technically incorrect (it's a simplification). |
| 1800 | // The correct behavior would be if bp2build wrote `system_dynamic_deps = []` |
| 1801 | // only for linux_bionic, but `android` had `["libc", "libdl", "libm"]. |
| 1802 | // b/195791252 tracks the fix. |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1803 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1804 | Description: "cc_library system_shared_libs empty for linux_bionic variant", |
| 1805 | ModuleTypeUnderTest: "cc_library", |
| 1806 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1807 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1808 | cc_library { |
| 1809 | name: "target_linux_bionic_empty", |
| 1810 | target: { |
| 1811 | linux_bionic: { |
| 1812 | system_shared_libs: [], |
| 1813 | }, |
| 1814 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1815 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1816 | } |
| 1817 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1818 | ExpectedBazelTargets: makeCcLibraryTargets("target_linux_bionic_empty", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1819 | "system_dynamic_deps": `[]`, |
| 1820 | }), |
| 1821 | }, |
| 1822 | ) |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | func TestCcLibrary_SystemSharedLibsBionicEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1826 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1827 | Description: "cc_library system_shared_libs empty for bionic variant", |
| 1828 | ModuleTypeUnderTest: "cc_library", |
| 1829 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1830 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1831 | cc_library { |
| 1832 | name: "target_bionic_empty", |
| 1833 | target: { |
| 1834 | bionic: { |
| 1835 | system_shared_libs: [], |
| 1836 | }, |
| 1837 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1838 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1839 | } |
| 1840 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1841 | ExpectedBazelTargets: makeCcLibraryTargets("target_bionic_empty", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1842 | "system_dynamic_deps": `[]`, |
| 1843 | }), |
| 1844 | }, |
| 1845 | ) |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | func TestCcLibrary_SystemSharedLibsSharedAndRoot(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1849 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1850 | Description: "cc_library system_shared_libs set for shared and root", |
| 1851 | ModuleTypeUnderTest: "cc_library", |
| 1852 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1853 | Blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1854 | cc_library { |
| 1855 | name: "libc", |
| 1856 | bazel_module: { bp2build_available: false }, |
| 1857 | } |
| 1858 | cc_library { |
| 1859 | name: "libm", |
| 1860 | bazel_module: { bp2build_available: false }, |
| 1861 | } |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1862 | |
| 1863 | cc_library { |
| 1864 | name: "foo", |
| 1865 | system_shared_libs: ["libc"], |
| 1866 | shared: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1867 | system_shared_libs: ["libm"], |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1868 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1869 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1870 | } |
| 1871 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1872 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1873 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1874 | "system_dynamic_deps": `[":libc"]`, |
| 1875 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1876 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1877 | "system_dynamic_deps": `[ |
| 1878 | ":libc", |
| 1879 | ":libm", |
| 1880 | ]`, |
| 1881 | }), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1882 | }, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1883 | }) |
| 1884 | } |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1885 | |
| 1886 | func TestCcLibraryOsSelects(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1887 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1888 | Description: "cc_library - selects for all os targets", |
| 1889 | ModuleTypeUnderTest: "cc_library", |
| 1890 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1891 | Filesystem: map[string]string{}, |
| 1892 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1893 | cc_library { |
| 1894 | name: "foo-lib", |
| 1895 | srcs: ["base.cpp"], |
| 1896 | target: { |
| 1897 | android: { |
| 1898 | srcs: ["android.cpp"], |
| 1899 | }, |
| 1900 | linux: { |
| 1901 | srcs: ["linux.cpp"], |
| 1902 | }, |
| 1903 | linux_glibc: { |
| 1904 | srcs: ["linux_glibc.cpp"], |
| 1905 | }, |
| 1906 | darwin: { |
| 1907 | srcs: ["darwin.cpp"], |
| 1908 | }, |
| 1909 | bionic: { |
| 1910 | srcs: ["bionic.cpp"], |
| 1911 | }, |
| 1912 | linux_musl: { |
| 1913 | srcs: ["linux_musl.cpp"], |
| 1914 | }, |
| 1915 | windows: { |
| 1916 | srcs: ["windows.cpp"], |
| 1917 | }, |
| 1918 | }, |
| 1919 | include_build_directory: false, |
| 1920 | } |
| 1921 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1922 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1923 | "srcs": `["base.cpp"] + select({ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1924 | "//build/bazel/platforms/os:android": [ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1925 | "linux.cpp", |
Liz Kammer | 9bad9d6 | 2021-10-11 15:40:35 -0400 | [diff] [blame] | 1926 | "bionic.cpp", |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 1927 | "android.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1928 | ], |
| 1929 | "//build/bazel/platforms/os:darwin": ["darwin.cpp"], |
| 1930 | "//build/bazel/platforms/os:linux": [ |
Liz Kammer | 9bad9d6 | 2021-10-11 15:40:35 -0400 | [diff] [blame] | 1931 | "linux.cpp", |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 1932 | "linux_glibc.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1933 | ], |
| 1934 | "//build/bazel/platforms/os:linux_bionic": [ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1935 | "linux.cpp", |
Liz Kammer | 9bad9d6 | 2021-10-11 15:40:35 -0400 | [diff] [blame] | 1936 | "bionic.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1937 | ], |
| 1938 | "//build/bazel/platforms/os:linux_musl": [ |
Liz Kammer | 9bad9d6 | 2021-10-11 15:40:35 -0400 | [diff] [blame] | 1939 | "linux.cpp", |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 1940 | "linux_musl.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1941 | ], |
| 1942 | "//build/bazel/platforms/os:windows": ["windows.cpp"], |
| 1943 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1944 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1945 | }), |
| 1946 | }, |
| 1947 | ) |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1948 | } |
| 1949 | |
Yu Liu | 75be7b9 | 2022-02-01 09:54:09 -0800 | [diff] [blame] | 1950 | func TestLibcryptoHashInjection(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1951 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1952 | Description: "cc_library - libcrypto hash injection", |
| 1953 | ModuleTypeUnderTest: "cc_library", |
| 1954 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1955 | Filesystem: map[string]string{}, |
| 1956 | Blueprint: soongCcLibraryPreamble + ` |
Yu Liu | 75be7b9 | 2022-02-01 09:54:09 -0800 | [diff] [blame] | 1957 | cc_library { |
| 1958 | name: "libcrypto", |
| 1959 | target: { |
| 1960 | android: { |
| 1961 | inject_bssl_hash: true, |
| 1962 | }, |
| 1963 | }, |
| 1964 | include_build_directory: false, |
| 1965 | } |
| 1966 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1967 | ExpectedBazelTargets: makeCcLibraryTargets("libcrypto", AttrNameToString{ |
Yu Liu | 75be7b9 | 2022-02-01 09:54:09 -0800 | [diff] [blame] | 1968 | "inject_bssl_hash": `select({ |
| 1969 | "//build/bazel/platforms/os:android": True, |
| 1970 | "//conditions:default": None, |
| 1971 | })`, |
| 1972 | }), |
| 1973 | }, |
| 1974 | ) |
| 1975 | } |
| 1976 | |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 1977 | func TestCcLibraryCppStdWithGnuExtensions_ConvertsToFeatureAttr(t *testing.T) { |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1978 | type testCase struct { |
| 1979 | cpp_std string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1980 | c_std string |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1981 | gnu_extensions string |
| 1982 | bazel_cpp_std string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 1983 | bazel_c_std string |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | testCases := []testCase{ |
| 1987 | // Existing usages of cpp_std in AOSP are: |
| 1988 | // experimental, c++11, c++17, c++2a, c++98, gnu++11, gnu++17 |
| 1989 | // |
| 1990 | // not set, only emit if gnu_extensions is disabled. the default (gnu+17 |
| 1991 | // is set in the toolchain.) |
| 1992 | {cpp_std: "", gnu_extensions: "", bazel_cpp_std: ""}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 1993 | {cpp_std: "", gnu_extensions: "false", bazel_cpp_std: "cpp_std_default_no_gnu", bazel_c_std: "c_std_default_no_gnu"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1994 | {cpp_std: "", gnu_extensions: "true", bazel_cpp_std: ""}, |
| 1995 | // experimental defaults to gnu++2a |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 1996 | {cpp_std: "experimental", gnu_extensions: "", bazel_cpp_std: "cpp_std_experimental"}, |
| 1997 | {cpp_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "cpp_std_experimental_no_gnu", bazel_c_std: "c_std_default_no_gnu"}, |
| 1998 | {cpp_std: "experimental", gnu_extensions: "true", bazel_cpp_std: "cpp_std_experimental"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 1999 | // Explicitly setting a c++ std does not use replace gnu++ std even if |
| 2000 | // gnu_extensions is true. |
| 2001 | // "c++11", |
| 2002 | {cpp_std: "c++11", gnu_extensions: "", bazel_cpp_std: "c++11"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2003 | {cpp_std: "c++11", gnu_extensions: "false", bazel_cpp_std: "c++11", bazel_c_std: "c_std_default_no_gnu"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2004 | {cpp_std: "c++11", gnu_extensions: "true", bazel_cpp_std: "c++11"}, |
| 2005 | // "c++17", |
| 2006 | {cpp_std: "c++17", gnu_extensions: "", bazel_cpp_std: "c++17"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2007 | {cpp_std: "c++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c_std_default_no_gnu"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2008 | {cpp_std: "c++17", gnu_extensions: "true", bazel_cpp_std: "c++17"}, |
| 2009 | // "c++2a", |
| 2010 | {cpp_std: "c++2a", gnu_extensions: "", bazel_cpp_std: "c++2a"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2011 | {cpp_std: "c++2a", gnu_extensions: "false", bazel_cpp_std: "c++2a", bazel_c_std: "c_std_default_no_gnu"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2012 | {cpp_std: "c++2a", gnu_extensions: "true", bazel_cpp_std: "c++2a"}, |
| 2013 | // "c++98", |
| 2014 | {cpp_std: "c++98", gnu_extensions: "", bazel_cpp_std: "c++98"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2015 | {cpp_std: "c++98", gnu_extensions: "false", bazel_cpp_std: "c++98", bazel_c_std: "c_std_default_no_gnu"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2016 | {cpp_std: "c++98", gnu_extensions: "true", bazel_cpp_std: "c++98"}, |
| 2017 | // gnu++ is replaced with c++ if gnu_extensions is explicitly false. |
| 2018 | // "gnu++11", |
| 2019 | {cpp_std: "gnu++11", gnu_extensions: "", bazel_cpp_std: "gnu++11"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2020 | {cpp_std: "gnu++11", gnu_extensions: "false", bazel_cpp_std: "c++11", bazel_c_std: "c_std_default_no_gnu"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2021 | {cpp_std: "gnu++11", gnu_extensions: "true", bazel_cpp_std: "gnu++11"}, |
| 2022 | // "gnu++17", |
| 2023 | {cpp_std: "gnu++17", gnu_extensions: "", bazel_cpp_std: "gnu++17"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2024 | {cpp_std: "gnu++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c_std_default_no_gnu"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2025 | {cpp_std: "gnu++17", gnu_extensions: "true", bazel_cpp_std: "gnu++17"}, |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2026 | |
| 2027 | // some c_std test cases |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2028 | {c_std: "experimental", gnu_extensions: "", bazel_c_std: "c_std_experimental"}, |
| 2029 | {c_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "cpp_std_default_no_gnu", bazel_c_std: "c_std_experimental_no_gnu"}, |
| 2030 | {c_std: "experimental", gnu_extensions: "true", bazel_c_std: "c_std_experimental"}, |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2031 | {c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "", bazel_cpp_std: "gnu++17", bazel_c_std: "gnu11"}, |
| 2032 | {c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c11"}, |
| 2033 | {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] | 2034 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2035 | for i, tc := range testCases { |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2036 | name := fmt.Sprintf("cpp std: %q, c std: %q, gnu_extensions: %q", tc.cpp_std, tc.c_std, tc.gnu_extensions) |
| 2037 | t.Run(name, func(t *testing.T) { |
| 2038 | name_prefix := fmt.Sprintf("a_%v", i) |
| 2039 | cppStdProp := "" |
| 2040 | if tc.cpp_std != "" { |
| 2041 | cppStdProp = fmt.Sprintf(" cpp_std: \"%s\",", tc.cpp_std) |
| 2042 | } |
| 2043 | cStdProp := "" |
| 2044 | if tc.c_std != "" { |
| 2045 | cStdProp = fmt.Sprintf(" c_std: \"%s\",", tc.c_std) |
| 2046 | } |
| 2047 | gnuExtensionsProp := "" |
| 2048 | if tc.gnu_extensions != "" { |
| 2049 | gnuExtensionsProp = fmt.Sprintf(" gnu_extensions: %s,", tc.gnu_extensions) |
| 2050 | } |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2051 | attrs := AttrNameToString{} |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2052 | if tc.bazel_cpp_std != "" { |
| 2053 | attrs["cpp_std"] = fmt.Sprintf(`"%s"`, tc.bazel_cpp_std) |
| 2054 | } |
| 2055 | if tc.bazel_c_std != "" { |
| 2056 | attrs["c_std"] = fmt.Sprintf(`"%s"`, tc.bazel_c_std) |
| 2057 | } |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2058 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2059 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2060 | Description: fmt.Sprintf( |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2061 | "cc_library with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2062 | ModuleTypeUnderTest: "cc_library", |
| 2063 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2064 | Blueprint: soongCcLibraryPreamble + fmt.Sprintf(` |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2065 | cc_library { |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2066 | name: "%s_full", |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2067 | %s // cpp_std: *string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2068 | %s // c_std: *string |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2069 | %s // gnu_extensions: *bool |
| 2070 | include_build_directory: false, |
| 2071 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2072 | `, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2073 | ExpectedBazelTargets: makeCcLibraryTargets(name_prefix+"_full", attrs), |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2074 | }) |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2075 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2076 | runCcLibraryStaticTestCase(t, Bp2buildTestCase{ |
| 2077 | Description: fmt.Sprintf( |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2078 | "cc_library_static with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2079 | ModuleTypeUnderTest: "cc_library_static", |
| 2080 | ModuleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 2081 | Blueprint: soongCcLibraryPreamble + fmt.Sprintf(` |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2082 | cc_library_static { |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2083 | name: "%s_static", |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2084 | %s // cpp_std: *string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2085 | %s // c_std: *string |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2086 | %s // gnu_extensions: *bool |
| 2087 | include_build_directory: false, |
| 2088 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2089 | `, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2090 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2091 | MakeBazelTarget("cc_library_static", name_prefix+"_static", attrs), |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2092 | }, |
| 2093 | }) |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2094 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2095 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 2096 | Description: fmt.Sprintf( |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2097 | "cc_library_shared with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2098 | ModuleTypeUnderTest: "cc_library_shared", |
| 2099 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 2100 | Blueprint: soongCcLibraryPreamble + fmt.Sprintf(` |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2101 | cc_library_shared { |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2102 | name: "%s_shared", |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2103 | %s // cpp_std: *string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2104 | %s // c_std: *string |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2105 | %s // gnu_extensions: *bool |
| 2106 | include_build_directory: false, |
| 2107 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2108 | `, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2109 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2110 | MakeBazelTarget("cc_library_shared", name_prefix+"_shared", attrs), |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2111 | }, |
| 2112 | }) |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2113 | }) |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2114 | } |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 2115 | } |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2116 | |
| 2117 | func TestCcLibraryProtoSimple(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2118 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2119 | ModuleTypeUnderTest: "cc_library", |
| 2120 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2121 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2122 | name: "foo", |
| 2123 | srcs: ["foo.proto"], |
| 2124 | include_build_directory: false, |
| 2125 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2126 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2127 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 7756c8f | 2022-02-14 20:49:15 -0500 | [diff] [blame] | 2128 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2129 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2130 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2131 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2132 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2133 | "deps": `[":libprotobuf-cpp-lite"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2134 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2135 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2136 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2137 | }), |
| 2138 | }, |
| 2139 | }) |
| 2140 | } |
| 2141 | |
| 2142 | func TestCcLibraryProtoNoCanonicalPathFromRoot(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2143 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2144 | ModuleTypeUnderTest: "cc_library", |
| 2145 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2146 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2147 | name: "foo", |
| 2148 | srcs: ["foo.proto"], |
| 2149 | proto: { canonical_path_from_root: false}, |
| 2150 | include_build_directory: false, |
| 2151 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2152 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2153 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 7756c8f | 2022-02-14 20:49:15 -0500 | [diff] [blame] | 2154 | "srcs": `["foo.proto"]`, |
| 2155 | "strip_import_prefix": `""`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2156 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2157 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2158 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2159 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2160 | "deps": `[":libprotobuf-cpp-lite"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2161 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2162 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2163 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2164 | }), |
| 2165 | }, |
| 2166 | }) |
| 2167 | } |
| 2168 | |
| 2169 | func TestCcLibraryProtoExplicitCanonicalPathFromRoot(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2170 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2171 | ModuleTypeUnderTest: "cc_library", |
| 2172 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2173 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2174 | name: "foo", |
| 2175 | srcs: ["foo.proto"], |
| 2176 | proto: { canonical_path_from_root: true}, |
| 2177 | include_build_directory: false, |
| 2178 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2179 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2180 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 7756c8f | 2022-02-14 20:49:15 -0500 | [diff] [blame] | 2181 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2182 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2183 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2184 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2185 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2186 | "deps": `[":libprotobuf-cpp-lite"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2187 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2188 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2189 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2190 | }), |
| 2191 | }, |
| 2192 | }) |
| 2193 | } |
| 2194 | |
| 2195 | func TestCcLibraryProtoFull(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2196 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2197 | ModuleTypeUnderTest: "cc_library", |
| 2198 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2199 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2200 | name: "foo", |
| 2201 | srcs: ["foo.proto"], |
| 2202 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2203 | type: "full", |
| 2204 | }, |
| 2205 | include_build_directory: false, |
| 2206 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2207 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2208 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2209 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2210 | }), MakeBazelTarget("cc_proto_library", "foo_cc_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2211 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2212 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2213 | "implementation_whole_archive_deps": `[":foo_cc_proto"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2214 | "deps": `[":libprotobuf-cpp-full"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2215 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2216 | "dynamic_deps": `[":libprotobuf-cpp-full"]`, |
| 2217 | "implementation_whole_archive_deps": `[":foo_cc_proto"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2218 | }), |
| 2219 | }, |
| 2220 | }) |
| 2221 | } |
| 2222 | |
| 2223 | func TestCcLibraryProtoLite(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2224 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2225 | ModuleTypeUnderTest: "cc_library", |
| 2226 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2227 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2228 | name: "foo", |
| 2229 | srcs: ["foo.proto"], |
| 2230 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2231 | type: "lite", |
| 2232 | }, |
| 2233 | include_build_directory: false, |
| 2234 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2235 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2236 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2237 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2238 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2239 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2240 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2241 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2242 | "deps": `[":libprotobuf-cpp-lite"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2243 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2244 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2245 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2246 | }), |
| 2247 | }, |
| 2248 | }) |
| 2249 | } |
| 2250 | |
| 2251 | func TestCcLibraryProtoExportHeaders(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2252 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2253 | ModuleTypeUnderTest: "cc_library", |
| 2254 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2255 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2256 | name: "foo", |
| 2257 | srcs: ["foo.proto"], |
| 2258 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2259 | export_proto_headers: true, |
| 2260 | }, |
| 2261 | include_build_directory: false, |
| 2262 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2263 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2264 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2265 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2266 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2267 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2268 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2269 | "deps": `[":libprotobuf-cpp-lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2270 | "whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2271 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2272 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2273 | "whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2274 | }), |
| 2275 | }, |
| 2276 | }) |
| 2277 | } |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2278 | |
Yu Liu | 2d13614 | 2022-08-18 14:46:13 -0700 | [diff] [blame] | 2279 | func TestCcLibraryProtoIncludeDirs(t *testing.T) { |
| 2280 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2281 | ModuleTypeUnderTest: "cc_library", |
| 2282 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2283 | Blueprint: soongCcProtoPreamble + `cc_library { |
| 2284 | name: "foo", |
| 2285 | srcs: ["foo.proto"], |
| 2286 | proto: { |
| 2287 | include_dirs: ["external/protobuf/src"], |
| 2288 | }, |
| 2289 | include_build_directory: false, |
| 2290 | }`, |
| 2291 | ExpectedBazelTargets: []string{ |
| 2292 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
| 2293 | "srcs": `["foo.proto"]`, |
| 2294 | "deps": `["//external/protobuf:libprotobuf-proto"]`, |
| 2295 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
| 2296 | "deps": `[":foo_proto"]`, |
| 2297 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 2298 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2299 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
| 2300 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2301 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2302 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Yu Liu | 2d13614 | 2022-08-18 14:46:13 -0700 | [diff] [blame] | 2303 | }), |
| 2304 | }, |
| 2305 | }) |
| 2306 | } |
| 2307 | |
| 2308 | func TestCcLibraryProtoIncludeDirsUnknown(t *testing.T) { |
| 2309 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2310 | ModuleTypeUnderTest: "cc_library", |
| 2311 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2312 | Blueprint: soongCcProtoPreamble + `cc_library { |
| 2313 | name: "foo", |
| 2314 | srcs: ["foo.proto"], |
| 2315 | proto: { |
| 2316 | include_dirs: ["external/protobuf/abc"], |
| 2317 | }, |
| 2318 | include_build_directory: false, |
| 2319 | }`, |
| 2320 | ExpectedErr: fmt.Errorf("module \"foo\": Could not find the proto_library target for include dir: external/protobuf/abc"), |
| 2321 | }) |
| 2322 | } |
| 2323 | |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 2324 | func TestCcLibraryConvertedProtoFilegroups(t *testing.T) { |
| 2325 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2326 | ModuleTypeUnderTest: "cc_library", |
| 2327 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2328 | Blueprint: soongCcProtoPreamble + ` |
| 2329 | filegroup { |
| 2330 | name: "a_fg_proto", |
| 2331 | srcs: ["a_fg.proto"], |
| 2332 | } |
| 2333 | |
| 2334 | cc_library { |
| 2335 | name: "a", |
| 2336 | srcs: [ |
| 2337 | ":a_fg_proto", |
| 2338 | "a.proto", |
| 2339 | ], |
| 2340 | proto: { |
| 2341 | export_proto_headers: true, |
| 2342 | }, |
| 2343 | include_build_directory: false, |
| 2344 | }`, |
| 2345 | ExpectedBazelTargets: []string{ |
| 2346 | MakeBazelTarget("proto_library", "a_proto", AttrNameToString{ |
Yu Liu | 2a85fb1 | 2022-09-15 22:18:48 -0700 | [diff] [blame] | 2347 | "deps": `[":a_fg_proto_bp2build_converted"]`, |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 2348 | "srcs": `["a.proto"]`, |
| 2349 | }), MakeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{ |
| 2350 | "deps": `[ |
| 2351 | ":a_fg_proto_bp2build_converted", |
| 2352 | ":a_proto", |
| 2353 | ]`, |
| 2354 | }), MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
| 2355 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2356 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2357 | }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
| 2358 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2359 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2360 | }), MakeBazelTargetNoRestrictions("proto_library", "a_fg_proto_bp2build_converted", AttrNameToString{ |
| 2361 | "srcs": `["a_fg.proto"]`, |
Yu Liu | 2a85fb1 | 2022-09-15 22:18:48 -0700 | [diff] [blame] | 2362 | "tags": `["manual"]`, |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 2363 | }), MakeBazelTargetNoRestrictions("filegroup", "a_fg_proto", AttrNameToString{ |
| 2364 | "srcs": `["a_fg.proto"]`, |
| 2365 | }), |
| 2366 | }, |
| 2367 | }) |
| 2368 | } |
| 2369 | |
| 2370 | func TestCcLibraryConvertedProtoFilegroupsNoProtoFiles(t *testing.T) { |
| 2371 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2372 | ModuleTypeUnderTest: "cc_library", |
| 2373 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2374 | Blueprint: soongCcProtoPreamble + ` |
| 2375 | filegroup { |
| 2376 | name: "a_fg_proto", |
| 2377 | srcs: ["a_fg.proto"], |
| 2378 | } |
| 2379 | |
| 2380 | cc_library { |
| 2381 | name: "a", |
| 2382 | srcs: [ |
| 2383 | ":a_fg_proto", |
| 2384 | ], |
| 2385 | proto: { |
| 2386 | export_proto_headers: true, |
| 2387 | }, |
| 2388 | include_build_directory: false, |
| 2389 | }`, |
| 2390 | ExpectedBazelTargets: []string{ |
| 2391 | MakeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{ |
| 2392 | "deps": `[":a_fg_proto_bp2build_converted"]`, |
| 2393 | }), MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
| 2394 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2395 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2396 | }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
| 2397 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2398 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2399 | }), MakeBazelTargetNoRestrictions("proto_library", "a_fg_proto_bp2build_converted", AttrNameToString{ |
| 2400 | "srcs": `["a_fg.proto"]`, |
Yu Liu | 2a85fb1 | 2022-09-15 22:18:48 -0700 | [diff] [blame] | 2401 | "tags": `["manual"]`, |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 2402 | }), MakeBazelTargetNoRestrictions("filegroup", "a_fg_proto", AttrNameToString{ |
| 2403 | "srcs": `["a_fg.proto"]`, |
| 2404 | }), |
| 2405 | }, |
| 2406 | }) |
| 2407 | } |
| 2408 | |
| 2409 | func TestCcLibraryExternalConvertedProtoFilegroups(t *testing.T) { |
| 2410 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2411 | ModuleTypeUnderTest: "cc_library", |
| 2412 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2413 | Filesystem: map[string]string{ |
| 2414 | "path/to/A/Android.bp": ` |
| 2415 | filegroup { |
| 2416 | name: "a_fg_proto", |
| 2417 | srcs: ["a_fg.proto"], |
| 2418 | }`, |
| 2419 | }, |
| 2420 | Blueprint: soongCcProtoPreamble + ` |
| 2421 | cc_library { |
| 2422 | name: "a", |
| 2423 | srcs: [ |
| 2424 | ":a_fg_proto", |
| 2425 | "a.proto", |
| 2426 | ], |
| 2427 | proto: { |
| 2428 | export_proto_headers: true, |
| 2429 | }, |
| 2430 | include_build_directory: false, |
| 2431 | }`, |
| 2432 | ExpectedBazelTargets: []string{ |
| 2433 | MakeBazelTarget("proto_library", "a_proto", AttrNameToString{ |
Yu Liu | 2a85fb1 | 2022-09-15 22:18:48 -0700 | [diff] [blame] | 2434 | "deps": `["//path/to/A:a_fg_proto_bp2build_converted"]`, |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 2435 | "srcs": `["a.proto"]`, |
| 2436 | }), MakeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{ |
| 2437 | "deps": `[ |
| 2438 | "//path/to/A:a_fg_proto_bp2build_converted", |
| 2439 | ":a_proto", |
| 2440 | ]`, |
| 2441 | }), MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
| 2442 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2443 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2444 | }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
| 2445 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2446 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2447 | }), |
| 2448 | }, |
| 2449 | }) |
| 2450 | } |
| 2451 | |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2452 | func TestCcLibraryProtoFilegroups(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2453 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2454 | ModuleTypeUnderTest: "cc_library", |
| 2455 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2456 | Blueprint: soongCcProtoPreamble + |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2457 | simpleModuleDoNotConvertBp2build("filegroup", "a_fg_proto") + |
| 2458 | simpleModuleDoNotConvertBp2build("filegroup", "b_protos") + |
| 2459 | simpleModuleDoNotConvertBp2build("filegroup", "c-proto-srcs") + |
| 2460 | simpleModuleDoNotConvertBp2build("filegroup", "proto-srcs-d") + ` |
| 2461 | cc_library { |
| 2462 | name: "a", |
| 2463 | srcs: [":a_fg_proto"], |
| 2464 | proto: { |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2465 | export_proto_headers: true, |
| 2466 | }, |
| 2467 | include_build_directory: false, |
| 2468 | } |
| 2469 | |
| 2470 | cc_library { |
| 2471 | name: "b", |
| 2472 | srcs: [":b_protos"], |
| 2473 | proto: { |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2474 | export_proto_headers: true, |
| 2475 | }, |
| 2476 | include_build_directory: false, |
| 2477 | } |
| 2478 | |
| 2479 | cc_library { |
| 2480 | name: "c", |
| 2481 | srcs: [":c-proto-srcs"], |
| 2482 | proto: { |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2483 | export_proto_headers: true, |
| 2484 | }, |
| 2485 | include_build_directory: false, |
| 2486 | } |
| 2487 | |
| 2488 | cc_library { |
| 2489 | name: "d", |
| 2490 | srcs: [":proto-srcs-d"], |
| 2491 | proto: { |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2492 | export_proto_headers: true, |
| 2493 | }, |
| 2494 | include_build_directory: false, |
| 2495 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2496 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2497 | MakeBazelTarget("proto_library", "a_proto", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2498 | "srcs": `[":a_fg_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2499 | }), MakeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2500 | "deps": `[":a_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2501 | }), MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2502 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2503 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2504 | "srcs": `[":a_fg_proto_cpp_srcs"]`, |
| 2505 | "srcs_as": `[":a_fg_proto_as_srcs"]`, |
| 2506 | "srcs_c": `[":a_fg_proto_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2507 | }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2508 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2509 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2510 | "srcs": `[":a_fg_proto_cpp_srcs"]`, |
| 2511 | "srcs_as": `[":a_fg_proto_as_srcs"]`, |
| 2512 | "srcs_c": `[":a_fg_proto_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2513 | }), MakeBazelTarget("proto_library", "b_proto", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2514 | "srcs": `[":b_protos"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2515 | }), MakeBazelTarget("cc_lite_proto_library", "b_cc_proto_lite", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2516 | "deps": `[":b_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2517 | }), MakeBazelTarget("cc_library_static", "b_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2518 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2519 | "whole_archive_deps": `[":b_cc_proto_lite"]`, |
| 2520 | "srcs": `[":b_protos_cpp_srcs"]`, |
| 2521 | "srcs_as": `[":b_protos_as_srcs"]`, |
| 2522 | "srcs_c": `[":b_protos_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2523 | }), MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2524 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2525 | "whole_archive_deps": `[":b_cc_proto_lite"]`, |
| 2526 | "srcs": `[":b_protos_cpp_srcs"]`, |
| 2527 | "srcs_as": `[":b_protos_as_srcs"]`, |
| 2528 | "srcs_c": `[":b_protos_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2529 | }), MakeBazelTarget("proto_library", "c_proto", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2530 | "srcs": `[":c-proto-srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2531 | }), MakeBazelTarget("cc_lite_proto_library", "c_cc_proto_lite", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2532 | "deps": `[":c_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2533 | }), MakeBazelTarget("cc_library_static", "c_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2534 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2535 | "whole_archive_deps": `[":c_cc_proto_lite"]`, |
| 2536 | "srcs": `[":c-proto-srcs_cpp_srcs"]`, |
| 2537 | "srcs_as": `[":c-proto-srcs_as_srcs"]`, |
| 2538 | "srcs_c": `[":c-proto-srcs_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2539 | }), MakeBazelTarget("cc_library_shared", "c", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2540 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2541 | "whole_archive_deps": `[":c_cc_proto_lite"]`, |
| 2542 | "srcs": `[":c-proto-srcs_cpp_srcs"]`, |
| 2543 | "srcs_as": `[":c-proto-srcs_as_srcs"]`, |
| 2544 | "srcs_c": `[":c-proto-srcs_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2545 | }), MakeBazelTarget("proto_library", "d_proto", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2546 | "srcs": `[":proto-srcs-d"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2547 | }), MakeBazelTarget("cc_lite_proto_library", "d_cc_proto_lite", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2548 | "deps": `[":d_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2549 | }), MakeBazelTarget("cc_library_static", "d_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2550 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2551 | "whole_archive_deps": `[":d_cc_proto_lite"]`, |
| 2552 | "srcs": `[":proto-srcs-d_cpp_srcs"]`, |
| 2553 | "srcs_as": `[":proto-srcs-d_as_srcs"]`, |
| 2554 | "srcs_c": `[":proto-srcs-d_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2555 | }), MakeBazelTarget("cc_library_shared", "d", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2556 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2557 | "whole_archive_deps": `[":d_cc_proto_lite"]`, |
| 2558 | "srcs": `[":proto-srcs-d_cpp_srcs"]`, |
| 2559 | "srcs_as": `[":proto-srcs-d_as_srcs"]`, |
| 2560 | "srcs_c": `[":proto-srcs-d_c_srcs"]`, |
| 2561 | }), |
| 2562 | }, |
| 2563 | }) |
| 2564 | } |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2565 | |
| 2566 | func TestCcLibraryDisabledArchAndTarget(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2567 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2568 | ModuleTypeUnderTest: "cc_library", |
| 2569 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2570 | Blueprint: soongCcProtoPreamble + `cc_library { |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2571 | name: "foo", |
| 2572 | srcs: ["foo.cpp"], |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 2573 | host_supported: true, |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2574 | target: { |
| 2575 | darwin: { |
| 2576 | enabled: false, |
| 2577 | }, |
| 2578 | windows: { |
| 2579 | enabled: false, |
| 2580 | }, |
| 2581 | linux_glibc_x86: { |
| 2582 | enabled: false, |
| 2583 | }, |
| 2584 | }, |
| 2585 | include_build_directory: false, |
| 2586 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2587 | ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2588 | "srcs": `["foo.cpp"]`, |
| 2589 | "target_compatible_with": `select({ |
| 2590 | "//build/bazel/platforms/os_arch:darwin_arm64": ["@platforms//:incompatible"], |
| 2591 | "//build/bazel/platforms/os_arch:darwin_x86_64": ["@platforms//:incompatible"], |
| 2592 | "//build/bazel/platforms/os_arch:linux_glibc_x86": ["@platforms//:incompatible"], |
| 2593 | "//build/bazel/platforms/os_arch:windows_x86": ["@platforms//:incompatible"], |
| 2594 | "//build/bazel/platforms/os_arch:windows_x86_64": ["@platforms//:incompatible"], |
| 2595 | "//conditions:default": [], |
| 2596 | })`, |
| 2597 | }), |
| 2598 | }) |
| 2599 | } |
| 2600 | |
| 2601 | func TestCcLibraryDisabledArchAndTargetWithDefault(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2602 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2603 | ModuleTypeUnderTest: "cc_library", |
| 2604 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2605 | Blueprint: soongCcProtoPreamble + `cc_library { |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2606 | name: "foo", |
| 2607 | srcs: ["foo.cpp"], |
| 2608 | enabled: false, |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 2609 | host_supported: true, |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2610 | target: { |
| 2611 | darwin: { |
| 2612 | enabled: true, |
| 2613 | }, |
| 2614 | windows: { |
| 2615 | enabled: false, |
| 2616 | }, |
| 2617 | linux_glibc_x86: { |
| 2618 | enabled: false, |
| 2619 | }, |
| 2620 | }, |
| 2621 | include_build_directory: false, |
| 2622 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2623 | ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2624 | "srcs": `["foo.cpp"]`, |
| 2625 | "target_compatible_with": `select({ |
| 2626 | "//build/bazel/platforms/os_arch:darwin_arm64": [], |
| 2627 | "//build/bazel/platforms/os_arch:darwin_x86_64": [], |
| 2628 | "//conditions:default": ["@platforms//:incompatible"], |
| 2629 | })`, |
| 2630 | }), |
| 2631 | }) |
| 2632 | } |
| 2633 | |
| 2634 | func TestCcLibrarySharedDisabled(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2635 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2636 | ModuleTypeUnderTest: "cc_library", |
| 2637 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2638 | Blueprint: soongCcProtoPreamble + `cc_library { |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2639 | name: "foo", |
| 2640 | srcs: ["foo.cpp"], |
| 2641 | enabled: false, |
| 2642 | shared: { |
| 2643 | enabled: true, |
| 2644 | }, |
| 2645 | target: { |
| 2646 | android: { |
| 2647 | shared: { |
| 2648 | enabled: false, |
| 2649 | }, |
| 2650 | } |
| 2651 | }, |
| 2652 | include_build_directory: false, |
| 2653 | }`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2654 | ExpectedBazelTargets: []string{MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2655 | "srcs": `["foo.cpp"]`, |
| 2656 | "target_compatible_with": `["@platforms//:incompatible"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2657 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2658 | "srcs": `["foo.cpp"]`, |
| 2659 | "target_compatible_with": `select({ |
| 2660 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 2661 | "//conditions:default": [], |
| 2662 | })`, |
| 2663 | }), |
| 2664 | }, |
| 2665 | }) |
| 2666 | } |
| 2667 | |
| 2668 | func TestCcLibraryStaticDisabledForSomeArch(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2669 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2670 | ModuleTypeUnderTest: "cc_library", |
| 2671 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2672 | Blueprint: soongCcProtoPreamble + `cc_library { |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2673 | name: "foo", |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 2674 | host_supported: true, |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2675 | srcs: ["foo.cpp"], |
| 2676 | shared: { |
| 2677 | enabled: false |
| 2678 | }, |
| 2679 | target: { |
| 2680 | darwin: { |
| 2681 | enabled: true, |
| 2682 | }, |
| 2683 | windows: { |
| 2684 | enabled: false, |
| 2685 | }, |
| 2686 | linux_glibc_x86: { |
| 2687 | shared: { |
| 2688 | enabled: true, |
| 2689 | }, |
| 2690 | }, |
| 2691 | }, |
| 2692 | include_build_directory: false, |
| 2693 | }`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2694 | ExpectedBazelTargets: []string{MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2695 | "srcs": `["foo.cpp"]`, |
| 2696 | "target_compatible_with": `select({ |
| 2697 | "//build/bazel/platforms/os:windows": ["@platforms//:incompatible"], |
| 2698 | "//conditions:default": [], |
| 2699 | })`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2700 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2701 | "srcs": `["foo.cpp"]`, |
| 2702 | "target_compatible_with": `select({ |
| 2703 | "//build/bazel/platforms/os_arch:darwin_arm64": [], |
| 2704 | "//build/bazel/platforms/os_arch:darwin_x86_64": [], |
| 2705 | "//build/bazel/platforms/os_arch:linux_glibc_x86": [], |
| 2706 | "//conditions:default": ["@platforms//:incompatible"], |
| 2707 | })`, |
| 2708 | }), |
| 2709 | }}) |
| 2710 | } |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 2711 | |
| 2712 | func TestCcLibraryStubs(t *testing.T) { |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 2713 | expectedBazelTargets := makeCcLibraryTargets("a", AttrNameToString{ |
Yu Liu | 56ccb1a | 2022-11-12 10:47:07 -0800 | [diff] [blame^] | 2714 | "has_stubs": `True`, |
| 2715 | "stubs_symbol_file": `"a.map.txt"`, |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 2716 | }) |
| 2717 | expectedBazelTargets = append(expectedBazelTargets, makeCcStubSuiteTargets("a", AttrNameToString{ |
| 2718 | "soname": `"a.so"`, |
| 2719 | "source_library": `":a"`, |
| 2720 | "stubs_symbol_file": `"a.map.txt"`, |
| 2721 | "stubs_versions": `[ |
| 2722 | "28", |
| 2723 | "29", |
| 2724 | "current", |
| 2725 | ]`, |
| 2726 | })) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2727 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2728 | Description: "cc_library stubs", |
| 2729 | ModuleTypeUnderTest: "cc_library", |
| 2730 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2731 | Dir: "foo/bar", |
| 2732 | Filesystem: map[string]string{ |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 2733 | "foo/bar/Android.bp": ` |
| 2734 | cc_library { |
| 2735 | name: "a", |
| 2736 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 2737 | bazel_module: { bp2build_available: true }, |
| 2738 | include_build_directory: false, |
| 2739 | } |
| 2740 | `, |
| 2741 | }, |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 2742 | Blueprint: soongCcLibraryPreamble, |
| 2743 | ExpectedBazelTargets: expectedBazelTargets, |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 2744 | }, |
| 2745 | ) |
| 2746 | } |
Liz Kammer | f38a837 | 2022-02-04 15:39:00 -0500 | [diff] [blame] | 2747 | |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2748 | func TestCcApiContributionsWithHdrs(t *testing.T) { |
| 2749 | bp := ` |
| 2750 | cc_library { |
| 2751 | name: "libfoo", |
| 2752 | stubs: { symbol_file: "libfoo.map.txt", versions: ["28", "29", "current"] }, |
| 2753 | llndk: { symbol_file: "libfoo.map.txt", override_export_include_dirs: ["dir2"]}, |
| 2754 | export_include_dirs: ["dir1"], |
| 2755 | } |
| 2756 | ` |
| 2757 | expectedBazelTargets := []string{ |
| 2758 | MakeBazelTarget( |
| 2759 | "cc_api_library_headers", |
| 2760 | "libfoo.systemapi.headers", |
| 2761 | AttrNameToString{ |
| 2762 | "export_includes": `["dir1"]`, |
| 2763 | }), |
| 2764 | MakeBazelTarget( |
| 2765 | "cc_api_library_headers", |
| 2766 | "libfoo.vendorapi.headers", |
| 2767 | AttrNameToString{ |
| 2768 | "export_includes": `["dir2"]`, |
| 2769 | }), |
| 2770 | MakeBazelTarget( |
| 2771 | "cc_api_contribution", |
| 2772 | "libfoo.contribution", |
| 2773 | AttrNameToString{ |
| 2774 | "api": `"libfoo.map.txt"`, |
| 2775 | "library_name": `"libfoo"`, |
| 2776 | "api_surfaces": `[ |
| 2777 | "systemapi", |
| 2778 | "vendorapi", |
| 2779 | ]`, |
| 2780 | "hdrs": `[ |
| 2781 | ":libfoo.systemapi.headers", |
| 2782 | ":libfoo.vendorapi.headers", |
| 2783 | ]`, |
| 2784 | }), |
| 2785 | } |
| 2786 | RunApiBp2BuildTestCase(t, cc.RegisterLibraryBuildComponents, Bp2buildTestCase{ |
| 2787 | Blueprint: bp, |
| 2788 | Description: "cc API contributions to systemapi and vendorapi", |
| 2789 | ExpectedBazelTargets: expectedBazelTargets, |
| 2790 | }) |
| 2791 | } |
| 2792 | |
| 2793 | func TestCcApiSurfaceCombinations(t *testing.T) { |
| 2794 | testCases := []struct { |
| 2795 | bp string |
| 2796 | expectedApi string |
| 2797 | expectedApiSurfaces string |
| 2798 | description string |
| 2799 | }{ |
| 2800 | { |
| 2801 | bp: ` |
| 2802 | cc_library { |
| 2803 | name: "a", |
| 2804 | stubs: {symbol_file: "a.map.txt"}, |
| 2805 | }`, |
| 2806 | expectedApi: `"a.map.txt"`, |
| 2807 | expectedApiSurfaces: `["systemapi"]`, |
| 2808 | description: "Library that contributes to systemapi", |
| 2809 | }, |
| 2810 | { |
| 2811 | bp: ` |
| 2812 | cc_library { |
| 2813 | name: "a", |
| 2814 | llndk: {symbol_file: "a.map.txt"}, |
| 2815 | }`, |
| 2816 | expectedApi: `"a.map.txt"`, |
| 2817 | expectedApiSurfaces: `["vendorapi"]`, |
| 2818 | description: "Library that contributes to vendorapi", |
| 2819 | }, |
| 2820 | { |
| 2821 | bp: ` |
| 2822 | cc_library { |
| 2823 | name: "a", |
| 2824 | llndk: {symbol_file: "a.map.txt"}, |
| 2825 | stubs: {symbol_file: "a.map.txt"}, |
| 2826 | }`, |
| 2827 | expectedApi: `"a.map.txt"`, |
| 2828 | expectedApiSurfaces: `[ |
| 2829 | "systemapi", |
| 2830 | "vendorapi", |
| 2831 | ]`, |
| 2832 | description: "Library that contributes to systemapi and vendorapi", |
| 2833 | }, |
| 2834 | } |
| 2835 | for _, testCase := range testCases { |
| 2836 | expectedBazelTargets := []string{ |
| 2837 | MakeBazelTarget( |
| 2838 | "cc_api_contribution", |
| 2839 | "a.contribution", |
| 2840 | AttrNameToString{ |
| 2841 | "library_name": `"a"`, |
| 2842 | "hdrs": `[]`, |
| 2843 | "api": testCase.expectedApi, |
| 2844 | "api_surfaces": testCase.expectedApiSurfaces, |
| 2845 | }, |
| 2846 | ), |
| 2847 | } |
| 2848 | RunApiBp2BuildTestCase(t, cc.RegisterLibraryBuildComponents, Bp2buildTestCase{ |
| 2849 | Blueprint: testCase.bp, |
| 2850 | Description: testCase.description, |
| 2851 | ExpectedBazelTargets: expectedBazelTargets, |
| 2852 | }) |
| 2853 | } |
| 2854 | } |
| 2855 | |
| 2856 | // llndk struct property in Soong provides users with several options to configure the exported include dirs |
| 2857 | // Test the generated bazel targets for the different configurations |
| 2858 | func TestCcVendorApiHeaders(t *testing.T) { |
| 2859 | testCases := []struct { |
| 2860 | bp string |
| 2861 | expectedIncludes string |
| 2862 | expectedSystemIncludes string |
| 2863 | description string |
| 2864 | }{ |
| 2865 | { |
| 2866 | bp: ` |
| 2867 | cc_library { |
| 2868 | name: "a", |
| 2869 | export_include_dirs: ["include"], |
| 2870 | export_system_include_dirs: ["base_system_include"], |
| 2871 | llndk: { |
| 2872 | symbol_file: "a.map.txt", |
| 2873 | export_headers_as_system: true, |
| 2874 | }, |
| 2875 | } |
| 2876 | `, |
| 2877 | expectedIncludes: "", |
| 2878 | expectedSystemIncludes: `[ |
| 2879 | "base_system_include", |
| 2880 | "include", |
| 2881 | ]`, |
| 2882 | description: "Headers are exported as system to API surface", |
| 2883 | }, |
| 2884 | { |
| 2885 | bp: ` |
| 2886 | cc_library { |
| 2887 | name: "a", |
| 2888 | export_include_dirs: ["include"], |
| 2889 | export_system_include_dirs: ["base_system_include"], |
| 2890 | llndk: { |
| 2891 | symbol_file: "a.map.txt", |
| 2892 | override_export_include_dirs: ["llndk_include"], |
| 2893 | }, |
| 2894 | } |
| 2895 | `, |
| 2896 | expectedIncludes: `["llndk_include"]`, |
| 2897 | expectedSystemIncludes: `["base_system_include"]`, |
| 2898 | description: "Non-system Headers are ovverriden before export to API surface", |
| 2899 | }, |
| 2900 | { |
| 2901 | bp: ` |
| 2902 | cc_library { |
| 2903 | name: "a", |
| 2904 | export_include_dirs: ["include"], |
| 2905 | export_system_include_dirs: ["base_system_include"], |
| 2906 | llndk: { |
| 2907 | symbol_file: "a.map.txt", |
| 2908 | override_export_include_dirs: ["llndk_include"], |
| 2909 | export_headers_as_system: true, |
| 2910 | }, |
| 2911 | } |
| 2912 | `, |
| 2913 | expectedIncludes: "", // includes are set to nil |
| 2914 | expectedSystemIncludes: `[ |
| 2915 | "base_system_include", |
| 2916 | "llndk_include", |
| 2917 | ]`, |
| 2918 | description: "System Headers are extended before export to API surface", |
| 2919 | }, |
| 2920 | } |
| 2921 | for _, testCase := range testCases { |
| 2922 | attrs := AttrNameToString{} |
| 2923 | if testCase.expectedIncludes != "" { |
| 2924 | attrs["export_includes"] = testCase.expectedIncludes |
| 2925 | } |
| 2926 | if testCase.expectedSystemIncludes != "" { |
| 2927 | attrs["export_system_includes"] = testCase.expectedSystemIncludes |
| 2928 | } |
| 2929 | |
| 2930 | expectedBazelTargets := []string{ |
| 2931 | MakeBazelTarget("cc_api_library_headers", "a.vendorapi.headers", attrs), |
| 2932 | // Create a target for cc_api_contribution target |
| 2933 | MakeBazelTarget("cc_api_contribution", "a.contribution", AttrNameToString{ |
| 2934 | "api": `"a.map.txt"`, |
| 2935 | "api_surfaces": `["vendorapi"]`, |
| 2936 | "hdrs": `[":a.vendorapi.headers"]`, |
| 2937 | "library_name": `"a"`, |
| 2938 | }), |
| 2939 | } |
| 2940 | RunApiBp2BuildTestCase(t, cc.RegisterLibraryBuildComponents, Bp2buildTestCase{ |
| 2941 | Blueprint: testCase.bp, |
| 2942 | ExpectedBazelTargets: expectedBazelTargets, |
| 2943 | }) |
| 2944 | } |
| 2945 | } |
| 2946 | |
Trevor Radcliffe | 0ed6b7d | 2022-09-12 20:19:26 +0000 | [diff] [blame] | 2947 | func TestCcLibraryStubsAcrossConfigsDuplicatesRemoved(t *testing.T) { |
| 2948 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2949 | Description: "stub target generation of the same lib across configs should not result in duplicates", |
| 2950 | ModuleTypeUnderTest: "cc_library", |
| 2951 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2952 | Filesystem: map[string]string{ |
| 2953 | "bar.map.txt": "", |
| 2954 | }, |
| 2955 | Blueprint: ` |
| 2956 | cc_library { |
| 2957 | name: "barlib", |
| 2958 | stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] }, |
| 2959 | bazel_module: { bp2build_available: false }, |
| 2960 | } |
| 2961 | cc_library { |
| 2962 | name: "foolib", |
| 2963 | shared_libs: ["barlib"], |
| 2964 | target: { |
| 2965 | android: { |
| 2966 | shared_libs: ["barlib"], |
| 2967 | }, |
| 2968 | }, |
| 2969 | bazel_module: { bp2build_available: true }, |
| 2970 | }`, |
| 2971 | ExpectedBazelTargets: makeCcLibraryTargets("foolib", AttrNameToString{ |
| 2972 | "implementation_dynamic_deps": `select({ |
| 2973 | "//build/bazel/rules/apex:android-in_apex": [":barlib_stub_libs_current"], |
| 2974 | "//conditions:default": [":barlib"], |
| 2975 | })`, |
| 2976 | "local_includes": `["."]`, |
| 2977 | }), |
| 2978 | }) |
| 2979 | } |
| 2980 | |
Liz Kammer | ffc17e4 | 2022-11-23 09:42:05 -0500 | [diff] [blame] | 2981 | func TestCcLibraryExcludesLibsHost(t *testing.T) { |
| 2982 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2983 | ModuleTypeUnderTest: "cc_library", |
| 2984 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2985 | Filesystem: map[string]string{ |
| 2986 | "bar.map.txt": "", |
| 2987 | }, |
| 2988 | Blueprint: simpleModuleDoNotConvertBp2build("cc_library", "bazlib") + ` |
| 2989 | cc_library { |
| 2990 | name: "quxlib", |
| 2991 | stubs: { symbol_file: "bar.map.txt", versions: ["current"] }, |
| 2992 | bazel_module: { bp2build_available: false }, |
| 2993 | } |
| 2994 | cc_library { |
| 2995 | name: "barlib", |
| 2996 | stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] }, |
| 2997 | bazel_module: { bp2build_available: false }, |
| 2998 | } |
| 2999 | cc_library { |
| 3000 | name: "foolib", |
| 3001 | shared_libs: ["barlib", "quxlib"], |
| 3002 | target: { |
| 3003 | host: { |
| 3004 | shared_libs: ["bazlib"], |
| 3005 | exclude_shared_libs: ["barlib"], |
| 3006 | }, |
| 3007 | }, |
| 3008 | include_build_directory: false, |
| 3009 | bazel_module: { bp2build_available: true }, |
| 3010 | }`, |
| 3011 | ExpectedBazelTargets: makeCcLibraryTargets("foolib", AttrNameToString{ |
| 3012 | "implementation_dynamic_deps": `select({ |
| 3013 | "//build/bazel/platforms/os:darwin": [":bazlib"], |
| 3014 | "//build/bazel/platforms/os:linux": [":bazlib"], |
| 3015 | "//build/bazel/platforms/os:linux_bionic": [":bazlib"], |
| 3016 | "//build/bazel/platforms/os:linux_musl": [":bazlib"], |
| 3017 | "//build/bazel/platforms/os:windows": [":bazlib"], |
| 3018 | "//conditions:default": [], |
| 3019 | }) + select({ |
| 3020 | "//build/bazel/platforms/os:darwin": [":quxlib"], |
| 3021 | "//build/bazel/platforms/os:linux": [":quxlib"], |
| 3022 | "//build/bazel/platforms/os:linux_bionic": [":quxlib"], |
| 3023 | "//build/bazel/platforms/os:linux_musl": [":quxlib"], |
| 3024 | "//build/bazel/platforms/os:windows": [":quxlib"], |
| 3025 | "//build/bazel/rules/apex:android-in_apex": [ |
| 3026 | ":barlib_stub_libs_current", |
| 3027 | ":quxlib_stub_libs_current", |
| 3028 | ], |
| 3029 | "//conditions:default": [ |
| 3030 | ":barlib", |
| 3031 | ":quxlib", |
| 3032 | ], |
| 3033 | })`, |
| 3034 | }), |
| 3035 | }) |
| 3036 | } |
| 3037 | |
Liz Kammer | f38a837 | 2022-02-04 15:39:00 -0500 | [diff] [blame] | 3038 | func TestCcLibraryEscapeLdflags(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3039 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3040 | ModuleTypeUnderTest: "cc_library", |
| 3041 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3042 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | f38a837 | 2022-02-04 15:39:00 -0500 | [diff] [blame] | 3043 | name: "foo", |
| 3044 | ldflags: ["-Wl,--rpath,${ORIGIN}"], |
| 3045 | include_build_directory: false, |
| 3046 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3047 | ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{ |
Liz Kammer | f38a837 | 2022-02-04 15:39:00 -0500 | [diff] [blame] | 3048 | "linkopts": `["-Wl,--rpath,$${ORIGIN}"]`, |
| 3049 | }), |
| 3050 | }) |
| 3051 | } |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3052 | |
| 3053 | func TestCcLibraryConvertLex(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3054 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3055 | ModuleTypeUnderTest: "cc_library", |
| 3056 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3057 | Filesystem: map[string]string{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3058 | "foo.c": "", |
| 3059 | "bar.cc": "", |
| 3060 | "foo1.l": "", |
| 3061 | "bar1.ll": "", |
| 3062 | "foo2.l": "", |
| 3063 | "bar2.ll": "", |
| 3064 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3065 | Blueprint: `cc_library { |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3066 | name: "foo_lib", |
| 3067 | srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"], |
| 3068 | lex: { flags: ["--foo_flags"] }, |
| 3069 | include_build_directory: false, |
| 3070 | bazel_module: { bp2build_available: true }, |
| 3071 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3072 | ExpectedBazelTargets: append([]string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3073 | MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3074 | "srcs": `[ |
| 3075 | "foo1.l", |
| 3076 | "foo2.l", |
| 3077 | ]`, |
| 3078 | "lexopts": `["--foo_flags"]`, |
| 3079 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3080 | MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3081 | "srcs": `[ |
| 3082 | "bar1.ll", |
| 3083 | "bar2.ll", |
| 3084 | ]`, |
| 3085 | "lexopts": `["--foo_flags"]`, |
| 3086 | }), |
| 3087 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3088 | makeCcLibraryTargets("foo_lib", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3089 | "srcs": `[ |
| 3090 | "bar.cc", |
| 3091 | ":foo_lib_genlex_ll", |
| 3092 | ]`, |
| 3093 | "srcs_c": `[ |
| 3094 | "foo.c", |
| 3095 | ":foo_lib_genlex_l", |
| 3096 | ]`, |
| 3097 | })...), |
| 3098 | }) |
| 3099 | } |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 3100 | |
| 3101 | func TestCCLibraryRuntimeDeps(t *testing.T) { |
| 3102 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 3103 | Blueprint: `cc_library_shared { |
| 3104 | name: "bar", |
| 3105 | } |
| 3106 | |
| 3107 | cc_library { |
| 3108 | name: "foo", |
| 3109 | runtime_libs: ["foo"], |
| 3110 | }`, |
| 3111 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3112 | MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{ |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 3113 | "local_includes": `["."]`, |
| 3114 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3115 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 3116 | "runtime_deps": `[":foo"]`, |
| 3117 | "local_includes": `["."]`, |
| 3118 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3119 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 3120 | "runtime_deps": `[":foo"]`, |
| 3121 | "local_includes": `["."]`, |
| 3122 | }), |
| 3123 | }, |
| 3124 | }) |
| 3125 | } |
Cole Faust | 5fa4e96 | 2022-08-22 14:31:04 -0700 | [diff] [blame] | 3126 | |
| 3127 | func TestCcLibraryWithInstructionSet(t *testing.T) { |
| 3128 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3129 | ModuleTypeUnderTest: "cc_library", |
| 3130 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3131 | Blueprint: `cc_library { |
| 3132 | name: "foo", |
| 3133 | arch: { |
| 3134 | arm: { |
| 3135 | instruction_set: "arm", |
| 3136 | } |
| 3137 | } |
| 3138 | } |
| 3139 | `, |
| 3140 | ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{ |
| 3141 | "features": `select({ |
| 3142 | "//build/bazel/platforms/arch:arm": [ |
| 3143 | "arm_isa_arm", |
| 3144 | "-arm_isa_thumb", |
| 3145 | ], |
| 3146 | "//conditions:default": [], |
| 3147 | })`, |
| 3148 | "local_includes": `["."]`, |
| 3149 | }), |
| 3150 | }) |
| 3151 | } |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3152 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 3153 | func TestCcLibraryEmptySuffix(t *testing.T) { |
| 3154 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3155 | Description: "cc_library with empty suffix", |
| 3156 | ModuleTypeUnderTest: "cc_library", |
| 3157 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3158 | Filesystem: map[string]string{ |
| 3159 | "foo.c": "", |
| 3160 | }, |
| 3161 | Blueprint: `cc_library { |
| 3162 | name: "foo", |
| 3163 | suffix: "", |
| 3164 | srcs: ["foo.c"], |
| 3165 | include_build_directory: false, |
| 3166 | }`, |
| 3167 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3168 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 3169 | "srcs_c": `["foo.c"]`, |
| 3170 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3171 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 3172 | "srcs_c": `["foo.c"]`, |
| 3173 | "suffix": `""`, |
| 3174 | }), |
| 3175 | }, |
| 3176 | }) |
| 3177 | } |
| 3178 | |
| 3179 | func TestCcLibrarySuffix(t *testing.T) { |
| 3180 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3181 | Description: "cc_library with suffix", |
| 3182 | ModuleTypeUnderTest: "cc_library", |
| 3183 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3184 | Filesystem: map[string]string{ |
| 3185 | "foo.c": "", |
| 3186 | }, |
| 3187 | Blueprint: `cc_library { |
| 3188 | name: "foo", |
| 3189 | suffix: "-suf", |
| 3190 | srcs: ["foo.c"], |
| 3191 | include_build_directory: false, |
| 3192 | }`, |
| 3193 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3194 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 3195 | "srcs_c": `["foo.c"]`, |
| 3196 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3197 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 3198 | "srcs_c": `["foo.c"]`, |
| 3199 | "suffix": `"-suf"`, |
| 3200 | }), |
| 3201 | }, |
| 3202 | }) |
| 3203 | } |
| 3204 | |
| 3205 | func TestCcLibraryArchVariantSuffix(t *testing.T) { |
| 3206 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3207 | Description: "cc_library with arch-variant suffix", |
| 3208 | ModuleTypeUnderTest: "cc_library", |
| 3209 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3210 | Filesystem: map[string]string{ |
| 3211 | "foo.c": "", |
| 3212 | }, |
| 3213 | Blueprint: `cc_library { |
| 3214 | name: "foo", |
| 3215 | arch: { |
| 3216 | arm64: { suffix: "-64" }, |
| 3217 | arm: { suffix: "-32" }, |
| 3218 | }, |
| 3219 | srcs: ["foo.c"], |
| 3220 | include_build_directory: false, |
| 3221 | }`, |
| 3222 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3223 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 3224 | "srcs_c": `["foo.c"]`, |
| 3225 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3226 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 3227 | "srcs_c": `["foo.c"]`, |
| 3228 | "suffix": `select({ |
| 3229 | "//build/bazel/platforms/arch:arm": "-32", |
| 3230 | "//build/bazel/platforms/arch:arm64": "-64", |
| 3231 | "//conditions:default": None, |
| 3232 | })`, |
| 3233 | }), |
| 3234 | }, |
| 3235 | }) |
| 3236 | } |
| 3237 | |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3238 | func TestCcLibraryWithAidlSrcs(t *testing.T) { |
| 3239 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3240 | Description: "cc_library with aidl srcs", |
| 3241 | ModuleTypeUnderTest: "cc_library", |
| 3242 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3243 | Blueprint: ` |
| 3244 | filegroup { |
| 3245 | name: "A_aidl", |
| 3246 | srcs: ["aidl/A.aidl"], |
| 3247 | path: "aidl", |
| 3248 | } |
| 3249 | cc_library { |
| 3250 | name: "foo", |
| 3251 | srcs: [ |
| 3252 | ":A_aidl", |
| 3253 | "B.aidl", |
| 3254 | ], |
| 3255 | }`, |
| 3256 | ExpectedBazelTargets: []string{ |
| 3257 | MakeBazelTargetNoRestrictions("aidl_library", "A_aidl", AttrNameToString{ |
| 3258 | "srcs": `["aidl/A.aidl"]`, |
| 3259 | "strip_import_prefix": `"aidl"`, |
| 3260 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3261 | MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{ |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3262 | "srcs": `["B.aidl"]`, |
| 3263 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3264 | MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3265 | "deps": `[ |
| 3266 | ":A_aidl", |
| 3267 | ":foo_aidl_library", |
| 3268 | ]`, |
| 3269 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3270 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3271 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3272 | "local_includes": `["."]`, |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3273 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3274 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 3275 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3276 | "local_includes": `["."]`, |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3277 | }), |
| 3278 | }, |
| 3279 | }) |
| 3280 | } |
| 3281 | |
| 3282 | func TestCcLibraryWithNonAdjacentAidlFilegroup(t *testing.T) { |
| 3283 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3284 | Description: "cc_library with non aidl filegroup", |
| 3285 | ModuleTypeUnderTest: "cc_library", |
| 3286 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3287 | Filesystem: map[string]string{ |
| 3288 | "path/to/A/Android.bp": ` |
| 3289 | filegroup { |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3290 | name: "A_aidl", |
| 3291 | srcs: ["aidl/A.aidl"], |
| 3292 | path: "aidl", |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3293 | }`, |
| 3294 | }, |
| 3295 | Blueprint: ` |
| 3296 | cc_library { |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3297 | name: "foo", |
| 3298 | srcs: [ |
| 3299 | ":A_aidl", |
| 3300 | ], |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3301 | }`, |
| 3302 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3303 | MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3304 | "deps": `["//path/to/A:A_aidl"]`, |
| 3305 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3306 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3307 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3308 | "local_includes": `["."]`, |
| 3309 | }), |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3310 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 3311 | "local_includes": `["."]`, |
| 3312 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3313 | }), |
| 3314 | }, |
| 3315 | }) |
| 3316 | } |
| 3317 | |
| 3318 | func TestCcLibraryWithExportAidlHeaders(t *testing.T) { |
| 3319 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3320 | Description: "cc_library with export aidl headers", |
| 3321 | ModuleTypeUnderTest: "cc_library", |
| 3322 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3323 | Blueprint: ` |
| 3324 | cc_library { |
| 3325 | name: "foo", |
| 3326 | srcs: [ |
| 3327 | "Foo.aidl", |
| 3328 | ], |
| 3329 | aidl: { |
| 3330 | export_aidl_headers: true, |
| 3331 | } |
| 3332 | }`, |
| 3333 | ExpectedBazelTargets: []string{ |
| 3334 | MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{ |
| 3335 | "srcs": `["Foo.aidl"]`, |
| 3336 | }), |
| 3337 | MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ |
| 3338 | "deps": `[":foo_aidl_library"]`, |
| 3339 | }), |
| 3340 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3341 | "whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3342 | "local_includes": `["."]`, |
| 3343 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3344 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3345 | "whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3346 | "local_includes": `["."]`, |
| 3347 | }), |
| 3348 | }, |
| 3349 | }) |
| 3350 | } |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3351 | |
| 3352 | func TestCcLibraryWithTargetApex(t *testing.T) { |
| 3353 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3354 | Description: "cc_library with target.apex", |
| 3355 | ModuleTypeUnderTest: "cc_library", |
| 3356 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3357 | Blueprint: ` |
| 3358 | cc_library { |
| 3359 | name: "foo", |
| 3360 | shared_libs: ["bar", "baz"], |
| 3361 | static_libs: ["baz", "buh"], |
| 3362 | target: { |
| 3363 | apex: { |
| 3364 | exclude_shared_libs: ["bar"], |
| 3365 | exclude_static_libs: ["buh"], |
| 3366 | } |
| 3367 | } |
| 3368 | }`, |
| 3369 | ExpectedBazelTargets: []string{ |
| 3370 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 3371 | "implementation_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({ |
| 3372 | "//build/bazel/rules/apex:non_apex": [":buh__BP2BUILD__MISSING__DEP"], |
| 3373 | "//conditions:default": [], |
| 3374 | })`, |
| 3375 | "implementation_dynamic_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({ |
| 3376 | "//build/bazel/rules/apex:non_apex": [":bar__BP2BUILD__MISSING__DEP"], |
| 3377 | "//conditions:default": [], |
| 3378 | })`, |
| 3379 | "local_includes": `["."]`, |
| 3380 | }), |
| 3381 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 3382 | "implementation_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({ |
| 3383 | "//build/bazel/rules/apex:non_apex": [":buh__BP2BUILD__MISSING__DEP"], |
| 3384 | "//conditions:default": [], |
| 3385 | })`, |
| 3386 | "implementation_dynamic_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({ |
| 3387 | "//build/bazel/rules/apex:non_apex": [":bar__BP2BUILD__MISSING__DEP"], |
| 3388 | "//conditions:default": [], |
| 3389 | })`, |
| 3390 | "local_includes": `["."]`, |
| 3391 | }), |
| 3392 | }, |
| 3393 | }) |
| 3394 | } |
| 3395 | |
| 3396 | func TestCcLibraryWithTargetApexAndExportLibHeaders(t *testing.T) { |
| 3397 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3398 | Description: "cc_library with target.apex and export_shared|static_lib_headers", |
| 3399 | ModuleTypeUnderTest: "cc_library", |
| 3400 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3401 | Blueprint: ` |
| 3402 | cc_library_static { |
| 3403 | name: "foo", |
| 3404 | shared_libs: ["bar", "baz"], |
| 3405 | static_libs: ["abc"], |
| 3406 | export_shared_lib_headers: ["baz"], |
| 3407 | export_static_lib_headers: ["abc"], |
| 3408 | target: { |
| 3409 | apex: { |
| 3410 | exclude_shared_libs: ["baz", "bar"], |
| 3411 | exclude_static_libs: ["abc"], |
| 3412 | } |
| 3413 | } |
| 3414 | }`, |
| 3415 | ExpectedBazelTargets: []string{ |
| 3416 | MakeBazelTarget("cc_library_static", "foo", AttrNameToString{ |
| 3417 | "implementation_dynamic_deps": `select({ |
| 3418 | "//build/bazel/rules/apex:non_apex": [":bar__BP2BUILD__MISSING__DEP"], |
| 3419 | "//conditions:default": [], |
| 3420 | })`, |
| 3421 | "dynamic_deps": `select({ |
| 3422 | "//build/bazel/rules/apex:non_apex": [":baz__BP2BUILD__MISSING__DEP"], |
| 3423 | "//conditions:default": [], |
| 3424 | })`, |
| 3425 | "deps": `select({ |
| 3426 | "//build/bazel/rules/apex:non_apex": [":abc__BP2BUILD__MISSING__DEP"], |
| 3427 | "//conditions:default": [], |
| 3428 | })`, |
| 3429 | "local_includes": `["."]`, |
| 3430 | }), |
| 3431 | }, |
| 3432 | }) |
| 3433 | } |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 3434 | |
| 3435 | func TestCcLibraryWithSyspropSrcs(t *testing.T) { |
| 3436 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3437 | Description: "cc_library with sysprop sources", |
| 3438 | ModuleTypeUnderTest: "cc_library", |
| 3439 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3440 | Blueprint: ` |
| 3441 | cc_library { |
| 3442 | name: "foo", |
| 3443 | srcs: [ |
| 3444 | "bar.sysprop", |
| 3445 | "baz.sysprop", |
| 3446 | "blah.cpp", |
| 3447 | ], |
| 3448 | min_sdk_version: "5", |
| 3449 | }`, |
| 3450 | ExpectedBazelTargets: []string{ |
| 3451 | MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{ |
| 3452 | "srcs": `[ |
| 3453 | "bar.sysprop", |
| 3454 | "baz.sysprop", |
| 3455 | ]`, |
| 3456 | }), |
| 3457 | MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{ |
| 3458 | "dep": `":foo_sysprop_library"`, |
| 3459 | "min_sdk_version": `"5"`, |
| 3460 | }), |
| 3461 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 3462 | "srcs": `["blah.cpp"]`, |
| 3463 | "local_includes": `["."]`, |
| 3464 | "min_sdk_version": `"5"`, |
| 3465 | "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`, |
| 3466 | }), |
| 3467 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 3468 | "srcs": `["blah.cpp"]`, |
| 3469 | "local_includes": `["."]`, |
| 3470 | "min_sdk_version": `"5"`, |
| 3471 | "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`, |
| 3472 | }), |
| 3473 | }, |
| 3474 | }) |
| 3475 | } |
| 3476 | |
| 3477 | func TestCcLibraryWithSyspropSrcsSomeConfigs(t *testing.T) { |
| 3478 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3479 | Description: "cc_library with sysprop sources in some configs but not others", |
| 3480 | ModuleTypeUnderTest: "cc_library", |
| 3481 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3482 | Blueprint: ` |
| 3483 | cc_library { |
| 3484 | name: "foo", |
| 3485 | host_supported: true, |
| 3486 | srcs: [ |
| 3487 | "blah.cpp", |
| 3488 | ], |
| 3489 | target: { |
| 3490 | android: { |
| 3491 | srcs: ["bar.sysprop"], |
| 3492 | }, |
| 3493 | }, |
| 3494 | min_sdk_version: "5", |
| 3495 | }`, |
| 3496 | ExpectedBazelTargets: []string{ |
| 3497 | MakeBazelTargetNoRestrictions("sysprop_library", "foo_sysprop_library", AttrNameToString{ |
| 3498 | "srcs": `select({ |
| 3499 | "//build/bazel/platforms/os:android": ["bar.sysprop"], |
| 3500 | "//conditions:default": [], |
| 3501 | })`, |
| 3502 | }), |
| 3503 | MakeBazelTargetNoRestrictions("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{ |
| 3504 | "dep": `":foo_sysprop_library"`, |
| 3505 | "min_sdk_version": `"5"`, |
| 3506 | }), |
| 3507 | MakeBazelTargetNoRestrictions("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 3508 | "srcs": `["blah.cpp"]`, |
| 3509 | "local_includes": `["."]`, |
| 3510 | "min_sdk_version": `"5"`, |
| 3511 | "whole_archive_deps": `select({ |
| 3512 | "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"], |
| 3513 | "//conditions:default": [], |
| 3514 | })`, |
| 3515 | }), |
| 3516 | MakeBazelTargetNoRestrictions("cc_library_shared", "foo", AttrNameToString{ |
| 3517 | "srcs": `["blah.cpp"]`, |
| 3518 | "local_includes": `["."]`, |
| 3519 | "min_sdk_version": `"5"`, |
| 3520 | "whole_archive_deps": `select({ |
| 3521 | "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"], |
| 3522 | "//conditions:default": [], |
| 3523 | })`, |
| 3524 | }), |
| 3525 | }, |
| 3526 | }) |
| 3527 | } |
Vinh Tran | 395a1e9 | 2022-09-16 18:27:29 -0400 | [diff] [blame] | 3528 | |
| 3529 | func TestCcLibraryWithAidlAndSharedLibs(t *testing.T) { |
| 3530 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3531 | Description: "cc_aidl_library depends on shared libs from parent cc_library_static", |
| 3532 | ModuleTypeUnderTest: "cc_library", |
| 3533 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3534 | Blueprint: ` |
| 3535 | cc_library_static { |
| 3536 | name: "foo", |
| 3537 | srcs: [ |
| 3538 | "Foo.aidl", |
| 3539 | ], |
| 3540 | shared_libs: [ |
| 3541 | "bar", |
| 3542 | "baz", |
| 3543 | ], |
| 3544 | export_shared_lib_headers: [ |
| 3545 | "baz", |
| 3546 | ], |
| 3547 | }` + |
| 3548 | simpleModuleDoNotConvertBp2build("cc_library", "bar") + |
| 3549 | simpleModuleDoNotConvertBp2build("cc_library", "baz"), |
| 3550 | ExpectedBazelTargets: []string{ |
| 3551 | MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{ |
| 3552 | "srcs": `["Foo.aidl"]`, |
| 3553 | }), |
| 3554 | MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ |
| 3555 | "deps": `[":foo_aidl_library"]`, |
| 3556 | "implementation_dynamic_deps": `[ |
| 3557 | ":baz", |
| 3558 | ":bar", |
| 3559 | ]`, |
| 3560 | }), |
| 3561 | MakeBazelTarget("cc_library_static", "foo", AttrNameToString{ |
| 3562 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3563 | "dynamic_deps": `[":baz"]`, |
| 3564 | "implementation_dynamic_deps": `[":bar"]`, |
| 3565 | "local_includes": `["."]`, |
| 3566 | }), |
| 3567 | }, |
| 3568 | }) |
| 3569 | } |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 3570 | |
| 3571 | func TestCcLibraryWithTidy(t *testing.T) { |
| 3572 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3573 | Description: "cc_library uses tidy properties", |
| 3574 | ModuleTypeUnderTest: "cc_library", |
| 3575 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3576 | Blueprint: ` |
| 3577 | cc_library_static { |
| 3578 | name: "foo", |
| 3579 | srcs: ["foo.cpp"], |
| 3580 | tidy: true, |
| 3581 | tidy_checks: ["check1", "check2"], |
| 3582 | tidy_checks_as_errors: ["check1error", "check2error"], |
| 3583 | tidy_disabled_srcs: ["bar.cpp"], |
Sam Delmerico | 4c902d6 | 2022-11-02 14:17:15 -0400 | [diff] [blame] | 3584 | tidy_timeout_srcs: ["baz.cpp"], |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 3585 | }`, |
| 3586 | ExpectedBazelTargets: []string{ |
| 3587 | MakeBazelTarget("cc_library_static", "foo", AttrNameToString{ |
| 3588 | "local_includes": `["."]`, |
| 3589 | "srcs": `["foo.cpp"]`, |
| 3590 | "tidy": `True`, |
| 3591 | "tidy_checks": `[ |
| 3592 | "check1", |
| 3593 | "check2", |
| 3594 | ]`, |
| 3595 | "tidy_checks_as_errors": `[ |
| 3596 | "check1error", |
| 3597 | "check2error", |
| 3598 | ]`, |
| 3599 | "tidy_disabled_srcs": `["bar.cpp"]`, |
Sam Delmerico | 4c902d6 | 2022-11-02 14:17:15 -0400 | [diff] [blame] | 3600 | "tidy_timeout_srcs": `["baz.cpp"]`, |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 3601 | }), |
| 3602 | }, |
| 3603 | }) |
| 3604 | } |
Yu Liu | 56ccb1a | 2022-11-12 10:47:07 -0800 | [diff] [blame^] | 3605 | |
| 3606 | func TestCcLibraryHeaderAbiChecker(t *testing.T) { |
| 3607 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3608 | Description: "cc_library with header abi checker", |
| 3609 | ModuleTypeUnderTest: "cc_library", |
| 3610 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3611 | Blueprint: `cc_library { |
| 3612 | name: "foo", |
| 3613 | header_abi_checker: { |
| 3614 | enabled: true, |
| 3615 | symbol_file: "a.map.txt", |
| 3616 | exclude_symbol_versions: [ |
| 3617 | "29", |
| 3618 | "30", |
| 3619 | ], |
| 3620 | exclude_symbol_tags: [ |
| 3621 | "tag1", |
| 3622 | "tag2", |
| 3623 | ], |
| 3624 | check_all_apis: true, |
| 3625 | diff_flags: ["-allow-adding-removing-weak-symbols"], |
| 3626 | }, |
| 3627 | include_build_directory: false, |
| 3628 | }`, |
| 3629 | ExpectedBazelTargets: []string{ |
| 3630 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), |
| 3631 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 3632 | "abi_checker_enabled": `True`, |
| 3633 | "abi_checker_symbol_file": `"a.map.txt"`, |
| 3634 | "abi_checker_exclude_symbol_versions": `[ |
| 3635 | "29", |
| 3636 | "30", |
| 3637 | ]`, |
| 3638 | "abi_checker_exclude_symbol_tags": `[ |
| 3639 | "tag1", |
| 3640 | "tag2", |
| 3641 | ]`, |
| 3642 | "abi_checker_check_all_apis": `True`, |
| 3643 | "abi_checker_diff_flags": `["-allow-adding-removing-weak-symbols"]`, |
| 3644 | }), |
| 3645 | }, |
| 3646 | }) |
| 3647 | } |