Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 1 | // Copyright 2020 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 | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 18 | "fmt" |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 19 | "strings" |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 20 | "testing" |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 21 | |
| 22 | "android/soong/android" |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame] | 23 | "android/soong/android/allowlists" |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 24 | "android/soong/python" |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 25 | ) |
| 26 | |
| 27 | func TestGenerateSoongModuleTargets(t *testing.T) { |
| 28 | testCases := []struct { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 29 | description string |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 30 | bp string |
| 31 | expectedBazelTarget string |
| 32 | }{ |
| 33 | { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 34 | description: "only name", |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 35 | bp: `custom { name: "foo" } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 36 | `, |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 37 | expectedBazelTarget: `soong_module( |
| 38 | name = "foo", |
Jingwen Chen | 288e2ba | 2021-01-25 04:36:04 -0500 | [diff] [blame] | 39 | soong_module_name = "foo", |
| 40 | soong_module_type = "custom", |
| 41 | soong_module_variant = "", |
| 42 | soong_module_deps = [ |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 43 | ], |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 44 | bool_prop = False, |
Liz Kammer | 46fb7ab | 2021-12-01 10:09:34 -0500 | [diff] [blame] | 45 | string_prop = "", |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 46 | )`, |
| 47 | }, |
| 48 | { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 49 | description: "handles bool", |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 50 | bp: `custom { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 51 | name: "foo", |
| 52 | bool_prop: true, |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 53 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 54 | `, |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 55 | expectedBazelTarget: `soong_module( |
| 56 | name = "foo", |
Jingwen Chen | 288e2ba | 2021-01-25 04:36:04 -0500 | [diff] [blame] | 57 | soong_module_name = "foo", |
| 58 | soong_module_type = "custom", |
| 59 | soong_module_variant = "", |
| 60 | soong_module_deps = [ |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 61 | ], |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 62 | bool_prop = True, |
Liz Kammer | 46fb7ab | 2021-12-01 10:09:34 -0500 | [diff] [blame] | 63 | string_prop = "", |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 64 | )`, |
| 65 | }, |
| 66 | { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 67 | description: "string escaping", |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 68 | bp: `custom { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 69 | name: "foo", |
| 70 | owner: "a_string_with\"quotes\"_and_\\backslashes\\\\", |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 71 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 72 | `, |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 73 | expectedBazelTarget: `soong_module( |
| 74 | name = "foo", |
Jingwen Chen | 288e2ba | 2021-01-25 04:36:04 -0500 | [diff] [blame] | 75 | soong_module_name = "foo", |
| 76 | soong_module_type = "custom", |
| 77 | soong_module_variant = "", |
| 78 | soong_module_deps = [ |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 79 | ], |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 80 | bool_prop = False, |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 81 | owner = "a_string_with\"quotes\"_and_\\backslashes\\\\", |
Liz Kammer | 46fb7ab | 2021-12-01 10:09:34 -0500 | [diff] [blame] | 82 | string_prop = "", |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 83 | )`, |
| 84 | }, |
| 85 | { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 86 | description: "single item string list", |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 87 | bp: `custom { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 88 | name: "foo", |
| 89 | required: ["bar"], |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 90 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 91 | `, |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 92 | expectedBazelTarget: `soong_module( |
| 93 | name = "foo", |
Jingwen Chen | 288e2ba | 2021-01-25 04:36:04 -0500 | [diff] [blame] | 94 | soong_module_name = "foo", |
| 95 | soong_module_type = "custom", |
| 96 | soong_module_variant = "", |
| 97 | soong_module_deps = [ |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 98 | ], |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 99 | bool_prop = False, |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 100 | required = ["bar"], |
Liz Kammer | 46fb7ab | 2021-12-01 10:09:34 -0500 | [diff] [blame] | 101 | string_prop = "", |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 102 | )`, |
| 103 | }, |
| 104 | { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 105 | description: "list of strings", |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 106 | bp: `custom { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 107 | name: "foo", |
| 108 | target_required: ["qux", "bazqux"], |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 109 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 110 | `, |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 111 | expectedBazelTarget: `soong_module( |
| 112 | name = "foo", |
Jingwen Chen | 288e2ba | 2021-01-25 04:36:04 -0500 | [diff] [blame] | 113 | soong_module_name = "foo", |
| 114 | soong_module_type = "custom", |
| 115 | soong_module_variant = "", |
| 116 | soong_module_deps = [ |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 117 | ], |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 118 | bool_prop = False, |
Liz Kammer | 46fb7ab | 2021-12-01 10:09:34 -0500 | [diff] [blame] | 119 | string_prop = "", |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 120 | target_required = [ |
| 121 | "qux", |
| 122 | "bazqux", |
| 123 | ], |
| 124 | )`, |
| 125 | }, |
| 126 | { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 127 | description: "dist/dists", |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 128 | bp: `custom { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 129 | name: "foo", |
| 130 | dist: { |
| 131 | targets: ["goal_foo"], |
| 132 | tag: ".foo", |
| 133 | }, |
| 134 | dists: [{ |
| 135 | targets: ["goal_bar"], |
| 136 | tag: ".bar", |
| 137 | }], |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 138 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 139 | `, |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 140 | expectedBazelTarget: `soong_module( |
| 141 | name = "foo", |
Jingwen Chen | 288e2ba | 2021-01-25 04:36:04 -0500 | [diff] [blame] | 142 | soong_module_name = "foo", |
| 143 | soong_module_type = "custom", |
| 144 | soong_module_variant = "", |
| 145 | soong_module_deps = [ |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 146 | ], |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 147 | bool_prop = False, |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 148 | dist = { |
| 149 | "tag": ".foo", |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 150 | "targets": ["goal_foo"], |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 151 | }, |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 152 | dists = [{ |
| 153 | "tag": ".bar", |
| 154 | "targets": ["goal_bar"], |
| 155 | }], |
Liz Kammer | 46fb7ab | 2021-12-01 10:09:34 -0500 | [diff] [blame] | 156 | string_prop = "", |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 157 | )`, |
| 158 | }, |
| 159 | { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 160 | description: "put it together", |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 161 | bp: `custom { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 162 | name: "foo", |
| 163 | required: ["bar"], |
| 164 | target_required: ["qux", "bazqux"], |
| 165 | bool_prop: true, |
| 166 | owner: "custom_owner", |
| 167 | dists: [ |
| 168 | { |
| 169 | tag: ".tag", |
| 170 | targets: ["my_goal"], |
| 171 | }, |
| 172 | ], |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 173 | } |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 174 | `, |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 175 | expectedBazelTarget: `soong_module( |
| 176 | name = "foo", |
Jingwen Chen | 288e2ba | 2021-01-25 04:36:04 -0500 | [diff] [blame] | 177 | soong_module_name = "foo", |
| 178 | soong_module_type = "custom", |
| 179 | soong_module_variant = "", |
| 180 | soong_module_deps = [ |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 181 | ], |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 182 | bool_prop = True, |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 183 | dists = [{ |
| 184 | "tag": ".tag", |
| 185 | "targets": ["my_goal"], |
| 186 | }], |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 187 | owner = "custom_owner", |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 188 | required = ["bar"], |
Liz Kammer | 46fb7ab | 2021-12-01 10:09:34 -0500 | [diff] [blame] | 189 | string_prop = "", |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 190 | target_required = [ |
| 191 | "qux", |
| 192 | "bazqux", |
| 193 | ], |
| 194 | )`, |
| 195 | }, |
| 196 | } |
| 197 | |
| 198 | dir := "." |
| 199 | for _, testCase := range testCases { |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 200 | t.Run(testCase.description, func(t *testing.T) { |
| 201 | config := android.TestConfig(buildDir, nil, testCase.bp, nil) |
| 202 | ctx := android.NewTestContext(config) |
Jingwen Chen | 164e086 | 2021-02-19 00:48:40 -0500 | [diff] [blame] | 203 | |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 204 | ctx.RegisterModuleType("custom", customModuleFactoryHostAndDevice) |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 205 | ctx.Register() |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 206 | |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 207 | _, errs := ctx.ParseFileList(dir, []string{"Android.bp"}) |
| 208 | android.FailIfErrored(t, errs) |
| 209 | _, errs = ctx.PrepareBuildActions(config) |
| 210 | android.FailIfErrored(t, errs) |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 211 | |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 212 | codegenCtx := NewCodegenContext(config, *ctx.Context, QueryView) |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 213 | bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir) |
| 214 | android.FailIfErrored(t, err) |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 215 | if actualCount, expectedCount := len(bazelTargets), 1; actualCount != expectedCount { |
| 216 | t.Fatalf("Expected %d bazel target, got %d", expectedCount, actualCount) |
| 217 | } |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 218 | |
Liz Kammer | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 219 | actualBazelTarget := bazelTargets[0] |
| 220 | if actualBazelTarget.content != testCase.expectedBazelTarget { |
| 221 | t.Errorf( |
| 222 | "Expected generated Bazel target to be '%s', got '%s'", |
| 223 | testCase.expectedBazelTarget, |
| 224 | actualBazelTarget.content, |
| 225 | ) |
| 226 | } |
| 227 | }) |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | |
| 231 | func TestGenerateBazelTargetModules(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 232 | testCases := []Bp2buildTestCase{ |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 233 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 234 | Description: "string ptr props", |
| 235 | Blueprint: `custom { |
Liz Kammer | 46fb7ab | 2021-12-01 10:09:34 -0500 | [diff] [blame] | 236 | name: "foo", |
| 237 | string_ptr_prop: "", |
| 238 | bazel_module: { bp2build_available: true }, |
| 239 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 240 | ExpectedBazelTargets: []string{ |
| 241 | makeBazelTarget("custom", "foo", AttrNameToString{ |
Liz Kammer | 46fb7ab | 2021-12-01 10:09:34 -0500 | [diff] [blame] | 242 | "string_ptr_prop": `""`, |
| 243 | }), |
| 244 | }, |
| 245 | }, |
| 246 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 247 | Description: "string props", |
| 248 | Blueprint: `custom { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 249 | name: "foo", |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 250 | string_list_prop: ["a", "b"], |
Liz Kammer | 46fb7ab | 2021-12-01 10:09:34 -0500 | [diff] [blame] | 251 | string_ptr_prop: "a", |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 252 | bazel_module: { bp2build_available: true }, |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 253 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 254 | ExpectedBazelTargets: []string{ |
| 255 | makeBazelTarget("custom", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 256 | "string_list_prop": `[ |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 257 | "a", |
| 258 | "b", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 259 | ]`, |
Liz Kammer | 46fb7ab | 2021-12-01 10:09:34 -0500 | [diff] [blame] | 260 | "string_ptr_prop": `"a"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 261 | }), |
Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 262 | }, |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 263 | }, |
Jingwen Chen | 58a12b8 | 2021-03-30 13:08:36 +0000 | [diff] [blame] | 264 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 265 | Description: "control characters", |
| 266 | Blueprint: `custom { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 267 | name: "foo", |
Jingwen Chen | 58a12b8 | 2021-03-30 13:08:36 +0000 | [diff] [blame] | 268 | string_list_prop: ["\t", "\n"], |
Liz Kammer | 46fb7ab | 2021-12-01 10:09:34 -0500 | [diff] [blame] | 269 | string_ptr_prop: "a\t\n\r", |
Jingwen Chen | 58a12b8 | 2021-03-30 13:08:36 +0000 | [diff] [blame] | 270 | bazel_module: { bp2build_available: true }, |
| 271 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 272 | ExpectedBazelTargets: []string{ |
| 273 | makeBazelTarget("custom", "foo", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 274 | "string_list_prop": `[ |
Jingwen Chen | 58a12b8 | 2021-03-30 13:08:36 +0000 | [diff] [blame] | 275 | "\t", |
| 276 | "\n", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 277 | ]`, |
Liz Kammer | 46fb7ab | 2021-12-01 10:09:34 -0500 | [diff] [blame] | 278 | "string_ptr_prop": `"a\t\n\r"`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 279 | }), |
Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 280 | }, |
| 281 | }, |
| 282 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 283 | Description: "handles dep", |
| 284 | Blueprint: `custom { |
Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 285 | name: "has_dep", |
| 286 | arch_paths: [":dep"], |
| 287 | bazel_module: { bp2build_available: true }, |
| 288 | } |
| 289 | |
| 290 | custom { |
| 291 | name: "dep", |
| 292 | arch_paths: ["abc"], |
| 293 | bazel_module: { bp2build_available: true }, |
| 294 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 295 | ExpectedBazelTargets: []string{ |
| 296 | makeBazelTarget("custom", "dep", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 297 | "arch_paths": `["abc"]`, |
| 298 | }), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 299 | makeBazelTarget("custom", "has_dep", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 300 | "arch_paths": `[":dep"]`, |
| 301 | }), |
Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 302 | }, |
| 303 | }, |
| 304 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 305 | Description: "non-existent dep", |
| 306 | Blueprint: `custom { |
Liz Kammer | daa09ef | 2021-12-15 15:35:38 -0500 | [diff] [blame] | 307 | name: "has_dep", |
| 308 | arch_paths: [":dep"], |
| 309 | bazel_module: { bp2build_available: true }, |
| 310 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 311 | ExpectedBazelTargets: []string{ |
| 312 | makeBazelTarget("custom", "has_dep", AttrNameToString{ |
Liz Kammer | daa09ef | 2021-12-15 15:35:38 -0500 | [diff] [blame] | 313 | "arch_paths": `[":dep__BP2BUILD__MISSING__DEP"]`, |
| 314 | }), |
| 315 | }, |
| 316 | }, |
| 317 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 318 | Description: "arch-variant srcs", |
| 319 | Blueprint: `custom { |
Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 320 | name: "arch_paths", |
| 321 | arch: { |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 322 | x86: { arch_paths: ["x86.txt"] }, |
| 323 | x86_64: { arch_paths: ["x86_64.txt"] }, |
| 324 | arm: { arch_paths: ["arm.txt"] }, |
| 325 | arm64: { arch_paths: ["arm64.txt"] }, |
| 326 | }, |
| 327 | target: { |
| 328 | linux: { arch_paths: ["linux.txt"] }, |
| 329 | bionic: { arch_paths: ["bionic.txt"] }, |
| 330 | host: { arch_paths: ["host.txt"] }, |
| 331 | not_windows: { arch_paths: ["not_windows.txt"] }, |
| 332 | android: { arch_paths: ["android.txt"] }, |
| 333 | linux_musl: { arch_paths: ["linux_musl.txt"] }, |
| 334 | musl: { arch_paths: ["musl.txt"] }, |
| 335 | linux_glibc: { arch_paths: ["linux_glibc.txt"] }, |
| 336 | glibc: { arch_paths: ["glibc.txt"] }, |
| 337 | linux_bionic: { arch_paths: ["linux_bionic.txt"] }, |
| 338 | darwin: { arch_paths: ["darwin.txt"] }, |
| 339 | windows: { arch_paths: ["windows.txt"] }, |
| 340 | }, |
| 341 | multilib: { |
| 342 | lib32: { arch_paths: ["lib32.txt"] }, |
| 343 | lib64: { arch_paths: ["lib64.txt"] }, |
Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 344 | }, |
| 345 | bazel_module: { bp2build_available: true }, |
| 346 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 347 | ExpectedBazelTargets: []string{ |
| 348 | makeBazelTarget("custom", "arch_paths", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 349 | "arch_paths": `select({ |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 350 | "//build/bazel/platforms/arch:arm": [ |
| 351 | "arm.txt", |
| 352 | "lib32.txt", |
| 353 | ], |
| 354 | "//build/bazel/platforms/arch:arm64": [ |
| 355 | "arm64.txt", |
| 356 | "lib64.txt", |
| 357 | ], |
| 358 | "//build/bazel/platforms/arch:x86": [ |
| 359 | "x86.txt", |
| 360 | "lib32.txt", |
| 361 | ], |
| 362 | "//build/bazel/platforms/arch:x86_64": [ |
| 363 | "x86_64.txt", |
| 364 | "lib64.txt", |
| 365 | ], |
| 366 | "//conditions:default": [], |
| 367 | }) + select({ |
| 368 | "//build/bazel/platforms/os:android": [ |
| 369 | "linux.txt", |
| 370 | "bionic.txt", |
| 371 | "android.txt", |
| 372 | ], |
| 373 | "//build/bazel/platforms/os:darwin": [ |
| 374 | "host.txt", |
| 375 | "darwin.txt", |
| 376 | "not_windows.txt", |
| 377 | ], |
| 378 | "//build/bazel/platforms/os:linux": [ |
| 379 | "host.txt", |
| 380 | "linux.txt", |
| 381 | "glibc.txt", |
| 382 | "linux_glibc.txt", |
| 383 | "not_windows.txt", |
| 384 | ], |
| 385 | "//build/bazel/platforms/os:linux_bionic": [ |
| 386 | "host.txt", |
| 387 | "linux.txt", |
| 388 | "bionic.txt", |
| 389 | "linux_bionic.txt", |
| 390 | "not_windows.txt", |
| 391 | ], |
| 392 | "//build/bazel/platforms/os:linux_musl": [ |
| 393 | "host.txt", |
| 394 | "linux.txt", |
| 395 | "musl.txt", |
| 396 | "linux_musl.txt", |
| 397 | "not_windows.txt", |
| 398 | ], |
| 399 | "//build/bazel/platforms/os:windows": [ |
| 400 | "host.txt", |
| 401 | "windows.txt", |
| 402 | ], |
Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 403 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 404 | })`, |
| 405 | }), |
Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 406 | }, |
| 407 | }, |
| 408 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 409 | Description: "arch-variant deps", |
| 410 | Blueprint: `custom { |
Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 411 | name: "has_dep", |
| 412 | arch: { |
| 413 | x86: { |
| 414 | arch_paths: [":dep"], |
| 415 | }, |
| 416 | }, |
| 417 | bazel_module: { bp2build_available: true }, |
| 418 | } |
| 419 | |
| 420 | custom { |
| 421 | name: "dep", |
| 422 | arch_paths: ["abc"], |
| 423 | bazel_module: { bp2build_available: true }, |
| 424 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 425 | ExpectedBazelTargets: []string{ |
| 426 | makeBazelTarget("custom", "dep", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 427 | "arch_paths": `["abc"]`, |
| 428 | }), |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 429 | makeBazelTarget("custom", "has_dep", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 430 | "arch_paths": `select({ |
Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 431 | "//build/bazel/platforms/arch:x86": [":dep"], |
| 432 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 433 | })`, |
| 434 | }), |
Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 435 | }, |
Jingwen Chen | 58a12b8 | 2021-03-30 13:08:36 +0000 | [diff] [blame] | 436 | }, |
Liz Kammer | 32a0339 | 2021-09-14 11:17:21 -0400 | [diff] [blame] | 437 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 438 | Description: "embedded props", |
| 439 | Blueprint: `custom { |
Liz Kammer | 32a0339 | 2021-09-14 11:17:21 -0400 | [diff] [blame] | 440 | name: "embedded_props", |
| 441 | embedded_prop: "abc", |
| 442 | bazel_module: { bp2build_available: true }, |
| 443 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 444 | ExpectedBazelTargets: []string{ |
| 445 | makeBazelTarget("custom", "embedded_props", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 446 | "embedded_attr": `"abc"`, |
| 447 | }), |
Liz Kammer | 32a0339 | 2021-09-14 11:17:21 -0400 | [diff] [blame] | 448 | }, |
| 449 | }, |
| 450 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 451 | Description: "ptr to embedded props", |
| 452 | Blueprint: `custom { |
Liz Kammer | 32a0339 | 2021-09-14 11:17:21 -0400 | [diff] [blame] | 453 | name: "ptr_to_embedded_props", |
| 454 | other_embedded_prop: "abc", |
| 455 | bazel_module: { bp2build_available: true }, |
| 456 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 457 | ExpectedBazelTargets: []string{ |
| 458 | makeBazelTarget("custom", "ptr_to_embedded_props", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 459 | "other_embedded_attr": `"abc"`, |
| 460 | }), |
Liz Kammer | 32a0339 | 2021-09-14 11:17:21 -0400 | [diff] [blame] | 461 | }, |
| 462 | }, |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | dir := "." |
| 466 | for _, testCase := range testCases { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 467 | t.Run(testCase.Description, func(t *testing.T) { |
| 468 | config := android.TestConfig(buildDir, nil, testCase.Blueprint, nil) |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 469 | ctx := android.NewTestContext(config) |
Jingwen Chen | 164e086 | 2021-02-19 00:48:40 -0500 | [diff] [blame] | 470 | |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 471 | registerCustomModuleForBp2buildConversion(ctx) |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 472 | |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 473 | _, errs := ctx.ParseFileList(dir, []string{"Android.bp"}) |
| 474 | if errored(t, testCase, errs) { |
| 475 | return |
| 476 | } |
| 477 | _, errs = ctx.ResolveDependencies(config) |
| 478 | if errored(t, testCase, errs) { |
| 479 | return |
| 480 | } |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 481 | |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 482 | codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) |
| 483 | bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir) |
| 484 | android.FailIfErrored(t, err) |
Jingwen Chen | 164e086 | 2021-02-19 00:48:40 -0500 | [diff] [blame] | 485 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 486 | if actualCount, expectedCount := len(bazelTargets), len(testCase.ExpectedBazelTargets); actualCount != expectedCount { |
| 487 | t.Errorf("Expected %d bazel target (%s),\ngot %d (%s)", expectedCount, testCase.ExpectedBazelTargets, actualCount, bazelTargets) |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 488 | } else { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 489 | for i, expectedBazelTarget := range testCase.ExpectedBazelTargets { |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 490 | actualBazelTarget := bazelTargets[i] |
| 491 | if actualBazelTarget.content != expectedBazelTarget { |
| 492 | t.Errorf( |
| 493 | "Expected generated Bazel target to be '%s', got '%s'", |
| 494 | expectedBazelTarget, |
| 495 | actualBazelTarget.content, |
| 496 | ) |
| 497 | } |
Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 498 | } |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 499 | } |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 500 | }) |
Liz Kammer | 2dd9ca4 | 2020-11-25 16:06:39 -0800 | [diff] [blame] | 501 | } |
| 502 | } |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 503 | |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 504 | func TestBp2buildHostAndDevice(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 505 | testCases := []Bp2buildTestCase{ |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 506 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 507 | Description: "host and device, device only", |
| 508 | ModuleTypeUnderTest: "custom", |
| 509 | ModuleTypeUnderTestFactory: customModuleFactoryHostAndDevice, |
| 510 | Blueprint: `custom { |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 511 | name: "foo", |
| 512 | bazel_module: { bp2build_available: true }, |
| 513 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 514 | ExpectedBazelTargets: []string{ |
| 515 | makeBazelTargetHostOrDevice("custom", "foo", AttrNameToString{}, android.DeviceSupported), |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 516 | }, |
| 517 | }, |
| 518 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 519 | Description: "host and device, both", |
| 520 | ModuleTypeUnderTest: "custom", |
| 521 | ModuleTypeUnderTestFactory: customModuleFactoryHostAndDevice, |
| 522 | Blueprint: `custom { |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 523 | name: "foo", |
| 524 | host_supported: true, |
| 525 | bazel_module: { bp2build_available: true }, |
| 526 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 527 | ExpectedBazelTargets: []string{ |
| 528 | MakeBazelTargetNoRestrictions("custom", "foo", AttrNameToString{}), |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 529 | }, |
| 530 | }, |
| 531 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 532 | Description: "host and device, host explicitly disabled", |
| 533 | ModuleTypeUnderTest: "custom", |
| 534 | ModuleTypeUnderTestFactory: customModuleFactoryHostAndDevice, |
| 535 | Blueprint: `custom { |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 536 | name: "foo", |
| 537 | host_supported: false, |
| 538 | bazel_module: { bp2build_available: true }, |
| 539 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 540 | ExpectedBazelTargets: []string{ |
| 541 | makeBazelTargetHostOrDevice("custom", "foo", AttrNameToString{}, android.DeviceSupported), |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 542 | }, |
| 543 | }, |
| 544 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 545 | Description: "host and device, neither", |
| 546 | ModuleTypeUnderTest: "custom", |
| 547 | ModuleTypeUnderTestFactory: customModuleFactoryHostAndDevice, |
| 548 | Blueprint: `custom { |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 549 | name: "foo", |
| 550 | host_supported: false, |
| 551 | device_supported: false, |
| 552 | bazel_module: { bp2build_available: true }, |
| 553 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 554 | ExpectedBazelTargets: []string{ |
| 555 | MakeBazelTargetNoRestrictions("custom", "foo", AttrNameToString{ |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 556 | "target_compatible_with": `["@platforms//:incompatible"]`, |
| 557 | }), |
| 558 | }, |
| 559 | }, |
| 560 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 561 | Description: "host and device, neither, cannot override with product_var", |
| 562 | ModuleTypeUnderTest: "custom", |
| 563 | ModuleTypeUnderTestFactory: customModuleFactoryHostAndDevice, |
| 564 | Blueprint: `custom { |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 565 | name: "foo", |
| 566 | host_supported: false, |
| 567 | device_supported: false, |
| 568 | product_variables: { unbundled_build: { enabled: true } }, |
| 569 | bazel_module: { bp2build_available: true }, |
| 570 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 571 | ExpectedBazelTargets: []string{ |
| 572 | MakeBazelTargetNoRestrictions("custom", "foo", AttrNameToString{ |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 573 | "target_compatible_with": `["@platforms//:incompatible"]`, |
| 574 | }), |
| 575 | }, |
| 576 | }, |
| 577 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 578 | Description: "host and device, both, disabled overrided with product_var", |
| 579 | ModuleTypeUnderTest: "custom", |
| 580 | ModuleTypeUnderTestFactory: customModuleFactoryHostAndDevice, |
| 581 | Blueprint: `custom { |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 582 | name: "foo", |
| 583 | host_supported: true, |
| 584 | device_supported: true, |
| 585 | enabled: false, |
| 586 | product_variables: { unbundled_build: { enabled: true } }, |
| 587 | bazel_module: { bp2build_available: true }, |
| 588 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 589 | ExpectedBazelTargets: []string{ |
| 590 | MakeBazelTargetNoRestrictions("custom", "foo", AttrNameToString{ |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 591 | "target_compatible_with": `["//build/bazel/product_variables:unbundled_build"]`, |
| 592 | }), |
| 593 | }, |
| 594 | }, |
| 595 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 596 | Description: "host and device, neither, cannot override with arch enabled", |
| 597 | ModuleTypeUnderTest: "custom", |
| 598 | ModuleTypeUnderTestFactory: customModuleFactoryHostAndDevice, |
| 599 | Blueprint: `custom { |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 600 | name: "foo", |
| 601 | host_supported: false, |
| 602 | device_supported: false, |
| 603 | arch: { x86: { enabled: true } }, |
| 604 | bazel_module: { bp2build_available: true }, |
| 605 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 606 | ExpectedBazelTargets: []string{ |
| 607 | MakeBazelTargetNoRestrictions("custom", "foo", AttrNameToString{ |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 608 | "target_compatible_with": `["@platforms//:incompatible"]`, |
| 609 | }), |
| 610 | }, |
| 611 | }, |
| 612 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 613 | Description: "host and device, host only", |
| 614 | ModuleTypeUnderTest: "custom", |
| 615 | ModuleTypeUnderTestFactory: customModuleFactoryHostAndDevice, |
| 616 | Blueprint: `custom { |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 617 | name: "foo", |
| 618 | host_supported: true, |
| 619 | device_supported: false, |
| 620 | bazel_module: { bp2build_available: true }, |
| 621 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 622 | ExpectedBazelTargets: []string{ |
| 623 | makeBazelTargetHostOrDevice("custom", "foo", AttrNameToString{}, android.HostSupported), |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 624 | }, |
| 625 | }, |
| 626 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 627 | Description: "host only", |
| 628 | ModuleTypeUnderTest: "custom", |
| 629 | ModuleTypeUnderTestFactory: customModuleFactoryHostSupported, |
| 630 | Blueprint: `custom { |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 631 | name: "foo", |
| 632 | bazel_module: { bp2build_available: true }, |
| 633 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 634 | ExpectedBazelTargets: []string{ |
| 635 | makeBazelTargetHostOrDevice("custom", "foo", AttrNameToString{}, android.HostSupported), |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 636 | }, |
| 637 | }, |
| 638 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 639 | Description: "device only", |
| 640 | ModuleTypeUnderTest: "custom", |
| 641 | ModuleTypeUnderTestFactory: customModuleFactoryDeviceSupported, |
| 642 | Blueprint: `custom { |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 643 | name: "foo", |
| 644 | bazel_module: { bp2build_available: true }, |
| 645 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 646 | ExpectedBazelTargets: []string{ |
| 647 | makeBazelTargetHostOrDevice("custom", "foo", AttrNameToString{}, android.DeviceSupported), |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 648 | }, |
| 649 | }, |
| 650 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 651 | Description: "host and device default, default", |
| 652 | ModuleTypeUnderTest: "custom", |
| 653 | ModuleTypeUnderTestFactory: customModuleFactoryHostAndDeviceDefault, |
| 654 | Blueprint: `custom { |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 655 | name: "foo", |
| 656 | bazel_module: { bp2build_available: true }, |
| 657 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 658 | ExpectedBazelTargets: []string{ |
| 659 | MakeBazelTargetNoRestrictions("custom", "foo", AttrNameToString{}), |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 660 | }, |
| 661 | }, |
| 662 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 663 | Description: "host and device default, device only", |
| 664 | ModuleTypeUnderTest: "custom", |
| 665 | ModuleTypeUnderTestFactory: customModuleFactoryHostAndDeviceDefault, |
| 666 | Blueprint: `custom { |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 667 | name: "foo", |
| 668 | host_supported: false, |
| 669 | bazel_module: { bp2build_available: true }, |
| 670 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 671 | ExpectedBazelTargets: []string{ |
| 672 | makeBazelTargetHostOrDevice("custom", "foo", AttrNameToString{}, android.DeviceSupported), |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 673 | }, |
| 674 | }, |
| 675 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 676 | Description: "host and device default, host only", |
| 677 | ModuleTypeUnderTest: "custom", |
| 678 | ModuleTypeUnderTestFactory: customModuleFactoryHostAndDeviceDefault, |
| 679 | Blueprint: `custom { |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 680 | name: "foo", |
| 681 | device_supported: false, |
| 682 | bazel_module: { bp2build_available: true }, |
| 683 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 684 | ExpectedBazelTargets: []string{ |
| 685 | makeBazelTargetHostOrDevice("custom", "foo", AttrNameToString{}, android.HostSupported), |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 686 | }, |
| 687 | }, |
| 688 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 689 | Description: "host and device default, neither", |
| 690 | ModuleTypeUnderTest: "custom", |
| 691 | ModuleTypeUnderTestFactory: customModuleFactoryHostAndDeviceDefault, |
| 692 | Blueprint: `custom { |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 693 | name: "foo", |
| 694 | host_supported: false, |
| 695 | device_supported: false, |
| 696 | bazel_module: { bp2build_available: true }, |
| 697 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 698 | ExpectedBazelTargets: []string{ |
| 699 | MakeBazelTargetNoRestrictions("custom", "foo", AttrNameToString{ |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 700 | "target_compatible_with": `["@platforms//:incompatible"]`, |
| 701 | }), |
| 702 | }, |
| 703 | }, |
| 704 | } |
| 705 | |
| 706 | for _, tc := range testCases { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 707 | t.Run(tc.Description, func(t *testing.T) { |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 708 | runBp2BuildTestCaseSimple(t, tc) |
| 709 | }) |
| 710 | } |
| 711 | } |
| 712 | |
Jingwen Chen | 40067de | 2021-01-26 21:58:43 -0500 | [diff] [blame] | 713 | func TestLoadStatements(t *testing.T) { |
| 714 | testCases := []struct { |
| 715 | bazelTargets BazelTargets |
| 716 | expectedLoadStatements string |
| 717 | }{ |
| 718 | { |
| 719 | bazelTargets: BazelTargets{ |
| 720 | BazelTarget{ |
| 721 | name: "foo", |
| 722 | ruleClass: "cc_library", |
| 723 | bzlLoadLocation: "//build/bazel/rules:cc.bzl", |
| 724 | }, |
| 725 | }, |
| 726 | expectedLoadStatements: `load("//build/bazel/rules:cc.bzl", "cc_library")`, |
| 727 | }, |
| 728 | { |
| 729 | bazelTargets: BazelTargets{ |
| 730 | BazelTarget{ |
| 731 | name: "foo", |
| 732 | ruleClass: "cc_library", |
| 733 | bzlLoadLocation: "//build/bazel/rules:cc.bzl", |
| 734 | }, |
| 735 | BazelTarget{ |
| 736 | name: "bar", |
| 737 | ruleClass: "cc_library", |
| 738 | bzlLoadLocation: "//build/bazel/rules:cc.bzl", |
| 739 | }, |
| 740 | }, |
| 741 | expectedLoadStatements: `load("//build/bazel/rules:cc.bzl", "cc_library")`, |
| 742 | }, |
| 743 | { |
| 744 | bazelTargets: BazelTargets{ |
| 745 | BazelTarget{ |
| 746 | name: "foo", |
| 747 | ruleClass: "cc_library", |
| 748 | bzlLoadLocation: "//build/bazel/rules:cc.bzl", |
| 749 | }, |
| 750 | BazelTarget{ |
| 751 | name: "bar", |
| 752 | ruleClass: "cc_binary", |
| 753 | bzlLoadLocation: "//build/bazel/rules:cc.bzl", |
| 754 | }, |
| 755 | }, |
| 756 | expectedLoadStatements: `load("//build/bazel/rules:cc.bzl", "cc_binary", "cc_library")`, |
| 757 | }, |
| 758 | { |
| 759 | bazelTargets: BazelTargets{ |
| 760 | BazelTarget{ |
| 761 | name: "foo", |
| 762 | ruleClass: "cc_library", |
| 763 | bzlLoadLocation: "//build/bazel/rules:cc.bzl", |
| 764 | }, |
| 765 | BazelTarget{ |
| 766 | name: "bar", |
| 767 | ruleClass: "cc_binary", |
| 768 | bzlLoadLocation: "//build/bazel/rules:cc.bzl", |
| 769 | }, |
| 770 | BazelTarget{ |
| 771 | name: "baz", |
| 772 | ruleClass: "java_binary", |
| 773 | bzlLoadLocation: "//build/bazel/rules:java.bzl", |
| 774 | }, |
| 775 | }, |
| 776 | expectedLoadStatements: `load("//build/bazel/rules:cc.bzl", "cc_binary", "cc_library") |
| 777 | load("//build/bazel/rules:java.bzl", "java_binary")`, |
| 778 | }, |
| 779 | { |
| 780 | bazelTargets: BazelTargets{ |
| 781 | BazelTarget{ |
| 782 | name: "foo", |
| 783 | ruleClass: "cc_binary", |
| 784 | bzlLoadLocation: "//build/bazel/rules:cc.bzl", |
| 785 | }, |
| 786 | BazelTarget{ |
| 787 | name: "bar", |
| 788 | ruleClass: "java_binary", |
| 789 | bzlLoadLocation: "//build/bazel/rules:java.bzl", |
| 790 | }, |
| 791 | BazelTarget{ |
| 792 | name: "baz", |
| 793 | ruleClass: "genrule", |
| 794 | // Note: no bzlLoadLocation for native rules |
| 795 | }, |
| 796 | }, |
| 797 | expectedLoadStatements: `load("//build/bazel/rules:cc.bzl", "cc_binary") |
| 798 | load("//build/bazel/rules:java.bzl", "java_binary")`, |
| 799 | }, |
| 800 | } |
| 801 | |
| 802 | for _, testCase := range testCases { |
| 803 | actual := testCase.bazelTargets.LoadStatements() |
| 804 | expected := testCase.expectedLoadStatements |
| 805 | if actual != expected { |
| 806 | t.Fatalf("Expected load statements to be %s, got %s", expected, actual) |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | } |
| 811 | |
| 812 | func TestGenerateBazelTargetModules_OneToMany_LoadedFromStarlark(t *testing.T) { |
| 813 | testCases := []struct { |
| 814 | bp string |
| 815 | expectedBazelTarget string |
| 816 | expectedBazelTargetCount int |
| 817 | expectedLoadStatements string |
| 818 | }{ |
| 819 | { |
| 820 | bp: `custom { |
| 821 | name: "bar", |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 822 | host_supported: true, |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 823 | one_to_many_prop: true, |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 824 | bazel_module: { bp2build_available: true }, |
Jingwen Chen | 40067de | 2021-01-26 21:58:43 -0500 | [diff] [blame] | 825 | }`, |
| 826 | expectedBazelTarget: `my_library( |
| 827 | name = "bar", |
| 828 | ) |
| 829 | |
Jingwen Chen | 40067de | 2021-01-26 21:58:43 -0500 | [diff] [blame] | 830 | proto_library( |
| 831 | name = "bar_proto_library_deps", |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 832 | ) |
| 833 | |
| 834 | my_proto_library( |
| 835 | name = "bar_my_proto_library_deps", |
Jingwen Chen | 40067de | 2021-01-26 21:58:43 -0500 | [diff] [blame] | 836 | )`, |
| 837 | expectedBazelTargetCount: 3, |
| 838 | expectedLoadStatements: `load("//build/bazel/rules:proto.bzl", "my_proto_library", "proto_library") |
| 839 | load("//build/bazel/rules:rules.bzl", "my_library")`, |
| 840 | }, |
| 841 | } |
| 842 | |
| 843 | dir := "." |
| 844 | for _, testCase := range testCases { |
| 845 | config := android.TestConfig(buildDir, nil, testCase.bp, nil) |
| 846 | ctx := android.NewTestContext(config) |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 847 | ctx.RegisterModuleType("custom", customModuleFactoryHostAndDevice) |
Jingwen Chen | 40067de | 2021-01-26 21:58:43 -0500 | [diff] [blame] | 848 | ctx.RegisterForBazelConversion() |
| 849 | |
| 850 | _, errs := ctx.ParseFileList(dir, []string{"Android.bp"}) |
| 851 | android.FailIfErrored(t, errs) |
| 852 | _, errs = ctx.ResolveDependencies(config) |
| 853 | android.FailIfErrored(t, errs) |
| 854 | |
Jingwen Chen | 164e086 | 2021-02-19 00:48:40 -0500 | [diff] [blame] | 855 | codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 856 | bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir) |
| 857 | android.FailIfErrored(t, err) |
Jingwen Chen | 40067de | 2021-01-26 21:58:43 -0500 | [diff] [blame] | 858 | if actualCount := len(bazelTargets); actualCount != testCase.expectedBazelTargetCount { |
| 859 | t.Fatalf("Expected %d bazel target, got %d", testCase.expectedBazelTargetCount, actualCount) |
| 860 | } |
| 861 | |
| 862 | actualBazelTargets := bazelTargets.String() |
| 863 | if actualBazelTargets != testCase.expectedBazelTarget { |
| 864 | t.Errorf( |
| 865 | "Expected generated Bazel target to be '%s', got '%s'", |
| 866 | testCase.expectedBazelTarget, |
| 867 | actualBazelTargets, |
| 868 | ) |
| 869 | } |
| 870 | |
| 871 | actualLoadStatements := bazelTargets.LoadStatements() |
| 872 | if actualLoadStatements != testCase.expectedLoadStatements { |
| 873 | t.Errorf( |
| 874 | "Expected generated load statements to be '%s', got '%s'", |
| 875 | testCase.expectedLoadStatements, |
| 876 | actualLoadStatements, |
| 877 | ) |
| 878 | } |
| 879 | } |
| 880 | } |
| 881 | |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 882 | func TestModuleTypeBp2Build(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 883 | testCases := []Bp2buildTestCase{ |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 884 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 885 | Description: "filegroup with does not specify srcs", |
| 886 | ModuleTypeUnderTest: "filegroup", |
| 887 | ModuleTypeUnderTestFactory: android.FileGroupFactory, |
| 888 | Blueprint: `filegroup { |
Liz Kammer | ebfcf67 | 2021-02-16 15:00:05 -0500 | [diff] [blame] | 889 | name: "fg_foo", |
| 890 | bazel_module: { bp2build_available: true }, |
| 891 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 892 | ExpectedBazelTargets: []string{ |
| 893 | MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{}), |
Liz Kammer | ebfcf67 | 2021-02-16 15:00:05 -0500 | [diff] [blame] | 894 | }, |
| 895 | }, |
| 896 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 897 | Description: "filegroup with no srcs", |
| 898 | ModuleTypeUnderTest: "filegroup", |
| 899 | ModuleTypeUnderTestFactory: android.FileGroupFactory, |
| 900 | Blueprint: `filegroup { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 901 | name: "fg_foo", |
| 902 | srcs: [], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 903 | bazel_module: { bp2build_available: true }, |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 904 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 905 | ExpectedBazelTargets: []string{ |
| 906 | MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{}), |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 907 | }, |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 908 | }, |
| 909 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 910 | Description: "filegroup with srcs", |
| 911 | ModuleTypeUnderTest: "filegroup", |
| 912 | ModuleTypeUnderTestFactory: android.FileGroupFactory, |
| 913 | Blueprint: `filegroup { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 914 | name: "fg_foo", |
| 915 | srcs: ["a", "b"], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 916 | bazel_module: { bp2build_available: true }, |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 917 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 918 | ExpectedBazelTargets: []string{ |
| 919 | MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 920 | "srcs": `[ |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 921 | "a", |
| 922 | "b", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 923 | ]`, |
| 924 | }), |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 925 | }, |
| 926 | }, |
| 927 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 928 | Description: "filegroup with excludes srcs", |
| 929 | ModuleTypeUnderTest: "filegroup", |
| 930 | ModuleTypeUnderTestFactory: android.FileGroupFactory, |
| 931 | Blueprint: `filegroup { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 932 | name: "fg_foo", |
| 933 | srcs: ["a", "b"], |
| 934 | exclude_srcs: ["a"], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 935 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 936 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 937 | ExpectedBazelTargets: []string{ |
| 938 | MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 939 | "srcs": `["b"]`, |
| 940 | }), |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 941 | }, |
| 942 | }, |
| 943 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 944 | Description: "filegroup with glob", |
| 945 | ModuleTypeUnderTest: "filegroup", |
| 946 | ModuleTypeUnderTestFactory: android.FileGroupFactory, |
| 947 | Blueprint: `filegroup { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 948 | name: "fg_foo", |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 949 | srcs: ["**/*.txt"], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 950 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 951 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 952 | ExpectedBazelTargets: []string{ |
| 953 | MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 954 | "srcs": `[ |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 955 | "other/a.txt", |
| 956 | "other/b.txt", |
| 957 | "other/subdir/a.txt", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 958 | ]`, |
| 959 | }), |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 960 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 961 | Filesystem: map[string]string{ |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 962 | "other/a.txt": "", |
| 963 | "other/b.txt": "", |
| 964 | "other/subdir/a.txt": "", |
| 965 | "other/file": "", |
| 966 | }, |
| 967 | }, |
| 968 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 969 | Description: "filegroup with glob in subdir", |
| 970 | ModuleTypeUnderTest: "filegroup", |
| 971 | ModuleTypeUnderTestFactory: android.FileGroupFactory, |
| 972 | Dir: "other", |
| 973 | Filesystem: map[string]string{ |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 974 | "other/Android.bp": `filegroup { |
| 975 | name: "fg_foo", |
| 976 | srcs: ["**/*.txt"], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 977 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 978 | }`, |
| 979 | "other/a.txt": "", |
| 980 | "other/b.txt": "", |
| 981 | "other/subdir/a.txt": "", |
| 982 | "other/file": "", |
| 983 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 984 | ExpectedBazelTargets: []string{ |
| 985 | MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 986 | "srcs": `[ |
| 987 | "a.txt", |
| 988 | "b.txt", |
| 989 | "subdir/a.txt", |
| 990 | ]`, |
| 991 | }), |
| 992 | }, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 993 | }, |
| 994 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 995 | Description: "depends_on_other_dir_module", |
| 996 | ModuleTypeUnderTest: "filegroup", |
| 997 | ModuleTypeUnderTestFactory: android.FileGroupFactory, |
| 998 | Blueprint: `filegroup { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 999 | name: "fg_foo", |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 1000 | srcs: [ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 1001 | ":foo", |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 1002 | "c", |
| 1003 | ], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 1004 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 1005 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1006 | Filesystem: map[string]string{ |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 1007 | "other/Android.bp": `filegroup { |
| 1008 | name: "foo", |
| 1009 | srcs: ["a", "b"], |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 1010 | bazel_module: { bp2build_available: true }, |
| 1011 | }`, |
| 1012 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1013 | ExpectedBazelTargets: []string{ |
| 1014 | MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1015 | "srcs": `[ |
| 1016 | "//other:foo", |
| 1017 | "c", |
| 1018 | ]`, |
| 1019 | }), |
| 1020 | }, |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 1021 | }, |
| 1022 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1023 | Description: "depends_on_other_unconverted_module_error", |
| 1024 | ModuleTypeUnderTest: "filegroup", |
| 1025 | ModuleTypeUnderTestFactory: android.FileGroupFactory, |
| 1026 | UnconvertedDepsMode: errorModulesUnconvertedDeps, |
| 1027 | Blueprint: `filegroup { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1028 | name: "foobar", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1029 | srcs: [ |
| 1030 | ":foo", |
| 1031 | "c", |
| 1032 | ], |
| 1033 | bazel_module: { bp2build_available: true }, |
| 1034 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1035 | ExpectedErr: fmt.Errorf(`"foobar" depends on unconverted modules: foo`), |
| 1036 | Filesystem: map[string]string{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1037 | "other/Android.bp": `filegroup { |
| 1038 | name: "foo", |
| 1039 | srcs: ["a", "b"], |
| 1040 | }`, |
| 1041 | }, |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 1042 | }, |
| 1043 | } |
| 1044 | |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 1045 | for _, testCase := range testCases { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1046 | t.Run(testCase.Description, func(t *testing.T) { |
| 1047 | RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, testCase) |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 1048 | }) |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 1049 | } |
| 1050 | } |
Jingwen Chen | 041b184 | 2021-02-01 00:23:25 -0500 | [diff] [blame] | 1051 | |
| 1052 | type bp2buildMutator = func(android.TopDownMutatorContext) |
| 1053 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 1054 | func TestAllowlistingBp2buildTargetsExplicitly(t *testing.T) { |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 1055 | testCases := []struct { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1056 | moduleTypeUnderTest string |
| 1057 | moduleTypeUnderTestFactory android.ModuleFactory |
| 1058 | bp string |
| 1059 | expectedCount int |
| 1060 | description string |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 1061 | }{ |
| 1062 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1063 | description: "explicitly unavailable", |
| 1064 | moduleTypeUnderTest: "filegroup", |
| 1065 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 1066 | bp: `filegroup { |
| 1067 | name: "foo", |
| 1068 | srcs: ["a", "b"], |
| 1069 | bazel_module: { bp2build_available: false }, |
| 1070 | }`, |
| 1071 | expectedCount: 0, |
| 1072 | }, |
| 1073 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1074 | description: "implicitly unavailable", |
| 1075 | moduleTypeUnderTest: "filegroup", |
| 1076 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 1077 | bp: `filegroup { |
| 1078 | name: "foo", |
| 1079 | srcs: ["a", "b"], |
| 1080 | }`, |
| 1081 | expectedCount: 0, |
| 1082 | }, |
| 1083 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1084 | description: "explicitly available", |
| 1085 | moduleTypeUnderTest: "filegroup", |
| 1086 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 1087 | bp: `filegroup { |
| 1088 | name: "foo", |
| 1089 | srcs: ["a", "b"], |
| 1090 | bazel_module: { bp2build_available: true }, |
| 1091 | }`, |
| 1092 | expectedCount: 1, |
| 1093 | }, |
| 1094 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1095 | description: "generates more than 1 target if needed", |
| 1096 | moduleTypeUnderTest: "custom", |
Liz Kammer | dfeb120 | 2022-05-13 17:20:20 -0400 | [diff] [blame] | 1097 | moduleTypeUnderTestFactory: customModuleFactoryHostAndDevice, |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 1098 | bp: `custom { |
| 1099 | name: "foo", |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1100 | one_to_many_prop: true, |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 1101 | bazel_module: { bp2build_available: true }, |
| 1102 | }`, |
| 1103 | expectedCount: 3, |
| 1104 | }, |
| 1105 | } |
| 1106 | |
| 1107 | dir := "." |
| 1108 | for _, testCase := range testCases { |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 1109 | t.Run(testCase.description, func(t *testing.T) { |
| 1110 | config := android.TestConfig(buildDir, nil, testCase.bp, nil) |
| 1111 | ctx := android.NewTestContext(config) |
| 1112 | ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory) |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 1113 | ctx.RegisterForBazelConversion() |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 1114 | |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 1115 | _, errs := ctx.ParseFileList(dir, []string{"Android.bp"}) |
| 1116 | android.FailIfErrored(t, errs) |
| 1117 | _, errs = ctx.ResolveDependencies(config) |
| 1118 | android.FailIfErrored(t, errs) |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 1119 | |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 1120 | codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 1121 | bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir) |
| 1122 | android.FailIfErrored(t, err) |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 1123 | if actualCount := len(bazelTargets); actualCount != testCase.expectedCount { |
| 1124 | t.Fatalf("%s: Expected %d bazel target, got %d", testCase.description, testCase.expectedCount, actualCount) |
| 1125 | } |
| 1126 | }) |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 1127 | } |
| 1128 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1129 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 1130 | func TestAllowlistingBp2buildTargetsWithConfig(t *testing.T) { |
| 1131 | testCases := []struct { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1132 | moduleTypeUnderTest string |
| 1133 | moduleTypeUnderTestFactory android.ModuleFactory |
| 1134 | expectedCount map[string]int |
| 1135 | description string |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame] | 1136 | bp2buildConfig allowlists.Bp2BuildConfig |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1137 | checkDir string |
| 1138 | fs map[string]string |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 1139 | }{ |
| 1140 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1141 | description: "test bp2build config package and subpackages config", |
| 1142 | moduleTypeUnderTest: "filegroup", |
| 1143 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 1144 | expectedCount: map[string]int{ |
| 1145 | "migrated": 1, |
| 1146 | "migrated/but_not_really": 0, |
| 1147 | "migrated/but_not_really/but_really": 1, |
| 1148 | "not_migrated": 0, |
| 1149 | "also_not_migrated": 0, |
| 1150 | }, |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame] | 1151 | bp2buildConfig: allowlists.Bp2BuildConfig{ |
| 1152 | "migrated": allowlists.Bp2BuildDefaultTrueRecursively, |
| 1153 | "migrated/but_not_really": allowlists.Bp2BuildDefaultFalse, |
| 1154 | "not_migrated": allowlists.Bp2BuildDefaultFalse, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 1155 | }, |
| 1156 | fs: map[string]string{ |
| 1157 | "migrated/Android.bp": `filegroup { name: "a" }`, |
| 1158 | "migrated/but_not_really/Android.bp": `filegroup { name: "b" }`, |
| 1159 | "migrated/but_not_really/but_really/Android.bp": `filegroup { name: "c" }`, |
| 1160 | "not_migrated/Android.bp": `filegroup { name: "d" }`, |
| 1161 | "also_not_migrated/Android.bp": `filegroup { name: "e" }`, |
| 1162 | }, |
| 1163 | }, |
| 1164 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1165 | description: "test bp2build config opt-in and opt-out", |
| 1166 | moduleTypeUnderTest: "filegroup", |
| 1167 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 1168 | expectedCount: map[string]int{ |
| 1169 | "package-opt-in": 2, |
| 1170 | "package-opt-in/subpackage": 0, |
| 1171 | "package-opt-out": 1, |
| 1172 | "package-opt-out/subpackage": 0, |
| 1173 | }, |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame] | 1174 | bp2buildConfig: allowlists.Bp2BuildConfig{ |
| 1175 | "package-opt-in": allowlists.Bp2BuildDefaultFalse, |
| 1176 | "package-opt-out": allowlists.Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 1177 | }, |
| 1178 | fs: map[string]string{ |
| 1179 | "package-opt-in/Android.bp": ` |
| 1180 | filegroup { name: "opt-in-a" } |
| 1181 | filegroup { name: "opt-in-b", bazel_module: { bp2build_available: true } } |
| 1182 | filegroup { name: "opt-in-c", bazel_module: { bp2build_available: true } } |
| 1183 | `, |
| 1184 | |
| 1185 | "package-opt-in/subpackage/Android.bp": ` |
| 1186 | filegroup { name: "opt-in-d" } // parent package not configured to DefaultTrueRecursively |
| 1187 | `, |
| 1188 | |
| 1189 | "package-opt-out/Android.bp": ` |
| 1190 | filegroup { name: "opt-out-a" } |
| 1191 | filegroup { name: "opt-out-b", bazel_module: { bp2build_available: false } } |
| 1192 | filegroup { name: "opt-out-c", bazel_module: { bp2build_available: false } } |
| 1193 | `, |
| 1194 | |
| 1195 | "package-opt-out/subpackage/Android.bp": ` |
| 1196 | filegroup { name: "opt-out-g", bazel_module: { bp2build_available: false } } |
| 1197 | filegroup { name: "opt-out-h", bazel_module: { bp2build_available: false } } |
| 1198 | `, |
| 1199 | }, |
| 1200 | }, |
| 1201 | } |
| 1202 | |
| 1203 | dir := "." |
| 1204 | for _, testCase := range testCases { |
| 1205 | fs := make(map[string][]byte) |
| 1206 | toParse := []string{ |
| 1207 | "Android.bp", |
| 1208 | } |
| 1209 | for f, content := range testCase.fs { |
| 1210 | if strings.HasSuffix(f, "Android.bp") { |
| 1211 | toParse = append(toParse, f) |
| 1212 | } |
| 1213 | fs[f] = []byte(content) |
| 1214 | } |
| 1215 | config := android.TestConfig(buildDir, nil, "", fs) |
| 1216 | ctx := android.NewTestContext(config) |
| 1217 | ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory) |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame] | 1218 | allowlist := android.NewBp2BuildAllowlist().SetDefaultConfig(testCase.bp2buildConfig) |
| 1219 | ctx.RegisterBp2BuildConfig(allowlist) |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 1220 | ctx.RegisterForBazelConversion() |
| 1221 | |
| 1222 | _, errs := ctx.ParseFileList(dir, toParse) |
| 1223 | android.FailIfErrored(t, errs) |
| 1224 | _, errs = ctx.ResolveDependencies(config) |
| 1225 | android.FailIfErrored(t, errs) |
| 1226 | |
| 1227 | codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) |
| 1228 | |
| 1229 | // For each directory, test that the expected number of generated targets is correct. |
| 1230 | for dir, expectedCount := range testCase.expectedCount { |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 1231 | bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir) |
| 1232 | android.FailIfErrored(t, err) |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 1233 | if actualCount := len(bazelTargets); actualCount != expectedCount { |
| 1234 | t.Fatalf( |
| 1235 | "%s: Expected %d bazel target for %s package, got %d", |
| 1236 | testCase.description, |
| 1237 | expectedCount, |
| 1238 | dir, |
| 1239 | actualCount) |
| 1240 | } |
| 1241 | |
| 1242 | } |
| 1243 | } |
| 1244 | } |
| 1245 | |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1246 | func TestCombineBuildFilesBp2buildTargets(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1247 | testCases := []Bp2buildTestCase{ |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1248 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1249 | Description: "filegroup bazel_module.label", |
| 1250 | ModuleTypeUnderTest: "filegroup", |
| 1251 | ModuleTypeUnderTestFactory: android.FileGroupFactory, |
| 1252 | Blueprint: `filegroup { |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1253 | name: "fg_foo", |
| 1254 | bazel_module: { label: "//other:fg_foo" }, |
| 1255 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1256 | ExpectedBazelTargets: []string{ |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1257 | `// BUILD file`, |
| 1258 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1259 | Filesystem: map[string]string{ |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1260 | "other/BUILD.bazel": `// BUILD file`, |
| 1261 | }, |
| 1262 | }, |
| 1263 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1264 | Description: "multiple bazel_module.label same BUILD", |
| 1265 | ModuleTypeUnderTest: "filegroup", |
| 1266 | ModuleTypeUnderTestFactory: android.FileGroupFactory, |
| 1267 | Blueprint: `filegroup { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1268 | name: "fg_foo", |
| 1269 | bazel_module: { label: "//other:fg_foo" }, |
| 1270 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1271 | |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1272 | filegroup { |
| 1273 | name: "foo", |
| 1274 | bazel_module: { label: "//other:foo" }, |
| 1275 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1276 | ExpectedBazelTargets: []string{ |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1277 | `// BUILD file`, |
| 1278 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1279 | Filesystem: map[string]string{ |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1280 | "other/BUILD.bazel": `// BUILD file`, |
| 1281 | }, |
| 1282 | }, |
| 1283 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1284 | Description: "filegroup bazel_module.label and bp2build in subdir", |
| 1285 | ModuleTypeUnderTest: "filegroup", |
| 1286 | ModuleTypeUnderTestFactory: android.FileGroupFactory, |
| 1287 | Dir: "other", |
| 1288 | Blueprint: ``, |
| 1289 | Filesystem: map[string]string{ |
Jingwen Chen | c63677b | 2021-06-17 05:43:19 +0000 | [diff] [blame] | 1290 | "other/Android.bp": `filegroup { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1291 | name: "fg_foo", |
| 1292 | bazel_module: { |
| 1293 | bp2build_available: true, |
| 1294 | }, |
| 1295 | } |
| 1296 | filegroup { |
| 1297 | name: "fg_bar", |
| 1298 | bazel_module: { |
| 1299 | label: "//other:fg_bar" |
| 1300 | }, |
| 1301 | }`, |
Jingwen Chen | c63677b | 2021-06-17 05:43:19 +0000 | [diff] [blame] | 1302 | "other/BUILD.bazel": `// definition for fg_bar`, |
| 1303 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1304 | ExpectedBazelTargets: []string{ |
| 1305 | MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{}), |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1306 | `// definition for fg_bar`, |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1307 | }, |
| 1308 | }, |
| 1309 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1310 | Description: "filegroup bazel_module.label and filegroup bp2build", |
| 1311 | ModuleTypeUnderTest: "filegroup", |
| 1312 | ModuleTypeUnderTestFactory: android.FileGroupFactory, |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1313 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1314 | Filesystem: map[string]string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1315 | "other/BUILD.bazel": `// BUILD file`, |
| 1316 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1317 | Blueprint: `filegroup { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1318 | name: "fg_foo", |
| 1319 | bazel_module: { |
| 1320 | label: "//other:fg_foo", |
| 1321 | }, |
| 1322 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1323 | |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1324 | filegroup { |
| 1325 | name: "fg_bar", |
| 1326 | bazel_module: { |
| 1327 | bp2build_available: true, |
| 1328 | }, |
| 1329 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1330 | ExpectedBazelTargets: []string{ |
| 1331 | MakeBazelTargetNoRestrictions("filegroup", "fg_bar", map[string]string{}), |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1332 | `// BUILD file`, |
| 1333 | }, |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1334 | }, |
| 1335 | } |
| 1336 | |
| 1337 | dir := "." |
| 1338 | for _, testCase := range testCases { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1339 | t.Run(testCase.Description, func(t *testing.T) { |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1340 | fs := make(map[string][]byte) |
| 1341 | toParse := []string{ |
| 1342 | "Android.bp", |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1343 | } |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1344 | for f, content := range testCase.Filesystem { |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1345 | if strings.HasSuffix(f, "Android.bp") { |
| 1346 | toParse = append(toParse, f) |
| 1347 | } |
| 1348 | fs[f] = []byte(content) |
| 1349 | } |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1350 | config := android.TestConfig(buildDir, nil, testCase.Blueprint, fs) |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1351 | ctx := android.NewTestContext(config) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1352 | ctx.RegisterModuleType(testCase.ModuleTypeUnderTest, testCase.ModuleTypeUnderTestFactory) |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1353 | ctx.RegisterForBazelConversion() |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1354 | |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1355 | _, errs := ctx.ParseFileList(dir, toParse) |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1356 | if errored(t, testCase, errs) { |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1357 | return |
| 1358 | } |
| 1359 | _, errs = ctx.ResolveDependencies(config) |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1360 | if errored(t, testCase, errs) { |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1361 | return |
| 1362 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1363 | |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1364 | checkDir := dir |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1365 | if testCase.Dir != "" { |
| 1366 | checkDir = testCase.Dir |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1367 | } |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 1368 | codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) |
| 1369 | bazelTargets, err := generateBazelTargetsForDir(codegenCtx, checkDir) |
| 1370 | android.FailIfErrored(t, err) |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1371 | bazelTargets.sort() |
| 1372 | actualCount := len(bazelTargets) |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1373 | expectedCount := len(testCase.ExpectedBazelTargets) |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1374 | if actualCount != expectedCount { |
| 1375 | t.Errorf("Expected %d bazel target, got %d\n%s", expectedCount, actualCount, bazelTargets) |
| 1376 | } |
| 1377 | if !strings.Contains(bazelTargets.String(), "Section: Handcrafted targets. ") { |
| 1378 | t.Errorf("Expected string representation of bazelTargets to contain handcrafted section header.") |
| 1379 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1380 | for i, target := range bazelTargets { |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1381 | actualContent := target.content |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1382 | expectedContent := testCase.ExpectedBazelTargets[i] |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1383 | if expectedContent != actualContent { |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1384 | t.Errorf( |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1385 | "Expected generated Bazel target to be '%s', got '%s'", |
| 1386 | expectedContent, |
| 1387 | actualContent, |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1388 | ) |
| 1389 | } |
| 1390 | } |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1391 | }) |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1392 | } |
| 1393 | } |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1394 | |
| 1395 | func TestGlobExcludeSrcs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1396 | testCases := []Bp2buildTestCase{ |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1397 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1398 | Description: "filegroup top level exclude_srcs", |
| 1399 | ModuleTypeUnderTest: "filegroup", |
| 1400 | ModuleTypeUnderTestFactory: android.FileGroupFactory, |
| 1401 | Blueprint: `filegroup { |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1402 | name: "fg_foo", |
| 1403 | srcs: ["**/*.txt"], |
| 1404 | exclude_srcs: ["c.txt"], |
| 1405 | bazel_module: { bp2build_available: true }, |
| 1406 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1407 | Filesystem: map[string]string{ |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1408 | "a.txt": "", |
| 1409 | "b.txt": "", |
| 1410 | "c.txt": "", |
| 1411 | "dir/Android.bp": "", |
| 1412 | "dir/e.txt": "", |
| 1413 | "dir/f.txt": "", |
| 1414 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1415 | ExpectedBazelTargets: []string{ |
| 1416 | MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1417 | "srcs": `[ |
| 1418 | "a.txt", |
| 1419 | "b.txt", |
| 1420 | "//dir:e.txt", |
| 1421 | "//dir:f.txt", |
| 1422 | ]`, |
| 1423 | }), |
| 1424 | }, |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1425 | }, |
| 1426 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1427 | Description: "filegroup in subdir exclude_srcs", |
| 1428 | ModuleTypeUnderTest: "filegroup", |
| 1429 | ModuleTypeUnderTestFactory: android.FileGroupFactory, |
| 1430 | Blueprint: "", |
| 1431 | Dir: "dir", |
| 1432 | Filesystem: map[string]string{ |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1433 | "dir/Android.bp": `filegroup { |
| 1434 | name: "fg_foo", |
| 1435 | srcs: ["**/*.txt"], |
| 1436 | exclude_srcs: ["b.txt"], |
| 1437 | bazel_module: { bp2build_available: true }, |
| 1438 | } |
| 1439 | `, |
| 1440 | "dir/a.txt": "", |
| 1441 | "dir/b.txt": "", |
| 1442 | "dir/subdir/Android.bp": "", |
| 1443 | "dir/subdir/e.txt": "", |
| 1444 | "dir/subdir/f.txt": "", |
| 1445 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1446 | ExpectedBazelTargets: []string{ |
| 1447 | MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1448 | "srcs": `[ |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 1449 | "a.txt", |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1450 | "//dir/subdir:e.txt", |
| 1451 | "//dir/subdir:f.txt", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1452 | ]`, |
| 1453 | }), |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1454 | }, |
| 1455 | }, |
| 1456 | } |
| 1457 | |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1458 | for _, testCase := range testCases { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1459 | t.Run(testCase.Description, func(t *testing.T) { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1460 | runBp2BuildTestCaseSimple(t, testCase) |
| 1461 | }) |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1462 | } |
| 1463 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1464 | |
| 1465 | func TestCommonBp2BuildModuleAttrs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1466 | testCases := []Bp2buildTestCase{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1467 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1468 | Description: "Required into data test", |
| 1469 | ModuleTypeUnderTest: "filegroup", |
| 1470 | ModuleTypeUnderTestFactory: android.FileGroupFactory, |
| 1471 | Blueprint: simpleModuleDoNotConvertBp2build("filegroup", "reqd") + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1472 | filegroup { |
| 1473 | name: "fg_foo", |
| 1474 | required: ["reqd"], |
| 1475 | bazel_module: { bp2build_available: true }, |
| 1476 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1477 | ExpectedBazelTargets: []string{ |
| 1478 | MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1479 | "data": `[":reqd"]`, |
| 1480 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1481 | }, |
| 1482 | }, |
| 1483 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1484 | Description: "Required via arch into data test", |
| 1485 | ModuleTypeUnderTest: "python_library", |
| 1486 | ModuleTypeUnderTestFactory: python.PythonLibraryFactory, |
| 1487 | Blueprint: simpleModuleDoNotConvertBp2build("python_library", "reqdx86") + |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1488 | simpleModuleDoNotConvertBp2build("python_library", "reqdarm") + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1489 | python_library { |
| 1490 | name: "fg_foo", |
| 1491 | arch: { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1492 | arm: { |
| 1493 | required: ["reqdarm"], |
| 1494 | }, |
| 1495 | x86: { |
| 1496 | required: ["reqdx86"], |
| 1497 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1498 | }, |
| 1499 | bazel_module: { bp2build_available: true }, |
| 1500 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1501 | ExpectedBazelTargets: []string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1502 | makeBazelTarget("py_library", "fg_foo", map[string]string{ |
| 1503 | "data": `select({ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1504 | "//build/bazel/platforms/arch:arm": [":reqdarm"], |
| 1505 | "//build/bazel/platforms/arch:x86": [":reqdx86"], |
| 1506 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1507 | })`, |
| 1508 | "srcs_version": `"PY3"`, |
Cole Faust | b09da7e | 2022-05-18 10:57:33 -0700 | [diff] [blame] | 1509 | "imports": `["."]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1510 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1511 | }, |
| 1512 | }, |
| 1513 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1514 | Description: "Required appended to data test", |
| 1515 | ModuleTypeUnderTest: "python_library", |
| 1516 | ModuleTypeUnderTestFactory: python.PythonLibraryFactory, |
| 1517 | Filesystem: map[string]string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1518 | "data.bin": "", |
| 1519 | "src.py": "", |
| 1520 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1521 | Blueprint: simpleModuleDoNotConvertBp2build("python_library", "reqd") + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1522 | python_library { |
| 1523 | name: "fg_foo", |
| 1524 | data: ["data.bin"], |
| 1525 | required: ["reqd"], |
| 1526 | bazel_module: { bp2build_available: true }, |
| 1527 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1528 | ExpectedBazelTargets: []string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1529 | makeBazelTarget("py_library", "fg_foo", map[string]string{ |
| 1530 | "data": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1531 | "data.bin", |
| 1532 | ":reqd", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1533 | ]`, |
| 1534 | "srcs_version": `"PY3"`, |
Cole Faust | b09da7e | 2022-05-18 10:57:33 -0700 | [diff] [blame] | 1535 | "imports": `["."]`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1536 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1537 | }, |
| 1538 | }, |
| 1539 | { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1540 | Description: "All props-to-attrs at once together test", |
| 1541 | ModuleTypeUnderTest: "filegroup", |
| 1542 | ModuleTypeUnderTestFactory: android.FileGroupFactory, |
| 1543 | Blueprint: simpleModuleDoNotConvertBp2build("filegroup", "reqd") + ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1544 | filegroup { |
| 1545 | name: "fg_foo", |
| 1546 | required: ["reqd"], |
| 1547 | bazel_module: { bp2build_available: true }, |
| 1548 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1549 | ExpectedBazelTargets: []string{ |
| 1550 | MakeBazelTargetNoRestrictions("filegroup", "fg_foo", map[string]string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1551 | "data": `[":reqd"]`, |
| 1552 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1553 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1554 | }, |
| 1555 | } |
| 1556 | |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1557 | for _, tc := range testCases { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 1558 | t.Run(tc.Description, func(t *testing.T) { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1559 | runBp2BuildTestCaseSimple(t, tc) |
| 1560 | }) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1561 | } |
| 1562 | } |