Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [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 | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 19 | "testing" |
| 20 | |
| 21 | "android/soong/android" |
| 22 | "android/soong/cc" |
| 23 | ) |
| 24 | |
| 25 | const ( |
| 26 | // See cc/testing.go for more context |
| 27 | // TODO(alexmarquez): Split out the preamble into common code? |
| 28 | soongCcLibrarySharedPreamble = soongCcLibraryStaticPreamble |
| 29 | ) |
| 30 | |
| 31 | func registerCcLibrarySharedModuleTypes(ctx android.RegistrationContext) { |
| 32 | cc.RegisterCCBuildComponents(ctx) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 33 | ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) |
| 34 | ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 35 | ctx.RegisterModuleType("cc_library", cc.LibraryFactory) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 38 | func runCcLibrarySharedTestCase(t *testing.T, tc Bp2buildTestCase) { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 39 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 40 | (&tc).ModuleTypeUnderTest = "cc_library_shared" |
| 41 | (&tc).ModuleTypeUnderTestFactory = cc.LibrarySharedFactory |
| 42 | RunBp2BuildTestCase(t, registerCcLibrarySharedModuleTypes, tc) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | func TestCcLibrarySharedSimple(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 46 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 47 | Description: "cc_library_shared simple overall test", |
| 48 | Filesystem: map[string]string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 49 | // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?) |
| 50 | "include_dir_1/include_dir_1_a.h": "", |
| 51 | "include_dir_1/include_dir_1_b.h": "", |
| 52 | "include_dir_2/include_dir_2_a.h": "", |
| 53 | "include_dir_2/include_dir_2_b.h": "", |
| 54 | // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?) |
| 55 | "local_include_dir_1/local_include_dir_1_a.h": "", |
| 56 | "local_include_dir_1/local_include_dir_1_b.h": "", |
| 57 | "local_include_dir_2/local_include_dir_2_a.h": "", |
| 58 | "local_include_dir_2/local_include_dir_2_b.h": "", |
| 59 | // NOTE: export_include_dir headers *should* appear in Bazel hdrs later |
| 60 | "export_include_dir_1/export_include_dir_1_a.h": "", |
| 61 | "export_include_dir_1/export_include_dir_1_b.h": "", |
| 62 | "export_include_dir_2/export_include_dir_2_a.h": "", |
| 63 | "export_include_dir_2/export_include_dir_2_b.h": "", |
| 64 | // NOTE: Soong implicitly includes headers in the current directory |
| 65 | "implicit_include_1.h": "", |
| 66 | "implicit_include_2.h": "", |
| 67 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 68 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 69 | cc_library_headers { |
| 70 | name: "header_lib_1", |
| 71 | export_include_dirs: ["header_lib_1"], |
| 72 | bazel_module: { bp2build_available: false }, |
| 73 | } |
| 74 | |
| 75 | cc_library_headers { |
| 76 | name: "header_lib_2", |
| 77 | export_include_dirs: ["header_lib_2"], |
| 78 | bazel_module: { bp2build_available: false }, |
| 79 | } |
| 80 | |
| 81 | cc_library_shared { |
| 82 | name: "shared_lib_1", |
| 83 | srcs: ["shared_lib_1.cc"], |
| 84 | bazel_module: { bp2build_available: false }, |
| 85 | } |
| 86 | |
| 87 | cc_library_shared { |
| 88 | name: "shared_lib_2", |
| 89 | srcs: ["shared_lib_2.cc"], |
| 90 | bazel_module: { bp2build_available: false }, |
| 91 | } |
| 92 | |
| 93 | cc_library_static { |
| 94 | name: "whole_static_lib_1", |
| 95 | srcs: ["whole_static_lib_1.cc"], |
| 96 | bazel_module: { bp2build_available: false }, |
| 97 | } |
| 98 | |
| 99 | cc_library_static { |
| 100 | name: "whole_static_lib_2", |
| 101 | srcs: ["whole_static_lib_2.cc"], |
| 102 | bazel_module: { bp2build_available: false }, |
| 103 | } |
| 104 | |
| 105 | cc_library_shared { |
| 106 | name: "foo_shared", |
| 107 | srcs: [ |
| 108 | "foo_shared1.cc", |
| 109 | "foo_shared2.cc", |
| 110 | ], |
| 111 | cflags: [ |
| 112 | "-Dflag1", |
| 113 | "-Dflag2" |
| 114 | ], |
| 115 | shared_libs: [ |
| 116 | "shared_lib_1", |
| 117 | "shared_lib_2" |
| 118 | ], |
| 119 | whole_static_libs: [ |
| 120 | "whole_static_lib_1", |
| 121 | "whole_static_lib_2" |
| 122 | ], |
| 123 | include_dirs: [ |
| 124 | "include_dir_1", |
| 125 | "include_dir_2", |
| 126 | ], |
| 127 | local_include_dirs: [ |
| 128 | "local_include_dir_1", |
| 129 | "local_include_dir_2", |
| 130 | ], |
| 131 | export_include_dirs: [ |
| 132 | "export_include_dir_1", |
| 133 | "export_include_dir_2" |
| 134 | ], |
| 135 | header_libs: [ |
| 136 | "header_lib_1", |
| 137 | "header_lib_2" |
| 138 | ], |
Yu Liu | fc60316 | 2022-03-01 15:44:08 -0800 | [diff] [blame] | 139 | sdk_version: "current", |
| 140 | min_sdk_version: "29", |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 141 | |
| 142 | // TODO: Also support export_header_lib_headers |
| 143 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 144 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 145 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 146 | "absolute_includes": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 147 | "include_dir_1", |
| 148 | "include_dir_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 149 | ]`, |
| 150 | "copts": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 151 | "-Dflag1", |
| 152 | "-Dflag2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 153 | ]`, |
| 154 | "export_includes": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 155 | "export_include_dir_1", |
| 156 | "export_include_dir_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 157 | ]`, |
| 158 | "implementation_deps": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 159 | ":header_lib_1", |
| 160 | ":header_lib_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 161 | ]`, |
| 162 | "implementation_dynamic_deps": `[ |
Liz Kammer | 7a210ac | 2021-09-22 15:52:58 -0400 | [diff] [blame] | 163 | ":shared_lib_1", |
| 164 | ":shared_lib_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 165 | ]`, |
| 166 | "local_includes": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 167 | "local_include_dir_1", |
| 168 | "local_include_dir_2", |
| 169 | ".", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 170 | ]`, |
| 171 | "srcs": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 172 | "foo_shared1.cc", |
| 173 | "foo_shared2.cc", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 174 | ]`, |
| 175 | "whole_archive_deps": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 176 | ":whole_static_lib_1", |
| 177 | ":whole_static_lib_2", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 178 | ]`, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 126bd58 | 2022-04-21 15:19:27 +0000 | [diff] [blame] | 179 | "sdk_version": `"current"`, |
| 180 | "min_sdk_version": `"29"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 181 | }), |
| 182 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 183 | }) |
| 184 | } |
| 185 | |
| 186 | func TestCcLibrarySharedArchSpecificSharedLib(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 187 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 188 | Description: "cc_library_shared arch-specific shared_libs with whole_static_libs", |
| 189 | Filesystem: map[string]string{}, |
| 190 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 191 | cc_library_static { |
| 192 | name: "static_dep", |
| 193 | bazel_module: { bp2build_available: false }, |
| 194 | } |
| 195 | cc_library_shared { |
| 196 | name: "shared_dep", |
| 197 | bazel_module: { bp2build_available: false }, |
| 198 | } |
| 199 | cc_library_shared { |
| 200 | name: "foo_shared", |
| 201 | arch: { arm64: { shared_libs: ["shared_dep"], whole_static_libs: ["static_dep"] } }, |
| 202 | include_build_directory: false, |
| 203 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 204 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 205 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 206 | "implementation_dynamic_deps": `select({ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 207 | "//build/bazel/platforms/arch:arm64": [":shared_dep"], |
| 208 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 209 | })`, |
| 210 | "whole_archive_deps": `select({ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 211 | "//build/bazel/platforms/arch:arm64": [":static_dep"], |
| 212 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 213 | })`, |
| 214 | }), |
| 215 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 216 | }) |
| 217 | } |
| 218 | |
| 219 | func TestCcLibrarySharedOsSpecificSharedLib(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 220 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 221 | Description: "cc_library_shared os-specific shared_libs", |
| 222 | Filesystem: map[string]string{}, |
| 223 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 224 | cc_library_shared { |
| 225 | name: "shared_dep", |
| 226 | bazel_module: { bp2build_available: false }, |
| 227 | } |
| 228 | cc_library_shared { |
| 229 | name: "foo_shared", |
| 230 | target: { android: { shared_libs: ["shared_dep"], } }, |
| 231 | include_build_directory: false, |
| 232 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 233 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 234 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 235 | "implementation_dynamic_deps": `select({ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 236 | "//build/bazel/platforms/os:android": [":shared_dep"], |
| 237 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 238 | })`, |
| 239 | }), |
| 240 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 241 | }) |
| 242 | } |
| 243 | |
| 244 | func TestCcLibrarySharedBaseArchOsSpecificSharedLib(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 245 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 246 | Description: "cc_library_shared base, arch, and os-specific shared_libs", |
| 247 | Filesystem: map[string]string{}, |
| 248 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 249 | cc_library_shared { |
| 250 | name: "shared_dep", |
| 251 | bazel_module: { bp2build_available: false }, |
| 252 | } |
| 253 | cc_library_shared { |
| 254 | name: "shared_dep2", |
| 255 | bazel_module: { bp2build_available: false }, |
| 256 | } |
| 257 | cc_library_shared { |
| 258 | name: "shared_dep3", |
| 259 | bazel_module: { bp2build_available: false }, |
| 260 | } |
| 261 | cc_library_shared { |
| 262 | name: "foo_shared", |
| 263 | shared_libs: ["shared_dep"], |
| 264 | target: { android: { shared_libs: ["shared_dep2"] } }, |
| 265 | arch: { arm64: { shared_libs: ["shared_dep3"] } }, |
| 266 | include_build_directory: false, |
| 267 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 268 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 269 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 270 | "implementation_dynamic_deps": `[":shared_dep"] + select({ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 271 | "//build/bazel/platforms/arch:arm64": [":shared_dep3"], |
| 272 | "//conditions:default": [], |
| 273 | }) + select({ |
| 274 | "//build/bazel/platforms/os:android": [":shared_dep2"], |
| 275 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 276 | })`, |
| 277 | }), |
| 278 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 279 | }) |
| 280 | } |
| 281 | |
| 282 | func TestCcLibrarySharedSimpleExcludeSrcs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 283 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 284 | Description: "cc_library_shared simple exclude_srcs", |
| 285 | Filesystem: map[string]string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 286 | "common.c": "", |
| 287 | "foo-a.c": "", |
| 288 | "foo-excluded.c": "", |
| 289 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 290 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 291 | cc_library_shared { |
| 292 | name: "foo_shared", |
| 293 | srcs: ["common.c", "foo-*.c"], |
| 294 | exclude_srcs: ["foo-excluded.c"], |
| 295 | include_build_directory: false, |
| 296 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 297 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 298 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 299 | "srcs_c": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 300 | "common.c", |
| 301 | "foo-a.c", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 302 | ]`, |
| 303 | }), |
| 304 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 305 | }) |
| 306 | } |
| 307 | |
| 308 | func TestCcLibrarySharedStrip(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 309 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 310 | Description: "cc_library_shared stripping", |
| 311 | Filesystem: map[string]string{}, |
| 312 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 313 | cc_library_shared { |
| 314 | name: "foo_shared", |
| 315 | strip: { |
| 316 | keep_symbols: false, |
| 317 | keep_symbols_and_debug_frame: true, |
| 318 | keep_symbols_list: ["sym", "sym2"], |
| 319 | all: true, |
| 320 | none: false, |
| 321 | }, |
| 322 | include_build_directory: false, |
| 323 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 324 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 325 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 326 | "strip": `{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 327 | "all": True, |
| 328 | "keep_symbols": False, |
| 329 | "keep_symbols_and_debug_frame": True, |
| 330 | "keep_symbols_list": [ |
| 331 | "sym", |
| 332 | "sym2", |
| 333 | ], |
| 334 | "none": False, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 335 | }`, |
| 336 | }), |
| 337 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 338 | }) |
| 339 | } |
| 340 | |
Trevor Radcliffe | 37ec2f7 | 2022-09-27 01:46:01 +0000 | [diff] [blame] | 341 | func TestCcLibrarySharedVersionScriptAndDynamicList(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 342 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
Trevor Radcliffe | 37ec2f7 | 2022-09-27 01:46:01 +0000 | [diff] [blame] | 343 | Description: "cc_library_shared version script and dynamic list", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 344 | Filesystem: map[string]string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 345 | "version_script": "", |
Trevor Radcliffe | 37ec2f7 | 2022-09-27 01:46:01 +0000 | [diff] [blame] | 346 | "dynamic.list": "", |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 347 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 348 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 349 | cc_library_shared { |
| 350 | name: "foo_shared", |
| 351 | version_script: "version_script", |
Trevor Radcliffe | 37ec2f7 | 2022-09-27 01:46:01 +0000 | [diff] [blame] | 352 | dynamic_list: "dynamic.list", |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 353 | include_build_directory: false, |
| 354 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 355 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 356 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Trevor Radcliffe | 37ec2f7 | 2022-09-27 01:46:01 +0000 | [diff] [blame] | 357 | "additional_linker_inputs": `[ |
| 358 | "version_script", |
| 359 | "dynamic.list", |
| 360 | ]`, |
| 361 | "linkopts": `[ |
| 362 | "-Wl,--version-script,$(location version_script)", |
| 363 | "-Wl,--dynamic-list,$(location dynamic.list)", |
| 364 | ]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 365 | }), |
| 366 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ac5097f | 2021-09-01 21:22:09 +0000 | [diff] [blame] | 367 | }) |
| 368 | } |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 369 | |
Trevor Radcliffe | ea6a45d | 2022-09-20 18:58:01 +0000 | [diff] [blame^] | 370 | func TestCcLibraryLdflagsSplitBySpaceSoongAdded(t *testing.T) { |
| 371 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 372 | Description: "ldflags are split by spaces except for the ones added by soong (version script and dynamic list)", |
| 373 | Filesystem: map[string]string{ |
| 374 | "version_script": "", |
| 375 | "dynamic.list": "", |
| 376 | }, |
| 377 | Blueprint: ` |
| 378 | cc_library_shared { |
| 379 | name: "foo", |
| 380 | ldflags: [ |
| 381 | "--nospace_flag", |
| 382 | "-z spaceflag", |
| 383 | ], |
| 384 | version_script: "version_script", |
| 385 | dynamic_list: "dynamic.list", |
| 386 | include_build_directory: false, |
| 387 | }`, |
| 388 | ExpectedBazelTargets: []string{ |
| 389 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 390 | "additional_linker_inputs": `[ |
| 391 | "version_script", |
| 392 | "dynamic.list", |
| 393 | ]`, |
| 394 | "linkopts": `[ |
| 395 | "--nospace_flag", |
| 396 | "-z", |
| 397 | "spaceflag", |
| 398 | "-Wl,--version-script,$(location version_script)", |
| 399 | "-Wl,--dynamic-list,$(location dynamic.list)", |
| 400 | ]`, |
| 401 | }), |
| 402 | }, |
| 403 | }) |
| 404 | } |
| 405 | |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 406 | func TestCcLibrarySharedNoCrtTrue(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 407 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 408 | Description: "cc_library_shared - nocrt: true emits attribute", |
| 409 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 410 | "impl.cpp": "", |
| 411 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 412 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 413 | cc_library_shared { |
| 414 | name: "foo_shared", |
| 415 | srcs: ["impl.cpp"], |
| 416 | nocrt: true, |
| 417 | include_build_directory: false, |
| 418 | } |
| 419 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 420 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 421 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 422 | "link_crt": `False`, |
| 423 | "srcs": `["impl.cpp"]`, |
| 424 | }), |
| 425 | }, |
| 426 | }) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | func TestCcLibrarySharedNoCrtFalse(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 430 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 431 | Description: "cc_library_shared - nocrt: false doesn't emit attribute", |
| 432 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 433 | "impl.cpp": "", |
| 434 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 435 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 436 | cc_library_shared { |
| 437 | name: "foo_shared", |
| 438 | srcs: ["impl.cpp"], |
| 439 | nocrt: false, |
| 440 | include_build_directory: false, |
| 441 | } |
| 442 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 443 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 444 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 445 | "srcs": `["impl.cpp"]`, |
| 446 | }), |
| 447 | }, |
| 448 | }) |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | func TestCcLibrarySharedNoCrtArchVariant(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 452 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 453 | Description: "cc_library_shared - nocrt in select", |
| 454 | Filesystem: map[string]string{ |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 455 | "impl.cpp": "", |
| 456 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 457 | Blueprint: soongCcLibraryPreamble + ` |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 458 | cc_library_shared { |
| 459 | name: "foo_shared", |
| 460 | srcs: ["impl.cpp"], |
| 461 | arch: { |
| 462 | arm: { |
| 463 | nocrt: true, |
| 464 | }, |
| 465 | x86: { |
| 466 | nocrt: false, |
| 467 | }, |
| 468 | }, |
| 469 | include_build_directory: false, |
| 470 | } |
| 471 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 472 | ExpectedErr: fmt.Errorf("module \"foo_shared\": nocrt is not supported for arch variants"), |
Jingwen Chen | 6ada589 | 2021-09-17 11:38:09 +0000 | [diff] [blame] | 473 | }) |
| 474 | } |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 475 | |
| 476 | func TestCcLibrarySharedProto(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 477 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 478 | Blueprint: soongCcProtoPreamble + `cc_library_shared { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 479 | name: "foo", |
| 480 | srcs: ["foo.proto"], |
| 481 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 482 | export_proto_headers: true, |
| 483 | }, |
| 484 | include_build_directory: false, |
| 485 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 486 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 487 | MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 488 | "srcs": `["foo.proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 489 | }), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 490 | "deps": `[":foo_proto"]`, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 491 | }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 492 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 493 | "whole_archive_deps": `[":foo_cc_proto_lite"]`, |
| 494 | }), |
| 495 | }, |
| 496 | }) |
| 497 | } |
Rupert Shuttleworth | 484aa25 | 2021-12-10 07:22:53 -0500 | [diff] [blame] | 498 | |
| 499 | func TestCcLibrarySharedUseVersionLib(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 500 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 501 | Filesystem: map[string]string{ |
| 502 | soongCcVersionLibBpPath: soongCcVersionLibBp, |
| 503 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 504 | Blueprint: soongCcProtoPreamble + `cc_library_shared { |
Rupert Shuttleworth | 484aa25 | 2021-12-10 07:22:53 -0500 | [diff] [blame] | 505 | name: "foo", |
| 506 | use_version_lib: true, |
| 507 | include_build_directory: false, |
| 508 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 509 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 510 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 511 | "use_version_lib": "True", |
| 512 | "implementation_whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`, |
Rupert Shuttleworth | 484aa25 | 2021-12-10 07:22:53 -0500 | [diff] [blame] | 513 | }), |
| 514 | }, |
| 515 | }) |
| 516 | } |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 517 | |
| 518 | func TestCcLibrarySharedStubs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 519 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 520 | Description: "cc_library_shared stubs", |
| 521 | ModuleTypeUnderTest: "cc_library_shared", |
| 522 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 523 | Dir: "foo/bar", |
| 524 | Filesystem: map[string]string{ |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 525 | "foo/bar/Android.bp": ` |
| 526 | cc_library_shared { |
| 527 | name: "a", |
| 528 | stubs: { symbol_file: "a.map.txt", versions: ["28", "29", "current"] }, |
| 529 | bazel_module: { bp2build_available: true }, |
| 530 | include_build_directory: false, |
| 531 | } |
| 532 | `, |
| 533 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 534 | Blueprint: soongCcLibraryPreamble, |
Trevor Radcliffe | f19d8a7 | 2022-09-20 23:04:39 +0000 | [diff] [blame] | 535 | ExpectedBazelTargets: []string{makeCcStubSuiteTargets("a", AttrNameToString{ |
| 536 | "soname": `"a.so"`, |
| 537 | "source_library": `":a"`, |
| 538 | "stubs_symbol_file": `"a.map.txt"`, |
| 539 | "stubs_versions": `[ |
Trevor Radcliffe | 087af54 | 2022-09-16 15:36:10 +0000 | [diff] [blame] | 540 | "28", |
| 541 | "29", |
| 542 | "current", |
| 543 | ]`, |
Trevor Radcliffe | f19d8a7 | 2022-09-20 23:04:39 +0000 | [diff] [blame] | 544 | }), |
| 545 | MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ |
| 546 | "has_stubs": `True`, |
Trevor Radcliffe | 087af54 | 2022-09-16 15:36:10 +0000 | [diff] [blame] | 547 | }), |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 548 | }, |
Trevor Radcliffe | f19d8a7 | 2022-09-20 23:04:39 +0000 | [diff] [blame] | 549 | }) |
Jingwen Chen | 0ee88a6 | 2022-01-07 14:55:29 +0000 | [diff] [blame] | 550 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 126bd58 | 2022-04-21 15:19:27 +0000 | [diff] [blame] | 551 | |
| 552 | func TestCcLibrarySharedSystemSharedLibsSharedEmpty(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 553 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 554 | Description: "cc_library_shared system_shared_libs empty shared default", |
| 555 | ModuleTypeUnderTest: "cc_library_shared", |
| 556 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 557 | Blueprint: soongCcLibrarySharedPreamble + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 126bd58 | 2022-04-21 15:19:27 +0000 | [diff] [blame] | 558 | cc_defaults { |
| 559 | name: "empty_defaults", |
| 560 | shared: { |
| 561 | system_shared_libs: [], |
| 562 | }, |
| 563 | include_build_directory: false, |
| 564 | } |
| 565 | cc_library_shared { |
| 566 | name: "empty", |
| 567 | defaults: ["empty_defaults"], |
| 568 | } |
| 569 | `, |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 570 | ExpectedBazelTargets: []string{MakeBazelTarget("cc_library_shared", "empty", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 126bd58 | 2022-04-21 15:19:27 +0000 | [diff] [blame] | 571 | "system_dynamic_deps": "[]", |
| 572 | })}, |
| 573 | }) |
| 574 | } |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 575 | |
| 576 | func TestCcLibrarySharedConvertLex(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 577 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 578 | Description: "cc_library_shared with lex files", |
| 579 | ModuleTypeUnderTest: "cc_library_shared", |
| 580 | ModuleTypeUnderTestFactory: cc.LibrarySharedFactory, |
| 581 | Filesystem: map[string]string{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 582 | "foo.c": "", |
| 583 | "bar.cc": "", |
| 584 | "foo1.l": "", |
| 585 | "bar1.ll": "", |
| 586 | "foo2.l": "", |
| 587 | "bar2.ll": "", |
| 588 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 589 | Blueprint: `cc_library_shared { |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 590 | name: "foo_lib", |
| 591 | srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"], |
| 592 | lex: { flags: ["--foo_flags"] }, |
| 593 | include_build_directory: false, |
| 594 | bazel_module: { bp2build_available: true }, |
| 595 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 596 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 597 | MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 598 | "srcs": `[ |
| 599 | "foo1.l", |
| 600 | "foo2.l", |
| 601 | ]`, |
| 602 | "lexopts": `["--foo_flags"]`, |
| 603 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 604 | MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 605 | "srcs": `[ |
| 606 | "bar1.ll", |
| 607 | "bar2.ll", |
| 608 | ]`, |
| 609 | "lexopts": `["--foo_flags"]`, |
| 610 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 611 | MakeBazelTarget("cc_library_shared", "foo_lib", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 612 | "srcs": `[ |
| 613 | "bar.cc", |
| 614 | ":foo_lib_genlex_ll", |
| 615 | ]`, |
| 616 | "srcs_c": `[ |
| 617 | "foo.c", |
| 618 | ":foo_lib_genlex_l", |
| 619 | ]`, |
| 620 | }), |
| 621 | }, |
| 622 | }) |
| 623 | } |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 624 | |
| 625 | func TestCcLibrarySharedClangUnknownFlags(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 626 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 627 | Blueprint: soongCcProtoPreamble + `cc_library_shared { |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 628 | name: "foo", |
| 629 | conlyflags: ["-a", "-finline-functions"], |
| 630 | cflags: ["-b","-finline-functions"], |
| 631 | cppflags: ["-c", "-finline-functions"], |
| 632 | ldflags: ["-d","-finline-functions", "-e"], |
| 633 | include_build_directory: false, |
| 634 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 635 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 636 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 637 | "conlyflags": `["-a"]`, |
| 638 | "copts": `["-b"]`, |
| 639 | "cppflags": `["-c"]`, |
| 640 | "linkopts": `[ |
| 641 | "-d", |
| 642 | "-e", |
| 643 | ]`, |
| 644 | }), |
| 645 | }, |
| 646 | }) |
| 647 | } |
| 648 | |
| 649 | func TestCCLibraryFlagSpaceSplitting(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 650 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 651 | Blueprint: soongCcProtoPreamble + `cc_library_shared { |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 652 | name: "foo", |
| 653 | conlyflags: [ "-include header.h"], |
| 654 | cflags: ["-include header.h"], |
| 655 | cppflags: ["-include header.h"], |
| 656 | version_script: "version_script", |
| 657 | include_build_directory: false, |
| 658 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 659 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 660 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Alix | 1be00d4 | 2022-05-16 22:56:04 +0000 | [diff] [blame] | 661 | "additional_linker_inputs": `["version_script"]`, |
| 662 | "conlyflags": `[ |
| 663 | "-include", |
| 664 | "header.h", |
| 665 | ]`, |
| 666 | "copts": `[ |
| 667 | "-include", |
| 668 | "header.h", |
| 669 | ]`, |
| 670 | "cppflags": `[ |
| 671 | "-include", |
| 672 | "header.h", |
| 673 | ]`, |
| 674 | "linkopts": `["-Wl,--version-script,$(location version_script)"]`, |
| 675 | }), |
| 676 | }, |
| 677 | }) |
| 678 | } |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 679 | |
| 680 | func TestCCLibrarySharedRuntimeDeps(t *testing.T) { |
| 681 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 682 | Blueprint: `cc_library_shared { |
| 683 | name: "bar", |
| 684 | } |
| 685 | |
| 686 | cc_library_shared { |
| 687 | name: "foo", |
| 688 | runtime_libs: ["foo"], |
| 689 | }`, |
| 690 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 691 | MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{ |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 692 | "local_includes": `["."]`, |
| 693 | }), |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 694 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 695 | "runtime_deps": `[":foo"]`, |
| 696 | "local_includes": `["."]`, |
| 697 | }), |
| 698 | }, |
| 699 | }) |
| 700 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 701 | |
| 702 | func TestCcLibrarySharedEmptySuffix(t *testing.T) { |
| 703 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 704 | Description: "cc_library_shared with empty suffix", |
| 705 | Filesystem: map[string]string{ |
| 706 | "foo.c": "", |
| 707 | }, |
| 708 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 709 | cc_library_shared { |
| 710 | name: "foo_shared", |
| 711 | suffix: "", |
| 712 | srcs: ["foo.c"], |
| 713 | include_build_directory: false, |
| 714 | }`, |
| 715 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 716 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 717 | "srcs_c": `["foo.c"]`, |
| 718 | "suffix": `""`, |
| 719 | }), |
| 720 | }, |
| 721 | }) |
| 722 | } |
| 723 | |
| 724 | func TestCcLibrarySharedSuffix(t *testing.T) { |
| 725 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 726 | Description: "cc_library_shared with suffix", |
| 727 | Filesystem: map[string]string{ |
| 728 | "foo.c": "", |
| 729 | }, |
| 730 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 731 | cc_library_shared { |
| 732 | name: "foo_shared", |
| 733 | suffix: "-suf", |
| 734 | srcs: ["foo.c"], |
| 735 | include_build_directory: false, |
| 736 | }`, |
| 737 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 738 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 739 | "srcs_c": `["foo.c"]`, |
| 740 | "suffix": `"-suf"`, |
| 741 | }), |
| 742 | }, |
| 743 | }) |
| 744 | } |
| 745 | |
| 746 | func TestCcLibrarySharedArchVariantSuffix(t *testing.T) { |
| 747 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 748 | Description: "cc_library_shared with arch-variant suffix", |
| 749 | Filesystem: map[string]string{ |
| 750 | "foo.c": "", |
| 751 | }, |
| 752 | Blueprint: soongCcLibrarySharedPreamble + ` |
| 753 | cc_library_shared { |
| 754 | name: "foo_shared", |
| 755 | arch: { |
| 756 | arm64: { suffix: "-64" }, |
| 757 | arm: { suffix: "-32" }, |
| 758 | }, |
| 759 | srcs: ["foo.c"], |
| 760 | include_build_directory: false, |
| 761 | }`, |
| 762 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 763 | MakeBazelTarget("cc_library_shared", "foo_shared", AttrNameToString{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 764 | "srcs_c": `["foo.c"]`, |
| 765 | "suffix": `select({ |
| 766 | "//build/bazel/platforms/arch:arm": "-32", |
| 767 | "//build/bazel/platforms/arch:arm64": "-64", |
| 768 | "//conditions:default": None, |
| 769 | })`, |
| 770 | }), |
| 771 | }, |
| 772 | }) |
| 773 | } |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 774 | |
| 775 | func TestCcLibrarySharedWithSyspropSrcs(t *testing.T) { |
| 776 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 777 | Description: "cc_library_shared with sysprop sources", |
| 778 | Blueprint: ` |
| 779 | cc_library_shared { |
| 780 | name: "foo", |
| 781 | srcs: [ |
| 782 | "bar.sysprop", |
| 783 | "baz.sysprop", |
| 784 | "blah.cpp", |
| 785 | ], |
| 786 | min_sdk_version: "5", |
| 787 | }`, |
| 788 | ExpectedBazelTargets: []string{ |
| 789 | MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{ |
| 790 | "srcs": `[ |
| 791 | "bar.sysprop", |
| 792 | "baz.sysprop", |
| 793 | ]`, |
| 794 | }), |
| 795 | MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{ |
| 796 | "dep": `":foo_sysprop_library"`, |
| 797 | "min_sdk_version": `"5"`, |
| 798 | }), |
| 799 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 800 | "srcs": `["blah.cpp"]`, |
| 801 | "local_includes": `["."]`, |
| 802 | "min_sdk_version": `"5"`, |
| 803 | "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`, |
| 804 | }), |
| 805 | }, |
| 806 | }) |
| 807 | } |
| 808 | |
| 809 | func TestCcLibrarySharedWithSyspropSrcsSomeConfigs(t *testing.T) { |
| 810 | runCcLibrarySharedTestCase(t, Bp2buildTestCase{ |
| 811 | Description: "cc_library_shared with sysprop sources in some configs but not others", |
| 812 | Blueprint: ` |
| 813 | cc_library_shared { |
| 814 | name: "foo", |
| 815 | srcs: [ |
| 816 | "blah.cpp", |
| 817 | ], |
| 818 | target: { |
| 819 | android: { |
| 820 | srcs: ["bar.sysprop"], |
| 821 | }, |
| 822 | }, |
| 823 | min_sdk_version: "5", |
| 824 | }`, |
| 825 | ExpectedBazelTargets: []string{ |
| 826 | MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{ |
| 827 | "srcs": `select({ |
| 828 | "//build/bazel/platforms/os:android": ["bar.sysprop"], |
| 829 | "//conditions:default": [], |
| 830 | })`, |
| 831 | }), |
| 832 | MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{ |
| 833 | "dep": `":foo_sysprop_library"`, |
| 834 | "min_sdk_version": `"5"`, |
| 835 | }), |
| 836 | MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ |
| 837 | "srcs": `["blah.cpp"]`, |
| 838 | "local_includes": `["."]`, |
| 839 | "min_sdk_version": `"5"`, |
| 840 | "whole_archive_deps": `select({ |
| 841 | "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"], |
| 842 | "//conditions:default": [], |
| 843 | })`, |
| 844 | }), |
| 845 | }, |
| 846 | }) |
| 847 | } |