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