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 ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/cc" |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 20 | "android/soong/genrule" |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 21 | "fmt" |
| 22 | "strings" |
| 23 | "testing" |
| 24 | ) |
| 25 | |
| 26 | const ( |
| 27 | ccBinaryTypePlaceHolder = "{rule_name}" |
| 28 | compatibleWithPlaceHolder = "{target_compatible_with}" |
| 29 | ) |
| 30 | |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 31 | type testBazelTarget struct { |
| 32 | typ string |
| 33 | name string |
| 34 | attrs attrNameToString |
| 35 | } |
| 36 | |
| 37 | func generateBazelTargetsForTest(targets []testBazelTarget) []string { |
| 38 | ret := make([]string, 0, len(targets)) |
| 39 | for _, t := range targets { |
| 40 | ret = append(ret, makeBazelTarget(t.typ, t.name, t.attrs)) |
| 41 | } |
| 42 | return ret |
| 43 | } |
| 44 | |
| 45 | type ccBinaryBp2buildTestCase struct { |
| 46 | description string |
| 47 | blueprint string |
| 48 | targets []testBazelTarget |
| 49 | } |
| 50 | |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 51 | func registerCcBinaryModuleTypes(ctx android.RegistrationContext) { |
| 52 | cc.RegisterCCBuildComponents(ctx) |
| 53 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
| 54 | ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) |
| 55 | ctx.RegisterModuleType("cc_library", cc.LibraryFactory) |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 56 | ctx.RegisterModuleType("genrule", genrule.GenRuleFactory) |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 57 | } |
| 58 | |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 59 | var binaryReplacer = strings.NewReplacer(ccBinaryTypePlaceHolder, "cc_binary") |
| 60 | var hostBinaryReplacer = strings.NewReplacer(ccBinaryTypePlaceHolder, "cc_binary_host") |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 61 | |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 62 | func runCcBinaryTests(t *testing.T, tc ccBinaryBp2buildTestCase) { |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 63 | t.Helper() |
| 64 | runCcBinaryTestCase(t, tc) |
| 65 | runCcHostBinaryTestCase(t, tc) |
| 66 | } |
| 67 | |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 68 | func runCcBinaryTestCase(t *testing.T, tc ccBinaryBp2buildTestCase) { |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 69 | t.Helper() |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 70 | moduleTypeUnderTest := "cc_binary" |
| 71 | testCase := bp2buildTestCase{ |
| 72 | expectedBazelTargets: generateBazelTargetsForTest(tc.targets), |
| 73 | moduleTypeUnderTest: moduleTypeUnderTest, |
| 74 | moduleTypeUnderTestFactory: cc.BinaryFactory, |
| 75 | moduleTypeUnderTestBp2BuildMutator: cc.BinaryBp2build, |
| 76 | description: fmt.Sprintf("%s %s", moduleTypeUnderTest, tc.description), |
| 77 | blueprint: binaryReplacer.Replace(tc.blueprint), |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 78 | } |
| 79 | t.Run(testCase.description, func(t *testing.T) { |
| 80 | runBp2BuildTestCase(t, registerCcBinaryModuleTypes, testCase) |
| 81 | }) |
| 82 | } |
| 83 | |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 84 | func runCcHostBinaryTestCase(t *testing.T, tc ccBinaryBp2buildTestCase) { |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 85 | t.Helper() |
| 86 | testCase := tc |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 87 | for i, t := range testCase.targets { |
| 88 | t.attrs["target_compatible_with"] = `select({ |
| 89 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 90 | "//conditions:default": [], |
| 91 | })` |
| 92 | testCase.targets[i] = t |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 93 | } |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 94 | moduleTypeUnderTest := "cc_binary_host" |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 95 | t.Run(testCase.description, func(t *testing.T) { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 96 | runBp2BuildTestCase(t, registerCcBinaryModuleTypes, bp2buildTestCase{ |
| 97 | expectedBazelTargets: generateBazelTargetsForTest(testCase.targets), |
| 98 | moduleTypeUnderTest: moduleTypeUnderTest, |
| 99 | moduleTypeUnderTestFactory: cc.BinaryHostFactory, |
| 100 | moduleTypeUnderTestBp2BuildMutator: cc.BinaryHostBp2build, |
| 101 | description: fmt.Sprintf("%s %s", moduleTypeUnderTest, tc.description), |
| 102 | blueprint: hostBinaryReplacer.Replace(testCase.blueprint), |
| 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", |
| 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 | }, |
| 129 | } |
| 130 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 131 | targets: []testBazelTarget{ |
| 132 | {"cc_binary", "foo", attrNameToString{ |
| 133 | "absolute_includes": `["absolute_dir"]`, |
| 134 | "asflags": `["-Dasflag"]`, |
| 135 | "conlyflags": `["-Dconlyflag"]`, |
| 136 | "copts": `["-Dcopt"]`, |
| 137 | "cppflags": `["-Dcppflag"]`, |
| 138 | "linkopts": `["ld-flag"]`, |
| 139 | "local_includes": `[ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 140 | "dir", |
| 141 | ".", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 142 | ]`, |
| 143 | "rtti": `True`, |
| 144 | "srcs": `["a.cc"]`, |
| 145 | "strip": `{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 146 | "all": True, |
| 147 | "keep_symbols": True, |
| 148 | "keep_symbols_and_debug_frame": True, |
| 149 | "keep_symbols_list": ["symbol"], |
| 150 | "none": True, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 151 | }`, |
| 152 | }, |
| 153 | }, |
| 154 | }, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 155 | }) |
| 156 | } |
| 157 | |
| 158 | func TestCcBinaryWithSharedLdflagDisableFeature(t *testing.T) { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 159 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 160 | description: `ldflag "-shared" disables static_flag feature`, |
| 161 | blueprint: ` |
| 162 | {rule_name} { |
| 163 | name: "foo", |
| 164 | ldflags: ["-shared"], |
| 165 | include_build_directory: false, |
| 166 | } |
| 167 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 168 | targets: []testBazelTarget{ |
| 169 | {"cc_binary", "foo", attrNameToString{ |
| 170 | "features": `["-static_flag"]`, |
| 171 | "linkopts": `["-shared"]`, |
| 172 | }, |
| 173 | }, |
| 174 | }, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 175 | }) |
| 176 | } |
| 177 | |
| 178 | func TestCcBinaryWithLinkStatic(t *testing.T) { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 179 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 180 | description: "link static", |
| 181 | blueprint: ` |
| 182 | {rule_name} { |
| 183 | name: "foo", |
| 184 | static_executable: true, |
| 185 | include_build_directory: false, |
| 186 | } |
| 187 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 188 | targets: []testBazelTarget{ |
| 189 | {"cc_binary", "foo", attrNameToString{ |
| 190 | "linkshared": `False`, |
| 191 | }, |
| 192 | }, |
| 193 | }, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 194 | }) |
| 195 | } |
| 196 | |
| 197 | func TestCcBinaryVersionScript(t *testing.T) { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 198 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 199 | description: `version script`, |
| 200 | blueprint: ` |
| 201 | {rule_name} { |
| 202 | name: "foo", |
| 203 | include_build_directory: false, |
| 204 | version_script: "vs", |
| 205 | } |
| 206 | `, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 207 | targets: []testBazelTarget{ |
| 208 | {"cc_binary", "foo", attrNameToString{ |
| 209 | "additional_linker_inputs": `["vs"]`, |
| 210 | "linkopts": `["-Wl,--version-script,$(location vs)"]`, |
| 211 | }, |
| 212 | }, |
| 213 | }, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 214 | }) |
| 215 | } |
| 216 | |
| 217 | func TestCcBinarySplitSrcsByLang(t *testing.T) { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 218 | runCcHostBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 219 | description: "split srcs by lang", |
| 220 | blueprint: ` |
| 221 | {rule_name} { |
| 222 | name: "foo", |
| 223 | srcs: [ |
| 224 | "asonly.S", |
| 225 | "conly.c", |
| 226 | "cpponly.cpp", |
| 227 | ":fg_foo", |
| 228 | ], |
| 229 | include_build_directory: false, |
| 230 | } |
| 231 | ` + simpleModuleDoNotConvertBp2build("filegroup", "fg_foo"), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 232 | targets: []testBazelTarget{ |
| 233 | {"cc_binary", "foo", attrNameToString{ |
| 234 | "srcs": `[ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 235 | "cpponly.cpp", |
| 236 | ":fg_foo_cpp_srcs", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 237 | ]`, |
| 238 | "srcs_as": `[ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 239 | "asonly.S", |
| 240 | ":fg_foo_as_srcs", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 241 | ]`, |
| 242 | "srcs_c": `[ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 243 | "conly.c", |
| 244 | ":fg_foo_c_srcs", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 245 | ]`, |
| 246 | }, |
| 247 | }, |
| 248 | }, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 249 | }) |
| 250 | } |
| 251 | |
| 252 | func TestCcBinaryDoNotDistinguishBetweenDepsAndImplementationDeps(t *testing.T) { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 253 | runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 254 | description: "no implementation deps", |
| 255 | blueprint: ` |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 256 | genrule { |
| 257 | name: "generated_hdr", |
| 258 | cmd: "nothing to see here", |
| 259 | } |
| 260 | |
| 261 | genrule { |
| 262 | name: "export_generated_hdr", |
| 263 | cmd: "nothing to see here", |
| 264 | } |
| 265 | |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 266 | {rule_name} { |
| 267 | name: "foo", |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 268 | srcs: ["foo.cpp"], |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 269 | shared_libs: ["implementation_shared_dep", "shared_dep"], |
| 270 | export_shared_lib_headers: ["shared_dep"], |
| 271 | static_libs: ["implementation_static_dep", "static_dep"], |
| 272 | export_static_lib_headers: ["static_dep", "whole_static_dep"], |
| 273 | whole_static_libs: ["not_explicitly_exported_whole_static_dep", "whole_static_dep"], |
| 274 | include_build_directory: false, |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 275 | generated_headers: ["generated_hdr", "export_generated_hdr"], |
| 276 | export_generated_headers: ["export_generated_hdr"], |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 277 | } |
| 278 | ` + |
| 279 | simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep") + |
| 280 | simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep") + |
| 281 | simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep") + |
| 282 | simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep") + |
| 283 | simpleModuleDoNotConvertBp2build("cc_library", "shared_dep") + |
| 284 | simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep"), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 285 | targets: []testBazelTarget{ |
| 286 | {"cc_binary", "foo", attrNameToString{ |
| 287 | "deps": `[ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 288 | ":implementation_static_dep", |
| 289 | ":static_dep", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 290 | ]`, |
| 291 | "dynamic_deps": `[ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 292 | ":implementation_shared_dep", |
| 293 | ":shared_dep", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 294 | ]`, |
| 295 | "srcs": `[ |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 296 | "foo.cpp", |
| 297 | ":generated_hdr", |
| 298 | ":export_generated_hdr", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 299 | ]`, |
| 300 | "whole_archive_deps": `[ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 301 | ":not_explicitly_exported_whole_static_dep", |
| 302 | ":whole_static_dep", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 303 | ]`, |
| 304 | }, |
| 305 | }, |
| 306 | }, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 307 | }) |
| 308 | } |
| 309 | |
| 310 | func TestCcBinaryNocrtTests(t *testing.T) { |
| 311 | baseTestCases := []struct { |
| 312 | description string |
| 313 | soongProperty string |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 314 | bazelAttr attrNameToString |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 315 | }{ |
| 316 | { |
| 317 | description: "nocrt: true", |
| 318 | soongProperty: `nocrt: true,`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 319 | bazelAttr: attrNameToString{"link_crt": `False`}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 320 | }, |
| 321 | { |
| 322 | description: "nocrt: false", |
| 323 | soongProperty: `nocrt: false,`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 324 | bazelAttr: attrNameToString{}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 325 | }, |
| 326 | { |
| 327 | description: "nocrt: not set", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 328 | bazelAttr: attrNameToString{}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 329 | }, |
| 330 | } |
| 331 | |
| 332 | baseBlueprint := `{rule_name} { |
| 333 | name: "foo",%s |
| 334 | include_build_directory: false, |
| 335 | } |
| 336 | ` |
| 337 | |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 338 | for _, btc := range baseTestCases { |
| 339 | prop := btc.soongProperty |
| 340 | if len(prop) > 0 { |
| 341 | prop = "\n" + prop |
| 342 | } |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 343 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 344 | description: btc.description, |
| 345 | blueprint: fmt.Sprintf(baseBlueprint, prop), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 346 | targets: []testBazelTarget{ |
| 347 | {"cc_binary", "foo", btc.bazelAttr}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 348 | }, |
| 349 | }) |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | func TestCcBinaryNo_libcrtTests(t *testing.T) { |
| 354 | baseTestCases := []struct { |
| 355 | description string |
| 356 | soongProperty string |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 357 | bazelAttr attrNameToString |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 358 | }{ |
| 359 | { |
| 360 | description: "no_libcrt: true", |
| 361 | soongProperty: `no_libcrt: true,`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 362 | bazelAttr: attrNameToString{"use_libcrt": `False`}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 363 | }, |
| 364 | { |
| 365 | description: "no_libcrt: false", |
| 366 | soongProperty: `no_libcrt: false,`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 367 | bazelAttr: attrNameToString{"use_libcrt": `True`}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 368 | }, |
| 369 | { |
| 370 | description: "no_libcrt: not set", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 371 | bazelAttr: attrNameToString{}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 372 | }, |
| 373 | } |
| 374 | |
| 375 | baseBlueprint := `{rule_name} { |
| 376 | name: "foo",%s |
| 377 | include_build_directory: false, |
| 378 | } |
| 379 | ` |
| 380 | |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 381 | for _, btc := range baseTestCases { |
| 382 | prop := btc.soongProperty |
| 383 | if len(prop) > 0 { |
| 384 | prop = "\n" + prop |
| 385 | } |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 386 | runCcBinaryTests(t, ccBinaryBp2buildTestCase{ |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 387 | description: btc.description, |
| 388 | blueprint: fmt.Sprintf(baseBlueprint, prop), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 389 | targets: []testBazelTarget{ |
| 390 | {"cc_binary", "foo", btc.bazelAttr}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 391 | }, |
| 392 | }) |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | func TestCcBinaryPropertiesToFeatures(t *testing.T) { |
| 397 | baseTestCases := []struct { |
| 398 | description string |
| 399 | soongProperty string |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 400 | bazelAttr attrNameToString |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 401 | }{ |
| 402 | { |
| 403 | description: "pack_relocation: true", |
| 404 | soongProperty: `pack_relocations: true,`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 405 | bazelAttr: attrNameToString{}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 406 | }, |
| 407 | { |
| 408 | description: "pack_relocations: false", |
| 409 | soongProperty: `pack_relocations: false,`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 410 | bazelAttr: attrNameToString{"features": `["disable_pack_relocations"]`}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 411 | }, |
| 412 | { |
| 413 | description: "pack_relocations: not set", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 414 | bazelAttr: attrNameToString{}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 415 | }, |
| 416 | { |
| 417 | description: "pack_relocation: true", |
| 418 | soongProperty: `allow_undefined_symbols: true,`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 419 | bazelAttr: attrNameToString{"features": `["-no_undefined_symbols"]`}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 420 | }, |
| 421 | { |
| 422 | description: "allow_undefined_symbols: false", |
| 423 | soongProperty: `allow_undefined_symbols: false,`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 424 | bazelAttr: attrNameToString{}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 425 | }, |
| 426 | { |
| 427 | description: "allow_undefined_symbols: not set", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 428 | bazelAttr: attrNameToString{}, |
Liz Kammer | 2b8004b | 2021-10-04 13:55:44 -0400 | [diff] [blame] | 429 | }, |
| 430 | } |
| 431 | |
| 432 | baseBlueprint := `{rule_name} { |
| 433 | name: "foo",%s |
| 434 | include_build_directory: false, |
| 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 | } |