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 | d366c90 | 2021-06-03 13:43:01 -0400 | [diff] [blame] | 204 | ctx.RegisterModuleType("custom", customModuleFactory) |
| 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) { |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 232 | testCases := []bp2buildTestCase{ |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 233 | { |
Liz Kammer | 46fb7ab | 2021-12-01 10:09:34 -0500 | [diff] [blame] | 234 | description: "string ptr props", |
| 235 | blueprint: `custom { |
| 236 | name: "foo", |
| 237 | string_ptr_prop: "", |
| 238 | bazel_module: { bp2build_available: true }, |
| 239 | }`, |
| 240 | expectedBazelTargets: []string{ |
| 241 | makeBazelTarget("custom", "foo", attrNameToString{ |
| 242 | "string_ptr_prop": `""`, |
| 243 | }), |
| 244 | }, |
| 245 | }, |
| 246 | { |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 247 | description: "string props", |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 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 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 254 | expectedBazelTargets: []string{ |
| 255 | makeBazelTarget("custom", "foo", attrNameToString{ |
| 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 | { |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 265 | description: "control characters", |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 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 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 272 | expectedBazelTargets: []string{ |
| 273 | makeBazelTarget("custom", "foo", attrNameToString{ |
| 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 | { |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 283 | description: "handles dep", |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 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 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 295 | expectedBazelTargets: []string{ |
| 296 | makeBazelTarget("custom", "dep", attrNameToString{ |
| 297 | "arch_paths": `["abc"]`, |
| 298 | }), |
| 299 | makeBazelTarget("custom", "has_dep", attrNameToString{ |
| 300 | "arch_paths": `[":dep"]`, |
| 301 | }), |
Liz Kammer | 4562a3b | 2021-04-21 18:15:34 -0400 | [diff] [blame] | 302 | }, |
| 303 | }, |
| 304 | { |
Liz Kammer | daa09ef | 2021-12-15 15:35:38 -0500 | [diff] [blame] | 305 | description: "non-existent dep", |
| 306 | blueprint: `custom { |
| 307 | name: "has_dep", |
| 308 | arch_paths: [":dep"], |
| 309 | bazel_module: { bp2build_available: true }, |
| 310 | }`, |
| 311 | expectedBazelTargets: []string{ |
| 312 | makeBazelTarget("custom", "has_dep", attrNameToString{ |
| 313 | "arch_paths": `[":dep__BP2BUILD__MISSING__DEP"]`, |
| 314 | }), |
| 315 | }, |
| 316 | }, |
| 317 | { |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 318 | description: "arch-variant srcs", |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 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 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 347 | expectedBazelTargets: []string{ |
| 348 | makeBazelTarget("custom", "arch_paths", attrNameToString{ |
| 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 | { |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 409 | description: "arch-variant deps", |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 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 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 425 | expectedBazelTargets: []string{ |
| 426 | makeBazelTarget("custom", "dep", attrNameToString{ |
| 427 | "arch_paths": `["abc"]`, |
| 428 | }), |
| 429 | makeBazelTarget("custom", "has_dep", attrNameToString{ |
| 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 | { |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 438 | description: "embedded props", |
Liz Kammer | 32a0339 | 2021-09-14 11:17:21 -0400 | [diff] [blame] | 439 | blueprint: `custom { |
| 440 | name: "embedded_props", |
| 441 | embedded_prop: "abc", |
| 442 | bazel_module: { bp2build_available: true }, |
| 443 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 444 | expectedBazelTargets: []string{ |
| 445 | makeBazelTarget("custom", "embedded_props", attrNameToString{ |
| 446 | "embedded_attr": `"abc"`, |
| 447 | }), |
Liz Kammer | 32a0339 | 2021-09-14 11:17:21 -0400 | [diff] [blame] | 448 | }, |
| 449 | }, |
| 450 | { |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 451 | description: "ptr to embedded props", |
Liz Kammer | 32a0339 | 2021-09-14 11:17:21 -0400 | [diff] [blame] | 452 | blueprint: `custom { |
| 453 | name: "ptr_to_embedded_props", |
| 454 | other_embedded_prop: "abc", |
| 455 | bazel_module: { bp2build_available: true }, |
| 456 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 457 | expectedBazelTargets: []string{ |
| 458 | makeBazelTarget("custom", "ptr_to_embedded_props", attrNameToString{ |
| 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 { |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 467 | t.Run(testCase.description, func(t *testing.T) { |
| 468 | config := android.TestConfig(buildDir, nil, testCase.blueprint, nil) |
| 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 | |
Liz Kammer | fdd72e6 | 2021-10-11 15:41:03 -0400 | [diff] [blame] | 486 | if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 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 { |
| 489 | for i, expectedBazelTarget := range testCase.expectedBazelTargets { |
| 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 | |
Jingwen Chen | 40067de | 2021-01-26 21:58:43 -0500 | [diff] [blame] | 504 | func TestLoadStatements(t *testing.T) { |
| 505 | testCases := []struct { |
| 506 | bazelTargets BazelTargets |
| 507 | expectedLoadStatements string |
| 508 | }{ |
| 509 | { |
| 510 | bazelTargets: BazelTargets{ |
| 511 | BazelTarget{ |
| 512 | name: "foo", |
| 513 | ruleClass: "cc_library", |
| 514 | bzlLoadLocation: "//build/bazel/rules:cc.bzl", |
| 515 | }, |
| 516 | }, |
| 517 | expectedLoadStatements: `load("//build/bazel/rules:cc.bzl", "cc_library")`, |
| 518 | }, |
| 519 | { |
| 520 | bazelTargets: BazelTargets{ |
| 521 | BazelTarget{ |
| 522 | name: "foo", |
| 523 | ruleClass: "cc_library", |
| 524 | bzlLoadLocation: "//build/bazel/rules:cc.bzl", |
| 525 | }, |
| 526 | BazelTarget{ |
| 527 | name: "bar", |
| 528 | ruleClass: "cc_library", |
| 529 | bzlLoadLocation: "//build/bazel/rules:cc.bzl", |
| 530 | }, |
| 531 | }, |
| 532 | expectedLoadStatements: `load("//build/bazel/rules:cc.bzl", "cc_library")`, |
| 533 | }, |
| 534 | { |
| 535 | bazelTargets: BazelTargets{ |
| 536 | BazelTarget{ |
| 537 | name: "foo", |
| 538 | ruleClass: "cc_library", |
| 539 | bzlLoadLocation: "//build/bazel/rules:cc.bzl", |
| 540 | }, |
| 541 | BazelTarget{ |
| 542 | name: "bar", |
| 543 | ruleClass: "cc_binary", |
| 544 | bzlLoadLocation: "//build/bazel/rules:cc.bzl", |
| 545 | }, |
| 546 | }, |
| 547 | expectedLoadStatements: `load("//build/bazel/rules:cc.bzl", "cc_binary", "cc_library")`, |
| 548 | }, |
| 549 | { |
| 550 | bazelTargets: BazelTargets{ |
| 551 | BazelTarget{ |
| 552 | name: "foo", |
| 553 | ruleClass: "cc_library", |
| 554 | bzlLoadLocation: "//build/bazel/rules:cc.bzl", |
| 555 | }, |
| 556 | BazelTarget{ |
| 557 | name: "bar", |
| 558 | ruleClass: "cc_binary", |
| 559 | bzlLoadLocation: "//build/bazel/rules:cc.bzl", |
| 560 | }, |
| 561 | BazelTarget{ |
| 562 | name: "baz", |
| 563 | ruleClass: "java_binary", |
| 564 | bzlLoadLocation: "//build/bazel/rules:java.bzl", |
| 565 | }, |
| 566 | }, |
| 567 | expectedLoadStatements: `load("//build/bazel/rules:cc.bzl", "cc_binary", "cc_library") |
| 568 | load("//build/bazel/rules:java.bzl", "java_binary")`, |
| 569 | }, |
| 570 | { |
| 571 | bazelTargets: BazelTargets{ |
| 572 | BazelTarget{ |
| 573 | name: "foo", |
| 574 | ruleClass: "cc_binary", |
| 575 | bzlLoadLocation: "//build/bazel/rules:cc.bzl", |
| 576 | }, |
| 577 | BazelTarget{ |
| 578 | name: "bar", |
| 579 | ruleClass: "java_binary", |
| 580 | bzlLoadLocation: "//build/bazel/rules:java.bzl", |
| 581 | }, |
| 582 | BazelTarget{ |
| 583 | name: "baz", |
| 584 | ruleClass: "genrule", |
| 585 | // Note: no bzlLoadLocation for native rules |
| 586 | }, |
| 587 | }, |
| 588 | expectedLoadStatements: `load("//build/bazel/rules:cc.bzl", "cc_binary") |
| 589 | load("//build/bazel/rules:java.bzl", "java_binary")`, |
| 590 | }, |
| 591 | } |
| 592 | |
| 593 | for _, testCase := range testCases { |
| 594 | actual := testCase.bazelTargets.LoadStatements() |
| 595 | expected := testCase.expectedLoadStatements |
| 596 | if actual != expected { |
| 597 | t.Fatalf("Expected load statements to be %s, got %s", expected, actual) |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | } |
| 602 | |
| 603 | func TestGenerateBazelTargetModules_OneToMany_LoadedFromStarlark(t *testing.T) { |
| 604 | testCases := []struct { |
| 605 | bp string |
| 606 | expectedBazelTarget string |
| 607 | expectedBazelTargetCount int |
| 608 | expectedLoadStatements string |
| 609 | }{ |
| 610 | { |
| 611 | bp: `custom { |
| 612 | name: "bar", |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 613 | one_to_many_prop: true, |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 614 | bazel_module: { bp2build_available: true }, |
Jingwen Chen | 40067de | 2021-01-26 21:58:43 -0500 | [diff] [blame] | 615 | }`, |
| 616 | expectedBazelTarget: `my_library( |
| 617 | name = "bar", |
| 618 | ) |
| 619 | |
Jingwen Chen | 40067de | 2021-01-26 21:58:43 -0500 | [diff] [blame] | 620 | proto_library( |
| 621 | name = "bar_proto_library_deps", |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 622 | ) |
| 623 | |
| 624 | my_proto_library( |
| 625 | name = "bar_my_proto_library_deps", |
Jingwen Chen | 40067de | 2021-01-26 21:58:43 -0500 | [diff] [blame] | 626 | )`, |
| 627 | expectedBazelTargetCount: 3, |
| 628 | expectedLoadStatements: `load("//build/bazel/rules:proto.bzl", "my_proto_library", "proto_library") |
| 629 | load("//build/bazel/rules:rules.bzl", "my_library")`, |
| 630 | }, |
| 631 | } |
| 632 | |
| 633 | dir := "." |
| 634 | for _, testCase := range testCases { |
| 635 | config := android.TestConfig(buildDir, nil, testCase.bp, nil) |
| 636 | ctx := android.NewTestContext(config) |
| 637 | ctx.RegisterModuleType("custom", customModuleFactory) |
Jingwen Chen | 40067de | 2021-01-26 21:58:43 -0500 | [diff] [blame] | 638 | ctx.RegisterForBazelConversion() |
| 639 | |
| 640 | _, errs := ctx.ParseFileList(dir, []string{"Android.bp"}) |
| 641 | android.FailIfErrored(t, errs) |
| 642 | _, errs = ctx.ResolveDependencies(config) |
| 643 | android.FailIfErrored(t, errs) |
| 644 | |
Jingwen Chen | 164e086 | 2021-02-19 00:48:40 -0500 | [diff] [blame] | 645 | codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 646 | bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir) |
| 647 | android.FailIfErrored(t, err) |
Jingwen Chen | 40067de | 2021-01-26 21:58:43 -0500 | [diff] [blame] | 648 | if actualCount := len(bazelTargets); actualCount != testCase.expectedBazelTargetCount { |
| 649 | t.Fatalf("Expected %d bazel target, got %d", testCase.expectedBazelTargetCount, actualCount) |
| 650 | } |
| 651 | |
| 652 | actualBazelTargets := bazelTargets.String() |
| 653 | if actualBazelTargets != testCase.expectedBazelTarget { |
| 654 | t.Errorf( |
| 655 | "Expected generated Bazel target to be '%s', got '%s'", |
| 656 | testCase.expectedBazelTarget, |
| 657 | actualBazelTargets, |
| 658 | ) |
| 659 | } |
| 660 | |
| 661 | actualLoadStatements := bazelTargets.LoadStatements() |
| 662 | if actualLoadStatements != testCase.expectedLoadStatements { |
| 663 | t.Errorf( |
| 664 | "Expected generated load statements to be '%s', got '%s'", |
| 665 | testCase.expectedLoadStatements, |
| 666 | actualLoadStatements, |
| 667 | ) |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 672 | func TestModuleTypeBp2Build(t *testing.T) { |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 673 | testCases := []bp2buildTestCase{ |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 674 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 675 | description: "filegroup with does not specify srcs", |
| 676 | moduleTypeUnderTest: "filegroup", |
| 677 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 678 | blueprint: `filegroup { |
Liz Kammer | ebfcf67 | 2021-02-16 15:00:05 -0500 | [diff] [blame] | 679 | name: "fg_foo", |
| 680 | bazel_module: { bp2build_available: true }, |
| 681 | }`, |
| 682 | expectedBazelTargets: []string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 683 | makeBazelTarget("filegroup", "fg_foo", map[string]string{}), |
Liz Kammer | ebfcf67 | 2021-02-16 15:00:05 -0500 | [diff] [blame] | 684 | }, |
| 685 | }, |
| 686 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 687 | description: "filegroup with no srcs", |
| 688 | moduleTypeUnderTest: "filegroup", |
| 689 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 690 | blueprint: `filegroup { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 691 | name: "fg_foo", |
| 692 | srcs: [], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 693 | bazel_module: { bp2build_available: true }, |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 694 | }`, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 695 | expectedBazelTargets: []string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 696 | makeBazelTarget("filegroup", "fg_foo", map[string]string{}), |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 697 | }, |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 698 | }, |
| 699 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 700 | description: "filegroup with srcs", |
| 701 | moduleTypeUnderTest: "filegroup", |
| 702 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 703 | blueprint: `filegroup { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 704 | name: "fg_foo", |
| 705 | srcs: ["a", "b"], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 706 | bazel_module: { bp2build_available: true }, |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 707 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 708 | expectedBazelTargets: []string{ |
| 709 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 710 | "srcs": `[ |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 711 | "a", |
| 712 | "b", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 713 | ]`, |
| 714 | }), |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 715 | }, |
| 716 | }, |
| 717 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 718 | description: "filegroup with excludes srcs", |
| 719 | moduleTypeUnderTest: "filegroup", |
| 720 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 721 | blueprint: `filegroup { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 722 | name: "fg_foo", |
| 723 | srcs: ["a", "b"], |
| 724 | exclude_srcs: ["a"], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 725 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 726 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 727 | expectedBazelTargets: []string{ |
| 728 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 729 | "srcs": `["b"]`, |
| 730 | }), |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 731 | }, |
| 732 | }, |
| 733 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 734 | description: "filegroup with glob", |
| 735 | moduleTypeUnderTest: "filegroup", |
| 736 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 737 | blueprint: `filegroup { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 738 | name: "fg_foo", |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 739 | srcs: ["**/*.txt"], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 740 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 741 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 742 | expectedBazelTargets: []string{ |
| 743 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 744 | "srcs": `[ |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 745 | "other/a.txt", |
| 746 | "other/b.txt", |
| 747 | "other/subdir/a.txt", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 748 | ]`, |
| 749 | }), |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 750 | }, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 751 | filesystem: map[string]string{ |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 752 | "other/a.txt": "", |
| 753 | "other/b.txt": "", |
| 754 | "other/subdir/a.txt": "", |
| 755 | "other/file": "", |
| 756 | }, |
| 757 | }, |
| 758 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 759 | description: "filegroup with glob in subdir", |
| 760 | moduleTypeUnderTest: "filegroup", |
| 761 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 762 | dir: "other", |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 763 | filesystem: map[string]string{ |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 764 | "other/Android.bp": `filegroup { |
| 765 | name: "fg_foo", |
| 766 | srcs: ["**/*.txt"], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 767 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 768 | }`, |
| 769 | "other/a.txt": "", |
| 770 | "other/b.txt": "", |
| 771 | "other/subdir/a.txt": "", |
| 772 | "other/file": "", |
| 773 | }, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 774 | expectedBazelTargets: []string{ |
| 775 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 776 | "srcs": `[ |
| 777 | "a.txt", |
| 778 | "b.txt", |
| 779 | "subdir/a.txt", |
| 780 | ]`, |
| 781 | }), |
| 782 | }, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 783 | }, |
| 784 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 785 | description: "depends_on_other_dir_module", |
| 786 | moduleTypeUnderTest: "filegroup", |
| 787 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 788 | blueprint: `filegroup { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 789 | name: "fg_foo", |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 790 | srcs: [ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 791 | ":foo", |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 792 | "c", |
| 793 | ], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 794 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 795 | }`, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 796 | filesystem: map[string]string{ |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 797 | "other/Android.bp": `filegroup { |
| 798 | name: "foo", |
| 799 | srcs: ["a", "b"], |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 800 | bazel_module: { bp2build_available: true }, |
| 801 | }`, |
| 802 | }, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 803 | expectedBazelTargets: []string{ |
| 804 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 805 | "srcs": `[ |
| 806 | "//other:foo", |
| 807 | "c", |
| 808 | ]`, |
| 809 | }), |
| 810 | }, |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 811 | }, |
| 812 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 813 | description: "depends_on_other_unconverted_module_error", |
| 814 | moduleTypeUnderTest: "filegroup", |
| 815 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 816 | unconvertedDepsMode: errorModulesUnconvertedDeps, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 817 | blueprint: `filegroup { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 818 | name: "foobar", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 819 | srcs: [ |
| 820 | ":foo", |
| 821 | "c", |
| 822 | ], |
| 823 | bazel_module: { bp2build_available: true }, |
| 824 | }`, |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 825 | expectedErr: fmt.Errorf(`"foobar" depends on unconverted modules: foo`), |
| 826 | filesystem: map[string]string{ |
| 827 | "other/Android.bp": `filegroup { |
| 828 | name: "foo", |
| 829 | srcs: ["a", "b"], |
| 830 | }`, |
| 831 | }, |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 832 | }, |
| 833 | } |
| 834 | |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 835 | for _, testCase := range testCases { |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 836 | t.Run(testCase.description, func(t *testing.T) { |
| 837 | runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, testCase) |
| 838 | }) |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 839 | } |
| 840 | } |
Jingwen Chen | 041b184 | 2021-02-01 00:23:25 -0500 | [diff] [blame] | 841 | |
| 842 | type bp2buildMutator = func(android.TopDownMutatorContext) |
| 843 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 844 | func TestAllowlistingBp2buildTargetsExplicitly(t *testing.T) { |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 845 | testCases := []struct { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 846 | moduleTypeUnderTest string |
| 847 | moduleTypeUnderTestFactory android.ModuleFactory |
| 848 | bp string |
| 849 | expectedCount int |
| 850 | description string |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 851 | }{ |
| 852 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 853 | description: "explicitly unavailable", |
| 854 | moduleTypeUnderTest: "filegroup", |
| 855 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 856 | bp: `filegroup { |
| 857 | name: "foo", |
| 858 | srcs: ["a", "b"], |
| 859 | bazel_module: { bp2build_available: false }, |
| 860 | }`, |
| 861 | expectedCount: 0, |
| 862 | }, |
| 863 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 864 | description: "implicitly unavailable", |
| 865 | moduleTypeUnderTest: "filegroup", |
| 866 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 867 | bp: `filegroup { |
| 868 | name: "foo", |
| 869 | srcs: ["a", "b"], |
| 870 | }`, |
| 871 | expectedCount: 0, |
| 872 | }, |
| 873 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 874 | description: "explicitly available", |
| 875 | moduleTypeUnderTest: "filegroup", |
| 876 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 877 | bp: `filegroup { |
| 878 | name: "foo", |
| 879 | srcs: ["a", "b"], |
| 880 | bazel_module: { bp2build_available: true }, |
| 881 | }`, |
| 882 | expectedCount: 1, |
| 883 | }, |
| 884 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 885 | description: "generates more than 1 target if needed", |
| 886 | moduleTypeUnderTest: "custom", |
| 887 | moduleTypeUnderTestFactory: customModuleFactory, |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 888 | bp: `custom { |
| 889 | name: "foo", |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 890 | one_to_many_prop: true, |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 891 | bazel_module: { bp2build_available: true }, |
| 892 | }`, |
| 893 | expectedCount: 3, |
| 894 | }, |
| 895 | } |
| 896 | |
| 897 | dir := "." |
| 898 | for _, testCase := range testCases { |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 899 | t.Run(testCase.description, func(t *testing.T) { |
| 900 | config := android.TestConfig(buildDir, nil, testCase.bp, nil) |
| 901 | ctx := android.NewTestContext(config) |
| 902 | ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory) |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 903 | ctx.RegisterForBazelConversion() |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 904 | |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 905 | _, errs := ctx.ParseFileList(dir, []string{"Android.bp"}) |
| 906 | android.FailIfErrored(t, errs) |
| 907 | _, errs = ctx.ResolveDependencies(config) |
| 908 | android.FailIfErrored(t, errs) |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 909 | |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 910 | codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 911 | bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir) |
| 912 | android.FailIfErrored(t, err) |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 913 | if actualCount := len(bazelTargets); actualCount != testCase.expectedCount { |
| 914 | t.Fatalf("%s: Expected %d bazel target, got %d", testCase.description, testCase.expectedCount, actualCount) |
| 915 | } |
| 916 | }) |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 917 | } |
| 918 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 919 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 920 | func TestAllowlistingBp2buildTargetsWithConfig(t *testing.T) { |
| 921 | testCases := []struct { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 922 | moduleTypeUnderTest string |
| 923 | moduleTypeUnderTestFactory android.ModuleFactory |
| 924 | expectedCount map[string]int |
| 925 | description string |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame] | 926 | bp2buildConfig allowlists.Bp2BuildConfig |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 927 | checkDir string |
| 928 | fs map[string]string |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 929 | }{ |
| 930 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 931 | description: "test bp2build config package and subpackages config", |
| 932 | moduleTypeUnderTest: "filegroup", |
| 933 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 934 | expectedCount: map[string]int{ |
| 935 | "migrated": 1, |
| 936 | "migrated/but_not_really": 0, |
| 937 | "migrated/but_not_really/but_really": 1, |
| 938 | "not_migrated": 0, |
| 939 | "also_not_migrated": 0, |
| 940 | }, |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame] | 941 | bp2buildConfig: allowlists.Bp2BuildConfig{ |
| 942 | "migrated": allowlists.Bp2BuildDefaultTrueRecursively, |
| 943 | "migrated/but_not_really": allowlists.Bp2BuildDefaultFalse, |
| 944 | "not_migrated": allowlists.Bp2BuildDefaultFalse, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 945 | }, |
| 946 | fs: map[string]string{ |
| 947 | "migrated/Android.bp": `filegroup { name: "a" }`, |
| 948 | "migrated/but_not_really/Android.bp": `filegroup { name: "b" }`, |
| 949 | "migrated/but_not_really/but_really/Android.bp": `filegroup { name: "c" }`, |
| 950 | "not_migrated/Android.bp": `filegroup { name: "d" }`, |
| 951 | "also_not_migrated/Android.bp": `filegroup { name: "e" }`, |
| 952 | }, |
| 953 | }, |
| 954 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 955 | description: "test bp2build config opt-in and opt-out", |
| 956 | moduleTypeUnderTest: "filegroup", |
| 957 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 958 | expectedCount: map[string]int{ |
| 959 | "package-opt-in": 2, |
| 960 | "package-opt-in/subpackage": 0, |
| 961 | "package-opt-out": 1, |
| 962 | "package-opt-out/subpackage": 0, |
| 963 | }, |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame] | 964 | bp2buildConfig: allowlists.Bp2BuildConfig{ |
| 965 | "package-opt-in": allowlists.Bp2BuildDefaultFalse, |
| 966 | "package-opt-out": allowlists.Bp2BuildDefaultTrueRecursively, |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 967 | }, |
| 968 | fs: map[string]string{ |
| 969 | "package-opt-in/Android.bp": ` |
| 970 | filegroup { name: "opt-in-a" } |
| 971 | filegroup { name: "opt-in-b", bazel_module: { bp2build_available: true } } |
| 972 | filegroup { name: "opt-in-c", bazel_module: { bp2build_available: true } } |
| 973 | `, |
| 974 | |
| 975 | "package-opt-in/subpackage/Android.bp": ` |
| 976 | filegroup { name: "opt-in-d" } // parent package not configured to DefaultTrueRecursively |
| 977 | `, |
| 978 | |
| 979 | "package-opt-out/Android.bp": ` |
| 980 | filegroup { name: "opt-out-a" } |
| 981 | filegroup { name: "opt-out-b", bazel_module: { bp2build_available: false } } |
| 982 | filegroup { name: "opt-out-c", bazel_module: { bp2build_available: false } } |
| 983 | `, |
| 984 | |
| 985 | "package-opt-out/subpackage/Android.bp": ` |
| 986 | filegroup { name: "opt-out-g", bazel_module: { bp2build_available: false } } |
| 987 | filegroup { name: "opt-out-h", bazel_module: { bp2build_available: false } } |
| 988 | `, |
| 989 | }, |
| 990 | }, |
| 991 | } |
| 992 | |
| 993 | dir := "." |
| 994 | for _, testCase := range testCases { |
| 995 | fs := make(map[string][]byte) |
| 996 | toParse := []string{ |
| 997 | "Android.bp", |
| 998 | } |
| 999 | for f, content := range testCase.fs { |
| 1000 | if strings.HasSuffix(f, "Android.bp") { |
| 1001 | toParse = append(toParse, f) |
| 1002 | } |
| 1003 | fs[f] = []byte(content) |
| 1004 | } |
| 1005 | config := android.TestConfig(buildDir, nil, "", fs) |
| 1006 | ctx := android.NewTestContext(config) |
| 1007 | ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory) |
Sam Delmerico | 24c5603 | 2022-03-28 19:53:03 +0000 | [diff] [blame] | 1008 | allowlist := android.NewBp2BuildAllowlist().SetDefaultConfig(testCase.bp2buildConfig) |
| 1009 | ctx.RegisterBp2BuildConfig(allowlist) |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 1010 | ctx.RegisterForBazelConversion() |
| 1011 | |
| 1012 | _, errs := ctx.ParseFileList(dir, toParse) |
| 1013 | android.FailIfErrored(t, errs) |
| 1014 | _, errs = ctx.ResolveDependencies(config) |
| 1015 | android.FailIfErrored(t, errs) |
| 1016 | |
| 1017 | codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) |
| 1018 | |
| 1019 | // For each directory, test that the expected number of generated targets is correct. |
| 1020 | for dir, expectedCount := range testCase.expectedCount { |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 1021 | bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir) |
| 1022 | android.FailIfErrored(t, err) |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 1023 | if actualCount := len(bazelTargets); actualCount != expectedCount { |
| 1024 | t.Fatalf( |
| 1025 | "%s: Expected %d bazel target for %s package, got %d", |
| 1026 | testCase.description, |
| 1027 | expectedCount, |
| 1028 | dir, |
| 1029 | actualCount) |
| 1030 | } |
| 1031 | |
| 1032 | } |
| 1033 | } |
| 1034 | } |
| 1035 | |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1036 | func TestCombineBuildFilesBp2buildTargets(t *testing.T) { |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1037 | testCases := []bp2buildTestCase{ |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1038 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1039 | description: "filegroup bazel_module.label", |
| 1040 | moduleTypeUnderTest: "filegroup", |
| 1041 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1042 | blueprint: `filegroup { |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1043 | name: "fg_foo", |
| 1044 | bazel_module: { label: "//other:fg_foo" }, |
| 1045 | }`, |
| 1046 | expectedBazelTargets: []string{ |
| 1047 | `// BUILD file`, |
| 1048 | }, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1049 | filesystem: map[string]string{ |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1050 | "other/BUILD.bazel": `// BUILD file`, |
| 1051 | }, |
| 1052 | }, |
| 1053 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1054 | description: "multiple bazel_module.label same BUILD", |
| 1055 | moduleTypeUnderTest: "filegroup", |
| 1056 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1057 | blueprint: `filegroup { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1058 | name: "fg_foo", |
| 1059 | bazel_module: { label: "//other:fg_foo" }, |
| 1060 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1061 | |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1062 | filegroup { |
| 1063 | name: "foo", |
| 1064 | bazel_module: { label: "//other:foo" }, |
| 1065 | }`, |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1066 | expectedBazelTargets: []string{ |
| 1067 | `// BUILD file`, |
| 1068 | }, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1069 | filesystem: map[string]string{ |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1070 | "other/BUILD.bazel": `// BUILD file`, |
| 1071 | }, |
| 1072 | }, |
| 1073 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1074 | description: "filegroup bazel_module.label and bp2build in subdir", |
| 1075 | moduleTypeUnderTest: "filegroup", |
| 1076 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 1077 | dir: "other", |
| 1078 | blueprint: ``, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1079 | filesystem: map[string]string{ |
Jingwen Chen | c63677b | 2021-06-17 05:43:19 +0000 | [diff] [blame] | 1080 | "other/Android.bp": `filegroup { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1081 | name: "fg_foo", |
| 1082 | bazel_module: { |
| 1083 | bp2build_available: true, |
| 1084 | }, |
| 1085 | } |
| 1086 | filegroup { |
| 1087 | name: "fg_bar", |
| 1088 | bazel_module: { |
| 1089 | label: "//other:fg_bar" |
| 1090 | }, |
| 1091 | }`, |
Jingwen Chen | c63677b | 2021-06-17 05:43:19 +0000 | [diff] [blame] | 1092 | "other/BUILD.bazel": `// definition for fg_bar`, |
| 1093 | }, |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1094 | expectedBazelTargets: []string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1095 | makeBazelTarget("filegroup", "fg_foo", map[string]string{}), |
| 1096 | `// definition for fg_bar`, |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1097 | }, |
| 1098 | }, |
| 1099 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1100 | description: "filegroup bazel_module.label and filegroup bp2build", |
| 1101 | moduleTypeUnderTest: "filegroup", |
| 1102 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 1103 | |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1104 | filesystem: map[string]string{ |
| 1105 | "other/BUILD.bazel": `// BUILD file`, |
| 1106 | }, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1107 | blueprint: `filegroup { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1108 | name: "fg_foo", |
| 1109 | bazel_module: { |
| 1110 | label: "//other:fg_foo", |
| 1111 | }, |
| 1112 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1113 | |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1114 | filegroup { |
| 1115 | name: "fg_bar", |
| 1116 | bazel_module: { |
| 1117 | bp2build_available: true, |
| 1118 | }, |
| 1119 | }`, |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1120 | expectedBazelTargets: []string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1121 | makeBazelTarget("filegroup", "fg_bar", map[string]string{}), |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1122 | `// BUILD file`, |
| 1123 | }, |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1124 | }, |
| 1125 | } |
| 1126 | |
| 1127 | dir := "." |
| 1128 | for _, testCase := range testCases { |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1129 | t.Run(testCase.description, func(t *testing.T) { |
| 1130 | fs := make(map[string][]byte) |
| 1131 | toParse := []string{ |
| 1132 | "Android.bp", |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1133 | } |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1134 | for f, content := range testCase.filesystem { |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1135 | if strings.HasSuffix(f, "Android.bp") { |
| 1136 | toParse = append(toParse, f) |
| 1137 | } |
| 1138 | fs[f] = []byte(content) |
| 1139 | } |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1140 | config := android.TestConfig(buildDir, nil, testCase.blueprint, fs) |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1141 | ctx := android.NewTestContext(config) |
| 1142 | ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory) |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1143 | ctx.RegisterForBazelConversion() |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1144 | |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1145 | _, errs := ctx.ParseFileList(dir, toParse) |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1146 | if errored(t, testCase, errs) { |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1147 | return |
| 1148 | } |
| 1149 | _, errs = ctx.ResolveDependencies(config) |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1150 | if errored(t, testCase, errs) { |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1151 | return |
| 1152 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1153 | |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1154 | checkDir := dir |
| 1155 | if testCase.dir != "" { |
| 1156 | checkDir = testCase.dir |
| 1157 | } |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 1158 | codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) |
| 1159 | bazelTargets, err := generateBazelTargetsForDir(codegenCtx, checkDir) |
| 1160 | android.FailIfErrored(t, err) |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1161 | bazelTargets.sort() |
| 1162 | actualCount := len(bazelTargets) |
| 1163 | expectedCount := len(testCase.expectedBazelTargets) |
| 1164 | if actualCount != expectedCount { |
| 1165 | t.Errorf("Expected %d bazel target, got %d\n%s", expectedCount, actualCount, bazelTargets) |
| 1166 | } |
| 1167 | if !strings.Contains(bazelTargets.String(), "Section: Handcrafted targets. ") { |
| 1168 | t.Errorf("Expected string representation of bazelTargets to contain handcrafted section header.") |
| 1169 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1170 | for i, target := range bazelTargets { |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1171 | actualContent := target.content |
| 1172 | expectedContent := testCase.expectedBazelTargets[i] |
| 1173 | if expectedContent != actualContent { |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1174 | t.Errorf( |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1175 | "Expected generated Bazel target to be '%s', got '%s'", |
| 1176 | expectedContent, |
| 1177 | actualContent, |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1178 | ) |
| 1179 | } |
| 1180 | } |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1181 | }) |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1182 | } |
| 1183 | } |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1184 | |
| 1185 | func TestGlobExcludeSrcs(t *testing.T) { |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1186 | testCases := []bp2buildTestCase{ |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1187 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1188 | description: "filegroup top level exclude_srcs", |
| 1189 | moduleTypeUnderTest: "filegroup", |
| 1190 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1191 | blueprint: `filegroup { |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1192 | name: "fg_foo", |
| 1193 | srcs: ["**/*.txt"], |
| 1194 | exclude_srcs: ["c.txt"], |
| 1195 | bazel_module: { bp2build_available: true }, |
| 1196 | }`, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1197 | filesystem: map[string]string{ |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1198 | "a.txt": "", |
| 1199 | "b.txt": "", |
| 1200 | "c.txt": "", |
| 1201 | "dir/Android.bp": "", |
| 1202 | "dir/e.txt": "", |
| 1203 | "dir/f.txt": "", |
| 1204 | }, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1205 | expectedBazelTargets: []string{ |
| 1206 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 1207 | "srcs": `[ |
| 1208 | "a.txt", |
| 1209 | "b.txt", |
| 1210 | "//dir:e.txt", |
| 1211 | "//dir:f.txt", |
| 1212 | ]`, |
| 1213 | }), |
| 1214 | }, |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1215 | }, |
| 1216 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1217 | description: "filegroup in subdir exclude_srcs", |
| 1218 | moduleTypeUnderTest: "filegroup", |
| 1219 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 1220 | blueprint: "", |
| 1221 | dir: "dir", |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1222 | filesystem: map[string]string{ |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1223 | "dir/Android.bp": `filegroup { |
| 1224 | name: "fg_foo", |
| 1225 | srcs: ["**/*.txt"], |
| 1226 | exclude_srcs: ["b.txt"], |
| 1227 | bazel_module: { bp2build_available: true }, |
| 1228 | } |
| 1229 | `, |
| 1230 | "dir/a.txt": "", |
| 1231 | "dir/b.txt": "", |
| 1232 | "dir/subdir/Android.bp": "", |
| 1233 | "dir/subdir/e.txt": "", |
| 1234 | "dir/subdir/f.txt": "", |
| 1235 | }, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1236 | expectedBazelTargets: []string{ |
| 1237 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 1238 | "srcs": `[ |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 1239 | "a.txt", |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1240 | "//dir/subdir:e.txt", |
| 1241 | "//dir/subdir:f.txt", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1242 | ]`, |
| 1243 | }), |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1244 | }, |
| 1245 | }, |
| 1246 | } |
| 1247 | |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1248 | for _, testCase := range testCases { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1249 | t.Run(testCase.description, func(t *testing.T) { |
| 1250 | runBp2BuildTestCaseSimple(t, testCase) |
| 1251 | }) |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1252 | } |
| 1253 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1254 | |
| 1255 | func TestCommonBp2BuildModuleAttrs(t *testing.T) { |
| 1256 | testCases := []bp2buildTestCase{ |
| 1257 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1258 | description: "Required into data test", |
| 1259 | moduleTypeUnderTest: "filegroup", |
| 1260 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1261 | 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] | 1262 | filegroup { |
| 1263 | name: "fg_foo", |
| 1264 | required: ["reqd"], |
| 1265 | bazel_module: { bp2build_available: true }, |
| 1266 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1267 | expectedBazelTargets: []string{ |
| 1268 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 1269 | "data": `[":reqd"]`, |
| 1270 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1271 | }, |
| 1272 | }, |
| 1273 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1274 | description: "Required via arch into data test", |
| 1275 | moduleTypeUnderTest: "python_library", |
| 1276 | moduleTypeUnderTestFactory: python.PythonLibraryFactory, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1277 | blueprint: simpleModuleDoNotConvertBp2build("python_library", "reqdx86") + |
| 1278 | 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] | 1279 | python_library { |
| 1280 | name: "fg_foo", |
| 1281 | arch: { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1282 | arm: { |
| 1283 | required: ["reqdarm"], |
| 1284 | }, |
| 1285 | x86: { |
| 1286 | required: ["reqdx86"], |
| 1287 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1288 | }, |
| 1289 | bazel_module: { bp2build_available: true }, |
| 1290 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1291 | expectedBazelTargets: []string{ |
| 1292 | makeBazelTarget("py_library", "fg_foo", map[string]string{ |
| 1293 | "data": `select({ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1294 | "//build/bazel/platforms/arch:arm": [":reqdarm"], |
| 1295 | "//build/bazel/platforms/arch:x86": [":reqdx86"], |
| 1296 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1297 | })`, |
| 1298 | "srcs_version": `"PY3"`, |
| 1299 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1300 | }, |
| 1301 | }, |
| 1302 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1303 | description: "Required appended to data test", |
| 1304 | moduleTypeUnderTest: "python_library", |
| 1305 | moduleTypeUnderTestFactory: python.PythonLibraryFactory, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1306 | filesystem: map[string]string{ |
| 1307 | "data.bin": "", |
| 1308 | "src.py": "", |
| 1309 | }, |
| 1310 | 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] | 1311 | python_library { |
| 1312 | name: "fg_foo", |
| 1313 | data: ["data.bin"], |
| 1314 | required: ["reqd"], |
| 1315 | bazel_module: { bp2build_available: true }, |
| 1316 | }`, |
| 1317 | expectedBazelTargets: []string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1318 | makeBazelTarget("py_library", "fg_foo", map[string]string{ |
| 1319 | "data": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1320 | "data.bin", |
| 1321 | ":reqd", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1322 | ]`, |
| 1323 | "srcs_version": `"PY3"`, |
| 1324 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1325 | }, |
| 1326 | }, |
| 1327 | { |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 1328 | description: "All props-to-attrs at once together test", |
| 1329 | moduleTypeUnderTest: "filegroup", |
| 1330 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1331 | 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] | 1332 | filegroup { |
| 1333 | name: "fg_foo", |
| 1334 | required: ["reqd"], |
| 1335 | bazel_module: { bp2build_available: true }, |
| 1336 | }`, |
| 1337 | expectedBazelTargets: []string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1338 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 1339 | "data": `[":reqd"]`, |
| 1340 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1341 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1342 | }, |
| 1343 | } |
| 1344 | |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1345 | for _, tc := range testCases { |
| 1346 | t.Run(tc.description, func(t *testing.T) { |
| 1347 | runBp2BuildTestCaseSimple(t, tc) |
| 1348 | }) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1349 | } |
| 1350 | } |