Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 1 | // Copyright 2019 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 android |
| 16 | |
| 17 | import ( |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 18 | "fmt" |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 19 | "io" |
| 20 | "reflect" |
Dan Willemsen | def7b5d | 2021-10-17 00:22:33 -0700 | [diff] [blame] | 21 | "runtime" |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 22 | "strings" |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 23 | "testing" |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 24 | |
| 25 | "github.com/google/blueprint/proptools" |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | type customModule struct { |
| 29 | ModuleBase |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 30 | |
| 31 | properties struct { |
| 32 | Default_dist_files *string |
| 33 | Dist_output_file *bool |
| 34 | } |
| 35 | |
| 36 | data AndroidMkData |
| 37 | distFiles TaggedDistFiles |
| 38 | outputFile OptionalPath |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 39 | |
| 40 | // The paths that will be used as the default dist paths if no tag is |
| 41 | // specified. |
| 42 | defaultDistPaths Paths |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 43 | } |
| 44 | |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 45 | const ( |
| 46 | defaultDistFiles_None = "none" |
| 47 | defaultDistFiles_Default = "default" |
| 48 | defaultDistFiles_Tagged = "tagged" |
| 49 | ) |
| 50 | |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 51 | func (m *customModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 52 | |
| 53 | // If the dist_output_file: true then create an output file that is stored in |
| 54 | // the OutputFile property of the AndroidMkEntry. |
| 55 | if proptools.BoolDefault(m.properties.Dist_output_file, true) { |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 56 | path := PathForTesting("dist-output-file.out") |
| 57 | m.outputFile = OptionalPathForPath(path) |
| 58 | |
| 59 | // Previous code would prioritize the DistFiles property over the OutputFile |
| 60 | // property in AndroidMkEntry when determining the default dist paths. |
| 61 | // Setting this first allows it to be overridden based on the |
| 62 | // default_dist_files setting replicating that previous behavior. |
| 63 | m.defaultDistPaths = Paths{path} |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | // Based on the setting of the default_dist_files property possibly create a |
| 67 | // TaggedDistFiles structure that will be stored in the DistFiles property of |
| 68 | // the AndroidMkEntry. |
| 69 | defaultDistFiles := proptools.StringDefault(m.properties.Default_dist_files, defaultDistFiles_Tagged) |
| 70 | switch defaultDistFiles { |
| 71 | case defaultDistFiles_None: |
| 72 | // Do nothing |
| 73 | |
| 74 | case defaultDistFiles_Default: |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 75 | path := PathForTesting("default-dist.out") |
| 76 | m.defaultDistPaths = Paths{path} |
| 77 | m.distFiles = MakeDefaultDistFiles(path) |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 78 | |
| 79 | case defaultDistFiles_Tagged: |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 80 | // Module types that set AndroidMkEntry.DistFiles to the result of calling |
| 81 | // GenerateTaggedDistFiles(ctx) relied on no tag being treated as "" which |
| 82 | // meant that the default dist paths would be whatever was returned by |
| 83 | // OutputFiles(""). In order to preserve that behavior when treating no tag |
| 84 | // as being equal to DefaultDistTag this ensures that |
| 85 | // OutputFiles(DefaultDistTag) will return the same as OutputFiles(""). |
| 86 | m.defaultDistPaths = PathsForTesting("one.out") |
| 87 | |
| 88 | // This must be called after setting defaultDistPaths/outputFile as |
| 89 | // GenerateTaggedDistFiles calls into OutputFiles(tag) which may use those |
| 90 | // fields. |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 91 | m.distFiles = m.GenerateTaggedDistFiles(ctx) |
| 92 | } |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | func (m *customModule) AndroidMk() AndroidMkData { |
| 96 | return AndroidMkData{ |
| 97 | Custom: func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData) { |
| 98 | m.data = data |
| 99 | }, |
| 100 | } |
| 101 | } |
| 102 | |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 103 | func (m *customModule) OutputFiles(tag string) (Paths, error) { |
| 104 | switch tag { |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 105 | case DefaultDistTag: |
| 106 | if m.defaultDistPaths != nil { |
| 107 | return m.defaultDistPaths, nil |
| 108 | } else { |
| 109 | return nil, fmt.Errorf("default dist tag is not available") |
| 110 | } |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 111 | case "": |
| 112 | return PathsForTesting("one.out"), nil |
| 113 | case ".multiple": |
| 114 | return PathsForTesting("two.out", "three/four.out"), nil |
Jingwen Chen | 8481186 | 2020-07-21 11:32:19 +0000 | [diff] [blame] | 115 | case ".another-tag": |
| 116 | return PathsForTesting("another.out"), nil |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 117 | default: |
| 118 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | func (m *customModule) AndroidMkEntries() []AndroidMkEntries { |
| 123 | return []AndroidMkEntries{ |
| 124 | { |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 125 | Class: "CUSTOM_MODULE", |
| 126 | DistFiles: m.distFiles, |
| 127 | OutputFile: m.outputFile, |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 128 | }, |
| 129 | } |
| 130 | } |
| 131 | |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 132 | func customModuleFactory() Module { |
| 133 | module := &customModule{} |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 134 | |
| 135 | module.AddProperties(&module.properties) |
| 136 | |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 137 | InitAndroidModule(module) |
| 138 | return module |
| 139 | } |
| 140 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 141 | // buildContextAndCustomModuleFoo creates a config object, processes the supplied |
Paul Duffin | 103aaae | 2020-11-26 17:36:46 +0000 | [diff] [blame] | 142 | // bp module and then returns the config and the custom module called "foo". |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 143 | func buildContextAndCustomModuleFoo(t *testing.T, bp string) (*TestContext, *customModule) { |
Paul Duffin | 103aaae | 2020-11-26 17:36:46 +0000 | [diff] [blame] | 144 | t.Helper() |
Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame] | 145 | result := GroupFixturePreparers( |
Paul Duffin | 9ca14c1 | 2021-03-16 17:30:13 +0000 | [diff] [blame] | 146 | // Enable androidmk Singleton |
| 147 | PrepareForTestWithAndroidMk, |
| 148 | FixtureRegisterWithContext(func(ctx RegistrationContext) { |
| 149 | ctx.RegisterModuleType("custom", customModuleFactory) |
| 150 | }), |
Trevor Radcliffe | 90727f4 | 2022-03-21 19:34:02 +0000 | [diff] [blame] | 151 | FixtureModifyProductVariables(func(variables FixtureProductVariables) { |
| 152 | variables.DeviceProduct = proptools.StringPtr("bar") |
| 153 | }), |
Paul Duffin | 9ca14c1 | 2021-03-16 17:30:13 +0000 | [diff] [blame] | 154 | FixtureWithRootAndroidBp(bp), |
Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame] | 155 | ).RunTest(t) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 156 | |
Paul Duffin | 9ca14c1 | 2021-03-16 17:30:13 +0000 | [diff] [blame] | 157 | module := result.ModuleForTests("foo", "").Module().(*customModule) |
| 158 | return result.TestContext, module |
Paul Duffin | 103aaae | 2020-11-26 17:36:46 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | func TestAndroidMkSingleton_PassesUpdatedAndroidMkDataToCustomCallback(t *testing.T) { |
Dan Willemsen | def7b5d | 2021-10-17 00:22:33 -0700 | [diff] [blame] | 162 | if runtime.GOOS == "darwin" { |
| 163 | // Device modules are not exported on Mac, so this test doesn't work. |
| 164 | t.SkipNow() |
| 165 | } |
| 166 | |
Paul Duffin | 103aaae | 2020-11-26 17:36:46 +0000 | [diff] [blame] | 167 | bp := ` |
| 168 | custom { |
| 169 | name: "foo", |
| 170 | required: ["bar"], |
| 171 | host_required: ["baz"], |
| 172 | target_required: ["qux"], |
| 173 | } |
| 174 | ` |
| 175 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 176 | _, m := buildContextAndCustomModuleFoo(t, bp) |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 177 | |
| 178 | assertEqual := func(expected interface{}, actual interface{}) { |
| 179 | if !reflect.DeepEqual(expected, actual) { |
| 180 | t.Errorf("%q expected, but got %q", expected, actual) |
| 181 | } |
| 182 | } |
| 183 | assertEqual([]string{"bar"}, m.data.Required) |
| 184 | assertEqual([]string{"baz"}, m.data.Host_required) |
| 185 | assertEqual([]string{"qux"}, m.data.Target_required) |
| 186 | } |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 187 | |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 188 | func TestGenerateDistContributionsForMake(t *testing.T) { |
| 189 | dc := &distContributions{ |
| 190 | copiesForGoals: []*copiesForGoals{ |
| 191 | { |
| 192 | goals: "my_goal", |
| 193 | copies: []distCopy{ |
| 194 | distCopyForTest("one.out", "one.out"), |
| 195 | distCopyForTest("two.out", "other.out"), |
| 196 | }, |
| 197 | }, |
| 198 | }, |
| 199 | } |
| 200 | |
| 201 | makeOutput := generateDistContributionsForMake(dc) |
| 202 | |
| 203 | assertStringEquals(t, `.PHONY: my_goal |
| 204 | $(call dist-for-goals,my_goal,one.out:one.out) |
| 205 | $(call dist-for-goals,my_goal,two.out:other.out) |
| 206 | `, strings.Join(makeOutput, "")) |
| 207 | } |
| 208 | |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 209 | func TestGetDistForGoals(t *testing.T) { |
Paul Duffin | d83988d | 2020-11-26 17:29:35 +0000 | [diff] [blame] | 210 | bp := ` |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 211 | custom { |
| 212 | name: "foo", |
| 213 | dist: { |
| 214 | targets: ["my_goal", "my_other_goal"], |
| 215 | tag: ".multiple", |
| 216 | }, |
| 217 | dists: [ |
| 218 | { |
| 219 | targets: ["my_second_goal"], |
| 220 | tag: ".multiple", |
| 221 | }, |
| 222 | { |
| 223 | targets: ["my_third_goal"], |
| 224 | dir: "test/dir", |
| 225 | }, |
| 226 | { |
| 227 | targets: ["my_fourth_goal"], |
| 228 | suffix: ".suffix", |
| 229 | }, |
| 230 | { |
| 231 | targets: ["my_fifth_goal"], |
| 232 | dest: "new-name", |
| 233 | }, |
| 234 | { |
| 235 | targets: ["my_sixth_goal"], |
| 236 | dest: "new-name", |
| 237 | dir: "some/dir", |
| 238 | suffix: ".suffix", |
| 239 | }, |
| 240 | ], |
| 241 | } |
Paul Duffin | d83988d | 2020-11-26 17:29:35 +0000 | [diff] [blame] | 242 | ` |
| 243 | |
| 244 | expectedAndroidMkLines := []string{ |
| 245 | ".PHONY: my_second_goal\n", |
| 246 | "$(call dist-for-goals,my_second_goal,two.out:two.out)\n", |
| 247 | "$(call dist-for-goals,my_second_goal,three/four.out:four.out)\n", |
| 248 | ".PHONY: my_third_goal\n", |
| 249 | "$(call dist-for-goals,my_third_goal,one.out:test/dir/one.out)\n", |
| 250 | ".PHONY: my_fourth_goal\n", |
| 251 | "$(call dist-for-goals,my_fourth_goal,one.out:one.suffix.out)\n", |
| 252 | ".PHONY: my_fifth_goal\n", |
| 253 | "$(call dist-for-goals,my_fifth_goal,one.out:new-name)\n", |
| 254 | ".PHONY: my_sixth_goal\n", |
| 255 | "$(call dist-for-goals,my_sixth_goal,one.out:some/dir/new-name.suffix)\n", |
| 256 | ".PHONY: my_goal my_other_goal\n", |
| 257 | "$(call dist-for-goals,my_goal my_other_goal,two.out:two.out)\n", |
| 258 | "$(call dist-for-goals,my_goal my_other_goal,three/four.out:four.out)\n", |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 261 | ctx, module := buildContextAndCustomModuleFoo(t, bp) |
| 262 | entries := AndroidMkEntriesForTest(t, ctx, module) |
Paul Duffin | d83988d | 2020-11-26 17:29:35 +0000 | [diff] [blame] | 263 | if len(entries) != 1 { |
| 264 | t.Errorf("Expected a single AndroidMk entry, got %d", len(entries)) |
| 265 | } |
| 266 | androidMkLines := entries[0].GetDistForGoals(module) |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 267 | |
Paul Duffin | d83988d | 2020-11-26 17:29:35 +0000 | [diff] [blame] | 268 | if len(androidMkLines) != len(expectedAndroidMkLines) { |
| 269 | t.Errorf( |
| 270 | "Expected %d AndroidMk lines, got %d:\n%v", |
| 271 | len(expectedAndroidMkLines), |
| 272 | len(androidMkLines), |
| 273 | androidMkLines, |
| 274 | ) |
| 275 | } |
| 276 | for idx, line := range androidMkLines { |
| 277 | expectedLine := expectedAndroidMkLines[idx] |
| 278 | if line != expectedLine { |
| 279 | t.Errorf( |
| 280 | "Expected AndroidMk line to be '%s', got '%s'", |
| 281 | expectedLine, |
| 282 | line, |
| 283 | ) |
| 284 | } |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 285 | } |
| 286 | } |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 287 | |
| 288 | func distCopyForTest(from, to string) distCopy { |
| 289 | return distCopy{PathForTesting(from), to} |
| 290 | } |
| 291 | |
| 292 | func TestGetDistContributions(t *testing.T) { |
| 293 | compareContributions := func(d1 *distContributions, d2 *distContributions) error { |
| 294 | if d1 == nil || d2 == nil { |
| 295 | if d1 != d2 { |
| 296 | return fmt.Errorf("pointer mismatch, expected both to be nil but they were %p and %p", d1, d2) |
| 297 | } else { |
| 298 | return nil |
| 299 | } |
| 300 | } |
| 301 | if expected, actual := len(d1.copiesForGoals), len(d2.copiesForGoals); expected != actual { |
| 302 | return fmt.Errorf("length mismatch, expected %d found %d", expected, actual) |
| 303 | } |
| 304 | |
| 305 | for i, copies1 := range d1.copiesForGoals { |
| 306 | copies2 := d2.copiesForGoals[i] |
| 307 | if expected, actual := copies1.goals, copies2.goals; expected != actual { |
| 308 | return fmt.Errorf("goals mismatch at position %d: expected %q found %q", i, expected, actual) |
| 309 | } |
| 310 | |
| 311 | if expected, actual := len(copies1.copies), len(copies2.copies); expected != actual { |
| 312 | return fmt.Errorf("length mismatch in copy instructions at position %d, expected %d found %d", i, expected, actual) |
| 313 | } |
| 314 | |
| 315 | for j, c1 := range copies1.copies { |
| 316 | c2 := copies2.copies[j] |
| 317 | if expected, actual := NormalizePathForTesting(c1.from), NormalizePathForTesting(c2.from); expected != actual { |
| 318 | return fmt.Errorf("paths mismatch at position %d.%d: expected %q found %q", i, j, expected, actual) |
| 319 | } |
| 320 | |
| 321 | if expected, actual := c1.dest, c2.dest; expected != actual { |
| 322 | return fmt.Errorf("dest mismatch at position %d.%d: expected %q found %q", i, j, expected, actual) |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | return nil |
| 328 | } |
| 329 | |
| 330 | formatContributions := func(d *distContributions) string { |
| 331 | buf := &strings.Builder{} |
| 332 | if d == nil { |
| 333 | fmt.Fprint(buf, "nil") |
| 334 | } else { |
| 335 | for _, copiesForGoals := range d.copiesForGoals { |
| 336 | fmt.Fprintf(buf, " Goals: %q {\n", copiesForGoals.goals) |
| 337 | for _, c := range copiesForGoals.copies { |
| 338 | fmt.Fprintf(buf, " %s -> %s\n", NormalizePathForTesting(c.from), c.dest) |
| 339 | } |
| 340 | fmt.Fprint(buf, " }\n") |
| 341 | } |
| 342 | } |
| 343 | return buf.String() |
| 344 | } |
| 345 | |
| 346 | testHelper := func(t *testing.T, name, bp string, expectedContributions *distContributions) { |
| 347 | t.Helper() |
| 348 | t.Run(name, func(t *testing.T) { |
| 349 | t.Helper() |
| 350 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 351 | ctx, module := buildContextAndCustomModuleFoo(t, bp) |
| 352 | entries := AndroidMkEntriesForTest(t, ctx, module) |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 353 | if len(entries) != 1 { |
| 354 | t.Errorf("Expected a single AndroidMk entry, got %d", len(entries)) |
| 355 | } |
| 356 | distContributions := entries[0].getDistContributions(module) |
| 357 | |
| 358 | if err := compareContributions(expectedContributions, distContributions); err != nil { |
| 359 | t.Errorf("%s\nExpected Contributions\n%sActualContributions\n%s", |
| 360 | err, |
| 361 | formatContributions(expectedContributions), |
| 362 | formatContributions(distContributions)) |
| 363 | } |
| 364 | }) |
| 365 | } |
| 366 | |
| 367 | testHelper(t, "dist-without-tag", ` |
| 368 | custom { |
| 369 | name: "foo", |
| 370 | dist: { |
| 371 | targets: ["my_goal"] |
| 372 | } |
| 373 | } |
| 374 | `, |
| 375 | &distContributions{ |
| 376 | copiesForGoals: []*copiesForGoals{ |
| 377 | { |
| 378 | goals: "my_goal", |
| 379 | copies: []distCopy{ |
| 380 | distCopyForTest("one.out", "one.out"), |
| 381 | }, |
| 382 | }, |
| 383 | }, |
| 384 | }) |
| 385 | |
| 386 | testHelper(t, "dist-with-tag", ` |
| 387 | custom { |
| 388 | name: "foo", |
| 389 | dist: { |
| 390 | targets: ["my_goal"], |
| 391 | tag: ".another-tag", |
| 392 | } |
| 393 | } |
| 394 | `, |
| 395 | &distContributions{ |
| 396 | copiesForGoals: []*copiesForGoals{ |
| 397 | { |
| 398 | goals: "my_goal", |
| 399 | copies: []distCopy{ |
| 400 | distCopyForTest("another.out", "another.out"), |
| 401 | }, |
| 402 | }, |
| 403 | }, |
| 404 | }) |
| 405 | |
Trevor Radcliffe | 90727f4 | 2022-03-21 19:34:02 +0000 | [diff] [blame] | 406 | testHelper(t, "append-artifact-with-product", ` |
| 407 | custom { |
| 408 | name: "foo", |
| 409 | dist: { |
| 410 | targets: ["my_goal"], |
| 411 | append_artifact_with_product: true, |
| 412 | } |
| 413 | } |
| 414 | `, &distContributions{ |
| 415 | copiesForGoals: []*copiesForGoals{ |
| 416 | { |
| 417 | goals: "my_goal", |
| 418 | copies: []distCopy{ |
| 419 | distCopyForTest("one.out", "one_bar.out"), |
| 420 | }, |
| 421 | }, |
| 422 | }, |
| 423 | }) |
| 424 | |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 425 | testHelper(t, "dists-with-tag", ` |
| 426 | custom { |
| 427 | name: "foo", |
| 428 | dists: [ |
| 429 | { |
| 430 | targets: ["my_goal"], |
| 431 | tag: ".another-tag", |
| 432 | }, |
| 433 | ], |
| 434 | } |
| 435 | `, |
| 436 | &distContributions{ |
| 437 | copiesForGoals: []*copiesForGoals{ |
| 438 | { |
| 439 | goals: "my_goal", |
| 440 | copies: []distCopy{ |
| 441 | distCopyForTest("another.out", "another.out"), |
| 442 | }, |
| 443 | }, |
| 444 | }, |
| 445 | }) |
| 446 | |
| 447 | testHelper(t, "multiple-dists-with-and-without-tag", ` |
| 448 | custom { |
| 449 | name: "foo", |
| 450 | dists: [ |
| 451 | { |
| 452 | targets: ["my_goal"], |
| 453 | }, |
| 454 | { |
| 455 | targets: ["my_second_goal", "my_third_goal"], |
| 456 | }, |
| 457 | ], |
| 458 | } |
| 459 | `, |
| 460 | &distContributions{ |
| 461 | copiesForGoals: []*copiesForGoals{ |
| 462 | { |
| 463 | goals: "my_goal", |
| 464 | copies: []distCopy{ |
| 465 | distCopyForTest("one.out", "one.out"), |
| 466 | }, |
| 467 | }, |
| 468 | { |
| 469 | goals: "my_second_goal my_third_goal", |
| 470 | copies: []distCopy{ |
| 471 | distCopyForTest("one.out", "one.out"), |
| 472 | }, |
| 473 | }, |
| 474 | }, |
| 475 | }) |
| 476 | |
| 477 | testHelper(t, "dist-plus-dists-without-tags", ` |
| 478 | custom { |
| 479 | name: "foo", |
| 480 | dist: { |
| 481 | targets: ["my_goal"], |
| 482 | }, |
| 483 | dists: [ |
| 484 | { |
| 485 | targets: ["my_second_goal", "my_third_goal"], |
| 486 | }, |
| 487 | ], |
| 488 | } |
| 489 | `, |
| 490 | &distContributions{ |
| 491 | copiesForGoals: []*copiesForGoals{ |
| 492 | { |
| 493 | goals: "my_second_goal my_third_goal", |
| 494 | copies: []distCopy{ |
| 495 | distCopyForTest("one.out", "one.out"), |
| 496 | }, |
| 497 | }, |
| 498 | { |
| 499 | goals: "my_goal", |
| 500 | copies: []distCopy{ |
| 501 | distCopyForTest("one.out", "one.out"), |
| 502 | }, |
| 503 | }, |
| 504 | }, |
| 505 | }) |
| 506 | |
| 507 | testHelper(t, "dist-plus-dists-with-tags", ` |
| 508 | custom { |
| 509 | name: "foo", |
| 510 | dist: { |
| 511 | targets: ["my_goal", "my_other_goal"], |
| 512 | tag: ".multiple", |
| 513 | }, |
| 514 | dists: [ |
| 515 | { |
| 516 | targets: ["my_second_goal"], |
| 517 | tag: ".multiple", |
| 518 | }, |
| 519 | { |
| 520 | targets: ["my_third_goal"], |
| 521 | dir: "test/dir", |
| 522 | }, |
| 523 | { |
| 524 | targets: ["my_fourth_goal"], |
| 525 | suffix: ".suffix", |
| 526 | }, |
| 527 | { |
| 528 | targets: ["my_fifth_goal"], |
| 529 | dest: "new-name", |
| 530 | }, |
| 531 | { |
| 532 | targets: ["my_sixth_goal"], |
| 533 | dest: "new-name", |
| 534 | dir: "some/dir", |
| 535 | suffix: ".suffix", |
| 536 | }, |
| 537 | ], |
| 538 | } |
| 539 | `, |
| 540 | &distContributions{ |
| 541 | copiesForGoals: []*copiesForGoals{ |
| 542 | { |
| 543 | goals: "my_second_goal", |
| 544 | copies: []distCopy{ |
| 545 | distCopyForTest("two.out", "two.out"), |
| 546 | distCopyForTest("three/four.out", "four.out"), |
| 547 | }, |
| 548 | }, |
| 549 | { |
| 550 | goals: "my_third_goal", |
| 551 | copies: []distCopy{ |
| 552 | distCopyForTest("one.out", "test/dir/one.out"), |
| 553 | }, |
| 554 | }, |
| 555 | { |
| 556 | goals: "my_fourth_goal", |
| 557 | copies: []distCopy{ |
| 558 | distCopyForTest("one.out", "one.suffix.out"), |
| 559 | }, |
| 560 | }, |
| 561 | { |
| 562 | goals: "my_fifth_goal", |
| 563 | copies: []distCopy{ |
| 564 | distCopyForTest("one.out", "new-name"), |
| 565 | }, |
| 566 | }, |
| 567 | { |
| 568 | goals: "my_sixth_goal", |
| 569 | copies: []distCopy{ |
| 570 | distCopyForTest("one.out", "some/dir/new-name.suffix"), |
| 571 | }, |
| 572 | }, |
| 573 | { |
| 574 | goals: "my_goal my_other_goal", |
| 575 | copies: []distCopy{ |
| 576 | distCopyForTest("two.out", "two.out"), |
| 577 | distCopyForTest("three/four.out", "four.out"), |
| 578 | }, |
| 579 | }, |
| 580 | }, |
| 581 | }) |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 582 | |
| 583 | // The above test the default values of default_dist_files and use_output_file. |
| 584 | |
| 585 | // The following tests explicitly test the different combinations of those settings. |
| 586 | testHelper(t, "tagged-dist-files-no-output", ` |
| 587 | custom { |
| 588 | name: "foo", |
| 589 | default_dist_files: "tagged", |
| 590 | dist_output_file: false, |
| 591 | dists: [ |
| 592 | { |
| 593 | targets: ["my_goal"], |
| 594 | }, |
| 595 | { |
| 596 | targets: ["my_goal"], |
| 597 | tag: ".multiple", |
| 598 | }, |
| 599 | ], |
| 600 | } |
| 601 | `, &distContributions{ |
| 602 | copiesForGoals: []*copiesForGoals{ |
| 603 | { |
| 604 | goals: "my_goal", |
| 605 | copies: []distCopy{ |
| 606 | distCopyForTest("one.out", "one.out"), |
| 607 | }, |
| 608 | }, |
| 609 | { |
| 610 | goals: "my_goal", |
| 611 | copies: []distCopy{ |
| 612 | distCopyForTest("two.out", "two.out"), |
| 613 | distCopyForTest("three/four.out", "four.out"), |
| 614 | }, |
| 615 | }, |
| 616 | }, |
| 617 | }) |
| 618 | |
| 619 | testHelper(t, "default-dist-files-no-output", ` |
| 620 | custom { |
| 621 | name: "foo", |
| 622 | default_dist_files: "default", |
| 623 | dist_output_file: false, |
| 624 | dists: [ |
| 625 | { |
| 626 | targets: ["my_goal"], |
| 627 | }, |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 628 | { |
| 629 | targets: ["my_goal"], |
| 630 | tag: ".multiple", |
| 631 | }, |
| 632 | ], |
| 633 | } |
| 634 | `, &distContributions{ |
| 635 | copiesForGoals: []*copiesForGoals{ |
| 636 | { |
| 637 | goals: "my_goal", |
| 638 | copies: []distCopy{ |
| 639 | distCopyForTest("default-dist.out", "default-dist.out"), |
| 640 | }, |
| 641 | }, |
Paul Duffin | af970a2 | 2020-11-23 23:32:56 +0000 | [diff] [blame] | 642 | { |
| 643 | goals: "my_goal", |
| 644 | copies: []distCopy{ |
| 645 | distCopyForTest("two.out", "two.out"), |
| 646 | distCopyForTest("three/four.out", "four.out"), |
| 647 | }, |
| 648 | }, |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 649 | }, |
| 650 | }) |
| 651 | |
| 652 | testHelper(t, "no-dist-files-no-output", ` |
| 653 | custom { |
| 654 | name: "foo", |
| 655 | default_dist_files: "none", |
| 656 | dist_output_file: false, |
| 657 | dists: [ |
| 658 | // The following is silently ignored because there is not default file |
| 659 | // in either the dist files or the output file. |
| 660 | { |
| 661 | targets: ["my_goal"], |
| 662 | }, |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 663 | { |
| 664 | targets: ["my_goal"], |
| 665 | tag: ".multiple", |
| 666 | }, |
| 667 | ], |
| 668 | } |
Paul Duffin | af970a2 | 2020-11-23 23:32:56 +0000 | [diff] [blame] | 669 | `, &distContributions{ |
| 670 | copiesForGoals: []*copiesForGoals{ |
| 671 | { |
| 672 | goals: "my_goal", |
| 673 | copies: []distCopy{ |
| 674 | distCopyForTest("two.out", "two.out"), |
| 675 | distCopyForTest("three/four.out", "four.out"), |
| 676 | }, |
| 677 | }, |
| 678 | }, |
| 679 | }) |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 680 | |
| 681 | testHelper(t, "tagged-dist-files-default-output", ` |
| 682 | custom { |
| 683 | name: "foo", |
| 684 | default_dist_files: "tagged", |
| 685 | dist_output_file: true, |
| 686 | dists: [ |
| 687 | { |
| 688 | targets: ["my_goal"], |
| 689 | }, |
| 690 | { |
| 691 | targets: ["my_goal"], |
| 692 | tag: ".multiple", |
| 693 | }, |
| 694 | ], |
| 695 | } |
| 696 | `, &distContributions{ |
| 697 | copiesForGoals: []*copiesForGoals{ |
| 698 | { |
| 699 | goals: "my_goal", |
| 700 | copies: []distCopy{ |
| 701 | distCopyForTest("one.out", "one.out"), |
| 702 | }, |
| 703 | }, |
| 704 | { |
| 705 | goals: "my_goal", |
| 706 | copies: []distCopy{ |
| 707 | distCopyForTest("two.out", "two.out"), |
| 708 | distCopyForTest("three/four.out", "four.out"), |
| 709 | }, |
| 710 | }, |
| 711 | }, |
| 712 | }) |
| 713 | |
| 714 | testHelper(t, "default-dist-files-default-output", ` |
| 715 | custom { |
| 716 | name: "foo", |
| 717 | default_dist_files: "default", |
| 718 | dist_output_file: true, |
| 719 | dists: [ |
| 720 | { |
| 721 | targets: ["my_goal"], |
| 722 | }, |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 723 | { |
| 724 | targets: ["my_goal"], |
| 725 | tag: ".multiple", |
| 726 | }, |
| 727 | ], |
| 728 | } |
| 729 | `, &distContributions{ |
| 730 | copiesForGoals: []*copiesForGoals{ |
| 731 | { |
| 732 | goals: "my_goal", |
| 733 | copies: []distCopy{ |
| 734 | distCopyForTest("default-dist.out", "default-dist.out"), |
| 735 | }, |
| 736 | }, |
Paul Duffin | af970a2 | 2020-11-23 23:32:56 +0000 | [diff] [blame] | 737 | { |
| 738 | goals: "my_goal", |
| 739 | copies: []distCopy{ |
| 740 | distCopyForTest("two.out", "two.out"), |
| 741 | distCopyForTest("three/four.out", "four.out"), |
| 742 | }, |
| 743 | }, |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 744 | }, |
| 745 | }) |
| 746 | |
| 747 | testHelper(t, "no-dist-files-default-output", ` |
| 748 | custom { |
| 749 | name: "foo", |
| 750 | default_dist_files: "none", |
| 751 | dist_output_file: true, |
| 752 | dists: [ |
| 753 | { |
| 754 | targets: ["my_goal"], |
| 755 | }, |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 756 | { |
| 757 | targets: ["my_goal"], |
| 758 | tag: ".multiple", |
| 759 | }, |
| 760 | ], |
| 761 | } |
| 762 | `, &distContributions{ |
| 763 | copiesForGoals: []*copiesForGoals{ |
| 764 | { |
| 765 | goals: "my_goal", |
| 766 | copies: []distCopy{ |
| 767 | distCopyForTest("dist-output-file.out", "dist-output-file.out"), |
| 768 | }, |
| 769 | }, |
Paul Duffin | af970a2 | 2020-11-23 23:32:56 +0000 | [diff] [blame] | 770 | { |
| 771 | goals: "my_goal", |
| 772 | copies: []distCopy{ |
| 773 | distCopyForTest("two.out", "two.out"), |
| 774 | distCopyForTest("three/four.out", "four.out"), |
| 775 | }, |
| 776 | }, |
Paul Duffin | 6226949 | 2020-11-26 20:18:42 +0000 | [diff] [blame] | 777 | }, |
| 778 | }) |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 779 | } |