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 { |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 248 | name: "foo", |
| 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 { |
| 473 | t.Errorf("Expected %d bazel target, got %d", expectedCount, actualCount) |
| 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", |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 599 | bazel_module: { bp2build_available: true }, |
Jingwen Chen | 40067de | 2021-01-26 21:58:43 -0500 | [diff] [blame] | 600 | }`, |
| 601 | expectedBazelTarget: `my_library( |
| 602 | name = "bar", |
| 603 | ) |
| 604 | |
Jingwen Chen | 40067de | 2021-01-26 21:58:43 -0500 | [diff] [blame] | 605 | proto_library( |
| 606 | name = "bar_proto_library_deps", |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 607 | ) |
| 608 | |
| 609 | my_proto_library( |
| 610 | name = "bar_my_proto_library_deps", |
Jingwen Chen | 40067de | 2021-01-26 21:58:43 -0500 | [diff] [blame] | 611 | )`, |
| 612 | expectedBazelTargetCount: 3, |
| 613 | expectedLoadStatements: `load("//build/bazel/rules:proto.bzl", "my_proto_library", "proto_library") |
| 614 | load("//build/bazel/rules:rules.bzl", "my_library")`, |
| 615 | }, |
| 616 | } |
| 617 | |
| 618 | dir := "." |
| 619 | for _, testCase := range testCases { |
| 620 | config := android.TestConfig(buildDir, nil, testCase.bp, nil) |
| 621 | ctx := android.NewTestContext(config) |
| 622 | ctx.RegisterModuleType("custom", customModuleFactory) |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 623 | ctx.RegisterBp2BuildMutator("custom", customBp2BuildMutatorFromStarlark) |
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 | ebfcf67 | 2021-02-16 15:00:05 -0500 | [diff] [blame] | 661 | description: "filegroup with does not specify srcs", |
| 662 | moduleTypeUnderTest: "filegroup", |
| 663 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 664 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 665 | blueprint: `filegroup { |
Liz Kammer | ebfcf67 | 2021-02-16 15:00:05 -0500 | [diff] [blame] | 666 | name: "fg_foo", |
| 667 | bazel_module: { bp2build_available: true }, |
| 668 | }`, |
| 669 | expectedBazelTargets: []string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 670 | makeBazelTarget("filegroup", "fg_foo", map[string]string{}), |
Liz Kammer | ebfcf67 | 2021-02-16 15:00:05 -0500 | [diff] [blame] | 671 | }, |
| 672 | }, |
| 673 | { |
Jingwen Chen | a42d641 | 2021-01-26 21:57:27 -0500 | [diff] [blame] | 674 | description: "filegroup with no srcs", |
| 675 | moduleTypeUnderTest: "filegroup", |
| 676 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 677 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 678 | blueprint: `filegroup { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 679 | name: "fg_foo", |
| 680 | srcs: [], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 681 | bazel_module: { bp2build_available: true }, |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 682 | }`, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 683 | expectedBazelTargets: []string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 684 | makeBazelTarget("filegroup", "fg_foo", map[string]string{}), |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 685 | }, |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 686 | }, |
| 687 | { |
Jingwen Chen | a42d641 | 2021-01-26 21:57:27 -0500 | [diff] [blame] | 688 | description: "filegroup with srcs", |
| 689 | moduleTypeUnderTest: "filegroup", |
| 690 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 691 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 692 | blueprint: `filegroup { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 693 | name: "fg_foo", |
| 694 | srcs: ["a", "b"], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 695 | bazel_module: { bp2build_available: true }, |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 696 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 697 | expectedBazelTargets: []string{ |
| 698 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 699 | "srcs": `[ |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 700 | "a", |
| 701 | "b", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 702 | ]`, |
| 703 | }), |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 704 | }, |
| 705 | }, |
| 706 | { |
| 707 | description: "filegroup with excludes srcs", |
| 708 | moduleTypeUnderTest: "filegroup", |
| 709 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 710 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 711 | blueprint: `filegroup { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 712 | name: "fg_foo", |
| 713 | srcs: ["a", "b"], |
| 714 | exclude_srcs: ["a"], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 715 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 716 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 717 | expectedBazelTargets: []string{ |
| 718 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 719 | "srcs": `["b"]`, |
| 720 | }), |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 721 | }, |
| 722 | }, |
| 723 | { |
| 724 | description: "filegroup with glob", |
| 725 | moduleTypeUnderTest: "filegroup", |
| 726 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 727 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 728 | blueprint: `filegroup { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 729 | name: "fg_foo", |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 730 | srcs: ["**/*.txt"], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 731 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 732 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 733 | expectedBazelTargets: []string{ |
| 734 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 735 | "srcs": `[ |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 736 | "other/a.txt", |
| 737 | "other/b.txt", |
| 738 | "other/subdir/a.txt", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 739 | ]`, |
| 740 | }), |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 741 | }, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 742 | filesystem: map[string]string{ |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 743 | "other/a.txt": "", |
| 744 | "other/b.txt": "", |
| 745 | "other/subdir/a.txt": "", |
| 746 | "other/file": "", |
| 747 | }, |
| 748 | }, |
| 749 | { |
| 750 | description: "filegroup with glob in subdir", |
| 751 | moduleTypeUnderTest: "filegroup", |
| 752 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 753 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 754 | blueprint: ``, |
| 755 | dir: "other", |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 756 | filesystem: map[string]string{ |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 757 | "other/Android.bp": `filegroup { |
| 758 | name: "fg_foo", |
| 759 | srcs: ["**/*.txt"], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 760 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 761 | }`, |
| 762 | "other/a.txt": "", |
| 763 | "other/b.txt": "", |
| 764 | "other/subdir/a.txt": "", |
| 765 | "other/file": "", |
| 766 | }, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 767 | expectedBazelTargets: []string{ |
| 768 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 769 | "srcs": `[ |
| 770 | "a.txt", |
| 771 | "b.txt", |
| 772 | "subdir/a.txt", |
| 773 | ]`, |
| 774 | }), |
| 775 | }, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 776 | }, |
| 777 | { |
| 778 | description: "depends_on_other_dir_module", |
| 779 | moduleTypeUnderTest: "filegroup", |
| 780 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 781 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 782 | blueprint: `filegroup { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 783 | name: "fg_foo", |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 784 | srcs: [ |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 785 | ":foo", |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 786 | "c", |
| 787 | ], |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 788 | bazel_module: { bp2build_available: true }, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 789 | }`, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 790 | filesystem: map[string]string{ |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 791 | "other/Android.bp": `filegroup { |
| 792 | name: "foo", |
| 793 | srcs: ["a", "b"], |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 794 | bazel_module: { bp2build_available: true }, |
| 795 | }`, |
| 796 | }, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 797 | expectedBazelTargets: []string{ |
| 798 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 799 | "srcs": `[ |
| 800 | "//other:foo", |
| 801 | "c", |
| 802 | ]`, |
| 803 | }), |
| 804 | }, |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 805 | }, |
| 806 | { |
| 807 | description: "depends_on_other_unconverted_module_error", |
| 808 | moduleTypeUnderTest: "filegroup", |
| 809 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 810 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
| 811 | unconvertedDepsMode: errorModulesUnconvertedDeps, |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 812 | filesystem: map[string]string{ |
| 813 | "other/Android.bp": `filegroup { |
| 814 | name: "foo", |
| 815 | srcs: ["a", "b"], |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 816 | }`, |
| 817 | }, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 818 | blueprint: `filegroup { |
| 819 | name: "fg_foo", |
| 820 | srcs: [ |
| 821 | ":foo", |
| 822 | "c", |
| 823 | ], |
| 824 | bazel_module: { bp2build_available: true }, |
| 825 | }`, |
| 826 | expectedErr: fmt.Errorf(`"fg_foo" depends on unconverted modules: foo`), |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 827 | }, |
| 828 | } |
| 829 | |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 830 | for _, testCase := range testCases { |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 831 | t.Run(testCase.description, func(t *testing.T) { |
| 832 | runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, testCase) |
| 833 | }) |
Jingwen Chen | 32b4ece | 2021-01-21 03:20:18 -0500 | [diff] [blame] | 834 | } |
| 835 | } |
Jingwen Chen | 041b184 | 2021-02-01 00:23:25 -0500 | [diff] [blame] | 836 | |
| 837 | type bp2buildMutator = func(android.TopDownMutatorContext) |
| 838 | |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 839 | func TestAllowlistingBp2buildTargetsExplicitly(t *testing.T) { |
Jingwen Chen | 77e8b7b | 2021-02-05 03:03:24 -0500 | [diff] [blame] | 840 | testCases := []struct { |
| 841 | moduleTypeUnderTest string |
| 842 | moduleTypeUnderTestFactory android.ModuleFactory |
| 843 | moduleTypeUnderTestBp2BuildMutator bp2buildMutator |
| 844 | bp string |
| 845 | expectedCount int |
| 846 | description string |
| 847 | }{ |
| 848 | { |
| 849 | description: "explicitly unavailable", |
| 850 | moduleTypeUnderTest: "filegroup", |
| 851 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 852 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
| 853 | bp: `filegroup { |
| 854 | name: "foo", |
| 855 | srcs: ["a", "b"], |
| 856 | bazel_module: { bp2build_available: false }, |
| 857 | }`, |
| 858 | expectedCount: 0, |
| 859 | }, |
| 860 | { |
| 861 | description: "implicitly unavailable", |
| 862 | moduleTypeUnderTest: "filegroup", |
| 863 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 864 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
| 865 | bp: `filegroup { |
| 866 | name: "foo", |
| 867 | srcs: ["a", "b"], |
| 868 | }`, |
| 869 | expectedCount: 0, |
| 870 | }, |
| 871 | { |
| 872 | description: "explicitly available", |
| 873 | moduleTypeUnderTest: "filegroup", |
| 874 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 875 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
| 876 | bp: `filegroup { |
| 877 | name: "foo", |
| 878 | srcs: ["a", "b"], |
| 879 | bazel_module: { bp2build_available: true }, |
| 880 | }`, |
| 881 | expectedCount: 1, |
| 882 | }, |
| 883 | { |
| 884 | description: "generates more than 1 target if needed", |
| 885 | moduleTypeUnderTest: "custom", |
| 886 | moduleTypeUnderTestFactory: customModuleFactory, |
| 887 | moduleTypeUnderTestBp2BuildMutator: customBp2BuildMutatorFromStarlark, |
| 888 | bp: `custom { |
| 889 | name: "foo", |
| 890 | bazel_module: { bp2build_available: true }, |
| 891 | }`, |
| 892 | expectedCount: 3, |
| 893 | }, |
| 894 | } |
| 895 | |
| 896 | dir := "." |
| 897 | for _, testCase := range testCases { |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 898 | t.Run(testCase.description, func(t *testing.T) { |
| 899 | config := android.TestConfig(buildDir, nil, testCase.bp, nil) |
| 900 | ctx := android.NewTestContext(config) |
| 901 | ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory) |
| 902 | ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator) |
| 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 { |
| 922 | moduleTypeUnderTest string |
| 923 | moduleTypeUnderTestFactory android.ModuleFactory |
| 924 | moduleTypeUnderTestBp2BuildMutator bp2buildMutator |
| 925 | expectedCount map[string]int |
| 926 | description string |
| 927 | bp2buildConfig android.Bp2BuildConfig |
| 928 | checkDir string |
| 929 | fs map[string]string |
| 930 | }{ |
| 931 | { |
| 932 | description: "test bp2build config package and subpackages config", |
| 933 | moduleTypeUnderTest: "filegroup", |
| 934 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 935 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
| 936 | expectedCount: map[string]int{ |
| 937 | "migrated": 1, |
| 938 | "migrated/but_not_really": 0, |
| 939 | "migrated/but_not_really/but_really": 1, |
| 940 | "not_migrated": 0, |
| 941 | "also_not_migrated": 0, |
| 942 | }, |
| 943 | bp2buildConfig: android.Bp2BuildConfig{ |
| 944 | "migrated": android.Bp2BuildDefaultTrueRecursively, |
| 945 | "migrated/but_not_really": android.Bp2BuildDefaultFalse, |
| 946 | "not_migrated": android.Bp2BuildDefaultFalse, |
| 947 | }, |
| 948 | fs: map[string]string{ |
| 949 | "migrated/Android.bp": `filegroup { name: "a" }`, |
| 950 | "migrated/but_not_really/Android.bp": `filegroup { name: "b" }`, |
| 951 | "migrated/but_not_really/but_really/Android.bp": `filegroup { name: "c" }`, |
| 952 | "not_migrated/Android.bp": `filegroup { name: "d" }`, |
| 953 | "also_not_migrated/Android.bp": `filegroup { name: "e" }`, |
| 954 | }, |
| 955 | }, |
| 956 | { |
| 957 | description: "test bp2build config opt-in and opt-out", |
| 958 | moduleTypeUnderTest: "filegroup", |
| 959 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 960 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
| 961 | expectedCount: map[string]int{ |
| 962 | "package-opt-in": 2, |
| 963 | "package-opt-in/subpackage": 0, |
| 964 | "package-opt-out": 1, |
| 965 | "package-opt-out/subpackage": 0, |
| 966 | }, |
| 967 | bp2buildConfig: android.Bp2BuildConfig{ |
| 968 | "package-opt-in": android.Bp2BuildDefaultFalse, |
| 969 | "package-opt-out": android.Bp2BuildDefaultTrueRecursively, |
| 970 | }, |
| 971 | fs: map[string]string{ |
| 972 | "package-opt-in/Android.bp": ` |
| 973 | filegroup { name: "opt-in-a" } |
| 974 | filegroup { name: "opt-in-b", bazel_module: { bp2build_available: true } } |
| 975 | filegroup { name: "opt-in-c", bazel_module: { bp2build_available: true } } |
| 976 | `, |
| 977 | |
| 978 | "package-opt-in/subpackage/Android.bp": ` |
| 979 | filegroup { name: "opt-in-d" } // parent package not configured to DefaultTrueRecursively |
| 980 | `, |
| 981 | |
| 982 | "package-opt-out/Android.bp": ` |
| 983 | filegroup { name: "opt-out-a" } |
| 984 | filegroup { name: "opt-out-b", bazel_module: { bp2build_available: false } } |
| 985 | filegroup { name: "opt-out-c", bazel_module: { bp2build_available: false } } |
| 986 | `, |
| 987 | |
| 988 | "package-opt-out/subpackage/Android.bp": ` |
| 989 | filegroup { name: "opt-out-g", bazel_module: { bp2build_available: false } } |
| 990 | filegroup { name: "opt-out-h", bazel_module: { bp2build_available: false } } |
| 991 | `, |
| 992 | }, |
| 993 | }, |
| 994 | } |
| 995 | |
| 996 | dir := "." |
| 997 | for _, testCase := range testCases { |
| 998 | fs := make(map[string][]byte) |
| 999 | toParse := []string{ |
| 1000 | "Android.bp", |
| 1001 | } |
| 1002 | for f, content := range testCase.fs { |
| 1003 | if strings.HasSuffix(f, "Android.bp") { |
| 1004 | toParse = append(toParse, f) |
| 1005 | } |
| 1006 | fs[f] = []byte(content) |
| 1007 | } |
| 1008 | config := android.TestConfig(buildDir, nil, "", fs) |
| 1009 | ctx := android.NewTestContext(config) |
| 1010 | ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory) |
| 1011 | ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator) |
| 1012 | ctx.RegisterBp2BuildConfig(testCase.bp2buildConfig) |
| 1013 | ctx.RegisterForBazelConversion() |
| 1014 | |
| 1015 | _, errs := ctx.ParseFileList(dir, toParse) |
| 1016 | android.FailIfErrored(t, errs) |
| 1017 | _, errs = ctx.ResolveDependencies(config) |
| 1018 | android.FailIfErrored(t, errs) |
| 1019 | |
| 1020 | codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) |
| 1021 | |
| 1022 | // For each directory, test that the expected number of generated targets is correct. |
| 1023 | for dir, expectedCount := range testCase.expectedCount { |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 1024 | bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir) |
| 1025 | android.FailIfErrored(t, err) |
Jingwen Chen | 12b4c27 | 2021-03-10 02:05:59 -0500 | [diff] [blame] | 1026 | if actualCount := len(bazelTargets); actualCount != expectedCount { |
| 1027 | t.Fatalf( |
| 1028 | "%s: Expected %d bazel target for %s package, got %d", |
| 1029 | testCase.description, |
| 1030 | expectedCount, |
| 1031 | dir, |
| 1032 | actualCount) |
| 1033 | } |
| 1034 | |
| 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1039 | func TestCombineBuildFilesBp2buildTargets(t *testing.T) { |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1040 | testCases := []bp2buildTestCase{ |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1041 | { |
| 1042 | description: "filegroup bazel_module.label", |
| 1043 | moduleTypeUnderTest: "filegroup", |
| 1044 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 1045 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1046 | blueprint: `filegroup { |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1047 | name: "fg_foo", |
| 1048 | bazel_module: { label: "//other:fg_foo" }, |
| 1049 | }`, |
| 1050 | expectedBazelTargets: []string{ |
| 1051 | `// BUILD file`, |
| 1052 | }, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1053 | filesystem: map[string]string{ |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1054 | "other/BUILD.bazel": `// BUILD file`, |
| 1055 | }, |
| 1056 | }, |
| 1057 | { |
| 1058 | description: "multiple bazel_module.label same BUILD", |
| 1059 | moduleTypeUnderTest: "filegroup", |
| 1060 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 1061 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1062 | blueprint: `filegroup { |
Jingwen Chen | c63677b | 2021-06-17 05:43:19 +0000 | [diff] [blame] | 1063 | name: "fg_foo", |
| 1064 | bazel_module: { label: "//other:fg_foo" }, |
| 1065 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1066 | |
Jingwen Chen | c63677b | 2021-06-17 05:43:19 +0000 | [diff] [blame] | 1067 | filegroup { |
| 1068 | name: "foo", |
| 1069 | bazel_module: { label: "//other:foo" }, |
| 1070 | }`, |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1071 | expectedBazelTargets: []string{ |
| 1072 | `// BUILD file`, |
| 1073 | }, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1074 | filesystem: map[string]string{ |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1075 | "other/BUILD.bazel": `// BUILD file`, |
| 1076 | }, |
| 1077 | }, |
| 1078 | { |
Jingwen Chen | c63677b | 2021-06-17 05:43:19 +0000 | [diff] [blame] | 1079 | description: "filegroup bazel_module.label and bp2build in subdir", |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1080 | moduleTypeUnderTest: "filegroup", |
| 1081 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 1082 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
Jingwen Chen | c63677b | 2021-06-17 05:43:19 +0000 | [diff] [blame] | 1083 | dir: "other", |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1084 | blueprint: ``, |
| 1085 | filesystem: map[string]string{ |
Jingwen Chen | c63677b | 2021-06-17 05:43:19 +0000 | [diff] [blame] | 1086 | "other/Android.bp": `filegroup { |
| 1087 | name: "fg_foo", |
| 1088 | bazel_module: { |
| 1089 | bp2build_available: true, |
| 1090 | }, |
| 1091 | } |
| 1092 | filegroup { |
| 1093 | name: "fg_bar", |
| 1094 | bazel_module: { |
| 1095 | label: "//other:fg_bar" |
| 1096 | }, |
| 1097 | }`, |
| 1098 | "other/BUILD.bazel": `// definition for fg_bar`, |
| 1099 | }, |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1100 | expectedBazelTargets: []string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1101 | makeBazelTarget("filegroup", "fg_foo", map[string]string{}), |
| 1102 | `// definition for fg_bar`, |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1103 | }, |
| 1104 | }, |
| 1105 | { |
| 1106 | description: "filegroup bazel_module.label and filegroup bp2build", |
| 1107 | moduleTypeUnderTest: "filegroup", |
| 1108 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 1109 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1110 | filesystem: map[string]string{ |
| 1111 | "other/BUILD.bazel": `// BUILD file`, |
| 1112 | }, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1113 | blueprint: `filegroup { |
Jingwen Chen | c63677b | 2021-06-17 05:43:19 +0000 | [diff] [blame] | 1114 | name: "fg_foo", |
| 1115 | bazel_module: { |
| 1116 | label: "//other:fg_foo", |
| 1117 | }, |
| 1118 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1119 | |
Jingwen Chen | c63677b | 2021-06-17 05:43:19 +0000 | [diff] [blame] | 1120 | filegroup { |
| 1121 | name: "fg_bar", |
| 1122 | bazel_module: { |
| 1123 | bp2build_available: true, |
| 1124 | }, |
| 1125 | }`, |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1126 | expectedBazelTargets: []string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1127 | makeBazelTarget("filegroup", "fg_bar", map[string]string{}), |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1128 | `// BUILD file`, |
| 1129 | }, |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1130 | }, |
| 1131 | } |
| 1132 | |
| 1133 | dir := "." |
| 1134 | for _, testCase := range testCases { |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1135 | t.Run(testCase.description, func(t *testing.T) { |
| 1136 | fs := make(map[string][]byte) |
| 1137 | toParse := []string{ |
| 1138 | "Android.bp", |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1139 | } |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1140 | for f, content := range testCase.filesystem { |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1141 | if strings.HasSuffix(f, "Android.bp") { |
| 1142 | toParse = append(toParse, f) |
| 1143 | } |
| 1144 | fs[f] = []byte(content) |
| 1145 | } |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1146 | config := android.TestConfig(buildDir, nil, testCase.blueprint, fs) |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1147 | ctx := android.NewTestContext(config) |
| 1148 | ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory) |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1149 | ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator) |
| 1150 | ctx.RegisterForBazelConversion() |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1151 | |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1152 | _, errs := ctx.ParseFileList(dir, toParse) |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1153 | if errored(t, testCase, errs) { |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1154 | return |
| 1155 | } |
| 1156 | _, errs = ctx.ResolveDependencies(config) |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1157 | if errored(t, testCase, errs) { |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1158 | return |
| 1159 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1160 | |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1161 | checkDir := dir |
| 1162 | if testCase.dir != "" { |
| 1163 | checkDir = testCase.dir |
| 1164 | } |
Liz Kammer | 6eff323 | 2021-08-26 08:37:59 -0400 | [diff] [blame] | 1165 | codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build) |
| 1166 | bazelTargets, err := generateBazelTargetsForDir(codegenCtx, checkDir) |
| 1167 | android.FailIfErrored(t, err) |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1168 | bazelTargets.sort() |
| 1169 | actualCount := len(bazelTargets) |
| 1170 | expectedCount := len(testCase.expectedBazelTargets) |
| 1171 | if actualCount != expectedCount { |
| 1172 | t.Errorf("Expected %d bazel target, got %d\n%s", expectedCount, actualCount, bazelTargets) |
| 1173 | } |
| 1174 | if !strings.Contains(bazelTargets.String(), "Section: Handcrafted targets. ") { |
| 1175 | t.Errorf("Expected string representation of bazelTargets to contain handcrafted section header.") |
| 1176 | } |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1177 | for i, target := range bazelTargets { |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1178 | actualContent := target.content |
| 1179 | expectedContent := testCase.expectedBazelTargets[i] |
| 1180 | if expectedContent != actualContent { |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1181 | t.Errorf( |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1182 | "Expected generated Bazel target to be '%s', got '%s'", |
| 1183 | expectedContent, |
| 1184 | actualContent, |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1185 | ) |
| 1186 | } |
| 1187 | } |
Jingwen Chen | 4910976 | 2021-05-25 05:16:48 +0000 | [diff] [blame] | 1188 | }) |
Liz Kammer | ba3ea16 | 2021-02-17 13:22:03 -0500 | [diff] [blame] | 1189 | } |
| 1190 | } |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1191 | |
| 1192 | func TestGlobExcludeSrcs(t *testing.T) { |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1193 | testCases := []bp2buildTestCase{ |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1194 | { |
| 1195 | description: "filegroup top level exclude_srcs", |
| 1196 | moduleTypeUnderTest: "filegroup", |
| 1197 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 1198 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1199 | blueprint: `filegroup { |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1200 | name: "fg_foo", |
| 1201 | srcs: ["**/*.txt"], |
| 1202 | exclude_srcs: ["c.txt"], |
| 1203 | bazel_module: { bp2build_available: true }, |
| 1204 | }`, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1205 | filesystem: map[string]string{ |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1206 | "a.txt": "", |
| 1207 | "b.txt": "", |
| 1208 | "c.txt": "", |
| 1209 | "dir/Android.bp": "", |
| 1210 | "dir/e.txt": "", |
| 1211 | "dir/f.txt": "", |
| 1212 | }, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1213 | expectedBazelTargets: []string{ |
| 1214 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 1215 | "srcs": `[ |
| 1216 | "a.txt", |
| 1217 | "b.txt", |
| 1218 | "//dir:e.txt", |
| 1219 | "//dir:f.txt", |
| 1220 | ]`, |
| 1221 | }), |
| 1222 | }, |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1223 | }, |
| 1224 | { |
| 1225 | description: "filegroup in subdir exclude_srcs", |
| 1226 | moduleTypeUnderTest: "filegroup", |
| 1227 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 1228 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1229 | blueprint: "", |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1230 | dir: "dir", |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1231 | filesystem: map[string]string{ |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1232 | "dir/Android.bp": `filegroup { |
| 1233 | name: "fg_foo", |
| 1234 | srcs: ["**/*.txt"], |
| 1235 | exclude_srcs: ["b.txt"], |
| 1236 | bazel_module: { bp2build_available: true }, |
| 1237 | } |
| 1238 | `, |
| 1239 | "dir/a.txt": "", |
| 1240 | "dir/b.txt": "", |
| 1241 | "dir/subdir/Android.bp": "", |
| 1242 | "dir/subdir/e.txt": "", |
| 1243 | "dir/subdir/f.txt": "", |
| 1244 | }, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1245 | expectedBazelTargets: []string{ |
| 1246 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 1247 | "srcs": `[ |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 1248 | "a.txt", |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1249 | "//dir/subdir:e.txt", |
| 1250 | "//dir/subdir:f.txt", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1251 | ]`, |
| 1252 | }), |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1253 | }, |
| 1254 | }, |
| 1255 | } |
| 1256 | |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1257 | for _, testCase := range testCases { |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1258 | t.Run(testCase.description, func(t *testing.T) { |
| 1259 | runBp2BuildTestCaseSimple(t, testCase) |
| 1260 | }) |
Jingwen Chen | 4ecc67d | 2021-04-27 09:47:02 +0000 | [diff] [blame] | 1261 | } |
| 1262 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1263 | |
| 1264 | func TestCommonBp2BuildModuleAttrs(t *testing.T) { |
| 1265 | testCases := []bp2buildTestCase{ |
| 1266 | { |
| 1267 | description: "Required into data test", |
| 1268 | moduleTypeUnderTest: "filegroup", |
| 1269 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 1270 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1271 | 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] | 1272 | filegroup { |
| 1273 | name: "fg_foo", |
| 1274 | required: ["reqd"], |
| 1275 | bazel_module: { bp2build_available: true }, |
| 1276 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1277 | expectedBazelTargets: []string{ |
| 1278 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 1279 | "data": `[":reqd"]`, |
| 1280 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1281 | }, |
| 1282 | }, |
| 1283 | { |
| 1284 | description: "Required via arch into data test", |
| 1285 | moduleTypeUnderTest: "python_library", |
| 1286 | moduleTypeUnderTestFactory: python.PythonLibraryFactory, |
| 1287 | moduleTypeUnderTestBp2BuildMutator: python.PythonLibraryBp2Build, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1288 | blueprint: simpleModuleDoNotConvertBp2build("python_library", "reqdx86") + |
| 1289 | 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] | 1290 | python_library { |
| 1291 | name: "fg_foo", |
| 1292 | arch: { |
| 1293 | arm: { |
| 1294 | required: ["reqdarm"], |
| 1295 | }, |
| 1296 | x86: { |
| 1297 | required: ["reqdx86"], |
| 1298 | }, |
| 1299 | }, |
| 1300 | bazel_module: { bp2build_available: true }, |
| 1301 | }`, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1302 | expectedBazelTargets: []string{ |
| 1303 | makeBazelTarget("py_library", "fg_foo", map[string]string{ |
| 1304 | "data": `select({ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1305 | "//build/bazel/platforms/arch:arm": [":reqdarm"], |
| 1306 | "//build/bazel/platforms/arch:x86": [":reqdx86"], |
| 1307 | "//conditions:default": [], |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1308 | })`, |
| 1309 | "srcs_version": `"PY3"`, |
| 1310 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1311 | }, |
| 1312 | }, |
| 1313 | { |
| 1314 | description: "Required appended to data test", |
| 1315 | moduleTypeUnderTest: "python_library", |
| 1316 | moduleTypeUnderTestFactory: python.PythonLibraryFactory, |
| 1317 | moduleTypeUnderTestBp2BuildMutator: python.PythonLibraryBp2Build, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1318 | filesystem: map[string]string{ |
| 1319 | "data.bin": "", |
| 1320 | "src.py": "", |
| 1321 | }, |
| 1322 | 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] | 1323 | python_library { |
| 1324 | name: "fg_foo", |
| 1325 | data: ["data.bin"], |
| 1326 | required: ["reqd"], |
| 1327 | bazel_module: { bp2build_available: true }, |
| 1328 | }`, |
| 1329 | expectedBazelTargets: []string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1330 | makeBazelTarget("py_library", "fg_foo", map[string]string{ |
| 1331 | "data": `[ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1332 | "data.bin", |
| 1333 | ":reqd", |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1334 | ]`, |
| 1335 | "srcs_version": `"PY3"`, |
| 1336 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1337 | }, |
| 1338 | }, |
| 1339 | { |
| 1340 | description: "All props-to-attrs at once together test", |
| 1341 | moduleTypeUnderTest: "filegroup", |
| 1342 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 1343 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1344 | 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] | 1345 | filegroup { |
| 1346 | name: "fg_foo", |
| 1347 | required: ["reqd"], |
| 1348 | bazel_module: { bp2build_available: true }, |
| 1349 | }`, |
| 1350 | expectedBazelTargets: []string{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1351 | makeBazelTarget("filegroup", "fg_foo", map[string]string{ |
| 1352 | "data": `[":reqd"]`, |
| 1353 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1354 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1355 | }, |
| 1356 | } |
| 1357 | |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 1358 | for _, tc := range testCases { |
| 1359 | t.Run(tc.description, func(t *testing.T) { |
| 1360 | runBp2BuildTestCaseSimple(t, tc) |
| 1361 | }) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 1362 | } |
| 1363 | } |