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