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