blob: 4cdd6a37b219bfb1c1b18a62670a47416d493e1a [file] [log] [blame]
Jooyung Han12df5fb2019-07-11 16:18:47 +09001// 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
15package android
16
17import (
Jingwen Chen40fd90a2020-06-15 05:24:19 +000018 "fmt"
Jooyung Han12df5fb2019-07-11 16:18:47 +090019 "io"
20 "reflect"
Dan Willemsendef7b5d2021-10-17 00:22:33 -070021 "runtime"
Paul Duffin8b0349c2020-11-26 14:33:21 +000022 "strings"
Jooyung Han12df5fb2019-07-11 16:18:47 +090023 "testing"
Paul Duffin62269492020-11-26 20:18:42 +000024
25 "github.com/google/blueprint/proptools"
Jooyung Han12df5fb2019-07-11 16:18:47 +090026)
27
28type customModule struct {
29 ModuleBase
Paul Duffin62269492020-11-26 20:18:42 +000030
31 properties struct {
32 Default_dist_files *string
33 Dist_output_file *bool
34 }
35
36 data AndroidMkData
Paul Duffin62269492020-11-26 20:18:42 +000037 outputFile OptionalPath
Jooyung Han12df5fb2019-07-11 16:18:47 +090038}
39
Paul Duffin62269492020-11-26 20:18:42 +000040const (
41 defaultDistFiles_None = "none"
42 defaultDistFiles_Default = "default"
43 defaultDistFiles_Tagged = "tagged"
44)
45
Jooyung Han12df5fb2019-07-11 16:18:47 +090046func (m *customModule) GenerateAndroidBuildActions(ctx ModuleContext) {
Paul Duffin62269492020-11-26 20:18:42 +000047
mrziwang01715ca2024-07-01 11:50:18 -070048 var defaultDistPaths Paths
Bob Badour51804382022-04-13 11:27:19 -070049
Paul Duffin62269492020-11-26 20:18:42 +000050 // If the dist_output_file: true then create an output file that is stored in
51 // the OutputFile property of the AndroidMkEntry.
52 if proptools.BoolDefault(m.properties.Dist_output_file, true) {
Paul Duffin74f05592020-11-25 16:37:46 +000053 path := PathForTesting("dist-output-file.out")
54 m.outputFile = OptionalPathForPath(path)
55
56 // Previous code would prioritize the DistFiles property over the OutputFile
57 // property in AndroidMkEntry when determining the default dist paths.
58 // Setting this first allows it to be overridden based on the
59 // default_dist_files setting replicating that previous behavior.
mrziwang01715ca2024-07-01 11:50:18 -070060 defaultDistPaths = Paths{path}
Paul Duffin62269492020-11-26 20:18:42 +000061 }
62
63 // Based on the setting of the default_dist_files property possibly create a
64 // TaggedDistFiles structure that will be stored in the DistFiles property of
65 // the AndroidMkEntry.
66 defaultDistFiles := proptools.StringDefault(m.properties.Default_dist_files, defaultDistFiles_Tagged)
67 switch defaultDistFiles {
68 case defaultDistFiles_None:
mrziwang01715ca2024-07-01 11:50:18 -070069 m.setOutputFiles(ctx, defaultDistPaths)
Paul Duffin62269492020-11-26 20:18:42 +000070
71 case defaultDistFiles_Default:
Paul Duffin74f05592020-11-25 16:37:46 +000072 path := PathForTesting("default-dist.out")
mrziwang01715ca2024-07-01 11:50:18 -070073 defaultDistPaths = Paths{path}
74 m.setOutputFiles(ctx, defaultDistPaths)
Paul Duffin62269492020-11-26 20:18:42 +000075
76 case defaultDistFiles_Tagged:
Paul Duffin74f05592020-11-25 16:37:46 +000077 // Module types that set AndroidMkEntry.DistFiles to the result of calling
78 // GenerateTaggedDistFiles(ctx) relied on no tag being treated as "" which
mrziwang01715ca2024-07-01 11:50:18 -070079 // meant that the default dist paths would be the same as empty-string-tag
80 // output files. In order to preserve that behavior when treating no tag
81 // as being equal to DefaultDistTag this ensures that DefaultDistTag output
82 // will be the same as empty-string-tag output.
83 defaultDistPaths = PathsForTesting("one.out")
84 m.setOutputFiles(ctx, defaultDistPaths)
Paul Duffin62269492020-11-26 20:18:42 +000085 }
Jooyung Han12df5fb2019-07-11 16:18:47 +090086}
87
mrziwang01715ca2024-07-01 11:50:18 -070088func (m *customModule) setOutputFiles(ctx ModuleContext, defaultDistPaths Paths) {
89 ctx.SetOutputFiles(PathsForTesting("one.out"), "")
90 ctx.SetOutputFiles(PathsForTesting("two.out", "three/four.out"), ".multiple")
91 ctx.SetOutputFiles(PathsForTesting("another.out"), ".another-tag")
92 if defaultDistPaths != nil {
93 ctx.SetOutputFiles(defaultDistPaths, DefaultDistTag)
94 }
95}
96
Jooyung Han12df5fb2019-07-11 16:18:47 +090097func (m *customModule) AndroidMk() AndroidMkData {
98 return AndroidMkData{
99 Custom: func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData) {
100 m.data = data
101 },
102 }
103}
104
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000105func (m *customModule) AndroidMkEntries() []AndroidMkEntries {
106 return []AndroidMkEntries{
107 {
Paul Duffin62269492020-11-26 20:18:42 +0000108 Class: "CUSTOM_MODULE",
Paul Duffin62269492020-11-26 20:18:42 +0000109 OutputFile: m.outputFile,
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000110 },
111 }
112}
113
Jooyung Han12df5fb2019-07-11 16:18:47 +0900114func customModuleFactory() Module {
115 module := &customModule{}
Paul Duffin62269492020-11-26 20:18:42 +0000116
117 module.AddProperties(&module.properties)
118
Jooyung Han12df5fb2019-07-11 16:18:47 +0900119 InitAndroidModule(module)
120 return module
121}
122
Colin Crossaa255532020-07-03 13:18:24 -0700123// buildContextAndCustomModuleFoo creates a config object, processes the supplied
Paul Duffin103aaae2020-11-26 17:36:46 +0000124// bp module and then returns the config and the custom module called "foo".
Colin Crossaa255532020-07-03 13:18:24 -0700125func buildContextAndCustomModuleFoo(t *testing.T, bp string) (*TestContext, *customModule) {
Paul Duffin103aaae2020-11-26 17:36:46 +0000126 t.Helper()
Paul Duffin30ac3e72021-03-20 00:36:14 +0000127 result := GroupFixturePreparers(
Paul Duffin9ca14c12021-03-16 17:30:13 +0000128 // Enable androidmk Singleton
129 PrepareForTestWithAndroidMk,
130 FixtureRegisterWithContext(func(ctx RegistrationContext) {
131 ctx.RegisterModuleType("custom", customModuleFactory)
132 }),
Trevor Radcliffe90727f42022-03-21 19:34:02 +0000133 FixtureModifyProductVariables(func(variables FixtureProductVariables) {
134 variables.DeviceProduct = proptools.StringPtr("bar")
135 }),
Paul Duffin9ca14c12021-03-16 17:30:13 +0000136 FixtureWithRootAndroidBp(bp),
Paul Duffin30ac3e72021-03-20 00:36:14 +0000137 ).RunTest(t)
Colin Cross98be1bb2019-12-13 20:41:13 -0800138
Colin Cross90607e92025-02-11 14:58:07 -0800139 module := result.ModuleForTests(t, "foo", "").Module().(*customModule)
Paul Duffin9ca14c12021-03-16 17:30:13 +0000140 return result.TestContext, module
Paul Duffin103aaae2020-11-26 17:36:46 +0000141}
142
143func TestAndroidMkSingleton_PassesUpdatedAndroidMkDataToCustomCallback(t *testing.T) {
Dan Willemsendef7b5d2021-10-17 00:22:33 -0700144 if runtime.GOOS == "darwin" {
145 // Device modules are not exported on Mac, so this test doesn't work.
146 t.SkipNow()
147 }
148
Paul Duffin103aaae2020-11-26 17:36:46 +0000149 bp := `
150 custom {
151 name: "foo",
152 required: ["bar"],
153 host_required: ["baz"],
154 target_required: ["qux"],
155 }
156 `
157
Colin Crossaa255532020-07-03 13:18:24 -0700158 _, m := buildContextAndCustomModuleFoo(t, bp)
Jooyung Han12df5fb2019-07-11 16:18:47 +0900159
160 assertEqual := func(expected interface{}, actual interface{}) {
161 if !reflect.DeepEqual(expected, actual) {
162 t.Errorf("%q expected, but got %q", expected, actual)
163 }
164 }
165 assertEqual([]string{"bar"}, m.data.Required)
166 assertEqual([]string{"baz"}, m.data.Host_required)
167 assertEqual([]string{"qux"}, m.data.Target_required)
168}
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000169
Paul Duffin8b0349c2020-11-26 14:33:21 +0000170func TestGenerateDistContributionsForMake(t *testing.T) {
171 dc := &distContributions{
172 copiesForGoals: []*copiesForGoals{
173 {
174 goals: "my_goal",
175 copies: []distCopy{
176 distCopyForTest("one.out", "one.out"),
177 distCopyForTest("two.out", "other.out"),
178 },
179 },
180 },
181 }
182
Bob Badour51804382022-04-13 11:27:19 -0700183 dc.licenseMetadataFile = PathForTesting("meta_lic")
Paul Duffin8b0349c2020-11-26 14:33:21 +0000184 makeOutput := generateDistContributionsForMake(dc)
185
186 assertStringEquals(t, `.PHONY: my_goal
Bob Badour51804382022-04-13 11:27:19 -0700187$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))
Paul Duffin8b0349c2020-11-26 14:33:21 +0000188$(call dist-for-goals,my_goal,one.out:one.out)
Bob Badour51804382022-04-13 11:27:19 -0700189$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))
Yu Liue70976d2024-10-15 20:45:35 +0000190$(call dist-for-goals,my_goal,two.out:other.out)`, strings.Join(makeOutput, "\n"))
Paul Duffin8b0349c2020-11-26 14:33:21 +0000191}
192
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000193func TestGetDistForGoals(t *testing.T) {
Paul Duffind83988d2020-11-26 17:29:35 +0000194 bp := `
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000195 custom {
196 name: "foo",
197 dist: {
198 targets: ["my_goal", "my_other_goal"],
199 tag: ".multiple",
200 },
201 dists: [
202 {
203 targets: ["my_second_goal"],
204 tag: ".multiple",
205 },
206 {
207 targets: ["my_third_goal"],
208 dir: "test/dir",
209 },
210 {
211 targets: ["my_fourth_goal"],
212 suffix: ".suffix",
213 },
214 {
215 targets: ["my_fifth_goal"],
216 dest: "new-name",
217 },
218 {
219 targets: ["my_sixth_goal"],
220 dest: "new-name",
221 dir: "some/dir",
222 suffix: ".suffix",
223 },
224 ],
225 }
Paul Duffind83988d2020-11-26 17:29:35 +0000226 `
227
228 expectedAndroidMkLines := []string{
Yu Liue70976d2024-10-15 20:45:35 +0000229 ".PHONY: my_second_goal",
230 "$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))",
231 "$(call dist-for-goals,my_second_goal,two.out:two.out)",
232 "$(if $(strip $(ALL_TARGETS.three/four.out.META_LIC)),,$(eval ALL_TARGETS.three/four.out.META_LIC := meta_lic))",
233 "$(call dist-for-goals,my_second_goal,three/four.out:four.out)",
234 ".PHONY: my_third_goal",
235 "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))",
236 "$(call dist-for-goals,my_third_goal,one.out:test/dir/one.out)",
237 ".PHONY: my_fourth_goal",
238 "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))",
239 "$(call dist-for-goals,my_fourth_goal,one.out:one.suffix.out)",
240 ".PHONY: my_fifth_goal",
241 "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))",
242 "$(call dist-for-goals,my_fifth_goal,one.out:new-name)",
243 ".PHONY: my_sixth_goal",
244 "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))",
245 "$(call dist-for-goals,my_sixth_goal,one.out:some/dir/new-name.suffix)",
246 ".PHONY: my_goal my_other_goal",
247 "$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))",
248 "$(call dist-for-goals,my_goal my_other_goal,two.out:two.out)",
249 "$(if $(strip $(ALL_TARGETS.three/four.out.META_LIC)),,$(eval ALL_TARGETS.three/four.out.META_LIC := meta_lic))",
250 "$(call dist-for-goals,my_goal my_other_goal,three/four.out:four.out)",
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000251 }
252
Colin Crossaa255532020-07-03 13:18:24 -0700253 ctx, module := buildContextAndCustomModuleFoo(t, bp)
254 entries := AndroidMkEntriesForTest(t, ctx, module)
Paul Duffind83988d2020-11-26 17:29:35 +0000255 if len(entries) != 1 {
256 t.Errorf("Expected a single AndroidMk entry, got %d", len(entries))
257 }
258 androidMkLines := entries[0].GetDistForGoals(module)
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000259
Paul Duffind83988d2020-11-26 17:29:35 +0000260 if len(androidMkLines) != len(expectedAndroidMkLines) {
261 t.Errorf(
262 "Expected %d AndroidMk lines, got %d:\n%v",
263 len(expectedAndroidMkLines),
264 len(androidMkLines),
265 androidMkLines,
266 )
267 }
268 for idx, line := range androidMkLines {
Yu Liuec810542024-08-26 18:09:15 +0000269 expectedLine := strings.ReplaceAll(expectedAndroidMkLines[idx], "meta_lic",
270 OtherModuleProviderOrDefault(ctx, module, InstallFilesProvider).LicenseMetadataFile.String())
Paul Duffind83988d2020-11-26 17:29:35 +0000271 if line != expectedLine {
272 t.Errorf(
273 "Expected AndroidMk line to be '%s', got '%s'",
274 expectedLine,
275 line,
276 )
277 }
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000278 }
279}
Paul Duffin8b0349c2020-11-26 14:33:21 +0000280
281func distCopyForTest(from, to string) distCopy {
282 return distCopy{PathForTesting(from), to}
283}
284
285func TestGetDistContributions(t *testing.T) {
286 compareContributions := func(d1 *distContributions, d2 *distContributions) error {
287 if d1 == nil || d2 == nil {
288 if d1 != d2 {
289 return fmt.Errorf("pointer mismatch, expected both to be nil but they were %p and %p", d1, d2)
290 } else {
291 return nil
292 }
293 }
294 if expected, actual := len(d1.copiesForGoals), len(d2.copiesForGoals); expected != actual {
295 return fmt.Errorf("length mismatch, expected %d found %d", expected, actual)
296 }
297
298 for i, copies1 := range d1.copiesForGoals {
299 copies2 := d2.copiesForGoals[i]
300 if expected, actual := copies1.goals, copies2.goals; expected != actual {
301 return fmt.Errorf("goals mismatch at position %d: expected %q found %q", i, expected, actual)
302 }
303
304 if expected, actual := len(copies1.copies), len(copies2.copies); expected != actual {
305 return fmt.Errorf("length mismatch in copy instructions at position %d, expected %d found %d", i, expected, actual)
306 }
307
308 for j, c1 := range copies1.copies {
309 c2 := copies2.copies[j]
310 if expected, actual := NormalizePathForTesting(c1.from), NormalizePathForTesting(c2.from); expected != actual {
311 return fmt.Errorf("paths mismatch at position %d.%d: expected %q found %q", i, j, expected, actual)
312 }
313
314 if expected, actual := c1.dest, c2.dest; expected != actual {
315 return fmt.Errorf("dest mismatch at position %d.%d: expected %q found %q", i, j, expected, actual)
316 }
317 }
318 }
319
320 return nil
321 }
322
323 formatContributions := func(d *distContributions) string {
324 buf := &strings.Builder{}
325 if d == nil {
326 fmt.Fprint(buf, "nil")
327 } else {
328 for _, copiesForGoals := range d.copiesForGoals {
329 fmt.Fprintf(buf, " Goals: %q {\n", copiesForGoals.goals)
330 for _, c := range copiesForGoals.copies {
331 fmt.Fprintf(buf, " %s -> %s\n", NormalizePathForTesting(c.from), c.dest)
332 }
333 fmt.Fprint(buf, " }\n")
334 }
335 }
336 return buf.String()
337 }
338
339 testHelper := func(t *testing.T, name, bp string, expectedContributions *distContributions) {
340 t.Helper()
341 t.Run(name, func(t *testing.T) {
342 t.Helper()
343
Colin Crossaa255532020-07-03 13:18:24 -0700344 ctx, module := buildContextAndCustomModuleFoo(t, bp)
345 entries := AndroidMkEntriesForTest(t, ctx, module)
Paul Duffin8b0349c2020-11-26 14:33:21 +0000346 if len(entries) != 1 {
347 t.Errorf("Expected a single AndroidMk entry, got %d", len(entries))
348 }
349 distContributions := entries[0].getDistContributions(module)
350
351 if err := compareContributions(expectedContributions, distContributions); err != nil {
352 t.Errorf("%s\nExpected Contributions\n%sActualContributions\n%s",
353 err,
354 formatContributions(expectedContributions),
355 formatContributions(distContributions))
356 }
357 })
358 }
359
360 testHelper(t, "dist-without-tag", `
361 custom {
362 name: "foo",
363 dist: {
364 targets: ["my_goal"]
365 }
366 }
367`,
368 &distContributions{
369 copiesForGoals: []*copiesForGoals{
370 {
371 goals: "my_goal",
372 copies: []distCopy{
373 distCopyForTest("one.out", "one.out"),
374 },
375 },
376 },
377 })
378
379 testHelper(t, "dist-with-tag", `
380 custom {
381 name: "foo",
382 dist: {
383 targets: ["my_goal"],
384 tag: ".another-tag",
385 }
386 }
387`,
388 &distContributions{
389 copiesForGoals: []*copiesForGoals{
390 {
391 goals: "my_goal",
392 copies: []distCopy{
393 distCopyForTest("another.out", "another.out"),
394 },
395 },
396 },
397 })
398
Trevor Radcliffe90727f42022-03-21 19:34:02 +0000399 testHelper(t, "append-artifact-with-product", `
400 custom {
401 name: "foo",
402 dist: {
403 targets: ["my_goal"],
404 append_artifact_with_product: true,
405 }
406 }
407`, &distContributions{
408 copiesForGoals: []*copiesForGoals{
409 {
410 goals: "my_goal",
411 copies: []distCopy{
412 distCopyForTest("one.out", "one_bar.out"),
413 },
414 },
415 },
416 })
417
Paul Duffin8b0349c2020-11-26 14:33:21 +0000418 testHelper(t, "dists-with-tag", `
419 custom {
420 name: "foo",
421 dists: [
422 {
423 targets: ["my_goal"],
424 tag: ".another-tag",
425 },
426 ],
427 }
428`,
429 &distContributions{
430 copiesForGoals: []*copiesForGoals{
431 {
432 goals: "my_goal",
433 copies: []distCopy{
434 distCopyForTest("another.out", "another.out"),
435 },
436 },
437 },
438 })
439
440 testHelper(t, "multiple-dists-with-and-without-tag", `
441 custom {
442 name: "foo",
443 dists: [
444 {
445 targets: ["my_goal"],
446 },
447 {
448 targets: ["my_second_goal", "my_third_goal"],
449 },
450 ],
451 }
452`,
453 &distContributions{
454 copiesForGoals: []*copiesForGoals{
455 {
456 goals: "my_goal",
457 copies: []distCopy{
458 distCopyForTest("one.out", "one.out"),
459 },
460 },
461 {
462 goals: "my_second_goal my_third_goal",
463 copies: []distCopy{
464 distCopyForTest("one.out", "one.out"),
465 },
466 },
467 },
468 })
469
470 testHelper(t, "dist-plus-dists-without-tags", `
471 custom {
472 name: "foo",
473 dist: {
474 targets: ["my_goal"],
475 },
476 dists: [
477 {
478 targets: ["my_second_goal", "my_third_goal"],
479 },
480 ],
481 }
482`,
483 &distContributions{
484 copiesForGoals: []*copiesForGoals{
485 {
486 goals: "my_second_goal my_third_goal",
487 copies: []distCopy{
488 distCopyForTest("one.out", "one.out"),
489 },
490 },
491 {
492 goals: "my_goal",
493 copies: []distCopy{
494 distCopyForTest("one.out", "one.out"),
495 },
496 },
497 },
498 })
499
500 testHelper(t, "dist-plus-dists-with-tags", `
501 custom {
502 name: "foo",
503 dist: {
504 targets: ["my_goal", "my_other_goal"],
505 tag: ".multiple",
506 },
507 dists: [
508 {
509 targets: ["my_second_goal"],
510 tag: ".multiple",
511 },
512 {
513 targets: ["my_third_goal"],
514 dir: "test/dir",
515 },
516 {
517 targets: ["my_fourth_goal"],
518 suffix: ".suffix",
519 },
520 {
521 targets: ["my_fifth_goal"],
522 dest: "new-name",
523 },
524 {
525 targets: ["my_sixth_goal"],
526 dest: "new-name",
527 dir: "some/dir",
528 suffix: ".suffix",
529 },
530 ],
531 }
532`,
533 &distContributions{
534 copiesForGoals: []*copiesForGoals{
535 {
536 goals: "my_second_goal",
537 copies: []distCopy{
538 distCopyForTest("two.out", "two.out"),
539 distCopyForTest("three/four.out", "four.out"),
540 },
541 },
542 {
543 goals: "my_third_goal",
544 copies: []distCopy{
545 distCopyForTest("one.out", "test/dir/one.out"),
546 },
547 },
548 {
549 goals: "my_fourth_goal",
550 copies: []distCopy{
551 distCopyForTest("one.out", "one.suffix.out"),
552 },
553 },
554 {
555 goals: "my_fifth_goal",
556 copies: []distCopy{
557 distCopyForTest("one.out", "new-name"),
558 },
559 },
560 {
561 goals: "my_sixth_goal",
562 copies: []distCopy{
563 distCopyForTest("one.out", "some/dir/new-name.suffix"),
564 },
565 },
566 {
567 goals: "my_goal my_other_goal",
568 copies: []distCopy{
569 distCopyForTest("two.out", "two.out"),
570 distCopyForTest("three/four.out", "four.out"),
571 },
572 },
573 },
574 })
Paul Duffin62269492020-11-26 20:18:42 +0000575
576 // The above test the default values of default_dist_files and use_output_file.
577
578 // The following tests explicitly test the different combinations of those settings.
579 testHelper(t, "tagged-dist-files-no-output", `
580 custom {
581 name: "foo",
582 default_dist_files: "tagged",
583 dist_output_file: false,
584 dists: [
585 {
586 targets: ["my_goal"],
587 },
588 {
589 targets: ["my_goal"],
590 tag: ".multiple",
591 },
592 ],
593 }
594`, &distContributions{
595 copiesForGoals: []*copiesForGoals{
596 {
597 goals: "my_goal",
598 copies: []distCopy{
599 distCopyForTest("one.out", "one.out"),
600 },
601 },
602 {
603 goals: "my_goal",
604 copies: []distCopy{
605 distCopyForTest("two.out", "two.out"),
606 distCopyForTest("three/four.out", "four.out"),
607 },
608 },
609 },
610 })
611
612 testHelper(t, "default-dist-files-no-output", `
613 custom {
614 name: "foo",
615 default_dist_files: "default",
616 dist_output_file: false,
617 dists: [
618 {
619 targets: ["my_goal"],
620 },
Paul Duffin62269492020-11-26 20:18:42 +0000621 {
622 targets: ["my_goal"],
623 tag: ".multiple",
624 },
625 ],
626 }
627`, &distContributions{
628 copiesForGoals: []*copiesForGoals{
629 {
630 goals: "my_goal",
631 copies: []distCopy{
632 distCopyForTest("default-dist.out", "default-dist.out"),
633 },
634 },
Paul Duffinaf970a22020-11-23 23:32:56 +0000635 {
636 goals: "my_goal",
637 copies: []distCopy{
638 distCopyForTest("two.out", "two.out"),
639 distCopyForTest("three/four.out", "four.out"),
640 },
641 },
Paul Duffin62269492020-11-26 20:18:42 +0000642 },
643 })
644
645 testHelper(t, "no-dist-files-no-output", `
646 custom {
647 name: "foo",
648 default_dist_files: "none",
649 dist_output_file: false,
650 dists: [
651 // The following is silently ignored because there is not default file
652 // in either the dist files or the output file.
653 {
654 targets: ["my_goal"],
655 },
Paul Duffin62269492020-11-26 20:18:42 +0000656 {
657 targets: ["my_goal"],
658 tag: ".multiple",
659 },
660 ],
661 }
Paul Duffinaf970a22020-11-23 23:32:56 +0000662`, &distContributions{
663 copiesForGoals: []*copiesForGoals{
664 {
665 goals: "my_goal",
666 copies: []distCopy{
667 distCopyForTest("two.out", "two.out"),
668 distCopyForTest("three/four.out", "four.out"),
669 },
670 },
671 },
672 })
Paul Duffin62269492020-11-26 20:18:42 +0000673
674 testHelper(t, "tagged-dist-files-default-output", `
675 custom {
676 name: "foo",
677 default_dist_files: "tagged",
678 dist_output_file: true,
679 dists: [
680 {
681 targets: ["my_goal"],
682 },
683 {
684 targets: ["my_goal"],
685 tag: ".multiple",
686 },
687 ],
688 }
689`, &distContributions{
690 copiesForGoals: []*copiesForGoals{
691 {
692 goals: "my_goal",
693 copies: []distCopy{
694 distCopyForTest("one.out", "one.out"),
695 },
696 },
697 {
698 goals: "my_goal",
699 copies: []distCopy{
700 distCopyForTest("two.out", "two.out"),
701 distCopyForTest("three/four.out", "four.out"),
702 },
703 },
704 },
705 })
706
707 testHelper(t, "default-dist-files-default-output", `
708 custom {
709 name: "foo",
710 default_dist_files: "default",
711 dist_output_file: true,
712 dists: [
713 {
714 targets: ["my_goal"],
715 },
Paul Duffin62269492020-11-26 20:18:42 +0000716 {
717 targets: ["my_goal"],
718 tag: ".multiple",
719 },
720 ],
721 }
722`, &distContributions{
723 copiesForGoals: []*copiesForGoals{
724 {
725 goals: "my_goal",
726 copies: []distCopy{
727 distCopyForTest("default-dist.out", "default-dist.out"),
728 },
729 },
Paul Duffinaf970a22020-11-23 23:32:56 +0000730 {
731 goals: "my_goal",
732 copies: []distCopy{
733 distCopyForTest("two.out", "two.out"),
734 distCopyForTest("three/four.out", "four.out"),
735 },
736 },
Paul Duffin62269492020-11-26 20:18:42 +0000737 },
738 })
739
740 testHelper(t, "no-dist-files-default-output", `
741 custom {
742 name: "foo",
743 default_dist_files: "none",
744 dist_output_file: true,
745 dists: [
746 {
747 targets: ["my_goal"],
748 },
Paul Duffin62269492020-11-26 20:18:42 +0000749 {
750 targets: ["my_goal"],
751 tag: ".multiple",
752 },
753 ],
754 }
755`, &distContributions{
756 copiesForGoals: []*copiesForGoals{
757 {
758 goals: "my_goal",
759 copies: []distCopy{
760 distCopyForTest("dist-output-file.out", "dist-output-file.out"),
761 },
762 },
Paul Duffinaf970a22020-11-23 23:32:56 +0000763 {
764 goals: "my_goal",
765 copies: []distCopy{
766 distCopyForTest("two.out", "two.out"),
767 distCopyForTest("three/four.out", "four.out"),
768 },
769 },
Paul Duffin62269492020-11-26 20:18:42 +0000770 },
771 })
Paul Duffin8b0349c2020-11-26 14:33:21 +0000772}