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"} |
Makoto Onuki | 6867657 | 2024-02-02 13:29:01 -0800 | [diff] [blame^] | 33 | var ravenwoodJniTag = dependencyTag{name: "ravenwood-jni"} |
Makoto Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 34 | |
| 35 | const ravenwoodUtilsName = "ravenwood-utils" |
| 36 | const ravenwoodRuntimeName = "ravenwood-runtime" |
| 37 | |
Makoto Onuki | 6867657 | 2024-02-02 13:29:01 -0800 | [diff] [blame^] | 38 | func getLibPath(archType android.ArchType) string { |
| 39 | if archType.Multilib == "lib64" { |
| 40 | return "lib64" |
| 41 | } |
| 42 | return "lib" |
| 43 | } |
| 44 | |
| 45 | type ravenwoodTestProperties struct { |
| 46 | Jni_libs []string |
| 47 | } |
| 48 | |
Makoto Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 49 | type ravenwoodTest struct { |
| 50 | Library |
| 51 | |
Makoto Onuki | 6867657 | 2024-02-02 13:29:01 -0800 | [diff] [blame^] | 52 | ravenwoodTestProperties ravenwoodTestProperties |
| 53 | |
Makoto Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 54 | testProperties testProperties |
| 55 | testConfig android.Path |
| 56 | |
| 57 | forceOSType android.OsType |
| 58 | forceArchType android.ArchType |
| 59 | } |
| 60 | |
| 61 | func ravenwoodTestFactory() android.Module { |
| 62 | module := &ravenwoodTest{} |
| 63 | |
| 64 | module.addHostAndDeviceProperties() |
Makoto Onuki | 6867657 | 2024-02-02 13:29:01 -0800 | [diff] [blame^] | 65 | module.AddProperties(&module.testProperties, &module.ravenwoodTestProperties) |
Makoto Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 66 | |
| 67 | module.Module.dexpreopter.isTest = true |
| 68 | module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) |
| 69 | |
Jeff Sharkey | 4bbf86f | 2023-11-30 09:29:50 -0700 | [diff] [blame] | 70 | module.testProperties.Test_suites = []string{ |
| 71 | "general-tests", |
| 72 | "ravenwood-tests", |
| 73 | } |
Makoto Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 74 | 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 | |
| 82 | func (r *ravenwoodTest) InstallInTestcases() bool { return true } |
| 83 | func (r *ravenwoodTest) InstallForceOS() (*android.OsType, *android.ArchType) { |
| 84 | return &r.forceOSType, &r.forceArchType |
| 85 | } |
| 86 | func (r *ravenwoodTest) TestSuites() []string { |
| 87 | return r.testProperties.Test_suites |
| 88 | } |
| 89 | |
| 90 | func (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 Onuki | 6867657 | 2024-02-02 13:29:01 -0800 | [diff] [blame^] | 103 | |
| 104 | // Add jni libs |
| 105 | for _, lib := range r.ravenwoodTestProperties.Jni_libs { |
| 106 | ctx.AddVariationDependencies(ctx.Config().BuildOSTarget.Variations(), ravenwoodJniTag, lib) |
| 107 | } |
Makoto Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | func (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 Onuki | 6867657 | 2024-02-02 13:29:01 -0800 | [diff] [blame^] | 138 | // 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 Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 147 | ctx.InstallFile(installPath, ctx.ModuleName()+".jar", r.outputFile, installDeps...) |
| 148 | } |
| 149 | |
| 150 | func (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 Sharkey | 4bbf86f | 2023-11-30 09:29:50 -0700 | [diff] [blame] | 156 | entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", |
| 157 | "general-tests", "ravenwood-tests") |
Makoto Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 158 | if r.testConfig != nil { |
| 159 | entries.SetPath("LOCAL_FULL_TEST_CONFIG", r.testConfig) |
| 160 | } |
| 161 | }) |
| 162 | return entriesList |
| 163 | } |
| 164 | |
| 165 | type ravenwoodLibgroupProperties struct { |
| 166 | Libs []string |
Makoto Onuki | 6867657 | 2024-02-02 13:29:01 -0800 | [diff] [blame^] | 167 | |
| 168 | Jni_libs []string |
Makoto Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | type ravenwoodLibgroup struct { |
| 172 | android.ModuleBase |
| 173 | |
| 174 | ravenwoodLibgroupProperties ravenwoodLibgroupProperties |
| 175 | |
| 176 | forceOSType android.OsType |
| 177 | forceArchType android.ArchType |
| 178 | } |
| 179 | |
| 180 | func 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 | |
| 188 | func (r *ravenwoodLibgroup) InstallInTestcases() bool { return true } |
| 189 | func (r *ravenwoodLibgroup) InstallForceOS() (*android.OsType, *android.ArchType) { |
| 190 | return &r.forceOSType, &r.forceArchType |
| 191 | } |
| 192 | func (r *ravenwoodLibgroup) TestSuites() []string { |
Jeff Sharkey | 4bbf86f | 2023-11-30 09:29:50 -0700 | [diff] [blame] | 193 | return []string{ |
| 194 | "general-tests", |
| 195 | "ravenwood-tests", |
| 196 | } |
Makoto Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | func (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 Onuki | 6867657 | 2024-02-02 13:29:01 -0800 | [diff] [blame^] | 204 | for _, lib := range r.ravenwoodLibgroupProperties.Jni_libs { |
| 205 | ctx.AddVariationDependencies(ctx.Config().BuildOSTarget.Variations(), ravenwoodJniTag, lib) |
| 206 | } |
Makoto Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | func (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 Onuki | 6867657 | 2024-02-02 13:29:01 -0800 | [diff] [blame^] | 220 | 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 Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 225 | |
| 226 | // Normal build should perform install steps |
| 227 | ctx.Phony(r.BaseModuleName(), android.PathForPhony(ctx, r.BaseModuleName()+"-install")) |
| 228 | } |