| Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 1 | // Copyright 2020 Google Inc. All rights reserved. | 
|  | 2 | // | 
|  | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 4 | // you may not use this file except in compliance with the License. | 
|  | 5 | // You may obtain a copy of the License at | 
|  | 6 | // | 
|  | 7 | //     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 8 | // | 
|  | 9 | // Unless required by applicable law or agreed to in writing, software | 
|  | 10 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 12 | // See the License for the specific language governing permissions and | 
|  | 13 | // limitations under the License. | 
|  | 14 |  | 
|  | 15 | package android | 
|  | 16 |  | 
|  | 17 | func init() { | 
| LaMont Jones | 0c10e4d | 2023-05-16 00:58:37 +0000 | [diff] [blame] | 18 | RegisterParallelSingletonType("testsuites", testSuiteFilesFactory) | 
| Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 19 | } | 
|  | 20 |  | 
|  | 21 | func testSuiteFilesFactory() Singleton { | 
|  | 22 | return &testSuiteFiles{} | 
|  | 23 | } | 
|  | 24 |  | 
|  | 25 | type testSuiteFiles struct { | 
|  | 26 | robolectric WritablePath | 
|  | 27 | } | 
|  | 28 |  | 
|  | 29 | type TestSuiteModule interface { | 
|  | 30 | Module | 
|  | 31 | TestSuites() []string | 
|  | 32 | } | 
|  | 33 |  | 
|  | 34 | func (t *testSuiteFiles) GenerateBuildActions(ctx SingletonContext) { | 
|  | 35 | files := make(map[string]map[string]InstallPaths) | 
|  | 36 |  | 
|  | 37 | ctx.VisitAllModules(func(m Module) { | 
|  | 38 | if tsm, ok := m.(TestSuiteModule); ok { | 
|  | 39 | for _, testSuite := range tsm.TestSuites() { | 
|  | 40 | if files[testSuite] == nil { | 
|  | 41 | files[testSuite] = make(map[string]InstallPaths) | 
|  | 42 | } | 
|  | 43 | name := ctx.ModuleName(m) | 
| Jiyong Park | 4dc2a1a | 2020-09-28 17:46:22 +0900 | [diff] [blame] | 44 | files[testSuite][name] = append(files[testSuite][name], tsm.FilesToInstall()...) | 
| Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 45 | } | 
|  | 46 | } | 
|  | 47 | }) | 
|  | 48 |  | 
|  | 49 | t.robolectric = robolectricTestSuite(ctx, files["robolectric-tests"]) | 
| Colin Cross | cf0e422 | 2020-07-20 17:19:02 -0700 | [diff] [blame] | 50 |  | 
|  | 51 | ctx.Phony("robolectric-tests", t.robolectric) | 
| Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 52 | } | 
|  | 53 |  | 
|  | 54 | func (t *testSuiteFiles) MakeVars(ctx MakeVarsContext) { | 
| Colin Cross | cf0e422 | 2020-07-20 17:19:02 -0700 | [diff] [blame] | 55 | ctx.DistForGoal("robolectric-tests", t.robolectric) | 
| Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 56 | } | 
|  | 57 |  | 
|  | 58 | func robolectricTestSuite(ctx SingletonContext, files map[string]InstallPaths) WritablePath { | 
|  | 59 | var installedPaths InstallPaths | 
| Cole Faust | 18994c7 | 2023-02-28 16:02:16 -0800 | [diff] [blame] | 60 | for _, module := range SortedKeys(files) { | 
| Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 61 | installedPaths = append(installedPaths, files[module]...) | 
|  | 62 | } | 
| Cole Faust | 3b703f3 | 2023-10-16 13:30:51 -0700 | [diff] [blame] | 63 | testCasesDir := pathForInstall(ctx, ctx.Config().BuildOS, X86, "testcases") | 
| Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 64 |  | 
|  | 65 | outputFile := PathForOutput(ctx, "packaging", "robolectric-tests.zip") | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 66 | rule := NewRuleBuilder(pctx, ctx) | 
|  | 67 | rule.Command().BuiltTool("soong_zip"). | 
| Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 68 | FlagWithOutput("-o ", outputFile). | 
|  | 69 | FlagWithArg("-P ", "host/testcases"). | 
|  | 70 | FlagWithArg("-C ", testCasesDir.String()). | 
| Julien Desprez | f368073 | 2023-06-27 20:48:04 +0000 | [diff] [blame] | 71 | FlagWithRspFileInputList("-r ", outputFile.ReplaceExtension(ctx, "rsp"), installedPaths.Paths()). | 
| Cole Faust | 3b703f3 | 2023-10-16 13:30:51 -0700 | [diff] [blame] | 72 | Flag("-sha256") | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 73 | rule.Build("robolectric_tests_zip", "robolectric-tests.zip") | 
| Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 74 |  | 
|  | 75 | return outputFile | 
|  | 76 | } |