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