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"], |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 152 | "//build/bazel/platforms/os:linux_bionic": ["bionic.cpp"], |
Colin Cross | 133782e | 2022-12-20 15:29:31 -0800 | [diff] [blame] | 153 | "//build/bazel/platforms/os:linux_glibc": ["linux.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", |
| 1034 | ]`, |
Yu Liu | f01a0f0 | 2022-12-07 15:45:30 -0800 | [diff] [blame] | 1035 | "native_coverage": `False`, |
| 1036 | "srcs": `["a.cpp"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1037 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1038 | expected_targets = append(expected_targets, makeCcLibraryTargets("b", AttrNameToString{ |
Yu Liu | f01a0f0 | 2022-12-07 15:45:30 -0800 | [diff] [blame] | 1039 | "features": `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 | })`, |
Yu Liu | f01a0f0 | 2022-12-07 15:45:30 -0800 | [diff] [blame] | 1046 | "native_coverage": `False`, |
| 1047 | "srcs": `["b.cpp"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1048 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1049 | expected_targets = append(expected_targets, makeCcLibraryTargets("c", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1050 | "features": `select({ |
| 1051 | "//build/bazel/platforms/os:darwin": [ |
| 1052 | "disable_pack_relocations", |
| 1053 | "-no_undefined_symbols", |
| 1054 | ], |
| 1055 | "//conditions:default": [], |
| 1056 | })`, |
| 1057 | "srcs": `["c.cpp"]`, |
| 1058 | })...) |
| 1059 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1060 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1061 | Description: "cc_library pack_relocations test", |
| 1062 | ModuleTypeUnderTest: "cc_library", |
| 1063 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1064 | Blueprint: soongCcLibraryPreamble + ` |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1065 | cc_library { |
| 1066 | name: "a", |
| 1067 | srcs: ["a.cpp"], |
| 1068 | pack_relocations: false, |
Liz Kammer | 0eae52e | 2021-10-06 10:32:26 -0400 | [diff] [blame] | 1069 | allow_undefined_symbols: true, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1070 | include_build_directory: false, |
Yu Liu | 8d82ac5 | 2022-05-17 15:13:28 -0700 | [diff] [blame] | 1071 | native_coverage: false, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | cc_library { |
| 1075 | name: "b", |
| 1076 | srcs: ["b.cpp"], |
| 1077 | arch: { |
| 1078 | x86_64: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1079 | pack_relocations: false, |
Liz Kammer | 0eae52e | 2021-10-06 10:32:26 -0400 | [diff] [blame] | 1080 | allow_undefined_symbols: true, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1081 | }, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1082 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1083 | include_build_directory: false, |
Yu Liu | 8d82ac5 | 2022-05-17 15:13:28 -0700 | [diff] [blame] | 1084 | native_coverage: false, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | cc_library { |
| 1088 | name: "c", |
| 1089 | srcs: ["c.cpp"], |
| 1090 | target: { |
| 1091 | darwin: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1092 | pack_relocations: false, |
Liz Kammer | 0eae52e | 2021-10-06 10:32:26 -0400 | [diff] [blame] | 1093 | allow_undefined_symbols: true, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1094 | }, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1095 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1096 | include_build_directory: false, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1097 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1098 | ExpectedBazelTargets: expected_targets, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1099 | }) |
| 1100 | } |
| 1101 | |
| 1102 | func TestCcLibrarySpacesInCopts(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1103 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1104 | Description: "cc_library spaces in copts", |
| 1105 | ModuleTypeUnderTest: "cc_library", |
| 1106 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1107 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 1108 | cc_library { |
| 1109 | name: "a", |
| 1110 | cflags: ["-include header.h",], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1111 | include_build_directory: false, |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 1112 | } |
| 1113 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1114 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1115 | "copts": `[ |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 1116 | "-include", |
| 1117 | "header.h", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1118 | ]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1119 | }), |
| 1120 | }, |
| 1121 | ) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1125 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1126 | Description: "cc_library cppflags usage", |
| 1127 | ModuleTypeUnderTest: "cc_library", |
| 1128 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1129 | Blueprint: soongCcLibraryPreamble + `cc_library { |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1130 | name: "a", |
| 1131 | srcs: ["a.cpp"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1132 | cflags: ["-Wall"], |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1133 | cppflags: [ |
| 1134 | "-fsigned-char", |
| 1135 | "-pedantic", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1136 | ], |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1137 | arch: { |
| 1138 | arm64: { |
| 1139 | cppflags: ["-DARM64=1"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1140 | }, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1141 | }, |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1142 | target: { |
| 1143 | android: { |
| 1144 | cppflags: ["-DANDROID=1"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1145 | }, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1146 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1147 | include_build_directory: false, |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1148 | } |
| 1149 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1150 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1151 | "copts": `["-Wall"]`, |
| 1152 | "cppflags": `[ |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 1153 | "-fsigned-char", |
| 1154 | "-pedantic", |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1155 | ] + select({ |
| 1156 | "//build/bazel/platforms/arch:arm64": ["-DARM64=1"], |
| 1157 | "//conditions:default": [], |
| 1158 | }) + select({ |
| 1159 | "//build/bazel/platforms/os:android": ["-DANDROID=1"], |
| 1160 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1161 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1162 | "srcs": `["a.cpp"]`, |
| 1163 | }), |
| 1164 | }, |
| 1165 | ) |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 1166 | } |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 1167 | |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1168 | func TestCcLibraryExcludeLibs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1169 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1170 | ModuleTypeUnderTest: "cc_library", |
| 1171 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1172 | Filesystem: map[string]string{}, |
| 1173 | Blueprint: soongCcLibraryStaticPreamble + ` |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1174 | cc_library { |
| 1175 | name: "foo_static", |
| 1176 | srcs: ["common.c"], |
| 1177 | whole_static_libs: [ |
| 1178 | "arm_whole_static_lib_excludes", |
| 1179 | "malloc_not_svelte_whole_static_lib_excludes" |
| 1180 | ], |
| 1181 | static_libs: [ |
| 1182 | "arm_static_lib_excludes", |
| 1183 | "malloc_not_svelte_static_lib_excludes" |
| 1184 | ], |
| 1185 | shared_libs: [ |
| 1186 | "arm_shared_lib_excludes", |
| 1187 | ], |
| 1188 | arch: { |
| 1189 | arm: { |
| 1190 | exclude_shared_libs: [ |
| 1191 | "arm_shared_lib_excludes", |
| 1192 | ], |
| 1193 | exclude_static_libs: [ |
| 1194 | "arm_static_lib_excludes", |
| 1195 | "arm_whole_static_lib_excludes", |
| 1196 | ], |
| 1197 | }, |
| 1198 | }, |
| 1199 | product_variables: { |
| 1200 | malloc_not_svelte: { |
| 1201 | shared_libs: ["malloc_not_svelte_shared_lib"], |
| 1202 | whole_static_libs: ["malloc_not_svelte_whole_static_lib"], |
| 1203 | exclude_static_libs: [ |
| 1204 | "malloc_not_svelte_static_lib_excludes", |
| 1205 | "malloc_not_svelte_whole_static_lib_excludes", |
| 1206 | ], |
| 1207 | }, |
| 1208 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1209 | include_build_directory: false, |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | cc_library { |
| 1213 | name: "arm_whole_static_lib_excludes", |
| 1214 | bazel_module: { bp2build_available: false }, |
| 1215 | } |
| 1216 | |
| 1217 | cc_library { |
| 1218 | name: "malloc_not_svelte_whole_static_lib", |
| 1219 | bazel_module: { bp2build_available: false }, |
| 1220 | } |
| 1221 | |
| 1222 | cc_library { |
| 1223 | name: "malloc_not_svelte_whole_static_lib_excludes", |
| 1224 | bazel_module: { bp2build_available: false }, |
| 1225 | } |
| 1226 | |
| 1227 | cc_library { |
| 1228 | name: "arm_static_lib_excludes", |
| 1229 | bazel_module: { bp2build_available: false }, |
| 1230 | } |
| 1231 | |
| 1232 | cc_library { |
| 1233 | name: "malloc_not_svelte_static_lib_excludes", |
| 1234 | bazel_module: { bp2build_available: false }, |
| 1235 | } |
| 1236 | |
| 1237 | cc_library { |
| 1238 | name: "arm_shared_lib_excludes", |
| 1239 | bazel_module: { bp2build_available: false }, |
| 1240 | } |
| 1241 | |
| 1242 | cc_library { |
| 1243 | name: "malloc_not_svelte_shared_lib", |
| 1244 | bazel_module: { bp2build_available: false }, |
| 1245 | } |
| 1246 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1247 | ExpectedBazelTargets: makeCcLibraryTargets("foo_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1248 | "implementation_deps": `select({ |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1249 | "//build/bazel/platforms/arch:arm": [], |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1250 | "//conditions:default": [":arm_static_lib_excludes_bp2build_cc_library_static"], |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1251 | }) + select({ |
| 1252 | "//build/bazel/product_variables:malloc_not_svelte": [], |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1253 | "//conditions:default": [":malloc_not_svelte_static_lib_excludes_bp2build_cc_library_static"], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1254 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1255 | "implementation_dynamic_deps": `select({ |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 1256 | "//build/bazel/platforms/arch:arm": [], |
| 1257 | "//conditions:default": [":arm_shared_lib_excludes"], |
| 1258 | }) + select({ |
| 1259 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_shared_lib"], |
| 1260 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1261 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1262 | "srcs_c": `["common.c"]`, |
| 1263 | "whole_archive_deps": `select({ |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1264 | "//build/bazel/platforms/arch:arm": [], |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1265 | "//conditions:default": [":arm_whole_static_lib_excludes_bp2build_cc_library_static"], |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1266 | }) + select({ |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1267 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_whole_static_lib_bp2build_cc_library_static"], |
| 1268 | "//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] | 1269 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1270 | }), |
| 1271 | }, |
| 1272 | ) |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1273 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1274 | |
Zi Wang | 0a8a129 | 2022-08-30 06:27:01 +0000 | [diff] [blame] | 1275 | func TestCcLibraryProductVariablesHeaderLibs(t *testing.T) { |
| 1276 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1277 | ModuleTypeUnderTest: "cc_library", |
| 1278 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1279 | Filesystem: map[string]string{}, |
| 1280 | Blueprint: soongCcLibraryStaticPreamble + ` |
| 1281 | cc_library { |
| 1282 | name: "foo_static", |
| 1283 | srcs: ["common.c"], |
| 1284 | product_variables: { |
| 1285 | malloc_not_svelte: { |
| 1286 | header_libs: ["malloc_not_svelte_header_lib"], |
| 1287 | }, |
| 1288 | }, |
| 1289 | include_build_directory: false, |
| 1290 | } |
| 1291 | |
| 1292 | cc_library { |
| 1293 | name: "malloc_not_svelte_header_lib", |
| 1294 | bazel_module: { bp2build_available: false }, |
| 1295 | } |
| 1296 | `, |
| 1297 | ExpectedBazelTargets: makeCcLibraryTargets("foo_static", AttrNameToString{ |
| 1298 | "implementation_deps": `select({ |
| 1299 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_header_lib"], |
| 1300 | "//conditions:default": [], |
| 1301 | })`, |
| 1302 | "srcs_c": `["common.c"]`, |
| 1303 | "target_compatible_with": `["//build/bazel/platforms/os:android"]`, |
| 1304 | }), |
| 1305 | }, |
| 1306 | ) |
| 1307 | } |
| 1308 | |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1309 | func TestCCLibraryNoCrtTrue(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1310 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 1311 | Description: "cc_library - nocrt: true disables feature", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1312 | ModuleTypeUnderTest: "cc_library", |
| 1313 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1314 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1315 | "impl.cpp": "", |
| 1316 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1317 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1318 | cc_library { |
| 1319 | name: "foo-lib", |
| 1320 | srcs: ["impl.cpp"], |
| 1321 | nocrt: true, |
| 1322 | include_build_directory: false, |
| 1323 | } |
| 1324 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1325 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 1326 | "features": `["-link_crt"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1327 | "srcs": `["impl.cpp"]`, |
| 1328 | }), |
| 1329 | }, |
| 1330 | ) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | func TestCCLibraryNoCrtFalse(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1334 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1335 | Description: "cc_library - nocrt: false - does not emit attribute", |
| 1336 | ModuleTypeUnderTest: "cc_library", |
| 1337 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1338 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1339 | "impl.cpp": "", |
| 1340 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1341 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1342 | cc_library { |
| 1343 | name: "foo-lib", |
| 1344 | srcs: ["impl.cpp"], |
| 1345 | nocrt: false, |
| 1346 | include_build_directory: false, |
| 1347 | } |
| 1348 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1349 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1350 | "srcs": `["impl.cpp"]`, |
| 1351 | }), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1352 | }) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | func TestCCLibraryNoCrtArchVariant(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1356 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1357 | Description: "cc_library - nocrt in select", |
| 1358 | ModuleTypeUnderTest: "cc_library", |
| 1359 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1360 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1361 | "impl.cpp": "", |
| 1362 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1363 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1364 | cc_library { |
| 1365 | name: "foo-lib", |
| 1366 | srcs: ["impl.cpp"], |
| 1367 | arch: { |
| 1368 | arm: { |
| 1369 | nocrt: true, |
| 1370 | }, |
| 1371 | x86: { |
| 1372 | nocrt: false, |
| 1373 | }, |
| 1374 | }, |
| 1375 | include_build_directory: false, |
| 1376 | } |
| 1377 | `, |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 1378 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
| 1379 | "features": `select({ |
| 1380 | "//build/bazel/platforms/arch:arm": ["-link_crt"], |
| 1381 | "//conditions:default": [], |
| 1382 | })`, |
| 1383 | "srcs": `["impl.cpp"]`, |
| 1384 | }), |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1385 | }) |
| 1386 | } |
| 1387 | |
| 1388 | func TestCCLibraryNoLibCrtTrue(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1389 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1390 | ModuleTypeUnderTest: "cc_library", |
| 1391 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1392 | Filesystem: map[string]string{ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1393 | "impl.cpp": "", |
| 1394 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1395 | Blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1396 | cc_library { |
| 1397 | name: "foo-lib", |
| 1398 | srcs: ["impl.cpp"], |
| 1399 | no_libcrt: true, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1400 | include_build_directory: false, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1401 | } |
| 1402 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1403 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 1404 | "features": `["-use_libcrt"]`, |
| 1405 | "srcs": `["impl.cpp"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1406 | }), |
| 1407 | }) |
| 1408 | } |
| 1409 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1410 | func makeCcLibraryTargets(name string, attrs AttrNameToString) []string { |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1411 | STATIC_ONLY_ATTRS := map[string]bool{} |
| 1412 | SHARED_ONLY_ATTRS := map[string]bool{ |
| 1413 | "link_crt": true, |
| 1414 | "additional_linker_inputs": true, |
| 1415 | "linkopts": true, |
| 1416 | "strip": true, |
Yu Liu | 75be7b9 | 2022-02-01 09:54:09 -0800 | [diff] [blame] | 1417 | "inject_bssl_hash": true, |
Yu Liu | 56ccb1a | 2022-11-12 10:47:07 -0800 | [diff] [blame] | 1418 | "stubs_symbol_file": true, |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 1419 | "use_version_lib": true, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1420 | } |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 1421 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1422 | sharedAttrs := AttrNameToString{} |
| 1423 | staticAttrs := AttrNameToString{} |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1424 | for key, val := range attrs { |
| 1425 | if _, staticOnly := STATIC_ONLY_ATTRS[key]; !staticOnly { |
| 1426 | sharedAttrs[key] = val |
| 1427 | } |
| 1428 | if _, sharedOnly := SHARED_ONLY_ATTRS[key]; !sharedOnly { |
| 1429 | staticAttrs[key] = val |
| 1430 | } |
| 1431 | } |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1432 | sharedTarget := MakeBazelTarget("cc_library_shared", name, sharedAttrs) |
| 1433 | staticTarget := MakeBazelTarget("cc_library_static", name+"_bp2build_cc_library_static", staticAttrs) |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1434 | |
| 1435 | return []string{staticTarget, sharedTarget} |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1436 | } |
| 1437 | |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1438 | func TestCCLibraryNoLibCrtFalse(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1439 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1440 | ModuleTypeUnderTest: "cc_library", |
| 1441 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1442 | Filesystem: map[string]string{ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1443 | "impl.cpp": "", |
| 1444 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1445 | Blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1446 | cc_library { |
| 1447 | name: "foo-lib", |
| 1448 | srcs: ["impl.cpp"], |
| 1449 | no_libcrt: false, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1450 | include_build_directory: false, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1451 | } |
| 1452 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1453 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 1454 | "srcs": `["impl.cpp"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1455 | }), |
| 1456 | }) |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1457 | } |
| 1458 | |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1459 | func TestCCLibraryNoLibCrtArchVariant(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1460 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1461 | ModuleTypeUnderTest: "cc_library", |
| 1462 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1463 | Filesystem: map[string]string{ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1464 | "impl.cpp": "", |
| 1465 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1466 | Blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1467 | cc_library { |
| 1468 | name: "foo-lib", |
| 1469 | srcs: ["impl.cpp"], |
| 1470 | arch: { |
| 1471 | arm: { |
| 1472 | no_libcrt: true, |
| 1473 | }, |
| 1474 | x86: { |
| 1475 | no_libcrt: true, |
| 1476 | }, |
| 1477 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1478 | include_build_directory: false, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1479 | } |
| 1480 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1481 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1482 | "srcs": `["impl.cpp"]`, |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 1483 | "features": `select({ |
| 1484 | "//build/bazel/platforms/arch:arm": ["-use_libcrt"], |
| 1485 | "//build/bazel/platforms/arch:x86": ["-use_libcrt"], |
| 1486 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1487 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1488 | }), |
| 1489 | }) |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1490 | } |
| 1491 | |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1492 | func TestCCLibraryNoLibCrtArchAndTargetVariant(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1493 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1494 | ModuleTypeUnderTest: "cc_library", |
| 1495 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1496 | Filesystem: map[string]string{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1497 | "impl.cpp": "", |
| 1498 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1499 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1500 | cc_library { |
| 1501 | name: "foo-lib", |
| 1502 | srcs: ["impl.cpp"], |
| 1503 | arch: { |
| 1504 | arm: { |
| 1505 | no_libcrt: true, |
| 1506 | }, |
| 1507 | x86: { |
| 1508 | no_libcrt: true, |
| 1509 | }, |
| 1510 | }, |
| 1511 | target: { |
| 1512 | darwin: { |
| 1513 | no_libcrt: true, |
| 1514 | } |
| 1515 | }, |
| 1516 | include_build_directory: false, |
| 1517 | } |
| 1518 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1519 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 1520 | "features": `select({ |
| 1521 | "//build/bazel/platforms/arch:arm": ["-use_libcrt"], |
| 1522 | "//build/bazel/platforms/arch:x86": ["-use_libcrt"], |
| 1523 | "//conditions:default": [], |
| 1524 | }) + select({ |
| 1525 | "//build/bazel/platforms/os:darwin": ["-use_libcrt"], |
| 1526 | "//conditions:default": [], |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1527 | })`, |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 1528 | "srcs": `["impl.cpp"]`, |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1529 | }), |
| 1530 | }) |
| 1531 | } |
| 1532 | |
| 1533 | func TestCCLibraryNoLibCrtArchAndTargetVariantConflict(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1534 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1535 | ModuleTypeUnderTest: "cc_library", |
| 1536 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1537 | Filesystem: map[string]string{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1538 | "impl.cpp": "", |
| 1539 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1540 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1541 | cc_library { |
| 1542 | name: "foo-lib", |
| 1543 | srcs: ["impl.cpp"], |
| 1544 | arch: { |
| 1545 | arm: { |
| 1546 | no_libcrt: true, |
| 1547 | }, |
| 1548 | // This is expected to override the value for darwin_x86_64. |
| 1549 | x86_64: { |
| 1550 | no_libcrt: true, |
| 1551 | }, |
| 1552 | }, |
| 1553 | target: { |
| 1554 | darwin: { |
| 1555 | no_libcrt: false, |
| 1556 | } |
| 1557 | }, |
| 1558 | include_build_directory: false, |
| 1559 | } |
| 1560 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1561 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1562 | "srcs": `["impl.cpp"]`, |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 1563 | "features": `select({ |
| 1564 | "//build/bazel/platforms/arch:arm": ["-use_libcrt"], |
| 1565 | "//build/bazel/platforms/arch:x86_64": ["-use_libcrt"], |
| 1566 | "//conditions:default": [], |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1567 | })`, |
| 1568 | }), |
| 1569 | }) |
| 1570 | } |
| 1571 | |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1572 | func TestCcLibraryStrip(t *testing.T) { |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1573 | expectedTargets := []string{} |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1574 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("all", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1575 | "strip": `{ |
| 1576 | "all": True, |
| 1577 | }`, |
| 1578 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1579 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1580 | "strip": `{ |
| 1581 | "keep_symbols": True, |
| 1582 | }`, |
| 1583 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1584 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols_and_debug_frame", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1585 | "strip": `{ |
| 1586 | "keep_symbols_and_debug_frame": True, |
| 1587 | }`, |
| 1588 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1589 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols_list", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1590 | "strip": `{ |
| 1591 | "keep_symbols_list": ["symbol"], |
| 1592 | }`, |
| 1593 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1594 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("none", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1595 | "strip": `{ |
| 1596 | "none": True, |
| 1597 | }`, |
| 1598 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1599 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("nothing", AttrNameToString{})...) |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1600 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1601 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1602 | Description: "cc_library strip args", |
| 1603 | ModuleTypeUnderTest: "cc_library", |
| 1604 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1605 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1606 | cc_library { |
| 1607 | name: "nothing", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1608 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1609 | } |
| 1610 | cc_library { |
| 1611 | name: "keep_symbols", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1612 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1613 | keep_symbols: true, |
| 1614 | }, |
| 1615 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1616 | } |
| 1617 | cc_library { |
| 1618 | name: "keep_symbols_and_debug_frame", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1619 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1620 | keep_symbols_and_debug_frame: true, |
| 1621 | }, |
| 1622 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1623 | } |
| 1624 | cc_library { |
| 1625 | name: "none", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1626 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1627 | none: true, |
| 1628 | }, |
| 1629 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1630 | } |
| 1631 | cc_library { |
| 1632 | name: "keep_symbols_list", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1633 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1634 | keep_symbols_list: ["symbol"], |
| 1635 | }, |
| 1636 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1637 | } |
| 1638 | cc_library { |
| 1639 | name: "all", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1640 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1641 | all: true, |
| 1642 | }, |
| 1643 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1644 | } |
| 1645 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1646 | ExpectedBazelTargets: expectedTargets, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1647 | }) |
| 1648 | } |
| 1649 | |
| 1650 | func TestCcLibraryStripWithArch(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1651 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1652 | Description: "cc_library strip args", |
| 1653 | ModuleTypeUnderTest: "cc_library", |
| 1654 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1655 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1656 | cc_library { |
| 1657 | name: "multi-arch", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1658 | target: { |
| 1659 | darwin: { |
| 1660 | strip: { |
| 1661 | keep_symbols_list: ["foo", "bar"] |
| 1662 | } |
| 1663 | }, |
| 1664 | }, |
| 1665 | arch: { |
| 1666 | arm: { |
| 1667 | strip: { |
| 1668 | keep_symbols_and_debug_frame: true, |
| 1669 | }, |
| 1670 | }, |
| 1671 | arm64: { |
| 1672 | strip: { |
| 1673 | keep_symbols: true, |
| 1674 | }, |
| 1675 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1676 | }, |
| 1677 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1678 | } |
| 1679 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1680 | ExpectedBazelTargets: makeCcLibraryTargets("multi-arch", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1681 | "strip": `{ |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1682 | "keep_symbols": select({ |
| 1683 | "//build/bazel/platforms/arch:arm64": True, |
| 1684 | "//conditions:default": None, |
| 1685 | }), |
| 1686 | "keep_symbols_and_debug_frame": select({ |
| 1687 | "//build/bazel/platforms/arch:arm": True, |
| 1688 | "//conditions:default": None, |
| 1689 | }), |
| 1690 | "keep_symbols_list": select({ |
| 1691 | "//build/bazel/platforms/os:darwin": [ |
| 1692 | "foo", |
| 1693 | "bar", |
| 1694 | ], |
| 1695 | "//conditions:default": [], |
| 1696 | }), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1697 | }`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1698 | }), |
| 1699 | }, |
| 1700 | ) |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1701 | } |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1702 | |
| 1703 | func TestCcLibrary_SystemSharedLibsRootEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1704 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1705 | Description: "cc_library system_shared_libs empty at root", |
| 1706 | ModuleTypeUnderTest: "cc_library", |
| 1707 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1708 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1709 | cc_library { |
| 1710 | name: "root_empty", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1711 | system_shared_libs: [], |
| 1712 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1713 | } |
| 1714 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1715 | ExpectedBazelTargets: makeCcLibraryTargets("root_empty", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1716 | "system_dynamic_deps": `[]`, |
| 1717 | }), |
| 1718 | }, |
| 1719 | ) |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | func TestCcLibrary_SystemSharedLibsStaticEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1723 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1724 | Description: "cc_library system_shared_libs empty for static variant", |
| 1725 | ModuleTypeUnderTest: "cc_library", |
| 1726 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1727 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1728 | cc_library { |
| 1729 | name: "static_empty", |
| 1730 | static: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1731 | system_shared_libs: [], |
| 1732 | }, |
| 1733 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1734 | } |
| 1735 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1736 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1737 | MakeBazelTarget("cc_library_static", "static_empty_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1738 | "system_dynamic_deps": "[]", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1739 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1740 | MakeBazelTarget("cc_library_shared", "static_empty", AttrNameToString{}), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1741 | }, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1742 | }) |
| 1743 | } |
| 1744 | |
| 1745 | func TestCcLibrary_SystemSharedLibsSharedEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1746 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1747 | Description: "cc_library system_shared_libs empty for shared variant", |
| 1748 | ModuleTypeUnderTest: "cc_library", |
| 1749 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1750 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1751 | cc_library { |
| 1752 | name: "shared_empty", |
| 1753 | shared: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1754 | system_shared_libs: [], |
| 1755 | }, |
| 1756 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1757 | } |
| 1758 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1759 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1760 | MakeBazelTarget("cc_library_static", "shared_empty_bp2build_cc_library_static", AttrNameToString{}), |
| 1761 | MakeBazelTarget("cc_library_shared", "shared_empty", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1762 | "system_dynamic_deps": "[]", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1763 | }), |
| 1764 | }, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1765 | }) |
| 1766 | } |
| 1767 | |
| 1768 | func TestCcLibrary_SystemSharedLibsSharedBionicEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1769 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1770 | Description: "cc_library system_shared_libs empty for shared, bionic variant", |
| 1771 | ModuleTypeUnderTest: "cc_library", |
| 1772 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1773 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1774 | cc_library { |
| 1775 | name: "shared_empty", |
| 1776 | target: { |
| 1777 | bionic: { |
| 1778 | shared: { |
| 1779 | system_shared_libs: [], |
| 1780 | } |
| 1781 | } |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1782 | }, |
| 1783 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1784 | } |
| 1785 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1786 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1787 | MakeBazelTarget("cc_library_static", "shared_empty_bp2build_cc_library_static", AttrNameToString{}), |
| 1788 | MakeBazelTarget("cc_library_shared", "shared_empty", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1789 | "system_dynamic_deps": "[]", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1790 | }), |
| 1791 | }, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1792 | }) |
| 1793 | } |
| 1794 | |
| 1795 | func TestCcLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) { |
| 1796 | // Note that this behavior is technically incorrect (it's a simplification). |
| 1797 | // The correct behavior would be if bp2build wrote `system_dynamic_deps = []` |
| 1798 | // only for linux_bionic, but `android` had `["libc", "libdl", "libm"]. |
| 1799 | // b/195791252 tracks the fix. |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1800 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1801 | Description: "cc_library system_shared_libs empty for linux_bionic variant", |
| 1802 | ModuleTypeUnderTest: "cc_library", |
| 1803 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1804 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1805 | cc_library { |
Trevor Radcliffe | 0d1b402 | 2022-12-12 22:26:34 +0000 | [diff] [blame] | 1806 | name: "libc_musl", |
| 1807 | bazel_module: { bp2build_available: false }, |
| 1808 | } |
| 1809 | |
| 1810 | cc_library { |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1811 | name: "target_linux_bionic_empty", |
| 1812 | target: { |
| 1813 | linux_bionic: { |
| 1814 | system_shared_libs: [], |
| 1815 | }, |
| 1816 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1817 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1818 | } |
| 1819 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1820 | ExpectedBazelTargets: makeCcLibraryTargets("target_linux_bionic_empty", AttrNameToString{ |
Trevor Radcliffe | 0d1b402 | 2022-12-12 22:26:34 +0000 | [diff] [blame] | 1821 | "system_dynamic_deps": `select({ |
| 1822 | "//build/bazel/platforms/os:linux_musl": [":libc_musl"], |
| 1823 | "//conditions:default": [], |
| 1824 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1825 | }), |
| 1826 | }, |
| 1827 | ) |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | func TestCcLibrary_SystemSharedLibsBionicEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1831 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1832 | Description: "cc_library system_shared_libs empty for bionic variant", |
| 1833 | ModuleTypeUnderTest: "cc_library", |
| 1834 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1835 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1836 | cc_library { |
Trevor Radcliffe | 0d1b402 | 2022-12-12 22:26:34 +0000 | [diff] [blame] | 1837 | name: "libc_musl", |
| 1838 | bazel_module: { bp2build_available: false }, |
| 1839 | } |
| 1840 | |
| 1841 | cc_library { |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1842 | name: "target_bionic_empty", |
| 1843 | target: { |
| 1844 | bionic: { |
| 1845 | system_shared_libs: [], |
| 1846 | }, |
| 1847 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1848 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1849 | } |
| 1850 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1851 | ExpectedBazelTargets: makeCcLibraryTargets("target_bionic_empty", AttrNameToString{ |
Trevor Radcliffe | 0d1b402 | 2022-12-12 22:26:34 +0000 | [diff] [blame] | 1852 | "system_dynamic_deps": `select({ |
| 1853 | "//build/bazel/platforms/os:linux_musl": [":libc_musl"], |
| 1854 | "//conditions:default": [], |
| 1855 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1856 | }), |
| 1857 | }, |
| 1858 | ) |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1859 | } |
| 1860 | |
Trevor Radcliffe | 0d1b402 | 2022-12-12 22:26:34 +0000 | [diff] [blame] | 1861 | func TestCcLibrary_SystemSharedLibsMuslEmpty(t *testing.T) { |
| 1862 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1863 | Description: "cc_library system_shared_lib empty for musl variant", |
| 1864 | ModuleTypeUnderTest: "cc_library", |
| 1865 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1866 | Blueprint: soongCcLibraryPreamble + ` |
| 1867 | cc_library { |
| 1868 | name: "libc_musl", |
| 1869 | bazel_module: { bp2build_available: false }, |
| 1870 | } |
| 1871 | |
| 1872 | cc_library { |
| 1873 | name: "target_musl_empty", |
| 1874 | target: { |
| 1875 | musl: { |
| 1876 | system_shared_libs: [], |
| 1877 | }, |
| 1878 | }, |
| 1879 | include_build_directory: false, |
| 1880 | } |
| 1881 | `, |
| 1882 | ExpectedBazelTargets: makeCcLibraryTargets("target_musl_empty", AttrNameToString{ |
| 1883 | "system_dynamic_deps": `[]`, |
| 1884 | }), |
| 1885 | }) |
| 1886 | } |
| 1887 | |
| 1888 | func TestCcLibrary_SystemSharedLibsLinuxMuslEmpty(t *testing.T) { |
| 1889 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1890 | Description: "cc_library system_shared_lib empty for linux_musl variant", |
| 1891 | ModuleTypeUnderTest: "cc_library", |
| 1892 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1893 | Blueprint: soongCcLibraryPreamble + ` |
| 1894 | cc_library { |
| 1895 | name: "libc_musl", |
| 1896 | bazel_module: { bp2build_available: false }, |
| 1897 | } |
| 1898 | |
| 1899 | cc_library { |
| 1900 | name: "target_linux_musl_empty", |
| 1901 | target: { |
| 1902 | linux_musl: { |
| 1903 | system_shared_libs: [], |
| 1904 | }, |
| 1905 | }, |
| 1906 | include_build_directory: false, |
| 1907 | } |
| 1908 | `, |
| 1909 | ExpectedBazelTargets: makeCcLibraryTargets("target_linux_musl_empty", AttrNameToString{ |
| 1910 | "system_dynamic_deps": `[]`, |
| 1911 | }), |
| 1912 | }) |
| 1913 | } |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1914 | func TestCcLibrary_SystemSharedLibsSharedAndRoot(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1915 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1916 | Description: "cc_library system_shared_libs set for shared and root", |
| 1917 | ModuleTypeUnderTest: "cc_library", |
| 1918 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1919 | Blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1920 | cc_library { |
| 1921 | name: "libc", |
| 1922 | bazel_module: { bp2build_available: false }, |
| 1923 | } |
| 1924 | cc_library { |
| 1925 | name: "libm", |
| 1926 | bazel_module: { bp2build_available: false }, |
| 1927 | } |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1928 | |
| 1929 | cc_library { |
| 1930 | name: "foo", |
| 1931 | system_shared_libs: ["libc"], |
| 1932 | shared: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1933 | system_shared_libs: ["libm"], |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1934 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1935 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1936 | } |
| 1937 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1938 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1939 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1940 | "system_dynamic_deps": `[":libc"]`, |
| 1941 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1942 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1943 | "system_dynamic_deps": `[ |
| 1944 | ":libc", |
| 1945 | ":libm", |
| 1946 | ]`, |
| 1947 | }), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1948 | }, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1949 | }) |
| 1950 | } |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1951 | |
| 1952 | func TestCcLibraryOsSelects(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1953 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1954 | Description: "cc_library - selects for all os targets", |
| 1955 | ModuleTypeUnderTest: "cc_library", |
| 1956 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1957 | Filesystem: map[string]string{}, |
| 1958 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1959 | cc_library { |
| 1960 | name: "foo-lib", |
| 1961 | srcs: ["base.cpp"], |
| 1962 | target: { |
| 1963 | android: { |
| 1964 | srcs: ["android.cpp"], |
| 1965 | }, |
| 1966 | linux: { |
| 1967 | srcs: ["linux.cpp"], |
| 1968 | }, |
| 1969 | linux_glibc: { |
| 1970 | srcs: ["linux_glibc.cpp"], |
| 1971 | }, |
| 1972 | darwin: { |
| 1973 | srcs: ["darwin.cpp"], |
| 1974 | }, |
| 1975 | bionic: { |
| 1976 | srcs: ["bionic.cpp"], |
| 1977 | }, |
| 1978 | linux_musl: { |
| 1979 | srcs: ["linux_musl.cpp"], |
| 1980 | }, |
| 1981 | windows: { |
| 1982 | srcs: ["windows.cpp"], |
| 1983 | }, |
| 1984 | }, |
| 1985 | include_build_directory: false, |
| 1986 | } |
| 1987 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1988 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1989 | "srcs": `["base.cpp"] + select({ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1990 | "//build/bazel/platforms/os:android": [ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1991 | "linux.cpp", |
Liz Kammer | 9bad9d6 | 2021-10-11 15:40:35 -0400 | [diff] [blame] | 1992 | "bionic.cpp", |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 1993 | "android.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1994 | ], |
| 1995 | "//build/bazel/platforms/os:darwin": ["darwin.cpp"], |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1996 | "//build/bazel/platforms/os:linux_bionic": [ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1997 | "linux.cpp", |
Liz Kammer | 9bad9d6 | 2021-10-11 15:40:35 -0400 | [diff] [blame] | 1998 | "bionic.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1999 | ], |
Colin Cross | 133782e | 2022-12-20 15:29:31 -0800 | [diff] [blame] | 2000 | "//build/bazel/platforms/os:linux_glibc": [ |
| 2001 | "linux.cpp", |
| 2002 | "linux_glibc.cpp", |
| 2003 | ], |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 2004 | "//build/bazel/platforms/os:linux_musl": [ |
Liz Kammer | 9bad9d6 | 2021-10-11 15:40:35 -0400 | [diff] [blame] | 2005 | "linux.cpp", |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 2006 | "linux_musl.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 2007 | ], |
| 2008 | "//build/bazel/platforms/os:windows": ["windows.cpp"], |
| 2009 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 2010 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2011 | }), |
| 2012 | }, |
| 2013 | ) |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
Yu Liu | 75be7b9 | 2022-02-01 09:54:09 -0800 | [diff] [blame] | 2016 | func TestLibcryptoHashInjection(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2017 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2018 | Description: "cc_library - libcrypto hash injection", |
| 2019 | ModuleTypeUnderTest: "cc_library", |
| 2020 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2021 | Filesystem: map[string]string{}, |
| 2022 | Blueprint: soongCcLibraryPreamble + ` |
Yu Liu | 75be7b9 | 2022-02-01 09:54:09 -0800 | [diff] [blame] | 2023 | cc_library { |
| 2024 | name: "libcrypto", |
| 2025 | target: { |
| 2026 | android: { |
| 2027 | inject_bssl_hash: true, |
| 2028 | }, |
| 2029 | }, |
| 2030 | include_build_directory: false, |
| 2031 | } |
| 2032 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2033 | ExpectedBazelTargets: makeCcLibraryTargets("libcrypto", AttrNameToString{ |
Yu Liu | 75be7b9 | 2022-02-01 09:54:09 -0800 | [diff] [blame] | 2034 | "inject_bssl_hash": `select({ |
| 2035 | "//build/bazel/platforms/os:android": True, |
| 2036 | "//conditions:default": None, |
| 2037 | })`, |
| 2038 | }), |
| 2039 | }, |
| 2040 | ) |
| 2041 | } |
| 2042 | |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2043 | func TestCcLibraryCppStdWithGnuExtensions_ConvertsToFeatureAttr(t *testing.T) { |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2044 | type testCase struct { |
| 2045 | cpp_std string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2046 | c_std string |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2047 | gnu_extensions string |
| 2048 | bazel_cpp_std string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2049 | bazel_c_std string |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | testCases := []testCase{ |
| 2053 | // Existing usages of cpp_std in AOSP are: |
| 2054 | // experimental, c++11, c++17, c++2a, c++98, gnu++11, gnu++17 |
| 2055 | // |
| 2056 | // not set, only emit if gnu_extensions is disabled. the default (gnu+17 |
| 2057 | // is set in the toolchain.) |
| 2058 | {cpp_std: "", gnu_extensions: "", bazel_cpp_std: ""}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2059 | {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] | 2060 | {cpp_std: "", gnu_extensions: "true", bazel_cpp_std: ""}, |
| 2061 | // experimental defaults to gnu++2a |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2062 | {cpp_std: "experimental", gnu_extensions: "", bazel_cpp_std: "cpp_std_experimental"}, |
| 2063 | {cpp_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "cpp_std_experimental_no_gnu", bazel_c_std: "c_std_default_no_gnu"}, |
| 2064 | {cpp_std: "experimental", gnu_extensions: "true", bazel_cpp_std: "cpp_std_experimental"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2065 | // Explicitly setting a c++ std does not use replace gnu++ std even if |
| 2066 | // gnu_extensions is true. |
| 2067 | // "c++11", |
| 2068 | {cpp_std: "c++11", gnu_extensions: "", bazel_cpp_std: "c++11"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2069 | {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] | 2070 | {cpp_std: "c++11", gnu_extensions: "true", bazel_cpp_std: "c++11"}, |
| 2071 | // "c++17", |
| 2072 | {cpp_std: "c++17", gnu_extensions: "", bazel_cpp_std: "c++17"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2073 | {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] | 2074 | {cpp_std: "c++17", gnu_extensions: "true", bazel_cpp_std: "c++17"}, |
| 2075 | // "c++2a", |
| 2076 | {cpp_std: "c++2a", gnu_extensions: "", bazel_cpp_std: "c++2a"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2077 | {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] | 2078 | {cpp_std: "c++2a", gnu_extensions: "true", bazel_cpp_std: "c++2a"}, |
| 2079 | // "c++98", |
| 2080 | {cpp_std: "c++98", gnu_extensions: "", bazel_cpp_std: "c++98"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2081 | {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] | 2082 | {cpp_std: "c++98", gnu_extensions: "true", bazel_cpp_std: "c++98"}, |
| 2083 | // gnu++ is replaced with c++ if gnu_extensions is explicitly false. |
| 2084 | // "gnu++11", |
| 2085 | {cpp_std: "gnu++11", gnu_extensions: "", bazel_cpp_std: "gnu++11"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2086 | {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] | 2087 | {cpp_std: "gnu++11", gnu_extensions: "true", bazel_cpp_std: "gnu++11"}, |
| 2088 | // "gnu++17", |
| 2089 | {cpp_std: "gnu++17", gnu_extensions: "", bazel_cpp_std: "gnu++17"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2090 | {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] | 2091 | {cpp_std: "gnu++17", gnu_extensions: "true", bazel_cpp_std: "gnu++17"}, |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2092 | |
| 2093 | // some c_std test cases |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2094 | {c_std: "experimental", gnu_extensions: "", bazel_c_std: "c_std_experimental"}, |
| 2095 | {c_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "cpp_std_default_no_gnu", bazel_c_std: "c_std_experimental_no_gnu"}, |
| 2096 | {c_std: "experimental", gnu_extensions: "true", bazel_c_std: "c_std_experimental"}, |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2097 | {c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "", bazel_cpp_std: "gnu++17", bazel_c_std: "gnu11"}, |
| 2098 | {c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c11"}, |
| 2099 | {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] | 2100 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2101 | for i, tc := range testCases { |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2102 | name := fmt.Sprintf("cpp std: %q, c std: %q, gnu_extensions: %q", tc.cpp_std, tc.c_std, tc.gnu_extensions) |
| 2103 | t.Run(name, func(t *testing.T) { |
| 2104 | name_prefix := fmt.Sprintf("a_%v", i) |
| 2105 | cppStdProp := "" |
| 2106 | if tc.cpp_std != "" { |
| 2107 | cppStdProp = fmt.Sprintf(" cpp_std: \"%s\",", tc.cpp_std) |
| 2108 | } |
| 2109 | cStdProp := "" |
| 2110 | if tc.c_std != "" { |
| 2111 | cStdProp = fmt.Sprintf(" c_std: \"%s\",", tc.c_std) |
| 2112 | } |
| 2113 | gnuExtensionsProp := "" |
| 2114 | if tc.gnu_extensions != "" { |
| 2115 | gnuExtensionsProp = fmt.Sprintf(" gnu_extensions: %s,", tc.gnu_extensions) |
| 2116 | } |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2117 | attrs := AttrNameToString{} |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2118 | if tc.bazel_cpp_std != "" { |
| 2119 | attrs["cpp_std"] = fmt.Sprintf(`"%s"`, tc.bazel_cpp_std) |
| 2120 | } |
| 2121 | if tc.bazel_c_std != "" { |
| 2122 | attrs["c_std"] = fmt.Sprintf(`"%s"`, tc.bazel_c_std) |
| 2123 | } |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2124 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2125 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2126 | Description: fmt.Sprintf( |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2127 | "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] | 2128 | ModuleTypeUnderTest: "cc_library", |
| 2129 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2130 | Blueprint: soongCcLibraryPreamble + fmt.Sprintf(` |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2131 | cc_library { |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2132 | name: "%s_full", |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2133 | %s // cpp_std: *string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2134 | %s // c_std: *string |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2135 | %s // gnu_extensions: *bool |
| 2136 | include_build_directory: false, |
| 2137 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2138 | `, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2139 | ExpectedBazelTargets: makeCcLibraryTargets(name_prefix+"_full", attrs), |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2140 | }) |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2141 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2142 | runCcLibraryStaticTestCase(t, Bp2buildTestCase{ |
| 2143 | Description: fmt.Sprintf( |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2144 | "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] | 2145 | ModuleTypeUnderTest: "cc_library_static", |
| 2146 | ModuleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 2147 | Blueprint: soongCcLibraryPreamble + fmt.Sprintf(` |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2148 | cc_library_static { |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2149 | name: "%s_static", |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2150 | %s // cpp_std: *string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2151 | %s // c_std: *string |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2152 | %s // gnu_extensions: *bool |
| 2153 | include_build_directory: false, |
| 2154 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2155 | `, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2156 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2157 | MakeBazelTarget("cc_library_static", name_prefix+"_static", attrs), |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2158 | }, |
| 2159 | }) |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2160 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2161 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 2162 | Description: fmt.Sprintf( |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2163 | "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] | 2164 | ModuleTypeUnderTest: "cc_library_shared", |
| 2165 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 2166 | Blueprint: soongCcLibraryPreamble + fmt.Sprintf(` |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2167 | cc_library_shared { |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2168 | name: "%s_shared", |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2169 | %s // cpp_std: *string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2170 | %s // c_std: *string |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2171 | %s // gnu_extensions: *bool |
| 2172 | include_build_directory: false, |
| 2173 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2174 | `, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2175 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2176 | MakeBazelTarget("cc_library_shared", name_prefix+"_shared", attrs), |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2177 | }, |
| 2178 | }) |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2179 | }) |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2180 | } |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 2181 | } |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2182 | |
| 2183 | func TestCcLibraryProtoSimple(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2184 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2185 | ModuleTypeUnderTest: "cc_library", |
| 2186 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2187 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2188 | name: "foo", |
| 2189 | srcs: ["foo.proto"], |
| 2190 | include_build_directory: false, |
| 2191 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2192 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2193 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 7756c8f | 2022-02-14 20:49:15 -0500 | [diff] [blame] | 2194 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2195 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2196 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2197 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2198 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2199 | "deps": `[":libprotobuf-cpp-lite"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2200 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2201 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2202 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2203 | }), |
| 2204 | }, |
| 2205 | }) |
| 2206 | } |
| 2207 | |
| 2208 | func TestCcLibraryProtoNoCanonicalPathFromRoot(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2209 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2210 | ModuleTypeUnderTest: "cc_library", |
| 2211 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2212 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2213 | name: "foo", |
| 2214 | srcs: ["foo.proto"], |
| 2215 | proto: { canonical_path_from_root: false}, |
| 2216 | include_build_directory: false, |
| 2217 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2218 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2219 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 7756c8f | 2022-02-14 20:49:15 -0500 | [diff] [blame] | 2220 | "srcs": `["foo.proto"]`, |
| 2221 | "strip_import_prefix": `""`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2222 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2223 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2224 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2225 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2226 | "deps": `[":libprotobuf-cpp-lite"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2227 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2228 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2229 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2230 | }), |
| 2231 | }, |
| 2232 | }) |
| 2233 | } |
| 2234 | |
| 2235 | func TestCcLibraryProtoExplicitCanonicalPathFromRoot(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2236 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2237 | ModuleTypeUnderTest: "cc_library", |
| 2238 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2239 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2240 | name: "foo", |
| 2241 | srcs: ["foo.proto"], |
| 2242 | proto: { canonical_path_from_root: true}, |
| 2243 | include_build_directory: false, |
| 2244 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2245 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2246 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 7756c8f | 2022-02-14 20:49:15 -0500 | [diff] [blame] | 2247 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2248 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2249 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2250 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2251 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2252 | "deps": `[":libprotobuf-cpp-lite"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2253 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2254 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2255 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2256 | }), |
| 2257 | }, |
| 2258 | }) |
| 2259 | } |
| 2260 | |
| 2261 | func TestCcLibraryProtoFull(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2262 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2263 | ModuleTypeUnderTest: "cc_library", |
| 2264 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2265 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2266 | name: "foo", |
| 2267 | srcs: ["foo.proto"], |
| 2268 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2269 | type: "full", |
| 2270 | }, |
| 2271 | include_build_directory: false, |
| 2272 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2273 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2274 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2275 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2276 | }), MakeBazelTarget("cc_proto_library", "foo_cc_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2277 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2278 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2279 | "implementation_whole_archive_deps": `[":foo_cc_proto"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2280 | "deps": `[":libprotobuf-cpp-full"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2281 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2282 | "dynamic_deps": `[":libprotobuf-cpp-full"]`, |
| 2283 | "implementation_whole_archive_deps": `[":foo_cc_proto"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2284 | }), |
| 2285 | }, |
| 2286 | }) |
| 2287 | } |
| 2288 | |
| 2289 | func TestCcLibraryProtoLite(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2290 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2291 | ModuleTypeUnderTest: "cc_library", |
| 2292 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2293 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2294 | name: "foo", |
| 2295 | srcs: ["foo.proto"], |
| 2296 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2297 | type: "lite", |
| 2298 | }, |
| 2299 | include_build_directory: false, |
| 2300 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2301 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2302 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2303 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2304 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2305 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2306 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2307 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2308 | "deps": `[":libprotobuf-cpp-lite"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2309 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2310 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2311 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2312 | }), |
| 2313 | }, |
| 2314 | }) |
| 2315 | } |
| 2316 | |
| 2317 | func TestCcLibraryProtoExportHeaders(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2318 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2319 | ModuleTypeUnderTest: "cc_library", |
| 2320 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2321 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2322 | name: "foo", |
| 2323 | srcs: ["foo.proto"], |
| 2324 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2325 | export_proto_headers: true, |
| 2326 | }, |
| 2327 | include_build_directory: false, |
| 2328 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2329 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2330 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2331 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2332 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2333 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2334 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2335 | "deps": `[":libprotobuf-cpp-lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2336 | "whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2337 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2338 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2339 | "whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2340 | }), |
| 2341 | }, |
| 2342 | }) |
| 2343 | } |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2344 | |
Yu Liu | 2d13614 | 2022-08-18 14:46:13 -0700 | [diff] [blame] | 2345 | func TestCcLibraryProtoIncludeDirs(t *testing.T) { |
| 2346 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2347 | ModuleTypeUnderTest: "cc_library", |
| 2348 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2349 | Blueprint: soongCcProtoPreamble + `cc_library { |
| 2350 | name: "foo", |
| 2351 | srcs: ["foo.proto"], |
| 2352 | proto: { |
| 2353 | include_dirs: ["external/protobuf/src"], |
| 2354 | }, |
| 2355 | include_build_directory: false, |
| 2356 | }`, |
| 2357 | ExpectedBazelTargets: []string{ |
| 2358 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
| 2359 | "srcs": `["foo.proto"]`, |
| 2360 | "deps": `["//external/protobuf:libprotobuf-proto"]`, |
| 2361 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
| 2362 | "deps": `[":foo_proto"]`, |
| 2363 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 2364 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2365 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
| 2366 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2367 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2368 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Yu Liu | 2d13614 | 2022-08-18 14:46:13 -0700 | [diff] [blame] | 2369 | }), |
| 2370 | }, |
| 2371 | }) |
| 2372 | } |
| 2373 | |
| 2374 | func TestCcLibraryProtoIncludeDirsUnknown(t *testing.T) { |
| 2375 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2376 | ModuleTypeUnderTest: "cc_library", |
| 2377 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2378 | Blueprint: soongCcProtoPreamble + `cc_library { |
| 2379 | name: "foo", |
| 2380 | srcs: ["foo.proto"], |
| 2381 | proto: { |
| 2382 | include_dirs: ["external/protobuf/abc"], |
| 2383 | }, |
| 2384 | include_build_directory: false, |
| 2385 | }`, |
| 2386 | ExpectedErr: fmt.Errorf("module \"foo\": Could not find the proto_library target for include dir: external/protobuf/abc"), |
| 2387 | }) |
| 2388 | } |
| 2389 | |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 2390 | func TestCcLibraryConvertedProtoFilegroups(t *testing.T) { |
| 2391 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2392 | ModuleTypeUnderTest: "cc_library", |
| 2393 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2394 | Blueprint: soongCcProtoPreamble + ` |
| 2395 | filegroup { |
| 2396 | name: "a_fg_proto", |
| 2397 | srcs: ["a_fg.proto"], |
| 2398 | } |
| 2399 | |
| 2400 | cc_library { |
| 2401 | name: "a", |
| 2402 | srcs: [ |
| 2403 | ":a_fg_proto", |
| 2404 | "a.proto", |
| 2405 | ], |
| 2406 | proto: { |
| 2407 | export_proto_headers: true, |
| 2408 | }, |
| 2409 | include_build_directory: false, |
| 2410 | }`, |
| 2411 | ExpectedBazelTargets: []string{ |
| 2412 | MakeBazelTarget("proto_library", "a_proto", AttrNameToString{ |
Yu Liu | 2a85fb1 | 2022-09-15 22:18:48 -0700 | [diff] [blame] | 2413 | "deps": `[":a_fg_proto_bp2build_converted"]`, |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 2414 | "srcs": `["a.proto"]`, |
| 2415 | }), MakeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{ |
| 2416 | "deps": `[ |
| 2417 | ":a_fg_proto_bp2build_converted", |
| 2418 | ":a_proto", |
| 2419 | ]`, |
| 2420 | }), MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
| 2421 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2422 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2423 | }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
| 2424 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2425 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2426 | }), MakeBazelTargetNoRestrictions("proto_library", "a_fg_proto_bp2build_converted", AttrNameToString{ |
| 2427 | "srcs": `["a_fg.proto"]`, |
Yu Liu | 2a85fb1 | 2022-09-15 22:18:48 -0700 | [diff] [blame] | 2428 | "tags": `["manual"]`, |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 2429 | }), MakeBazelTargetNoRestrictions("filegroup", "a_fg_proto", AttrNameToString{ |
| 2430 | "srcs": `["a_fg.proto"]`, |
| 2431 | }), |
| 2432 | }, |
| 2433 | }) |
| 2434 | } |
| 2435 | |
| 2436 | func TestCcLibraryConvertedProtoFilegroupsNoProtoFiles(t *testing.T) { |
| 2437 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2438 | ModuleTypeUnderTest: "cc_library", |
| 2439 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2440 | Blueprint: soongCcProtoPreamble + ` |
| 2441 | filegroup { |
| 2442 | name: "a_fg_proto", |
| 2443 | srcs: ["a_fg.proto"], |
| 2444 | } |
| 2445 | |
| 2446 | cc_library { |
| 2447 | name: "a", |
| 2448 | srcs: [ |
| 2449 | ":a_fg_proto", |
| 2450 | ], |
| 2451 | proto: { |
| 2452 | export_proto_headers: true, |
| 2453 | }, |
| 2454 | include_build_directory: false, |
| 2455 | }`, |
| 2456 | ExpectedBazelTargets: []string{ |
| 2457 | MakeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{ |
| 2458 | "deps": `[":a_fg_proto_bp2build_converted"]`, |
| 2459 | }), MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
| 2460 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2461 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2462 | }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
| 2463 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2464 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2465 | }), MakeBazelTargetNoRestrictions("proto_library", "a_fg_proto_bp2build_converted", AttrNameToString{ |
| 2466 | "srcs": `["a_fg.proto"]`, |
Yu Liu | 2a85fb1 | 2022-09-15 22:18:48 -0700 | [diff] [blame] | 2467 | "tags": `["manual"]`, |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 2468 | }), MakeBazelTargetNoRestrictions("filegroup", "a_fg_proto", AttrNameToString{ |
| 2469 | "srcs": `["a_fg.proto"]`, |
| 2470 | }), |
| 2471 | }, |
| 2472 | }) |
| 2473 | } |
| 2474 | |
| 2475 | func TestCcLibraryExternalConvertedProtoFilegroups(t *testing.T) { |
| 2476 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2477 | ModuleTypeUnderTest: "cc_library", |
| 2478 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2479 | Filesystem: map[string]string{ |
| 2480 | "path/to/A/Android.bp": ` |
| 2481 | filegroup { |
| 2482 | name: "a_fg_proto", |
| 2483 | srcs: ["a_fg.proto"], |
| 2484 | }`, |
| 2485 | }, |
| 2486 | Blueprint: soongCcProtoPreamble + ` |
| 2487 | cc_library { |
| 2488 | name: "a", |
| 2489 | srcs: [ |
| 2490 | ":a_fg_proto", |
| 2491 | "a.proto", |
| 2492 | ], |
| 2493 | proto: { |
| 2494 | export_proto_headers: true, |
| 2495 | }, |
| 2496 | include_build_directory: false, |
| 2497 | }`, |
| 2498 | ExpectedBazelTargets: []string{ |
| 2499 | MakeBazelTarget("proto_library", "a_proto", AttrNameToString{ |
Yu Liu | 2a85fb1 | 2022-09-15 22:18:48 -0700 | [diff] [blame] | 2500 | "deps": `["//path/to/A:a_fg_proto_bp2build_converted"]`, |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 2501 | "srcs": `["a.proto"]`, |
| 2502 | }), MakeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{ |
| 2503 | "deps": `[ |
| 2504 | "//path/to/A:a_fg_proto_bp2build_converted", |
| 2505 | ":a_proto", |
| 2506 | ]`, |
| 2507 | }), MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
| 2508 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2509 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2510 | }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
| 2511 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2512 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2513 | }), |
| 2514 | }, |
| 2515 | }) |
| 2516 | } |
| 2517 | |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2518 | func TestCcLibraryProtoFilegroups(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2519 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2520 | ModuleTypeUnderTest: "cc_library", |
| 2521 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2522 | Blueprint: soongCcProtoPreamble + |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2523 | simpleModuleDoNotConvertBp2build("filegroup", "a_fg_proto") + |
| 2524 | simpleModuleDoNotConvertBp2build("filegroup", "b_protos") + |
| 2525 | simpleModuleDoNotConvertBp2build("filegroup", "c-proto-srcs") + |
| 2526 | simpleModuleDoNotConvertBp2build("filegroup", "proto-srcs-d") + ` |
| 2527 | cc_library { |
| 2528 | name: "a", |
| 2529 | srcs: [":a_fg_proto"], |
| 2530 | proto: { |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2531 | export_proto_headers: true, |
| 2532 | }, |
| 2533 | include_build_directory: false, |
| 2534 | } |
| 2535 | |
| 2536 | cc_library { |
| 2537 | name: "b", |
| 2538 | srcs: [":b_protos"], |
| 2539 | proto: { |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2540 | export_proto_headers: true, |
| 2541 | }, |
| 2542 | include_build_directory: false, |
| 2543 | } |
| 2544 | |
| 2545 | cc_library { |
| 2546 | name: "c", |
| 2547 | srcs: [":c-proto-srcs"], |
| 2548 | proto: { |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2549 | export_proto_headers: true, |
| 2550 | }, |
| 2551 | include_build_directory: false, |
| 2552 | } |
| 2553 | |
| 2554 | cc_library { |
| 2555 | name: "d", |
| 2556 | srcs: [":proto-srcs-d"], |
| 2557 | proto: { |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2558 | export_proto_headers: true, |
| 2559 | }, |
| 2560 | include_build_directory: false, |
| 2561 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2562 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2563 | MakeBazelTarget("proto_library", "a_proto", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2564 | "srcs": `[":a_fg_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2565 | }), MakeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2566 | "deps": `[":a_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2567 | }), MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2568 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2569 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2570 | "srcs": `[":a_fg_proto_cpp_srcs"]`, |
| 2571 | "srcs_as": `[":a_fg_proto_as_srcs"]`, |
| 2572 | "srcs_c": `[":a_fg_proto_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2573 | }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2574 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2575 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2576 | "srcs": `[":a_fg_proto_cpp_srcs"]`, |
| 2577 | "srcs_as": `[":a_fg_proto_as_srcs"]`, |
| 2578 | "srcs_c": `[":a_fg_proto_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2579 | }), MakeBazelTarget("proto_library", "b_proto", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2580 | "srcs": `[":b_protos"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2581 | }), MakeBazelTarget("cc_lite_proto_library", "b_cc_proto_lite", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2582 | "deps": `[":b_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2583 | }), MakeBazelTarget("cc_library_static", "b_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2584 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2585 | "whole_archive_deps": `[":b_cc_proto_lite"]`, |
| 2586 | "srcs": `[":b_protos_cpp_srcs"]`, |
| 2587 | "srcs_as": `[":b_protos_as_srcs"]`, |
| 2588 | "srcs_c": `[":b_protos_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2589 | }), MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2590 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2591 | "whole_archive_deps": `[":b_cc_proto_lite"]`, |
| 2592 | "srcs": `[":b_protos_cpp_srcs"]`, |
| 2593 | "srcs_as": `[":b_protos_as_srcs"]`, |
| 2594 | "srcs_c": `[":b_protos_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2595 | }), MakeBazelTarget("proto_library", "c_proto", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2596 | "srcs": `[":c-proto-srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2597 | }), MakeBazelTarget("cc_lite_proto_library", "c_cc_proto_lite", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2598 | "deps": `[":c_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2599 | }), MakeBazelTarget("cc_library_static", "c_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2600 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2601 | "whole_archive_deps": `[":c_cc_proto_lite"]`, |
| 2602 | "srcs": `[":c-proto-srcs_cpp_srcs"]`, |
| 2603 | "srcs_as": `[":c-proto-srcs_as_srcs"]`, |
| 2604 | "srcs_c": `[":c-proto-srcs_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2605 | }), MakeBazelTarget("cc_library_shared", "c", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2606 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2607 | "whole_archive_deps": `[":c_cc_proto_lite"]`, |
| 2608 | "srcs": `[":c-proto-srcs_cpp_srcs"]`, |
| 2609 | "srcs_as": `[":c-proto-srcs_as_srcs"]`, |
| 2610 | "srcs_c": `[":c-proto-srcs_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2611 | }), MakeBazelTarget("proto_library", "d_proto", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2612 | "srcs": `[":proto-srcs-d"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2613 | }), MakeBazelTarget("cc_lite_proto_library", "d_cc_proto_lite", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2614 | "deps": `[":d_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2615 | }), MakeBazelTarget("cc_library_static", "d_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2616 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2617 | "whole_archive_deps": `[":d_cc_proto_lite"]`, |
| 2618 | "srcs": `[":proto-srcs-d_cpp_srcs"]`, |
| 2619 | "srcs_as": `[":proto-srcs-d_as_srcs"]`, |
| 2620 | "srcs_c": `[":proto-srcs-d_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2621 | }), MakeBazelTarget("cc_library_shared", "d", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2622 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2623 | "whole_archive_deps": `[":d_cc_proto_lite"]`, |
| 2624 | "srcs": `[":proto-srcs-d_cpp_srcs"]`, |
| 2625 | "srcs_as": `[":proto-srcs-d_as_srcs"]`, |
| 2626 | "srcs_c": `[":proto-srcs-d_c_srcs"]`, |
| 2627 | }), |
| 2628 | }, |
| 2629 | }) |
| 2630 | } |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2631 | |
| 2632 | func TestCcLibraryDisabledArchAndTarget(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2633 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2634 | ModuleTypeUnderTest: "cc_library", |
| 2635 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2636 | Blueprint: soongCcProtoPreamble + `cc_library { |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2637 | name: "foo", |
| 2638 | srcs: ["foo.cpp"], |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 2639 | host_supported: true, |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2640 | target: { |
| 2641 | darwin: { |
| 2642 | enabled: false, |
| 2643 | }, |
| 2644 | windows: { |
| 2645 | enabled: false, |
| 2646 | }, |
| 2647 | linux_glibc_x86: { |
| 2648 | enabled: false, |
| 2649 | }, |
| 2650 | }, |
| 2651 | include_build_directory: false, |
| 2652 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2653 | ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2654 | "srcs": `["foo.cpp"]`, |
| 2655 | "target_compatible_with": `select({ |
| 2656 | "//build/bazel/platforms/os_arch:darwin_arm64": ["@platforms//:incompatible"], |
| 2657 | "//build/bazel/platforms/os_arch:darwin_x86_64": ["@platforms//:incompatible"], |
| 2658 | "//build/bazel/platforms/os_arch:linux_glibc_x86": ["@platforms//:incompatible"], |
| 2659 | "//build/bazel/platforms/os_arch:windows_x86": ["@platforms//:incompatible"], |
| 2660 | "//build/bazel/platforms/os_arch:windows_x86_64": ["@platforms//:incompatible"], |
| 2661 | "//conditions:default": [], |
| 2662 | })`, |
| 2663 | }), |
| 2664 | }) |
| 2665 | } |
| 2666 | |
| 2667 | func TestCcLibraryDisabledArchAndTargetWithDefault(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2668 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2669 | ModuleTypeUnderTest: "cc_library", |
| 2670 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2671 | Blueprint: soongCcProtoPreamble + `cc_library { |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2672 | name: "foo", |
| 2673 | srcs: ["foo.cpp"], |
| 2674 | enabled: false, |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 2675 | host_supported: true, |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2676 | target: { |
| 2677 | darwin: { |
| 2678 | enabled: true, |
| 2679 | }, |
| 2680 | windows: { |
| 2681 | enabled: false, |
| 2682 | }, |
| 2683 | linux_glibc_x86: { |
| 2684 | enabled: false, |
| 2685 | }, |
| 2686 | }, |
| 2687 | include_build_directory: false, |
| 2688 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2689 | ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2690 | "srcs": `["foo.cpp"]`, |
| 2691 | "target_compatible_with": `select({ |
| 2692 | "//build/bazel/platforms/os_arch:darwin_arm64": [], |
| 2693 | "//build/bazel/platforms/os_arch:darwin_x86_64": [], |
| 2694 | "//conditions:default": ["@platforms//:incompatible"], |
| 2695 | })`, |
| 2696 | }), |
| 2697 | }) |
| 2698 | } |
| 2699 | |
| 2700 | func TestCcLibrarySharedDisabled(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2701 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2702 | ModuleTypeUnderTest: "cc_library", |
| 2703 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2704 | Blueprint: soongCcProtoPreamble + `cc_library { |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2705 | name: "foo", |
| 2706 | srcs: ["foo.cpp"], |
| 2707 | enabled: false, |
| 2708 | shared: { |
| 2709 | enabled: true, |
| 2710 | }, |
| 2711 | target: { |
| 2712 | android: { |
| 2713 | shared: { |
| 2714 | enabled: false, |
| 2715 | }, |
| 2716 | } |
| 2717 | }, |
| 2718 | include_build_directory: false, |
| 2719 | }`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2720 | ExpectedBazelTargets: []string{MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2721 | "srcs": `["foo.cpp"]`, |
| 2722 | "target_compatible_with": `["@platforms//:incompatible"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2723 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2724 | "srcs": `["foo.cpp"]`, |
| 2725 | "target_compatible_with": `select({ |
| 2726 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 2727 | "//conditions:default": [], |
| 2728 | })`, |
| 2729 | }), |
| 2730 | }, |
| 2731 | }) |
| 2732 | } |
| 2733 | |
| 2734 | func TestCcLibraryStaticDisabledForSomeArch(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2735 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2736 | ModuleTypeUnderTest: "cc_library", |
| 2737 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2738 | Blueprint: soongCcProtoPreamble + `cc_library { |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2739 | name: "foo", |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 2740 | host_supported: true, |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2741 | srcs: ["foo.cpp"], |
| 2742 | shared: { |
| 2743 | enabled: false |
| 2744 | }, |
| 2745 | target: { |
| 2746 | darwin: { |
| 2747 | enabled: true, |
| 2748 | }, |
| 2749 | windows: { |
| 2750 | enabled: false, |
| 2751 | }, |
| 2752 | linux_glibc_x86: { |
| 2753 | shared: { |
| 2754 | enabled: true, |
| 2755 | }, |
| 2756 | }, |
| 2757 | }, |
| 2758 | include_build_directory: false, |
| 2759 | }`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2760 | ExpectedBazelTargets: []string{MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2761 | "srcs": `["foo.cpp"]`, |
| 2762 | "target_compatible_with": `select({ |
| 2763 | "//build/bazel/platforms/os:windows": ["@platforms//:incompatible"], |
| 2764 | "//conditions:default": [], |
| 2765 | })`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2766 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2767 | "srcs": `["foo.cpp"]`, |
| 2768 | "target_compatible_with": `select({ |
| 2769 | "//build/bazel/platforms/os_arch:darwin_arm64": [], |
| 2770 | "//build/bazel/platforms/os_arch:darwin_x86_64": [], |
| 2771 | "//build/bazel/platforms/os_arch:linux_glibc_x86": [], |
| 2772 | "//conditions:default": ["@platforms//:incompatible"], |
| 2773 | })`, |
| 2774 | }), |
| 2775 | }}) |
| 2776 | } |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 2777 | |
| 2778 | func TestCcLibraryStubs(t *testing.T) { |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 2779 | expectedBazelTargets := makeCcLibraryTargets("a", AttrNameToString{ |
Yu Liu | 56ccb1a | 2022-11-12 10:47:07 -0800 | [diff] [blame] | 2780 | "stubs_symbol_file": `"a.map.txt"`, |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 2781 | }) |
| 2782 | expectedBazelTargets = append(expectedBazelTargets, makeCcStubSuiteTargets("a", AttrNameToString{ |
| 2783 | "soname": `"a.so"`, |
| 2784 | "source_library": `":a"`, |
| 2785 | "stubs_symbol_file": `"a.map.txt"`, |
| 2786 | "stubs_versions": `[ |
| 2787 | "28", |
| 2788 | "29", |
| 2789 | "current", |
| 2790 | ]`, |
| 2791 | })) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2792 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2793 | Description: "cc_library stubs", |
| 2794 | ModuleTypeUnderTest: "cc_library", |
| 2795 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2796 | Dir: "foo/bar", |
| 2797 | Filesystem: map[string]string{ |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 2798 | "foo/bar/Android.bp": ` |
| 2799 | cc_library { |
| 2800 | name: "a", |
| 2801 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 2802 | bazel_module: { bp2build_available: true }, |
| 2803 | include_build_directory: false, |
| 2804 | } |
| 2805 | `, |
| 2806 | }, |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 2807 | Blueprint: soongCcLibraryPreamble, |
| 2808 | ExpectedBazelTargets: expectedBazelTargets, |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 2809 | }, |
| 2810 | ) |
| 2811 | } |
Liz Kammer | f38a837 | 2022-02-04 15:39:00 -0500 | [diff] [blame] | 2812 | |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2813 | func TestCcApiContributionsWithHdrs(t *testing.T) { |
| 2814 | bp := ` |
| 2815 | cc_library { |
| 2816 | name: "libfoo", |
| 2817 | stubs: { symbol_file: "libfoo.map.txt", versions: ["28", "29", "current"] }, |
| 2818 | llndk: { symbol_file: "libfoo.map.txt", override_export_include_dirs: ["dir2"]}, |
| 2819 | export_include_dirs: ["dir1"], |
| 2820 | } |
| 2821 | ` |
| 2822 | expectedBazelTargets := []string{ |
| 2823 | MakeBazelTarget( |
| 2824 | "cc_api_library_headers", |
Spandan Das | 627fc3e | 2023-01-26 23:02:00 +0000 | [diff] [blame] | 2825 | "libfoo.module-libapi.headers", |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2826 | AttrNameToString{ |
| 2827 | "export_includes": `["dir1"]`, |
| 2828 | }), |
| 2829 | MakeBazelTarget( |
| 2830 | "cc_api_library_headers", |
| 2831 | "libfoo.vendorapi.headers", |
| 2832 | AttrNameToString{ |
| 2833 | "export_includes": `["dir2"]`, |
| 2834 | }), |
| 2835 | MakeBazelTarget( |
| 2836 | "cc_api_contribution", |
| 2837 | "libfoo.contribution", |
| 2838 | AttrNameToString{ |
| 2839 | "api": `"libfoo.map.txt"`, |
| 2840 | "library_name": `"libfoo"`, |
| 2841 | "api_surfaces": `[ |
Spandan Das | 627fc3e | 2023-01-26 23:02:00 +0000 | [diff] [blame] | 2842 | "module-libapi", |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2843 | "vendorapi", |
| 2844 | ]`, |
| 2845 | "hdrs": `[ |
Spandan Das | 627fc3e | 2023-01-26 23:02:00 +0000 | [diff] [blame] | 2846 | ":libfoo.module-libapi.headers", |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2847 | ":libfoo.vendorapi.headers", |
| 2848 | ]`, |
| 2849 | }), |
| 2850 | } |
| 2851 | RunApiBp2BuildTestCase(t, cc.RegisterLibraryBuildComponents, Bp2buildTestCase{ |
| 2852 | Blueprint: bp, |
Spandan Das | 627fc3e | 2023-01-26 23:02:00 +0000 | [diff] [blame] | 2853 | Description: "cc API contributions to module-libapi and vendorapi", |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2854 | ExpectedBazelTargets: expectedBazelTargets, |
| 2855 | }) |
| 2856 | } |
| 2857 | |
| 2858 | func TestCcApiSurfaceCombinations(t *testing.T) { |
| 2859 | testCases := []struct { |
| 2860 | bp string |
| 2861 | expectedApi string |
| 2862 | expectedApiSurfaces string |
| 2863 | description string |
| 2864 | }{ |
| 2865 | { |
| 2866 | bp: ` |
| 2867 | cc_library { |
| 2868 | name: "a", |
| 2869 | stubs: {symbol_file: "a.map.txt"}, |
| 2870 | }`, |
| 2871 | expectedApi: `"a.map.txt"`, |
Spandan Das | 627fc3e | 2023-01-26 23:02:00 +0000 | [diff] [blame] | 2872 | expectedApiSurfaces: `["module-libapi"]`, |
| 2873 | description: "Library that contributes to module-libapi", |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2874 | }, |
| 2875 | { |
| 2876 | bp: ` |
| 2877 | cc_library { |
| 2878 | name: "a", |
| 2879 | llndk: {symbol_file: "a.map.txt"}, |
| 2880 | }`, |
| 2881 | expectedApi: `"a.map.txt"`, |
| 2882 | expectedApiSurfaces: `["vendorapi"]`, |
| 2883 | description: "Library that contributes to vendorapi", |
| 2884 | }, |
| 2885 | { |
| 2886 | bp: ` |
| 2887 | cc_library { |
| 2888 | name: "a", |
| 2889 | llndk: {symbol_file: "a.map.txt"}, |
| 2890 | stubs: {symbol_file: "a.map.txt"}, |
| 2891 | }`, |
| 2892 | expectedApi: `"a.map.txt"`, |
| 2893 | expectedApiSurfaces: `[ |
Spandan Das | 627fc3e | 2023-01-26 23:02:00 +0000 | [diff] [blame] | 2894 | "module-libapi", |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2895 | "vendorapi", |
| 2896 | ]`, |
Spandan Das | 627fc3e | 2023-01-26 23:02:00 +0000 | [diff] [blame] | 2897 | description: "Library that contributes to module-libapi and vendorapi", |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2898 | }, |
| 2899 | } |
| 2900 | for _, testCase := range testCases { |
| 2901 | expectedBazelTargets := []string{ |
| 2902 | MakeBazelTarget( |
| 2903 | "cc_api_contribution", |
| 2904 | "a.contribution", |
| 2905 | AttrNameToString{ |
| 2906 | "library_name": `"a"`, |
| 2907 | "hdrs": `[]`, |
| 2908 | "api": testCase.expectedApi, |
| 2909 | "api_surfaces": testCase.expectedApiSurfaces, |
| 2910 | }, |
| 2911 | ), |
| 2912 | } |
| 2913 | RunApiBp2BuildTestCase(t, cc.RegisterLibraryBuildComponents, Bp2buildTestCase{ |
| 2914 | Blueprint: testCase.bp, |
| 2915 | Description: testCase.description, |
| 2916 | ExpectedBazelTargets: expectedBazelTargets, |
| 2917 | }) |
| 2918 | } |
| 2919 | } |
| 2920 | |
| 2921 | // llndk struct property in Soong provides users with several options to configure the exported include dirs |
| 2922 | // Test the generated bazel targets for the different configurations |
| 2923 | func TestCcVendorApiHeaders(t *testing.T) { |
| 2924 | testCases := []struct { |
| 2925 | bp string |
| 2926 | expectedIncludes string |
| 2927 | expectedSystemIncludes string |
| 2928 | description string |
| 2929 | }{ |
| 2930 | { |
| 2931 | bp: ` |
| 2932 | cc_library { |
| 2933 | name: "a", |
| 2934 | export_include_dirs: ["include"], |
| 2935 | export_system_include_dirs: ["base_system_include"], |
| 2936 | llndk: { |
| 2937 | symbol_file: "a.map.txt", |
| 2938 | export_headers_as_system: true, |
| 2939 | }, |
| 2940 | } |
| 2941 | `, |
| 2942 | expectedIncludes: "", |
| 2943 | expectedSystemIncludes: `[ |
| 2944 | "base_system_include", |
| 2945 | "include", |
| 2946 | ]`, |
| 2947 | description: "Headers are exported as system to API surface", |
| 2948 | }, |
| 2949 | { |
| 2950 | bp: ` |
| 2951 | cc_library { |
| 2952 | name: "a", |
| 2953 | export_include_dirs: ["include"], |
| 2954 | export_system_include_dirs: ["base_system_include"], |
| 2955 | llndk: { |
| 2956 | symbol_file: "a.map.txt", |
| 2957 | override_export_include_dirs: ["llndk_include"], |
| 2958 | }, |
| 2959 | } |
| 2960 | `, |
| 2961 | expectedIncludes: `["llndk_include"]`, |
| 2962 | expectedSystemIncludes: `["base_system_include"]`, |
| 2963 | description: "Non-system Headers are ovverriden before export to API surface", |
| 2964 | }, |
| 2965 | { |
| 2966 | bp: ` |
| 2967 | cc_library { |
| 2968 | name: "a", |
| 2969 | export_include_dirs: ["include"], |
| 2970 | export_system_include_dirs: ["base_system_include"], |
| 2971 | llndk: { |
| 2972 | symbol_file: "a.map.txt", |
| 2973 | override_export_include_dirs: ["llndk_include"], |
| 2974 | export_headers_as_system: true, |
| 2975 | }, |
| 2976 | } |
| 2977 | `, |
| 2978 | expectedIncludes: "", // includes are set to nil |
| 2979 | expectedSystemIncludes: `[ |
| 2980 | "base_system_include", |
| 2981 | "llndk_include", |
| 2982 | ]`, |
| 2983 | description: "System Headers are extended before export to API surface", |
| 2984 | }, |
| 2985 | } |
| 2986 | for _, testCase := range testCases { |
| 2987 | attrs := AttrNameToString{} |
| 2988 | if testCase.expectedIncludes != "" { |
| 2989 | attrs["export_includes"] = testCase.expectedIncludes |
| 2990 | } |
| 2991 | if testCase.expectedSystemIncludes != "" { |
| 2992 | attrs["export_system_includes"] = testCase.expectedSystemIncludes |
| 2993 | } |
| 2994 | |
| 2995 | expectedBazelTargets := []string{ |
| 2996 | MakeBazelTarget("cc_api_library_headers", "a.vendorapi.headers", attrs), |
| 2997 | // Create a target for cc_api_contribution target |
| 2998 | MakeBazelTarget("cc_api_contribution", "a.contribution", AttrNameToString{ |
| 2999 | "api": `"a.map.txt"`, |
| 3000 | "api_surfaces": `["vendorapi"]`, |
| 3001 | "hdrs": `[":a.vendorapi.headers"]`, |
| 3002 | "library_name": `"a"`, |
| 3003 | }), |
| 3004 | } |
| 3005 | RunApiBp2BuildTestCase(t, cc.RegisterLibraryBuildComponents, Bp2buildTestCase{ |
| 3006 | Blueprint: testCase.bp, |
| 3007 | ExpectedBazelTargets: expectedBazelTargets, |
| 3008 | }) |
| 3009 | } |
| 3010 | } |
| 3011 | |
Trevor Radcliffe | 0ed6b7d | 2022-09-12 20:19:26 +0000 | [diff] [blame] | 3012 | func TestCcLibraryStubsAcrossConfigsDuplicatesRemoved(t *testing.T) { |
| 3013 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3014 | Description: "stub target generation of the same lib across configs should not result in duplicates", |
| 3015 | ModuleTypeUnderTest: "cc_library", |
| 3016 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3017 | Filesystem: map[string]string{ |
| 3018 | "bar.map.txt": "", |
| 3019 | }, |
| 3020 | Blueprint: ` |
| 3021 | cc_library { |
| 3022 | name: "barlib", |
| 3023 | stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] }, |
| 3024 | bazel_module: { bp2build_available: false }, |
| 3025 | } |
| 3026 | cc_library { |
| 3027 | name: "foolib", |
| 3028 | shared_libs: ["barlib"], |
| 3029 | target: { |
| 3030 | android: { |
| 3031 | shared_libs: ["barlib"], |
| 3032 | }, |
| 3033 | }, |
| 3034 | bazel_module: { bp2build_available: true }, |
| 3035 | }`, |
| 3036 | ExpectedBazelTargets: makeCcLibraryTargets("foolib", AttrNameToString{ |
| 3037 | "implementation_dynamic_deps": `select({ |
| 3038 | "//build/bazel/rules/apex:android-in_apex": [":barlib_stub_libs_current"], |
| 3039 | "//conditions:default": [":barlib"], |
| 3040 | })`, |
| 3041 | "local_includes": `["."]`, |
| 3042 | }), |
| 3043 | }) |
| 3044 | } |
| 3045 | |
Liz Kammer | ffc17e4 | 2022-11-23 09:42:05 -0500 | [diff] [blame] | 3046 | func TestCcLibraryExcludesLibsHost(t *testing.T) { |
| 3047 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3048 | ModuleTypeUnderTest: "cc_library", |
| 3049 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3050 | Filesystem: map[string]string{ |
| 3051 | "bar.map.txt": "", |
| 3052 | }, |
| 3053 | Blueprint: simpleModuleDoNotConvertBp2build("cc_library", "bazlib") + ` |
| 3054 | cc_library { |
| 3055 | name: "quxlib", |
| 3056 | stubs: { symbol_file: "bar.map.txt", versions: ["current"] }, |
| 3057 | bazel_module: { bp2build_available: false }, |
| 3058 | } |
| 3059 | cc_library { |
| 3060 | name: "barlib", |
| 3061 | stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] }, |
| 3062 | bazel_module: { bp2build_available: false }, |
| 3063 | } |
| 3064 | cc_library { |
| 3065 | name: "foolib", |
| 3066 | shared_libs: ["barlib", "quxlib"], |
| 3067 | target: { |
| 3068 | host: { |
| 3069 | shared_libs: ["bazlib"], |
| 3070 | exclude_shared_libs: ["barlib"], |
| 3071 | }, |
| 3072 | }, |
| 3073 | include_build_directory: false, |
| 3074 | bazel_module: { bp2build_available: true }, |
| 3075 | }`, |
| 3076 | ExpectedBazelTargets: makeCcLibraryTargets("foolib", AttrNameToString{ |
| 3077 | "implementation_dynamic_deps": `select({ |
| 3078 | "//build/bazel/platforms/os:darwin": [":bazlib"], |
Liz Kammer | ffc17e4 | 2022-11-23 09:42:05 -0500 | [diff] [blame] | 3079 | "//build/bazel/platforms/os:linux_bionic": [":bazlib"], |
Colin Cross | 133782e | 2022-12-20 15:29:31 -0800 | [diff] [blame] | 3080 | "//build/bazel/platforms/os:linux_glibc": [":bazlib"], |
Liz Kammer | ffc17e4 | 2022-11-23 09:42:05 -0500 | [diff] [blame] | 3081 | "//build/bazel/platforms/os:linux_musl": [":bazlib"], |
| 3082 | "//build/bazel/platforms/os:windows": [":bazlib"], |
| 3083 | "//conditions:default": [], |
| 3084 | }) + select({ |
| 3085 | "//build/bazel/platforms/os:darwin": [":quxlib"], |
Liz Kammer | ffc17e4 | 2022-11-23 09:42:05 -0500 | [diff] [blame] | 3086 | "//build/bazel/platforms/os:linux_bionic": [":quxlib"], |
Colin Cross | 133782e | 2022-12-20 15:29:31 -0800 | [diff] [blame] | 3087 | "//build/bazel/platforms/os:linux_glibc": [":quxlib"], |
Liz Kammer | ffc17e4 | 2022-11-23 09:42:05 -0500 | [diff] [blame] | 3088 | "//build/bazel/platforms/os:linux_musl": [":quxlib"], |
| 3089 | "//build/bazel/platforms/os:windows": [":quxlib"], |
| 3090 | "//build/bazel/rules/apex:android-in_apex": [ |
| 3091 | ":barlib_stub_libs_current", |
| 3092 | ":quxlib_stub_libs_current", |
| 3093 | ], |
| 3094 | "//conditions:default": [ |
| 3095 | ":barlib", |
| 3096 | ":quxlib", |
| 3097 | ], |
| 3098 | })`, |
| 3099 | }), |
| 3100 | }) |
| 3101 | } |
| 3102 | |
Liz Kammer | f38a837 | 2022-02-04 15:39:00 -0500 | [diff] [blame] | 3103 | func TestCcLibraryEscapeLdflags(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3104 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3105 | ModuleTypeUnderTest: "cc_library", |
| 3106 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3107 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | f38a837 | 2022-02-04 15:39:00 -0500 | [diff] [blame] | 3108 | name: "foo", |
| 3109 | ldflags: ["-Wl,--rpath,${ORIGIN}"], |
| 3110 | include_build_directory: false, |
| 3111 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3112 | ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{ |
Liz Kammer | f38a837 | 2022-02-04 15:39:00 -0500 | [diff] [blame] | 3113 | "linkopts": `["-Wl,--rpath,$${ORIGIN}"]`, |
| 3114 | }), |
| 3115 | }) |
| 3116 | } |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3117 | |
| 3118 | func TestCcLibraryConvertLex(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3119 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3120 | ModuleTypeUnderTest: "cc_library", |
| 3121 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3122 | Filesystem: map[string]string{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3123 | "foo.c": "", |
| 3124 | "bar.cc": "", |
| 3125 | "foo1.l": "", |
| 3126 | "bar1.ll": "", |
| 3127 | "foo2.l": "", |
| 3128 | "bar2.ll": "", |
| 3129 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3130 | Blueprint: `cc_library { |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3131 | name: "foo_lib", |
| 3132 | srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"], |
| 3133 | lex: { flags: ["--foo_flags"] }, |
| 3134 | include_build_directory: false, |
| 3135 | bazel_module: { bp2build_available: true }, |
| 3136 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3137 | ExpectedBazelTargets: append([]string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3138 | MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3139 | "srcs": `[ |
| 3140 | "foo1.l", |
| 3141 | "foo2.l", |
| 3142 | ]`, |
| 3143 | "lexopts": `["--foo_flags"]`, |
| 3144 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3145 | MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3146 | "srcs": `[ |
| 3147 | "bar1.ll", |
| 3148 | "bar2.ll", |
| 3149 | ]`, |
| 3150 | "lexopts": `["--foo_flags"]`, |
| 3151 | }), |
| 3152 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3153 | makeCcLibraryTargets("foo_lib", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3154 | "srcs": `[ |
| 3155 | "bar.cc", |
| 3156 | ":foo_lib_genlex_ll", |
| 3157 | ]`, |
| 3158 | "srcs_c": `[ |
| 3159 | "foo.c", |
| 3160 | ":foo_lib_genlex_l", |
| 3161 | ]`, |
| 3162 | })...), |
| 3163 | }) |
| 3164 | } |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 3165 | |
| 3166 | func TestCCLibraryRuntimeDeps(t *testing.T) { |
| 3167 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 3168 | Blueprint: `cc_library_shared { |
| 3169 | name: "bar", |
| 3170 | } |
| 3171 | |
| 3172 | cc_library { |
| 3173 | name: "foo", |
| 3174 | runtime_libs: ["foo"], |
| 3175 | }`, |
| 3176 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3177 | MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{ |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 3178 | "local_includes": `["."]`, |
| 3179 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3180 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 3181 | "runtime_deps": `[":foo"]`, |
| 3182 | "local_includes": `["."]`, |
| 3183 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3184 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 3185 | "runtime_deps": `[":foo"]`, |
| 3186 | "local_includes": `["."]`, |
| 3187 | }), |
| 3188 | }, |
| 3189 | }) |
| 3190 | } |
Cole Faust | 5fa4e96 | 2022-08-22 14:31:04 -0700 | [diff] [blame] | 3191 | |
| 3192 | func TestCcLibraryWithInstructionSet(t *testing.T) { |
| 3193 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3194 | ModuleTypeUnderTest: "cc_library", |
| 3195 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3196 | Blueprint: `cc_library { |
| 3197 | name: "foo", |
| 3198 | arch: { |
| 3199 | arm: { |
| 3200 | instruction_set: "arm", |
| 3201 | } |
| 3202 | } |
| 3203 | } |
| 3204 | `, |
| 3205 | ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{ |
| 3206 | "features": `select({ |
| 3207 | "//build/bazel/platforms/arch:arm": [ |
| 3208 | "arm_isa_arm", |
| 3209 | "-arm_isa_thumb", |
| 3210 | ], |
| 3211 | "//conditions:default": [], |
| 3212 | })`, |
| 3213 | "local_includes": `["."]`, |
| 3214 | }), |
| 3215 | }) |
| 3216 | } |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3217 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 3218 | func TestCcLibraryEmptySuffix(t *testing.T) { |
| 3219 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3220 | Description: "cc_library with empty suffix", |
| 3221 | ModuleTypeUnderTest: "cc_library", |
| 3222 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3223 | Filesystem: map[string]string{ |
| 3224 | "foo.c": "", |
| 3225 | }, |
| 3226 | Blueprint: `cc_library { |
| 3227 | name: "foo", |
| 3228 | suffix: "", |
| 3229 | srcs: ["foo.c"], |
| 3230 | include_build_directory: false, |
| 3231 | }`, |
| 3232 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3233 | 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] | 3234 | "srcs_c": `["foo.c"]`, |
| 3235 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3236 | 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] | 3237 | "srcs_c": `["foo.c"]`, |
| 3238 | "suffix": `""`, |
| 3239 | }), |
| 3240 | }, |
| 3241 | }) |
| 3242 | } |
| 3243 | |
| 3244 | func TestCcLibrarySuffix(t *testing.T) { |
| 3245 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3246 | Description: "cc_library with suffix", |
| 3247 | ModuleTypeUnderTest: "cc_library", |
| 3248 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3249 | Filesystem: map[string]string{ |
| 3250 | "foo.c": "", |
| 3251 | }, |
| 3252 | Blueprint: `cc_library { |
| 3253 | name: "foo", |
| 3254 | suffix: "-suf", |
| 3255 | srcs: ["foo.c"], |
| 3256 | include_build_directory: false, |
| 3257 | }`, |
| 3258 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3259 | 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] | 3260 | "srcs_c": `["foo.c"]`, |
| 3261 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3262 | 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] | 3263 | "srcs_c": `["foo.c"]`, |
| 3264 | "suffix": `"-suf"`, |
| 3265 | }), |
| 3266 | }, |
| 3267 | }) |
| 3268 | } |
| 3269 | |
| 3270 | func TestCcLibraryArchVariantSuffix(t *testing.T) { |
| 3271 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3272 | Description: "cc_library with arch-variant suffix", |
| 3273 | ModuleTypeUnderTest: "cc_library", |
| 3274 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3275 | Filesystem: map[string]string{ |
| 3276 | "foo.c": "", |
| 3277 | }, |
| 3278 | Blueprint: `cc_library { |
| 3279 | name: "foo", |
| 3280 | arch: { |
| 3281 | arm64: { suffix: "-64" }, |
| 3282 | arm: { suffix: "-32" }, |
| 3283 | }, |
| 3284 | srcs: ["foo.c"], |
| 3285 | include_build_directory: false, |
| 3286 | }`, |
| 3287 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3288 | 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] | 3289 | "srcs_c": `["foo.c"]`, |
| 3290 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3291 | 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] | 3292 | "srcs_c": `["foo.c"]`, |
| 3293 | "suffix": `select({ |
| 3294 | "//build/bazel/platforms/arch:arm": "-32", |
| 3295 | "//build/bazel/platforms/arch:arm64": "-64", |
| 3296 | "//conditions:default": None, |
| 3297 | })`, |
| 3298 | }), |
| 3299 | }, |
| 3300 | }) |
| 3301 | } |
| 3302 | |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3303 | func TestCcLibraryWithAidlSrcs(t *testing.T) { |
| 3304 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3305 | Description: "cc_library with aidl srcs", |
| 3306 | ModuleTypeUnderTest: "cc_library", |
| 3307 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3308 | Blueprint: ` |
| 3309 | filegroup { |
| 3310 | name: "A_aidl", |
| 3311 | srcs: ["aidl/A.aidl"], |
| 3312 | path: "aidl", |
| 3313 | } |
| 3314 | cc_library { |
| 3315 | name: "foo", |
| 3316 | srcs: [ |
| 3317 | ":A_aidl", |
| 3318 | "B.aidl", |
| 3319 | ], |
| 3320 | }`, |
| 3321 | ExpectedBazelTargets: []string{ |
| 3322 | MakeBazelTargetNoRestrictions("aidl_library", "A_aidl", AttrNameToString{ |
| 3323 | "srcs": `["aidl/A.aidl"]`, |
| 3324 | "strip_import_prefix": `"aidl"`, |
| 3325 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3326 | MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{ |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3327 | "srcs": `["B.aidl"]`, |
| 3328 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3329 | MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3330 | "deps": `[ |
| 3331 | ":A_aidl", |
| 3332 | ":foo_aidl_library", |
| 3333 | ]`, |
| 3334 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3335 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3336 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3337 | "local_includes": `["."]`, |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3338 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3339 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 3340 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3341 | "local_includes": `["."]`, |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3342 | }), |
| 3343 | }, |
| 3344 | }) |
| 3345 | } |
| 3346 | |
| 3347 | func TestCcLibraryWithNonAdjacentAidlFilegroup(t *testing.T) { |
| 3348 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3349 | Description: "cc_library with non aidl filegroup", |
| 3350 | ModuleTypeUnderTest: "cc_library", |
| 3351 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3352 | Filesystem: map[string]string{ |
| 3353 | "path/to/A/Android.bp": ` |
| 3354 | filegroup { |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3355 | name: "A_aidl", |
| 3356 | srcs: ["aidl/A.aidl"], |
| 3357 | path: "aidl", |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3358 | }`, |
| 3359 | }, |
| 3360 | Blueprint: ` |
| 3361 | cc_library { |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3362 | name: "foo", |
| 3363 | srcs: [ |
| 3364 | ":A_aidl", |
| 3365 | ], |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3366 | }`, |
| 3367 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3368 | MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3369 | "deps": `["//path/to/A:A_aidl"]`, |
| 3370 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3371 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3372 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3373 | "local_includes": `["."]`, |
| 3374 | }), |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3375 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 3376 | "local_includes": `["."]`, |
| 3377 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3378 | }), |
| 3379 | }, |
| 3380 | }) |
| 3381 | } |
| 3382 | |
| 3383 | func TestCcLibraryWithExportAidlHeaders(t *testing.T) { |
| 3384 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3385 | Description: "cc_library with export aidl headers", |
| 3386 | ModuleTypeUnderTest: "cc_library", |
| 3387 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3388 | Blueprint: ` |
| 3389 | cc_library { |
| 3390 | name: "foo", |
| 3391 | srcs: [ |
| 3392 | "Foo.aidl", |
| 3393 | ], |
| 3394 | aidl: { |
| 3395 | export_aidl_headers: true, |
| 3396 | } |
| 3397 | }`, |
| 3398 | ExpectedBazelTargets: []string{ |
| 3399 | MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{ |
| 3400 | "srcs": `["Foo.aidl"]`, |
| 3401 | }), |
| 3402 | MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ |
| 3403 | "deps": `[":foo_aidl_library"]`, |
| 3404 | }), |
| 3405 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3406 | "whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3407 | "local_includes": `["."]`, |
| 3408 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3409 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3410 | "whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3411 | "local_includes": `["."]`, |
| 3412 | }), |
| 3413 | }, |
| 3414 | }) |
| 3415 | } |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3416 | |
| 3417 | func TestCcLibraryWithTargetApex(t *testing.T) { |
| 3418 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3419 | Description: "cc_library with target.apex", |
| 3420 | ModuleTypeUnderTest: "cc_library", |
| 3421 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3422 | Blueprint: ` |
| 3423 | cc_library { |
| 3424 | name: "foo", |
| 3425 | shared_libs: ["bar", "baz"], |
| 3426 | static_libs: ["baz", "buh"], |
| 3427 | target: { |
| 3428 | apex: { |
| 3429 | exclude_shared_libs: ["bar"], |
| 3430 | exclude_static_libs: ["buh"], |
| 3431 | } |
| 3432 | } |
| 3433 | }`, |
| 3434 | ExpectedBazelTargets: []string{ |
| 3435 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 3436 | "implementation_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({ |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 3437 | "//build/bazel/rules/apex:in_apex": [], |
| 3438 | "//conditions:default": [":buh__BP2BUILD__MISSING__DEP"], |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3439 | })`, |
| 3440 | "implementation_dynamic_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({ |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 3441 | "//build/bazel/rules/apex:in_apex": [], |
| 3442 | "//conditions:default": [":bar__BP2BUILD__MISSING__DEP"], |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3443 | })`, |
| 3444 | "local_includes": `["."]`, |
| 3445 | }), |
| 3446 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 3447 | "implementation_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({ |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 3448 | "//build/bazel/rules/apex:in_apex": [], |
| 3449 | "//conditions:default": [":buh__BP2BUILD__MISSING__DEP"], |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3450 | })`, |
| 3451 | "implementation_dynamic_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({ |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 3452 | "//build/bazel/rules/apex:in_apex": [], |
| 3453 | "//conditions:default": [":bar__BP2BUILD__MISSING__DEP"], |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3454 | })`, |
| 3455 | "local_includes": `["."]`, |
| 3456 | }), |
| 3457 | }, |
| 3458 | }) |
| 3459 | } |
| 3460 | |
| 3461 | func TestCcLibraryWithTargetApexAndExportLibHeaders(t *testing.T) { |
| 3462 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3463 | Description: "cc_library with target.apex and export_shared|static_lib_headers", |
| 3464 | ModuleTypeUnderTest: "cc_library", |
| 3465 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3466 | Blueprint: ` |
| 3467 | cc_library_static { |
| 3468 | name: "foo", |
| 3469 | shared_libs: ["bar", "baz"], |
| 3470 | static_libs: ["abc"], |
| 3471 | export_shared_lib_headers: ["baz"], |
| 3472 | export_static_lib_headers: ["abc"], |
| 3473 | target: { |
| 3474 | apex: { |
| 3475 | exclude_shared_libs: ["baz", "bar"], |
| 3476 | exclude_static_libs: ["abc"], |
| 3477 | } |
| 3478 | } |
| 3479 | }`, |
| 3480 | ExpectedBazelTargets: []string{ |
| 3481 | MakeBazelTarget("cc_library_static", "foo", AttrNameToString{ |
| 3482 | "implementation_dynamic_deps": `select({ |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 3483 | "//build/bazel/rules/apex:in_apex": [], |
| 3484 | "//conditions:default": [":bar__BP2BUILD__MISSING__DEP"], |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3485 | })`, |
| 3486 | "dynamic_deps": `select({ |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 3487 | "//build/bazel/rules/apex:in_apex": [], |
| 3488 | "//conditions:default": [":baz__BP2BUILD__MISSING__DEP"], |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3489 | })`, |
| 3490 | "deps": `select({ |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 3491 | "//build/bazel/rules/apex:in_apex": [], |
| 3492 | "//conditions:default": [":abc__BP2BUILD__MISSING__DEP"], |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3493 | })`, |
| 3494 | "local_includes": `["."]`, |
| 3495 | }), |
| 3496 | }, |
| 3497 | }) |
| 3498 | } |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 3499 | |
| 3500 | func TestCcLibraryWithSyspropSrcs(t *testing.T) { |
| 3501 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3502 | Description: "cc_library with sysprop sources", |
| 3503 | ModuleTypeUnderTest: "cc_library", |
| 3504 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3505 | Blueprint: ` |
| 3506 | cc_library { |
| 3507 | name: "foo", |
| 3508 | srcs: [ |
| 3509 | "bar.sysprop", |
| 3510 | "baz.sysprop", |
| 3511 | "blah.cpp", |
| 3512 | ], |
| 3513 | min_sdk_version: "5", |
| 3514 | }`, |
| 3515 | ExpectedBazelTargets: []string{ |
| 3516 | MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{ |
| 3517 | "srcs": `[ |
| 3518 | "bar.sysprop", |
| 3519 | "baz.sysprop", |
| 3520 | ]`, |
| 3521 | }), |
| 3522 | MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{ |
| 3523 | "dep": `":foo_sysprop_library"`, |
| 3524 | "min_sdk_version": `"5"`, |
| 3525 | }), |
| 3526 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 3527 | "srcs": `["blah.cpp"]`, |
| 3528 | "local_includes": `["."]`, |
| 3529 | "min_sdk_version": `"5"`, |
| 3530 | "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`, |
| 3531 | }), |
| 3532 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 3533 | "srcs": `["blah.cpp"]`, |
| 3534 | "local_includes": `["."]`, |
| 3535 | "min_sdk_version": `"5"`, |
| 3536 | "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`, |
| 3537 | }), |
| 3538 | }, |
| 3539 | }) |
| 3540 | } |
| 3541 | |
| 3542 | func TestCcLibraryWithSyspropSrcsSomeConfigs(t *testing.T) { |
| 3543 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3544 | Description: "cc_library with sysprop sources in some configs but not others", |
| 3545 | ModuleTypeUnderTest: "cc_library", |
| 3546 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3547 | Blueprint: ` |
| 3548 | cc_library { |
| 3549 | name: "foo", |
| 3550 | host_supported: true, |
| 3551 | srcs: [ |
| 3552 | "blah.cpp", |
| 3553 | ], |
| 3554 | target: { |
| 3555 | android: { |
| 3556 | srcs: ["bar.sysprop"], |
| 3557 | }, |
| 3558 | }, |
| 3559 | min_sdk_version: "5", |
| 3560 | }`, |
| 3561 | ExpectedBazelTargets: []string{ |
| 3562 | MakeBazelTargetNoRestrictions("sysprop_library", "foo_sysprop_library", AttrNameToString{ |
| 3563 | "srcs": `select({ |
| 3564 | "//build/bazel/platforms/os:android": ["bar.sysprop"], |
| 3565 | "//conditions:default": [], |
| 3566 | })`, |
| 3567 | }), |
| 3568 | MakeBazelTargetNoRestrictions("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{ |
| 3569 | "dep": `":foo_sysprop_library"`, |
| 3570 | "min_sdk_version": `"5"`, |
| 3571 | }), |
| 3572 | MakeBazelTargetNoRestrictions("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 3573 | "srcs": `["blah.cpp"]`, |
| 3574 | "local_includes": `["."]`, |
| 3575 | "min_sdk_version": `"5"`, |
| 3576 | "whole_archive_deps": `select({ |
| 3577 | "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"], |
| 3578 | "//conditions:default": [], |
| 3579 | })`, |
| 3580 | }), |
| 3581 | MakeBazelTargetNoRestrictions("cc_library_shared", "foo", AttrNameToString{ |
| 3582 | "srcs": `["blah.cpp"]`, |
| 3583 | "local_includes": `["."]`, |
| 3584 | "min_sdk_version": `"5"`, |
| 3585 | "whole_archive_deps": `select({ |
| 3586 | "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"], |
| 3587 | "//conditions:default": [], |
| 3588 | })`, |
| 3589 | }), |
| 3590 | }, |
| 3591 | }) |
| 3592 | } |
Vinh Tran | 395a1e9 | 2022-09-16 18:27:29 -0400 | [diff] [blame] | 3593 | |
| 3594 | func TestCcLibraryWithAidlAndSharedLibs(t *testing.T) { |
| 3595 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3596 | Description: "cc_aidl_library depends on shared libs from parent cc_library_static", |
| 3597 | ModuleTypeUnderTest: "cc_library", |
| 3598 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3599 | Blueprint: ` |
| 3600 | cc_library_static { |
| 3601 | name: "foo", |
| 3602 | srcs: [ |
| 3603 | "Foo.aidl", |
| 3604 | ], |
| 3605 | shared_libs: [ |
| 3606 | "bar", |
| 3607 | "baz", |
| 3608 | ], |
| 3609 | export_shared_lib_headers: [ |
| 3610 | "baz", |
| 3611 | ], |
| 3612 | }` + |
| 3613 | simpleModuleDoNotConvertBp2build("cc_library", "bar") + |
| 3614 | simpleModuleDoNotConvertBp2build("cc_library", "baz"), |
| 3615 | ExpectedBazelTargets: []string{ |
| 3616 | MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{ |
| 3617 | "srcs": `["Foo.aidl"]`, |
| 3618 | }), |
| 3619 | MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ |
| 3620 | "deps": `[":foo_aidl_library"]`, |
| 3621 | "implementation_dynamic_deps": `[ |
| 3622 | ":baz", |
| 3623 | ":bar", |
| 3624 | ]`, |
| 3625 | }), |
| 3626 | MakeBazelTarget("cc_library_static", "foo", AttrNameToString{ |
| 3627 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3628 | "dynamic_deps": `[":baz"]`, |
| 3629 | "implementation_dynamic_deps": `[":bar"]`, |
| 3630 | "local_includes": `["."]`, |
| 3631 | }), |
| 3632 | }, |
| 3633 | }) |
| 3634 | } |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 3635 | |
| 3636 | func TestCcLibraryWithTidy(t *testing.T) { |
| 3637 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3638 | Description: "cc_library uses tidy properties", |
| 3639 | ModuleTypeUnderTest: "cc_library", |
| 3640 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3641 | Blueprint: ` |
| 3642 | cc_library_static { |
Sam Delmerico | 63f0c93 | 2023-03-14 14:05:28 -0400 | [diff] [blame^] | 3643 | name: "foo", |
| 3644 | srcs: ["foo.cpp"], |
| 3645 | } |
| 3646 | cc_library_static { |
| 3647 | name: "foo-no-tidy", |
| 3648 | srcs: ["foo.cpp"], |
| 3649 | tidy: false, |
| 3650 | } |
| 3651 | cc_library_static { |
| 3652 | name: "foo-tidy", |
| 3653 | srcs: ["foo.cpp"], |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 3654 | tidy: true, |
| 3655 | tidy_checks: ["check1", "check2"], |
| 3656 | tidy_checks_as_errors: ["check1error", "check2error"], |
| 3657 | tidy_disabled_srcs: ["bar.cpp"], |
Sam Delmerico | 4c902d6 | 2022-11-02 14:17:15 -0400 | [diff] [blame] | 3658 | tidy_timeout_srcs: ["baz.cpp"], |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 3659 | }`, |
| 3660 | ExpectedBazelTargets: []string{ |
| 3661 | MakeBazelTarget("cc_library_static", "foo", AttrNameToString{ |
| 3662 | "local_includes": `["."]`, |
| 3663 | "srcs": `["foo.cpp"]`, |
Sam Delmerico | 63f0c93 | 2023-03-14 14:05:28 -0400 | [diff] [blame^] | 3664 | }), |
| 3665 | MakeBazelTarget("cc_library_static", "foo-no-tidy", AttrNameToString{ |
| 3666 | "local_includes": `["."]`, |
| 3667 | "srcs": `["foo.cpp"]`, |
| 3668 | "tidy": `"never"`, |
| 3669 | }), |
| 3670 | MakeBazelTarget("cc_library_static", "foo-tidy", AttrNameToString{ |
| 3671 | "local_includes": `["."]`, |
| 3672 | "srcs": `["foo.cpp"]`, |
| 3673 | "tidy": `"local"`, |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 3674 | "tidy_checks": `[ |
| 3675 | "check1", |
| 3676 | "check2", |
| 3677 | ]`, |
| 3678 | "tidy_checks_as_errors": `[ |
| 3679 | "check1error", |
| 3680 | "check2error", |
| 3681 | ]`, |
| 3682 | "tidy_disabled_srcs": `["bar.cpp"]`, |
Sam Delmerico | 4c902d6 | 2022-11-02 14:17:15 -0400 | [diff] [blame] | 3683 | "tidy_timeout_srcs": `["baz.cpp"]`, |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 3684 | }), |
| 3685 | }, |
| 3686 | }) |
| 3687 | } |
Yu Liu | 56ccb1a | 2022-11-12 10:47:07 -0800 | [diff] [blame] | 3688 | |
Vinh Tran | 99270ea | 2022-11-28 11:15:23 -0500 | [diff] [blame] | 3689 | func TestCcLibraryWithAfdoEnabled(t *testing.T) { |
| 3690 | bp := ` |
| 3691 | cc_library { |
| 3692 | name: "foo", |
| 3693 | afdo: true, |
| 3694 | include_build_directory: false, |
| 3695 | }` |
| 3696 | |
| 3697 | // TODO(b/260714900): Add test case for arch-specific afdo profile |
| 3698 | testCases := []struct { |
| 3699 | description string |
| 3700 | filesystem map[string]string |
| 3701 | expectedBazelTargets []string |
| 3702 | }{ |
| 3703 | { |
| 3704 | description: "cc_library with afdo enabled and existing profile", |
Vinh Tran | bc9c8b4 | 2022-12-09 12:03:52 -0500 | [diff] [blame] | 3705 | filesystem: map[string]string{ |
| 3706 | "vendor/google_data/pgo_profile/sampling/BUILD": "", |
| 3707 | "vendor/google_data/pgo_profile/sampling/foo.afdo": "", |
| 3708 | }, |
Vinh Tran | 99270ea | 2022-11-28 11:15:23 -0500 | [diff] [blame] | 3709 | expectedBazelTargets: []string{ |
| 3710 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), |
| 3711 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 3712 | "fdo_profile": `"//vendor/google_data/pgo_profile/sampling:foo"`, |
| 3713 | }), |
| 3714 | }, |
| 3715 | }, |
| 3716 | { |
| 3717 | description: "cc_library with afdo enabled and existing profile in AOSP", |
Vinh Tran | bc9c8b4 | 2022-12-09 12:03:52 -0500 | [diff] [blame] | 3718 | filesystem: map[string]string{ |
| 3719 | "toolchain/pgo-profiles/sampling/BUILD": "", |
| 3720 | "toolchain/pgo-profiles/sampling/foo.afdo": "", |
| 3721 | }, |
Vinh Tran | 99270ea | 2022-11-28 11:15:23 -0500 | [diff] [blame] | 3722 | expectedBazelTargets: []string{ |
| 3723 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), |
| 3724 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 3725 | "fdo_profile": `"//toolchain/pgo-profiles/sampling:foo"`, |
| 3726 | }), |
| 3727 | }, |
| 3728 | }, |
| 3729 | { |
| 3730 | description: "cc_library with afdo enabled but profile filename doesn't match with module name", |
Vinh Tran | bc9c8b4 | 2022-12-09 12:03:52 -0500 | [diff] [blame] | 3731 | filesystem: map[string]string{ |
| 3732 | "toolchain/pgo-profiles/sampling/BUILD": "", |
| 3733 | "toolchain/pgo-profiles/sampling/bar.afdo": "", |
| 3734 | }, |
Vinh Tran | 99270ea | 2022-11-28 11:15:23 -0500 | [diff] [blame] | 3735 | expectedBazelTargets: []string{ |
| 3736 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), |
| 3737 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{}), |
| 3738 | }, |
| 3739 | }, |
| 3740 | { |
| 3741 | description: "cc_library with afdo enabled but profile doesn't exist", |
| 3742 | expectedBazelTargets: []string{ |
| 3743 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), |
| 3744 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{}), |
| 3745 | }, |
| 3746 | }, |
Vinh Tran | bc9c8b4 | 2022-12-09 12:03:52 -0500 | [diff] [blame] | 3747 | { |
| 3748 | description: "cc_library with afdo enabled and existing profile but BUILD file doesn't exist", |
| 3749 | filesystem: map[string]string{ |
| 3750 | "vendor/google_data/pgo_profile/sampling/foo.afdo": "", |
| 3751 | }, |
| 3752 | expectedBazelTargets: []string{ |
| 3753 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), |
| 3754 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{}), |
| 3755 | }, |
| 3756 | }, |
Vinh Tran | 99270ea | 2022-11-28 11:15:23 -0500 | [diff] [blame] | 3757 | } |
| 3758 | for _, testCase := range testCases { |
| 3759 | t.Run(testCase.description, func(t *testing.T) { |
| 3760 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3761 | ExpectedBazelTargets: testCase.expectedBazelTargets, |
| 3762 | ModuleTypeUnderTest: "cc_library", |
| 3763 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3764 | Description: testCase.description, |
| 3765 | Blueprint: binaryReplacer.Replace(bp), |
| 3766 | Filesystem: testCase.filesystem, |
| 3767 | }) |
| 3768 | }) |
| 3769 | } |
| 3770 | } |
| 3771 | |
Yu Liu | 56ccb1a | 2022-11-12 10:47:07 -0800 | [diff] [blame] | 3772 | func TestCcLibraryHeaderAbiChecker(t *testing.T) { |
| 3773 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3774 | Description: "cc_library with header abi checker", |
| 3775 | ModuleTypeUnderTest: "cc_library", |
| 3776 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3777 | Blueprint: `cc_library { |
| 3778 | name: "foo", |
| 3779 | header_abi_checker: { |
| 3780 | enabled: true, |
| 3781 | symbol_file: "a.map.txt", |
| 3782 | exclude_symbol_versions: [ |
| 3783 | "29", |
| 3784 | "30", |
| 3785 | ], |
| 3786 | exclude_symbol_tags: [ |
| 3787 | "tag1", |
| 3788 | "tag2", |
| 3789 | ], |
| 3790 | check_all_apis: true, |
| 3791 | diff_flags: ["-allow-adding-removing-weak-symbols"], |
| 3792 | }, |
| 3793 | include_build_directory: false, |
| 3794 | }`, |
| 3795 | ExpectedBazelTargets: []string{ |
| 3796 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), |
| 3797 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 3798 | "abi_checker_enabled": `True`, |
| 3799 | "abi_checker_symbol_file": `"a.map.txt"`, |
| 3800 | "abi_checker_exclude_symbol_versions": `[ |
| 3801 | "29", |
| 3802 | "30", |
| 3803 | ]`, |
| 3804 | "abi_checker_exclude_symbol_tags": `[ |
| 3805 | "tag1", |
| 3806 | "tag2", |
| 3807 | ]`, |
| 3808 | "abi_checker_check_all_apis": `True`, |
| 3809 | "abi_checker_diff_flags": `["-allow-adding-removing-weak-symbols"]`, |
| 3810 | }), |
| 3811 | }, |
| 3812 | }) |
| 3813 | } |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 3814 | |
| 3815 | func TestCcLibraryApexAvailable(t *testing.T) { |
| 3816 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3817 | Description: "cc_library apex_available converted to tags", |
| 3818 | ModuleTypeUnderTest: "cc_library", |
| 3819 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3820 | Blueprint: soongCcLibraryPreamble + ` |
| 3821 | cc_library { |
| 3822 | name: "a", |
| 3823 | srcs: ["a.cpp"], |
| 3824 | apex_available: ["com.android.foo"], |
| 3825 | } |
| 3826 | `, |
| 3827 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
| 3828 | "tags": `["apex_available=com.android.foo"]`, |
| 3829 | "srcs": `["a.cpp"]`, |
| 3830 | "local_includes": `["."]`, |
| 3831 | }), |
| 3832 | }, |
| 3833 | ) |
| 3834 | } |
| 3835 | |
| 3836 | func TestCcLibraryApexAvailableMultiple(t *testing.T) { |
| 3837 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3838 | Description: "cc_library apex_available converted to multiple tags", |
| 3839 | ModuleTypeUnderTest: "cc_library", |
| 3840 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3841 | Blueprint: soongCcLibraryPreamble + ` |
| 3842 | cc_library { |
| 3843 | name: "a", |
| 3844 | srcs: ["a.cpp"], |
| 3845 | apex_available: ["com.android.foo", "//apex_available:platform", "com.android.bar"], |
| 3846 | } |
| 3847 | `, |
| 3848 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
| 3849 | "tags": `[ |
| 3850 | "apex_available=com.android.foo", |
| 3851 | "apex_available=//apex_available:platform", |
| 3852 | "apex_available=com.android.bar", |
| 3853 | ]`, |
| 3854 | "srcs": `["a.cpp"]`, |
| 3855 | "local_includes": `["."]`, |
| 3856 | }), |
| 3857 | }, |
| 3858 | ) |
| 3859 | } |
Zi Wang | 0f82844 | 2022-12-28 11:18:11 -0800 | [diff] [blame] | 3860 | |
| 3861 | // Export_include_dirs and Export_system_include_dirs have "variant_prepend" tag. |
| 3862 | // In bp2build output, variant info(select) should go before general info. |
| 3863 | // Internal order of the property should be unchanged. (e.g. ["eid1", "eid2"]) |
| 3864 | func TestCcLibraryVariantPrependPropOrder(t *testing.T) { |
| 3865 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3866 | Description: "cc_library variant prepend properties order", |
| 3867 | ModuleTypeUnderTest: "cc_library", |
| 3868 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3869 | Blueprint: soongCcLibraryPreamble + ` |
| 3870 | cc_library { |
| 3871 | name: "a", |
| 3872 | srcs: ["a.cpp"], |
| 3873 | export_include_dirs: ["eid1", "eid2"], |
| 3874 | export_system_include_dirs: ["esid1", "esid2"], |
| 3875 | target: { |
| 3876 | android: { |
| 3877 | export_include_dirs: ["android_eid1", "android_eid2"], |
| 3878 | export_system_include_dirs: ["android_esid1", "android_esid2"], |
| 3879 | }, |
| 3880 | android_arm: { |
| 3881 | export_include_dirs: ["android_arm_eid1", "android_arm_eid2"], |
| 3882 | export_system_include_dirs: ["android_arm_esid1", "android_arm_esid2"], |
| 3883 | }, |
| 3884 | linux: { |
| 3885 | export_include_dirs: ["linux_eid1", "linux_eid2"], |
| 3886 | export_system_include_dirs: ["linux_esid1", "linux_esid2"], |
| 3887 | }, |
| 3888 | }, |
| 3889 | multilib: { |
| 3890 | lib32: { |
| 3891 | export_include_dirs: ["lib32_eid1", "lib32_eid2"], |
| 3892 | export_system_include_dirs: ["lib32_esid1", "lib32_esid2"], |
| 3893 | }, |
| 3894 | }, |
| 3895 | arch: { |
| 3896 | arm: { |
| 3897 | export_include_dirs: ["arm_eid1", "arm_eid2"], |
| 3898 | export_system_include_dirs: ["arm_esid1", "arm_esid2"], |
| 3899 | }, |
| 3900 | } |
| 3901 | } |
| 3902 | `, |
| 3903 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
| 3904 | "export_includes": `select({ |
| 3905 | "//build/bazel/platforms/os_arch:android_arm": [ |
| 3906 | "android_arm_eid1", |
| 3907 | "android_arm_eid2", |
| 3908 | ], |
| 3909 | "//conditions:default": [], |
| 3910 | }) + select({ |
| 3911 | "//build/bazel/platforms/os:android": [ |
| 3912 | "android_eid1", |
| 3913 | "android_eid2", |
| 3914 | "linux_eid1", |
| 3915 | "linux_eid2", |
| 3916 | ], |
| 3917 | "//build/bazel/platforms/os:linux_bionic": [ |
| 3918 | "linux_eid1", |
| 3919 | "linux_eid2", |
| 3920 | ], |
| 3921 | "//build/bazel/platforms/os:linux_glibc": [ |
| 3922 | "linux_eid1", |
| 3923 | "linux_eid2", |
| 3924 | ], |
| 3925 | "//build/bazel/platforms/os:linux_musl": [ |
| 3926 | "linux_eid1", |
| 3927 | "linux_eid2", |
| 3928 | ], |
| 3929 | "//conditions:default": [], |
| 3930 | }) + select({ |
| 3931 | "//build/bazel/platforms/arch:arm": [ |
| 3932 | "lib32_eid1", |
| 3933 | "lib32_eid2", |
| 3934 | "arm_eid1", |
| 3935 | "arm_eid2", |
| 3936 | ], |
| 3937 | "//build/bazel/platforms/arch:x86": [ |
| 3938 | "lib32_eid1", |
| 3939 | "lib32_eid2", |
| 3940 | ], |
| 3941 | "//conditions:default": [], |
| 3942 | }) + [ |
| 3943 | "eid1", |
| 3944 | "eid2", |
| 3945 | ]`, |
| 3946 | "export_system_includes": `select({ |
| 3947 | "//build/bazel/platforms/os_arch:android_arm": [ |
| 3948 | "android_arm_esid1", |
| 3949 | "android_arm_esid2", |
| 3950 | ], |
| 3951 | "//conditions:default": [], |
| 3952 | }) + select({ |
| 3953 | "//build/bazel/platforms/os:android": [ |
| 3954 | "android_esid1", |
| 3955 | "android_esid2", |
| 3956 | "linux_esid1", |
| 3957 | "linux_esid2", |
| 3958 | ], |
| 3959 | "//build/bazel/platforms/os:linux_bionic": [ |
| 3960 | "linux_esid1", |
| 3961 | "linux_esid2", |
| 3962 | ], |
| 3963 | "//build/bazel/platforms/os:linux_glibc": [ |
| 3964 | "linux_esid1", |
| 3965 | "linux_esid2", |
| 3966 | ], |
| 3967 | "//build/bazel/platforms/os:linux_musl": [ |
| 3968 | "linux_esid1", |
| 3969 | "linux_esid2", |
| 3970 | ], |
| 3971 | "//conditions:default": [], |
| 3972 | }) + select({ |
| 3973 | "//build/bazel/platforms/arch:arm": [ |
| 3974 | "lib32_esid1", |
| 3975 | "lib32_esid2", |
| 3976 | "arm_esid1", |
| 3977 | "arm_esid2", |
| 3978 | ], |
| 3979 | "//build/bazel/platforms/arch:x86": [ |
| 3980 | "lib32_esid1", |
| 3981 | "lib32_esid2", |
| 3982 | ], |
| 3983 | "//conditions:default": [], |
| 3984 | }) + [ |
| 3985 | "esid1", |
| 3986 | "esid2", |
| 3987 | ]`, |
| 3988 | "srcs": `["a.cpp"]`, |
| 3989 | "local_includes": `["."]`, |
| 3990 | "target_compatible_with": `["//build/bazel/platforms/os:android"]`, |
| 3991 | }), |
| 3992 | }, |
| 3993 | ) |
| 3994 | } |
Trevor Radcliffe | db7e026 | 2022-10-28 16:48:18 +0000 | [diff] [blame] | 3995 | |
| 3996 | func TestCcLibraryWithIntegerOverflowProperty(t *testing.T) { |
| 3997 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3998 | Description: "cc_library has correct features when integer_overflow property is provided", |
| 3999 | ModuleTypeUnderTest: "cc_library", |
| 4000 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4001 | Blueprint: ` |
| 4002 | cc_library { |
| 4003 | name: "foo", |
| 4004 | sanitize: { |
| 4005 | integer_overflow: true, |
| 4006 | }, |
| 4007 | } |
| 4008 | `, |
| 4009 | ExpectedBazelTargets: []string{ |
| 4010 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4011 | "features": `["ubsan_integer_overflow"]`, |
| 4012 | "local_includes": `["."]`, |
| 4013 | }), |
| 4014 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4015 | "features": `["ubsan_integer_overflow"]`, |
| 4016 | "local_includes": `["."]`, |
| 4017 | }), |
| 4018 | }, |
| 4019 | }) |
| 4020 | } |
| 4021 | |
| 4022 | func TestCcLibraryWithMiscUndefinedProperty(t *testing.T) { |
| 4023 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4024 | Description: "cc_library has correct features when misc_undefined property is provided", |
| 4025 | ModuleTypeUnderTest: "cc_library", |
| 4026 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4027 | Blueprint: ` |
| 4028 | cc_library { |
| 4029 | name: "foo", |
| 4030 | sanitize: { |
| 4031 | misc_undefined: ["undefined", "nullability"], |
| 4032 | }, |
| 4033 | } |
| 4034 | `, |
| 4035 | ExpectedBazelTargets: []string{ |
| 4036 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4037 | "features": `[ |
| 4038 | "ubsan_undefined", |
| 4039 | "ubsan_nullability", |
| 4040 | ]`, |
| 4041 | "local_includes": `["."]`, |
| 4042 | }), |
| 4043 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4044 | "features": `[ |
| 4045 | "ubsan_undefined", |
| 4046 | "ubsan_nullability", |
| 4047 | ]`, |
| 4048 | "local_includes": `["."]`, |
| 4049 | }), |
| 4050 | }, |
| 4051 | }) |
| 4052 | } |
| 4053 | |
| 4054 | func TestCcLibraryWithUBSanPropertiesArchSpecific(t *testing.T) { |
| 4055 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4056 | Description: "cc_library has correct feature select when UBSan props are specified in arch specific blocks", |
| 4057 | ModuleTypeUnderTest: "cc_library", |
| 4058 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4059 | Blueprint: ` |
| 4060 | cc_library { |
| 4061 | name: "foo", |
| 4062 | sanitize: { |
| 4063 | misc_undefined: ["undefined", "nullability"], |
| 4064 | }, |
| 4065 | target: { |
| 4066 | android: { |
| 4067 | sanitize: { |
| 4068 | misc_undefined: ["alignment"], |
| 4069 | }, |
| 4070 | }, |
| 4071 | linux_glibc: { |
| 4072 | sanitize: { |
| 4073 | integer_overflow: true, |
| 4074 | }, |
| 4075 | }, |
| 4076 | }, |
| 4077 | } |
| 4078 | `, |
| 4079 | ExpectedBazelTargets: []string{ |
| 4080 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4081 | "features": `[ |
| 4082 | "ubsan_undefined", |
| 4083 | "ubsan_nullability", |
| 4084 | ] + select({ |
| 4085 | "//build/bazel/platforms/os:android": ["ubsan_alignment"], |
| 4086 | "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"], |
| 4087 | "//conditions:default": [], |
| 4088 | })`, |
| 4089 | "local_includes": `["."]`, |
| 4090 | }), |
| 4091 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4092 | "features": `[ |
| 4093 | "ubsan_undefined", |
| 4094 | "ubsan_nullability", |
| 4095 | ] + select({ |
| 4096 | "//build/bazel/platforms/os:android": ["ubsan_alignment"], |
| 4097 | "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"], |
| 4098 | "//conditions:default": [], |
| 4099 | })`, |
| 4100 | "local_includes": `["."]`, |
| 4101 | }), |
| 4102 | }, |
| 4103 | }) |
| 4104 | } |
Yu Liu | 10174ff | 2023-02-21 12:05:26 -0800 | [diff] [blame] | 4105 | |
| 4106 | func TestCcLibraryInApexWithStubSharedLibs(t *testing.T) { |
| 4107 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 4108 | Description: "cc_library with in apex with stub shared_libs and export_shared_lib_headers", |
| 4109 | ModuleTypeUnderTest: "cc_library", |
| 4110 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4111 | Blueprint: ` |
| 4112 | cc_library { |
| 4113 | name: "barlib", |
| 4114 | stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] }, |
| 4115 | bazel_module: { bp2build_available: false }, |
| 4116 | } |
| 4117 | cc_library { |
| 4118 | name: "bazlib", |
| 4119 | stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] }, |
| 4120 | bazel_module: { bp2build_available: false }, |
| 4121 | } |
| 4122 | cc_library { |
| 4123 | name: "foo", |
| 4124 | shared_libs: ["barlib", "bazlib"], |
| 4125 | export_shared_lib_headers: ["bazlib"], |
| 4126 | apex_available: [ |
| 4127 | "apex_available:platform", |
| 4128 | ], |
| 4129 | }`, |
| 4130 | ExpectedBazelTargets: []string{ |
| 4131 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4132 | "implementation_dynamic_deps": `select({ |
| 4133 | "//build/bazel/rules/apex:android-in_apex": [":barlib_stub_libs_current"], |
| 4134 | "//conditions:default": [":barlib"], |
| 4135 | })`, |
| 4136 | "dynamic_deps": `select({ |
| 4137 | "//build/bazel/rules/apex:android-in_apex": [":bazlib_stub_libs_current"], |
| 4138 | "//conditions:default": [":bazlib"], |
| 4139 | })`, |
| 4140 | "local_includes": `["."]`, |
| 4141 | "tags": `["apex_available=apex_available:platform"]`, |
| 4142 | }), |
| 4143 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4144 | "implementation_dynamic_deps": `select({ |
| 4145 | "//build/bazel/rules/apex:android-in_apex": [":barlib_stub_libs_current"], |
| 4146 | "//conditions:default": [":barlib"], |
| 4147 | })`, |
| 4148 | "dynamic_deps": `select({ |
| 4149 | "//build/bazel/rules/apex:android-in_apex": [":bazlib_stub_libs_current"], |
| 4150 | "//conditions:default": [":bazlib"], |
| 4151 | })`, |
| 4152 | "local_includes": `["."]`, |
| 4153 | "tags": `["apex_available=apex_available:platform"]`, |
| 4154 | }), |
| 4155 | }, |
| 4156 | }) |
| 4157 | } |
Trevor Radcliffe | 56b1a2b | 2023-02-06 21:58:30 +0000 | [diff] [blame] | 4158 | |
| 4159 | func TestCcLibraryWithThinLto(t *testing.T) { |
| 4160 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4161 | Description: "cc_library has correct features when thin LTO is enabled", |
| 4162 | ModuleTypeUnderTest: "cc_library", |
| 4163 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4164 | Blueprint: ` |
| 4165 | cc_library { |
| 4166 | name: "foo", |
| 4167 | lto: { |
| 4168 | thin: true, |
| 4169 | }, |
| 4170 | }`, |
| 4171 | ExpectedBazelTargets: []string{ |
| 4172 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4173 | "features": `["android_thin_lto"]`, |
| 4174 | "local_includes": `["."]`, |
| 4175 | }), |
| 4176 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4177 | "features": `["android_thin_lto"]`, |
| 4178 | "local_includes": `["."]`, |
| 4179 | }), |
| 4180 | }, |
| 4181 | }) |
| 4182 | } |
| 4183 | |
| 4184 | func TestCcLibraryWithLtoNever(t *testing.T) { |
| 4185 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4186 | Description: "cc_library has correct features when LTO is explicitly disabled", |
| 4187 | ModuleTypeUnderTest: "cc_library", |
| 4188 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4189 | Blueprint: ` |
| 4190 | cc_library { |
| 4191 | name: "foo", |
| 4192 | lto: { |
| 4193 | never: true, |
| 4194 | }, |
| 4195 | }`, |
| 4196 | ExpectedBazelTargets: []string{ |
| 4197 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4198 | "features": `["-android_thin_lto"]`, |
| 4199 | "local_includes": `["."]`, |
| 4200 | }), |
| 4201 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4202 | "features": `["-android_thin_lto"]`, |
| 4203 | "local_includes": `["."]`, |
| 4204 | }), |
| 4205 | }, |
| 4206 | }) |
| 4207 | } |
| 4208 | |
| 4209 | func TestCcLibraryWithThinLtoArchSpecific(t *testing.T) { |
| 4210 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4211 | Description: "cc_library has correct features when LTO differs across arch and os variants", |
| 4212 | ModuleTypeUnderTest: "cc_library", |
| 4213 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4214 | Blueprint: ` |
| 4215 | cc_library { |
| 4216 | name: "foo", |
| 4217 | target: { |
| 4218 | android: { |
| 4219 | lto: { |
| 4220 | thin: true, |
| 4221 | }, |
| 4222 | }, |
| 4223 | }, |
| 4224 | arch: { |
| 4225 | riscv64: { |
| 4226 | lto: { |
| 4227 | thin: false, |
| 4228 | }, |
| 4229 | }, |
| 4230 | }, |
| 4231 | }`, |
| 4232 | ExpectedBazelTargets: []string{ |
| 4233 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4234 | "local_includes": `["."]`, |
| 4235 | "features": `select({ |
| 4236 | "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"], |
| 4237 | "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"], |
| 4238 | "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"], |
| 4239 | "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"], |
| 4240 | "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"], |
| 4241 | "//conditions:default": [], |
| 4242 | })`}), |
| 4243 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4244 | "local_includes": `["."]`, |
| 4245 | "features": `select({ |
| 4246 | "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"], |
| 4247 | "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"], |
| 4248 | "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"], |
| 4249 | "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"], |
| 4250 | "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"], |
| 4251 | "//conditions:default": [], |
| 4252 | })`}), |
| 4253 | }, |
| 4254 | }) |
| 4255 | } |
| 4256 | |
| 4257 | func TestCcLibraryWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) { |
| 4258 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4259 | Description: "cc_library has correct features when LTO disabled by default but enabled on a particular variant", |
| 4260 | ModuleTypeUnderTest: "cc_library", |
| 4261 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4262 | Blueprint: ` |
| 4263 | cc_library { |
| 4264 | name: "foo", |
| 4265 | lto: { |
| 4266 | never: true, |
| 4267 | }, |
| 4268 | target: { |
| 4269 | android: { |
| 4270 | lto: { |
| 4271 | thin: true, |
| 4272 | never: false, |
| 4273 | }, |
| 4274 | }, |
| 4275 | }, |
| 4276 | }`, |
| 4277 | ExpectedBazelTargets: []string{ |
| 4278 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4279 | "local_includes": `["."]`, |
| 4280 | "features": `select({ |
| 4281 | "//build/bazel/platforms/os:android": ["android_thin_lto"], |
| 4282 | "//conditions:default": ["-android_thin_lto"], |
| 4283 | })`, |
| 4284 | }), |
| 4285 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4286 | "local_includes": `["."]`, |
| 4287 | "features": `select({ |
| 4288 | "//build/bazel/platforms/os:android": ["android_thin_lto"], |
| 4289 | "//conditions:default": ["-android_thin_lto"], |
| 4290 | })`, |
| 4291 | }), |
| 4292 | }, |
| 4293 | }) |
| 4294 | } |
| 4295 | |
| 4296 | func TestCcLibraryWithThinLtoWholeProgramVtables(t *testing.T) { |
| 4297 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4298 | Description: "cc_library has correct features when thin LTO is enabled with whole_program_vtables", |
| 4299 | ModuleTypeUnderTest: "cc_library", |
| 4300 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4301 | Blueprint: ` |
| 4302 | cc_library { |
| 4303 | name: "foo", |
| 4304 | lto: { |
| 4305 | thin: true, |
| 4306 | }, |
| 4307 | whole_program_vtables: true, |
| 4308 | }`, |
| 4309 | ExpectedBazelTargets: []string{ |
| 4310 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4311 | "features": `[ |
| 4312 | "android_thin_lto", |
| 4313 | "android_thin_lto_whole_program_vtables", |
| 4314 | ]`, |
| 4315 | "local_includes": `["."]`, |
| 4316 | }), |
| 4317 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4318 | "features": `[ |
| 4319 | "android_thin_lto", |
| 4320 | "android_thin_lto_whole_program_vtables", |
| 4321 | ]`, |
| 4322 | "local_includes": `["."]`, |
| 4323 | }), |
| 4324 | }, |
| 4325 | }) |
| 4326 | } |