blob: b6ca0e6f044aa34fadeacd4d876efc0867a07fbc [file] [log] [blame]
Colin Cross8eebb132020-01-29 20:07:03 -08001// 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
15package android
16
17func init() {
18 RegisterSingletonType("testsuites", testSuiteFilesFactory)
19}
20
21func testSuiteFilesFactory() Singleton {
22 return &testSuiteFiles{}
23}
24
25type testSuiteFiles struct {
26 robolectric WritablePath
27}
28
29type TestSuiteModule interface {
30 Module
31 TestSuites() []string
32}
33
34func (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)
44 files[testSuite][name] = append(files[testSuite][name], tsm.filesToInstall()...)
45 }
46 }
47 })
48
49 t.robolectric = robolectricTestSuite(ctx, files["robolectric-tests"])
50}
51
52func (t *testSuiteFiles) MakeVars(ctx MakeVarsContext) {
53 ctx.Strict("ROBOLECTRIC_TEST_SUITE", t.robolectric.String())
54}
55
56func robolectricTestSuite(ctx SingletonContext, files map[string]InstallPaths) WritablePath {
57 var installedPaths InstallPaths
58 for _, module := range SortedStringKeys(files) {
59 installedPaths = append(installedPaths, files[module]...)
60 }
61 testCasesDir := pathForInstall(ctx, BuildOs, "testcases", false).ToMakePath()
62
63 outputFile := PathForOutput(ctx, "packaging", "robolectric-tests.zip")
64 rule := NewRuleBuilder()
65 rule.Command().BuiltTool(ctx, "soong_zip").
66 FlagWithOutput("-o ", outputFile).
67 FlagWithArg("-P ", "host/testcases").
68 FlagWithArg("-C ", testCasesDir.String()).
69 FlagWithRspFileInputList("-l ", installedPaths.Paths())
70 rule.Build(pctx, ctx, "robolectric_tests_zip", "robolectric-tests.zip")
71
72 return outputFile
73}