blob: 85f64a86ce35dc20f19b466fe43d52c728bffc2b [file] [log] [blame]
Makoto Onuki4a9869d2023-10-20 10:42:47 -07001// Copyright 2023 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.
14package java
15
16import (
17 "android/soong/android"
18 "android/soong/tradefed"
19
20 "github.com/google/blueprint/proptools"
21)
22
23func init() {
24 RegisterRavenwoodBuildComponents(android.InitRegistrationContext)
25}
26
27func RegisterRavenwoodBuildComponents(ctx android.RegistrationContext) {
28 ctx.RegisterModuleType("android_ravenwood_test", ravenwoodTestFactory)
29 ctx.RegisterModuleType("android_ravenwood_libgroup", ravenwoodLibgroupFactory)
30}
31
32var ravenwoodTag = dependencyTag{name: "ravenwood"}
33
34const ravenwoodUtilsName = "ravenwood-utils"
35const ravenwoodRuntimeName = "ravenwood-runtime"
36
37type ravenwoodTest struct {
38 Library
39
40 testProperties testProperties
41 testConfig android.Path
42
43 forceOSType android.OsType
44 forceArchType android.ArchType
45}
46
47func ravenwoodTestFactory() android.Module {
48 module := &ravenwoodTest{}
49
50 module.addHostAndDeviceProperties()
51 module.AddProperties(&module.testProperties)
52
53 module.Module.dexpreopter.isTest = true
54 module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
55
56 module.testProperties.Test_suites = []string{"ravenwood-tests"}
57 module.testProperties.Test_options.Unit_test = proptools.BoolPtr(false)
58
59 InitJavaModule(module, android.DeviceSupported)
60 android.InitDefaultableModule(module)
61
62 return module
63}
64
65func (r *ravenwoodTest) InstallInTestcases() bool { return true }
66func (r *ravenwoodTest) InstallForceOS() (*android.OsType, *android.ArchType) {
67 return &r.forceOSType, &r.forceArchType
68}
69func (r *ravenwoodTest) TestSuites() []string {
70 return r.testProperties.Test_suites
71}
72
73func (r *ravenwoodTest) DepsMutator(ctx android.BottomUpMutatorContext) {
74 r.Library.DepsMutator(ctx)
75
76 // Generically depend on the runtime so that it's installed together with us
77 ctx.AddVariationDependencies(nil, ravenwoodTag, ravenwoodRuntimeName)
78
79 // Directly depend on any utils so that we link against them
80 utils := ctx.AddVariationDependencies(nil, ravenwoodTag, ravenwoodUtilsName)[0]
81 if utils != nil {
82 for _, lib := range utils.(*ravenwoodLibgroup).ravenwoodLibgroupProperties.Libs {
83 ctx.AddVariationDependencies(nil, libTag, lib)
84 }
85 }
86}
87
88func (r *ravenwoodTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
89 r.forceOSType = ctx.Config().BuildOS
90 r.forceArchType = ctx.Config().BuildArch
91
92 r.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{
93 TestConfigProp: r.testProperties.Test_config,
94 TestConfigTemplateProp: r.testProperties.Test_config_template,
95 TestSuites: r.testProperties.Test_suites,
96 AutoGenConfig: r.testProperties.Auto_gen_config,
97 DeviceTemplate: "${RavenwoodTestConfigTemplate}",
98 HostTemplate: "${RavenwoodTestConfigTemplate}",
99 })
100
101 r.Library.GenerateAndroidBuildActions(ctx)
102
103 // Start by depending on all files installed by dependancies
104 var installDeps android.InstallPaths
105 for _, dep := range ctx.GetDirectDepsWithTag(ravenwoodTag) {
106 for _, installFile := range dep.FilesToInstall() {
107 installDeps = append(installDeps, installFile)
108 }
109 }
110
111 // Also depend on our config
112 installPath := android.PathForModuleInstall(ctx, r.BaseModuleName())
113 installConfig := ctx.InstallFile(installPath, ctx.ModuleName()+".config", r.testConfig)
114 installDeps = append(installDeps, installConfig)
115
116 // Finally install our JAR with all dependencies
117 ctx.InstallFile(installPath, ctx.ModuleName()+".jar", r.outputFile, installDeps...)
118}
119
120func (r *ravenwoodTest) AndroidMkEntries() []android.AndroidMkEntries {
121 entriesList := r.Library.AndroidMkEntries()
122 entries := &entriesList[0]
123 entries.ExtraEntries = append(entries.ExtraEntries,
124 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
125 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
126 entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", "ravenwood-tests")
127 if r.testConfig != nil {
128 entries.SetPath("LOCAL_FULL_TEST_CONFIG", r.testConfig)
129 }
130 })
131 return entriesList
132}
133
134type ravenwoodLibgroupProperties struct {
135 Libs []string
136}
137
138type ravenwoodLibgroup struct {
139 android.ModuleBase
140
141 ravenwoodLibgroupProperties ravenwoodLibgroupProperties
142
143 forceOSType android.OsType
144 forceArchType android.ArchType
145}
146
147func ravenwoodLibgroupFactory() android.Module {
148 module := &ravenwoodLibgroup{}
149 module.AddProperties(&module.ravenwoodLibgroupProperties)
150
151 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
152 return module
153}
154
155func (r *ravenwoodLibgroup) InstallInTestcases() bool { return true }
156func (r *ravenwoodLibgroup) InstallForceOS() (*android.OsType, *android.ArchType) {
157 return &r.forceOSType, &r.forceArchType
158}
159func (r *ravenwoodLibgroup) TestSuites() []string {
160 return []string{"ravenwood-tests"}
161}
162
163func (r *ravenwoodLibgroup) DepsMutator(ctx android.BottomUpMutatorContext) {
164 // Always depends on our underlying libs
165 for _, lib := range r.ravenwoodLibgroupProperties.Libs {
166 ctx.AddVariationDependencies(nil, ravenwoodTag, lib)
167 }
168}
169
170func (r *ravenwoodLibgroup) GenerateAndroidBuildActions(ctx android.ModuleContext) {
171 r.forceOSType = ctx.Config().BuildOS
172 r.forceArchType = ctx.Config().BuildArch
173
174 // Install our runtime into expected location for packaging
175 installPath := android.PathForModuleInstall(ctx, r.BaseModuleName())
176 for _, lib := range r.ravenwoodLibgroupProperties.Libs {
177 libModule := ctx.GetDirectDepWithTag(lib, ravenwoodTag)
178 libJar := android.OutputFileForModule(ctx, libModule, "")
179 ctx.InstallFile(installPath, lib+".jar", libJar)
180 }
181
182 // Normal build should perform install steps
183 ctx.Phony(r.BaseModuleName(), android.PathForPhony(ctx, r.BaseModuleName()+"-install"))
184}