Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -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 ( |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 18 | "fmt" |
| 19 | "strings" |
| 20 | "testing" |
Yu Liu | fc60316 | 2022-03-01 15:44:08 -0800 | [diff] [blame] | 21 | |
| 22 | "android/soong/android" |
| 23 | "android/soong/cc" |
| 24 | "android/soong/genrule" |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 25 | ) |
| 26 | |
| 27 | const ( |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 28 | ccBinaryTypePlaceHolder = "{rule_name}" |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 29 | ) |
| 30 | |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 31 | type testBazelTarget struct { |
| 32 | typ string |
| 33 | name string |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 34 | attrs AttrNameToString |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 35 | } |
| 36 | |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 37 | func generateBazelTargetsForTest(targets []testBazelTarget, hod android.HostOrDeviceSupported) []string { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 38 | ret := make([]string, 0, len(targets)) |
| 39 | for _, t := range targets { |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 40 | attrs := t.attrs.clone() |
| 41 | ret = append(ret, makeBazelTargetHostOrDevice(t.typ, t.name, attrs, hod)) |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 42 | } |
| 43 | return ret |
| 44 | } |
| 45 | |
| 46 | type ccBinaryBp2buildTestCase struct { |
| 47 | description string |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 48 | filesystem map[string]string |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 49 | blueprint string |
| 50 | targets []testBazelTarget |
| 51 | } |
| 52 | |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 53 | func registerCcBinaryModuleTypes(ctx android.RegistrationContext) { |
| 54 | cc.RegisterCCBuildComponents(ctx) |
| 55 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
| 56 | ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) |
| 57 | ctx.RegisterModuleType("cc_library", cc.LibraryFactory) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 58 | ctx.RegisterModuleType("genrule", genrule.GenRuleFactory) |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 59 | } |
| 60 | |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 61 | var binaryReplacer = strings.NewReplacer(ccBinaryTypePlaceHolder, "cc_binary") |
| 62 | var hostBinaryReplacer = strings.NewReplacer(ccBinaryTypePlaceHolder, "cc_binary_host") |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 63 | |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 64 | func runCcBinaryTests(t *testing.T, tc ccBinaryBp2buildTestCase) { |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 65 | t.Helper() |
| 66 | runCcBinaryTestCase(t, tc) |
| 67 | runCcHostBinaryTestCase(t, tc) |
| 68 | } |
| 69 | |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 70 | func runCcBinaryTestCase(t *testing.T, testCase ccBinaryBp2buildTestCase) { |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 71 | t.Helper() |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 72 | moduleTypeUnderTest := "cc_binary" |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 73 | |
| 74 | description := fmt.Sprintf("%s %s", moduleTypeUnderTest, testCase.description) |
| 75 | t.Run(description, func(t *testing.T) { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 76 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 77 | RunBp2BuildTestCase(t, registerCcBinaryModuleTypes, Bp2buildTestCase{ |
| 78 | ExpectedBazelTargets: generateBazelTargetsForTest(testCase.targets, android.DeviceSupported), |
| 79 | ModuleTypeUnderTest: moduleTypeUnderTest, |
| 80 | ModuleTypeUnderTestFactory: cc.BinaryFactory, |
| 81 | Description: description, |
| 82 | Blueprint: binaryReplacer.Replace(testCase.blueprint), |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 83 | Filesystem: testCase.filesystem, |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 84 | }) |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 85 | }) |
| 86 | } |
| 87 | |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 88 | func runCcHostBinaryTestCase(t *testing.T, testCase ccBinaryBp2buildTestCase) { |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 89 | t.Helper() |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 90 | moduleTypeUnderTest := "cc_binary_host" |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 91 | description := fmt.Sprintf("%s %s", moduleTypeUnderTest, testCase.description) |
| 92 | t.Run(description, func(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 93 | RunBp2BuildTestCase(t, registerCcBinaryModuleTypes, Bp2buildTestCase{ |
| 94 | ExpectedBazelTargets: generateBazelTargetsForTest(testCase.targets, android.HostSupported), |
| 95 | ModuleTypeUnderTest: moduleTypeUnderTest, |
| 96 | ModuleTypeUnderTestFactory: cc.BinaryHostFactory, |
| 97 | Description: description, |
| 98 | Blueprint: hostBinaryReplacer.Replace(testCase.blueprint), |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 99 | Filesystem: testCase.filesystem, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 100 | }) |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 101 | }) |
| 102 | } |
| 103 | |
| 104 | func TestBasicCcBinary(t *testing.T) { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 105 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 106 | description: "basic -- properties -> attrs with little/no transformation", |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 107 | filesystem: map[string]string{ |
| 108 | soongCcVersionLibBpPath: soongCcVersionLibBp, |
| 109 | }, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 110 | blueprint: ` |
| 111 | {rule_name} { |
| 112 | name: "foo", |
| 113 | srcs: ["a.cc"], |
| 114 | local_include_dirs: ["dir"], |
| 115 | include_dirs: ["absolute_dir"], |
| 116 | cflags: ["-Dcopt"], |
| 117 | cppflags: ["-Dcppflag"], |
| 118 | conlyflags: ["-Dconlyflag"], |
| 119 | asflags: ["-Dasflag"], |
| 120 | ldflags: ["ld-flag"], |
| 121 | rtti: true, |
| 122 | strip: { |
| 123 | all: true, |
| 124 | keep_symbols: true, |
| 125 | keep_symbols_and_debug_frame: true, |
| 126 | keep_symbols_list: ["symbol"], |
| 127 | none: true, |
| 128 | }, |
Yu Liu | fc60316 | 2022-03-01 15:44:08 -0800 | [diff] [blame] | 129 | sdk_version: "current", |
| 130 | min_sdk_version: "29", |
Yu Liu | a79c946 | 2022-03-22 16:35:22 -0700 | [diff] [blame] | 131 | use_version_lib: true, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 132 | } |
| 133 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 134 | targets: []testBazelTarget{ |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 135 | {"cc_binary", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 136 | "absolute_includes": `["absolute_dir"]`, |
| 137 | "asflags": `["-Dasflag"]`, |
| 138 | "conlyflags": `["-Dconlyflag"]`, |
| 139 | "copts": `["-Dcopt"]`, |
| 140 | "cppflags": `["-Dcppflag"]`, |
| 141 | "linkopts": `["ld-flag"]`, |
| 142 | "local_includes": `[ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 143 | "dir", |
| 144 | ".", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 145 | ]`, |
| 146 | "rtti": `True`, |
| 147 | "srcs": `["a.cc"]`, |
| 148 | "strip": `{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 149 | "all": True, |
| 150 | "keep_symbols": True, |
| 151 | "keep_symbols_and_debug_frame": True, |
| 152 | "keep_symbols_list": ["symbol"], |
| 153 | "none": True, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 154 | }`, |
Liz Kammer | baced71 | 2022-09-16 09:01:29 -0400 | [diff] [blame] | 155 | "sdk_version": `"current"`, |
| 156 | "min_sdk_version": `"29"`, |
| 157 | "use_version_lib": `True`, |
| 158 | "whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 159 | }, |
| 160 | }, |
| 161 | }, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 162 | }) |
| 163 | } |
| 164 | |
| 165 | func TestCcBinaryWithSharedLdflagDisableFeature(t *testing.T) { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 166 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 167 | description: `ldflag "-shared" disables static_flag feature`, |
| 168 | blueprint: ` |
| 169 | {rule_name} { |
| 170 | name: "foo", |
| 171 | ldflags: ["-shared"], |
| 172 | include_build_directory: false, |
| 173 | } |
| 174 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 175 | targets: []testBazelTarget{ |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 176 | {"cc_binary", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 177 | "features": `["-static_flag"]`, |
| 178 | "linkopts": `["-shared"]`, |
| 179 | }, |
| 180 | }, |
| 181 | }, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 182 | }) |
| 183 | } |
| 184 | |
| 185 | func TestCcBinaryWithLinkStatic(t *testing.T) { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 186 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 187 | description: "link static", |
| 188 | blueprint: ` |
| 189 | {rule_name} { |
| 190 | name: "foo", |
| 191 | static_executable: true, |
| 192 | include_build_directory: false, |
| 193 | } |
| 194 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 195 | targets: []testBazelTarget{ |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 196 | {"cc_binary", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 197 | "linkshared": `False`, |
| 198 | }, |
| 199 | }, |
| 200 | }, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 201 | }) |
| 202 | } |
| 203 | |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 204 | func TestCcBinaryVersionScriptAndDynamicList(t *testing.T) { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 205 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 206 | description: `version script and dynamic list`, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 207 | blueprint: ` |
| 208 | {rule_name} { |
| 209 | name: "foo", |
| 210 | include_build_directory: false, |
| 211 | version_script: "vs", |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 212 | dynamic_list: "dynamic.list", |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 213 | } |
| 214 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 215 | targets: []testBazelTarget{ |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 216 | {"cc_binary", "foo", AttrNameToString{ |
Trevor Radcliffe | 82dd855 | 2022-10-03 20:27:27 +0000 | [diff] [blame] | 217 | "additional_linker_inputs": `[ |
| 218 | "vs", |
| 219 | "dynamic.list", |
| 220 | ]`, |
| 221 | "linkopts": `[ |
| 222 | "-Wl,--version-script,$(location vs)", |
| 223 | "-Wl,--dynamic-list,$(location dynamic.list)", |
| 224 | ]`, |
Trevor Radcliffe | f06dd91 | 2023-05-19 14:51:41 +0000 | [diff] [blame] | 225 | "features": `["android_cfi_exports_map"]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 226 | }, |
| 227 | }, |
| 228 | }, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 229 | }) |
| 230 | } |
| 231 | |
Trevor Radcliffe | ea6a45d | 2022-09-20 18:58:01 +0000 | [diff] [blame] | 232 | func TestCcBinaryLdflagsSplitBySpaceExceptSoongAdded(t *testing.T) { |
| 233 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
| 234 | description: "ldflags are split by spaces except for the ones added by soong (version script and dynamic list)", |
| 235 | blueprint: ` |
| 236 | {rule_name} { |
| 237 | name: "foo", |
| 238 | ldflags: [ |
| 239 | "--nospace_flag", |
| 240 | "-z spaceflag", |
| 241 | ], |
| 242 | version_script: "version_script", |
| 243 | dynamic_list: "dynamic.list", |
| 244 | include_build_directory: false, |
| 245 | } |
| 246 | `, |
| 247 | targets: []testBazelTarget{ |
| 248 | {"cc_binary", "foo", AttrNameToString{ |
| 249 | "additional_linker_inputs": `[ |
| 250 | "version_script", |
| 251 | "dynamic.list", |
| 252 | ]`, |
Trevor Radcliffe | f06dd91 | 2023-05-19 14:51:41 +0000 | [diff] [blame] | 253 | "features": `["android_cfi_exports_map"]`, |
Trevor Radcliffe | ea6a45d | 2022-09-20 18:58:01 +0000 | [diff] [blame] | 254 | "linkopts": `[ |
| 255 | "--nospace_flag", |
| 256 | "-z", |
| 257 | "spaceflag", |
| 258 | "-Wl,--version-script,$(location version_script)", |
| 259 | "-Wl,--dynamic-list,$(location dynamic.list)", |
| 260 | ]`, |
| 261 | }}}, |
| 262 | }) |
| 263 | } |
| 264 | |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 265 | func TestCcBinarySplitSrcsByLang(t *testing.T) { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 266 | runCcHostBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 267 | description: "split srcs by lang", |
| 268 | blueprint: ` |
| 269 | {rule_name} { |
| 270 | name: "foo", |
| 271 | srcs: [ |
| 272 | "asonly.S", |
| 273 | "conly.c", |
| 274 | "cpponly.cpp", |
| 275 | ":fg_foo", |
| 276 | ], |
| 277 | include_build_directory: false, |
| 278 | } |
Sam Delmerico | 130d75b | 2023-08-31 00:51:44 +0000 | [diff] [blame] | 279 | ` + SimpleModuleDoNotConvertBp2build("filegroup", "fg_foo"), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 280 | targets: []testBazelTarget{ |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 281 | {"cc_binary", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 282 | "srcs": `[ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 283 | "cpponly.cpp", |
| 284 | ":fg_foo_cpp_srcs", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 285 | ]`, |
| 286 | "srcs_as": `[ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 287 | "asonly.S", |
| 288 | ":fg_foo_as_srcs", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 289 | ]`, |
| 290 | "srcs_c": `[ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 291 | "conly.c", |
| 292 | ":fg_foo_c_srcs", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 293 | ]`, |
| 294 | }, |
| 295 | }, |
| 296 | }, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 297 | }) |
| 298 | } |
| 299 | |
| 300 | func TestCcBinaryDoNotDistinguishBetweenDepsAndImplementationDeps(t *testing.T) { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 301 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 302 | description: "no implementation deps", |
| 303 | blueprint: ` |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 304 | genrule { |
| 305 | name: "generated_hdr", |
| 306 | cmd: "nothing to see here", |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 307 | bazel_module: { bp2build_available: false }, |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | genrule { |
| 311 | name: "export_generated_hdr", |
| 312 | cmd: "nothing to see here", |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 313 | bazel_module: { bp2build_available: false }, |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 314 | } |
| 315 | |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 316 | {rule_name} { |
| 317 | name: "foo", |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 318 | srcs: ["foo.cpp"], |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 319 | shared_libs: ["implementation_shared_dep", "shared_dep"], |
| 320 | export_shared_lib_headers: ["shared_dep"], |
| 321 | static_libs: ["implementation_static_dep", "static_dep"], |
| 322 | export_static_lib_headers: ["static_dep", "whole_static_dep"], |
| 323 | whole_static_libs: ["not_explicitly_exported_whole_static_dep", "whole_static_dep"], |
| 324 | include_build_directory: false, |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 325 | generated_headers: ["generated_hdr", "export_generated_hdr"], |
| 326 | export_generated_headers: ["export_generated_hdr"], |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 327 | } |
| 328 | ` + |
Sam Delmerico | 130d75b | 2023-08-31 00:51:44 +0000 | [diff] [blame] | 329 | SimpleModuleDoNotConvertBp2build("cc_library_static", "static_dep") + |
| 330 | SimpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep") + |
| 331 | SimpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep") + |
| 332 | SimpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep") + |
| 333 | SimpleModuleDoNotConvertBp2build("cc_library", "shared_dep") + |
| 334 | SimpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep"), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 335 | targets: []testBazelTarget{ |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 336 | {"cc_binary", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 337 | "deps": `[ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 338 | ":implementation_static_dep", |
| 339 | ":static_dep", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 340 | ]`, |
| 341 | "dynamic_deps": `[ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 342 | ":implementation_shared_dep", |
| 343 | ":shared_dep", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 344 | ]`, |
| 345 | "srcs": `[ |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 346 | "foo.cpp", |
| 347 | ":generated_hdr", |
| 348 | ":export_generated_hdr", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 349 | ]`, |
| 350 | "whole_archive_deps": `[ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 351 | ":not_explicitly_exported_whole_static_dep", |
| 352 | ":whole_static_dep", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 353 | ]`, |
Liz Kammer | 1263d9b | 2021-12-10 14:28:20 -0500 | [diff] [blame] | 354 | "local_includes": `["."]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 355 | }, |
| 356 | }, |
| 357 | }, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 358 | }) |
| 359 | } |
| 360 | |
| 361 | func TestCcBinaryNocrtTests(t *testing.T) { |
| 362 | baseTestCases := []struct { |
| 363 | description string |
| 364 | soongProperty string |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 365 | bazelAttr AttrNameToString |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 366 | }{ |
| 367 | { |
| 368 | description: "nocrt: true", |
| 369 | soongProperty: `nocrt: true,`, |
Alex Márquez Pérez MuñÃz DÃaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 370 | bazelAttr: AttrNameToString{"features": `["-link_crt"]`}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 371 | }, |
| 372 | { |
| 373 | description: "nocrt: false", |
| 374 | soongProperty: `nocrt: false,`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 375 | bazelAttr: AttrNameToString{}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 376 | }, |
| 377 | { |
| 378 | description: "nocrt: not set", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 379 | bazelAttr: AttrNameToString{}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 380 | }, |
| 381 | } |
| 382 | |
| 383 | baseBlueprint := `{rule_name} { |
| 384 | name: "foo",%s |
| 385 | include_build_directory: false, |
| 386 | } |
| 387 | ` |
| 388 | |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 389 | for _, btc := range baseTestCases { |
| 390 | prop := btc.soongProperty |
| 391 | if len(prop) > 0 { |
| 392 | prop = "\n" + prop |
| 393 | } |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 394 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 395 | description: btc.description, |
| 396 | blueprint: fmt.Sprintf(baseBlueprint, prop), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 397 | targets: []testBazelTarget{ |
| 398 | {"cc_binary", "foo", btc.bazelAttr}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 399 | }, |
| 400 | }) |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | func TestCcBinaryNo_libcrtTests(t *testing.T) { |
| 405 | baseTestCases := []struct { |
| 406 | description string |
| 407 | soongProperty string |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 408 | bazelAttr AttrNameToString |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 409 | }{ |
| 410 | { |
| 411 | description: "no_libcrt: true", |
| 412 | soongProperty: `no_libcrt: true,`, |
Alex Márquez Pérez MuñÃz DÃaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 413 | bazelAttr: AttrNameToString{"features": `["-use_libcrt"]`}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 414 | }, |
| 415 | { |
| 416 | description: "no_libcrt: false", |
| 417 | soongProperty: `no_libcrt: false,`, |
Alex Márquez Pérez MuñÃz DÃaz Puras Thaureaux | 01ec55e | 2023-01-30 22:53:04 +0000 | [diff] [blame] | 418 | bazelAttr: AttrNameToString{}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 419 | }, |
| 420 | { |
| 421 | description: "no_libcrt: not set", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 422 | bazelAttr: AttrNameToString{}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 423 | }, |
| 424 | } |
| 425 | |
| 426 | baseBlueprint := `{rule_name} { |
| 427 | name: "foo",%s |
| 428 | include_build_directory: false, |
| 429 | } |
| 430 | ` |
| 431 | |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 432 | for _, btc := range baseTestCases { |
| 433 | prop := btc.soongProperty |
| 434 | if len(prop) > 0 { |
| 435 | prop = "\n" + prop |
| 436 | } |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 437 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 438 | description: btc.description, |
| 439 | blueprint: fmt.Sprintf(baseBlueprint, prop), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 440 | targets: []testBazelTarget{ |
| 441 | {"cc_binary", "foo", btc.bazelAttr}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 442 | }, |
| 443 | }) |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | func TestCcBinaryPropertiesToFeatures(t *testing.T) { |
| 448 | baseTestCases := []struct { |
| 449 | description string |
| 450 | soongProperty string |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 451 | bazelAttr AttrNameToString |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 452 | }{ |
| 453 | { |
| 454 | description: "pack_relocation: true", |
| 455 | soongProperty: `pack_relocations: true,`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 456 | bazelAttr: AttrNameToString{}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 457 | }, |
| 458 | { |
| 459 | description: "pack_relocations: false", |
| 460 | soongProperty: `pack_relocations: false,`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 461 | bazelAttr: AttrNameToString{"features": `["disable_pack_relocations"]`}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 462 | }, |
| 463 | { |
| 464 | description: "pack_relocations: not set", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 465 | bazelAttr: AttrNameToString{}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 466 | }, |
| 467 | { |
| 468 | description: "pack_relocation: true", |
| 469 | soongProperty: `allow_undefined_symbols: true,`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 470 | bazelAttr: AttrNameToString{"features": `["-no_undefined_symbols"]`}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 471 | }, |
| 472 | { |
| 473 | description: "allow_undefined_symbols: false", |
| 474 | soongProperty: `allow_undefined_symbols: false,`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 475 | bazelAttr: AttrNameToString{}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 476 | }, |
| 477 | { |
| 478 | description: "allow_undefined_symbols: not set", |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 479 | bazelAttr: AttrNameToString{}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 480 | }, |
| 481 | } |
| 482 | |
| 483 | baseBlueprint := `{rule_name} { |
| 484 | name: "foo",%s |
| 485 | include_build_directory: false, |
| 486 | } |
| 487 | ` |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 488 | for _, btc := range baseTestCases { |
| 489 | prop := btc.soongProperty |
| 490 | if len(prop) > 0 { |
| 491 | prop = "\n" + prop |
| 492 | } |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 493 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 494 | description: btc.description, |
| 495 | blueprint: fmt.Sprintf(baseBlueprint, prop), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 496 | targets: []testBazelTarget{ |
| 497 | {"cc_binary", "foo", btc.bazelAttr}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 498 | }, |
| 499 | }) |
| 500 | } |
| 501 | } |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 502 | |
| 503 | func TestCcBinarySharedProto(t *testing.T) { |
| 504 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
| 505 | blueprint: soongCcProtoLibraries + `{rule_name} { |
| 506 | name: "foo", |
| 507 | srcs: ["foo.proto"], |
| 508 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 509 | }, |
| 510 | include_build_directory: false, |
| 511 | }`, |
| 512 | targets: []testBazelTarget{ |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 513 | {"proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 514 | "srcs": `["foo.proto"]`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 515 | }}, {"cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 516 | "deps": `[":foo_proto"]`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 517 | }}, {"cc_binary", "foo", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 518 | "dynamic_deps": `[":libprotobuf-cpp-lite"]`, |
| 519 | "whole_archive_deps": `[":foo_cc_proto_lite"]`, |
| 520 | }}, |
| 521 | }, |
| 522 | }) |
| 523 | } |
| 524 | |
| 525 | func TestCcBinaryStaticProto(t *testing.T) { |
| 526 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
| 527 | blueprint: soongCcProtoLibraries + `{rule_name} { |
| 528 | name: "foo", |
| 529 | srcs: ["foo.proto"], |
| 530 | static_executable: true, |
| 531 | proto: { |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 532 | }, |
| 533 | include_build_directory: false, |
| 534 | }`, |
| 535 | targets: []testBazelTarget{ |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 536 | {"proto_library", "foo_proto", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 537 | "srcs": `["foo.proto"]`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 538 | }}, {"cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 539 | "deps": `[":foo_proto"]`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 540 | }}, {"cc_binary", "foo", AttrNameToString{ |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 541 | "deps": `[":libprotobuf-cpp-lite"]`, |
| 542 | "whole_archive_deps": `[":foo_cc_proto_lite"]`, |
| 543 | "linkshared": `False`, |
| 544 | }}, |
| 545 | }, |
| 546 | }) |
| 547 | } |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 548 | |
| 549 | func TestCcBinaryConvertLex(t *testing.T) { |
| 550 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
| 551 | description: `.l and .ll sources converted to .c and .cc`, |
| 552 | blueprint: ` |
| 553 | {rule_name} { |
| 554 | name: "foo", |
| 555 | srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"], |
| 556 | lex: { flags: ["--foo_opt", "--bar_opt"] }, |
| 557 | include_build_directory: false, |
| 558 | } |
| 559 | `, |
| 560 | targets: []testBazelTarget{ |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 561 | {"genlex", "foo_genlex_l", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 562 | "srcs": `[ |
| 563 | "foo1.l", |
| 564 | "foo2.l", |
| 565 | ]`, |
| 566 | "lexopts": `[ |
| 567 | "--foo_opt", |
| 568 | "--bar_opt", |
| 569 | ]`, |
| 570 | }}, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 571 | {"genlex", "foo_genlex_ll", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 572 | "srcs": `[ |
| 573 | "bar1.ll", |
| 574 | "bar2.ll", |
| 575 | ]`, |
| 576 | "lexopts": `[ |
| 577 | "--foo_opt", |
| 578 | "--bar_opt", |
| 579 | ]`, |
| 580 | }}, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 581 | {"cc_binary", "foo", AttrNameToString{ |
Trevor Radcliffe | ef9c900 | 2022-05-13 20:55:35 +0000 | [diff] [blame] | 582 | "srcs": `[ |
| 583 | "bar.cc", |
| 584 | ":foo_genlex_ll", |
| 585 | ]`, |
| 586 | "srcs_c": `[ |
| 587 | "foo.c", |
| 588 | ":foo_genlex_l", |
| 589 | ]`, |
| 590 | }}, |
| 591 | }, |
| 592 | }) |
| 593 | } |
Cole Faust | 6b29f59 | 2022-08-09 09:50:56 -0700 | [diff] [blame] | 594 | |
| 595 | func TestCcBinaryRuntimeLibs(t *testing.T) { |
| 596 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
| 597 | description: "cc_binary with runtime libs", |
| 598 | blueprint: ` |
| 599 | cc_library { |
| 600 | name: "bar", |
| 601 | srcs: ["b.cc"], |
| 602 | } |
| 603 | |
| 604 | {rule_name} { |
| 605 | name: "foo", |
| 606 | srcs: ["a.cc"], |
| 607 | runtime_libs: ["bar"], |
| 608 | } |
| 609 | `, |
| 610 | targets: []testBazelTarget{ |
| 611 | {"cc_library_static", "bar_bp2build_cc_library_static", AttrNameToString{ |
| 612 | "local_includes": `["."]`, |
| 613 | "srcs": `["b.cc"]`, |
| 614 | "target_compatible_with": `["//build/bazel/platforms/os:android"]`, |
| 615 | }, |
| 616 | }, |
| 617 | {"cc_library_shared", "bar", AttrNameToString{ |
| 618 | "local_includes": `["."]`, |
| 619 | "srcs": `["b.cc"]`, |
| 620 | "target_compatible_with": `["//build/bazel/platforms/os:android"]`, |
| 621 | }, |
| 622 | }, |
| 623 | {"cc_binary", "foo", AttrNameToString{ |
| 624 | "local_includes": `["."]`, |
| 625 | "srcs": `["a.cc"]`, |
| 626 | "runtime_deps": `[":bar"]`, |
| 627 | }, |
| 628 | }, |
| 629 | }, |
| 630 | }) |
| 631 | } |
Cole Faust | 5fa4e96 | 2022-08-22 14:31:04 -0700 | [diff] [blame] | 632 | |
| 633 | func TestCcBinaryWithInstructionSet(t *testing.T) { |
| 634 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
| 635 | description: "instruction set", |
| 636 | blueprint: ` |
| 637 | {rule_name} { |
| 638 | name: "foo", |
| 639 | arch: { |
| 640 | arm: { |
| 641 | instruction_set: "arm", |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | `, |
| 646 | targets: []testBazelTarget{ |
| 647 | {"cc_binary", "foo", AttrNameToString{ |
| 648 | "features": `select({ |
Trevor Radcliffe | 5f0c2ac | 2023-05-15 18:00:59 +0000 | [diff] [blame] | 649 | "//build/bazel/platforms/arch:arm": ["arm_isa_arm"], |
Cole Faust | 5fa4e96 | 2022-08-22 14:31:04 -0700 | [diff] [blame] | 650 | "//conditions:default": [], |
| 651 | })`, |
| 652 | "local_includes": `["."]`, |
Alex Márquez Pérez MuñÃz DÃaz Púras Thaureaux | a56e970 | 2022-02-23 18:39:59 -0500 | [diff] [blame] | 653 | }}, |
| 654 | }, |
| 655 | }) |
| 656 | } |
| 657 | |
| 658 | func TestCcBinaryEmptySuffix(t *testing.T) { |
| 659 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
| 660 | description: "binary with empty suffix", |
| 661 | blueprint: ` |
| 662 | {rule_name} { |
| 663 | name: "foo", |
| 664 | suffix: "", |
| 665 | }`, |
| 666 | targets: []testBazelTarget{ |
| 667 | {"cc_binary", "foo", AttrNameToString{ |
| 668 | "local_includes": `["."]`, |
| 669 | "suffix": `""`, |
| 670 | }}, |
| 671 | }, |
| 672 | }) |
| 673 | } |
| 674 | |
| 675 | func TestCcBinarySuffix(t *testing.T) { |
| 676 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
| 677 | description: "binary with suffix", |
| 678 | blueprint: ` |
| 679 | {rule_name} { |
| 680 | name: "foo", |
| 681 | suffix: "-suf", |
| 682 | } |
| 683 | `, |
| 684 | targets: []testBazelTarget{ |
| 685 | {"cc_binary", "foo", AttrNameToString{ |
| 686 | "local_includes": `["."]`, |
| 687 | "suffix": `"-suf"`, |
| 688 | }}, |
| 689 | }, |
| 690 | }) |
| 691 | } |
| 692 | |
| 693 | func TestCcArchVariantBinarySuffix(t *testing.T) { |
| 694 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
| 695 | description: "binary with suffix", |
| 696 | blueprint: ` |
| 697 | {rule_name} { |
| 698 | name: "foo", |
| 699 | arch: { |
| 700 | arm64: { suffix: "-64" }, |
| 701 | arm: { suffix: "-32" }, |
| 702 | }, |
| 703 | } |
| 704 | `, |
| 705 | targets: []testBazelTarget{ |
| 706 | {"cc_binary", "foo", AttrNameToString{ |
| 707 | "local_includes": `["."]`, |
| 708 | "suffix": `select({ |
| 709 | "//build/bazel/platforms/arch:arm": "-32", |
| 710 | "//build/bazel/platforms/arch:arm64": "-64", |
| 711 | "//conditions:default": None, |
| 712 | })`, |
| 713 | }}, |
Cole Faust | 5fa4e96 | 2022-08-22 14:31:04 -0700 | [diff] [blame] | 714 | }, |
| 715 | }) |
| 716 | } |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 717 | |
| 718 | func TestCcBinaryWithSyspropSrcs(t *testing.T) { |
| 719 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 720 | description: "cc_binary with sysprop sources", |
| 721 | blueprint: ` |
| 722 | {rule_name} { |
| 723 | name: "foo", |
| 724 | srcs: [ |
| 725 | "bar.sysprop", |
| 726 | "baz.sysprop", |
| 727 | "blah.cpp", |
| 728 | ], |
| 729 | min_sdk_version: "5", |
| 730 | }`, |
| 731 | targets: []testBazelTarget{ |
| 732 | {"sysprop_library", "foo_sysprop_library", AttrNameToString{ |
| 733 | "srcs": `[ |
| 734 | "bar.sysprop", |
| 735 | "baz.sysprop", |
| 736 | ]`, |
| 737 | }}, |
| 738 | {"cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{ |
| 739 | "dep": `":foo_sysprop_library"`, |
| 740 | "min_sdk_version": `"5"`, |
| 741 | }}, |
| 742 | {"cc_binary", "foo", AttrNameToString{ |
| 743 | "srcs": `["blah.cpp"]`, |
| 744 | "local_includes": `["."]`, |
| 745 | "min_sdk_version": `"5"`, |
| 746 | "whole_archive_deps": `[":foo_cc_sysprop_library_static"]`, |
| 747 | }}, |
| 748 | }, |
| 749 | }) |
| 750 | } |
| 751 | |
| 752 | func TestCcBinaryWithSyspropSrcsSomeConfigs(t *testing.T) { |
| 753 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 754 | description: "cc_binary with sysprop sources in some configs but not others", |
| 755 | blueprint: ` |
| 756 | {rule_name} { |
| 757 | name: "foo", |
| 758 | srcs: [ |
| 759 | "blah.cpp", |
| 760 | ], |
| 761 | target: { |
| 762 | android: { |
| 763 | srcs: ["bar.sysprop"], |
| 764 | }, |
| 765 | }, |
| 766 | min_sdk_version: "5", |
| 767 | }`, |
| 768 | targets: []testBazelTarget{ |
| 769 | {"sysprop_library", "foo_sysprop_library", AttrNameToString{ |
| 770 | "srcs": `select({ |
| 771 | "//build/bazel/platforms/os:android": ["bar.sysprop"], |
| 772 | "//conditions:default": [], |
| 773 | })`, |
| 774 | }}, |
| 775 | {"cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{ |
| 776 | "dep": `":foo_sysprop_library"`, |
| 777 | "min_sdk_version": `"5"`, |
| 778 | }}, |
| 779 | {"cc_binary", "foo", AttrNameToString{ |
| 780 | "srcs": `["blah.cpp"]`, |
| 781 | "local_includes": `["."]`, |
| 782 | "min_sdk_version": `"5"`, |
| 783 | "whole_archive_deps": `select({ |
| 784 | "//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"], |
| 785 | "//conditions:default": [], |
| 786 | })`, |
| 787 | }}, |
| 788 | }, |
| 789 | }) |
| 790 | } |
Trevor Radcliffe | db7e026 | 2022-10-28 16:48:18 +0000 | [diff] [blame] | 791 | |
| 792 | func TestCcBinaryWithIntegerOverflowProperty(t *testing.T) { |
| 793 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 794 | description: "cc_binary with integer overflow property specified", |
| 795 | blueprint: ` |
| 796 | {rule_name} { |
| 797 | name: "foo", |
| 798 | sanitize: { |
| 799 | integer_overflow: true, |
| 800 | }, |
| 801 | }`, |
| 802 | targets: []testBazelTarget{ |
| 803 | {"cc_binary", "foo", AttrNameToString{ |
| 804 | "local_includes": `["."]`, |
| 805 | "features": `["ubsan_integer_overflow"]`, |
| 806 | }}, |
| 807 | }, |
| 808 | }) |
| 809 | } |
| 810 | |
| 811 | func TestCcBinaryWithMiscUndefinedProperty(t *testing.T) { |
| 812 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 813 | description: "cc_binary with miscellaneous properties specified", |
| 814 | blueprint: ` |
| 815 | {rule_name} { |
| 816 | name: "foo", |
| 817 | sanitize: { |
| 818 | misc_undefined: ["undefined", "nullability"], |
| 819 | }, |
| 820 | }`, |
| 821 | targets: []testBazelTarget{ |
| 822 | {"cc_binary", "foo", AttrNameToString{ |
| 823 | "local_includes": `["."]`, |
| 824 | "features": `[ |
| 825 | "ubsan_undefined", |
| 826 | "ubsan_nullability", |
| 827 | ]`, |
| 828 | }}, |
| 829 | }, |
| 830 | }) |
| 831 | } |
| 832 | |
| 833 | func TestCcBinaryWithUBSanPropertiesArchSpecific(t *testing.T) { |
| 834 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 835 | description: "cc_binary has correct feature select when UBSan props are specified in arch specific blocks", |
| 836 | blueprint: ` |
| 837 | {rule_name} { |
| 838 | name: "foo", |
| 839 | sanitize: { |
| 840 | misc_undefined: ["undefined", "nullability"], |
| 841 | }, |
| 842 | target: { |
| 843 | android: { |
| 844 | sanitize: { |
| 845 | misc_undefined: ["alignment"], |
| 846 | }, |
| 847 | }, |
| 848 | linux_glibc: { |
| 849 | sanitize: { |
| 850 | integer_overflow: true, |
| 851 | }, |
| 852 | }, |
| 853 | }, |
| 854 | }`, |
| 855 | targets: []testBazelTarget{ |
| 856 | {"cc_binary", "foo", AttrNameToString{ |
| 857 | "local_includes": `["."]`, |
| 858 | "features": `[ |
| 859 | "ubsan_undefined", |
| 860 | "ubsan_nullability", |
| 861 | ] + select({ |
| 862 | "//build/bazel/platforms/os:android": ["ubsan_alignment"], |
| 863 | "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"], |
| 864 | "//conditions:default": [], |
| 865 | })`, |
| 866 | }}, |
| 867 | }, |
| 868 | }) |
| 869 | } |
Trevor Radcliffe | 56b1a2b | 2023-02-06 21:58:30 +0000 | [diff] [blame] | 870 | |
Trevor Radcliffe | ded095c | 2023-06-12 19:18:28 +0000 | [diff] [blame] | 871 | func TestCcBinaryWithSanitizerBlocklist(t *testing.T) { |
| 872 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 873 | description: "cc_binary has the correct feature when sanitize.blocklist is provided", |
| 874 | blueprint: ` |
| 875 | {rule_name} { |
| 876 | name: "foo", |
| 877 | sanitize: { |
| 878 | blocklist: "foo_blocklist.txt", |
| 879 | }, |
| 880 | }`, |
| 881 | targets: []testBazelTarget{ |
| 882 | {"cc_binary", "foo", AttrNameToString{ |
Trevor Radcliffe | d9b7f17 | 2023-08-09 22:21:38 +0000 | [diff] [blame] | 883 | "copts": `select({ |
| 884 | "//build/bazel/rules/cc:sanitizers_enabled": ["-fsanitize-ignorelist=$(location foo_blocklist.txt)"], |
| 885 | "//conditions:default": [], |
| 886 | })`, |
| 887 | "additional_compiler_inputs": `select({ |
| 888 | "//build/bazel/rules/cc:sanitizers_enabled": [":foo_blocklist.txt"], |
| 889 | "//conditions:default": [], |
| 890 | })`, |
Trevor Radcliffe | ded095c | 2023-06-12 19:18:28 +0000 | [diff] [blame] | 891 | "local_includes": `["."]`, |
Trevor Radcliffe | ded095c | 2023-06-12 19:18:28 +0000 | [diff] [blame] | 892 | }}, |
| 893 | }, |
| 894 | }) |
| 895 | } |
| 896 | |
Trevor Radcliffe | 56b1a2b | 2023-02-06 21:58:30 +0000 | [diff] [blame] | 897 | func TestCcBinaryWithThinLto(t *testing.T) { |
| 898 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 899 | description: "cc_binary has correct features when thin LTO is enabled", |
| 900 | blueprint: ` |
| 901 | {rule_name} { |
| 902 | name: "foo", |
| 903 | lto: { |
| 904 | thin: true, |
| 905 | }, |
| 906 | }`, |
| 907 | targets: []testBazelTarget{ |
| 908 | {"cc_binary", "foo", AttrNameToString{ |
| 909 | "local_includes": `["."]`, |
| 910 | "features": `["android_thin_lto"]`, |
| 911 | }}, |
| 912 | }, |
| 913 | }) |
| 914 | } |
| 915 | |
| 916 | func TestCcBinaryWithLtoNever(t *testing.T) { |
| 917 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 918 | description: "cc_binary has correct features when LTO is explicitly disabled", |
| 919 | blueprint: ` |
| 920 | {rule_name} { |
| 921 | name: "foo", |
| 922 | lto: { |
| 923 | never: true, |
| 924 | }, |
| 925 | }`, |
| 926 | targets: []testBazelTarget{ |
| 927 | {"cc_binary", "foo", AttrNameToString{ |
| 928 | "local_includes": `["."]`, |
| 929 | "features": `["-android_thin_lto"]`, |
| 930 | }}, |
| 931 | }, |
| 932 | }) |
| 933 | } |
| 934 | |
| 935 | func TestCcBinaryWithThinLtoArchSpecific(t *testing.T) { |
| 936 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 937 | description: "cc_binary has correct features when LTO differs across arch and os variants", |
| 938 | blueprint: ` |
| 939 | {rule_name} { |
| 940 | name: "foo", |
| 941 | target: { |
| 942 | android: { |
| 943 | lto: { |
| 944 | thin: true, |
| 945 | }, |
| 946 | }, |
| 947 | }, |
| 948 | arch: { |
| 949 | riscv64: { |
| 950 | lto: { |
| 951 | thin: false, |
| 952 | }, |
| 953 | }, |
| 954 | }, |
| 955 | }`, |
| 956 | targets: []testBazelTarget{ |
| 957 | {"cc_binary", "foo", AttrNameToString{ |
| 958 | "local_includes": `["."]`, |
| 959 | "features": `select({ |
| 960 | "//build/bazel/platforms/os_arch:android_arm": ["android_thin_lto"], |
| 961 | "//build/bazel/platforms/os_arch:android_arm64": ["android_thin_lto"], |
| 962 | "//build/bazel/platforms/os_arch:android_riscv64": ["-android_thin_lto"], |
| 963 | "//build/bazel/platforms/os_arch:android_x86": ["android_thin_lto"], |
| 964 | "//build/bazel/platforms/os_arch:android_x86_64": ["android_thin_lto"], |
| 965 | "//conditions:default": [], |
| 966 | })`, |
| 967 | }}, |
| 968 | }, |
| 969 | }) |
| 970 | } |
| 971 | |
| 972 | func TestCcBinaryWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) { |
| 973 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 974 | description: "cc_binary has correct features when LTO disabled by default but enabled on a particular variant", |
| 975 | blueprint: ` |
| 976 | {rule_name} { |
| 977 | name: "foo", |
| 978 | lto: { |
| 979 | never: true, |
| 980 | }, |
| 981 | target: { |
| 982 | android: { |
| 983 | lto: { |
| 984 | thin: true, |
| 985 | never: false, |
| 986 | }, |
| 987 | }, |
| 988 | }, |
| 989 | }`, |
| 990 | targets: []testBazelTarget{ |
| 991 | {"cc_binary", "foo", AttrNameToString{ |
| 992 | "local_includes": `["."]`, |
| 993 | "features": `select({ |
| 994 | "//build/bazel/platforms/os:android": ["android_thin_lto"], |
| 995 | "//conditions:default": ["-android_thin_lto"], |
| 996 | })`, |
| 997 | }}, |
| 998 | }, |
| 999 | }) |
| 1000 | } |
| 1001 | |
| 1002 | func TestCcBinaryWithThinLtoAndWholeProgramVtables(t *testing.T) { |
| 1003 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 1004 | description: "cc_binary has correct features when thin LTO is enabled with whole_program_vtables", |
| 1005 | blueprint: ` |
| 1006 | {rule_name} { |
| 1007 | name: "foo", |
| 1008 | lto: { |
| 1009 | thin: true, |
| 1010 | }, |
| 1011 | whole_program_vtables: true, |
| 1012 | }`, |
| 1013 | targets: []testBazelTarget{ |
| 1014 | {"cc_binary", "foo", AttrNameToString{ |
| 1015 | "local_includes": `["."]`, |
| 1016 | "features": `[ |
| 1017 | "android_thin_lto", |
| 1018 | "android_thin_lto_whole_program_vtables", |
| 1019 | ]`, |
| 1020 | }}, |
| 1021 | }, |
| 1022 | }) |
| 1023 | } |
Trevor Radcliffe | a8b4416 | 2023-04-14 18:25:24 +0000 | [diff] [blame] | 1024 | |
| 1025 | func TestCcBinaryHiddenVisibilityConvertedToFeature(t *testing.T) { |
| 1026 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 1027 | description: "cc_binary changes hidden visibility to feature", |
| 1028 | blueprint: ` |
| 1029 | {rule_name} { |
| 1030 | name: "foo", |
| 1031 | cflags: ["-fvisibility=hidden"], |
| 1032 | }`, |
| 1033 | targets: []testBazelTarget{ |
| 1034 | {"cc_binary", "foo", AttrNameToString{ |
| 1035 | "local_includes": `["."]`, |
| 1036 | "features": `["visibility_hidden"]`, |
| 1037 | }}, |
| 1038 | }, |
| 1039 | }) |
| 1040 | } |
| 1041 | |
| 1042 | func TestCcBinaryHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) { |
| 1043 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 1044 | description: "cc_binary changes hidden visibility to feature for specific os", |
| 1045 | blueprint: ` |
| 1046 | {rule_name} { |
| 1047 | name: "foo", |
| 1048 | target: { |
| 1049 | android: { |
| 1050 | cflags: ["-fvisibility=hidden"], |
| 1051 | }, |
| 1052 | }, |
| 1053 | }`, |
| 1054 | targets: []testBazelTarget{ |
| 1055 | {"cc_binary", "foo", AttrNameToString{ |
| 1056 | "local_includes": `["."]`, |
| 1057 | "features": `select({ |
| 1058 | "//build/bazel/platforms/os:android": ["visibility_hidden"], |
| 1059 | "//conditions:default": [], |
| 1060 | })`, |
| 1061 | }}, |
| 1062 | }, |
| 1063 | }) |
| 1064 | } |
Trevor Radcliffe | 27669c0 | 2023-03-28 20:47:10 +0000 | [diff] [blame] | 1065 | |
| 1066 | func TestCcBinaryWithCfi(t *testing.T) { |
| 1067 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 1068 | description: "cc_binary has correct features when cfi is enabled", |
| 1069 | blueprint: ` |
| 1070 | {rule_name} { |
| 1071 | name: "foo", |
| 1072 | sanitize: { |
| 1073 | cfi: true, |
| 1074 | }, |
| 1075 | }`, |
| 1076 | targets: []testBazelTarget{ |
| 1077 | {"cc_binary", "foo", AttrNameToString{ |
| 1078 | "features": `["android_cfi"]`, |
| 1079 | "local_includes": `["."]`, |
| 1080 | }}, |
| 1081 | }, |
| 1082 | }) |
| 1083 | } |
| 1084 | |
| 1085 | func TestCcBinaryWithCfiOsSpecific(t *testing.T) { |
| 1086 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 1087 | description: "cc_binary has correct features when cfi is enabled for specific variants", |
| 1088 | blueprint: ` |
| 1089 | {rule_name} { |
| 1090 | name: "foo", |
| 1091 | target: { |
| 1092 | android: { |
| 1093 | sanitize: { |
| 1094 | cfi: true, |
| 1095 | }, |
| 1096 | }, |
| 1097 | }, |
| 1098 | }`, |
| 1099 | targets: []testBazelTarget{ |
| 1100 | {"cc_binary", "foo", AttrNameToString{ |
| 1101 | "features": `select({ |
| 1102 | "//build/bazel/platforms/os:android": ["android_cfi"], |
| 1103 | "//conditions:default": [], |
| 1104 | })`, |
| 1105 | "local_includes": `["."]`, |
| 1106 | }}, |
| 1107 | }, |
| 1108 | }) |
| 1109 | } |
| 1110 | |
| 1111 | func TestCcBinaryWithCfiAndCfiAssemblySupport(t *testing.T) { |
| 1112 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 1113 | description: "cc_binary has correct features when cfi is enabled with cfi assembly support", |
| 1114 | blueprint: ` |
| 1115 | {rule_name} { |
| 1116 | name: "foo", |
| 1117 | sanitize: { |
| 1118 | cfi: true, |
| 1119 | config: { |
| 1120 | cfi_assembly_support: true, |
| 1121 | }, |
| 1122 | }, |
| 1123 | }`, |
| 1124 | targets: []testBazelTarget{ |
| 1125 | {"cc_binary", "foo", AttrNameToString{ |
| 1126 | "features": `[ |
| 1127 | "android_cfi", |
| 1128 | "android_cfi_assembly_support", |
| 1129 | ]`, |
| 1130 | "local_includes": `["."]`, |
| 1131 | }}, |
| 1132 | }, |
| 1133 | }) |
| 1134 | } |
Spandan Das | 39ccf93 | 2023-05-26 18:03:39 +0000 | [diff] [blame] | 1135 | |
Trevor Radcliffe | 523c5c6 | 2023-06-16 20:15:45 +0000 | [diff] [blame] | 1136 | func TestCcBinaryExplicitlyDisablesCfiWhenFalse(t *testing.T) { |
| 1137 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 1138 | description: "cc_binary disables cfi when explciitly set to false in the bp", |
| 1139 | blueprint: ` |
| 1140 | {rule_name} { |
| 1141 | name: "foo", |
| 1142 | sanitize: { |
| 1143 | cfi: false, |
| 1144 | }, |
| 1145 | } |
| 1146 | `, |
| 1147 | targets: []testBazelTarget{ |
| 1148 | {"cc_binary", "foo", AttrNameToString{ |
| 1149 | "features": `["-android_cfi"]`, |
| 1150 | "local_includes": `["."]`, |
| 1151 | }}, |
| 1152 | }, |
| 1153 | }) |
| 1154 | } |
| 1155 | |
Spandan Das | 39ccf93 | 2023-05-26 18:03:39 +0000 | [diff] [blame] | 1156 | func TestCcBinaryStem(t *testing.T) { |
| 1157 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 1158 | description: "cc_binary with stem property", |
| 1159 | blueprint: ` |
| 1160 | cc_binary { |
| 1161 | name: "foo_with_stem_simple", |
| 1162 | stem: "foo", |
| 1163 | } |
| 1164 | cc_binary { |
| 1165 | name: "foo_with_arch_variant_stem", |
| 1166 | arch: { |
| 1167 | arm: { |
| 1168 | stem: "foo-arm", |
| 1169 | }, |
| 1170 | arm64: { |
| 1171 | stem: "foo-arm64", |
| 1172 | }, |
| 1173 | }, |
| 1174 | } |
| 1175 | `, |
| 1176 | targets: []testBazelTarget{ |
| 1177 | {"cc_binary", "foo_with_stem_simple", AttrNameToString{ |
| 1178 | "stem": `"foo"`, |
| 1179 | "local_includes": `["."]`, |
| 1180 | }}, |
| 1181 | {"cc_binary", "foo_with_arch_variant_stem", AttrNameToString{ |
| 1182 | "stem": `select({ |
| 1183 | "//build/bazel/platforms/arch:arm": "foo-arm", |
| 1184 | "//build/bazel/platforms/arch:arm64": "foo-arm64", |
| 1185 | "//conditions:default": None, |
| 1186 | })`, |
| 1187 | "local_includes": `["."]`, |
| 1188 | }}, |
| 1189 | }, |
| 1190 | }) |
| 1191 | } |
Alix | e266787 | 2023-04-24 14:57:32 +0000 | [diff] [blame] | 1192 | |
| 1193 | func TestCCBinaryRscriptSrc(t *testing.T) { |
| 1194 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
| 1195 | description: `cc_binary with rscript files in sources`, |
| 1196 | blueprint: ` |
| 1197 | {rule_name} { |
| 1198 | name : "foo", |
| 1199 | srcs : [ |
| 1200 | "ccSrc.cc", |
| 1201 | "rsSrc.rscript", |
| 1202 | ], |
| 1203 | include_build_directory: false, |
| 1204 | } |
| 1205 | `, |
| 1206 | targets: []testBazelTarget{ |
| 1207 | {"rscript_to_cpp", "foo_renderscript", AttrNameToString{ |
| 1208 | "srcs": `["rsSrc.rscript"]`, |
| 1209 | }}, |
| 1210 | {"cc_binary", "foo", AttrNameToString{ |
| 1211 | "absolute_includes": `[ |
| 1212 | "frameworks/rs", |
| 1213 | "frameworks/rs/cpp", |
| 1214 | ]`, |
| 1215 | "local_includes": `["."]`, |
| 1216 | "srcs": `[ |
| 1217 | "ccSrc.cc", |
| 1218 | "foo_renderscript", |
| 1219 | ]`, |
| 1220 | }}, |
| 1221 | }, |
| 1222 | }) |
| 1223 | } |
Liz Kammer | b492843 | 2023-06-02 18:43:36 -0400 | [diff] [blame] | 1224 | |
| 1225 | func TestCcBinaryStatic_SystemSharedLibUsedAsDep(t *testing.T) { |
| 1226 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
| 1227 | description: "cc_library_static system_shared_lib empty for linux_bionic variant", |
| 1228 | blueprint: soongCcLibraryStaticPreamble + |
Sam Delmerico | 130d75b | 2023-08-31 00:51:44 +0000 | [diff] [blame] | 1229 | SimpleModuleDoNotConvertBp2build("cc_library", "libc") + ` |
Liz Kammer | b492843 | 2023-06-02 18:43:36 -0400 | [diff] [blame] | 1230 | |
| 1231 | cc_library { |
| 1232 | name: "libm", |
| 1233 | bazel_module: { bp2build_available: false }, |
| 1234 | } |
| 1235 | |
| 1236 | cc_binary { |
| 1237 | name: "used_in_bionic_oses", |
| 1238 | target: { |
| 1239 | android: { |
| 1240 | static_libs: ["libc"], |
| 1241 | }, |
| 1242 | linux_bionic: { |
| 1243 | static_libs: ["libc"], |
| 1244 | }, |
| 1245 | }, |
| 1246 | include_build_directory: false, |
| 1247 | static_executable: true, |
| 1248 | } |
| 1249 | |
| 1250 | cc_binary { |
| 1251 | name: "all", |
| 1252 | static_libs: ["libc"], |
| 1253 | include_build_directory: false, |
| 1254 | static_executable: true, |
| 1255 | } |
| 1256 | |
| 1257 | cc_binary { |
| 1258 | name: "keep_for_empty_system_shared_libs", |
| 1259 | static_libs: ["libc"], |
| 1260 | system_shared_libs: [], |
| 1261 | include_build_directory: false, |
| 1262 | static_executable: true, |
| 1263 | } |
| 1264 | |
| 1265 | cc_binary { |
| 1266 | name: "used_with_stubs", |
| 1267 | static_libs: ["libm"], |
| 1268 | include_build_directory: false, |
| 1269 | static_executable: true, |
| 1270 | } |
| 1271 | |
| 1272 | cc_binary { |
| 1273 | name: "keep_with_stubs", |
| 1274 | static_libs: ["libm"], |
| 1275 | system_shared_libs: [], |
| 1276 | include_build_directory: false, |
| 1277 | static_executable: true, |
| 1278 | } |
| 1279 | `, |
| 1280 | targets: []testBazelTarget{ |
| 1281 | {"cc_binary", "all", AttrNameToString{ |
| 1282 | "linkshared": "False", |
| 1283 | }}, |
| 1284 | {"cc_binary", "keep_for_empty_system_shared_libs", AttrNameToString{ |
| 1285 | "deps": `[":libc_bp2build_cc_library_static"]`, |
| 1286 | "system_deps": `[]`, |
| 1287 | "linkshared": "False", |
| 1288 | }}, |
| 1289 | {"cc_binary", "keep_with_stubs", AttrNameToString{ |
| 1290 | "linkshared": "False", |
| 1291 | "deps": `[":libm_bp2build_cc_library_static"]`, |
| 1292 | "system_deps": `[]`, |
| 1293 | }}, |
| 1294 | {"cc_binary", "used_in_bionic_oses", AttrNameToString{ |
| 1295 | "linkshared": "False", |
| 1296 | }}, |
| 1297 | {"cc_binary", "used_with_stubs", AttrNameToString{ |
| 1298 | "linkshared": "False", |
| 1299 | }}, |
| 1300 | }, |
| 1301 | }) |
| 1302 | } |