2023-10-20 19:42:47 +02:00
|
|
|
// Copyright 2023 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
package java
|
|
|
|
|
|
|
|
import (
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/tradefed"
|
2023-11-15 21:29:33 +01:00
|
|
|
|
2024-02-08 17:14:40 +01:00
|
|
|
"github.com/google/blueprint"
|
2023-10-20 19:42:47 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RegisterRavenwoodBuildComponents(android.InitRegistrationContext)
|
|
|
|
}
|
|
|
|
|
|
|
|
func RegisterRavenwoodBuildComponents(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("android_ravenwood_test", ravenwoodTestFactory)
|
|
|
|
ctx.RegisterModuleType("android_ravenwood_libgroup", ravenwoodLibgroupFactory)
|
|
|
|
}
|
|
|
|
|
2024-02-08 17:14:40 +01:00
|
|
|
var ravenwoodLibContentTag = dependencyTag{name: "ravenwoodlibcontent"}
|
|
|
|
var ravenwoodUtilsTag = dependencyTag{name: "ravenwoodutils"}
|
|
|
|
var ravenwoodRuntimeTag = dependencyTag{name: "ravenwoodruntime"}
|
2023-10-20 19:42:47 +02:00
|
|
|
|
|
|
|
const ravenwoodUtilsName = "ravenwood-utils"
|
|
|
|
const ravenwoodRuntimeName = "ravenwood-runtime"
|
|
|
|
|
2024-02-08 17:14:40 +01:00
|
|
|
type ravenwoodLibgroupJniDepProviderInfo struct {
|
|
|
|
// All the jni_libs module names with transient dependencies.
|
|
|
|
names map[string]bool
|
|
|
|
}
|
|
|
|
|
|
|
|
var ravenwoodLibgroupJniDepProvider = blueprint.NewProvider[ravenwoodLibgroupJniDepProviderInfo]()
|
|
|
|
|
2024-02-02 22:29:01 +01:00
|
|
|
func getLibPath(archType android.ArchType) string {
|
|
|
|
if archType.Multilib == "lib64" {
|
|
|
|
return "lib64"
|
|
|
|
}
|
|
|
|
return "lib"
|
|
|
|
}
|
|
|
|
|
|
|
|
type ravenwoodTestProperties struct {
|
|
|
|
Jni_libs []string
|
|
|
|
}
|
|
|
|
|
2023-10-20 19:42:47 +02:00
|
|
|
type ravenwoodTest struct {
|
|
|
|
Library
|
|
|
|
|
2024-02-02 22:29:01 +01:00
|
|
|
ravenwoodTestProperties ravenwoodTestProperties
|
|
|
|
|
2023-10-20 19:42:47 +02:00
|
|
|
testProperties testProperties
|
|
|
|
testConfig android.Path
|
|
|
|
|
|
|
|
forceOSType android.OsType
|
|
|
|
forceArchType android.ArchType
|
|
|
|
}
|
|
|
|
|
|
|
|
func ravenwoodTestFactory() android.Module {
|
|
|
|
module := &ravenwoodTest{}
|
|
|
|
|
|
|
|
module.addHostAndDeviceProperties()
|
2024-02-02 22:29:01 +01:00
|
|
|
module.AddProperties(&module.testProperties, &module.ravenwoodTestProperties)
|
2023-10-20 19:42:47 +02:00
|
|
|
|
|
|
|
module.Module.dexpreopter.isTest = true
|
|
|
|
module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
|
|
|
|
|
2023-11-30 17:29:50 +01:00
|
|
|
module.testProperties.Test_suites = []string{
|
|
|
|
"general-tests",
|
|
|
|
"ravenwood-tests",
|
|
|
|
}
|
2023-10-20 19:42:47 +02:00
|
|
|
module.testProperties.Test_options.Unit_test = proptools.BoolPtr(false)
|
|
|
|
|
|
|
|
InitJavaModule(module, android.DeviceSupported)
|
|
|
|
android.InitDefaultableModule(module)
|
|
|
|
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ravenwoodTest) InstallInTestcases() bool { return true }
|
|
|
|
func (r *ravenwoodTest) InstallForceOS() (*android.OsType, *android.ArchType) {
|
|
|
|
return &r.forceOSType, &r.forceArchType
|
|
|
|
}
|
|
|
|
func (r *ravenwoodTest) TestSuites() []string {
|
|
|
|
return r.testProperties.Test_suites
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ravenwoodTest) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
r.Library.DepsMutator(ctx)
|
|
|
|
|
|
|
|
// Generically depend on the runtime so that it's installed together with us
|
2024-02-08 17:14:40 +01:00
|
|
|
ctx.AddVariationDependencies(nil, ravenwoodRuntimeTag, ravenwoodRuntimeName)
|
2023-10-20 19:42:47 +02:00
|
|
|
|
|
|
|
// Directly depend on any utils so that we link against them
|
2024-02-08 17:14:40 +01:00
|
|
|
utils := ctx.AddVariationDependencies(nil, ravenwoodUtilsTag, ravenwoodUtilsName)[0]
|
2023-10-20 19:42:47 +02:00
|
|
|
if utils != nil {
|
|
|
|
for _, lib := range utils.(*ravenwoodLibgroup).ravenwoodLibgroupProperties.Libs {
|
|
|
|
ctx.AddVariationDependencies(nil, libTag, lib)
|
|
|
|
}
|
|
|
|
}
|
2024-02-02 22:29:01 +01:00
|
|
|
|
|
|
|
// Add jni libs
|
|
|
|
for _, lib := range r.ravenwoodTestProperties.Jni_libs {
|
2024-02-08 17:14:40 +01:00
|
|
|
ctx.AddVariationDependencies(ctx.Config().BuildOSTarget.Variations(), jniLibTag, lib)
|
2024-02-02 22:29:01 +01:00
|
|
|
}
|
2023-10-20 19:42:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ravenwoodTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
r.forceOSType = ctx.Config().BuildOS
|
|
|
|
r.forceArchType = ctx.Config().BuildArch
|
|
|
|
|
|
|
|
r.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{
|
|
|
|
TestConfigProp: r.testProperties.Test_config,
|
|
|
|
TestConfigTemplateProp: r.testProperties.Test_config_template,
|
|
|
|
TestSuites: r.testProperties.Test_suites,
|
|
|
|
AutoGenConfig: r.testProperties.Auto_gen_config,
|
|
|
|
DeviceTemplate: "${RavenwoodTestConfigTemplate}",
|
|
|
|
HostTemplate: "${RavenwoodTestConfigTemplate}",
|
|
|
|
})
|
|
|
|
|
|
|
|
r.Library.GenerateAndroidBuildActions(ctx)
|
|
|
|
|
2024-02-08 17:14:40 +01:00
|
|
|
// Start by depending on all files installed by dependencies
|
2023-11-15 21:29:33 +01:00
|
|
|
var installDeps android.InstallPaths
|
2024-02-08 17:14:40 +01:00
|
|
|
|
|
|
|
// All JNI libraries included in the runtime
|
|
|
|
var runtimeJniModuleNames map[string]bool
|
|
|
|
|
|
|
|
if utils := ctx.GetDirectDepsWithTag(ravenwoodUtilsTag)[0]; utils != nil {
|
|
|
|
for _, installFile := range utils.FilesToInstall() {
|
|
|
|
installDeps = append(installDeps, installFile)
|
|
|
|
}
|
|
|
|
jniDeps, ok := android.OtherModuleProvider(ctx, utils, ravenwoodLibgroupJniDepProvider)
|
|
|
|
if ok {
|
|
|
|
runtimeJniModuleNames = jniDeps.names
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if runtime := ctx.GetDirectDepsWithTag(ravenwoodRuntimeTag)[0]; runtime != nil {
|
|
|
|
for _, installFile := range runtime.FilesToInstall() {
|
2023-10-20 19:42:47 +02:00
|
|
|
installDeps = append(installDeps, installFile)
|
|
|
|
}
|
2024-02-08 17:14:40 +01:00
|
|
|
jniDeps, ok := android.OtherModuleProvider(ctx, runtime, ravenwoodLibgroupJniDepProvider)
|
|
|
|
if ok {
|
|
|
|
runtimeJniModuleNames = jniDeps.names
|
|
|
|
}
|
2023-10-20 19:42:47 +02:00
|
|
|
}
|
|
|
|
|
2024-02-08 17:14:40 +01:00
|
|
|
// Also remember what JNI libs are in the runtime.
|
|
|
|
|
2023-10-20 19:42:47 +02:00
|
|
|
// Also depend on our config
|
|
|
|
installPath := android.PathForModuleInstall(ctx, r.BaseModuleName())
|
|
|
|
installConfig := ctx.InstallFile(installPath, ctx.ModuleName()+".config", r.testConfig)
|
|
|
|
installDeps = append(installDeps, installConfig)
|
|
|
|
|
2024-02-08 17:14:40 +01:00
|
|
|
// Depend on the JNI libraries, but don't install the ones that the runtime already
|
|
|
|
// contains.
|
2024-02-02 22:29:01 +01:00
|
|
|
soInstallPath := installPath.Join(ctx, getLibPath(r.forceArchType))
|
2024-02-08 17:14:40 +01:00
|
|
|
for _, jniLib := range collectTransitiveJniDeps(ctx) {
|
|
|
|
if _, ok := runtimeJniModuleNames[jniLib.name]; ok {
|
|
|
|
continue // Runtime already includes it.
|
|
|
|
}
|
|
|
|
installJni := ctx.InstallFile(soInstallPath, jniLib.path.Base(), jniLib.path)
|
2024-02-02 22:29:01 +01:00
|
|
|
installDeps = append(installDeps, installJni)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Install our JAR with all dependencies
|
2023-10-20 19:42:47 +02:00
|
|
|
ctx.InstallFile(installPath, ctx.ModuleName()+".jar", r.outputFile, installDeps...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ravenwoodTest) AndroidMkEntries() []android.AndroidMkEntries {
|
|
|
|
entriesList := r.Library.AndroidMkEntries()
|
|
|
|
entries := &entriesList[0]
|
|
|
|
entries.ExtraEntries = append(entries.ExtraEntries,
|
|
|
|
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
|
|
|
entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
|
2023-11-30 17:29:50 +01:00
|
|
|
entries.AddStrings("LOCAL_COMPATIBILITY_SUITE",
|
|
|
|
"general-tests", "ravenwood-tests")
|
2023-10-20 19:42:47 +02:00
|
|
|
if r.testConfig != nil {
|
|
|
|
entries.SetPath("LOCAL_FULL_TEST_CONFIG", r.testConfig)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return entriesList
|
|
|
|
}
|
|
|
|
|
|
|
|
type ravenwoodLibgroupProperties struct {
|
|
|
|
Libs []string
|
2024-02-02 22:29:01 +01:00
|
|
|
|
|
|
|
Jni_libs []string
|
2023-10-20 19:42:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type ravenwoodLibgroup struct {
|
|
|
|
android.ModuleBase
|
|
|
|
|
|
|
|
ravenwoodLibgroupProperties ravenwoodLibgroupProperties
|
|
|
|
|
|
|
|
forceOSType android.OsType
|
|
|
|
forceArchType android.ArchType
|
|
|
|
}
|
|
|
|
|
|
|
|
func ravenwoodLibgroupFactory() android.Module {
|
|
|
|
module := &ravenwoodLibgroup{}
|
|
|
|
module.AddProperties(&module.ravenwoodLibgroupProperties)
|
|
|
|
|
|
|
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ravenwoodLibgroup) InstallInTestcases() bool { return true }
|
|
|
|
func (r *ravenwoodLibgroup) InstallForceOS() (*android.OsType, *android.ArchType) {
|
|
|
|
return &r.forceOSType, &r.forceArchType
|
|
|
|
}
|
|
|
|
func (r *ravenwoodLibgroup) TestSuites() []string {
|
2023-11-30 17:29:50 +01:00
|
|
|
return []string{
|
|
|
|
"general-tests",
|
|
|
|
"ravenwood-tests",
|
|
|
|
}
|
2023-10-20 19:42:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ravenwoodLibgroup) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
// Always depends on our underlying libs
|
|
|
|
for _, lib := range r.ravenwoodLibgroupProperties.Libs {
|
2024-02-08 17:14:40 +01:00
|
|
|
ctx.AddVariationDependencies(nil, ravenwoodLibContentTag, lib)
|
2023-10-20 19:42:47 +02:00
|
|
|
}
|
2024-02-02 22:29:01 +01:00
|
|
|
for _, lib := range r.ravenwoodLibgroupProperties.Jni_libs {
|
2024-02-08 17:14:40 +01:00
|
|
|
ctx.AddVariationDependencies(ctx.Config().BuildOSTarget.Variations(), jniLibTag, lib)
|
2024-02-02 22:29:01 +01:00
|
|
|
}
|
2023-10-20 19:42:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ravenwoodLibgroup) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
r.forceOSType = ctx.Config().BuildOS
|
|
|
|
r.forceArchType = ctx.Config().BuildArch
|
|
|
|
|
2024-02-08 17:14:40 +01:00
|
|
|
// Collect the JNI dependencies, including the transitive deps.
|
|
|
|
jniDepNames := make(map[string]bool)
|
|
|
|
jniLibs := collectTransitiveJniDeps(ctx)
|
|
|
|
|
|
|
|
for _, jni := range jniLibs {
|
|
|
|
jniDepNames[jni.name] = true
|
|
|
|
}
|
|
|
|
android.SetProvider(ctx, ravenwoodLibgroupJniDepProvider, ravenwoodLibgroupJniDepProviderInfo{
|
|
|
|
names: jniDepNames,
|
|
|
|
})
|
|
|
|
|
2023-10-20 19:42:47 +02:00
|
|
|
// Install our runtime into expected location for packaging
|
|
|
|
installPath := android.PathForModuleInstall(ctx, r.BaseModuleName())
|
|
|
|
for _, lib := range r.ravenwoodLibgroupProperties.Libs {
|
2024-02-08 17:14:40 +01:00
|
|
|
libModule := ctx.GetDirectDepWithTag(lib, ravenwoodLibContentTag)
|
2023-10-20 19:42:47 +02:00
|
|
|
libJar := android.OutputFileForModule(ctx, libModule, "")
|
|
|
|
ctx.InstallFile(installPath, lib+".jar", libJar)
|
|
|
|
}
|
2024-02-02 22:29:01 +01:00
|
|
|
soInstallPath := android.PathForModuleInstall(ctx, r.BaseModuleName()).Join(ctx, getLibPath(r.forceArchType))
|
2024-02-08 17:14:40 +01:00
|
|
|
|
|
|
|
for _, jniLib := range jniLibs {
|
|
|
|
ctx.InstallFile(soInstallPath, jniLib.path.Base(), jniLib.path)
|
2024-02-02 22:29:01 +01:00
|
|
|
}
|
2023-10-20 19:42:47 +02:00
|
|
|
|
|
|
|
// Normal build should perform install steps
|
|
|
|
ctx.Phony(r.BaseModuleName(), android.PathForPhony(ctx, r.BaseModuleName()+"-install"))
|
|
|
|
}
|
2024-02-08 17:14:40 +01:00
|
|
|
|
|
|
|
// collectTransitiveJniDeps returns all JNI dependencies, including transitive
|
|
|
|
// ones, including NDK / stub libs. (Because Ravenwood has no "preinstalled" libraries)
|
|
|
|
func collectTransitiveJniDeps(ctx android.ModuleContext) []jniLib {
|
|
|
|
libs, _ := collectJniDeps(ctx, true, false, nil)
|
|
|
|
return libs
|
|
|
|
}
|