blob: c37eeabff77250373e194aa331d0e97abbfaebe6 [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
37 distFiles TaggedDistFiles
38 outputFile OptionalPath
Jooyung Han12df5fb2019-07-11 16:18:47 +090039}
40
Paul Duffin62269492020-11-26 20:18:42 +000041const (
42 defaultDistFiles_None = "none"
43 defaultDistFiles_Default = "default"
44 defaultDistFiles_Tagged = "tagged"
45)
46
Jooyung Han12df5fb2019-07-11 16:18:47 +090047func (m *customModule) GenerateAndroidBuildActions(ctx ModuleContext) {
Paul Duffin62269492020-11-26 20:18:42 +000048
mrziwang01715ca2024-07-01 11:50:18 -070049 var defaultDistPaths Paths
Bob Badour51804382022-04-13 11:27:19 -070050
Paul Duffin62269492020-11-26 20:18:42 +000051 // If the dist_output_file: true then create an output file that is stored in
52 // the OutputFile property of the AndroidMkEntry.
53 if proptools.BoolDefault(m.properties.Dist_output_file, true) {
Paul Duffin74f05592020-11-25 16:37:46 +000054 path := PathForTesting("dist-output-file.out")
55 m.outputFile = OptionalPathForPath(path)
56
57 // Previous code would prioritize the DistFiles property over the OutputFile
58 // property in AndroidMkEntry when determining the default dist paths.
59 // Setting this first allows it to be overridden based on the
60 // default_dist_files setting replicating that previous behavior.
mrziwang01715ca2024-07-01 11:50:18 -070061 defaultDistPaths = Paths{path}
Paul Duffin62269492020-11-26 20:18:42 +000062 }
63
64 // Based on the setting of the default_dist_files property possibly create a
65 // TaggedDistFiles structure that will be stored in the DistFiles property of
66 // the AndroidMkEntry.
67 defaultDistFiles := proptools.StringDefault(m.properties.Default_dist_files, defaultDistFiles_Tagged)
68 switch defaultDistFiles {
69 case defaultDistFiles_None:
mrziwang01715ca2024-07-01 11:50:18 -070070 m.setOutputFiles(ctx, defaultDistPaths)
Paul Duffin62269492020-11-26 20:18:42 +000071
72 case defaultDistFiles_Default:
Paul Duffin74f05592020-11-25 16:37:46 +000073 path := PathForTesting("default-dist.out")
mrziwang01715ca2024-07-01 11:50:18 -070074 defaultDistPaths = Paths{path}
75 m.setOutputFiles(ctx, defaultDistPaths)
Paul Duffin74f05592020-11-25 16:37:46 +000076 m.distFiles = MakeDefaultDistFiles(path)
Paul Duffin62269492020-11-26 20:18:42 +000077
78 case defaultDistFiles_Tagged:
Paul Duffin74f05592020-11-25 16:37:46 +000079 // Module types that set AndroidMkEntry.DistFiles to the result of calling
80 // GenerateTaggedDistFiles(ctx) relied on no tag being treated as "" which
mrziwang01715ca2024-07-01 11:50:18 -070081 // meant that the default dist paths would be the same as empty-string-tag
82 // output files. In order to preserve that behavior when treating no tag
83 // as being equal to DefaultDistTag this ensures that DefaultDistTag output
84 // will be the same as empty-string-tag output.
85 defaultDistPaths = PathsForTesting("one.out")
86 m.setOutputFiles(ctx, defaultDistPaths)
Paul Duffin74f05592020-11-25 16:37:46 +000087
88 // This must be called after setting defaultDistPaths/outputFile as
mrziwang01715ca2024-07-01 11:50:18 -070089 // GenerateTaggedDistFiles calls into outputFiles property which may use
90 // those fields.
Paul Duffin62269492020-11-26 20:18:42 +000091 m.distFiles = m.GenerateTaggedDistFiles(ctx)
92 }
Jooyung Han12df5fb2019-07-11 16:18:47 +090093}
94
mrziwang01715ca2024-07-01 11:50:18 -070095func (m *customModule) setOutputFiles(ctx ModuleContext, defaultDistPaths Paths) {
96 ctx.SetOutputFiles(PathsForTesting("one.out"), "")
97 ctx.SetOutputFiles(PathsForTesting("two.out", "three/four.out"), ".multiple")
98 ctx.SetOutputFiles(PathsForTesting("another.out"), ".another-tag")
99 if defaultDistPaths != nil {
100 ctx.SetOutputFiles(defaultDistPaths, DefaultDistTag)
101 }
102}
103
Jooyung Han12df5fb2019-07-11 16:18:47 +0900104func (m *customModule) AndroidMk() AndroidMkData {
105 return AndroidMkData{
106 Custom: func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData) {
107 m.data = data
108 },
109 }
110}
111
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000112func (m *customModule) AndroidMkEntries() []AndroidMkEntries {
113 return []AndroidMkEntries{
114 {
Paul Duffin62269492020-11-26 20:18:42 +0000115 Class: "CUSTOM_MODULE",
116 DistFiles: m.distFiles,
117 OutputFile: m.outputFile,
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000118 },
119 }
120}
121
Jooyung Han12df5fb2019-07-11 16:18:47 +0900122func customModuleFactory() Module {
123 module := &customModule{}
Paul Duffin62269492020-11-26 20:18:42 +0000124
125 module.AddProperties(&module.properties)
126
Jooyung Han12df5fb2019-07-11 16:18:47 +0900127 InitAndroidModule(module)
128 return module
129}
130
Colin Crossaa255532020-07-03 13:18:24 -0700131// buildContextAndCustomModuleFoo creates a config object, processes the supplied
Paul Duffin103aaae2020-11-26 17:36:46 +0000132// bp module and then returns the config and the custom module called "foo".
Colin Crossaa255532020-07-03 13:18:24 -0700133func buildContextAndCustomModuleFoo(t *testing.T, bp string) (*TestContext, *customModule) {
Paul Duffin103aaae2020-11-26 17:36:46 +0000134 t.Helper()
Paul Duffin30ac3e72021-03-20 00:36:14 +0000135 result := GroupFixturePreparers(
Paul Duffin9ca14c12021-03-16 17:30:13 +0000136 // Enable androidmk Singleton
137 PrepareForTestWithAndroidMk,
138 FixtureRegisterWithContext(func(ctx RegistrationContext) {
139 ctx.RegisterModuleType("custom", customModuleFactory)
140 }),
Trevor Radcliffe90727f42022-03-21 19:34:02 +0000141 FixtureModifyProductVariables(func(variables FixtureProductVariables) {
142 variables.DeviceProduct = proptools.StringPtr("bar")
143 }),
Paul Duffin9ca14c12021-03-16 17:30:13 +0000144 FixtureWithRootAndroidBp(bp),
Paul Duffin30ac3e72021-03-20 00:36:14 +0000145 ).RunTest(t)
Colin Cross98be1bb2019-12-13 20:41:13 -0800146
Paul Duffin9ca14c12021-03-16 17:30:13 +0000147 module := result.ModuleForTests("foo", "").Module().(*customModule)
148 return result.TestContext, module
Paul Duffin103aaae2020-11-26 17:36:46 +0000149}
150
151func TestAndroidMkSingleton_PassesUpdatedAndroidMkDataToCustomCallback(t *testing.T) {
Dan Willemsendef7b5d2021-10-17 00:22:33 -0700152 if runtime.GOOS == "darwin" {
153 // Device modules are not exported on Mac, so this test doesn't work.
154 t.SkipNow()
155 }
156
Paul Duffin103aaae2020-11-26 17:36:46 +0000157 bp := `
158 custom {
159 name: "foo",
160 required: ["bar"],
161 host_required: ["baz"],
162 target_required: ["qux"],
163 }
164 `
165
Colin Crossaa255532020-07-03 13:18:24 -0700166 _, m := buildContextAndCustomModuleFoo(t, bp)
Jooyung Han12df5fb2019-07-11 16:18:47 +0900167
168 assertEqual := func(expected interface{}, actual interface{}) {
169 if !reflect.DeepEqual(expected, actual) {
170 t.Errorf("%q expected, but got %q", expected, actual)
171 }
172 }
173 assertEqual([]string{"bar"}, m.data.Required)
174 assertEqual([]string{"baz"}, m.data.Host_required)
175 assertEqual([]string{"qux"}, m.data.Target_required)
176}
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000177
Paul Duffin8b0349c2020-11-26 14:33:21 +0000178func TestGenerateDistContributionsForMake(t *testing.T) {
179 dc := &distContributions{
180 copiesForGoals: []*copiesForGoals{
181 {
182 goals: "my_goal",
183 copies: []distCopy{
184 distCopyForTest("one.out", "one.out"),
185 distCopyForTest("two.out", "other.out"),
186 },
187 },
188 },
189 }
190
Bob Badour51804382022-04-13 11:27:19 -0700191 dc.licenseMetadataFile = PathForTesting("meta_lic")
Paul Duffin8b0349c2020-11-26 14:33:21 +0000192 makeOutput := generateDistContributionsForMake(dc)
193
194 assertStringEquals(t, `.PHONY: my_goal
Bob Badour51804382022-04-13 11:27:19 -0700195$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))
Paul Duffin8b0349c2020-11-26 14:33:21 +0000196$(call dist-for-goals,my_goal,one.out:one.out)
Bob Badour51804382022-04-13 11:27:19 -0700197$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))
Paul Duffin8b0349c2020-11-26 14:33:21 +0000198$(call dist-for-goals,my_goal,two.out:other.out)
199`, strings.Join(makeOutput, ""))
200}
201
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000202func TestGetDistForGoals(t *testing.T) {
Paul Duffind83988d2020-11-26 17:29:35 +0000203 bp := `
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000204 custom {
205 name: "foo",
206 dist: {
207 targets: ["my_goal", "my_other_goal"],
208 tag: ".multiple",
209 },
210 dists: [
211 {
212 targets: ["my_second_goal"],
213 tag: ".multiple",
214 },
215 {
216 targets: ["my_third_goal"],
217 dir: "test/dir",
218 },
219 {
220 targets: ["my_fourth_goal"],
221 suffix: ".suffix",
222 },
223 {
224 targets: ["my_fifth_goal"],
225 dest: "new-name",
226 },
227 {
228 targets: ["my_sixth_goal"],
229 dest: "new-name",
230 dir: "some/dir",
231 suffix: ".suffix",
232 },
233 ],
234 }
Paul Duffind83988d2020-11-26 17:29:35 +0000235 `
236
237 expectedAndroidMkLines := []string{
238 ".PHONY: my_second_goal\n",
Bob Badour51804382022-04-13 11:27:19 -0700239 "$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))\n",
Paul Duffind83988d2020-11-26 17:29:35 +0000240 "$(call dist-for-goals,my_second_goal,two.out:two.out)\n",
Bob Badour51804382022-04-13 11:27:19 -0700241 "$(if $(strip $(ALL_TARGETS.three/four.out.META_LIC)),,$(eval ALL_TARGETS.three/four.out.META_LIC := meta_lic))\n",
Paul Duffind83988d2020-11-26 17:29:35 +0000242 "$(call dist-for-goals,my_second_goal,three/four.out:four.out)\n",
243 ".PHONY: my_third_goal\n",
Bob Badour51804382022-04-13 11:27:19 -0700244 "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n",
Paul Duffind83988d2020-11-26 17:29:35 +0000245 "$(call dist-for-goals,my_third_goal,one.out:test/dir/one.out)\n",
246 ".PHONY: my_fourth_goal\n",
Bob Badour51804382022-04-13 11:27:19 -0700247 "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n",
Paul Duffind83988d2020-11-26 17:29:35 +0000248 "$(call dist-for-goals,my_fourth_goal,one.out:one.suffix.out)\n",
249 ".PHONY: my_fifth_goal\n",
Bob Badour51804382022-04-13 11:27:19 -0700250 "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n",
Paul Duffind83988d2020-11-26 17:29:35 +0000251 "$(call dist-for-goals,my_fifth_goal,one.out:new-name)\n",
252 ".PHONY: my_sixth_goal\n",
Bob Badour51804382022-04-13 11:27:19 -0700253 "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n",
Paul Duffind83988d2020-11-26 17:29:35 +0000254 "$(call dist-for-goals,my_sixth_goal,one.out:some/dir/new-name.suffix)\n",
255 ".PHONY: my_goal my_other_goal\n",
Bob Badour51804382022-04-13 11:27:19 -0700256 "$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))\n",
Paul Duffind83988d2020-11-26 17:29:35 +0000257 "$(call dist-for-goals,my_goal my_other_goal,two.out:two.out)\n",
Bob Badour51804382022-04-13 11:27:19 -0700258 "$(if $(strip $(ALL_TARGETS.three/four.out.META_LIC)),,$(eval ALL_TARGETS.three/four.out.META_LIC := meta_lic))\n",
Paul Duffind83988d2020-11-26 17:29:35 +0000259 "$(call dist-for-goals,my_goal my_other_goal,three/four.out:four.out)\n",
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000260 }
261
Colin Crossaa255532020-07-03 13:18:24 -0700262 ctx, module := buildContextAndCustomModuleFoo(t, bp)
263 entries := AndroidMkEntriesForTest(t, ctx, module)
Paul Duffind83988d2020-11-26 17:29:35 +0000264 if len(entries) != 1 {
265 t.Errorf("Expected a single AndroidMk entry, got %d", len(entries))
266 }
267 androidMkLines := entries[0].GetDistForGoals(module)
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000268
Paul Duffind83988d2020-11-26 17:29:35 +0000269 if len(androidMkLines) != len(expectedAndroidMkLines) {
270 t.Errorf(
271 "Expected %d AndroidMk lines, got %d:\n%v",
272 len(expectedAndroidMkLines),
273 len(androidMkLines),
274 androidMkLines,
275 )
276 }
277 for idx, line := range androidMkLines {
Yu Liuec810542024-08-26 18:09:15 +0000278 expectedLine := strings.ReplaceAll(expectedAndroidMkLines[idx], "meta_lic",
279 OtherModuleProviderOrDefault(ctx, module, InstallFilesProvider).LicenseMetadataFile.String())
Paul Duffind83988d2020-11-26 17:29:35 +0000280 if line != expectedLine {
281 t.Errorf(
282 "Expected AndroidMk line to be '%s', got '%s'",
283 expectedLine,
284 line,
285 )
286 }
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000287 }
288}
Paul Duffin8b0349c2020-11-26 14:33:21 +0000289
290func distCopyForTest(from, to string) distCopy {
291 return distCopy{PathForTesting(from), to}
292}
293
294func TestGetDistContributions(t *testing.T) {
295 compareContributions := func(d1 *distContributions, d2 *distContributions) error {
296 if d1 == nil || d2 == nil {
297 if d1 != d2 {
298 return fmt.Errorf("pointer mismatch, expected both to be nil but they were %p and %p", d1, d2)
299 } else {
300 return nil
301 }
302 }
303 if expected, actual := len(d1.copiesForGoals), len(d2.copiesForGoals); expected != actual {
304 return fmt.Errorf("length mismatch, expected %d found %d", expected, actual)
305 }
306
307 for i, copies1 := range d1.copiesForGoals {
308 copies2 := d2.copiesForGoals[i]
309 if expected, actual := copies1.goals, copies2.goals; expected != actual {
310 return fmt.Errorf("goals mismatch at position %d: expected %q found %q", i, expected, actual)
311 }
312
313 if expected, actual := len(copies1.copies), len(copies2.copies); expected != actual {
314 return fmt.Errorf("length mismatch in copy instructions at position %d, expected %d found %d", i, expected, actual)
315 }
316
317 for j, c1 := range copies1.copies {
318 c2 := copies2.copies[j]
319 if expected, actual := NormalizePathForTesting(c1.from), NormalizePathForTesting(c2.from); expected != actual {
320 return fmt.Errorf("paths mismatch at position %d.%d: expected %q found %q", i, j, expected, actual)
321 }
322
323 if expected, actual := c1.dest, c2.dest; expected != actual {
324 return fmt.Errorf("dest mismatch at position %d.%d: expected %q found %q", i, j, expected, actual)
325 }
326 }
327 }
328
329 return nil
330 }
331
332 formatContributions := func(d *distContributions) string {
333 buf := &strings.Builder{}
334 if d == nil {
335 fmt.Fprint(buf, "nil")
336 } else {
337 for _, copiesForGoals := range d.copiesForGoals {
338 fmt.Fprintf(buf, " Goals: %q {\n", copiesForGoals.goals)
339 for _, c := range copiesForGoals.copies {
340 fmt.Fprintf(buf, " %s -> %s\n", NormalizePathForTesting(c.from), c.dest)
341 }
342 fmt.Fprint(buf, " }\n")
343 }
344 }
345 return buf.String()
346 }
347
348 testHelper := func(t *testing.T, name, bp string, expectedContributions *distContributions) {
349 t.Helper()
350 t.Run(name, func(t *testing.T) {
351 t.Helper()
352
Colin Crossaa255532020-07-03 13:18:24 -0700353 ctx, module := buildContextAndCustomModuleFoo(t, bp)
354 entries := AndroidMkEntriesForTest(t, ctx, module)
Paul Duffin8b0349c2020-11-26 14:33:21 +0000355 if len(entries) != 1 {
356 t.Errorf("Expected a single AndroidMk entry, got %d", len(entries))
357 }
358 distContributions := entries[0].getDistContributions(module)
359
360 if err := compareContributions(expectedContributions, distContributions); err != nil {
361 t.Errorf("%s\nExpected Contributions\n%sActualContributions\n%s",
362 err,
363 formatContributions(expectedContributions),
364 formatContributions(distContributions))
365 }
366 })
367 }
368
369 testHelper(t, "dist-without-tag", `
370 custom {
371 name: "foo",
372 dist: {
373 targets: ["my_goal"]
374 }
375 }
376`,
377 &distContributions{
378 copiesForGoals: []*copiesForGoals{
379 {
380 goals: "my_goal",
381 copies: []distCopy{
382 distCopyForTest("one.out", "one.out"),
383 },
384 },
385 },
386 })
387
388 testHelper(t, "dist-with-tag", `
389 custom {
390 name: "foo",
391 dist: {
392 targets: ["my_goal"],
393 tag: ".another-tag",
394 }
395 }
396`,
397 &distContributions{
398 copiesForGoals: []*copiesForGoals{
399 {
400 goals: "my_goal",
401 copies: []distCopy{
402 distCopyForTest("another.out", "another.out"),
403 },
404 },
405 },
406 })
407
Trevor Radcliffe90727f42022-03-21 19:34:02 +0000408 testHelper(t, "append-artifact-with-product", `
409 custom {
410 name: "foo",
411 dist: {
412 targets: ["my_goal"],
413 append_artifact_with_product: true,
414 }
415 }
416`, &distContributions{
417 copiesForGoals: []*copiesForGoals{
418 {
419 goals: "my_goal",
420 copies: []distCopy{
421 distCopyForTest("one.out", "one_bar.out"),
422 },
423 },
424 },
425 })
426
Paul Duffin8b0349c2020-11-26 14:33:21 +0000427 testHelper(t, "dists-with-tag", `
428 custom {
429 name: "foo",
430 dists: [
431 {
432 targets: ["my_goal"],
433 tag: ".another-tag",
434 },
435 ],
436 }
437`,
438 &distContributions{
439 copiesForGoals: []*copiesForGoals{
440 {
441 goals: "my_goal",
442 copies: []distCopy{
443 distCopyForTest("another.out", "another.out"),
444 },
445 },
446 },
447 })
448
449 testHelper(t, "multiple-dists-with-and-without-tag", `
450 custom {
451 name: "foo",
452 dists: [
453 {
454 targets: ["my_goal"],
455 },
456 {
457 targets: ["my_second_goal", "my_third_goal"],
458 },
459 ],
460 }
461`,
462 &distContributions{
463 copiesForGoals: []*copiesForGoals{
464 {
465 goals: "my_goal",
466 copies: []distCopy{
467 distCopyForTest("one.out", "one.out"),
468 },
469 },
470 {
471 goals: "my_second_goal my_third_goal",
472 copies: []distCopy{
473 distCopyForTest("one.out", "one.out"),
474 },
475 },
476 },
477 })
478
479 testHelper(t, "dist-plus-dists-without-tags", `
480 custom {
481 name: "foo",
482 dist: {
483 targets: ["my_goal"],
484 },
485 dists: [
486 {
487 targets: ["my_second_goal", "my_third_goal"],
488 },
489 ],
490 }
491`,
492 &distContributions{
493 copiesForGoals: []*copiesForGoals{
494 {
495 goals: "my_second_goal my_third_goal",
496 copies: []distCopy{
497 distCopyForTest("one.out", "one.out"),
498 },
499 },
500 {
501 goals: "my_goal",
502 copies: []distCopy{
503 distCopyForTest("one.out", "one.out"),
504 },
505 },
506 },
507 })
508
509 testHelper(t, "dist-plus-dists-with-tags", `
510 custom {
511 name: "foo",
512 dist: {
513 targets: ["my_goal", "my_other_goal"],
514 tag: ".multiple",
515 },
516 dists: [
517 {
518 targets: ["my_second_goal"],
519 tag: ".multiple",
520 },
521 {
522 targets: ["my_third_goal"],
523 dir: "test/dir",
524 },
525 {
526 targets: ["my_fourth_goal"],
527 suffix: ".suffix",
528 },
529 {
530 targets: ["my_fifth_goal"],
531 dest: "new-name",
532 },
533 {
534 targets: ["my_sixth_goal"],
535 dest: "new-name",
536 dir: "some/dir",
537 suffix: ".suffix",
538 },
539 ],
540 }
541`,
542 &distContributions{
543 copiesForGoals: []*copiesForGoals{
544 {
545 goals: "my_second_goal",
546 copies: []distCopy{
547 distCopyForTest("two.out", "two.out"),
548 distCopyForTest("three/four.out", "four.out"),
549 },
550 },
551 {
552 goals: "my_third_goal",
553 copies: []distCopy{
554 distCopyForTest("one.out", "test/dir/one.out"),
555 },
556 },
557 {
558 goals: "my_fourth_goal",
559 copies: []distCopy{
560 distCopyForTest("one.out", "one.suffix.out"),
561 },
562 },
563 {
564 goals: "my_fifth_goal",
565 copies: []distCopy{
566 distCopyForTest("one.out", "new-name"),
567 },
568 },
569 {
570 goals: "my_sixth_goal",
571 copies: []distCopy{
572 distCopyForTest("one.out", "some/dir/new-name.suffix"),
573 },
574 },
575 {
576 goals: "my_goal my_other_goal",
577 copies: []distCopy{
578 distCopyForTest("two.out", "two.out"),
579 distCopyForTest("three/four.out", "four.out"),
580 },
581 },
582 },
583 })
Paul Duffin62269492020-11-26 20:18:42 +0000584
585 // The above test the default values of default_dist_files and use_output_file.
586
587 // The following tests explicitly test the different combinations of those settings.
588 testHelper(t, "tagged-dist-files-no-output", `
589 custom {
590 name: "foo",
591 default_dist_files: "tagged",
592 dist_output_file: false,
593 dists: [
594 {
595 targets: ["my_goal"],
596 },
597 {
598 targets: ["my_goal"],
599 tag: ".multiple",
600 },
601 ],
602 }
603`, &distContributions{
604 copiesForGoals: []*copiesForGoals{
605 {
606 goals: "my_goal",
607 copies: []distCopy{
608 distCopyForTest("one.out", "one.out"),
609 },
610 },
611 {
612 goals: "my_goal",
613 copies: []distCopy{
614 distCopyForTest("two.out", "two.out"),
615 distCopyForTest("three/four.out", "four.out"),
616 },
617 },
618 },
619 })
620
621 testHelper(t, "default-dist-files-no-output", `
622 custom {
623 name: "foo",
624 default_dist_files: "default",
625 dist_output_file: false,
626 dists: [
627 {
628 targets: ["my_goal"],
629 },
Paul Duffin62269492020-11-26 20:18:42 +0000630 {
631 targets: ["my_goal"],
632 tag: ".multiple",
633 },
634 ],
635 }
636`, &distContributions{
637 copiesForGoals: []*copiesForGoals{
638 {
639 goals: "my_goal",
640 copies: []distCopy{
641 distCopyForTest("default-dist.out", "default-dist.out"),
642 },
643 },
Paul Duffinaf970a22020-11-23 23:32:56 +0000644 {
645 goals: "my_goal",
646 copies: []distCopy{
647 distCopyForTest("two.out", "two.out"),
648 distCopyForTest("three/four.out", "four.out"),
649 },
650 },
Paul Duffin62269492020-11-26 20:18:42 +0000651 },
652 })
653
654 testHelper(t, "no-dist-files-no-output", `
655 custom {
656 name: "foo",
657 default_dist_files: "none",
658 dist_output_file: false,
659 dists: [
660 // The following is silently ignored because there is not default file
661 // in either the dist files or the output file.
662 {
663 targets: ["my_goal"],
664 },
Paul Duffin62269492020-11-26 20:18:42 +0000665 {
666 targets: ["my_goal"],
667 tag: ".multiple",
668 },
669 ],
670 }
Paul Duffinaf970a22020-11-23 23:32:56 +0000671`, &distContributions{
672 copiesForGoals: []*copiesForGoals{
673 {
674 goals: "my_goal",
675 copies: []distCopy{
676 distCopyForTest("two.out", "two.out"),
677 distCopyForTest("three/four.out", "four.out"),
678 },
679 },
680 },
681 })
Paul Duffin62269492020-11-26 20:18:42 +0000682
683 testHelper(t, "tagged-dist-files-default-output", `
684 custom {
685 name: "foo",
686 default_dist_files: "tagged",
687 dist_output_file: true,
688 dists: [
689 {
690 targets: ["my_goal"],
691 },
692 {
693 targets: ["my_goal"],
694 tag: ".multiple",
695 },
696 ],
697 }
698`, &distContributions{
699 copiesForGoals: []*copiesForGoals{
700 {
701 goals: "my_goal",
702 copies: []distCopy{
703 distCopyForTest("one.out", "one.out"),
704 },
705 },
706 {
707 goals: "my_goal",
708 copies: []distCopy{
709 distCopyForTest("two.out", "two.out"),
710 distCopyForTest("three/four.out", "four.out"),
711 },
712 },
713 },
714 })
715
716 testHelper(t, "default-dist-files-default-output", `
717 custom {
718 name: "foo",
719 default_dist_files: "default",
720 dist_output_file: true,
721 dists: [
722 {
723 targets: ["my_goal"],
724 },
Paul Duffin62269492020-11-26 20:18:42 +0000725 {
726 targets: ["my_goal"],
727 tag: ".multiple",
728 },
729 ],
730 }
731`, &distContributions{
732 copiesForGoals: []*copiesForGoals{
733 {
734 goals: "my_goal",
735 copies: []distCopy{
736 distCopyForTest("default-dist.out", "default-dist.out"),
737 },
738 },
Paul Duffinaf970a22020-11-23 23:32:56 +0000739 {
740 goals: "my_goal",
741 copies: []distCopy{
742 distCopyForTest("two.out", "two.out"),
743 distCopyForTest("three/four.out", "four.out"),
744 },
745 },
Paul Duffin62269492020-11-26 20:18:42 +0000746 },
747 })
748
749 testHelper(t, "no-dist-files-default-output", `
750 custom {
751 name: "foo",
752 default_dist_files: "none",
753 dist_output_file: true,
754 dists: [
755 {
756 targets: ["my_goal"],
757 },
Paul Duffin62269492020-11-26 20:18:42 +0000758 {
759 targets: ["my_goal"],
760 tag: ".multiple",
761 },
762 ],
763 }
764`, &distContributions{
765 copiesForGoals: []*copiesForGoals{
766 {
767 goals: "my_goal",
768 copies: []distCopy{
769 distCopyForTest("dist-output-file.out", "dist-output-file.out"),
770 },
771 },
Paul Duffinaf970a22020-11-23 23:32:56 +0000772 {
773 goals: "my_goal",
774 copies: []distCopy{
775 distCopyForTest("two.out", "two.out"),
776 distCopyForTest("three/four.out", "four.out"),
777 },
778 },
Paul Duffin62269492020-11-26 20:18:42 +0000779 },
780 })
Paul Duffin8b0349c2020-11-26 14:33:21 +0000781}