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