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