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