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