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 | |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 21 | "android/soong/aidl_library" |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 22 | "android/soong/android" |
| 23 | "android/soong/cc" |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | const ( |
| 27 | // See cc/testing.go for more context |
| 28 | soongCcLibraryPreamble = ` |
| 29 | cc_defaults { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 30 | name: "linux_bionic_supported", |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 31 | } |
| 32 | ` |
| 33 | |
| 34 | soongCcVersionLibBpPath = "build/soong/cc/libbuildversion/Android.bp" |
| 35 | soongCcVersionLibBp = ` |
| 36 | cc_library_static { |
| 37 | name: "libbuildversion", |
| 38 | bazel_module: { bp2build_available: false }, |
| 39 | } |
| 40 | ` |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 41 | |
| 42 | soongCcProtoLibraries = ` |
| 43 | cc_library { |
| 44 | name: "libprotobuf-cpp-lite", |
| 45 | bazel_module: { bp2build_available: false }, |
| 46 | } |
| 47 | |
| 48 | cc_library { |
| 49 | name: "libprotobuf-cpp-full", |
| 50 | bazel_module: { bp2build_available: false }, |
| 51 | }` |
| 52 | |
| 53 | soongCcProtoPreamble = soongCcLibraryPreamble + soongCcProtoLibraries |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 54 | ) |
| 55 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 56 | func runCcLibraryTestCase(t *testing.T, tc Bp2buildTestCase) { |
Liz Kammer | e4982e8 | 2021-05-25 10:39:35 -0400 | [diff] [blame] | 57 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 58 | RunBp2BuildTestCase(t, registerCcLibraryModuleTypes, tc) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | func registerCcLibraryModuleTypes(ctx android.RegistrationContext) { |
| 62 | cc.RegisterCCBuildComponents(ctx) |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 63 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 64 | ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 65 | ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 66 | ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 67 | ctx.RegisterModuleType("aidl_library", aidl_library.AidlLibraryFactory) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 68 | } |
| 69 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 70 | func TestCcLibrarySimple(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 71 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 72 | Description: "cc_library - simple example", |
| 73 | ModuleTypeUnderTest: "cc_library", |
| 74 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 75 | Filesystem: map[string]string{ |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 76 | soongCcVersionLibBpPath: soongCcVersionLibBp, |
| 77 | "android.cpp": "", |
| 78 | "bionic.cpp": "", |
| 79 | "darwin.cpp": "", |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 80 | // Refer to cc.headerExts for the supported header extensions in Soong. |
| 81 | "header.h": "", |
| 82 | "header.hh": "", |
| 83 | "header.hpp": "", |
| 84 | "header.hxx": "", |
| 85 | "header.h++": "", |
| 86 | "header.inl": "", |
| 87 | "header.inc": "", |
| 88 | "header.ipp": "", |
| 89 | "header.h.generic": "", |
| 90 | "impl.cpp": "", |
| 91 | "linux.cpp": "", |
| 92 | "x86.cpp": "", |
| 93 | "x86_64.cpp": "", |
| 94 | "foo-dir/a.h": "", |
| 95 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 96 | Blueprint: soongCcLibraryPreamble + |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 97 | simpleModuleDoNotConvertBp2build("cc_library_headers", "some-headers") + ` |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 98 | cc_library { |
| 99 | name: "foo-lib", |
| 100 | srcs: ["impl.cpp"], |
| 101 | cflags: ["-Wall"], |
| 102 | header_libs: ["some-headers"], |
| 103 | export_include_dirs: ["foo-dir"], |
| 104 | ldflags: ["-Wl,--exclude-libs=bar.a"], |
| 105 | arch: { |
| 106 | x86: { |
| 107 | ldflags: ["-Wl,--exclude-libs=baz.a"], |
| 108 | srcs: ["x86.cpp"], |
| 109 | }, |
| 110 | x86_64: { |
| 111 | ldflags: ["-Wl,--exclude-libs=qux.a"], |
| 112 | srcs: ["x86_64.cpp"], |
| 113 | }, |
| 114 | }, |
| 115 | target: { |
| 116 | android: { |
| 117 | srcs: ["android.cpp"], |
| 118 | }, |
| 119 | linux_glibc: { |
| 120 | srcs: ["linux.cpp"], |
| 121 | }, |
| 122 | darwin: { |
| 123 | srcs: ["darwin.cpp"], |
| 124 | }, |
Liz Kammer | 01a16e8 | 2021-07-16 16:33:47 -0400 | [diff] [blame] | 125 | bionic: { |
| 126 | srcs: ["bionic.cpp"] |
| 127 | }, |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 128 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 129 | include_build_directory: false, |
Yu Liu | fc60316 | 2022-03-01 15:44:08 -0800 | [diff] [blame] | 130 | sdk_version: "current", |
| 131 | min_sdk_version: "29", |
Yu Liu | a79c946 | 2022-03-22 16:35:22 -0700 | [diff] [blame] | 132 | use_version_lib: true, |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 133 | } |
| 134 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 135 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 136 | "copts": `["-Wall"]`, |
| 137 | "export_includes": `["foo-dir"]`, |
| 138 | "implementation_deps": `[":some-headers"]`, |
| 139 | "linkopts": `["-Wl,--exclude-libs=bar.a"] + select({ |
Jingwen Chen | ed9c17d | 2021-04-13 07:14:55 +0000 | [diff] [blame] | 140 | "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=baz.a"], |
| 141 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=qux.a"], |
| 142 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 143 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 144 | "srcs": `["impl.cpp"] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 145 | "//build/bazel/platforms/arch:x86": ["x86.cpp"], |
| 146 | "//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 147 | "//conditions:default": [], |
| 148 | }) + select({ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 149 | "//build/bazel/platforms/os:android": [ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 150 | "bionic.cpp", |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 151 | "android.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 152 | ], |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 153 | "//build/bazel/platforms/os:darwin": ["darwin.cpp"], |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 154 | "//build/bazel/platforms/os:linux_bionic": ["bionic.cpp"], |
Colin Cross | 133782e | 2022-12-20 15:29:31 -0800 | [diff] [blame] | 155 | "//build/bazel/platforms/os:linux_glibc": ["linux.cpp"], |
Liz Kammer | 01a16e8 | 2021-07-16 16:33:47 -0400 | [diff] [blame] | 156 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 157 | })`, |
Yu Liu | fe978fd | 2023-04-24 16:37:18 -0700 | [diff] [blame] | 158 | "sdk_version": `"current"`, |
| 159 | "min_sdk_version": `"29"`, |
| 160 | "use_version_lib": `True`, |
| 161 | "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 162 | }), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 163 | }) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | func TestCcLibraryTrimmedLdAndroid(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 167 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 168 | Description: "cc_library - trimmed example of //bionic/linker:ld-android", |
| 169 | ModuleTypeUnderTest: "cc_library", |
| 170 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 171 | Filesystem: map[string]string{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 172 | "ld-android.cpp": "", |
| 173 | "linked_list.h": "", |
| 174 | "linker.h": "", |
| 175 | "linker_block_allocator.h": "", |
| 176 | "linker_cfi.h": "", |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 177 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 178 | Blueprint: soongCcLibraryPreamble + |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 179 | simpleModuleDoNotConvertBp2build("cc_library_headers", "libc_headers") + ` |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 180 | cc_library { |
| 181 | name: "fake-ld-android", |
| 182 | srcs: ["ld_android.cpp"], |
| 183 | cflags: [ |
| 184 | "-Wall", |
| 185 | "-Wextra", |
| 186 | "-Wunused", |
| 187 | "-Werror", |
| 188 | ], |
| 189 | header_libs: ["libc_headers"], |
| 190 | ldflags: [ |
| 191 | "-Wl,--exclude-libs=libgcc.a", |
| 192 | "-Wl,--exclude-libs=libgcc_stripped.a", |
| 193 | "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a", |
| 194 | "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a", |
| 195 | "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a", |
| 196 | "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a", |
| 197 | ], |
| 198 | arch: { |
| 199 | x86: { |
| 200 | ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 201 | }, |
| 202 | x86_64: { |
| 203 | ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 204 | }, |
| 205 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 206 | include_build_directory: false, |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 207 | } |
| 208 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 209 | ExpectedBazelTargets: makeCcLibraryTargets("fake-ld-android", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 210 | "srcs": `["ld_android.cpp"]`, |
| 211 | "copts": `[ |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 212 | "-Wall", |
| 213 | "-Wextra", |
| 214 | "-Wunused", |
| 215 | "-Werror", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 216 | ]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 217 | "implementation_deps": `[":libc_headers"]`, |
| 218 | "linkopts": `[ |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 219 | "-Wl,--exclude-libs=libgcc.a", |
| 220 | "-Wl,--exclude-libs=libgcc_stripped.a", |
| 221 | "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a", |
| 222 | "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a", |
| 223 | "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a", |
| 224 | "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a", |
| 225 | ] + select({ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 226 | "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=libgcc_eh.a"], |
| 227 | "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=libgcc_eh.a"], |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 228 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 229 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 230 | }), |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 231 | }) |
| 232 | } |
| 233 | |
| 234 | func TestCcLibraryExcludeSrcs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 235 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 236 | Description: "cc_library exclude_srcs - trimmed example of //external/arm-optimized-routines:libarm-optimized-routines-math", |
| 237 | ModuleTypeUnderTest: "cc_library", |
| 238 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 239 | Dir: "external", |
| 240 | Filesystem: map[string]string{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 241 | "external/math/cosf.c": "", |
| 242 | "external/math/erf.c": "", |
| 243 | "external/math/erf_data.c": "", |
| 244 | "external/math/erff.c": "", |
| 245 | "external/math/erff_data.c": "", |
| 246 | "external/Android.bp": ` |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 247 | cc_library { |
| 248 | name: "fake-libarm-optimized-routines-math", |
| 249 | exclude_srcs: [ |
| 250 | // Provided by: |
| 251 | // bionic/libm/upstream-freebsd/lib/msun/src/s_erf.c |
| 252 | // bionic/libm/upstream-freebsd/lib/msun/src/s_erff.c |
| 253 | "math/erf.c", |
| 254 | "math/erf_data.c", |
| 255 | "math/erff.c", |
| 256 | "math/erff_data.c", |
| 257 | ], |
| 258 | srcs: [ |
| 259 | "math/*.c", |
| 260 | ], |
| 261 | // arch-specific settings |
| 262 | arch: { |
| 263 | arm64: { |
| 264 | cflags: [ |
| 265 | "-DHAVE_FAST_FMA=1", |
| 266 | ], |
| 267 | }, |
| 268 | }, |
| 269 | bazel_module: { bp2build_available: true }, |
| 270 | } |
| 271 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 272 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 273 | Blueprint: soongCcLibraryPreamble, |
| 274 | ExpectedBazelTargets: makeCcLibraryTargets("fake-libarm-optimized-routines-math", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 275 | "copts": `select({ |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 276 | "//build/bazel/platforms/arch:arm64": ["-DHAVE_FAST_FMA=1"], |
| 277 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 278 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 279 | "local_includes": `["."]`, |
| 280 | "srcs_c": `["math/cosf.c"]`, |
| 281 | }), |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 282 | }) |
| 283 | } |
| 284 | |
| 285 | func TestCcLibrarySharedStaticProps(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 286 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 287 | Description: "cc_library shared/static props", |
| 288 | ModuleTypeUnderTest: "cc_library", |
| 289 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 290 | Filesystem: map[string]string{ |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 291 | "both.cpp": "", |
| 292 | "sharedonly.cpp": "", |
| 293 | "staticonly.cpp": "", |
| 294 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 295 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 296 | cc_library { |
| 297 | name: "a", |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 298 | srcs: ["both.cpp"], |
| 299 | cflags: ["bothflag"], |
| 300 | shared_libs: ["shared_dep_for_both"], |
Liz Kammer | cc2c1ef | 2022-03-21 09:03:29 -0400 | [diff] [blame] | 301 | static_libs: ["static_dep_for_both", "whole_and_static_lib_for_both"], |
| 302 | 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] | 303 | static: { |
| 304 | srcs: ["staticonly.cpp"], |
| 305 | cflags: ["staticflag"], |
| 306 | shared_libs: ["shared_dep_for_static"], |
| 307 | static_libs: ["static_dep_for_static"], |
| 308 | whole_static_libs: ["whole_static_lib_for_static"], |
| 309 | }, |
| 310 | shared: { |
| 311 | srcs: ["sharedonly.cpp"], |
| 312 | cflags: ["sharedflag"], |
| 313 | shared_libs: ["shared_dep_for_shared"], |
| 314 | static_libs: ["static_dep_for_shared"], |
| 315 | whole_static_libs: ["whole_static_lib_for_shared"], |
| 316 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 317 | include_build_directory: false, |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 320 | cc_library_static { |
| 321 | name: "static_dep_for_shared", |
| 322 | bazel_module: { bp2build_available: false }, |
| 323 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 324 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 325 | cc_library_static { |
| 326 | name: "static_dep_for_static", |
| 327 | bazel_module: { bp2build_available: false }, |
| 328 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 329 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 330 | cc_library_static { |
| 331 | name: "static_dep_for_both", |
| 332 | bazel_module: { bp2build_available: false }, |
| 333 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 334 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 335 | cc_library_static { |
| 336 | name: "whole_static_lib_for_shared", |
| 337 | bazel_module: { bp2build_available: false }, |
| 338 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 339 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 340 | cc_library_static { |
| 341 | name: "whole_static_lib_for_static", |
| 342 | bazel_module: { bp2build_available: false }, |
| 343 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 344 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 345 | cc_library_static { |
| 346 | name: "whole_static_lib_for_both", |
| 347 | bazel_module: { bp2build_available: false }, |
| 348 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 349 | |
Liz Kammer | cc2c1ef | 2022-03-21 09:03:29 -0400 | [diff] [blame] | 350 | cc_library_static { |
| 351 | name: "whole_and_static_lib_for_both", |
| 352 | bazel_module: { bp2build_available: false }, |
| 353 | } |
| 354 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 355 | cc_library { |
| 356 | name: "shared_dep_for_shared", |
| 357 | bazel_module: { bp2build_available: false }, |
| 358 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 359 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 360 | cc_library { |
| 361 | name: "shared_dep_for_static", |
| 362 | bazel_module: { bp2build_available: false }, |
| 363 | } |
Chris Parsons | 0864831 | 2021-05-06 16:23:19 -0400 | [diff] [blame] | 364 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 365 | cc_library { |
| 366 | name: "shared_dep_for_both", |
| 367 | bazel_module: { bp2build_available: false }, |
| 368 | } |
Jingwen Chen | 53681ef | 2021-04-29 08:15:13 +0000 | [diff] [blame] | 369 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 370 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 371 | MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 372 | "copts": `[ |
| 373 | "bothflag", |
| 374 | "staticflag", |
| 375 | ]`, |
| 376 | "implementation_deps": `[ |
| 377 | ":static_dep_for_both", |
| 378 | ":static_dep_for_static", |
| 379 | ]`, |
| 380 | "implementation_dynamic_deps": `[ |
| 381 | ":shared_dep_for_both", |
| 382 | ":shared_dep_for_static", |
| 383 | ]`, |
| 384 | "srcs": `[ |
| 385 | "both.cpp", |
| 386 | "staticonly.cpp", |
| 387 | ]`, |
| 388 | "whole_archive_deps": `[ |
| 389 | ":whole_static_lib_for_both", |
Liz Kammer | cc2c1ef | 2022-03-21 09:03:29 -0400 | [diff] [blame] | 390 | ":whole_and_static_lib_for_both", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 391 | ":whole_static_lib_for_static", |
| 392 | ]`}), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 393 | MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 394 | "copts": `[ |
| 395 | "bothflag", |
| 396 | "sharedflag", |
| 397 | ]`, |
| 398 | "implementation_deps": `[ |
| 399 | ":static_dep_for_both", |
| 400 | ":static_dep_for_shared", |
| 401 | ]`, |
| 402 | "implementation_dynamic_deps": `[ |
| 403 | ":shared_dep_for_both", |
| 404 | ":shared_dep_for_shared", |
| 405 | ]`, |
| 406 | "srcs": `[ |
| 407 | "both.cpp", |
| 408 | "sharedonly.cpp", |
| 409 | ]`, |
| 410 | "whole_archive_deps": `[ |
| 411 | ":whole_static_lib_for_both", |
Liz Kammer | cc2c1ef | 2022-03-21 09:03:29 -0400 | [diff] [blame] | 412 | ":whole_and_static_lib_for_both", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 413 | ":whole_static_lib_for_shared", |
| 414 | ]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 415 | }), |
| 416 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 417 | }) |
| 418 | } |
| 419 | |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 420 | func TestCcLibraryDeps(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 421 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 422 | Description: "cc_library shared/static props", |
| 423 | ModuleTypeUnderTest: "cc_library", |
| 424 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 425 | Filesystem: map[string]string{ |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 426 | "both.cpp": "", |
| 427 | "sharedonly.cpp": "", |
| 428 | "staticonly.cpp": "", |
| 429 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 430 | Blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 431 | cc_library { |
| 432 | name: "a", |
| 433 | srcs: ["both.cpp"], |
| 434 | cflags: ["bothflag"], |
| 435 | shared_libs: ["implementation_shared_dep_for_both", "shared_dep_for_both"], |
| 436 | export_shared_lib_headers: ["shared_dep_for_both"], |
| 437 | static_libs: ["implementation_static_dep_for_both", "static_dep_for_both"], |
| 438 | export_static_lib_headers: ["static_dep_for_both", "whole_static_dep_for_both"], |
| 439 | whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_both", "whole_static_dep_for_both"], |
| 440 | static: { |
| 441 | srcs: ["staticonly.cpp"], |
| 442 | cflags: ["staticflag"], |
| 443 | shared_libs: ["implementation_shared_dep_for_static", "shared_dep_for_static"], |
| 444 | export_shared_lib_headers: ["shared_dep_for_static"], |
| 445 | static_libs: ["implementation_static_dep_for_static", "static_dep_for_static"], |
| 446 | export_static_lib_headers: ["static_dep_for_static", "whole_static_dep_for_static"], |
| 447 | whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_static", "whole_static_dep_for_static"], |
| 448 | }, |
| 449 | shared: { |
| 450 | srcs: ["sharedonly.cpp"], |
| 451 | cflags: ["sharedflag"], |
| 452 | shared_libs: ["implementation_shared_dep_for_shared", "shared_dep_for_shared"], |
| 453 | export_shared_lib_headers: ["shared_dep_for_shared"], |
| 454 | static_libs: ["implementation_static_dep_for_shared", "static_dep_for_shared"], |
| 455 | export_static_lib_headers: ["static_dep_for_shared", "whole_static_dep_for_shared"], |
| 456 | whole_static_libs: ["not_explicitly_exported_whole_static_dep_for_shared", "whole_static_dep_for_shared"], |
| 457 | }, |
| 458 | include_build_directory: false, |
| 459 | } |
| 460 | ` + simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_shared") + |
| 461 | simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_shared") + |
| 462 | simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_static") + |
| 463 | simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_static") + |
| 464 | simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_both") + |
| 465 | simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_both") + |
| 466 | simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_shared") + |
| 467 | simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_shared") + |
| 468 | simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_static") + |
| 469 | simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_static") + |
| 470 | simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_both") + |
| 471 | simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_both") + |
| 472 | simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_shared") + |
| 473 | simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_shared") + |
| 474 | simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_static") + |
| 475 | simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_static") + |
| 476 | simpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_both") + |
| 477 | simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_both"), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 478 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 479 | MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 480 | "copts": `[ |
| 481 | "bothflag", |
| 482 | "staticflag", |
| 483 | ]`, |
| 484 | "deps": `[ |
| 485 | ":static_dep_for_both", |
| 486 | ":static_dep_for_static", |
| 487 | ]`, |
| 488 | "dynamic_deps": `[ |
| 489 | ":shared_dep_for_both", |
| 490 | ":shared_dep_for_static", |
| 491 | ]`, |
| 492 | "implementation_deps": `[ |
| 493 | ":implementation_static_dep_for_both", |
| 494 | ":implementation_static_dep_for_static", |
| 495 | ]`, |
| 496 | "implementation_dynamic_deps": `[ |
| 497 | ":implementation_shared_dep_for_both", |
| 498 | ":implementation_shared_dep_for_static", |
| 499 | ]`, |
| 500 | "srcs": `[ |
| 501 | "both.cpp", |
| 502 | "staticonly.cpp", |
| 503 | ]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 504 | "whole_archive_deps": `[ |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 505 | ":not_explicitly_exported_whole_static_dep_for_both", |
| 506 | ":whole_static_dep_for_both", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 507 | ":not_explicitly_exported_whole_static_dep_for_static", |
| 508 | ":whole_static_dep_for_static", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 509 | ]`, |
| 510 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 511 | MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 512 | "copts": `[ |
| 513 | "bothflag", |
| 514 | "sharedflag", |
| 515 | ]`, |
| 516 | "deps": `[ |
| 517 | ":static_dep_for_both", |
| 518 | ":static_dep_for_shared", |
| 519 | ]`, |
| 520 | "dynamic_deps": `[ |
| 521 | ":shared_dep_for_both", |
| 522 | ":shared_dep_for_shared", |
| 523 | ]`, |
| 524 | "implementation_deps": `[ |
| 525 | ":implementation_static_dep_for_both", |
| 526 | ":implementation_static_dep_for_shared", |
| 527 | ]`, |
| 528 | "implementation_dynamic_deps": `[ |
| 529 | ":implementation_shared_dep_for_both", |
| 530 | ":implementation_shared_dep_for_shared", |
| 531 | ]`, |
| 532 | "srcs": `[ |
| 533 | "both.cpp", |
| 534 | "sharedonly.cpp", |
| 535 | ]`, |
| 536 | "whole_archive_deps": `[ |
| 537 | ":not_explicitly_exported_whole_static_dep_for_both", |
| 538 | ":whole_static_dep_for_both", |
| 539 | ":not_explicitly_exported_whole_static_dep_for_shared", |
| 540 | ":whole_static_dep_for_shared", |
| 541 | ]`, |
| 542 | })}, |
| 543 | }, |
| 544 | ) |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 545 | } |
| 546 | |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 547 | func TestCcLibraryWholeStaticLibsAlwaysLink(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 548 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 549 | ModuleTypeUnderTest: "cc_library", |
| 550 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 551 | Dir: "foo/bar", |
| 552 | Filesystem: map[string]string{ |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 553 | "foo/bar/Android.bp": ` |
| 554 | cc_library { |
| 555 | name: "a", |
| 556 | whole_static_libs: ["whole_static_lib_for_both"], |
| 557 | static: { |
| 558 | whole_static_libs: ["whole_static_lib_for_static"], |
| 559 | }, |
| 560 | shared: { |
| 561 | whole_static_libs: ["whole_static_lib_for_shared"], |
| 562 | }, |
| 563 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 564 | include_build_directory: false, |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | cc_prebuilt_library_static { name: "whole_static_lib_for_shared" } |
| 568 | |
| 569 | cc_prebuilt_library_static { name: "whole_static_lib_for_static" } |
| 570 | |
| 571 | cc_prebuilt_library_static { name: "whole_static_lib_for_both" } |
| 572 | `, |
| 573 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 574 | Blueprint: soongCcLibraryPreamble, |
| 575 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 576 | MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 577 | "whole_archive_deps": `[ |
| 578 | ":whole_static_lib_for_both_alwayslink", |
| 579 | ":whole_static_lib_for_static_alwayslink", |
| 580 | ]`, |
| 581 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 582 | MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 583 | "whole_archive_deps": `[ |
| 584 | ":whole_static_lib_for_both_alwayslink", |
| 585 | ":whole_static_lib_for_shared_alwayslink", |
| 586 | ]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 587 | }), |
| 588 | }, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 589 | }, |
| 590 | ) |
Liz Kammer | 2d7bbe3 | 2021-06-10 18:20:06 -0400 | [diff] [blame] | 591 | } |
| 592 | |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 593 | func TestCcLibrarySharedStaticPropsInArch(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 594 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 595 | Description: "cc_library shared/static props in arch", |
| 596 | ModuleTypeUnderTest: "cc_library", |
| 597 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 598 | Dir: "foo/bar", |
| 599 | Filesystem: map[string]string{ |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 600 | "foo/bar/arm.cpp": "", |
| 601 | "foo/bar/x86.cpp": "", |
| 602 | "foo/bar/sharedonly.cpp": "", |
| 603 | "foo/bar/staticonly.cpp": "", |
| 604 | "foo/bar/Android.bp": ` |
| 605 | cc_library { |
| 606 | name: "a", |
| 607 | arch: { |
| 608 | arm: { |
| 609 | shared: { |
| 610 | srcs: ["arm_shared.cpp"], |
| 611 | cflags: ["-DARM_SHARED"], |
| 612 | static_libs: ["arm_static_dep_for_shared"], |
| 613 | whole_static_libs: ["arm_whole_static_dep_for_shared"], |
| 614 | shared_libs: ["arm_shared_dep_for_shared"], |
| 615 | }, |
| 616 | }, |
| 617 | x86: { |
| 618 | static: { |
| 619 | srcs: ["x86_static.cpp"], |
| 620 | cflags: ["-DX86_STATIC"], |
| 621 | static_libs: ["x86_dep_for_static"], |
| 622 | }, |
| 623 | }, |
| 624 | }, |
| 625 | target: { |
| 626 | android: { |
| 627 | shared: { |
| 628 | srcs: ["android_shared.cpp"], |
| 629 | cflags: ["-DANDROID_SHARED"], |
| 630 | static_libs: ["android_dep_for_shared"], |
| 631 | }, |
| 632 | }, |
| 633 | android_arm: { |
| 634 | shared: { |
| 635 | cflags: ["-DANDROID_ARM_SHARED"], |
| 636 | }, |
| 637 | }, |
| 638 | }, |
| 639 | srcs: ["both.cpp"], |
| 640 | cflags: ["bothflag"], |
| 641 | static_libs: ["static_dep_for_both"], |
| 642 | static: { |
| 643 | srcs: ["staticonly.cpp"], |
| 644 | cflags: ["staticflag"], |
| 645 | static_libs: ["static_dep_for_static"], |
| 646 | }, |
| 647 | shared: { |
| 648 | srcs: ["sharedonly.cpp"], |
| 649 | cflags: ["sharedflag"], |
| 650 | static_libs: ["static_dep_for_shared"], |
| 651 | }, |
| 652 | bazel_module: { bp2build_available: true }, |
| 653 | } |
| 654 | |
| 655 | cc_library_static { name: "static_dep_for_shared" } |
| 656 | cc_library_static { name: "static_dep_for_static" } |
| 657 | cc_library_static { name: "static_dep_for_both" } |
| 658 | |
| 659 | cc_library_static { name: "arm_static_dep_for_shared" } |
| 660 | cc_library_static { name: "arm_whole_static_dep_for_shared" } |
| 661 | cc_library_static { name: "arm_shared_dep_for_shared" } |
| 662 | |
| 663 | cc_library_static { name: "x86_dep_for_static" } |
| 664 | |
| 665 | cc_library_static { name: "android_dep_for_shared" } |
| 666 | `, |
| 667 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 668 | Blueprint: soongCcLibraryPreamble, |
| 669 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 670 | MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 671 | "copts": `[ |
| 672 | "bothflag", |
| 673 | "staticflag", |
| 674 | ] + select({ |
| 675 | "//build/bazel/platforms/arch:x86": ["-DX86_STATIC"], |
| 676 | "//conditions:default": [], |
| 677 | })`, |
| 678 | "implementation_deps": `[ |
| 679 | ":static_dep_for_both", |
| 680 | ":static_dep_for_static", |
| 681 | ] + select({ |
| 682 | "//build/bazel/platforms/arch:x86": [":x86_dep_for_static"], |
| 683 | "//conditions:default": [], |
| 684 | })`, |
| 685 | "local_includes": `["."]`, |
| 686 | "srcs": `[ |
| 687 | "both.cpp", |
| 688 | "staticonly.cpp", |
| 689 | ] + select({ |
| 690 | "//build/bazel/platforms/arch:x86": ["x86_static.cpp"], |
| 691 | "//conditions:default": [], |
| 692 | })`, |
| 693 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 694 | MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 695 | "copts": `[ |
| 696 | "bothflag", |
| 697 | "sharedflag", |
| 698 | ] + select({ |
| 699 | "//build/bazel/platforms/arch:arm": ["-DARM_SHARED"], |
| 700 | "//conditions:default": [], |
| 701 | }) + select({ |
| 702 | "//build/bazel/platforms/os:android": ["-DANDROID_SHARED"], |
| 703 | "//conditions:default": [], |
| 704 | }) + select({ |
| 705 | "//build/bazel/platforms/os_arch:android_arm": ["-DANDROID_ARM_SHARED"], |
| 706 | "//conditions:default": [], |
| 707 | })`, |
| 708 | "implementation_deps": `[ |
| 709 | ":static_dep_for_both", |
| 710 | ":static_dep_for_shared", |
| 711 | ] + select({ |
| 712 | "//build/bazel/platforms/arch:arm": [":arm_static_dep_for_shared"], |
| 713 | "//conditions:default": [], |
| 714 | }) + select({ |
| 715 | "//build/bazel/platforms/os:android": [":android_dep_for_shared"], |
| 716 | "//conditions:default": [], |
| 717 | })`, |
| 718 | "implementation_dynamic_deps": `select({ |
| 719 | "//build/bazel/platforms/arch:arm": [":arm_shared_dep_for_shared"], |
| 720 | "//conditions:default": [], |
| 721 | })`, |
| 722 | "local_includes": `["."]`, |
| 723 | "srcs": `[ |
| 724 | "both.cpp", |
| 725 | "sharedonly.cpp", |
| 726 | ] + select({ |
| 727 | "//build/bazel/platforms/arch:arm": ["arm_shared.cpp"], |
| 728 | "//conditions:default": [], |
| 729 | }) + select({ |
| 730 | "//build/bazel/platforms/os:android": ["android_shared.cpp"], |
| 731 | "//conditions:default": [], |
| 732 | })`, |
| 733 | "whole_archive_deps": `select({ |
| 734 | "//build/bazel/platforms/arch:arm": [":arm_whole_static_dep_for_shared"], |
| 735 | "//conditions:default": [], |
| 736 | })`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 737 | }), |
| 738 | }, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 739 | }, |
| 740 | ) |
Jingwen Chen | bcf5304 | 2021-05-26 04:42:42 +0000 | [diff] [blame] | 741 | } |
| 742 | |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 743 | func TestCcLibrarySharedStaticPropsWithMixedSources(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 744 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 745 | Description: "cc_library shared/static props with c/cpp/s mixed sources", |
| 746 | ModuleTypeUnderTest: "cc_library", |
| 747 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 748 | Dir: "foo/bar", |
| 749 | Filesystem: map[string]string{ |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 750 | "foo/bar/both_source.cpp": "", |
| 751 | "foo/bar/both_source.cc": "", |
| 752 | "foo/bar/both_source.c": "", |
| 753 | "foo/bar/both_source.s": "", |
| 754 | "foo/bar/both_source.S": "", |
| 755 | "foo/bar/shared_source.cpp": "", |
| 756 | "foo/bar/shared_source.cc": "", |
| 757 | "foo/bar/shared_source.c": "", |
| 758 | "foo/bar/shared_source.s": "", |
| 759 | "foo/bar/shared_source.S": "", |
| 760 | "foo/bar/static_source.cpp": "", |
| 761 | "foo/bar/static_source.cc": "", |
| 762 | "foo/bar/static_source.c": "", |
| 763 | "foo/bar/static_source.s": "", |
| 764 | "foo/bar/static_source.S": "", |
| 765 | "foo/bar/Android.bp": ` |
| 766 | cc_library { |
| 767 | name: "a", |
| 768 | srcs: [ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 769 | "both_source.cpp", |
| 770 | "both_source.cc", |
| 771 | "both_source.c", |
| 772 | "both_source.s", |
| 773 | "both_source.S", |
Liz Kammer | 57e2e7a | 2021-09-20 12:55:02 -0400 | [diff] [blame] | 774 | ":both_filegroup", |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 775 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 776 | static: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 777 | srcs: [ |
| 778 | "static_source.cpp", |
| 779 | "static_source.cc", |
| 780 | "static_source.c", |
| 781 | "static_source.s", |
| 782 | "static_source.S", |
| 783 | ":static_filegroup", |
| 784 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 785 | }, |
| 786 | shared: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 787 | srcs: [ |
| 788 | "shared_source.cpp", |
| 789 | "shared_source.cc", |
| 790 | "shared_source.c", |
| 791 | "shared_source.s", |
| 792 | "shared_source.S", |
| 793 | ":shared_filegroup", |
| 794 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 795 | }, |
| 796 | bazel_module: { bp2build_available: true }, |
| 797 | } |
| 798 | |
| 799 | filegroup { |
| 800 | name: "both_filegroup", |
| 801 | srcs: [ |
| 802 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 803 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | filegroup { |
| 807 | name: "shared_filegroup", |
| 808 | srcs: [ |
| 809 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 810 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | filegroup { |
| 814 | name: "static_filegroup", |
| 815 | srcs: [ |
| 816 | // Not relevant, handled by filegroup macro |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 817 | ], |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 818 | } |
| 819 | `, |
| 820 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 821 | Blueprint: soongCcLibraryPreamble, |
| 822 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 823 | MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 824 | "local_includes": `["."]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 825 | "srcs": `[ |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 826 | "both_source.cpp", |
Liz Kammer | 57e2e7a | 2021-09-20 12:55:02 -0400 | [diff] [blame] | 827 | "both_source.cc", |
| 828 | ":both_filegroup_cpp_srcs", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 829 | "static_source.cpp", |
| 830 | "static_source.cc", |
| 831 | ":static_filegroup_cpp_srcs", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 832 | ]`, |
| 833 | "srcs_as": `[ |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 834 | "both_source.s", |
| 835 | "both_source.S", |
| 836 | ":both_filegroup_as_srcs", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 837 | "static_source.s", |
| 838 | "static_source.S", |
| 839 | ":static_filegroup_as_srcs", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 840 | ]`, |
| 841 | "srcs_c": `[ |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 842 | "both_source.c", |
| 843 | ":both_filegroup_c_srcs", |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 844 | "static_source.c", |
| 845 | ":static_filegroup_c_srcs", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 846 | ]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 847 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 848 | MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 849 | "local_includes": `["."]`, |
| 850 | "srcs": `[ |
| 851 | "both_source.cpp", |
| 852 | "both_source.cc", |
| 853 | ":both_filegroup_cpp_srcs", |
| 854 | "shared_source.cpp", |
| 855 | "shared_source.cc", |
| 856 | ":shared_filegroup_cpp_srcs", |
| 857 | ]`, |
| 858 | "srcs_as": `[ |
| 859 | "both_source.s", |
| 860 | "both_source.S", |
| 861 | ":both_filegroup_as_srcs", |
| 862 | "shared_source.s", |
| 863 | "shared_source.S", |
| 864 | ":shared_filegroup_as_srcs", |
| 865 | ]`, |
| 866 | "srcs_c": `[ |
| 867 | "both_source.c", |
| 868 | ":both_filegroup_c_srcs", |
| 869 | "shared_source.c", |
| 870 | ":shared_filegroup_c_srcs", |
| 871 | ]`, |
| 872 | })}}) |
Jingwen Chen | 14a8bda | 2021-06-02 11:10:02 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 875 | func TestCcLibraryNonConfiguredVersionScriptAndDynamicList(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 876 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 877 | Description: "cc_library non-configured version script and dynamic list", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 878 | ModuleTypeUnderTest: "cc_library", |
| 879 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 880 | Dir: "foo/bar", |
| 881 | Filesystem: map[string]string{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 882 | "foo/bar/Android.bp": ` |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 883 | cc_library { |
| 884 | name: "a", |
| 885 | srcs: ["a.cpp"], |
| 886 | version_script: "v.map", |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 887 | dynamic_list: "dynamic.list", |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 888 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 889 | include_build_directory: false, |
Lukacs T. Berki | 1353e59 | 2021-04-30 15:35:09 +0200 | [diff] [blame] | 890 | } |
| 891 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 892 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 893 | Blueprint: soongCcLibraryPreamble, |
| 894 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 895 | "additional_linker_inputs": `[ |
| 896 | "v.map", |
| 897 | "dynamic.list", |
| 898 | ]`, |
| 899 | "linkopts": `[ |
| 900 | "-Wl,--version-script,$(location v.map)", |
| 901 | "-Wl,--dynamic-list,$(location dynamic.list)", |
| 902 | ]`, |
Trevor Radcliffe | f06dd91 | 2023-05-19 14:51:41 +0000 | [diff] [blame] | 903 | "srcs": `["a.cpp"]`, |
| 904 | "features": `["android_cfi_exports_map"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 905 | }), |
| 906 | }, |
| 907 | ) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 908 | } |
| 909 | |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 910 | func TestCcLibraryConfiguredVersionScriptAndDynamicList(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 911 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 912 | Description: "cc_library configured version script and dynamic list", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 913 | ModuleTypeUnderTest: "cc_library", |
| 914 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 915 | Dir: "foo/bar", |
| 916 | Filesystem: map[string]string{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 917 | "foo/bar/Android.bp": ` |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 918 | cc_library { |
| 919 | name: "a", |
| 920 | srcs: ["a.cpp"], |
| 921 | arch: { |
| 922 | arm: { |
| 923 | version_script: "arm.map", |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 924 | dynamic_list: "dynamic_arm.list", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 925 | }, |
| 926 | arm64: { |
| 927 | version_script: "arm64.map", |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 928 | dynamic_list: "dynamic_arm64.list", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 929 | }, |
| 930 | }, |
Lukacs T. Berki | 56bb083 | 2021-05-12 12:36:45 +0200 | [diff] [blame] | 931 | |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 932 | bazel_module: { bp2build_available: true }, |
| 933 | include_build_directory: false, |
| 934 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 935 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 936 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 937 | Blueprint: soongCcLibraryPreamble, |
| 938 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 939 | "additional_linker_inputs": `select({ |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 940 | "//build/bazel/platforms/arch:arm": [ |
| 941 | "arm.map", |
| 942 | "dynamic_arm.list", |
| 943 | ], |
| 944 | "//build/bazel/platforms/arch:arm64": [ |
| 945 | "arm64.map", |
| 946 | "dynamic_arm64.list", |
| 947 | ], |
Liz Kammer | d287118 | 2021-10-04 13:54:37 -0400 | [diff] [blame] | 948 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 949 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 950 | "linkopts": `select({ |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 951 | "//build/bazel/platforms/arch:arm": [ |
| 952 | "-Wl,--version-script,$(location arm.map)", |
| 953 | "-Wl,--dynamic-list,$(location dynamic_arm.list)", |
| 954 | ], |
| 955 | "//build/bazel/platforms/arch:arm64": [ |
| 956 | "-Wl,--version-script,$(location arm64.map)", |
| 957 | "-Wl,--dynamic-list,$(location dynamic_arm64.list)", |
| 958 | ], |
Liz Kammer | d287118 | 2021-10-04 13:54:37 -0400 | [diff] [blame] | 959 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 960 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 961 | "srcs": `["a.cpp"]`, |
Trevor Radcliffe | f06dd91 | 2023-05-19 14:51:41 +0000 | [diff] [blame] | 962 | "features": `select({ |
| 963 | "//build/bazel/platforms/arch:arm": ["android_cfi_exports_map"], |
| 964 | "//build/bazel/platforms/arch:arm64": ["android_cfi_exports_map"], |
| 965 | "//conditions:default": [], |
| 966 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 967 | }), |
| 968 | }, |
| 969 | ) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 970 | } |
| 971 | |
Trevor Radcliffe | ea6a45d | 2022-09-20 18:58:01 +0000 | [diff] [blame] | 972 | func TestCcLibraryLdflagsSplitBySpaceExceptSoongAdded(t *testing.T) { |
| 973 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 974 | Description: "ldflags are split by spaces except for the ones added by soong (version script and dynamic list)", |
| 975 | ModuleTypeUnderTest: "cc_library", |
| 976 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 977 | Filesystem: map[string]string{ |
| 978 | "version_script": "", |
| 979 | "dynamic.list": "", |
| 980 | }, |
| 981 | Blueprint: ` |
| 982 | cc_library { |
| 983 | name: "foo", |
| 984 | ldflags: [ |
| 985 | "--nospace_flag", |
| 986 | "-z spaceflag", |
| 987 | ], |
| 988 | version_script: "version_script", |
| 989 | dynamic_list: "dynamic.list", |
| 990 | include_build_directory: false, |
| 991 | } |
| 992 | `, |
| 993 | ExpectedBazelTargets: []string{ |
Trevor Radcliffe | f06dd91 | 2023-05-19 14:51:41 +0000 | [diff] [blame] | 994 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 995 | "features": `["android_cfi_exports_map"]`, |
| 996 | }), |
Trevor Radcliffe | ea6a45d | 2022-09-20 18:58:01 +0000 | [diff] [blame] | 997 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 998 | "additional_linker_inputs": `[ |
| 999 | "version_script", |
| 1000 | "dynamic.list", |
| 1001 | ]`, |
Trevor Radcliffe | f06dd91 | 2023-05-19 14:51:41 +0000 | [diff] [blame] | 1002 | "features": `["android_cfi_exports_map"]`, |
Trevor Radcliffe | ea6a45d | 2022-09-20 18:58:01 +0000 | [diff] [blame] | 1003 | "linkopts": `[ |
| 1004 | "--nospace_flag", |
| 1005 | "-z", |
| 1006 | "spaceflag", |
| 1007 | "-Wl,--version-script,$(location version_script)", |
| 1008 | "-Wl,--dynamic-list,$(location dynamic.list)", |
| 1009 | ]`, |
| 1010 | }), |
| 1011 | }, |
| 1012 | }) |
| 1013 | } |
| 1014 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1015 | func TestCcLibrarySharedLibs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1016 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1017 | Description: "cc_library shared_libs", |
| 1018 | ModuleTypeUnderTest: "cc_library", |
| 1019 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1020 | Blueprint: soongCcLibraryPreamble + ` |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 1021 | cc_library { |
| 1022 | name: "mylib", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1023 | bazel_module: { bp2build_available: false }, |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | cc_library { |
| 1027 | name: "a", |
| 1028 | shared_libs: ["mylib",], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1029 | include_build_directory: false, |
Rupert Shuttleworth | c50fa8d | 2021-05-06 02:40:33 -0400 | [diff] [blame] | 1030 | } |
| 1031 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1032 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1033 | "implementation_dynamic_deps": `[":mylib"]`, |
| 1034 | }), |
| 1035 | }, |
| 1036 | ) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1037 | } |
| 1038 | |
Liz Kammer | 0eae52e | 2021-10-06 10:32:26 -0400 | [diff] [blame] | 1039 | func TestCcLibraryFeatures(t *testing.T) { |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1040 | expected_targets := []string{} |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1041 | expected_targets = append(expected_targets, makeCcLibraryTargets("a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1042 | "features": `[ |
| 1043 | "disable_pack_relocations", |
| 1044 | "-no_undefined_symbols", |
| 1045 | ]`, |
Yu Liu | f01a0f0 | 2022-12-07 15:45:30 -0800 | [diff] [blame] | 1046 | "native_coverage": `False`, |
| 1047 | "srcs": `["a.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("b", AttrNameToString{ |
Yu Liu | f01a0f0 | 2022-12-07 15:45:30 -0800 | [diff] [blame] | 1050 | "features": `select({ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1051 | "//build/bazel/platforms/arch:x86_64": [ |
| 1052 | "disable_pack_relocations", |
| 1053 | "-no_undefined_symbols", |
| 1054 | ], |
| 1055 | "//conditions:default": [], |
| 1056 | })`, |
Yu Liu | f01a0f0 | 2022-12-07 15:45:30 -0800 | [diff] [blame] | 1057 | "native_coverage": `False`, |
| 1058 | "srcs": `["b.cpp"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1059 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1060 | expected_targets = append(expected_targets, makeCcLibraryTargets("c", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1061 | "features": `select({ |
| 1062 | "//build/bazel/platforms/os:darwin": [ |
| 1063 | "disable_pack_relocations", |
| 1064 | "-no_undefined_symbols", |
| 1065 | ], |
| 1066 | "//conditions:default": [], |
| 1067 | })`, |
| 1068 | "srcs": `["c.cpp"]`, |
| 1069 | })...) |
| 1070 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1071 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1072 | Description: "cc_library pack_relocations test", |
| 1073 | ModuleTypeUnderTest: "cc_library", |
| 1074 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1075 | Blueprint: soongCcLibraryPreamble + ` |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1076 | cc_library { |
| 1077 | name: "a", |
| 1078 | srcs: ["a.cpp"], |
| 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 | include_build_directory: false, |
Yu Liu | 8d82ac5 | 2022-05-17 15:13:28 -0700 | [diff] [blame] | 1082 | native_coverage: false, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | cc_library { |
| 1086 | name: "b", |
| 1087 | srcs: ["b.cpp"], |
| 1088 | arch: { |
| 1089 | x86_64: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1090 | pack_relocations: false, |
Liz Kammer | 0eae52e | 2021-10-06 10:32:26 -0400 | [diff] [blame] | 1091 | allow_undefined_symbols: true, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1092 | }, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1093 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1094 | include_build_directory: false, |
Yu Liu | 8d82ac5 | 2022-05-17 15:13:28 -0700 | [diff] [blame] | 1095 | native_coverage: false, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | cc_library { |
| 1099 | name: "c", |
| 1100 | srcs: ["c.cpp"], |
| 1101 | target: { |
| 1102 | darwin: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1103 | pack_relocations: false, |
Liz Kammer | 0eae52e | 2021-10-06 10:32:26 -0400 | [diff] [blame] | 1104 | allow_undefined_symbols: true, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1105 | }, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1106 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1107 | include_build_directory: false, |
Rupert Shuttleworth | 143be94 | 2021-05-09 23:55:51 -0400 | [diff] [blame] | 1108 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1109 | ExpectedBazelTargets: expected_targets, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1110 | }) |
| 1111 | } |
| 1112 | |
| 1113 | func TestCcLibrarySpacesInCopts(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1114 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1115 | Description: "cc_library spaces in copts", |
| 1116 | ModuleTypeUnderTest: "cc_library", |
| 1117 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1118 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 1119 | cc_library { |
| 1120 | name: "a", |
| 1121 | cflags: ["-include header.h",], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1122 | include_build_directory: false, |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 1123 | } |
| 1124 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1125 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1126 | "copts": `[ |
Jingwen Chen | 3950cd6 | 2021-05-12 04:33:00 +0000 | [diff] [blame] | 1127 | "-include", |
| 1128 | "header.h", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1129 | ]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1130 | }), |
| 1131 | }, |
| 1132 | ) |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | func TestCcLibraryCppFlagsGoesIntoCopts(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1136 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1137 | Description: "cc_library cppflags usage", |
| 1138 | ModuleTypeUnderTest: "cc_library", |
| 1139 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1140 | Blueprint: soongCcLibraryPreamble + `cc_library { |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1141 | name: "a", |
| 1142 | srcs: ["a.cpp"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1143 | cflags: ["-Wall"], |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1144 | cppflags: [ |
| 1145 | "-fsigned-char", |
| 1146 | "-pedantic", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1147 | ], |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1148 | arch: { |
| 1149 | arm64: { |
| 1150 | cppflags: ["-DARM64=1"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1151 | }, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1152 | }, |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1153 | target: { |
| 1154 | android: { |
| 1155 | cppflags: ["-DANDROID=1"], |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1156 | }, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1157 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1158 | include_build_directory: false, |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1159 | } |
| 1160 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1161 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1162 | "copts": `["-Wall"]`, |
| 1163 | "cppflags": `[ |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 1164 | "-fsigned-char", |
| 1165 | "-pedantic", |
Jingwen Chen | 75be1ca | 2021-05-12 05:04:58 +0000 | [diff] [blame] | 1166 | ] + select({ |
| 1167 | "//build/bazel/platforms/arch:arm64": ["-DARM64=1"], |
| 1168 | "//conditions:default": [], |
| 1169 | }) + select({ |
| 1170 | "//build/bazel/platforms/os:android": ["-DANDROID=1"], |
| 1171 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1172 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1173 | "srcs": `["a.cpp"]`, |
| 1174 | }), |
| 1175 | }, |
| 1176 | ) |
Jingwen Chen | 6393098 | 2021-03-24 10:04:33 -0400 | [diff] [blame] | 1177 | } |
Rupert Shuttleworth | 22cd2eb | 2021-05-27 02:15:54 -0400 | [diff] [blame] | 1178 | |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1179 | func TestCcLibraryExcludeLibs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1180 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1181 | ModuleTypeUnderTest: "cc_library", |
| 1182 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1183 | Filesystem: map[string]string{}, |
| 1184 | Blueprint: soongCcLibraryStaticPreamble + ` |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1185 | cc_library { |
| 1186 | name: "foo_static", |
| 1187 | srcs: ["common.c"], |
| 1188 | whole_static_libs: [ |
| 1189 | "arm_whole_static_lib_excludes", |
| 1190 | "malloc_not_svelte_whole_static_lib_excludes" |
| 1191 | ], |
| 1192 | static_libs: [ |
| 1193 | "arm_static_lib_excludes", |
| 1194 | "malloc_not_svelte_static_lib_excludes" |
| 1195 | ], |
| 1196 | shared_libs: [ |
| 1197 | "arm_shared_lib_excludes", |
| 1198 | ], |
| 1199 | arch: { |
| 1200 | arm: { |
| 1201 | exclude_shared_libs: [ |
| 1202 | "arm_shared_lib_excludes", |
| 1203 | ], |
| 1204 | exclude_static_libs: [ |
| 1205 | "arm_static_lib_excludes", |
| 1206 | "arm_whole_static_lib_excludes", |
| 1207 | ], |
| 1208 | }, |
| 1209 | }, |
| 1210 | product_variables: { |
| 1211 | malloc_not_svelte: { |
| 1212 | shared_libs: ["malloc_not_svelte_shared_lib"], |
| 1213 | whole_static_libs: ["malloc_not_svelte_whole_static_lib"], |
| 1214 | exclude_static_libs: [ |
| 1215 | "malloc_not_svelte_static_lib_excludes", |
| 1216 | "malloc_not_svelte_whole_static_lib_excludes", |
| 1217 | ], |
| 1218 | }, |
| 1219 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1220 | include_build_directory: false, |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | cc_library { |
| 1224 | name: "arm_whole_static_lib_excludes", |
| 1225 | bazel_module: { bp2build_available: false }, |
| 1226 | } |
| 1227 | |
| 1228 | cc_library { |
| 1229 | name: "malloc_not_svelte_whole_static_lib", |
| 1230 | bazel_module: { bp2build_available: false }, |
| 1231 | } |
| 1232 | |
| 1233 | cc_library { |
| 1234 | name: "malloc_not_svelte_whole_static_lib_excludes", |
| 1235 | bazel_module: { bp2build_available: false }, |
| 1236 | } |
| 1237 | |
| 1238 | cc_library { |
| 1239 | name: "arm_static_lib_excludes", |
| 1240 | bazel_module: { bp2build_available: false }, |
| 1241 | } |
| 1242 | |
| 1243 | cc_library { |
| 1244 | name: "malloc_not_svelte_static_lib_excludes", |
| 1245 | bazel_module: { bp2build_available: false }, |
| 1246 | } |
| 1247 | |
| 1248 | cc_library { |
| 1249 | name: "arm_shared_lib_excludes", |
| 1250 | bazel_module: { bp2build_available: false }, |
| 1251 | } |
| 1252 | |
| 1253 | cc_library { |
| 1254 | name: "malloc_not_svelte_shared_lib", |
| 1255 | bazel_module: { bp2build_available: false }, |
| 1256 | } |
| 1257 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1258 | ExpectedBazelTargets: makeCcLibraryTargets("foo_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1259 | "implementation_deps": `select({ |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1260 | "//build/bazel/platforms/arch:arm": [], |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1261 | "//conditions:default": [":arm_static_lib_excludes_bp2build_cc_library_static"], |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1262 | }) + select({ |
| 1263 | "//build/bazel/product_variables:malloc_not_svelte": [], |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1264 | "//conditions:default": [":malloc_not_svelte_static_lib_excludes_bp2build_cc_library_static"], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1265 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1266 | "implementation_dynamic_deps": `select({ |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 1267 | "//build/bazel/platforms/arch:arm": [], |
| 1268 | "//conditions:default": [":arm_shared_lib_excludes"], |
| 1269 | }) + select({ |
| 1270 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_shared_lib"], |
| 1271 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1272 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1273 | "srcs_c": `["common.c"]`, |
| 1274 | "whole_archive_deps": `select({ |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1275 | "//build/bazel/platforms/arch:arm": [], |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1276 | "//conditions:default": [":arm_whole_static_lib_excludes_bp2build_cc_library_static"], |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1277 | }) + select({ |
Chris Parsons | 953b356 | 2021-09-20 15:14:39 -0400 | [diff] [blame] | 1278 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_whole_static_lib_bp2build_cc_library_static"], |
| 1279 | "//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] | 1280 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1281 | }), |
| 1282 | }, |
| 1283 | ) |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 1284 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1285 | |
Zi Wang | 0a8a129 | 2022-08-30 06:27:01 +0000 | [diff] [blame] | 1286 | func TestCcLibraryProductVariablesHeaderLibs(t *testing.T) { |
| 1287 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1288 | ModuleTypeUnderTest: "cc_library", |
| 1289 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1290 | Filesystem: map[string]string{}, |
| 1291 | Blueprint: soongCcLibraryStaticPreamble + ` |
| 1292 | cc_library { |
| 1293 | name: "foo_static", |
| 1294 | srcs: ["common.c"], |
| 1295 | product_variables: { |
| 1296 | malloc_not_svelte: { |
| 1297 | header_libs: ["malloc_not_svelte_header_lib"], |
| 1298 | }, |
| 1299 | }, |
| 1300 | include_build_directory: false, |
| 1301 | } |
| 1302 | |
| 1303 | cc_library { |
| 1304 | name: "malloc_not_svelte_header_lib", |
| 1305 | bazel_module: { bp2build_available: false }, |
| 1306 | } |
| 1307 | `, |
| 1308 | ExpectedBazelTargets: makeCcLibraryTargets("foo_static", AttrNameToString{ |
| 1309 | "implementation_deps": `select({ |
| 1310 | "//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_header_lib"], |
| 1311 | "//conditions:default": [], |
| 1312 | })`, |
| 1313 | "srcs_c": `["common.c"]`, |
| 1314 | "target_compatible_with": `["//build/bazel/platforms/os:android"]`, |
| 1315 | }), |
| 1316 | }, |
| 1317 | ) |
| 1318 | } |
| 1319 | |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1320 | func TestCCLibraryNoCrtTrue(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1321 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 1322 | Description: "cc_library - nocrt: true disables feature", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1323 | ModuleTypeUnderTest: "cc_library", |
| 1324 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1325 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1326 | "impl.cpp": "", |
| 1327 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1328 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1329 | cc_library { |
| 1330 | name: "foo-lib", |
| 1331 | srcs: ["impl.cpp"], |
| 1332 | nocrt: true, |
| 1333 | include_build_directory: false, |
| 1334 | } |
| 1335 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1336 | 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] | 1337 | "features": `["-link_crt"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1338 | "srcs": `["impl.cpp"]`, |
| 1339 | }), |
| 1340 | }, |
| 1341 | ) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | func TestCCLibraryNoCrtFalse(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1345 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1346 | Description: "cc_library - nocrt: false - does not emit attribute", |
| 1347 | ModuleTypeUnderTest: "cc_library", |
| 1348 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1349 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1350 | "impl.cpp": "", |
| 1351 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1352 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1353 | cc_library { |
| 1354 | name: "foo-lib", |
| 1355 | srcs: ["impl.cpp"], |
| 1356 | nocrt: false, |
| 1357 | include_build_directory: false, |
| 1358 | } |
| 1359 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1360 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1361 | "srcs": `["impl.cpp"]`, |
| 1362 | }), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1363 | }) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | func TestCCLibraryNoCrtArchVariant(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1367 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1368 | Description: "cc_library - nocrt in select", |
| 1369 | ModuleTypeUnderTest: "cc_library", |
| 1370 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1371 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1372 | "impl.cpp": "", |
| 1373 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1374 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1375 | cc_library { |
| 1376 | name: "foo-lib", |
| 1377 | srcs: ["impl.cpp"], |
| 1378 | arch: { |
| 1379 | arm: { |
| 1380 | nocrt: true, |
| 1381 | }, |
| 1382 | x86: { |
| 1383 | nocrt: false, |
| 1384 | }, |
| 1385 | }, |
| 1386 | include_build_directory: false, |
| 1387 | } |
| 1388 | `, |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 1389 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
| 1390 | "features": `select({ |
| 1391 | "//build/bazel/platforms/arch:arm": ["-link_crt"], |
| 1392 | "//conditions:default": [], |
| 1393 | })`, |
| 1394 | "srcs": `["impl.cpp"]`, |
| 1395 | }), |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1396 | }) |
| 1397 | } |
| 1398 | |
| 1399 | func TestCCLibraryNoLibCrtTrue(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1400 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1401 | ModuleTypeUnderTest: "cc_library", |
| 1402 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1403 | Filesystem: map[string]string{ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1404 | "impl.cpp": "", |
| 1405 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1406 | Blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1407 | cc_library { |
| 1408 | name: "foo-lib", |
| 1409 | srcs: ["impl.cpp"], |
| 1410 | no_libcrt: true, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1411 | include_build_directory: false, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1412 | } |
| 1413 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1414 | 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] | 1415 | "features": `["-use_libcrt"]`, |
| 1416 | "srcs": `["impl.cpp"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1417 | }), |
| 1418 | }) |
| 1419 | } |
| 1420 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1421 | func makeCcLibraryTargets(name string, attrs AttrNameToString) []string { |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1422 | STATIC_ONLY_ATTRS := map[string]bool{} |
| 1423 | SHARED_ONLY_ATTRS := map[string]bool{ |
| 1424 | "link_crt": true, |
| 1425 | "additional_linker_inputs": true, |
| 1426 | "linkopts": true, |
| 1427 | "strip": true, |
Yu Liu | 75be7b9 | 2022-02-01 09:54:09 -0800 | [diff] [blame] | 1428 | "inject_bssl_hash": true, |
Yu Liu | 56ccb1a | 2022-11-12 10:47:07 -0800 | [diff] [blame] | 1429 | "stubs_symbol_file": true, |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 1430 | "use_version_lib": true, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1431 | } |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 1432 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1433 | sharedAttrs := AttrNameToString{} |
| 1434 | staticAttrs := AttrNameToString{} |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1435 | for key, val := range attrs { |
| 1436 | if _, staticOnly := STATIC_ONLY_ATTRS[key]; !staticOnly { |
| 1437 | sharedAttrs[key] = val |
| 1438 | } |
| 1439 | if _, sharedOnly := SHARED_ONLY_ATTRS[key]; !sharedOnly { |
| 1440 | staticAttrs[key] = val |
| 1441 | } |
| 1442 | } |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1443 | sharedTarget := MakeBazelTarget("cc_library_shared", name, sharedAttrs) |
| 1444 | staticTarget := MakeBazelTarget("cc_library_static", name+"_bp2build_cc_library_static", staticAttrs) |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1445 | |
| 1446 | return []string{staticTarget, sharedTarget} |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1447 | } |
| 1448 | |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1449 | func TestCCLibraryNoLibCrtFalse(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1450 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1451 | ModuleTypeUnderTest: "cc_library", |
| 1452 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1453 | Filesystem: map[string]string{ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1454 | "impl.cpp": "", |
| 1455 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1456 | Blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1457 | cc_library { |
| 1458 | name: "foo-lib", |
| 1459 | srcs: ["impl.cpp"], |
| 1460 | no_libcrt: false, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1461 | include_build_directory: false, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1462 | } |
| 1463 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1464 | 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] | 1465 | "srcs": `["impl.cpp"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1466 | }), |
| 1467 | }) |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1468 | } |
| 1469 | |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 1470 | func TestCCLibraryNoLibCrtArchVariant(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1471 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1472 | ModuleTypeUnderTest: "cc_library", |
| 1473 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1474 | Filesystem: map[string]string{ |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1475 | "impl.cpp": "", |
| 1476 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1477 | Blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1478 | cc_library { |
| 1479 | name: "foo-lib", |
| 1480 | srcs: ["impl.cpp"], |
| 1481 | arch: { |
| 1482 | arm: { |
| 1483 | no_libcrt: true, |
| 1484 | }, |
| 1485 | x86: { |
| 1486 | no_libcrt: true, |
| 1487 | }, |
| 1488 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1489 | include_build_directory: false, |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1490 | } |
| 1491 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1492 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1493 | "srcs": `["impl.cpp"]`, |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 1494 | "features": `select({ |
| 1495 | "//build/bazel/platforms/arch:arm": ["-use_libcrt"], |
| 1496 | "//build/bazel/platforms/arch:x86": ["-use_libcrt"], |
| 1497 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1498 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1499 | }), |
| 1500 | }) |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 1501 | } |
| 1502 | |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1503 | func TestCCLibraryNoLibCrtArchAndTargetVariant(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1504 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1505 | ModuleTypeUnderTest: "cc_library", |
| 1506 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1507 | Filesystem: map[string]string{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1508 | "impl.cpp": "", |
| 1509 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1510 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1511 | cc_library { |
| 1512 | name: "foo-lib", |
| 1513 | srcs: ["impl.cpp"], |
| 1514 | arch: { |
| 1515 | arm: { |
| 1516 | no_libcrt: true, |
| 1517 | }, |
| 1518 | x86: { |
| 1519 | no_libcrt: true, |
| 1520 | }, |
| 1521 | }, |
| 1522 | target: { |
| 1523 | darwin: { |
| 1524 | no_libcrt: true, |
| 1525 | } |
| 1526 | }, |
| 1527 | include_build_directory: false, |
| 1528 | } |
| 1529 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1530 | 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] | 1531 | "features": `select({ |
| 1532 | "//build/bazel/platforms/arch:arm": ["-use_libcrt"], |
| 1533 | "//build/bazel/platforms/arch:x86": ["-use_libcrt"], |
| 1534 | "//conditions:default": [], |
| 1535 | }) + select({ |
| 1536 | "//build/bazel/platforms/os:darwin": ["-use_libcrt"], |
| 1537 | "//conditions:default": [], |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1538 | })`, |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 1539 | "srcs": `["impl.cpp"]`, |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1540 | }), |
| 1541 | }) |
| 1542 | } |
| 1543 | |
| 1544 | func TestCCLibraryNoLibCrtArchAndTargetVariantConflict(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1545 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1546 | ModuleTypeUnderTest: "cc_library", |
| 1547 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1548 | Filesystem: map[string]string{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1549 | "impl.cpp": "", |
| 1550 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1551 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1552 | cc_library { |
| 1553 | name: "foo-lib", |
| 1554 | srcs: ["impl.cpp"], |
| 1555 | arch: { |
| 1556 | arm: { |
| 1557 | no_libcrt: true, |
| 1558 | }, |
| 1559 | // This is expected to override the value for darwin_x86_64. |
| 1560 | x86_64: { |
| 1561 | no_libcrt: true, |
| 1562 | }, |
| 1563 | }, |
| 1564 | target: { |
| 1565 | darwin: { |
| 1566 | no_libcrt: false, |
| 1567 | } |
| 1568 | }, |
| 1569 | include_build_directory: false, |
| 1570 | } |
| 1571 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1572 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1573 | "srcs": `["impl.cpp"]`, |
Alex Márquez Pérez Muñíz Díaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 1574 | "features": `select({ |
| 1575 | "//build/bazel/platforms/arch:arm": ["-use_libcrt"], |
| 1576 | "//build/bazel/platforms/arch:x86_64": ["-use_libcrt"], |
| 1577 | "//conditions:default": [], |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 1578 | })`, |
| 1579 | }), |
| 1580 | }) |
| 1581 | } |
| 1582 | |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1583 | func TestCcLibraryStrip(t *testing.T) { |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1584 | expectedTargets := []string{} |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1585 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("all", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1586 | "strip": `{ |
| 1587 | "all": True, |
| 1588 | }`, |
| 1589 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1590 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1591 | "strip": `{ |
| 1592 | "keep_symbols": True, |
| 1593 | }`, |
| 1594 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1595 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols_and_debug_frame", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1596 | "strip": `{ |
| 1597 | "keep_symbols_and_debug_frame": True, |
| 1598 | }`, |
| 1599 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1600 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("keep_symbols_list", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1601 | "strip": `{ |
| 1602 | "keep_symbols_list": ["symbol"], |
| 1603 | }`, |
| 1604 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1605 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("none", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1606 | "strip": `{ |
| 1607 | "none": True, |
| 1608 | }`, |
| 1609 | })...) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1610 | expectedTargets = append(expectedTargets, makeCcLibraryTargets("nothing", AttrNameToString{})...) |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1611 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1612 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1613 | Description: "cc_library strip args", |
| 1614 | ModuleTypeUnderTest: "cc_library", |
| 1615 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1616 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1617 | cc_library { |
| 1618 | name: "nothing", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1619 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1620 | } |
| 1621 | cc_library { |
| 1622 | name: "keep_symbols", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1623 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1624 | keep_symbols: true, |
| 1625 | }, |
| 1626 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1627 | } |
| 1628 | cc_library { |
| 1629 | name: "keep_symbols_and_debug_frame", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1630 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1631 | keep_symbols_and_debug_frame: true, |
| 1632 | }, |
| 1633 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1634 | } |
| 1635 | cc_library { |
| 1636 | name: "none", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1637 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1638 | none: true, |
| 1639 | }, |
| 1640 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1641 | } |
| 1642 | cc_library { |
| 1643 | name: "keep_symbols_list", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1644 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1645 | keep_symbols_list: ["symbol"], |
| 1646 | }, |
| 1647 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1648 | } |
| 1649 | cc_library { |
| 1650 | name: "all", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1651 | strip: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1652 | all: true, |
| 1653 | }, |
| 1654 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1655 | } |
| 1656 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1657 | ExpectedBazelTargets: expectedTargets, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1658 | }) |
| 1659 | } |
| 1660 | |
| 1661 | func TestCcLibraryStripWithArch(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1662 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1663 | Description: "cc_library strip args", |
| 1664 | ModuleTypeUnderTest: "cc_library", |
| 1665 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1666 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1667 | cc_library { |
| 1668 | name: "multi-arch", |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1669 | target: { |
| 1670 | darwin: { |
| 1671 | strip: { |
| 1672 | keep_symbols_list: ["foo", "bar"] |
| 1673 | } |
| 1674 | }, |
| 1675 | }, |
| 1676 | arch: { |
| 1677 | arm: { |
| 1678 | strip: { |
| 1679 | keep_symbols_and_debug_frame: true, |
| 1680 | }, |
| 1681 | }, |
| 1682 | arm64: { |
| 1683 | strip: { |
| 1684 | keep_symbols: true, |
| 1685 | }, |
| 1686 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1687 | }, |
| 1688 | include_build_directory: false, |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1689 | } |
| 1690 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1691 | ExpectedBazelTargets: makeCcLibraryTargets("multi-arch", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1692 | "strip": `{ |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1693 | "keep_symbols": select({ |
| 1694 | "//build/bazel/platforms/arch:arm64": True, |
| 1695 | "//conditions:default": None, |
| 1696 | }), |
| 1697 | "keep_symbols_and_debug_frame": select({ |
| 1698 | "//build/bazel/platforms/arch:arm": True, |
| 1699 | "//conditions:default": None, |
| 1700 | }), |
| 1701 | "keep_symbols_list": select({ |
| 1702 | "//build/bazel/platforms/os:darwin": [ |
| 1703 | "foo", |
| 1704 | "bar", |
| 1705 | ], |
| 1706 | "//conditions:default": [], |
| 1707 | }), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1708 | }`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1709 | }), |
| 1710 | }, |
| 1711 | ) |
Jingwen Chen | 3d383bb | 2021-06-09 07:18:37 +0000 | [diff] [blame] | 1712 | } |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1713 | |
| 1714 | func TestCcLibrary_SystemSharedLibsRootEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1715 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1716 | Description: "cc_library system_shared_libs empty at root", |
| 1717 | ModuleTypeUnderTest: "cc_library", |
| 1718 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1719 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1720 | cc_library { |
| 1721 | name: "root_empty", |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1722 | system_shared_libs: [], |
| 1723 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1724 | } |
| 1725 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1726 | ExpectedBazelTargets: makeCcLibraryTargets("root_empty", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1727 | "system_dynamic_deps": `[]`, |
| 1728 | }), |
| 1729 | }, |
| 1730 | ) |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | func TestCcLibrary_SystemSharedLibsStaticEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1734 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1735 | Description: "cc_library system_shared_libs empty for static variant", |
| 1736 | ModuleTypeUnderTest: "cc_library", |
| 1737 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1738 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1739 | cc_library { |
| 1740 | name: "static_empty", |
| 1741 | static: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1742 | system_shared_libs: [], |
| 1743 | }, |
| 1744 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1745 | } |
| 1746 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1747 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1748 | MakeBazelTarget("cc_library_static", "static_empty_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1749 | "system_dynamic_deps": "[]", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1750 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1751 | MakeBazelTarget("cc_library_shared", "static_empty", AttrNameToString{}), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1752 | }, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1753 | }) |
| 1754 | } |
| 1755 | |
| 1756 | func TestCcLibrary_SystemSharedLibsSharedEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1757 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1758 | Description: "cc_library system_shared_libs empty for shared variant", |
| 1759 | ModuleTypeUnderTest: "cc_library", |
| 1760 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1761 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1762 | cc_library { |
| 1763 | name: "shared_empty", |
| 1764 | shared: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1765 | system_shared_libs: [], |
| 1766 | }, |
| 1767 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1768 | } |
| 1769 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1770 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1771 | MakeBazelTarget("cc_library_static", "shared_empty_bp2build_cc_library_static", AttrNameToString{}), |
| 1772 | MakeBazelTarget("cc_library_shared", "shared_empty", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1773 | "system_dynamic_deps": "[]", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1774 | }), |
| 1775 | }, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1776 | }) |
| 1777 | } |
| 1778 | |
| 1779 | func TestCcLibrary_SystemSharedLibsSharedBionicEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1780 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1781 | Description: "cc_library system_shared_libs empty for shared, bionic variant", |
| 1782 | ModuleTypeUnderTest: "cc_library", |
| 1783 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1784 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1785 | cc_library { |
| 1786 | name: "shared_empty", |
| 1787 | target: { |
| 1788 | bionic: { |
| 1789 | shared: { |
| 1790 | system_shared_libs: [], |
| 1791 | } |
| 1792 | } |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1793 | }, |
| 1794 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1795 | } |
| 1796 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1797 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1798 | MakeBazelTarget("cc_library_static", "shared_empty_bp2build_cc_library_static", AttrNameToString{}), |
| 1799 | MakeBazelTarget("cc_library_shared", "shared_empty", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1800 | "system_dynamic_deps": "[]", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1801 | }), |
| 1802 | }, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1803 | }) |
| 1804 | } |
| 1805 | |
| 1806 | func TestCcLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) { |
| 1807 | // Note that this behavior is technically incorrect (it's a simplification). |
| 1808 | // The correct behavior would be if bp2build wrote `system_dynamic_deps = []` |
| 1809 | // only for linux_bionic, but `android` had `["libc", "libdl", "libm"]. |
| 1810 | // b/195791252 tracks the fix. |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1811 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1812 | Description: "cc_library system_shared_libs empty for linux_bionic variant", |
| 1813 | ModuleTypeUnderTest: "cc_library", |
| 1814 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1815 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1816 | cc_library { |
Trevor Radcliffe | 0d1b402 | 2022-12-12 22:26:34 +0000 | [diff] [blame] | 1817 | name: "libc_musl", |
| 1818 | bazel_module: { bp2build_available: false }, |
| 1819 | } |
| 1820 | |
| 1821 | cc_library { |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1822 | name: "target_linux_bionic_empty", |
| 1823 | target: { |
| 1824 | linux_bionic: { |
| 1825 | system_shared_libs: [], |
| 1826 | }, |
| 1827 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1828 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1829 | } |
| 1830 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1831 | ExpectedBazelTargets: makeCcLibraryTargets("target_linux_bionic_empty", AttrNameToString{ |
Trevor Radcliffe | 0d1b402 | 2022-12-12 22:26:34 +0000 | [diff] [blame] | 1832 | "system_dynamic_deps": `select({ |
| 1833 | "//build/bazel/platforms/os:linux_musl": [":libc_musl"], |
| 1834 | "//conditions:default": [], |
| 1835 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1836 | }), |
| 1837 | }, |
| 1838 | ) |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | func TestCcLibrary_SystemSharedLibsBionicEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1842 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1843 | Description: "cc_library system_shared_libs empty for bionic variant", |
| 1844 | ModuleTypeUnderTest: "cc_library", |
| 1845 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1846 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1847 | cc_library { |
Trevor Radcliffe | 0d1b402 | 2022-12-12 22:26:34 +0000 | [diff] [blame] | 1848 | name: "libc_musl", |
| 1849 | bazel_module: { bp2build_available: false }, |
| 1850 | } |
| 1851 | |
| 1852 | cc_library { |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1853 | name: "target_bionic_empty", |
| 1854 | target: { |
| 1855 | bionic: { |
| 1856 | system_shared_libs: [], |
| 1857 | }, |
| 1858 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1859 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1860 | } |
| 1861 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1862 | ExpectedBazelTargets: makeCcLibraryTargets("target_bionic_empty", AttrNameToString{ |
Trevor Radcliffe | 0d1b402 | 2022-12-12 22:26:34 +0000 | [diff] [blame] | 1863 | "system_dynamic_deps": `select({ |
| 1864 | "//build/bazel/platforms/os:linux_musl": [":libc_musl"], |
| 1865 | "//conditions:default": [], |
| 1866 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1867 | }), |
| 1868 | }, |
| 1869 | ) |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1870 | } |
| 1871 | |
Trevor Radcliffe | 0d1b402 | 2022-12-12 22:26:34 +0000 | [diff] [blame] | 1872 | func TestCcLibrary_SystemSharedLibsMuslEmpty(t *testing.T) { |
| 1873 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1874 | Description: "cc_library system_shared_lib empty for musl variant", |
| 1875 | ModuleTypeUnderTest: "cc_library", |
| 1876 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1877 | Blueprint: soongCcLibraryPreamble + ` |
| 1878 | cc_library { |
| 1879 | name: "libc_musl", |
| 1880 | bazel_module: { bp2build_available: false }, |
| 1881 | } |
| 1882 | |
| 1883 | cc_library { |
| 1884 | name: "target_musl_empty", |
| 1885 | target: { |
| 1886 | musl: { |
| 1887 | system_shared_libs: [], |
| 1888 | }, |
| 1889 | }, |
| 1890 | include_build_directory: false, |
| 1891 | } |
| 1892 | `, |
| 1893 | ExpectedBazelTargets: makeCcLibraryTargets("target_musl_empty", AttrNameToString{ |
| 1894 | "system_dynamic_deps": `[]`, |
| 1895 | }), |
| 1896 | }) |
| 1897 | } |
| 1898 | |
| 1899 | func TestCcLibrary_SystemSharedLibsLinuxMuslEmpty(t *testing.T) { |
| 1900 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1901 | Description: "cc_library system_shared_lib empty for linux_musl variant", |
| 1902 | ModuleTypeUnderTest: "cc_library", |
| 1903 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1904 | Blueprint: soongCcLibraryPreamble + ` |
| 1905 | cc_library { |
| 1906 | name: "libc_musl", |
| 1907 | bazel_module: { bp2build_available: false }, |
| 1908 | } |
| 1909 | |
| 1910 | cc_library { |
| 1911 | name: "target_linux_musl_empty", |
| 1912 | target: { |
| 1913 | linux_musl: { |
| 1914 | system_shared_libs: [], |
| 1915 | }, |
| 1916 | }, |
| 1917 | include_build_directory: false, |
| 1918 | } |
| 1919 | `, |
| 1920 | ExpectedBazelTargets: makeCcLibraryTargets("target_linux_musl_empty", AttrNameToString{ |
| 1921 | "system_dynamic_deps": `[]`, |
| 1922 | }), |
| 1923 | }) |
| 1924 | } |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1925 | func TestCcLibrary_SystemSharedLibsSharedAndRoot(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1926 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1927 | Description: "cc_library system_shared_libs set for shared and root", |
| 1928 | ModuleTypeUnderTest: "cc_library", |
| 1929 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1930 | Blueprint: soongCcLibraryPreamble + ` |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1931 | cc_library { |
| 1932 | name: "libc", |
| 1933 | bazel_module: { bp2build_available: false }, |
| 1934 | } |
| 1935 | cc_library { |
| 1936 | name: "libm", |
| 1937 | bazel_module: { bp2build_available: false }, |
| 1938 | } |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1939 | |
| 1940 | cc_library { |
| 1941 | name: "foo", |
| 1942 | system_shared_libs: ["libc"], |
| 1943 | shared: { |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1944 | system_shared_libs: ["libm"], |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1945 | }, |
Liz Kammer | 8337ea4 | 2021-09-10 10:06:32 -0400 | [diff] [blame] | 1946 | include_build_directory: false, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1947 | } |
| 1948 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1949 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1950 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1951 | "system_dynamic_deps": `[":libc"]`, |
| 1952 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 1953 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 1954 | "system_dynamic_deps": `[ |
| 1955 | ":libc", |
| 1956 | ":libm", |
| 1957 | ]`, |
| 1958 | }), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1959 | }, |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 1960 | }) |
| 1961 | } |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1962 | |
| 1963 | func TestCcLibraryOsSelects(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1964 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 1965 | Description: "cc_library - selects for all os targets", |
| 1966 | ModuleTypeUnderTest: "cc_library", |
| 1967 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 1968 | Filesystem: map[string]string{}, |
| 1969 | Blueprint: soongCcLibraryPreamble + ` |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 1970 | cc_library { |
| 1971 | name: "foo-lib", |
| 1972 | srcs: ["base.cpp"], |
| 1973 | target: { |
| 1974 | android: { |
| 1975 | srcs: ["android.cpp"], |
| 1976 | }, |
| 1977 | linux: { |
| 1978 | srcs: ["linux.cpp"], |
| 1979 | }, |
| 1980 | linux_glibc: { |
| 1981 | srcs: ["linux_glibc.cpp"], |
| 1982 | }, |
| 1983 | darwin: { |
| 1984 | srcs: ["darwin.cpp"], |
| 1985 | }, |
| 1986 | bionic: { |
| 1987 | srcs: ["bionic.cpp"], |
| 1988 | }, |
| 1989 | linux_musl: { |
| 1990 | srcs: ["linux_musl.cpp"], |
| 1991 | }, |
| 1992 | windows: { |
| 1993 | srcs: ["windows.cpp"], |
| 1994 | }, |
| 1995 | }, |
| 1996 | include_build_directory: false, |
| 1997 | } |
| 1998 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1999 | ExpectedBazelTargets: makeCcLibraryTargets("foo-lib", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2000 | "srcs": `["base.cpp"] + select({ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 2001 | "//build/bazel/platforms/os:android": [ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 2002 | "linux.cpp", |
Liz Kammer | 9bad9d6 | 2021-10-11 15:40:35 -0400 | [diff] [blame] | 2003 | "bionic.cpp", |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 2004 | "android.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 2005 | ], |
| 2006 | "//build/bazel/platforms/os:darwin": ["darwin.cpp"], |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 2007 | "//build/bazel/platforms/os:linux_bionic": [ |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 2008 | "linux.cpp", |
Liz Kammer | 9bad9d6 | 2021-10-11 15:40:35 -0400 | [diff] [blame] | 2009 | "bionic.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 2010 | ], |
Colin Cross | 133782e | 2022-12-20 15:29:31 -0800 | [diff] [blame] | 2011 | "//build/bazel/platforms/os:linux_glibc": [ |
| 2012 | "linux.cpp", |
| 2013 | "linux_glibc.cpp", |
| 2014 | ], |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 2015 | "//build/bazel/platforms/os:linux_musl": [ |
Liz Kammer | 9bad9d6 | 2021-10-11 15:40:35 -0400 | [diff] [blame] | 2016 | "linux.cpp", |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 2017 | "linux_musl.cpp", |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 2018 | ], |
| 2019 | "//build/bazel/platforms/os:windows": ["windows.cpp"], |
| 2020 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 2021 | })`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2022 | }), |
| 2023 | }, |
| 2024 | ) |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2025 | } |
| 2026 | |
Yu Liu | 75be7b9 | 2022-02-01 09:54:09 -0800 | [diff] [blame] | 2027 | func TestLibcryptoHashInjection(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2028 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2029 | Description: "cc_library - libcrypto hash injection", |
| 2030 | ModuleTypeUnderTest: "cc_library", |
| 2031 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2032 | Filesystem: map[string]string{}, |
| 2033 | Blueprint: soongCcLibraryPreamble + ` |
Yu Liu | 75be7b9 | 2022-02-01 09:54:09 -0800 | [diff] [blame] | 2034 | cc_library { |
| 2035 | name: "libcrypto", |
| 2036 | target: { |
| 2037 | android: { |
| 2038 | inject_bssl_hash: true, |
| 2039 | }, |
| 2040 | }, |
| 2041 | include_build_directory: false, |
| 2042 | } |
| 2043 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2044 | ExpectedBazelTargets: makeCcLibraryTargets("libcrypto", AttrNameToString{ |
Yu Liu | 75be7b9 | 2022-02-01 09:54:09 -0800 | [diff] [blame] | 2045 | "inject_bssl_hash": `select({ |
| 2046 | "//build/bazel/platforms/os:android": True, |
| 2047 | "//conditions:default": None, |
| 2048 | })`, |
| 2049 | }), |
| 2050 | }, |
| 2051 | ) |
| 2052 | } |
| 2053 | |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2054 | func TestCcLibraryCppStdWithGnuExtensions_ConvertsToFeatureAttr(t *testing.T) { |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2055 | type testCase struct { |
| 2056 | cpp_std string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2057 | c_std string |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2058 | gnu_extensions string |
| 2059 | bazel_cpp_std string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2060 | bazel_c_std string |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | testCases := []testCase{ |
| 2064 | // Existing usages of cpp_std in AOSP are: |
| 2065 | // experimental, c++11, c++17, c++2a, c++98, gnu++11, gnu++17 |
| 2066 | // |
| 2067 | // not set, only emit if gnu_extensions is disabled. the default (gnu+17 |
| 2068 | // is set in the toolchain.) |
| 2069 | {cpp_std: "", gnu_extensions: "", bazel_cpp_std: ""}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2070 | {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] | 2071 | {cpp_std: "", gnu_extensions: "true", bazel_cpp_std: ""}, |
| 2072 | // experimental defaults to gnu++2a |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2073 | {cpp_std: "experimental", gnu_extensions: "", bazel_cpp_std: "cpp_std_experimental"}, |
| 2074 | {cpp_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "cpp_std_experimental_no_gnu", bazel_c_std: "c_std_default_no_gnu"}, |
| 2075 | {cpp_std: "experimental", gnu_extensions: "true", bazel_cpp_std: "cpp_std_experimental"}, |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2076 | // Explicitly setting a c++ std does not use replace gnu++ std even if |
| 2077 | // gnu_extensions is true. |
| 2078 | // "c++11", |
| 2079 | {cpp_std: "c++11", gnu_extensions: "", bazel_cpp_std: "c++11"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2080 | {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] | 2081 | {cpp_std: "c++11", gnu_extensions: "true", bazel_cpp_std: "c++11"}, |
| 2082 | // "c++17", |
| 2083 | {cpp_std: "c++17", gnu_extensions: "", bazel_cpp_std: "c++17"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2084 | {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] | 2085 | {cpp_std: "c++17", gnu_extensions: "true", bazel_cpp_std: "c++17"}, |
| 2086 | // "c++2a", |
| 2087 | {cpp_std: "c++2a", gnu_extensions: "", bazel_cpp_std: "c++2a"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2088 | {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] | 2089 | {cpp_std: "c++2a", gnu_extensions: "true", bazel_cpp_std: "c++2a"}, |
| 2090 | // "c++98", |
| 2091 | {cpp_std: "c++98", gnu_extensions: "", bazel_cpp_std: "c++98"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2092 | {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] | 2093 | {cpp_std: "c++98", gnu_extensions: "true", bazel_cpp_std: "c++98"}, |
| 2094 | // gnu++ is replaced with c++ if gnu_extensions is explicitly false. |
| 2095 | // "gnu++11", |
| 2096 | {cpp_std: "gnu++11", gnu_extensions: "", bazel_cpp_std: "gnu++11"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2097 | {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] | 2098 | {cpp_std: "gnu++11", gnu_extensions: "true", bazel_cpp_std: "gnu++11"}, |
| 2099 | // "gnu++17", |
| 2100 | {cpp_std: "gnu++17", gnu_extensions: "", bazel_cpp_std: "gnu++17"}, |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2101 | {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] | 2102 | {cpp_std: "gnu++17", gnu_extensions: "true", bazel_cpp_std: "gnu++17"}, |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2103 | |
| 2104 | // some c_std test cases |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2105 | {c_std: "experimental", gnu_extensions: "", bazel_c_std: "c_std_experimental"}, |
| 2106 | {c_std: "experimental", gnu_extensions: "false", bazel_cpp_std: "cpp_std_default_no_gnu", bazel_c_std: "c_std_experimental_no_gnu"}, |
| 2107 | {c_std: "experimental", gnu_extensions: "true", bazel_c_std: "c_std_experimental"}, |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2108 | {c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "", bazel_cpp_std: "gnu++17", bazel_c_std: "gnu11"}, |
| 2109 | {c_std: "gnu11", cpp_std: "gnu++17", gnu_extensions: "false", bazel_cpp_std: "c++17", bazel_c_std: "c11"}, |
| 2110 | {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] | 2111 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2112 | for i, tc := range testCases { |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2113 | name := fmt.Sprintf("cpp std: %q, c std: %q, gnu_extensions: %q", tc.cpp_std, tc.c_std, tc.gnu_extensions) |
| 2114 | t.Run(name, func(t *testing.T) { |
| 2115 | name_prefix := fmt.Sprintf("a_%v", i) |
| 2116 | cppStdProp := "" |
| 2117 | if tc.cpp_std != "" { |
| 2118 | cppStdProp = fmt.Sprintf(" cpp_std: \"%s\",", tc.cpp_std) |
| 2119 | } |
| 2120 | cStdProp := "" |
| 2121 | if tc.c_std != "" { |
| 2122 | cStdProp = fmt.Sprintf(" c_std: \"%s\",", tc.c_std) |
| 2123 | } |
| 2124 | gnuExtensionsProp := "" |
| 2125 | if tc.gnu_extensions != "" { |
| 2126 | gnuExtensionsProp = fmt.Sprintf(" gnu_extensions: %s,", tc.gnu_extensions) |
| 2127 | } |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2128 | attrs := AttrNameToString{} |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2129 | if tc.bazel_cpp_std != "" { |
| 2130 | attrs["cpp_std"] = fmt.Sprintf(`"%s"`, tc.bazel_cpp_std) |
| 2131 | } |
| 2132 | if tc.bazel_c_std != "" { |
| 2133 | attrs["c_std"] = fmt.Sprintf(`"%s"`, tc.bazel_c_std) |
| 2134 | } |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2135 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2136 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2137 | Description: fmt.Sprintf( |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2138 | "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] | 2139 | ModuleTypeUnderTest: "cc_library", |
| 2140 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2141 | Blueprint: soongCcLibraryPreamble + fmt.Sprintf(` |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2142 | cc_library { |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2143 | name: "%s_full", |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2144 | %s // cpp_std: *string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2145 | %s // c_std: *string |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2146 | %s // gnu_extensions: *bool |
| 2147 | include_build_directory: false, |
| 2148 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2149 | `, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2150 | ExpectedBazelTargets: makeCcLibraryTargets(name_prefix+"_full", attrs), |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2151 | }) |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2152 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2153 | runCcLibraryStaticTestCase(t, Bp2buildTestCase{ |
| 2154 | Description: fmt.Sprintf( |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2155 | "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] | 2156 | ModuleTypeUnderTest: "cc_library_static", |
| 2157 | ModuleTypeUnderTestFactory: cc.LibraryStaticFactory, |
| 2158 | Blueprint: soongCcLibraryPreamble + fmt.Sprintf(` |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2159 | cc_library_static { |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2160 | name: "%s_static", |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2161 | %s // cpp_std: *string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2162 | %s // c_std: *string |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2163 | %s // gnu_extensions: *bool |
| 2164 | include_build_directory: false, |
| 2165 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2166 | `, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2167 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2168 | MakeBazelTarget("cc_library_static", name_prefix+"_static", attrs), |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2169 | }, |
| 2170 | }) |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2171 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2172 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 2173 | Description: fmt.Sprintf( |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2174 | "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] | 2175 | ModuleTypeUnderTest: "cc_library_shared", |
| 2176 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 2177 | Blueprint: soongCcLibraryPreamble + fmt.Sprintf(` |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2178 | cc_library_shared { |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2179 | name: "%s_shared", |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2180 | %s // cpp_std: *string |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2181 | %s // c_std: *string |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2182 | %s // gnu_extensions: *bool |
| 2183 | include_build_directory: false, |
| 2184 | } |
Chris Parsons | 79bd2b7 | 2021-11-29 17:52:41 -0500 | [diff] [blame] | 2185 | `, name_prefix, cppStdProp, cStdProp, gnuExtensionsProp), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2186 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2187 | MakeBazelTarget("cc_library_shared", name_prefix+"_shared", attrs), |
Liz Kammer | a5a29de | 2022-05-25 23:19:37 -0400 | [diff] [blame] | 2188 | }, |
| 2189 | }) |
Jingwen Chen | 5b11ab1 | 2021-10-11 17:44:33 +0000 | [diff] [blame] | 2190 | }) |
Jingwen Chen | 97b8531 | 2021-10-08 10:41:31 +0000 | [diff] [blame] | 2191 | } |
Chris Parsons | 2dde0cb | 2021-10-01 14:45:30 -0400 | [diff] [blame] | 2192 | } |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2193 | |
| 2194 | func TestCcLibraryProtoSimple(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2195 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2196 | ModuleTypeUnderTest: "cc_library", |
| 2197 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2198 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2199 | name: "foo", |
| 2200 | srcs: ["foo.proto"], |
| 2201 | include_build_directory: false, |
| 2202 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2203 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2204 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 7756c8f | 2022-02-14 20:49:15 -0500 | [diff] [blame] | 2205 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2206 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2207 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2208 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2209 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2210 | "deps": `[":libprotobuf-cpp-lite"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2211 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2212 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2213 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2214 | }), |
| 2215 | }, |
| 2216 | }) |
| 2217 | } |
| 2218 | |
| 2219 | func TestCcLibraryProtoNoCanonicalPathFromRoot(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2220 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2221 | ModuleTypeUnderTest: "cc_library", |
| 2222 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2223 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2224 | name: "foo", |
| 2225 | srcs: ["foo.proto"], |
| 2226 | proto: { canonical_path_from_root: false}, |
| 2227 | include_build_directory: false, |
| 2228 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2229 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2230 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 7756c8f | 2022-02-14 20:49:15 -0500 | [diff] [blame] | 2231 | "srcs": `["foo.proto"]`, |
| 2232 | "strip_import_prefix": `""`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2233 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2234 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2235 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2236 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2237 | "deps": `[":libprotobuf-cpp-lite"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2238 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2239 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2240 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2241 | }), |
| 2242 | }, |
| 2243 | }) |
| 2244 | } |
| 2245 | |
| 2246 | func TestCcLibraryProtoExplicitCanonicalPathFromRoot(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2247 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2248 | ModuleTypeUnderTest: "cc_library", |
| 2249 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2250 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2251 | name: "foo", |
| 2252 | srcs: ["foo.proto"], |
| 2253 | proto: { canonical_path_from_root: true}, |
| 2254 | include_build_directory: false, |
| 2255 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2256 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2257 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 7756c8f | 2022-02-14 20:49:15 -0500 | [diff] [blame] | 2258 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2259 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2260 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2261 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2262 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2263 | "deps": `[":libprotobuf-cpp-lite"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2264 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2265 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2266 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2267 | }), |
| 2268 | }, |
| 2269 | }) |
| 2270 | } |
| 2271 | |
| 2272 | func TestCcLibraryProtoFull(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2273 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2274 | ModuleTypeUnderTest: "cc_library", |
| 2275 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2276 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2277 | name: "foo", |
| 2278 | srcs: ["foo.proto"], |
| 2279 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2280 | type: "full", |
| 2281 | }, |
| 2282 | include_build_directory: false, |
| 2283 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2284 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2285 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2286 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2287 | }), MakeBazelTarget("cc_proto_library", "foo_cc_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2288 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2289 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2290 | "implementation_whole_archive_deps": `[":foo_cc_proto"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2291 | "deps": `[":libprotobuf-cpp-full"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2292 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2293 | "dynamic_deps": `[":libprotobuf-cpp-full"]`, |
| 2294 | "implementation_whole_archive_deps": `[":foo_cc_proto"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2295 | }), |
| 2296 | }, |
| 2297 | }) |
| 2298 | } |
| 2299 | |
| 2300 | func TestCcLibraryProtoLite(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2301 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2302 | ModuleTypeUnderTest: "cc_library", |
| 2303 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2304 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2305 | name: "foo", |
| 2306 | srcs: ["foo.proto"], |
| 2307 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2308 | type: "lite", |
| 2309 | }, |
| 2310 | include_build_directory: false, |
| 2311 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2312 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2313 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2314 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2315 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2316 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2317 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2318 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2319 | "deps": `[":libprotobuf-cpp-lite"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2320 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2321 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2322 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2323 | }), |
| 2324 | }, |
| 2325 | }) |
| 2326 | } |
| 2327 | |
| 2328 | func TestCcLibraryProtoExportHeaders(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2329 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2330 | ModuleTypeUnderTest: "cc_library", |
| 2331 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2332 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2333 | name: "foo", |
| 2334 | srcs: ["foo.proto"], |
| 2335 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2336 | export_proto_headers: true, |
| 2337 | }, |
| 2338 | include_build_directory: false, |
| 2339 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2340 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2341 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2342 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2343 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2344 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2345 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2346 | "deps": `[":libprotobuf-cpp-lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2347 | "whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2348 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Chris Parsons | 77acf2e | 2021-12-03 17:27:16 -0500 | [diff] [blame] | 2349 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2350 | "whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 2351 | }), |
| 2352 | }, |
| 2353 | }) |
| 2354 | } |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2355 | |
Yu Liu | 2d13614 | 2022-08-18 14:46:13 -0700 | [diff] [blame] | 2356 | func TestCcLibraryProtoIncludeDirs(t *testing.T) { |
| 2357 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2358 | ModuleTypeUnderTest: "cc_library", |
| 2359 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2360 | Blueprint: soongCcProtoPreamble + `cc_library { |
| 2361 | name: "foo", |
| 2362 | srcs: ["foo.proto"], |
| 2363 | proto: { |
| 2364 | include_dirs: ["external/protobuf/src"], |
| 2365 | }, |
| 2366 | include_build_directory: false, |
| 2367 | }`, |
| 2368 | ExpectedBazelTargets: []string{ |
| 2369 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
| 2370 | "srcs": `["foo.proto"]`, |
| 2371 | "deps": `["//external/protobuf:libprotobuf-proto"]`, |
| 2372 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
| 2373 | "deps": `[":foo_proto"]`, |
| 2374 | }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 2375 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2376 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
| 2377 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 2378 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2379 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
Yu Liu | 2d13614 | 2022-08-18 14:46:13 -0700 | [diff] [blame] | 2380 | }), |
| 2381 | }, |
| 2382 | }) |
| 2383 | } |
| 2384 | |
| 2385 | func TestCcLibraryProtoIncludeDirsUnknown(t *testing.T) { |
| 2386 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2387 | ModuleTypeUnderTest: "cc_library", |
| 2388 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2389 | Blueprint: soongCcProtoPreamble + `cc_library { |
| 2390 | name: "foo", |
| 2391 | srcs: ["foo.proto"], |
| 2392 | proto: { |
| 2393 | include_dirs: ["external/protobuf/abc"], |
| 2394 | }, |
| 2395 | include_build_directory: false, |
| 2396 | }`, |
| 2397 | ExpectedErr: fmt.Errorf("module \"foo\": Could not find the proto_library target for include dir: external/protobuf/abc"), |
| 2398 | }) |
| 2399 | } |
| 2400 | |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 2401 | func TestCcLibraryConvertedProtoFilegroups(t *testing.T) { |
| 2402 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2403 | ModuleTypeUnderTest: "cc_library", |
| 2404 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2405 | Blueprint: soongCcProtoPreamble + ` |
| 2406 | filegroup { |
| 2407 | name: "a_fg_proto", |
| 2408 | srcs: ["a_fg.proto"], |
| 2409 | } |
| 2410 | |
| 2411 | cc_library { |
| 2412 | name: "a", |
| 2413 | srcs: [ |
| 2414 | ":a_fg_proto", |
| 2415 | "a.proto", |
| 2416 | ], |
| 2417 | proto: { |
| 2418 | export_proto_headers: true, |
| 2419 | }, |
| 2420 | include_build_directory: false, |
| 2421 | }`, |
| 2422 | ExpectedBazelTargets: []string{ |
| 2423 | MakeBazelTarget("proto_library", "a_proto", AttrNameToString{ |
Yu Liu | 2a85fb1 | 2022-09-15 22:18:48 -0700 | [diff] [blame] | 2424 | "deps": `[":a_fg_proto_bp2build_converted"]`, |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 2425 | "srcs": `["a.proto"]`, |
| 2426 | }), MakeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{ |
| 2427 | "deps": `[ |
| 2428 | ":a_fg_proto_bp2build_converted", |
| 2429 | ":a_proto", |
| 2430 | ]`, |
| 2431 | }), MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
| 2432 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2433 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2434 | }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
| 2435 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2436 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2437 | }), MakeBazelTargetNoRestrictions("proto_library", "a_fg_proto_bp2build_converted", AttrNameToString{ |
| 2438 | "srcs": `["a_fg.proto"]`, |
Liz Kammer | 2b3f56e | 2023-03-23 11:51:49 -0400 | [diff] [blame] | 2439 | "tags": `[ |
| 2440 | "apex_available=//apex_available:anyapex", |
| 2441 | "manual", |
| 2442 | ]`, |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 2443 | }), MakeBazelTargetNoRestrictions("filegroup", "a_fg_proto", AttrNameToString{ |
| 2444 | "srcs": `["a_fg.proto"]`, |
| 2445 | }), |
| 2446 | }, |
| 2447 | }) |
| 2448 | } |
| 2449 | |
| 2450 | func TestCcLibraryConvertedProtoFilegroupsNoProtoFiles(t *testing.T) { |
| 2451 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2452 | ModuleTypeUnderTest: "cc_library", |
| 2453 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2454 | Blueprint: soongCcProtoPreamble + ` |
| 2455 | filegroup { |
| 2456 | name: "a_fg_proto", |
| 2457 | srcs: ["a_fg.proto"], |
| 2458 | } |
| 2459 | |
| 2460 | cc_library { |
| 2461 | name: "a", |
| 2462 | srcs: [ |
| 2463 | ":a_fg_proto", |
| 2464 | ], |
| 2465 | proto: { |
| 2466 | export_proto_headers: true, |
| 2467 | }, |
| 2468 | include_build_directory: false, |
| 2469 | }`, |
| 2470 | ExpectedBazelTargets: []string{ |
| 2471 | MakeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{ |
| 2472 | "deps": `[":a_fg_proto_bp2build_converted"]`, |
| 2473 | }), MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
| 2474 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2475 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2476 | }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
| 2477 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2478 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2479 | }), MakeBazelTargetNoRestrictions("proto_library", "a_fg_proto_bp2build_converted", AttrNameToString{ |
| 2480 | "srcs": `["a_fg.proto"]`, |
Liz Kammer | 2b3f56e | 2023-03-23 11:51:49 -0400 | [diff] [blame] | 2481 | "tags": `[ |
| 2482 | "apex_available=//apex_available:anyapex", |
| 2483 | "manual", |
| 2484 | ]`, |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 2485 | }), MakeBazelTargetNoRestrictions("filegroup", "a_fg_proto", AttrNameToString{ |
| 2486 | "srcs": `["a_fg.proto"]`, |
| 2487 | }), |
| 2488 | }, |
| 2489 | }) |
| 2490 | } |
| 2491 | |
| 2492 | func TestCcLibraryExternalConvertedProtoFilegroups(t *testing.T) { |
| 2493 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2494 | ModuleTypeUnderTest: "cc_library", |
| 2495 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2496 | Filesystem: map[string]string{ |
| 2497 | "path/to/A/Android.bp": ` |
| 2498 | filegroup { |
| 2499 | name: "a_fg_proto", |
| 2500 | srcs: ["a_fg.proto"], |
| 2501 | }`, |
| 2502 | }, |
| 2503 | Blueprint: soongCcProtoPreamble + ` |
| 2504 | cc_library { |
| 2505 | name: "a", |
| 2506 | srcs: [ |
| 2507 | ":a_fg_proto", |
| 2508 | "a.proto", |
| 2509 | ], |
| 2510 | proto: { |
| 2511 | export_proto_headers: true, |
| 2512 | }, |
| 2513 | include_build_directory: false, |
| 2514 | }`, |
| 2515 | ExpectedBazelTargets: []string{ |
| 2516 | MakeBazelTarget("proto_library", "a_proto", AttrNameToString{ |
Yu Liu | 2a85fb1 | 2022-09-15 22:18:48 -0700 | [diff] [blame] | 2517 | "deps": `["//path/to/A:a_fg_proto_bp2build_converted"]`, |
Yu Liu | 2aa806b | 2022-09-01 11:54:47 -0700 | [diff] [blame] | 2518 | "srcs": `["a.proto"]`, |
| 2519 | }), MakeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{ |
| 2520 | "deps": `[ |
| 2521 | "//path/to/A:a_fg_proto_bp2build_converted", |
| 2522 | ":a_proto", |
| 2523 | ]`, |
| 2524 | }), MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
| 2525 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2526 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2527 | }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
| 2528 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2529 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2530 | }), |
| 2531 | }, |
| 2532 | }) |
| 2533 | } |
| 2534 | |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2535 | func TestCcLibraryProtoFilegroups(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2536 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2537 | ModuleTypeUnderTest: "cc_library", |
| 2538 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2539 | Blueprint: soongCcProtoPreamble + |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2540 | simpleModuleDoNotConvertBp2build("filegroup", "a_fg_proto") + |
| 2541 | simpleModuleDoNotConvertBp2build("filegroup", "b_protos") + |
| 2542 | simpleModuleDoNotConvertBp2build("filegroup", "c-proto-srcs") + |
| 2543 | simpleModuleDoNotConvertBp2build("filegroup", "proto-srcs-d") + ` |
| 2544 | cc_library { |
| 2545 | name: "a", |
| 2546 | srcs: [":a_fg_proto"], |
| 2547 | proto: { |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2548 | export_proto_headers: true, |
| 2549 | }, |
| 2550 | include_build_directory: false, |
| 2551 | } |
| 2552 | |
| 2553 | cc_library { |
| 2554 | name: "b", |
| 2555 | srcs: [":b_protos"], |
| 2556 | proto: { |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2557 | export_proto_headers: true, |
| 2558 | }, |
| 2559 | include_build_directory: false, |
| 2560 | } |
| 2561 | |
| 2562 | cc_library { |
| 2563 | name: "c", |
| 2564 | srcs: [":c-proto-srcs"], |
| 2565 | proto: { |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2566 | export_proto_headers: true, |
| 2567 | }, |
| 2568 | include_build_directory: false, |
| 2569 | } |
| 2570 | |
| 2571 | cc_library { |
| 2572 | name: "d", |
| 2573 | srcs: [":proto-srcs-d"], |
| 2574 | proto: { |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2575 | export_proto_headers: true, |
| 2576 | }, |
| 2577 | include_build_directory: false, |
| 2578 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2579 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2580 | MakeBazelTarget("proto_library", "a_proto", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2581 | "srcs": `[":a_fg_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2582 | }), MakeBazelTarget("cc_lite_proto_library", "a_cc_proto_lite", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2583 | "deps": `[":a_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2584 | }), MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2585 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2586 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2587 | "srcs": `[":a_fg_proto_cpp_srcs"]`, |
| 2588 | "srcs_as": `[":a_fg_proto_as_srcs"]`, |
| 2589 | "srcs_c": `[":a_fg_proto_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2590 | }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2591 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2592 | "whole_archive_deps": `[":a_cc_proto_lite"]`, |
| 2593 | "srcs": `[":a_fg_proto_cpp_srcs"]`, |
| 2594 | "srcs_as": `[":a_fg_proto_as_srcs"]`, |
| 2595 | "srcs_c": `[":a_fg_proto_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2596 | }), MakeBazelTarget("proto_library", "b_proto", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2597 | "srcs": `[":b_protos"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2598 | }), MakeBazelTarget("cc_lite_proto_library", "b_cc_proto_lite", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2599 | "deps": `[":b_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2600 | }), MakeBazelTarget("cc_library_static", "b_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2601 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2602 | "whole_archive_deps": `[":b_cc_proto_lite"]`, |
| 2603 | "srcs": `[":b_protos_cpp_srcs"]`, |
| 2604 | "srcs_as": `[":b_protos_as_srcs"]`, |
| 2605 | "srcs_c": `[":b_protos_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2606 | }), MakeBazelTarget("cc_library_shared", "b", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2607 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2608 | "whole_archive_deps": `[":b_cc_proto_lite"]`, |
| 2609 | "srcs": `[":b_protos_cpp_srcs"]`, |
| 2610 | "srcs_as": `[":b_protos_as_srcs"]`, |
| 2611 | "srcs_c": `[":b_protos_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2612 | }), MakeBazelTarget("proto_library", "c_proto", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2613 | "srcs": `[":c-proto-srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2614 | }), MakeBazelTarget("cc_lite_proto_library", "c_cc_proto_lite", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2615 | "deps": `[":c_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2616 | }), MakeBazelTarget("cc_library_static", "c_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2617 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2618 | "whole_archive_deps": `[":c_cc_proto_lite"]`, |
| 2619 | "srcs": `[":c-proto-srcs_cpp_srcs"]`, |
| 2620 | "srcs_as": `[":c-proto-srcs_as_srcs"]`, |
| 2621 | "srcs_c": `[":c-proto-srcs_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2622 | }), MakeBazelTarget("cc_library_shared", "c", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2623 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2624 | "whole_archive_deps": `[":c_cc_proto_lite"]`, |
| 2625 | "srcs": `[":c-proto-srcs_cpp_srcs"]`, |
| 2626 | "srcs_as": `[":c-proto-srcs_as_srcs"]`, |
| 2627 | "srcs_c": `[":c-proto-srcs_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2628 | }), MakeBazelTarget("proto_library", "d_proto", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2629 | "srcs": `[":proto-srcs-d"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2630 | }), MakeBazelTarget("cc_lite_proto_library", "d_cc_proto_lite", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2631 | "deps": `[":d_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2632 | }), MakeBazelTarget("cc_library_static", "d_bp2build_cc_library_static", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2633 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 2634 | "whole_archive_deps": `[":d_cc_proto_lite"]`, |
| 2635 | "srcs": `[":proto-srcs-d_cpp_srcs"]`, |
| 2636 | "srcs_as": `[":proto-srcs-d_as_srcs"]`, |
| 2637 | "srcs_c": `[":proto-srcs-d_c_srcs"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2638 | }), MakeBazelTarget("cc_library_shared", "d", AttrNameToString{ |
Liz Kammer | aabfb5d | 2021-12-08 15:25:06 -0500 | [diff] [blame] | 2639 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 2640 | "whole_archive_deps": `[":d_cc_proto_lite"]`, |
| 2641 | "srcs": `[":proto-srcs-d_cpp_srcs"]`, |
| 2642 | "srcs_as": `[":proto-srcs-d_as_srcs"]`, |
| 2643 | "srcs_c": `[":proto-srcs-d_c_srcs"]`, |
| 2644 | }), |
| 2645 | }, |
| 2646 | }) |
| 2647 | } |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2648 | |
| 2649 | func TestCcLibraryDisabledArchAndTarget(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2650 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2651 | ModuleTypeUnderTest: "cc_library", |
| 2652 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2653 | Blueprint: soongCcProtoPreamble + `cc_library { |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2654 | name: "foo", |
| 2655 | srcs: ["foo.cpp"], |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 2656 | host_supported: true, |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2657 | target: { |
| 2658 | darwin: { |
| 2659 | enabled: false, |
| 2660 | }, |
| 2661 | windows: { |
| 2662 | enabled: false, |
| 2663 | }, |
| 2664 | linux_glibc_x86: { |
| 2665 | enabled: false, |
| 2666 | }, |
| 2667 | }, |
| 2668 | include_build_directory: false, |
| 2669 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2670 | ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2671 | "srcs": `["foo.cpp"]`, |
| 2672 | "target_compatible_with": `select({ |
| 2673 | "//build/bazel/platforms/os_arch:darwin_arm64": ["@platforms//:incompatible"], |
| 2674 | "//build/bazel/platforms/os_arch:darwin_x86_64": ["@platforms//:incompatible"], |
| 2675 | "//build/bazel/platforms/os_arch:linux_glibc_x86": ["@platforms//:incompatible"], |
| 2676 | "//build/bazel/platforms/os_arch:windows_x86": ["@platforms//:incompatible"], |
| 2677 | "//build/bazel/platforms/os_arch:windows_x86_64": ["@platforms//:incompatible"], |
| 2678 | "//conditions:default": [], |
| 2679 | })`, |
| 2680 | }), |
| 2681 | }) |
| 2682 | } |
| 2683 | |
| 2684 | func TestCcLibraryDisabledArchAndTargetWithDefault(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2685 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2686 | ModuleTypeUnderTest: "cc_library", |
| 2687 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2688 | Blueprint: soongCcProtoPreamble + `cc_library { |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2689 | name: "foo", |
| 2690 | srcs: ["foo.cpp"], |
| 2691 | enabled: false, |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 2692 | host_supported: true, |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2693 | target: { |
| 2694 | darwin: { |
| 2695 | enabled: true, |
| 2696 | }, |
| 2697 | windows: { |
| 2698 | enabled: false, |
| 2699 | }, |
| 2700 | linux_glibc_x86: { |
| 2701 | enabled: false, |
| 2702 | }, |
| 2703 | }, |
| 2704 | include_build_directory: false, |
| 2705 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2706 | ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2707 | "srcs": `["foo.cpp"]`, |
| 2708 | "target_compatible_with": `select({ |
| 2709 | "//build/bazel/platforms/os_arch:darwin_arm64": [], |
| 2710 | "//build/bazel/platforms/os_arch:darwin_x86_64": [], |
| 2711 | "//conditions:default": ["@platforms//:incompatible"], |
| 2712 | })`, |
| 2713 | }), |
| 2714 | }) |
| 2715 | } |
| 2716 | |
| 2717 | func TestCcLibrarySharedDisabled(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2718 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2719 | ModuleTypeUnderTest: "cc_library", |
| 2720 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2721 | Blueprint: soongCcProtoPreamble + `cc_library { |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2722 | name: "foo", |
| 2723 | srcs: ["foo.cpp"], |
| 2724 | enabled: false, |
| 2725 | shared: { |
| 2726 | enabled: true, |
| 2727 | }, |
| 2728 | target: { |
| 2729 | android: { |
| 2730 | shared: { |
| 2731 | enabled: false, |
| 2732 | }, |
| 2733 | } |
| 2734 | }, |
| 2735 | include_build_directory: false, |
| 2736 | }`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2737 | ExpectedBazelTargets: []string{MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2738 | "srcs": `["foo.cpp"]`, |
| 2739 | "target_compatible_with": `["@platforms//:incompatible"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2740 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2741 | "srcs": `["foo.cpp"]`, |
| 2742 | "target_compatible_with": `select({ |
| 2743 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 2744 | "//conditions:default": [], |
| 2745 | })`, |
| 2746 | }), |
| 2747 | }, |
| 2748 | }) |
| 2749 | } |
| 2750 | |
| 2751 | func TestCcLibraryStaticDisabledForSomeArch(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2752 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2753 | ModuleTypeUnderTest: "cc_library", |
| 2754 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2755 | Blueprint: soongCcProtoPreamble + `cc_library { |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2756 | name: "foo", |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 2757 | host_supported: true, |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2758 | srcs: ["foo.cpp"], |
| 2759 | shared: { |
| 2760 | enabled: false |
| 2761 | }, |
| 2762 | target: { |
| 2763 | darwin: { |
| 2764 | enabled: true, |
| 2765 | }, |
| 2766 | windows: { |
| 2767 | enabled: false, |
| 2768 | }, |
| 2769 | linux_glibc_x86: { |
| 2770 | shared: { |
| 2771 | enabled: true, |
| 2772 | }, |
| 2773 | }, |
| 2774 | }, |
| 2775 | include_build_directory: false, |
| 2776 | }`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2777 | ExpectedBazelTargets: []string{MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2778 | "srcs": `["foo.cpp"]`, |
| 2779 | "target_compatible_with": `select({ |
| 2780 | "//build/bazel/platforms/os:windows": ["@platforms//:incompatible"], |
| 2781 | "//conditions:default": [], |
| 2782 | })`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 2783 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 2784 | "srcs": `["foo.cpp"]`, |
| 2785 | "target_compatible_with": `select({ |
| 2786 | "//build/bazel/platforms/os_arch:darwin_arm64": [], |
| 2787 | "//build/bazel/platforms/os_arch:darwin_x86_64": [], |
| 2788 | "//build/bazel/platforms/os_arch:linux_glibc_x86": [], |
| 2789 | "//conditions:default": ["@platforms//:incompatible"], |
| 2790 | })`, |
| 2791 | }), |
| 2792 | }}) |
| 2793 | } |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 2794 | |
| 2795 | func TestCcLibraryStubs(t *testing.T) { |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 2796 | expectedBazelTargets := makeCcLibraryTargets("a", AttrNameToString{ |
Yu Liu | 56ccb1a | 2022-11-12 10:47:07 -0800 | [diff] [blame] | 2797 | "stubs_symbol_file": `"a.map.txt"`, |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 2798 | }) |
| 2799 | expectedBazelTargets = append(expectedBazelTargets, makeCcStubSuiteTargets("a", AttrNameToString{ |
Sam Delmerico | 5f90649 | 2023-03-15 18:06:18 -0400 | [diff] [blame] | 2800 | "soname": `"a.so"`, |
| 2801 | "source_library_label": `"//foo/bar:a"`, |
| 2802 | "stubs_symbol_file": `"a.map.txt"`, |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 2803 | "stubs_versions": `[ |
| 2804 | "28", |
| 2805 | "29", |
| 2806 | "current", |
| 2807 | ]`, |
| 2808 | })) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 2809 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 2810 | Description: "cc_library stubs", |
| 2811 | ModuleTypeUnderTest: "cc_library", |
| 2812 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 2813 | Dir: "foo/bar", |
| 2814 | Filesystem: map[string]string{ |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 2815 | "foo/bar/Android.bp": ` |
| 2816 | cc_library { |
| 2817 | name: "a", |
| 2818 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 2819 | bazel_module: { bp2build_available: true }, |
| 2820 | include_build_directory: false, |
| 2821 | } |
| 2822 | `, |
| 2823 | }, |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 2824 | Blueprint: soongCcLibraryPreamble, |
| 2825 | ExpectedBazelTargets: expectedBazelTargets, |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 2826 | }, |
| 2827 | ) |
| 2828 | } |
Liz Kammer | f38a837 | 2022-02-04 15:39:00 -0500 | [diff] [blame] | 2829 | |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2830 | func TestCcApiContributionsWithHdrs(t *testing.T) { |
| 2831 | bp := ` |
| 2832 | cc_library { |
| 2833 | name: "libfoo", |
| 2834 | stubs: { symbol_file: "libfoo.map.txt", versions: ["28", "29", "current"] }, |
| 2835 | llndk: { symbol_file: "libfoo.map.txt", override_export_include_dirs: ["dir2"]}, |
| 2836 | export_include_dirs: ["dir1"], |
| 2837 | } |
| 2838 | ` |
| 2839 | expectedBazelTargets := []string{ |
| 2840 | MakeBazelTarget( |
| 2841 | "cc_api_library_headers", |
Spandan Das | 627fc3e | 2023-01-26 23:02:00 +0000 | [diff] [blame] | 2842 | "libfoo.module-libapi.headers", |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2843 | AttrNameToString{ |
| 2844 | "export_includes": `["dir1"]`, |
| 2845 | }), |
| 2846 | MakeBazelTarget( |
| 2847 | "cc_api_library_headers", |
| 2848 | "libfoo.vendorapi.headers", |
| 2849 | AttrNameToString{ |
| 2850 | "export_includes": `["dir2"]`, |
| 2851 | }), |
| 2852 | MakeBazelTarget( |
| 2853 | "cc_api_contribution", |
| 2854 | "libfoo.contribution", |
| 2855 | AttrNameToString{ |
| 2856 | "api": `"libfoo.map.txt"`, |
| 2857 | "library_name": `"libfoo"`, |
| 2858 | "api_surfaces": `[ |
Spandan Das | 627fc3e | 2023-01-26 23:02:00 +0000 | [diff] [blame] | 2859 | "module-libapi", |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2860 | "vendorapi", |
| 2861 | ]`, |
| 2862 | "hdrs": `[ |
Spandan Das | 627fc3e | 2023-01-26 23:02:00 +0000 | [diff] [blame] | 2863 | ":libfoo.module-libapi.headers", |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2864 | ":libfoo.vendorapi.headers", |
| 2865 | ]`, |
| 2866 | }), |
| 2867 | } |
| 2868 | RunApiBp2BuildTestCase(t, cc.RegisterLibraryBuildComponents, Bp2buildTestCase{ |
| 2869 | Blueprint: bp, |
Spandan Das | 627fc3e | 2023-01-26 23:02:00 +0000 | [diff] [blame] | 2870 | Description: "cc API contributions to module-libapi and vendorapi", |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2871 | ExpectedBazelTargets: expectedBazelTargets, |
| 2872 | }) |
| 2873 | } |
| 2874 | |
| 2875 | func TestCcApiSurfaceCombinations(t *testing.T) { |
| 2876 | testCases := []struct { |
| 2877 | bp string |
| 2878 | expectedApi string |
| 2879 | expectedApiSurfaces string |
| 2880 | description string |
| 2881 | }{ |
| 2882 | { |
| 2883 | bp: ` |
| 2884 | cc_library { |
| 2885 | name: "a", |
| 2886 | stubs: {symbol_file: "a.map.txt"}, |
| 2887 | }`, |
| 2888 | expectedApi: `"a.map.txt"`, |
Spandan Das | 627fc3e | 2023-01-26 23:02:00 +0000 | [diff] [blame] | 2889 | expectedApiSurfaces: `["module-libapi"]`, |
| 2890 | description: "Library that contributes to module-libapi", |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2891 | }, |
| 2892 | { |
| 2893 | bp: ` |
| 2894 | cc_library { |
| 2895 | name: "a", |
| 2896 | llndk: {symbol_file: "a.map.txt"}, |
| 2897 | }`, |
| 2898 | expectedApi: `"a.map.txt"`, |
| 2899 | expectedApiSurfaces: `["vendorapi"]`, |
| 2900 | description: "Library that contributes to vendorapi", |
| 2901 | }, |
| 2902 | { |
| 2903 | bp: ` |
| 2904 | cc_library { |
| 2905 | name: "a", |
| 2906 | llndk: {symbol_file: "a.map.txt"}, |
| 2907 | stubs: {symbol_file: "a.map.txt"}, |
| 2908 | }`, |
| 2909 | expectedApi: `"a.map.txt"`, |
| 2910 | expectedApiSurfaces: `[ |
Spandan Das | 627fc3e | 2023-01-26 23:02:00 +0000 | [diff] [blame] | 2911 | "module-libapi", |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2912 | "vendorapi", |
| 2913 | ]`, |
Spandan Das | 627fc3e | 2023-01-26 23:02:00 +0000 | [diff] [blame] | 2914 | description: "Library that contributes to module-libapi and vendorapi", |
Spandan Das | 4238c65 | 2022-09-09 01:38:47 +0000 | [diff] [blame] | 2915 | }, |
| 2916 | } |
| 2917 | for _, testCase := range testCases { |
| 2918 | expectedBazelTargets := []string{ |
| 2919 | MakeBazelTarget( |
| 2920 | "cc_api_contribution", |
| 2921 | "a.contribution", |
| 2922 | AttrNameToString{ |
| 2923 | "library_name": `"a"`, |
| 2924 | "hdrs": `[]`, |
| 2925 | "api": testCase.expectedApi, |
| 2926 | "api_surfaces": testCase.expectedApiSurfaces, |
| 2927 | }, |
| 2928 | ), |
| 2929 | } |
| 2930 | RunApiBp2BuildTestCase(t, cc.RegisterLibraryBuildComponents, Bp2buildTestCase{ |
| 2931 | Blueprint: testCase.bp, |
| 2932 | Description: testCase.description, |
| 2933 | ExpectedBazelTargets: expectedBazelTargets, |
| 2934 | }) |
| 2935 | } |
| 2936 | } |
| 2937 | |
| 2938 | // llndk struct property in Soong provides users with several options to configure the exported include dirs |
| 2939 | // Test the generated bazel targets for the different configurations |
| 2940 | func TestCcVendorApiHeaders(t *testing.T) { |
| 2941 | testCases := []struct { |
| 2942 | bp string |
| 2943 | expectedIncludes string |
| 2944 | expectedSystemIncludes string |
| 2945 | description string |
| 2946 | }{ |
| 2947 | { |
| 2948 | bp: ` |
| 2949 | cc_library { |
| 2950 | name: "a", |
| 2951 | export_include_dirs: ["include"], |
| 2952 | export_system_include_dirs: ["base_system_include"], |
| 2953 | llndk: { |
| 2954 | symbol_file: "a.map.txt", |
| 2955 | export_headers_as_system: true, |
| 2956 | }, |
| 2957 | } |
| 2958 | `, |
| 2959 | expectedIncludes: "", |
| 2960 | expectedSystemIncludes: `[ |
| 2961 | "base_system_include", |
| 2962 | "include", |
| 2963 | ]`, |
| 2964 | description: "Headers are exported as system to API surface", |
| 2965 | }, |
| 2966 | { |
| 2967 | bp: ` |
| 2968 | cc_library { |
| 2969 | name: "a", |
| 2970 | export_include_dirs: ["include"], |
| 2971 | export_system_include_dirs: ["base_system_include"], |
| 2972 | llndk: { |
| 2973 | symbol_file: "a.map.txt", |
| 2974 | override_export_include_dirs: ["llndk_include"], |
| 2975 | }, |
| 2976 | } |
| 2977 | `, |
| 2978 | expectedIncludes: `["llndk_include"]`, |
| 2979 | expectedSystemIncludes: `["base_system_include"]`, |
| 2980 | description: "Non-system Headers are ovverriden before export to API surface", |
| 2981 | }, |
| 2982 | { |
| 2983 | bp: ` |
| 2984 | cc_library { |
| 2985 | name: "a", |
| 2986 | export_include_dirs: ["include"], |
| 2987 | export_system_include_dirs: ["base_system_include"], |
| 2988 | llndk: { |
| 2989 | symbol_file: "a.map.txt", |
| 2990 | override_export_include_dirs: ["llndk_include"], |
| 2991 | export_headers_as_system: true, |
| 2992 | }, |
| 2993 | } |
| 2994 | `, |
| 2995 | expectedIncludes: "", // includes are set to nil |
| 2996 | expectedSystemIncludes: `[ |
| 2997 | "base_system_include", |
| 2998 | "llndk_include", |
| 2999 | ]`, |
| 3000 | description: "System Headers are extended before export to API surface", |
| 3001 | }, |
| 3002 | } |
| 3003 | for _, testCase := range testCases { |
| 3004 | attrs := AttrNameToString{} |
| 3005 | if testCase.expectedIncludes != "" { |
| 3006 | attrs["export_includes"] = testCase.expectedIncludes |
| 3007 | } |
| 3008 | if testCase.expectedSystemIncludes != "" { |
| 3009 | attrs["export_system_includes"] = testCase.expectedSystemIncludes |
| 3010 | } |
| 3011 | |
| 3012 | expectedBazelTargets := []string{ |
| 3013 | MakeBazelTarget("cc_api_library_headers", "a.vendorapi.headers", attrs), |
| 3014 | // Create a target for cc_api_contribution target |
| 3015 | MakeBazelTarget("cc_api_contribution", "a.contribution", AttrNameToString{ |
| 3016 | "api": `"a.map.txt"`, |
| 3017 | "api_surfaces": `["vendorapi"]`, |
| 3018 | "hdrs": `[":a.vendorapi.headers"]`, |
| 3019 | "library_name": `"a"`, |
| 3020 | }), |
| 3021 | } |
| 3022 | RunApiBp2BuildTestCase(t, cc.RegisterLibraryBuildComponents, Bp2buildTestCase{ |
| 3023 | Blueprint: testCase.bp, |
| 3024 | ExpectedBazelTargets: expectedBazelTargets, |
| 3025 | }) |
| 3026 | } |
| 3027 | } |
| 3028 | |
Trevor Radcliffe | 0ed6b7d | 2022-09-12 20:19:26 +0000 | [diff] [blame] | 3029 | func TestCcLibraryStubsAcrossConfigsDuplicatesRemoved(t *testing.T) { |
| 3030 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3031 | Description: "stub target generation of the same lib across configs should not result in duplicates", |
| 3032 | ModuleTypeUnderTest: "cc_library", |
| 3033 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3034 | Filesystem: map[string]string{ |
| 3035 | "bar.map.txt": "", |
| 3036 | }, |
| 3037 | Blueprint: ` |
| 3038 | cc_library { |
| 3039 | name: "barlib", |
| 3040 | stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] }, |
| 3041 | bazel_module: { bp2build_available: false }, |
| 3042 | } |
| 3043 | cc_library { |
| 3044 | name: "foolib", |
| 3045 | shared_libs: ["barlib"], |
| 3046 | target: { |
| 3047 | android: { |
| 3048 | shared_libs: ["barlib"], |
| 3049 | }, |
| 3050 | }, |
| 3051 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 3052 | apex_available: ["foo"], |
Trevor Radcliffe | 0ed6b7d | 2022-09-12 20:19:26 +0000 | [diff] [blame] | 3053 | }`, |
| 3054 | ExpectedBazelTargets: makeCcLibraryTargets("foolib", AttrNameToString{ |
| 3055 | "implementation_dynamic_deps": `select({ |
Spandan Das | 6d4d9da | 2023-04-18 06:20:40 +0000 | [diff] [blame] | 3056 | "//build/bazel/rules/apex:foo": ["@api_surfaces//module-libapi/current:barlib"], |
| 3057 | "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:barlib"], |
Trevor Radcliffe | 0ed6b7d | 2022-09-12 20:19:26 +0000 | [diff] [blame] | 3058 | "//conditions:default": [":barlib"], |
| 3059 | })`, |
| 3060 | "local_includes": `["."]`, |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 3061 | "tags": `["apex_available=foo"]`, |
Trevor Radcliffe | 0ed6b7d | 2022-09-12 20:19:26 +0000 | [diff] [blame] | 3062 | }), |
| 3063 | }) |
| 3064 | } |
| 3065 | |
Liz Kammer | ffc17e4 | 2022-11-23 09:42:05 -0500 | [diff] [blame] | 3066 | func TestCcLibraryExcludesLibsHost(t *testing.T) { |
| 3067 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3068 | ModuleTypeUnderTest: "cc_library", |
| 3069 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3070 | Filesystem: map[string]string{ |
| 3071 | "bar.map.txt": "", |
| 3072 | }, |
| 3073 | Blueprint: simpleModuleDoNotConvertBp2build("cc_library", "bazlib") + ` |
| 3074 | cc_library { |
| 3075 | name: "quxlib", |
| 3076 | stubs: { symbol_file: "bar.map.txt", versions: ["current"] }, |
| 3077 | bazel_module: { bp2build_available: false }, |
| 3078 | } |
| 3079 | cc_library { |
| 3080 | name: "barlib", |
| 3081 | stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] }, |
| 3082 | bazel_module: { bp2build_available: false }, |
| 3083 | } |
| 3084 | cc_library { |
| 3085 | name: "foolib", |
| 3086 | shared_libs: ["barlib", "quxlib"], |
| 3087 | target: { |
| 3088 | host: { |
| 3089 | shared_libs: ["bazlib"], |
| 3090 | exclude_shared_libs: ["barlib"], |
| 3091 | }, |
| 3092 | }, |
| 3093 | include_build_directory: false, |
| 3094 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 3095 | apex_available: ["foo"], |
Liz Kammer | ffc17e4 | 2022-11-23 09:42:05 -0500 | [diff] [blame] | 3096 | }`, |
| 3097 | ExpectedBazelTargets: makeCcLibraryTargets("foolib", AttrNameToString{ |
| 3098 | "implementation_dynamic_deps": `select({ |
| 3099 | "//build/bazel/platforms/os:darwin": [":bazlib"], |
Liz Kammer | ffc17e4 | 2022-11-23 09:42:05 -0500 | [diff] [blame] | 3100 | "//build/bazel/platforms/os:linux_bionic": [":bazlib"], |
Colin Cross | 133782e | 2022-12-20 15:29:31 -0800 | [diff] [blame] | 3101 | "//build/bazel/platforms/os:linux_glibc": [":bazlib"], |
Liz Kammer | ffc17e4 | 2022-11-23 09:42:05 -0500 | [diff] [blame] | 3102 | "//build/bazel/platforms/os:linux_musl": [":bazlib"], |
| 3103 | "//build/bazel/platforms/os:windows": [":bazlib"], |
| 3104 | "//conditions:default": [], |
| 3105 | }) + select({ |
| 3106 | "//build/bazel/platforms/os:darwin": [":quxlib"], |
Liz Kammer | ffc17e4 | 2022-11-23 09:42:05 -0500 | [diff] [blame] | 3107 | "//build/bazel/platforms/os:linux_bionic": [":quxlib"], |
Colin Cross | 133782e | 2022-12-20 15:29:31 -0800 | [diff] [blame] | 3108 | "//build/bazel/platforms/os:linux_glibc": [":quxlib"], |
Liz Kammer | ffc17e4 | 2022-11-23 09:42:05 -0500 | [diff] [blame] | 3109 | "//build/bazel/platforms/os:linux_musl": [":quxlib"], |
| 3110 | "//build/bazel/platforms/os:windows": [":quxlib"], |
Spandan Das | 6d4d9da | 2023-04-18 06:20:40 +0000 | [diff] [blame] | 3111 | "//build/bazel/rules/apex:foo": [ |
| 3112 | "@api_surfaces//module-libapi/current:barlib", |
| 3113 | "@api_surfaces//module-libapi/current:quxlib", |
| 3114 | ], |
| 3115 | "//build/bazel/rules/apex:system": [ |
Spandan Das | 2518c02 | 2023-03-17 03:02:32 +0000 | [diff] [blame] | 3116 | "@api_surfaces//module-libapi/current:barlib", |
| 3117 | "@api_surfaces//module-libapi/current:quxlib", |
Liz Kammer | ffc17e4 | 2022-11-23 09:42:05 -0500 | [diff] [blame] | 3118 | ], |
| 3119 | "//conditions:default": [ |
| 3120 | ":barlib", |
| 3121 | ":quxlib", |
| 3122 | ], |
| 3123 | })`, |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 3124 | "tags": `["apex_available=foo"]`, |
Liz Kammer | ffc17e4 | 2022-11-23 09:42:05 -0500 | [diff] [blame] | 3125 | }), |
| 3126 | }) |
| 3127 | } |
| 3128 | |
Liz Kammer | f38a837 | 2022-02-04 15:39:00 -0500 | [diff] [blame] | 3129 | func TestCcLibraryEscapeLdflags(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3130 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3131 | ModuleTypeUnderTest: "cc_library", |
| 3132 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3133 | Blueprint: soongCcProtoPreamble + `cc_library { |
Liz Kammer | f38a837 | 2022-02-04 15:39:00 -0500 | [diff] [blame] | 3134 | name: "foo", |
| 3135 | ldflags: ["-Wl,--rpath,${ORIGIN}"], |
| 3136 | include_build_directory: false, |
| 3137 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3138 | ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{ |
Liz Kammer | f38a837 | 2022-02-04 15:39:00 -0500 | [diff] [blame] | 3139 | "linkopts": `["-Wl,--rpath,$${ORIGIN}"]`, |
| 3140 | }), |
| 3141 | }) |
| 3142 | } |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3143 | |
| 3144 | func TestCcLibraryConvertLex(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3145 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3146 | ModuleTypeUnderTest: "cc_library", |
| 3147 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3148 | Filesystem: map[string]string{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3149 | "foo.c": "", |
| 3150 | "bar.cc": "", |
| 3151 | "foo1.l": "", |
| 3152 | "bar1.ll": "", |
| 3153 | "foo2.l": "", |
| 3154 | "bar2.ll": "", |
| 3155 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3156 | Blueprint: `cc_library { |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3157 | name: "foo_lib", |
| 3158 | srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"], |
| 3159 | lex: { flags: ["--foo_flags"] }, |
| 3160 | include_build_directory: false, |
| 3161 | bazel_module: { bp2build_available: true }, |
| 3162 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3163 | ExpectedBazelTargets: append([]string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3164 | MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3165 | "srcs": `[ |
| 3166 | "foo1.l", |
| 3167 | "foo2.l", |
| 3168 | ]`, |
| 3169 | "lexopts": `["--foo_flags"]`, |
| 3170 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3171 | MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3172 | "srcs": `[ |
| 3173 | "bar1.ll", |
| 3174 | "bar2.ll", |
| 3175 | ]`, |
| 3176 | "lexopts": `["--foo_flags"]`, |
| 3177 | }), |
| 3178 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 3179 | makeCcLibraryTargets("foo_lib", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 3180 | "srcs": `[ |
| 3181 | "bar.cc", |
| 3182 | ":foo_lib_genlex_ll", |
| 3183 | ]`, |
| 3184 | "srcs_c": `[ |
| 3185 | "foo.c", |
| 3186 | ":foo_lib_genlex_l", |
| 3187 | ]`, |
| 3188 | })...), |
| 3189 | }) |
| 3190 | } |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 3191 | |
| 3192 | func TestCCLibraryRuntimeDeps(t *testing.T) { |
| 3193 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 3194 | Blueprint: `cc_library_shared { |
| 3195 | name: "bar", |
| 3196 | } |
| 3197 | |
| 3198 | cc_library { |
| 3199 | name: "foo", |
| 3200 | runtime_libs: ["foo"], |
| 3201 | }`, |
| 3202 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3203 | MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{ |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 3204 | "local_includes": `["."]`, |
| 3205 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3206 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 3207 | "runtime_deps": `[":foo"]`, |
| 3208 | "local_includes": `["."]`, |
| 3209 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3210 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 3211 | "runtime_deps": `[":foo"]`, |
| 3212 | "local_includes": `["."]`, |
| 3213 | }), |
| 3214 | }, |
| 3215 | }) |
| 3216 | } |
Cole Faust | 5fa4e96 | 2022-08-22 14:31:04 -0700 | [diff] [blame] | 3217 | |
| 3218 | func TestCcLibraryWithInstructionSet(t *testing.T) { |
| 3219 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3220 | ModuleTypeUnderTest: "cc_library", |
| 3221 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3222 | Blueprint: `cc_library { |
| 3223 | name: "foo", |
| 3224 | arch: { |
| 3225 | arm: { |
| 3226 | instruction_set: "arm", |
| 3227 | } |
| 3228 | } |
| 3229 | } |
| 3230 | `, |
| 3231 | ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{ |
| 3232 | "features": `select({ |
Trevor Radcliffe | 5f0c2ac | 2023-05-15 18:00:59 +0000 | [diff] [blame] | 3233 | "//build/bazel/platforms/arch:arm": ["arm_isa_arm"], |
Cole Faust | 5fa4e96 | 2022-08-22 14:31:04 -0700 | [diff] [blame] | 3234 | "//conditions:default": [], |
| 3235 | })`, |
| 3236 | "local_includes": `["."]`, |
| 3237 | }), |
| 3238 | }) |
| 3239 | } |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3240 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 3241 | func TestCcLibraryEmptySuffix(t *testing.T) { |
| 3242 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3243 | Description: "cc_library with empty suffix", |
| 3244 | ModuleTypeUnderTest: "cc_library", |
| 3245 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3246 | Filesystem: map[string]string{ |
| 3247 | "foo.c": "", |
| 3248 | }, |
| 3249 | Blueprint: `cc_library { |
| 3250 | name: "foo", |
| 3251 | suffix: "", |
| 3252 | srcs: ["foo.c"], |
| 3253 | include_build_directory: false, |
| 3254 | }`, |
| 3255 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3256 | 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] | 3257 | "srcs_c": `["foo.c"]`, |
| 3258 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3259 | 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] | 3260 | "srcs_c": `["foo.c"]`, |
| 3261 | "suffix": `""`, |
| 3262 | }), |
| 3263 | }, |
| 3264 | }) |
| 3265 | } |
| 3266 | |
| 3267 | func TestCcLibrarySuffix(t *testing.T) { |
| 3268 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3269 | Description: "cc_library with suffix", |
| 3270 | ModuleTypeUnderTest: "cc_library", |
| 3271 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3272 | Filesystem: map[string]string{ |
| 3273 | "foo.c": "", |
| 3274 | }, |
| 3275 | Blueprint: `cc_library { |
| 3276 | name: "foo", |
| 3277 | suffix: "-suf", |
| 3278 | srcs: ["foo.c"], |
| 3279 | include_build_directory: false, |
| 3280 | }`, |
| 3281 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3282 | 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] | 3283 | "srcs_c": `["foo.c"]`, |
| 3284 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3285 | 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] | 3286 | "srcs_c": `["foo.c"]`, |
| 3287 | "suffix": `"-suf"`, |
| 3288 | }), |
| 3289 | }, |
| 3290 | }) |
| 3291 | } |
| 3292 | |
| 3293 | func TestCcLibraryArchVariantSuffix(t *testing.T) { |
| 3294 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3295 | Description: "cc_library with arch-variant suffix", |
| 3296 | ModuleTypeUnderTest: "cc_library", |
| 3297 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3298 | Filesystem: map[string]string{ |
| 3299 | "foo.c": "", |
| 3300 | }, |
| 3301 | Blueprint: `cc_library { |
| 3302 | name: "foo", |
| 3303 | arch: { |
| 3304 | arm64: { suffix: "-64" }, |
| 3305 | arm: { suffix: "-32" }, |
| 3306 | }, |
| 3307 | srcs: ["foo.c"], |
| 3308 | include_build_directory: false, |
| 3309 | }`, |
| 3310 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3311 | 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] | 3312 | "srcs_c": `["foo.c"]`, |
| 3313 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3314 | 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] | 3315 | "srcs_c": `["foo.c"]`, |
| 3316 | "suffix": `select({ |
| 3317 | "//build/bazel/platforms/arch:arm": "-32", |
| 3318 | "//build/bazel/platforms/arch:arm64": "-64", |
| 3319 | "//conditions:default": None, |
| 3320 | })`, |
| 3321 | }), |
| 3322 | }, |
| 3323 | }) |
| 3324 | } |
| 3325 | |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3326 | func TestCcLibraryWithAidlLibrary(t *testing.T) { |
| 3327 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3328 | Description: "cc_library with aidl_library", |
| 3329 | ModuleTypeUnderTest: "cc_library", |
| 3330 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3331 | Blueprint: ` |
| 3332 | aidl_library { |
| 3333 | name: "A_aidl", |
| 3334 | srcs: ["aidl/A.aidl"], |
| 3335 | hdrs: ["aidl/Header.aidl"], |
| 3336 | strip_import_prefix: "aidl", |
| 3337 | } |
| 3338 | cc_library { |
| 3339 | name: "foo", |
| 3340 | aidl: { |
| 3341 | libs: ["A_aidl"], |
Vinh Tran | e684294 | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3342 | }, |
| 3343 | export_include_dirs: ["include"], |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3344 | }`, |
| 3345 | ExpectedBazelTargets: []string{ |
| 3346 | MakeBazelTargetNoRestrictions("aidl_library", "A_aidl", AttrNameToString{ |
| 3347 | "srcs": `["aidl/A.aidl"]`, |
| 3348 | "hdrs": `["aidl/Header.aidl"]`, |
| 3349 | "strip_import_prefix": `"aidl"`, |
| 3350 | "tags": `["apex_available=//apex_available:anyapex"]`, |
| 3351 | }), |
| 3352 | MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ |
Vinh Tran | e684294 | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3353 | "deps": `[":A_aidl"]`, |
| 3354 | "local_includes": `["."]`, |
| 3355 | "export_includes": `["include"]`, |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3356 | }), |
| 3357 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 3358 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3359 | "local_includes": `["."]`, |
Vinh Tran | e684294 | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3360 | "export_includes": `["include"]`, |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3361 | }), |
| 3362 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 3363 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3364 | "local_includes": `["."]`, |
Vinh Tran | e684294 | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3365 | "export_includes": `["include"]`, |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3366 | }), |
| 3367 | }, |
| 3368 | }) |
| 3369 | } |
| 3370 | |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3371 | func TestCcLibraryWithAidlSrcs(t *testing.T) { |
| 3372 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3373 | Description: "cc_library with aidl srcs", |
| 3374 | ModuleTypeUnderTest: "cc_library", |
| 3375 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3376 | Blueprint: ` |
| 3377 | filegroup { |
| 3378 | name: "A_aidl", |
| 3379 | srcs: ["aidl/A.aidl"], |
| 3380 | path: "aidl", |
| 3381 | } |
| 3382 | cc_library { |
| 3383 | name: "foo", |
| 3384 | srcs: [ |
| 3385 | ":A_aidl", |
| 3386 | "B.aidl", |
| 3387 | ], |
| 3388 | }`, |
| 3389 | ExpectedBazelTargets: []string{ |
| 3390 | MakeBazelTargetNoRestrictions("aidl_library", "A_aidl", AttrNameToString{ |
| 3391 | "srcs": `["aidl/A.aidl"]`, |
| 3392 | "strip_import_prefix": `"aidl"`, |
Liz Kammer | 2b3f56e | 2023-03-23 11:51:49 -0400 | [diff] [blame] | 3393 | "tags": `["apex_available=//apex_available:anyapex"]`, |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3394 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3395 | MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{ |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3396 | "srcs": `["B.aidl"]`, |
| 3397 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3398 | MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ |
Vinh Tran | e684294 | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3399 | "local_includes": `["."]`, |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3400 | "deps": `[ |
| 3401 | ":A_aidl", |
| 3402 | ":foo_aidl_library", |
| 3403 | ]`, |
| 3404 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3405 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3406 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3407 | "local_includes": `["."]`, |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3408 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3409 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 3410 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3411 | "local_includes": `["."]`, |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3412 | }), |
| 3413 | }, |
| 3414 | }) |
| 3415 | } |
| 3416 | |
| 3417 | func TestCcLibraryWithNonAdjacentAidlFilegroup(t *testing.T) { |
| 3418 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3419 | Description: "cc_library with non aidl filegroup", |
| 3420 | ModuleTypeUnderTest: "cc_library", |
| 3421 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3422 | Filesystem: map[string]string{ |
| 3423 | "path/to/A/Android.bp": ` |
| 3424 | filegroup { |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3425 | name: "A_aidl", |
| 3426 | srcs: ["aidl/A.aidl"], |
| 3427 | path: "aidl", |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3428 | }`, |
| 3429 | }, |
| 3430 | Blueprint: ` |
| 3431 | cc_library { |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3432 | name: "foo", |
| 3433 | srcs: [ |
| 3434 | ":A_aidl", |
| 3435 | ], |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3436 | }`, |
| 3437 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3438 | MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ |
Vinh Tran | e684294 | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3439 | "local_includes": `["."]`, |
| 3440 | "deps": `["//path/to/A:A_aidl"]`, |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3441 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 3442 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3443 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3444 | "local_includes": `["."]`, |
| 3445 | }), |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3446 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 84b0ecb | 2022-09-14 10:49:13 -0400 | [diff] [blame] | 3447 | "local_includes": `["."]`, |
| 3448 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
Vinh Tran | fde57eb | 2022-08-29 17:46:58 -0400 | [diff] [blame] | 3449 | }), |
| 3450 | }, |
| 3451 | }) |
| 3452 | } |
| 3453 | |
| 3454 | func TestCcLibraryWithExportAidlHeaders(t *testing.T) { |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3455 | t.Parallel() |
| 3456 | |
| 3457 | expectedBazelTargets := []string{ |
| 3458 | MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ |
Vinh Tran | e684294 | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3459 | "local_includes": `["."]`, |
| 3460 | "deps": `[":foo_aidl_library"]`, |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3461 | }), |
| 3462 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 3463 | "whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3464 | "local_includes": `["."]`, |
| 3465 | }), |
| 3466 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 3467 | "whole_archive_deps": `[":foo_cc_aidl_library"]`, |
| 3468 | "local_includes": `["."]`, |
| 3469 | }), |
| 3470 | } |
| 3471 | testCases := []struct { |
| 3472 | description string |
| 3473 | bp string |
| 3474 | expectedBazelTargets []string |
| 3475 | }{ |
| 3476 | { |
| 3477 | description: "cc_library with aidl srcs and aidl.export_aidl_headers set", |
| 3478 | bp: ` |
| 3479 | cc_library { |
| 3480 | name: "foo", |
| 3481 | srcs: [ |
| 3482 | "Foo.aidl", |
| 3483 | ], |
| 3484 | aidl: { |
| 3485 | export_aidl_headers: true, |
| 3486 | } |
| 3487 | }`, |
| 3488 | expectedBazelTargets: append( |
| 3489 | expectedBazelTargets, |
| 3490 | MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{ |
| 3491 | "srcs": `["Foo.aidl"]`, |
| 3492 | })), |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3493 | }, |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3494 | { |
| 3495 | description: "cc_library with aidl.libs and aidl.export_aidl_headers set", |
| 3496 | bp: ` |
| 3497 | aidl_library { |
| 3498 | name: "foo_aidl_library", |
| 3499 | srcs: ["Foo.aidl"], |
| 3500 | } |
| 3501 | cc_library { |
| 3502 | name: "foo", |
| 3503 | aidl: { |
| 3504 | libs: ["foo_aidl_library"], |
| 3505 | export_aidl_headers: true, |
| 3506 | } |
| 3507 | }`, |
| 3508 | expectedBazelTargets: append( |
| 3509 | expectedBazelTargets, |
| 3510 | MakeBazelTargetNoRestrictions("aidl_library", "foo_aidl_library", AttrNameToString{ |
| 3511 | "srcs": `["Foo.aidl"]`, |
| 3512 | "tags": `["apex_available=//apex_available:anyapex"]`, |
| 3513 | }), |
| 3514 | ), |
| 3515 | }, |
| 3516 | } |
| 3517 | |
| 3518 | for _, testCase := range testCases { |
| 3519 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3520 | Description: "cc_library with export aidl headers", |
| 3521 | ModuleTypeUnderTest: "cc_library", |
| 3522 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3523 | Blueprint: testCase.bp, |
| 3524 | ExpectedBazelTargets: testCase.expectedBazelTargets, |
| 3525 | }) |
| 3526 | } |
Vinh Tran | 9f6796a | 2022-08-16 13:10:31 -0400 | [diff] [blame] | 3527 | } |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3528 | |
| 3529 | func TestCcLibraryWithTargetApex(t *testing.T) { |
| 3530 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3531 | Description: "cc_library with target.apex", |
| 3532 | ModuleTypeUnderTest: "cc_library", |
| 3533 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3534 | Blueprint: ` |
| 3535 | cc_library { |
| 3536 | name: "foo", |
| 3537 | shared_libs: ["bar", "baz"], |
| 3538 | static_libs: ["baz", "buh"], |
| 3539 | target: { |
| 3540 | apex: { |
| 3541 | exclude_shared_libs: ["bar"], |
| 3542 | exclude_static_libs: ["buh"], |
| 3543 | } |
| 3544 | } |
| 3545 | }`, |
| 3546 | ExpectedBazelTargets: []string{ |
| 3547 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 3548 | "implementation_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({ |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 3549 | "//build/bazel/rules/apex:in_apex": [], |
| 3550 | "//conditions:default": [":buh__BP2BUILD__MISSING__DEP"], |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3551 | })`, |
| 3552 | "implementation_dynamic_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({ |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 3553 | "//build/bazel/rules/apex:in_apex": [], |
| 3554 | "//conditions:default": [":bar__BP2BUILD__MISSING__DEP"], |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3555 | })`, |
| 3556 | "local_includes": `["."]`, |
| 3557 | }), |
| 3558 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 3559 | "implementation_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({ |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 3560 | "//build/bazel/rules/apex:in_apex": [], |
| 3561 | "//conditions:default": [":buh__BP2BUILD__MISSING__DEP"], |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3562 | })`, |
| 3563 | "implementation_dynamic_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({ |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 3564 | "//build/bazel/rules/apex:in_apex": [], |
| 3565 | "//conditions:default": [":bar__BP2BUILD__MISSING__DEP"], |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3566 | })`, |
| 3567 | "local_includes": `["."]`, |
| 3568 | }), |
| 3569 | }, |
| 3570 | }) |
| 3571 | } |
| 3572 | |
| 3573 | func TestCcLibraryWithTargetApexAndExportLibHeaders(t *testing.T) { |
| 3574 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3575 | Description: "cc_library with target.apex and export_shared|static_lib_headers", |
| 3576 | ModuleTypeUnderTest: "cc_library", |
| 3577 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3578 | Blueprint: ` |
| 3579 | cc_library_static { |
| 3580 | name: "foo", |
| 3581 | shared_libs: ["bar", "baz"], |
| 3582 | static_libs: ["abc"], |
| 3583 | export_shared_lib_headers: ["baz"], |
| 3584 | export_static_lib_headers: ["abc"], |
| 3585 | target: { |
| 3586 | apex: { |
| 3587 | exclude_shared_libs: ["baz", "bar"], |
| 3588 | exclude_static_libs: ["abc"], |
| 3589 | } |
| 3590 | } |
| 3591 | }`, |
| 3592 | ExpectedBazelTargets: []string{ |
| 3593 | MakeBazelTarget("cc_library_static", "foo", AttrNameToString{ |
| 3594 | "implementation_dynamic_deps": `select({ |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 3595 | "//build/bazel/rules/apex:in_apex": [], |
| 3596 | "//conditions:default": [":bar__BP2BUILD__MISSING__DEP"], |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3597 | })`, |
| 3598 | "dynamic_deps": `select({ |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 3599 | "//build/bazel/rules/apex:in_apex": [], |
| 3600 | "//conditions:default": [":baz__BP2BUILD__MISSING__DEP"], |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3601 | })`, |
| 3602 | "deps": `select({ |
Liz Kammer | 748d707 | 2023-01-25 12:07:43 -0500 | [diff] [blame] | 3603 | "//build/bazel/rules/apex:in_apex": [], |
| 3604 | "//conditions:default": [":abc__BP2BUILD__MISSING__DEP"], |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 3605 | })`, |
| 3606 | "local_includes": `["."]`, |
| 3607 | }), |
| 3608 | }, |
| 3609 | }) |
| 3610 | } |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 3611 | |
| 3612 | func TestCcLibraryWithSyspropSrcs(t *testing.T) { |
| 3613 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3614 | Description: "cc_library with sysprop sources", |
| 3615 | ModuleTypeUnderTest: "cc_library", |
| 3616 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3617 | Blueprint: ` |
| 3618 | cc_library { |
| 3619 | name: "foo", |
| 3620 | srcs: [ |
| 3621 | "bar.sysprop", |
| 3622 | "baz.sysprop", |
| 3623 | "blah.cpp", |
| 3624 | ], |
| 3625 | min_sdk_version: "5", |
| 3626 | }`, |
| 3627 | ExpectedBazelTargets: []string{ |
| 3628 | MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{ |
| 3629 | "srcs": `[ |
| 3630 | "bar.sysprop", |
| 3631 | "baz.sysprop", |
| 3632 | ]`, |
| 3633 | }), |
| 3634 | MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{ |
| 3635 | "dep": `":foo_sysprop_library"`, |
| 3636 | "min_sdk_version": `"5"`, |
| 3637 | }), |
| 3638 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 3639 | "srcs": `["blah.cpp"]`, |
| 3640 | "local_includes": `["."]`, |
| 3641 | "min_sdk_version": `"5"`, |
| 3642 | "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`, |
| 3643 | }), |
| 3644 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 3645 | "srcs": `["blah.cpp"]`, |
| 3646 | "local_includes": `["."]`, |
| 3647 | "min_sdk_version": `"5"`, |
| 3648 | "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`, |
| 3649 | }), |
| 3650 | }, |
| 3651 | }) |
| 3652 | } |
| 3653 | |
| 3654 | func TestCcLibraryWithSyspropSrcsSomeConfigs(t *testing.T) { |
| 3655 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3656 | Description: "cc_library with sysprop sources in some configs but not others", |
| 3657 | ModuleTypeUnderTest: "cc_library", |
| 3658 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3659 | Blueprint: ` |
| 3660 | cc_library { |
| 3661 | name: "foo", |
| 3662 | host_supported: true, |
| 3663 | srcs: [ |
| 3664 | "blah.cpp", |
| 3665 | ], |
| 3666 | target: { |
| 3667 | android: { |
| 3668 | srcs: ["bar.sysprop"], |
| 3669 | }, |
| 3670 | }, |
| 3671 | min_sdk_version: "5", |
| 3672 | }`, |
| 3673 | ExpectedBazelTargets: []string{ |
| 3674 | MakeBazelTargetNoRestrictions("sysprop_library", "foo_sysprop_library", AttrNameToString{ |
| 3675 | "srcs": `select({ |
| 3676 | "//build/bazel/platforms/os:android": ["bar.sysprop"], |
| 3677 | "//conditions:default": [], |
| 3678 | })`, |
| 3679 | }), |
| 3680 | MakeBazelTargetNoRestrictions("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{ |
| 3681 | "dep": `":foo_sysprop_library"`, |
| 3682 | "min_sdk_version": `"5"`, |
| 3683 | }), |
| 3684 | MakeBazelTargetNoRestrictions("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 3685 | "srcs": `["blah.cpp"]`, |
| 3686 | "local_includes": `["."]`, |
| 3687 | "min_sdk_version": `"5"`, |
| 3688 | "whole_archive_deps": `select({ |
| 3689 | "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"], |
| 3690 | "//conditions:default": [], |
| 3691 | })`, |
| 3692 | }), |
| 3693 | MakeBazelTargetNoRestrictions("cc_library_shared", "foo", AttrNameToString{ |
| 3694 | "srcs": `["blah.cpp"]`, |
| 3695 | "local_includes": `["."]`, |
| 3696 | "min_sdk_version": `"5"`, |
| 3697 | "whole_archive_deps": `select({ |
| 3698 | "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"], |
| 3699 | "//conditions:default": [], |
| 3700 | })`, |
| 3701 | }), |
| 3702 | }, |
| 3703 | }) |
| 3704 | } |
Vinh Tran | 395a1e9 | 2022-09-16 18:27:29 -0400 | [diff] [blame] | 3705 | |
Sam Delmerico | 512437b | 2023-03-17 11:34:15 -0400 | [diff] [blame] | 3706 | func TestCcLibraryWithAidlAndLibs(t *testing.T) { |
Vinh Tran | 395a1e9 | 2022-09-16 18:27:29 -0400 | [diff] [blame] | 3707 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
Sam Delmerico | 512437b | 2023-03-17 11:34:15 -0400 | [diff] [blame] | 3708 | Description: "cc_aidl_library depends on libs from parent cc_library_static", |
Vinh Tran | 395a1e9 | 2022-09-16 18:27:29 -0400 | [diff] [blame] | 3709 | ModuleTypeUnderTest: "cc_library", |
| 3710 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3711 | Blueprint: ` |
| 3712 | cc_library_static { |
Sam Delmerico | 512437b | 2023-03-17 11:34:15 -0400 | [diff] [blame] | 3713 | name: "foo", |
| 3714 | srcs: [ |
| 3715 | "Foo.aidl", |
| 3716 | ], |
| 3717 | static_libs: [ |
| 3718 | "bar-static", |
| 3719 | "baz-static", |
| 3720 | ], |
Vinh Tran | 395a1e9 | 2022-09-16 18:27:29 -0400 | [diff] [blame] | 3721 | shared_libs: [ |
Sam Delmerico | 512437b | 2023-03-17 11:34:15 -0400 | [diff] [blame] | 3722 | "bar-shared", |
| 3723 | "baz-shared", |
| 3724 | ], |
| 3725 | export_static_lib_headers: [ |
| 3726 | "baz-static", |
Vinh Tran | 395a1e9 | 2022-09-16 18:27:29 -0400 | [diff] [blame] | 3727 | ], |
| 3728 | export_shared_lib_headers: [ |
Sam Delmerico | 512437b | 2023-03-17 11:34:15 -0400 | [diff] [blame] | 3729 | "baz-shared", |
Vinh Tran | 395a1e9 | 2022-09-16 18:27:29 -0400 | [diff] [blame] | 3730 | ], |
| 3731 | }` + |
Sam Delmerico | 512437b | 2023-03-17 11:34:15 -0400 | [diff] [blame] | 3732 | simpleModuleDoNotConvertBp2build("cc_library_static", "bar-static") + |
| 3733 | simpleModuleDoNotConvertBp2build("cc_library_static", "baz-static") + |
| 3734 | simpleModuleDoNotConvertBp2build("cc_library", "bar-shared") + |
| 3735 | simpleModuleDoNotConvertBp2build("cc_library", "baz-shared"), |
Vinh Tran | 395a1e9 | 2022-09-16 18:27:29 -0400 | [diff] [blame] | 3736 | ExpectedBazelTargets: []string{ |
| 3737 | MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{ |
| 3738 | "srcs": `["Foo.aidl"]`, |
| 3739 | }), |
| 3740 | MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ |
Vinh Tran | e684294 | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3741 | "local_includes": `["."]`, |
| 3742 | "deps": `[":foo_aidl_library"]`, |
Sam Delmerico | 512437b | 2023-03-17 11:34:15 -0400 | [diff] [blame] | 3743 | "implementation_deps": `[ |
| 3744 | ":baz-static", |
| 3745 | ":bar-static", |
| 3746 | ]`, |
Vinh Tran | 395a1e9 | 2022-09-16 18:27:29 -0400 | [diff] [blame] | 3747 | "implementation_dynamic_deps": `[ |
Sam Delmerico | 512437b | 2023-03-17 11:34:15 -0400 | [diff] [blame] | 3748 | ":baz-shared", |
| 3749 | ":bar-shared", |
Vinh Tran | 395a1e9 | 2022-09-16 18:27:29 -0400 | [diff] [blame] | 3750 | ]`, |
| 3751 | }), |
| 3752 | MakeBazelTarget("cc_library_static", "foo", AttrNameToString{ |
| 3753 | "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, |
Sam Delmerico | 512437b | 2023-03-17 11:34:15 -0400 | [diff] [blame] | 3754 | "deps": `[":baz-static"]`, |
| 3755 | "implementation_deps": `[":bar-static"]`, |
| 3756 | "dynamic_deps": `[":baz-shared"]`, |
| 3757 | "implementation_dynamic_deps": `[":bar-shared"]`, |
Vinh Tran | 395a1e9 | 2022-09-16 18:27:29 -0400 | [diff] [blame] | 3758 | "local_includes": `["."]`, |
| 3759 | }), |
| 3760 | }, |
| 3761 | }) |
| 3762 | } |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 3763 | |
| 3764 | func TestCcLibraryWithTidy(t *testing.T) { |
| 3765 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3766 | Description: "cc_library uses tidy properties", |
| 3767 | ModuleTypeUnderTest: "cc_library", |
| 3768 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3769 | Blueprint: ` |
| 3770 | cc_library_static { |
Sam Delmerico | 63f0c93 | 2023-03-14 14:05:28 -0400 | [diff] [blame] | 3771 | name: "foo", |
| 3772 | srcs: ["foo.cpp"], |
| 3773 | } |
| 3774 | cc_library_static { |
| 3775 | name: "foo-no-tidy", |
| 3776 | srcs: ["foo.cpp"], |
| 3777 | tidy: false, |
| 3778 | } |
| 3779 | cc_library_static { |
| 3780 | name: "foo-tidy", |
| 3781 | srcs: ["foo.cpp"], |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 3782 | tidy: true, |
| 3783 | tidy_checks: ["check1", "check2"], |
| 3784 | tidy_checks_as_errors: ["check1error", "check2error"], |
| 3785 | tidy_disabled_srcs: ["bar.cpp"], |
Sam Delmerico | 4c902d6 | 2022-11-02 14:17:15 -0400 | [diff] [blame] | 3786 | tidy_timeout_srcs: ["baz.cpp"], |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 3787 | }`, |
| 3788 | ExpectedBazelTargets: []string{ |
| 3789 | MakeBazelTarget("cc_library_static", "foo", AttrNameToString{ |
| 3790 | "local_includes": `["."]`, |
| 3791 | "srcs": `["foo.cpp"]`, |
Sam Delmerico | 63f0c93 | 2023-03-14 14:05:28 -0400 | [diff] [blame] | 3792 | }), |
| 3793 | MakeBazelTarget("cc_library_static", "foo-no-tidy", AttrNameToString{ |
| 3794 | "local_includes": `["."]`, |
| 3795 | "srcs": `["foo.cpp"]`, |
| 3796 | "tidy": `"never"`, |
| 3797 | }), |
| 3798 | MakeBazelTarget("cc_library_static", "foo-tidy", AttrNameToString{ |
| 3799 | "local_includes": `["."]`, |
| 3800 | "srcs": `["foo.cpp"]`, |
| 3801 | "tidy": `"local"`, |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 3802 | "tidy_checks": `[ |
| 3803 | "check1", |
| 3804 | "check2", |
| 3805 | ]`, |
| 3806 | "tidy_checks_as_errors": `[ |
| 3807 | "check1error", |
| 3808 | "check2error", |
| 3809 | ]`, |
| 3810 | "tidy_disabled_srcs": `["bar.cpp"]`, |
Sam Delmerico | 4c902d6 | 2022-11-02 14:17:15 -0400 | [diff] [blame] | 3811 | "tidy_timeout_srcs": `["baz.cpp"]`, |
Sam Delmerico | c9b8fbd | 2022-10-25 15:47:17 -0400 | [diff] [blame] | 3812 | }), |
| 3813 | }, |
| 3814 | }) |
| 3815 | } |
Yu Liu | 56ccb1a | 2022-11-12 10:47:07 -0800 | [diff] [blame] | 3816 | |
Vinh Tran | 99270ea | 2022-11-28 11:15:23 -0500 | [diff] [blame] | 3817 | func TestCcLibraryWithAfdoEnabled(t *testing.T) { |
| 3818 | bp := ` |
| 3819 | cc_library { |
| 3820 | name: "foo", |
| 3821 | afdo: true, |
| 3822 | include_build_directory: false, |
| 3823 | }` |
| 3824 | |
| 3825 | // TODO(b/260714900): Add test case for arch-specific afdo profile |
| 3826 | testCases := []struct { |
| 3827 | description string |
| 3828 | filesystem map[string]string |
| 3829 | expectedBazelTargets []string |
| 3830 | }{ |
| 3831 | { |
| 3832 | description: "cc_library with afdo enabled and existing profile", |
Vinh Tran | bc9c8b4 | 2022-12-09 12:03:52 -0500 | [diff] [blame] | 3833 | filesystem: map[string]string{ |
| 3834 | "vendor/google_data/pgo_profile/sampling/BUILD": "", |
| 3835 | "vendor/google_data/pgo_profile/sampling/foo.afdo": "", |
| 3836 | }, |
Vinh Tran | 99270ea | 2022-11-28 11:15:23 -0500 | [diff] [blame] | 3837 | expectedBazelTargets: []string{ |
| 3838 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), |
| 3839 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 3840 | "fdo_profile": `"//vendor/google_data/pgo_profile/sampling:foo"`, |
| 3841 | }), |
| 3842 | }, |
| 3843 | }, |
| 3844 | { |
| 3845 | description: "cc_library with afdo enabled and existing profile in AOSP", |
Vinh Tran | bc9c8b4 | 2022-12-09 12:03:52 -0500 | [diff] [blame] | 3846 | filesystem: map[string]string{ |
| 3847 | "toolchain/pgo-profiles/sampling/BUILD": "", |
| 3848 | "toolchain/pgo-profiles/sampling/foo.afdo": "", |
| 3849 | }, |
Vinh Tran | 99270ea | 2022-11-28 11:15:23 -0500 | [diff] [blame] | 3850 | expectedBazelTargets: []string{ |
| 3851 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), |
| 3852 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 3853 | "fdo_profile": `"//toolchain/pgo-profiles/sampling:foo"`, |
| 3854 | }), |
| 3855 | }, |
| 3856 | }, |
| 3857 | { |
| 3858 | 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] | 3859 | filesystem: map[string]string{ |
| 3860 | "toolchain/pgo-profiles/sampling/BUILD": "", |
| 3861 | "toolchain/pgo-profiles/sampling/bar.afdo": "", |
| 3862 | }, |
Vinh Tran | 99270ea | 2022-11-28 11:15:23 -0500 | [diff] [blame] | 3863 | expectedBazelTargets: []string{ |
| 3864 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), |
| 3865 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{}), |
| 3866 | }, |
| 3867 | }, |
| 3868 | { |
| 3869 | description: "cc_library with afdo enabled but profile doesn't exist", |
| 3870 | expectedBazelTargets: []string{ |
| 3871 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), |
| 3872 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{}), |
| 3873 | }, |
| 3874 | }, |
Vinh Tran | bc9c8b4 | 2022-12-09 12:03:52 -0500 | [diff] [blame] | 3875 | { |
| 3876 | description: "cc_library with afdo enabled and existing profile but BUILD file doesn't exist", |
| 3877 | filesystem: map[string]string{ |
| 3878 | "vendor/google_data/pgo_profile/sampling/foo.afdo": "", |
| 3879 | }, |
| 3880 | expectedBazelTargets: []string{ |
| 3881 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), |
| 3882 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{}), |
| 3883 | }, |
| 3884 | }, |
Vinh Tran | 99270ea | 2022-11-28 11:15:23 -0500 | [diff] [blame] | 3885 | } |
| 3886 | for _, testCase := range testCases { |
| 3887 | t.Run(testCase.description, func(t *testing.T) { |
| 3888 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3889 | ExpectedBazelTargets: testCase.expectedBazelTargets, |
| 3890 | ModuleTypeUnderTest: "cc_library", |
| 3891 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3892 | Description: testCase.description, |
| 3893 | Blueprint: binaryReplacer.Replace(bp), |
| 3894 | Filesystem: testCase.filesystem, |
| 3895 | }) |
| 3896 | }) |
| 3897 | } |
| 3898 | } |
| 3899 | |
Yu Liu | 56ccb1a | 2022-11-12 10:47:07 -0800 | [diff] [blame] | 3900 | func TestCcLibraryHeaderAbiChecker(t *testing.T) { |
| 3901 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3902 | Description: "cc_library with header abi checker", |
| 3903 | ModuleTypeUnderTest: "cc_library", |
| 3904 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3905 | Blueprint: `cc_library { |
| 3906 | name: "foo", |
| 3907 | header_abi_checker: { |
| 3908 | enabled: true, |
| 3909 | symbol_file: "a.map.txt", |
| 3910 | exclude_symbol_versions: [ |
| 3911 | "29", |
| 3912 | "30", |
| 3913 | ], |
| 3914 | exclude_symbol_tags: [ |
| 3915 | "tag1", |
| 3916 | "tag2", |
| 3917 | ], |
| 3918 | check_all_apis: true, |
| 3919 | diff_flags: ["-allow-adding-removing-weak-symbols"], |
| 3920 | }, |
| 3921 | include_build_directory: false, |
| 3922 | }`, |
| 3923 | ExpectedBazelTargets: []string{ |
| 3924 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), |
| 3925 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 3926 | "abi_checker_enabled": `True`, |
| 3927 | "abi_checker_symbol_file": `"a.map.txt"`, |
| 3928 | "abi_checker_exclude_symbol_versions": `[ |
| 3929 | "29", |
| 3930 | "30", |
| 3931 | ]`, |
| 3932 | "abi_checker_exclude_symbol_tags": `[ |
| 3933 | "tag1", |
| 3934 | "tag2", |
| 3935 | ]`, |
| 3936 | "abi_checker_check_all_apis": `True`, |
| 3937 | "abi_checker_diff_flags": `["-allow-adding-removing-weak-symbols"]`, |
| 3938 | }), |
| 3939 | }, |
| 3940 | }) |
| 3941 | } |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 3942 | |
| 3943 | func TestCcLibraryApexAvailable(t *testing.T) { |
| 3944 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3945 | Description: "cc_library apex_available converted to tags", |
| 3946 | ModuleTypeUnderTest: "cc_library", |
| 3947 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3948 | Blueprint: soongCcLibraryPreamble + ` |
| 3949 | cc_library { |
| 3950 | name: "a", |
| 3951 | srcs: ["a.cpp"], |
| 3952 | apex_available: ["com.android.foo"], |
| 3953 | } |
| 3954 | `, |
| 3955 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
| 3956 | "tags": `["apex_available=com.android.foo"]`, |
| 3957 | "srcs": `["a.cpp"]`, |
| 3958 | "local_includes": `["."]`, |
| 3959 | }), |
| 3960 | }, |
| 3961 | ) |
| 3962 | } |
| 3963 | |
| 3964 | func TestCcLibraryApexAvailableMultiple(t *testing.T) { |
| 3965 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3966 | Description: "cc_library apex_available converted to multiple tags", |
| 3967 | ModuleTypeUnderTest: "cc_library", |
| 3968 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3969 | Blueprint: soongCcLibraryPreamble + ` |
| 3970 | cc_library { |
| 3971 | name: "a", |
| 3972 | srcs: ["a.cpp"], |
| 3973 | apex_available: ["com.android.foo", "//apex_available:platform", "com.android.bar"], |
| 3974 | } |
| 3975 | `, |
| 3976 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
| 3977 | "tags": `[ |
| 3978 | "apex_available=com.android.foo", |
| 3979 | "apex_available=//apex_available:platform", |
| 3980 | "apex_available=com.android.bar", |
| 3981 | ]`, |
| 3982 | "srcs": `["a.cpp"]`, |
| 3983 | "local_includes": `["."]`, |
| 3984 | }), |
| 3985 | }, |
| 3986 | ) |
| 3987 | } |
Zi Wang | 0f82844 | 2022-12-28 11:18:11 -0800 | [diff] [blame] | 3988 | |
| 3989 | // Export_include_dirs and Export_system_include_dirs have "variant_prepend" tag. |
| 3990 | // In bp2build output, variant info(select) should go before general info. |
| 3991 | // Internal order of the property should be unchanged. (e.g. ["eid1", "eid2"]) |
| 3992 | func TestCcLibraryVariantPrependPropOrder(t *testing.T) { |
| 3993 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 3994 | Description: "cc_library variant prepend properties order", |
| 3995 | ModuleTypeUnderTest: "cc_library", |
| 3996 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 3997 | Blueprint: soongCcLibraryPreamble + ` |
| 3998 | cc_library { |
| 3999 | name: "a", |
| 4000 | srcs: ["a.cpp"], |
| 4001 | export_include_dirs: ["eid1", "eid2"], |
| 4002 | export_system_include_dirs: ["esid1", "esid2"], |
| 4003 | target: { |
| 4004 | android: { |
| 4005 | export_include_dirs: ["android_eid1", "android_eid2"], |
| 4006 | export_system_include_dirs: ["android_esid1", "android_esid2"], |
| 4007 | }, |
| 4008 | android_arm: { |
| 4009 | export_include_dirs: ["android_arm_eid1", "android_arm_eid2"], |
| 4010 | export_system_include_dirs: ["android_arm_esid1", "android_arm_esid2"], |
| 4011 | }, |
| 4012 | linux: { |
| 4013 | export_include_dirs: ["linux_eid1", "linux_eid2"], |
| 4014 | export_system_include_dirs: ["linux_esid1", "linux_esid2"], |
| 4015 | }, |
| 4016 | }, |
| 4017 | multilib: { |
| 4018 | lib32: { |
| 4019 | export_include_dirs: ["lib32_eid1", "lib32_eid2"], |
| 4020 | export_system_include_dirs: ["lib32_esid1", "lib32_esid2"], |
| 4021 | }, |
| 4022 | }, |
| 4023 | arch: { |
| 4024 | arm: { |
| 4025 | export_include_dirs: ["arm_eid1", "arm_eid2"], |
| 4026 | export_system_include_dirs: ["arm_esid1", "arm_esid2"], |
| 4027 | }, |
| 4028 | } |
| 4029 | } |
| 4030 | `, |
| 4031 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
| 4032 | "export_includes": `select({ |
| 4033 | "//build/bazel/platforms/os_arch:android_arm": [ |
| 4034 | "android_arm_eid1", |
| 4035 | "android_arm_eid2", |
| 4036 | ], |
| 4037 | "//conditions:default": [], |
| 4038 | }) + select({ |
| 4039 | "//build/bazel/platforms/os:android": [ |
| 4040 | "android_eid1", |
| 4041 | "android_eid2", |
| 4042 | "linux_eid1", |
| 4043 | "linux_eid2", |
| 4044 | ], |
| 4045 | "//build/bazel/platforms/os:linux_bionic": [ |
| 4046 | "linux_eid1", |
| 4047 | "linux_eid2", |
| 4048 | ], |
| 4049 | "//build/bazel/platforms/os:linux_glibc": [ |
| 4050 | "linux_eid1", |
| 4051 | "linux_eid2", |
| 4052 | ], |
| 4053 | "//build/bazel/platforms/os:linux_musl": [ |
| 4054 | "linux_eid1", |
| 4055 | "linux_eid2", |
| 4056 | ], |
| 4057 | "//conditions:default": [], |
| 4058 | }) + select({ |
| 4059 | "//build/bazel/platforms/arch:arm": [ |
| 4060 | "lib32_eid1", |
| 4061 | "lib32_eid2", |
| 4062 | "arm_eid1", |
| 4063 | "arm_eid2", |
| 4064 | ], |
| 4065 | "//build/bazel/platforms/arch:x86": [ |
| 4066 | "lib32_eid1", |
| 4067 | "lib32_eid2", |
| 4068 | ], |
| 4069 | "//conditions:default": [], |
| 4070 | }) + [ |
| 4071 | "eid1", |
| 4072 | "eid2", |
| 4073 | ]`, |
| 4074 | "export_system_includes": `select({ |
| 4075 | "//build/bazel/platforms/os_arch:android_arm": [ |
| 4076 | "android_arm_esid1", |
| 4077 | "android_arm_esid2", |
| 4078 | ], |
| 4079 | "//conditions:default": [], |
| 4080 | }) + select({ |
| 4081 | "//build/bazel/platforms/os:android": [ |
| 4082 | "android_esid1", |
| 4083 | "android_esid2", |
| 4084 | "linux_esid1", |
| 4085 | "linux_esid2", |
| 4086 | ], |
| 4087 | "//build/bazel/platforms/os:linux_bionic": [ |
| 4088 | "linux_esid1", |
| 4089 | "linux_esid2", |
| 4090 | ], |
| 4091 | "//build/bazel/platforms/os:linux_glibc": [ |
| 4092 | "linux_esid1", |
| 4093 | "linux_esid2", |
| 4094 | ], |
| 4095 | "//build/bazel/platforms/os:linux_musl": [ |
| 4096 | "linux_esid1", |
| 4097 | "linux_esid2", |
| 4098 | ], |
| 4099 | "//conditions:default": [], |
| 4100 | }) + select({ |
| 4101 | "//build/bazel/platforms/arch:arm": [ |
| 4102 | "lib32_esid1", |
| 4103 | "lib32_esid2", |
| 4104 | "arm_esid1", |
| 4105 | "arm_esid2", |
| 4106 | ], |
| 4107 | "//build/bazel/platforms/arch:x86": [ |
| 4108 | "lib32_esid1", |
| 4109 | "lib32_esid2", |
| 4110 | ], |
| 4111 | "//conditions:default": [], |
| 4112 | }) + [ |
| 4113 | "esid1", |
| 4114 | "esid2", |
| 4115 | ]`, |
| 4116 | "srcs": `["a.cpp"]`, |
| 4117 | "local_includes": `["."]`, |
| 4118 | "target_compatible_with": `["//build/bazel/platforms/os:android"]`, |
| 4119 | }), |
| 4120 | }, |
| 4121 | ) |
| 4122 | } |
Trevor Radcliffe | db7e026 | 2022-10-28 16:48:18 +0000 | [diff] [blame] | 4123 | |
| 4124 | func TestCcLibraryWithIntegerOverflowProperty(t *testing.T) { |
| 4125 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4126 | Description: "cc_library has correct features when integer_overflow property is provided", |
| 4127 | ModuleTypeUnderTest: "cc_library", |
| 4128 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4129 | Blueprint: ` |
| 4130 | cc_library { |
| 4131 | name: "foo", |
| 4132 | sanitize: { |
| 4133 | integer_overflow: true, |
| 4134 | }, |
| 4135 | } |
| 4136 | `, |
| 4137 | ExpectedBazelTargets: []string{ |
| 4138 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4139 | "features": `["ubsan_integer_overflow"]`, |
| 4140 | "local_includes": `["."]`, |
| 4141 | }), |
| 4142 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4143 | "features": `["ubsan_integer_overflow"]`, |
| 4144 | "local_includes": `["."]`, |
| 4145 | }), |
| 4146 | }, |
| 4147 | }) |
| 4148 | } |
| 4149 | |
| 4150 | func TestCcLibraryWithMiscUndefinedProperty(t *testing.T) { |
| 4151 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4152 | Description: "cc_library has correct features when misc_undefined property is provided", |
| 4153 | ModuleTypeUnderTest: "cc_library", |
| 4154 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4155 | Blueprint: ` |
| 4156 | cc_library { |
| 4157 | name: "foo", |
| 4158 | sanitize: { |
| 4159 | misc_undefined: ["undefined", "nullability"], |
| 4160 | }, |
| 4161 | } |
| 4162 | `, |
| 4163 | ExpectedBazelTargets: []string{ |
| 4164 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4165 | "features": `[ |
| 4166 | "ubsan_undefined", |
| 4167 | "ubsan_nullability", |
| 4168 | ]`, |
| 4169 | "local_includes": `["."]`, |
| 4170 | }), |
| 4171 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4172 | "features": `[ |
| 4173 | "ubsan_undefined", |
| 4174 | "ubsan_nullability", |
| 4175 | ]`, |
| 4176 | "local_includes": `["."]`, |
| 4177 | }), |
| 4178 | }, |
| 4179 | }) |
| 4180 | } |
| 4181 | |
Trevor Radcliffe | ded095c | 2023-06-12 19:18:28 +0000 | [diff] [blame] | 4182 | func TestCcLibraryWithSanitizerBlocklist(t *testing.T) { |
| 4183 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4184 | Description: "cc_library has correct feature when sanitize.blocklist is provided", |
| 4185 | ModuleTypeUnderTest: "cc_library", |
| 4186 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4187 | Blueprint: ` |
| 4188 | cc_library { |
| 4189 | name: "foo", |
| 4190 | sanitize: { |
| 4191 | blocklist: "foo_blocklist.txt", |
| 4192 | }, |
| 4193 | } |
| 4194 | `, |
| 4195 | ExpectedBazelTargets: []string{ |
| 4196 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Trevor Radcliffe | d714871 | 2023-07-10 18:50:47 +0000 | [diff] [blame] | 4197 | "features": `["sanitizer_blocklist_foo_blocklist_txt"]`, |
Trevor Radcliffe | ded095c | 2023-06-12 19:18:28 +0000 | [diff] [blame] | 4198 | "local_includes": `["."]`, |
| 4199 | }), |
| 4200 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Trevor Radcliffe | d714871 | 2023-07-10 18:50:47 +0000 | [diff] [blame] | 4201 | "features": `["sanitizer_blocklist_foo_blocklist_txt"]`, |
Trevor Radcliffe | ded095c | 2023-06-12 19:18:28 +0000 | [diff] [blame] | 4202 | "local_includes": `["."]`, |
| 4203 | }), |
| 4204 | }, |
| 4205 | }) |
| 4206 | } |
| 4207 | |
Trevor Radcliffe | db7e026 | 2022-10-28 16:48:18 +0000 | [diff] [blame] | 4208 | func TestCcLibraryWithUBSanPropertiesArchSpecific(t *testing.T) { |
| 4209 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4210 | Description: "cc_library has correct feature select when UBSan props are specified in arch specific blocks", |
| 4211 | ModuleTypeUnderTest: "cc_library", |
| 4212 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4213 | Blueprint: ` |
| 4214 | cc_library { |
| 4215 | name: "foo", |
| 4216 | sanitize: { |
| 4217 | misc_undefined: ["undefined", "nullability"], |
| 4218 | }, |
| 4219 | target: { |
| 4220 | android: { |
| 4221 | sanitize: { |
| 4222 | misc_undefined: ["alignment"], |
| 4223 | }, |
| 4224 | }, |
| 4225 | linux_glibc: { |
| 4226 | sanitize: { |
| 4227 | integer_overflow: true, |
| 4228 | }, |
| 4229 | }, |
| 4230 | }, |
| 4231 | } |
| 4232 | `, |
| 4233 | ExpectedBazelTargets: []string{ |
| 4234 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4235 | "features": `[ |
| 4236 | "ubsan_undefined", |
| 4237 | "ubsan_nullability", |
| 4238 | ] + select({ |
| 4239 | "//build/bazel/platforms/os:android": ["ubsan_alignment"], |
| 4240 | "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"], |
| 4241 | "//conditions:default": [], |
| 4242 | })`, |
| 4243 | "local_includes": `["."]`, |
| 4244 | }), |
| 4245 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4246 | "features": `[ |
| 4247 | "ubsan_undefined", |
| 4248 | "ubsan_nullability", |
| 4249 | ] + select({ |
| 4250 | "//build/bazel/platforms/os:android": ["ubsan_alignment"], |
| 4251 | "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"], |
| 4252 | "//conditions:default": [], |
| 4253 | })`, |
| 4254 | "local_includes": `["."]`, |
| 4255 | }), |
| 4256 | }, |
| 4257 | }) |
| 4258 | } |
Yu Liu | 10174ff | 2023-02-21 12:05:26 -0800 | [diff] [blame] | 4259 | |
| 4260 | func TestCcLibraryInApexWithStubSharedLibs(t *testing.T) { |
| 4261 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 4262 | Description: "cc_library with in apex with stub shared_libs and export_shared_lib_headers", |
| 4263 | ModuleTypeUnderTest: "cc_library", |
| 4264 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4265 | Blueprint: ` |
| 4266 | cc_library { |
| 4267 | name: "barlib", |
| 4268 | stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] }, |
| 4269 | bazel_module: { bp2build_available: false }, |
Spandan Das | 6d4d9da | 2023-04-18 06:20:40 +0000 | [diff] [blame] | 4270 | apex_available: ["//apex_available:platform",], |
Yu Liu | 10174ff | 2023-02-21 12:05:26 -0800 | [diff] [blame] | 4271 | } |
| 4272 | cc_library { |
| 4273 | name: "bazlib", |
| 4274 | stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] }, |
| 4275 | bazel_module: { bp2build_available: false }, |
Spandan Das | 6d4d9da | 2023-04-18 06:20:40 +0000 | [diff] [blame] | 4276 | apex_available: ["//apex_available:platform",], |
Yu Liu | 10174ff | 2023-02-21 12:05:26 -0800 | [diff] [blame] | 4277 | } |
| 4278 | cc_library { |
| 4279 | name: "foo", |
| 4280 | shared_libs: ["barlib", "bazlib"], |
| 4281 | export_shared_lib_headers: ["bazlib"], |
| 4282 | apex_available: [ |
Spandan Das | 6d4d9da | 2023-04-18 06:20:40 +0000 | [diff] [blame] | 4283 | "//apex_available:platform", |
Yu Liu | 10174ff | 2023-02-21 12:05:26 -0800 | [diff] [blame] | 4284 | ], |
| 4285 | }`, |
| 4286 | ExpectedBazelTargets: []string{ |
| 4287 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
Spandan Das | 6d4d9da | 2023-04-18 06:20:40 +0000 | [diff] [blame] | 4288 | "implementation_dynamic_deps": `[":barlib"]`, |
| 4289 | "dynamic_deps": `[":bazlib"]`, |
| 4290 | "local_includes": `["."]`, |
| 4291 | "tags": `["apex_available=//apex_available:platform"]`, |
Yu Liu | 10174ff | 2023-02-21 12:05:26 -0800 | [diff] [blame] | 4292 | }), |
| 4293 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Spandan Das | 6d4d9da | 2023-04-18 06:20:40 +0000 | [diff] [blame] | 4294 | "implementation_dynamic_deps": `[":barlib"]`, |
| 4295 | "dynamic_deps": `[":bazlib"]`, |
| 4296 | "local_includes": `["."]`, |
| 4297 | "tags": `["apex_available=//apex_available:platform"]`, |
Yu Liu | 10174ff | 2023-02-21 12:05:26 -0800 | [diff] [blame] | 4298 | }), |
| 4299 | }, |
| 4300 | }) |
| 4301 | } |
Trevor Radcliffe | 56b1a2b | 2023-02-06 21:58:30 +0000 | [diff] [blame] | 4302 | |
| 4303 | func TestCcLibraryWithThinLto(t *testing.T) { |
| 4304 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4305 | Description: "cc_library has correct features when thin LTO is enabled", |
| 4306 | ModuleTypeUnderTest: "cc_library", |
| 4307 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4308 | Blueprint: ` |
| 4309 | cc_library { |
| 4310 | name: "foo", |
| 4311 | lto: { |
| 4312 | thin: true, |
| 4313 | }, |
| 4314 | }`, |
| 4315 | ExpectedBazelTargets: []string{ |
| 4316 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4317 | "features": `["android_thin_lto"]`, |
| 4318 | "local_includes": `["."]`, |
| 4319 | }), |
| 4320 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4321 | "features": `["android_thin_lto"]`, |
| 4322 | "local_includes": `["."]`, |
| 4323 | }), |
| 4324 | }, |
| 4325 | }) |
| 4326 | } |
| 4327 | |
| 4328 | func TestCcLibraryWithLtoNever(t *testing.T) { |
| 4329 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4330 | Description: "cc_library has correct features when LTO is explicitly disabled", |
| 4331 | ModuleTypeUnderTest: "cc_library", |
| 4332 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4333 | Blueprint: ` |
| 4334 | cc_library { |
| 4335 | name: "foo", |
| 4336 | lto: { |
| 4337 | never: true, |
| 4338 | }, |
| 4339 | }`, |
| 4340 | ExpectedBazelTargets: []string{ |
| 4341 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4342 | "features": `["-android_thin_lto"]`, |
| 4343 | "local_includes": `["."]`, |
| 4344 | }), |
| 4345 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4346 | "features": `["-android_thin_lto"]`, |
| 4347 | "local_includes": `["."]`, |
| 4348 | }), |
| 4349 | }, |
| 4350 | }) |
| 4351 | } |
| 4352 | |
| 4353 | func TestCcLibraryWithThinLtoArchSpecific(t *testing.T) { |
| 4354 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4355 | Description: "cc_library has correct features when LTO differs across arch and os variants", |
| 4356 | ModuleTypeUnderTest: "cc_library", |
| 4357 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4358 | Blueprint: ` |
| 4359 | cc_library { |
| 4360 | name: "foo", |
| 4361 | target: { |
| 4362 | android: { |
| 4363 | lto: { |
| 4364 | thin: true, |
| 4365 | }, |
| 4366 | }, |
| 4367 | }, |
| 4368 | arch: { |
| 4369 | riscv64: { |
| 4370 | lto: { |
| 4371 | thin: false, |
| 4372 | }, |
| 4373 | }, |
| 4374 | }, |
| 4375 | }`, |
| 4376 | ExpectedBazelTargets: []string{ |
| 4377 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4378 | "local_includes": `["."]`, |
| 4379 | "features": `select({ |
| 4380 | "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"], |
| 4381 | "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"], |
| 4382 | "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"], |
| 4383 | "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"], |
| 4384 | "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"], |
| 4385 | "//conditions:default": [], |
| 4386 | })`}), |
| 4387 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4388 | "local_includes": `["."]`, |
| 4389 | "features": `select({ |
| 4390 | "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"], |
| 4391 | "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"], |
| 4392 | "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"], |
| 4393 | "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"], |
| 4394 | "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"], |
| 4395 | "//conditions:default": [], |
| 4396 | })`}), |
| 4397 | }, |
| 4398 | }) |
| 4399 | } |
| 4400 | |
| 4401 | func TestCcLibraryWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) { |
| 4402 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4403 | Description: "cc_library has correct features when LTO disabled by default but enabled on a particular variant", |
| 4404 | ModuleTypeUnderTest: "cc_library", |
| 4405 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4406 | Blueprint: ` |
| 4407 | cc_library { |
| 4408 | name: "foo", |
| 4409 | lto: { |
| 4410 | never: true, |
| 4411 | }, |
| 4412 | target: { |
| 4413 | android: { |
| 4414 | lto: { |
| 4415 | thin: true, |
| 4416 | never: false, |
| 4417 | }, |
| 4418 | }, |
| 4419 | }, |
| 4420 | }`, |
| 4421 | ExpectedBazelTargets: []string{ |
| 4422 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4423 | "local_includes": `["."]`, |
| 4424 | "features": `select({ |
| 4425 | "//build/bazel/platforms/os:android": ["android_thin_lto"], |
| 4426 | "//conditions:default": ["-android_thin_lto"], |
| 4427 | })`, |
| 4428 | }), |
| 4429 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4430 | "local_includes": `["."]`, |
| 4431 | "features": `select({ |
| 4432 | "//build/bazel/platforms/os:android": ["android_thin_lto"], |
| 4433 | "//conditions:default": ["-android_thin_lto"], |
| 4434 | })`, |
| 4435 | }), |
| 4436 | }, |
| 4437 | }) |
| 4438 | } |
| 4439 | |
| 4440 | func TestCcLibraryWithThinLtoWholeProgramVtables(t *testing.T) { |
| 4441 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4442 | Description: "cc_library has correct features when thin LTO is enabled with whole_program_vtables", |
| 4443 | ModuleTypeUnderTest: "cc_library", |
| 4444 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4445 | Blueprint: ` |
| 4446 | cc_library { |
| 4447 | name: "foo", |
| 4448 | lto: { |
| 4449 | thin: true, |
| 4450 | }, |
| 4451 | whole_program_vtables: true, |
| 4452 | }`, |
| 4453 | ExpectedBazelTargets: []string{ |
| 4454 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4455 | "features": `[ |
| 4456 | "android_thin_lto", |
| 4457 | "android_thin_lto_whole_program_vtables", |
| 4458 | ]`, |
| 4459 | "local_includes": `["."]`, |
| 4460 | }), |
| 4461 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4462 | "features": `[ |
| 4463 | "android_thin_lto", |
| 4464 | "android_thin_lto_whole_program_vtables", |
| 4465 | ]`, |
| 4466 | "local_includes": `["."]`, |
| 4467 | }), |
| 4468 | }, |
| 4469 | }) |
| 4470 | } |
Trevor Radcliffe | a8b4416 | 2023-04-14 18:25:24 +0000 | [diff] [blame] | 4471 | |
| 4472 | func TestCcLibraryHiddenVisibilityConvertedToFeature(t *testing.T) { |
| 4473 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4474 | Description: "cc_library changes hidden visibility flag to feature", |
| 4475 | ModuleTypeUnderTest: "cc_library", |
| 4476 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4477 | Blueprint: ` |
| 4478 | cc_library { |
| 4479 | name: "foo", |
| 4480 | cflags: ["-fvisibility=hidden"], |
| 4481 | }`, |
| 4482 | ExpectedBazelTargets: []string{ |
| 4483 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4484 | "features": `["visibility_hidden"]`, |
| 4485 | "local_includes": `["."]`, |
| 4486 | }), |
| 4487 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4488 | "features": `["visibility_hidden"]`, |
| 4489 | "local_includes": `["."]`, |
| 4490 | }), |
| 4491 | }, |
| 4492 | }) |
| 4493 | } |
| 4494 | |
| 4495 | func TestCcLibraryHiddenVisibilityConvertedToFeatureSharedSpecific(t *testing.T) { |
| 4496 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4497 | Description: "cc_library changes hidden visibility flag to feature when specific to shared variant", |
| 4498 | ModuleTypeUnderTest: "cc_library", |
| 4499 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4500 | Blueprint: ` |
| 4501 | cc_library { |
| 4502 | name: "foo", |
| 4503 | shared: { |
| 4504 | cflags: ["-fvisibility=hidden"], |
| 4505 | }, |
| 4506 | }`, |
| 4507 | ExpectedBazelTargets: []string{ |
| 4508 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4509 | "local_includes": `["."]`, |
| 4510 | }), |
| 4511 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4512 | "features": `["visibility_hidden"]`, |
| 4513 | "local_includes": `["."]`, |
| 4514 | }), |
| 4515 | }, |
| 4516 | }) |
| 4517 | } |
| 4518 | |
| 4519 | func TestCcLibraryHiddenVisibilityConvertedToFeatureStaticSpecific(t *testing.T) { |
| 4520 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4521 | Description: "cc_library changes hidden visibility flag to feature when specific to static variant", |
| 4522 | ModuleTypeUnderTest: "cc_library", |
| 4523 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4524 | Blueprint: ` |
| 4525 | cc_library { |
| 4526 | name: "foo", |
| 4527 | static: { |
| 4528 | cflags: ["-fvisibility=hidden"], |
| 4529 | }, |
| 4530 | }`, |
| 4531 | ExpectedBazelTargets: []string{ |
| 4532 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4533 | "features": `["visibility_hidden"]`, |
| 4534 | "local_includes": `["."]`, |
| 4535 | }), |
| 4536 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4537 | "local_includes": `["."]`, |
| 4538 | }), |
| 4539 | }, |
| 4540 | }) |
| 4541 | } |
| 4542 | |
| 4543 | func TestCcLibraryHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) { |
| 4544 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4545 | Description: "cc_library changes hidden visibility flag to feature when specific to an os", |
| 4546 | ModuleTypeUnderTest: "cc_library", |
| 4547 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4548 | Blueprint: ` |
| 4549 | cc_library { |
| 4550 | name: "foo", |
| 4551 | target: { |
| 4552 | android: { |
| 4553 | cflags: ["-fvisibility=hidden"], |
| 4554 | }, |
| 4555 | }, |
| 4556 | }`, |
| 4557 | ExpectedBazelTargets: []string{ |
| 4558 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4559 | "features": `select({ |
| 4560 | "//build/bazel/platforms/os:android": ["visibility_hidden"], |
| 4561 | "//conditions:default": [], |
| 4562 | })`, |
| 4563 | "local_includes": `["."]`, |
| 4564 | }), |
| 4565 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4566 | "features": `select({ |
| 4567 | "//build/bazel/platforms/os:android": ["visibility_hidden"], |
| 4568 | "//conditions:default": [], |
| 4569 | })`, |
| 4570 | "local_includes": `["."]`, |
| 4571 | }), |
| 4572 | }, |
| 4573 | }) |
| 4574 | } |
Spandan Das | 4242f10 | 2023-04-19 22:31:54 +0000 | [diff] [blame] | 4575 | |
| 4576 | // Test that a config_setting specific to an apex is created by cc_library. |
| 4577 | func TestCcLibraryCreatesInApexConfigSetting(t *testing.T) { |
| 4578 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4579 | Description: "cc_library creates a config_setting for each apex in apex_available", |
| 4580 | ModuleTypeUnderTest: "cc_library", |
| 4581 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4582 | Dir: "build/bazel/rules/apex", |
| 4583 | Blueprint: ` |
| 4584 | cc_library { |
| 4585 | name: "foo", |
| 4586 | apex_available: [ |
| 4587 | "//apex_available:platform", // This will be skipped, since it is equivalent to //build/bazel/rules/apex:android-non_apex |
| 4588 | "myapex" |
| 4589 | ], |
| 4590 | }`, |
| 4591 | ExpectedBazelTargets: []string{ |
| 4592 | MakeBazelTargetNoRestrictions( |
| 4593 | "config_setting", |
Spandan Das | 9cad90f | 2023-05-04 17:15:44 +0000 | [diff] [blame] | 4594 | "myapex", |
Spandan Das | 4242f10 | 2023-04-19 22:31:54 +0000 | [diff] [blame] | 4595 | AttrNameToString{ |
| 4596 | "flag_values": `{ |
Spandan Das | 9cad90f | 2023-05-04 17:15:44 +0000 | [diff] [blame] | 4597 | "//build/bazel/rules/apex:api_domain": "myapex", |
Spandan Das | 4242f10 | 2023-04-19 22:31:54 +0000 | [diff] [blame] | 4598 | }`, |
Spandan Das | 9cad90f | 2023-05-04 17:15:44 +0000 | [diff] [blame] | 4599 | "constraint_values": `["//build/bazel/platforms/os:android"]`, |
Spandan Das | 4242f10 | 2023-04-19 22:31:54 +0000 | [diff] [blame] | 4600 | }, |
| 4601 | ), |
| 4602 | }, |
| 4603 | }) |
| 4604 | } |
Yu Liu | 93893ba | 2023-05-01 13:49:52 -0700 | [diff] [blame] | 4605 | |
| 4606 | func TestCcLibraryCppFlagsInProductVariables(t *testing.T) { |
| 4607 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4608 | Description: "cc_library cppflags in product variables", |
| 4609 | ModuleTypeUnderTest: "cc_library", |
| 4610 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4611 | Blueprint: soongCcLibraryPreamble + `cc_library { |
| 4612 | name: "a", |
| 4613 | srcs: ["a.cpp"], |
| 4614 | cppflags: [ |
| 4615 | "-Wextra", |
| 4616 | "-DDEBUG_ONLY_CODE=0", |
| 4617 | ], |
| 4618 | product_variables: { |
| 4619 | eng: { |
| 4620 | cppflags: [ |
| 4621 | "-UDEBUG_ONLY_CODE", |
| 4622 | "-DDEBUG_ONLY_CODE=1", |
| 4623 | ], |
| 4624 | }, |
| 4625 | }, |
| 4626 | include_build_directory: false, |
| 4627 | } |
| 4628 | `, |
| 4629 | ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{ |
| 4630 | "cppflags": `[ |
| 4631 | "-Wextra", |
| 4632 | "-DDEBUG_ONLY_CODE=0", |
| 4633 | ] + select({ |
| 4634 | "//build/bazel/product_variables:eng": [ |
| 4635 | "-UDEBUG_ONLY_CODE", |
| 4636 | "-DDEBUG_ONLY_CODE=1", |
| 4637 | ], |
| 4638 | "//conditions:default": [], |
| 4639 | })`, |
| 4640 | "srcs": `["a.cpp"]`, |
| 4641 | }), |
| 4642 | }, |
| 4643 | ) |
| 4644 | } |
Spandan Das | df4c213 | 2023-05-09 23:58:52 +0000 | [diff] [blame] | 4645 | |
| 4646 | func TestCcLibraryYaccConversion(t *testing.T) { |
| 4647 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4648 | Description: "cc_library is built from .y/.yy files", |
| 4649 | ModuleTypeUnderTest: "cc_library", |
| 4650 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4651 | Blueprint: soongCcLibraryPreamble + `cc_library { |
| 4652 | name: "a", |
| 4653 | srcs: [ |
| 4654 | "a.cpp", |
| 4655 | "a.yy", |
| 4656 | ], |
| 4657 | shared_libs: ["sharedlib"], |
| 4658 | static_libs: ["staticlib"], |
| 4659 | yacc: { |
| 4660 | flags: ["someYaccFlag"], |
| 4661 | gen_location_hh: true, |
| 4662 | gen_position_hh: true, |
| 4663 | }, |
| 4664 | } |
| 4665 | cc_library_static { |
| 4666 | name: "staticlib", |
| 4667 | bazel_module: { bp2build_available: false }, |
| 4668 | } |
| 4669 | cc_library { |
| 4670 | name: "sharedlib", |
| 4671 | bazel_module: { bp2build_available: false }, |
| 4672 | } |
| 4673 | `, |
| 4674 | ExpectedBazelTargets: []string{ |
| 4675 | MakeBazelTarget("cc_yacc_static_library", "a_yacc", AttrNameToString{ |
| 4676 | "src": `"a.yy"`, |
| 4677 | "implementation_deps": `[":staticlib"]`, |
| 4678 | "implementation_dynamic_deps": `[":sharedlib"]`, |
| 4679 | "flags": `["someYaccFlag"]`, |
| 4680 | "gen_location_hh": "True", |
| 4681 | "gen_position_hh": "True", |
| 4682 | "local_includes": `["."]`, |
| 4683 | }), |
| 4684 | MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
| 4685 | "srcs": `["a.cpp"]`, |
| 4686 | "implementation_deps": `[":staticlib"]`, |
| 4687 | "implementation_dynamic_deps": `[":sharedlib"]`, |
| 4688 | "implementation_whole_archive_deps": `[":a_yacc"]`, |
| 4689 | "local_includes": `["."]`, |
| 4690 | }), |
| 4691 | MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ |
| 4692 | "srcs": `["a.cpp"]`, |
| 4693 | "implementation_deps": `[":staticlib"]`, |
| 4694 | "implementation_dynamic_deps": `[":sharedlib"]`, |
| 4695 | "implementation_whole_archive_deps": `[":a_yacc"]`, |
| 4696 | "local_includes": `["."]`, |
| 4697 | }), |
| 4698 | }, |
| 4699 | }) |
| 4700 | } |
Spandan Das | fb04c41 | 2023-05-15 18:35:36 +0000 | [diff] [blame] | 4701 | |
| 4702 | func TestCcLibraryHostLdLibs(t *testing.T) { |
| 4703 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4704 | Description: "cc_binary linker flags for host_ldlibs", |
| 4705 | ModuleTypeUnderTest: "cc_binary", |
| 4706 | ModuleTypeUnderTestFactory: cc.BinaryFactory, |
| 4707 | Blueprint: soongCcLibraryPreamble + `cc_binary { |
| 4708 | name: "a", |
| 4709 | host_supported: true, |
| 4710 | ldflags: ["-lcommon"], |
| 4711 | target: { |
| 4712 | linux: { |
| 4713 | host_ldlibs: [ |
| 4714 | "-llinux", |
| 4715 | ], |
| 4716 | }, |
| 4717 | darwin: { |
| 4718 | ldflags: ["-ldarwinadditional"], |
| 4719 | host_ldlibs: [ |
| 4720 | "-ldarwin", |
| 4721 | ], |
| 4722 | }, |
| 4723 | windows: { |
| 4724 | host_ldlibs: [ |
| 4725 | "-lwindows", |
| 4726 | ], |
| 4727 | }, |
| 4728 | }, |
| 4729 | } |
| 4730 | `, |
| 4731 | ExpectedBazelTargets: []string{ |
| 4732 | MakeBazelTargetNoRestrictions("cc_binary", "a", AttrNameToString{ |
| 4733 | "linkopts": `["-lcommon"] + select({ |
| 4734 | "//build/bazel/platforms/os:darwin": [ |
| 4735 | "-ldarwinadditional", |
| 4736 | "-ldarwin", |
| 4737 | ], |
| 4738 | "//build/bazel/platforms/os:linux_glibc": ["-llinux"], |
| 4739 | "//build/bazel/platforms/os:windows": ["-lwindows"], |
| 4740 | "//conditions:default": [], |
| 4741 | })`, |
| 4742 | "local_includes": `["."]`, |
| 4743 | }), |
| 4744 | }, |
| 4745 | }) |
| 4746 | } |
Trevor Radcliffe | 27669c0 | 2023-03-28 20:47:10 +0000 | [diff] [blame] | 4747 | |
| 4748 | func TestCcLibraryWithCfi(t *testing.T) { |
| 4749 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4750 | Description: "cc_library has correct features when cfi is enabled", |
| 4751 | ModuleTypeUnderTest: "cc_library", |
| 4752 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4753 | Blueprint: ` |
| 4754 | cc_library { |
| 4755 | name: "foo", |
| 4756 | sanitize: { |
| 4757 | cfi: true, |
| 4758 | }, |
| 4759 | }`, |
| 4760 | ExpectedBazelTargets: []string{ |
| 4761 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4762 | "features": `["android_cfi"]`, |
| 4763 | "local_includes": `["."]`, |
| 4764 | }), |
| 4765 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4766 | "features": `["android_cfi"]`, |
| 4767 | "local_includes": `["."]`, |
| 4768 | }), |
| 4769 | }, |
| 4770 | }) |
| 4771 | } |
| 4772 | |
| 4773 | func TestCcLibraryWithCfiOsSpecific(t *testing.T) { |
| 4774 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4775 | Description: "cc_library has correct features when cfi is enabled for specific variants", |
| 4776 | ModuleTypeUnderTest: "cc_library", |
| 4777 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4778 | Blueprint: ` |
| 4779 | cc_library { |
| 4780 | name: "foo", |
| 4781 | target: { |
| 4782 | android: { |
| 4783 | sanitize: { |
| 4784 | cfi: true, |
| 4785 | }, |
| 4786 | }, |
| 4787 | }, |
| 4788 | }`, |
| 4789 | ExpectedBazelTargets: []string{ |
| 4790 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4791 | "features": `select({ |
| 4792 | "//build/bazel/platforms/os:android": ["android_cfi"], |
| 4793 | "//conditions:default": [], |
| 4794 | })`, |
| 4795 | "local_includes": `["."]`, |
| 4796 | }), |
| 4797 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4798 | "features": `select({ |
| 4799 | "//build/bazel/platforms/os:android": ["android_cfi"], |
| 4800 | "//conditions:default": [], |
| 4801 | })`, |
| 4802 | "local_includes": `["."]`, |
| 4803 | }), |
| 4804 | }, |
| 4805 | }) |
| 4806 | } |
| 4807 | |
| 4808 | func TestCcLibraryWithCfiAndCfiAssemblySupport(t *testing.T) { |
| 4809 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4810 | Description: "cc_library has correct features when cfi is enabled with cfi_assembly_support", |
| 4811 | ModuleTypeUnderTest: "cc_library", |
| 4812 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4813 | Blueprint: ` |
| 4814 | cc_library { |
| 4815 | name: "foo", |
| 4816 | sanitize: { |
| 4817 | cfi: true, |
| 4818 | config: { |
| 4819 | cfi_assembly_support: true, |
| 4820 | }, |
| 4821 | }, |
| 4822 | }`, |
| 4823 | ExpectedBazelTargets: []string{ |
| 4824 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4825 | "features": `[ |
| 4826 | "android_cfi", |
| 4827 | "android_cfi_assembly_support", |
| 4828 | ]`, |
| 4829 | "local_includes": `["."]`, |
| 4830 | }), |
| 4831 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4832 | "features": `[ |
| 4833 | "android_cfi", |
| 4834 | "android_cfi_assembly_support", |
| 4835 | ]`, |
| 4836 | "local_includes": `["."]`, |
| 4837 | }), |
| 4838 | }, |
| 4839 | }) |
| 4840 | } |
Spandan Das | 39ccf93 | 2023-05-26 18:03:39 +0000 | [diff] [blame] | 4841 | |
Trevor Radcliffe | 523c5c6 | 2023-06-16 20:15:45 +0000 | [diff] [blame] | 4842 | func TestCcLibraryExplicitlyDisablesCfiWhenFalse(t *testing.T) { |
| 4843 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4844 | Description: "cc_library disables cfi when explciitly set to false in the bp", |
| 4845 | ModuleTypeUnderTest: "cc_library", |
| 4846 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4847 | Blueprint: ` |
| 4848 | cc_library { |
| 4849 | name: "foo", |
| 4850 | sanitize: { |
| 4851 | cfi: false, |
| 4852 | }, |
| 4853 | } |
| 4854 | `, |
| 4855 | ExpectedBazelTargets: []string{ |
| 4856 | MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ |
| 4857 | "features": `["-android_cfi"]`, |
| 4858 | "local_includes": `["."]`, |
| 4859 | }), |
| 4860 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 4861 | "features": `["-android_cfi"]`, |
| 4862 | "local_includes": `["."]`, |
| 4863 | }), |
| 4864 | }, |
| 4865 | }) |
| 4866 | } |
| 4867 | |
Spandan Das | 39ccf93 | 2023-05-26 18:03:39 +0000 | [diff] [blame] | 4868 | func TestCcLibraryWithStem(t *testing.T) { |
| 4869 | runCcLibraryTestCase(t, Bp2buildTestCase{ |
| 4870 | Description: "cc_library with stem property", |
| 4871 | ModuleTypeUnderTest: "cc_library_shared", |
| 4872 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 4873 | Blueprint: soongCcLibraryPreamble + ` |
| 4874 | cc_library_shared { |
| 4875 | name: "foo_with_stem_simple", |
| 4876 | stem: "foo", |
| 4877 | } |
| 4878 | cc_library_shared { |
| 4879 | name: "foo_with_arch_variant_stem", |
| 4880 | arch: { |
| 4881 | arm: { |
| 4882 | stem: "foo-arm", |
| 4883 | }, |
| 4884 | arm64: { |
| 4885 | stem: "foo-arm64", |
| 4886 | }, |
| 4887 | }, |
| 4888 | } |
| 4889 | `, |
| 4890 | ExpectedBazelTargets: []string{ |
| 4891 | MakeBazelTarget("cc_library_shared", "foo_with_stem_simple", AttrNameToString{ |
| 4892 | "stem": `"foo"`, |
| 4893 | "local_includes": `["."]`, |
| 4894 | }), |
| 4895 | MakeBazelTarget("cc_library_shared", "foo_with_arch_variant_stem", AttrNameToString{ |
| 4896 | "stem": `select({ |
| 4897 | "//build/bazel/platforms/arch:arm": "foo-arm", |
| 4898 | "//build/bazel/platforms/arch:arm64": "foo-arm64", |
| 4899 | "//conditions:default": None, |
| 4900 | })`, |
| 4901 | "local_includes": `["."]`, |
| 4902 | }), |
| 4903 | }, |
| 4904 | }) |
| 4905 | } |
Spandan Das | c53767e | 2023-08-03 23:02:26 +0000 | [diff] [blame^] | 4906 | |
| 4907 | // Bazel enforces that proto_library and the .proto file are in the same bazel package |
| 4908 | func TestGenerateProtoLibraryInSamePackage(t *testing.T) { |
| 4909 | tc := Bp2buildTestCase{ |
| 4910 | Description: "cc_library depends on .proto files from multiple packages", |
| 4911 | ModuleTypeUnderTest: "cc_library", |
| 4912 | ModuleTypeUnderTestFactory: cc.LibraryFactory, |
| 4913 | Blueprint: ` |
| 4914 | cc_library_static { |
| 4915 | name: "foo", |
| 4916 | srcs: [ |
| 4917 | "foo.proto", |
| 4918 | "bar/bar.proto", // Different package because there is a bar/Android.bp |
| 4919 | "baz/subbaz/baz.proto", // Different package because there is baz/subbaz/Android.bp |
| 4920 | ], |
| 4921 | } |
| 4922 | ` + simpleModuleDoNotConvertBp2build("cc_library", "libprotobuf-cpp-lite"), |
| 4923 | Filesystem: map[string]string{ |
| 4924 | "bar/Android.bp": "", |
| 4925 | "baz/subbaz/Android.bp": "", |
| 4926 | }, |
| 4927 | } |
| 4928 | |
| 4929 | // We will run the test 3 times and check in the root, bar and baz/subbaz directories |
| 4930 | // Root dir |
| 4931 | tc.ExpectedBazelTargets = []string{ |
| 4932 | MakeBazelTarget("cc_library_static", "foo", AttrNameToString{ |
| 4933 | "local_includes": `["."]`, |
| 4934 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 4935 | "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, |
| 4936 | }), |
| 4937 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
| 4938 | "srcs": `["foo.proto"]`, |
| 4939 | }), |
| 4940 | MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
| 4941 | "deps": `[ |
| 4942 | ":foo_proto", |
| 4943 | "//bar:foo_proto", |
| 4944 | "//baz/subbaz:foo_proto", |
| 4945 | ]`, |
| 4946 | }), |
| 4947 | } |
| 4948 | runCcLibraryTestCase(t, tc) |
| 4949 | |
| 4950 | // bar dir |
| 4951 | tc.Dir = "bar" |
| 4952 | tc.ExpectedBazelTargets = []string{ |
| 4953 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
| 4954 | "srcs": `["//bar:bar.proto"]`, |
| 4955 | "import_prefix": `"bar"`, |
| 4956 | }), |
| 4957 | } |
| 4958 | runCcLibraryTestCase(t, tc) |
| 4959 | |
| 4960 | // baz/subbaz dir |
| 4961 | tc.Dir = "baz/subbaz" |
| 4962 | tc.ExpectedBazelTargets = []string{ |
| 4963 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
| 4964 | "srcs": `["//baz/subbaz:baz.proto"]`, |
| 4965 | "import_prefix": `"baz/subbaz"`, |
| 4966 | }), |
| 4967 | } |
| 4968 | runCcLibraryTestCase(t, tc) |
| 4969 | } |