blob: dcb5c8bdbf652f209ecff940ac72ac8e0f22ada9 [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"}
Makoto Onuki68676572024-02-02 13:29:01 -080033var ravenwoodJniTag = dependencyTag{name: "ravenwood-jni"}
Makoto Onuki4a9869d2023-10-20 10:42:47 -070034
35const ravenwoodUtilsName = "ravenwood-utils"
36const ravenwoodRuntimeName = "ravenwood-runtime"
37
Makoto Onuki68676572024-02-02 13:29:01 -080038func getLibPath(archType android.ArchType) string {
39 if archType.Multilib == "lib64" {
40 return "lib64"
41 }
42 return "lib"
43}
44
45type ravenwoodTestProperties struct {
46 Jni_libs []string
47}
48
Makoto Onuki4a9869d2023-10-20 10:42:47 -070049type ravenwoodTest struct {
50 Library
51
Makoto Onuki68676572024-02-02 13:29:01 -080052 ravenwoodTestProperties ravenwoodTestProperties
53
Makoto Onuki4a9869d2023-10-20 10:42:47 -070054 testProperties testProperties
55 testConfig android.Path
56
57 forceOSType android.OsType
58 forceArchType android.ArchType
59}
60
61func ravenwoodTestFactory() android.Module {
62 module := &ravenwoodTest{}
63
64 module.addHostAndDeviceProperties()
Makoto Onuki68676572024-02-02 13:29:01 -080065 module.AddProperties(&module.testProperties, &module.ravenwoodTestProperties)
Makoto Onuki4a9869d2023-10-20 10:42:47 -070066
67 module.Module.dexpreopter.isTest = true
68 module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
69
Jeff Sharkey4bbf86f2023-11-30 09:29:50 -070070 module.testProperties.Test_suites = []string{
71 "general-tests",
72 "ravenwood-tests",
73 }
Makoto Onuki4a9869d2023-10-20 10:42:47 -070074 module.testProperties.Test_options.Unit_test = proptools.BoolPtr(false)
75
76 InitJavaModule(module, android.DeviceSupported)
77 android.InitDefaultableModule(module)
78
79 return module
80}
81
82func (r *ravenwoodTest) InstallInTestcases() bool { return true }
83func (r *ravenwoodTest) InstallForceOS() (*android.OsType, *android.ArchType) {
84 return &r.forceOSType, &r.forceArchType
85}
86func (r *ravenwoodTest) TestSuites() []string {
87 return r.testProperties.Test_suites
88}
89
90func (r *ravenwoodTest) DepsMutator(ctx android.BottomUpMutatorContext) {
91 r.Library.DepsMutator(ctx)
92
93 // Generically depend on the runtime so that it's installed together with us
94 ctx.AddVariationDependencies(nil, ravenwoodTag, ravenwoodRuntimeName)
95
96 // Directly depend on any utils so that we link against them
97 utils := ctx.AddVariationDependencies(nil, ravenwoodTag, ravenwoodUtilsName)[0]
98 if utils != nil {
99 for _, lib := range utils.(*ravenwoodLibgroup).ravenwoodLibgroupProperties.Libs {
100 ctx.AddVariationDependencies(nil, libTag, lib)
101 }
102 }
Makoto Onuki68676572024-02-02 13:29:01 -0800103
104 // Add jni libs
105 for _, lib := range r.ravenwoodTestProperties.Jni_libs {
106 ctx.AddVariationDependencies(ctx.Config().BuildOSTarget.Variations(), ravenwoodJniTag, lib)
107 }
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700108}
109
110func (r *ravenwoodTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
111 r.forceOSType = ctx.Config().BuildOS
112 r.forceArchType = ctx.Config().BuildArch
113
114 r.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{
115 TestConfigProp: r.testProperties.Test_config,
116 TestConfigTemplateProp: r.testProperties.Test_config_template,
117 TestSuites: r.testProperties.Test_suites,
118 AutoGenConfig: r.testProperties.Auto_gen_config,
119 DeviceTemplate: "${RavenwoodTestConfigTemplate}",
120 HostTemplate: "${RavenwoodTestConfigTemplate}",
121 })
122
123 r.Library.GenerateAndroidBuildActions(ctx)
124
125 // Start by depending on all files installed by dependancies
126 var installDeps android.InstallPaths
127 for _, dep := range ctx.GetDirectDepsWithTag(ravenwoodTag) {
128 for _, installFile := range dep.FilesToInstall() {
129 installDeps = append(installDeps, installFile)
130 }
131 }
132
133 // Also depend on our config
134 installPath := android.PathForModuleInstall(ctx, r.BaseModuleName())
135 installConfig := ctx.InstallFile(installPath, ctx.ModuleName()+".config", r.testConfig)
136 installDeps = append(installDeps, installConfig)
137
Makoto Onuki68676572024-02-02 13:29:01 -0800138 // Depend on the JNI libraries.
139 soInstallPath := installPath.Join(ctx, getLibPath(r.forceArchType))
140 for _, dep := range ctx.GetDirectDepsWithTag(ravenwoodJniTag) {
141 file := android.OutputFileForModule(ctx, dep, "")
142 installJni := ctx.InstallFile(soInstallPath, file.Base(), file)
143 installDeps = append(installDeps, installJni)
144 }
145
146 // Install our JAR with all dependencies
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700147 ctx.InstallFile(installPath, ctx.ModuleName()+".jar", r.outputFile, installDeps...)
148}
149
150func (r *ravenwoodTest) AndroidMkEntries() []android.AndroidMkEntries {
151 entriesList := r.Library.AndroidMkEntries()
152 entries := &entriesList[0]
153 entries.ExtraEntries = append(entries.ExtraEntries,
154 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
155 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
Jeff Sharkey4bbf86f2023-11-30 09:29:50 -0700156 entries.AddStrings("LOCAL_COMPATIBILITY_SUITE",
157 "general-tests", "ravenwood-tests")
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700158 if r.testConfig != nil {
159 entries.SetPath("LOCAL_FULL_TEST_CONFIG", r.testConfig)
160 }
161 })
162 return entriesList
163}
164
165type ravenwoodLibgroupProperties struct {
166 Libs []string
Makoto Onuki68676572024-02-02 13:29:01 -0800167
168 Jni_libs []string
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700169}
170
171type ravenwoodLibgroup struct {
172 android.ModuleBase
173
174 ravenwoodLibgroupProperties ravenwoodLibgroupProperties
175
176 forceOSType android.OsType
177 forceArchType android.ArchType
178}
179
180func ravenwoodLibgroupFactory() android.Module {
181 module := &ravenwoodLibgroup{}
182 module.AddProperties(&module.ravenwoodLibgroupProperties)
183
184 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
185 return module
186}
187
188func (r *ravenwoodLibgroup) InstallInTestcases() bool { return true }
189func (r *ravenwoodLibgroup) InstallForceOS() (*android.OsType, *android.ArchType) {
190 return &r.forceOSType, &r.forceArchType
191}
192func (r *ravenwoodLibgroup) TestSuites() []string {
Jeff Sharkey4bbf86f2023-11-30 09:29:50 -0700193 return []string{
194 "general-tests",
195 "ravenwood-tests",
196 }
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700197}
198
199func (r *ravenwoodLibgroup) DepsMutator(ctx android.BottomUpMutatorContext) {
200 // Always depends on our underlying libs
201 for _, lib := range r.ravenwoodLibgroupProperties.Libs {
202 ctx.AddVariationDependencies(nil, ravenwoodTag, lib)
203 }
Makoto Onuki68676572024-02-02 13:29:01 -0800204 for _, lib := range r.ravenwoodLibgroupProperties.Jni_libs {
205 ctx.AddVariationDependencies(ctx.Config().BuildOSTarget.Variations(), ravenwoodJniTag, lib)
206 }
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700207}
208
209func (r *ravenwoodLibgroup) GenerateAndroidBuildActions(ctx android.ModuleContext) {
210 r.forceOSType = ctx.Config().BuildOS
211 r.forceArchType = ctx.Config().BuildArch
212
213 // Install our runtime into expected location for packaging
214 installPath := android.PathForModuleInstall(ctx, r.BaseModuleName())
215 for _, lib := range r.ravenwoodLibgroupProperties.Libs {
216 libModule := ctx.GetDirectDepWithTag(lib, ravenwoodTag)
217 libJar := android.OutputFileForModule(ctx, libModule, "")
218 ctx.InstallFile(installPath, lib+".jar", libJar)
219 }
Makoto Onuki68676572024-02-02 13:29:01 -0800220 soInstallPath := android.PathForModuleInstall(ctx, r.BaseModuleName()).Join(ctx, getLibPath(r.forceArchType))
221 for _, dep := range ctx.GetDirectDepsWithTag(ravenwoodJniTag) {
222 file := android.OutputFileForModule(ctx, dep, "")
223 ctx.InstallFile(soInstallPath, file.Base(), file)
224 }
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700225
226 // Normal build should perform install steps
227 ctx.Phony(r.BaseModuleName(), android.PathForPhony(ctx, r.BaseModuleName()+"-install"))
228}