2015-03-31 02:20:39 +02:00
|
|
|
// Copyright 2015 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
|
|
|
|
|
|
|
|
// This file contains the module types for compiling Java for Android, and converts the properties
|
2017-06-23 01:51:17 +02:00
|
|
|
// into the flags and filenames necessary to pass to the Module. The final creation of the rules
|
2015-03-31 02:20:39 +02:00
|
|
|
// is handled in builder.go
|
|
|
|
|
|
|
|
import (
|
2018-03-26 23:42:44 +02:00
|
|
|
"fmt"
|
2017-09-19 02:41:52 +02:00
|
|
|
"path/filepath"
|
2023-08-16 17:06:31 +02:00
|
|
|
"sort"
|
2021-12-10 12:14:59 +01:00
|
|
|
"strings"
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2022-11-15 20:06:14 +01:00
|
|
|
"android/soong/remoteexec"
|
2023-10-06 21:54:58 +02:00
|
|
|
"android/soong/testing"
|
2023-12-19 02:13:16 +01:00
|
|
|
|
2015-03-31 02:20:39 +02:00
|
|
|
"github.com/google/blueprint"
|
2017-08-30 01:02:06 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
"android/soong/android"
|
2021-01-26 20:01:43 +01:00
|
|
|
"android/soong/cc"
|
2020-08-14 18:32:16 +02:00
|
|
|
"android/soong/dexpreopt"
|
2017-06-23 02:20:19 +02:00
|
|
|
"android/soong/java/config"
|
2018-08-08 01:49:25 +02:00
|
|
|
"android/soong/tradefed"
|
2015-03-31 02:20:39 +02:00
|
|
|
)
|
|
|
|
|
2015-06-17 23:20:06 +02:00
|
|
|
func init() {
|
2021-03-31 00:34:32 +02:00
|
|
|
registerJavaBuildComponents(android.InitRegistrationContext)
|
2019-12-13 12:22:16 +01:00
|
|
|
|
2021-03-11 02:02:43 +01:00
|
|
|
RegisterJavaSdkMemberTypes()
|
|
|
|
}
|
|
|
|
|
2021-03-31 00:34:32 +02:00
|
|
|
func registerJavaBuildComponents(ctx android.RegistrationContext) {
|
2021-03-11 02:02:43 +01:00
|
|
|
ctx.RegisterModuleType("java_defaults", DefaultsFactory)
|
|
|
|
|
|
|
|
ctx.RegisterModuleType("java_library", LibraryFactory)
|
|
|
|
ctx.RegisterModuleType("java_library_static", LibraryStaticFactory)
|
|
|
|
ctx.RegisterModuleType("java_library_host", LibraryHostFactory)
|
|
|
|
ctx.RegisterModuleType("java_binary", BinaryFactory)
|
|
|
|
ctx.RegisterModuleType("java_binary_host", BinaryHostFactory)
|
|
|
|
ctx.RegisterModuleType("java_test", TestFactory)
|
|
|
|
ctx.RegisterModuleType("java_test_helper_library", TestHelperLibraryFactory)
|
|
|
|
ctx.RegisterModuleType("java_test_host", TestHostFactory)
|
|
|
|
ctx.RegisterModuleType("java_test_import", JavaTestImportFactory)
|
|
|
|
ctx.RegisterModuleType("java_import", ImportFactory)
|
|
|
|
ctx.RegisterModuleType("java_import_host", ImportFactoryHost)
|
|
|
|
ctx.RegisterModuleType("java_device_for_host", DeviceForHostFactory)
|
|
|
|
ctx.RegisterModuleType("java_host_for_device", HostForDeviceFactory)
|
|
|
|
ctx.RegisterModuleType("dex_import", DexImportFactory)
|
2022-11-15 20:06:14 +01:00
|
|
|
ctx.RegisterModuleType("java_api_library", ApiLibraryFactory)
|
|
|
|
ctx.RegisterModuleType("java_api_contribution", ApiContributionFactory)
|
2023-09-12 02:36:43 +02:00
|
|
|
ctx.RegisterModuleType("java_api_contribution_import", ApiContributionImportFactory)
|
2021-03-11 02:02:43 +01:00
|
|
|
|
2021-05-13 03:38:35 +02:00
|
|
|
// This mutator registers dependencies on dex2oat for modules that should be
|
|
|
|
// dexpreopted. This is done late when the final variants have been
|
|
|
|
// established, to not get the dependencies split into the wrong variants and
|
|
|
|
// to support the checks in dexpreoptDisabled().
|
2021-03-11 02:02:43 +01:00
|
|
|
ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) {
|
|
|
|
ctx.BottomUp("dexpreopt_tool_deps", dexpreoptToolDepsMutator).Parallel()
|
2022-09-07 18:07:07 +02:00
|
|
|
// needs access to ApexInfoProvider which is available after variant creation
|
|
|
|
ctx.BottomUp("jacoco_deps", jacocoDepsMutator).Parallel()
|
2021-03-11 02:02:43 +01:00
|
|
|
})
|
|
|
|
|
2023-05-16 02:58:37 +02:00
|
|
|
ctx.RegisterParallelSingletonType("logtags", LogtagsSingleton)
|
|
|
|
ctx.RegisterParallelSingletonType("kythe_java_extract", kytheExtractJavaFactory)
|
2021-03-11 02:02:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func RegisterJavaSdkMemberTypes() {
|
2019-12-13 12:22:16 +01:00
|
|
|
// Register sdk member types.
|
2020-01-13 22:03:22 +01:00
|
|
|
android.RegisterSdkMemberType(javaHeaderLibsSdkMemberType)
|
2021-04-23 20:43:28 +02:00
|
|
|
android.RegisterSdkMemberType(javaLibsSdkMemberType)
|
|
|
|
android.RegisterSdkMemberType(javaBootLibsSdkMemberType)
|
2021-09-26 10:58:02 +02:00
|
|
|
android.RegisterSdkMemberType(javaSystemserverLibsSdkMemberType)
|
2021-04-23 20:43:28 +02:00
|
|
|
android.RegisterSdkMemberType(javaTestSdkMemberType)
|
|
|
|
}
|
|
|
|
|
2024-02-12 23:49:21 +01:00
|
|
|
type StubsLinkType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
Unknown StubsLinkType = iota
|
|
|
|
Stubs
|
|
|
|
Implementation
|
|
|
|
)
|
|
|
|
|
2021-04-23 20:43:28 +02:00
|
|
|
var (
|
|
|
|
// Supports adding java header libraries to module_exports and sdk.
|
|
|
|
javaHeaderLibsSdkMemberType = &librarySdkMemberType{
|
2022-11-21 11:57:30 +01:00
|
|
|
android.SdkMemberTypeBase{
|
2021-04-23 20:43:28 +02:00
|
|
|
PropertyName: "java_header_libs",
|
|
|
|
SupportsSdk: true,
|
|
|
|
},
|
2022-11-21 11:57:30 +01:00
|
|
|
func(_ android.SdkMemberContext, j *Library) android.Path {
|
2021-04-23 20:43:28 +02:00
|
|
|
headerJars := j.HeaderJars()
|
|
|
|
if len(headerJars) != 1 {
|
|
|
|
panic(fmt.Errorf("there must be only one header jar from %q", j.Name()))
|
|
|
|
}
|
|
|
|
|
|
|
|
return headerJars[0]
|
|
|
|
},
|
2022-11-21 11:57:30 +01:00
|
|
|
sdkSnapshotFilePathForJar,
|
|
|
|
copyEverythingToSnapshot,
|
2021-04-23 20:43:28 +02:00
|
|
|
}
|
2019-12-13 12:22:16 +01:00
|
|
|
|
2021-02-04 12:15:34 +01:00
|
|
|
// Export implementation classes jar as part of the sdk.
|
2021-04-23 20:43:28 +02:00
|
|
|
exportImplementationClassesJar = func(_ android.SdkMemberContext, j *Library) android.Path {
|
2021-02-04 12:15:34 +01:00
|
|
|
implementationJars := j.ImplementationAndResourcesJars()
|
|
|
|
if len(implementationJars) != 1 {
|
|
|
|
panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name()))
|
|
|
|
}
|
|
|
|
return implementationJars[0]
|
|
|
|
}
|
|
|
|
|
2021-04-23 20:43:28 +02:00
|
|
|
// Supports adding java implementation libraries to module_exports but not sdk.
|
|
|
|
javaLibsSdkMemberType = &librarySdkMemberType{
|
2022-11-21 11:57:30 +01:00
|
|
|
android.SdkMemberTypeBase{
|
2020-02-28 15:39:53 +01:00
|
|
|
PropertyName: "java_libs",
|
|
|
|
},
|
2022-11-21 11:57:30 +01:00
|
|
|
exportImplementationClassesJar,
|
|
|
|
sdkSnapshotFilePathForJar,
|
|
|
|
copyEverythingToSnapshot,
|
2021-04-23 20:43:28 +02:00
|
|
|
}
|
2019-12-03 19:06:47 +01:00
|
|
|
|
2022-07-15 15:12:35 +02:00
|
|
|
snapshotRequiresImplementationJar = func(ctx android.SdkMemberContext) bool {
|
|
|
|
// In the S build the build will break if updatable-media does not provide a full implementation
|
|
|
|
// jar. That issue was fixed in Tiramisu by b/229932396.
|
|
|
|
if ctx.IsTargetBuildBeforeTiramisu() && ctx.Name() == "updatable-media" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-04-23 20:43:28 +02:00
|
|
|
// Supports adding java boot libraries to module_exports and sdk.
|
2020-12-08 18:48:25 +01:00
|
|
|
//
|
|
|
|
// The build has some implicit dependencies (via the boot jars configuration) on a number of
|
|
|
|
// modules, e.g. core-oj, apache-xml, that are part of the java boot class path and which are
|
|
|
|
// provided by mainline modules (e.g. art, conscrypt, runtime-i18n) but which are not otherwise
|
|
|
|
// used outside those mainline modules.
|
|
|
|
//
|
|
|
|
// As they are not needed outside the mainline modules adding them to the sdk/module-exports as
|
|
|
|
// either java_libs, or java_header_libs would end up exporting more information than was strictly
|
|
|
|
// necessary. The java_boot_libs property to allow those modules to be exported as part of the
|
|
|
|
// sdk/module_exports without exposing any unnecessary information.
|
2021-04-23 20:43:28 +02:00
|
|
|
javaBootLibsSdkMemberType = &librarySdkMemberType{
|
2022-11-21 11:57:30 +01:00
|
|
|
android.SdkMemberTypeBase{
|
2020-12-08 18:48:25 +01:00
|
|
|
PropertyName: "java_boot_libs",
|
|
|
|
SupportsSdk: true,
|
|
|
|
},
|
2022-11-21 11:57:30 +01:00
|
|
|
func(ctx android.SdkMemberContext, j *Library) android.Path {
|
2022-07-15 15:12:35 +02:00
|
|
|
if snapshotRequiresImplementationJar(ctx) {
|
|
|
|
return exportImplementationClassesJar(ctx, j)
|
|
|
|
}
|
|
|
|
|
2021-07-15 13:42:44 +02:00
|
|
|
// Java boot libs are only provided in the SDK to provide access to their dex implementation
|
|
|
|
// jar for use by dexpreopting and boot jars package check. They do not need to provide an
|
|
|
|
// actual implementation jar but the java_import will need a file that exists so just copy an
|
|
|
|
// empty file. Any attempt to use that file as a jar will cause a build error.
|
2022-11-21 11:57:30 +01:00
|
|
|
return ctx.SnapshotBuilder().EmptyFile()
|
2021-07-15 13:42:44 +02:00
|
|
|
},
|
2022-11-21 11:57:30 +01:00
|
|
|
func(ctx android.SdkMemberContext, osPrefix, name string) string {
|
2022-07-15 15:12:35 +02:00
|
|
|
if snapshotRequiresImplementationJar(ctx) {
|
|
|
|
return sdkSnapshotFilePathForJar(ctx, osPrefix, name)
|
|
|
|
}
|
|
|
|
|
2021-07-15 13:42:44 +02:00
|
|
|
// Create a special name for the implementation jar to try and provide some useful information
|
|
|
|
// to a developer that attempts to compile against this.
|
|
|
|
// TODO(b/175714559): Provide a proper error message in Soong not ninja.
|
|
|
|
return filepath.Join(osPrefix, "java_boot_libs", "snapshot", "jars", "are", "invalid", name+jarFileSuffix)
|
|
|
|
},
|
2022-11-21 11:57:30 +01:00
|
|
|
onlyCopyJarToSnapshot,
|
2021-04-23 20:43:28 +02:00
|
|
|
}
|
2020-12-08 18:48:25 +01:00
|
|
|
|
2021-09-26 10:58:02 +02:00
|
|
|
// Supports adding java systemserver libraries to module_exports and sdk.
|
|
|
|
//
|
|
|
|
// The build has some implicit dependencies (via the systemserver jars configuration) on a number
|
|
|
|
// of modules that are part of the java systemserver classpath and which are provided by mainline
|
|
|
|
// modules but which are not otherwise used outside those mainline modules.
|
|
|
|
//
|
|
|
|
// As they are not needed outside the mainline modules adding them to the sdk/module-exports as
|
|
|
|
// either java_libs, or java_header_libs would end up exporting more information than was strictly
|
|
|
|
// necessary. The java_systemserver_libs property to allow those modules to be exported as part of
|
|
|
|
// the sdk/module_exports without exposing any unnecessary information.
|
|
|
|
javaSystemserverLibsSdkMemberType = &librarySdkMemberType{
|
2022-11-21 11:57:30 +01:00
|
|
|
android.SdkMemberTypeBase{
|
2021-09-26 10:58:02 +02:00
|
|
|
PropertyName: "java_systemserver_libs",
|
|
|
|
SupportsSdk: true,
|
2022-07-01 17:56:06 +02:00
|
|
|
|
|
|
|
// This was only added in Tiramisu.
|
|
|
|
SupportedBuildReleaseSpecification: "Tiramisu+",
|
2021-09-26 10:58:02 +02:00
|
|
|
},
|
2022-11-21 11:57:30 +01:00
|
|
|
func(ctx android.SdkMemberContext, j *Library) android.Path {
|
2021-09-26 10:58:02 +02:00
|
|
|
// Java systemserver libs are only provided in the SDK to provide access to their dex
|
|
|
|
// implementation jar for use by dexpreopting. They do not need to provide an actual
|
|
|
|
// implementation jar but the java_import will need a file that exists so just copy an empty
|
|
|
|
// file. Any attempt to use that file as a jar will cause a build error.
|
2022-11-21 11:57:30 +01:00
|
|
|
return ctx.SnapshotBuilder().EmptyFile()
|
2021-09-26 10:58:02 +02:00
|
|
|
},
|
2022-11-21 11:57:30 +01:00
|
|
|
func(_ android.SdkMemberContext, osPrefix, name string) string {
|
2021-09-26 10:58:02 +02:00
|
|
|
// Create a special name for the implementation jar to try and provide some useful information
|
|
|
|
// to a developer that attempts to compile against this.
|
|
|
|
// TODO(b/175714559): Provide a proper error message in Soong not ninja.
|
|
|
|
return filepath.Join(osPrefix, "java_systemserver_libs", "snapshot", "jars", "are", "invalid", name+jarFileSuffix)
|
|
|
|
},
|
2022-11-21 11:57:30 +01:00
|
|
|
onlyCopyJarToSnapshot,
|
2021-09-26 10:58:02 +02:00
|
|
|
}
|
|
|
|
|
2021-04-23 20:43:28 +02:00
|
|
|
// Supports adding java test libraries to module_exports but not sdk.
|
|
|
|
javaTestSdkMemberType = &testSdkMemberType{
|
2019-12-03 19:06:47 +01:00
|
|
|
SdkMemberTypeBase: android.SdkMemberTypeBase{
|
|
|
|
PropertyName: "java_tests",
|
|
|
|
},
|
2021-04-23 20:43:28 +02:00
|
|
|
}
|
2022-10-10 22:45:06 +02:00
|
|
|
|
|
|
|
// Rule for generating device binary default wrapper
|
|
|
|
deviceBinaryWrapper = pctx.StaticRule("deviceBinaryWrapper", blueprint.RuleParams{
|
|
|
|
Command: `echo -e '#!/system/bin/sh\n` +
|
|
|
|
`export CLASSPATH=/system/framework/$jar_name\n` +
|
|
|
|
`exec app_process /$partition/bin $main_class "$$@"'> ${out}`,
|
|
|
|
Description: "Generating device binary wrapper ${jar_name}",
|
|
|
|
}, "jar_name", "partition", "main_class")
|
2021-04-23 20:43:28 +02:00
|
|
|
)
|
2019-07-11 08:54:27 +02:00
|
|
|
|
2023-08-03 00:00:35 +02:00
|
|
|
type ProguardSpecInfo struct {
|
|
|
|
// If true, proguard flags files will be exported to reverse dependencies across libs edges
|
|
|
|
// If false, proguard flags files will only be exported to reverse dependencies across
|
|
|
|
// static_libs edges.
|
|
|
|
Export_proguard_flags_files bool
|
|
|
|
|
|
|
|
// TransitiveDepsProguardSpecFiles is a depset of paths to proguard flags files that are exported from
|
|
|
|
// all transitive deps. This list includes all proguard flags files from transitive static dependencies,
|
|
|
|
// and all proguard flags files from transitive libs dependencies which set `export_proguard_spec: true`.
|
|
|
|
ProguardFlagsFiles *android.DepSet[android.Path]
|
|
|
|
|
|
|
|
// implementation detail to store transitive proguard flags files from exporting shared deps
|
|
|
|
UnconditionallyExportedProguardFlags *android.DepSet[android.Path]
|
|
|
|
}
|
|
|
|
|
2023-12-13 01:39:03 +01:00
|
|
|
var ProguardSpecInfoProvider = blueprint.NewProvider[ProguardSpecInfo]()
|
2023-08-03 00:00:35 +02:00
|
|
|
|
2021-02-01 22:59:03 +01:00
|
|
|
// JavaInfo contains information about a java module for use by modules that depend on it.
|
|
|
|
type JavaInfo struct {
|
|
|
|
// HeaderJars is a list of jars that can be passed as the javac classpath in order to link
|
|
|
|
// against this module. If empty, ImplementationJars should be used instead.
|
|
|
|
HeaderJars android.Paths
|
|
|
|
|
2024-02-05 23:46:00 +01:00
|
|
|
RepackagedHeaderJars android.Paths
|
|
|
|
|
2022-11-29 17:19:37 +01:00
|
|
|
// set of header jars for all transitive libs deps
|
2022-04-21 21:50:51 +02:00
|
|
|
TransitiveLibsHeaderJars *android.DepSet[android.Path]
|
2022-11-29 17:19:37 +01:00
|
|
|
|
|
|
|
// set of header jars for all transitive static libs deps
|
2022-04-21 21:50:51 +02:00
|
|
|
TransitiveStaticLibsHeaderJars *android.DepSet[android.Path]
|
2022-11-29 17:19:37 +01:00
|
|
|
|
2021-02-01 22:59:03 +01:00
|
|
|
// ImplementationAndResourceJars is a list of jars that contain the implementations of classes
|
|
|
|
// in the module as well as any resources included in the module.
|
|
|
|
ImplementationAndResourcesJars android.Paths
|
|
|
|
|
|
|
|
// ImplementationJars is a list of jars that contain the implementations of classes in the
|
2022-11-21 11:57:30 +01:00
|
|
|
//module.
|
2021-02-01 22:59:03 +01:00
|
|
|
ImplementationJars android.Paths
|
|
|
|
|
|
|
|
// ResourceJars is a list of jars that contain the resources included in the module.
|
|
|
|
ResourceJars android.Paths
|
|
|
|
|
|
|
|
// AidlIncludeDirs is a list of directories that should be passed to the aidl tool when
|
|
|
|
// depending on this module.
|
|
|
|
AidlIncludeDirs android.Paths
|
|
|
|
|
|
|
|
// SrcJarArgs is a list of arguments to pass to soong_zip to package the sources of this
|
|
|
|
// module.
|
2021-03-17 23:56:23 +01:00
|
|
|
SrcJarArgs []string
|
2020-06-03 05:09:13 +02:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
// SrcJarDeps is a list of paths to depend on when packaging the sources of this module.
|
|
|
|
SrcJarDeps android.Paths
|
|
|
|
|
2023-09-20 15:39:57 +02:00
|
|
|
// The source files of this module and all its transitive static dependencies.
|
|
|
|
TransitiveSrcFiles *android.DepSet[android.Path]
|
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
// ExportedPlugins is a list of paths that should be used as annotation processors for any
|
|
|
|
// module that depends on this module.
|
|
|
|
ExportedPlugins android.Paths
|
2020-06-03 05:09:13 +02:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
// ExportedPluginClasses is a list of classes that should be run as annotation processors for
|
|
|
|
// any module that depends on this module.
|
|
|
|
ExportedPluginClasses []string
|
2018-08-15 20:19:12 +02:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
// ExportedPluginDisableTurbine is true if this module's annotation processors generate APIs,
|
|
|
|
// requiring disbling turbine for any modules that depend on it.
|
|
|
|
ExportedPluginDisableTurbine bool
|
2021-02-01 22:59:03 +01:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
// JacocoReportClassesFile is the path to a jar containing uninstrumented classes that will be
|
|
|
|
// instrumented by jacoco.
|
|
|
|
JacocoReportClassesFile android.Path
|
2024-02-12 23:49:21 +01:00
|
|
|
|
|
|
|
// StubsLinkType provides information about whether the provided jars are stub jars or
|
|
|
|
// implementation jars. If the provider is set by java_sdk_library, the link type is "unknown"
|
|
|
|
// and selection between the stub jar vs implementation jar is deferred to SdkLibrary.sdkJars(...)
|
|
|
|
StubsLinkType StubsLinkType
|
2017-10-19 22:06:22 +02:00
|
|
|
}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2023-12-13 01:39:03 +01:00
|
|
|
var JavaInfoProvider = blueprint.NewProvider[JavaInfo]()
|
2019-09-06 01:44:18 +02:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
// SyspropPublicStubInfo contains info about the sysprop public stub library that corresponds to
|
|
|
|
// the sysprop implementation library.
|
|
|
|
type SyspropPublicStubInfo struct {
|
|
|
|
// JavaInfo is the JavaInfoProvider of the sysprop public stub library that corresponds to
|
|
|
|
// the sysprop implementation library.
|
|
|
|
JavaInfo JavaInfo
|
|
|
|
}
|
2019-09-06 01:44:18 +02:00
|
|
|
|
2023-12-13 01:39:03 +01:00
|
|
|
var SyspropPublicStubInfoProvider = blueprint.NewProvider[SyspropPublicStubInfo]()
|
2019-09-06 01:44:18 +02:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
// Methods that need to be implemented for a module that is added to apex java_libs property.
|
|
|
|
type ApexDependency interface {
|
|
|
|
HeaderJars() android.Paths
|
|
|
|
ImplementationAndResourcesJars() android.Paths
|
|
|
|
}
|
2019-09-06 01:44:18 +02:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
// Provides build path and install path to DEX jars.
|
|
|
|
type UsesLibraryDependency interface {
|
2024-01-09 22:35:56 +01:00
|
|
|
DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath
|
2021-03-17 23:56:23 +01:00
|
|
|
DexJarInstallPath() android.Path
|
|
|
|
ClassLoaderContexts() dexpreopt.ClassLoaderContextMap
|
2019-09-06 01:44:18 +02:00
|
|
|
}
|
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
// TODO(jungjw): Move this to kythe.go once it's created.
|
|
|
|
type xref interface {
|
|
|
|
XrefJavaFiles() android.Paths
|
|
|
|
}
|
2018-08-21 17:10:29 +02:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
func (j *Module) XrefJavaFiles() android.Paths {
|
|
|
|
return j.kytheFiles
|
2018-08-21 17:10:29 +02:00
|
|
|
}
|
|
|
|
|
2024-03-05 01:36:31 +01:00
|
|
|
func (d dependencyTag) PropagateAconfigValidation() bool {
|
|
|
|
return d.static
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ android.PropagateAconfigValidationDependencyTag = dependencyTag{}
|
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
type dependencyTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
name string
|
2021-12-11 00:05:02 +01:00
|
|
|
|
|
|
|
// True if the dependency is relinked at runtime.
|
|
|
|
runtimeLinked bool
|
2022-01-12 20:13:32 +01:00
|
|
|
|
|
|
|
// True if the dependency is a toolchain, for example an annotation processor.
|
|
|
|
toolchain bool
|
2024-03-05 01:36:31 +01:00
|
|
|
|
|
|
|
static bool
|
2021-03-17 23:56:23 +01:00
|
|
|
}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
// installDependencyTag is a dependency tag that is annotated to cause the installed files of the
|
|
|
|
// dependency to be installed when the parent module is installed.
|
|
|
|
type installDependencyTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
android.InstallAlwaysNeededDependencyTag
|
|
|
|
name string
|
|
|
|
}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2021-12-11 00:05:02 +01:00
|
|
|
func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
|
|
|
|
if d.runtimeLinked {
|
|
|
|
return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency}
|
2022-01-12 20:13:32 +01:00
|
|
|
} else if d.toolchain {
|
|
|
|
return []android.LicenseAnnotation{android.LicenseAnnotationToolchain}
|
2021-12-11 00:05:02 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ android.LicenseAnnotationsDependencyTag = dependencyTag{}
|
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
type usesLibraryDependencyTag struct {
|
|
|
|
dependencyTag
|
2022-05-04 13:00:02 +02:00
|
|
|
sdkVersion int // SDK version in which the library appared as a standalone library.
|
|
|
|
optional bool // If the dependency is optional or required.
|
2021-03-17 23:56:23 +01:00
|
|
|
}
|
|
|
|
|
2022-05-04 13:00:02 +02:00
|
|
|
func makeUsesLibraryDependencyTag(sdkVersion int, optional bool) usesLibraryDependencyTag {
|
2021-03-17 23:56:23 +01:00
|
|
|
return usesLibraryDependencyTag{
|
2021-12-11 00:05:02 +01:00
|
|
|
dependencyTag: dependencyTag{
|
|
|
|
name: fmt.Sprintf("uses-library-%d", sdkVersion),
|
|
|
|
runtimeLinked: true,
|
|
|
|
},
|
|
|
|
sdkVersion: sdkVersion,
|
|
|
|
optional: optional,
|
2017-10-19 22:06:22 +02:00
|
|
|
}
|
2021-03-17 23:56:23 +01:00
|
|
|
}
|
2017-08-31 21:30:37 +02:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
func IsJniDepTag(depTag blueprint.DependencyTag) bool {
|
|
|
|
return depTag == jniLibTag
|
2017-10-19 22:06:22 +02:00
|
|
|
}
|
2017-08-31 21:30:37 +02:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
var (
|
|
|
|
dataNativeBinsTag = dependencyTag{name: "dataNativeBins"}
|
2022-01-20 22:10:28 +01:00
|
|
|
dataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"}
|
2024-03-05 01:36:31 +01:00
|
|
|
staticLibTag = dependencyTag{name: "staticlib", static: true}
|
2021-12-11 00:05:02 +01:00
|
|
|
libTag = dependencyTag{name: "javalib", runtimeLinked: true}
|
2022-09-23 22:50:56 +02:00
|
|
|
sdkLibTag = dependencyTag{name: "sdklib", runtimeLinked: true}
|
2021-12-11 00:05:02 +01:00
|
|
|
java9LibTag = dependencyTag{name: "java9lib", runtimeLinked: true}
|
2022-01-12 20:13:32 +01:00
|
|
|
pluginTag = dependencyTag{name: "plugin", toolchain: true}
|
|
|
|
errorpronePluginTag = dependencyTag{name: "errorprone-plugin", toolchain: true}
|
|
|
|
exportedPluginTag = dependencyTag{name: "exported-plugin", toolchain: true}
|
2021-12-11 00:05:02 +01:00
|
|
|
bootClasspathTag = dependencyTag{name: "bootclasspath", runtimeLinked: true}
|
|
|
|
systemModulesTag = dependencyTag{name: "system modules", runtimeLinked: true}
|
2021-03-17 23:56:23 +01:00
|
|
|
frameworkResTag = dependencyTag{name: "framework-res"}
|
2021-12-11 00:05:02 +01:00
|
|
|
kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib", runtimeLinked: true}
|
|
|
|
kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations", runtimeLinked: true}
|
2022-01-12 20:13:32 +01:00
|
|
|
kotlinPluginTag = dependencyTag{name: "kotlin-plugin", toolchain: true}
|
2021-03-17 23:56:23 +01:00
|
|
|
proguardRaiseTag = dependencyTag{name: "proguard-raise"}
|
|
|
|
certificateTag = dependencyTag{name: "certificate"}
|
|
|
|
instrumentationForTag = dependencyTag{name: "instrumentation_for"}
|
2022-01-12 20:13:32 +01:00
|
|
|
extraLintCheckTag = dependencyTag{name: "extra-lint-check", toolchain: true}
|
2021-12-11 00:05:02 +01:00
|
|
|
jniLibTag = dependencyTag{name: "jnilib", runtimeLinked: true}
|
2022-11-29 17:19:37 +01:00
|
|
|
r8LibraryJarTag = dependencyTag{name: "r8-libraryjar", runtimeLinked: true}
|
2021-03-17 23:56:23 +01:00
|
|
|
syspropPublicStubDepTag = dependencyTag{name: "sysprop public stub"}
|
2023-03-14 02:09:34 +01:00
|
|
|
javaApiContributionTag = dependencyTag{name: "java-api-contribution"}
|
|
|
|
depApiSrcsTag = dependencyTag{name: "dep-api-srcs"}
|
2023-12-01 23:01:06 +01:00
|
|
|
aconfigDeclarationTag = dependencyTag{name: "aconfig-declaration"}
|
2021-03-17 23:56:23 +01:00
|
|
|
jniInstallTag = installDependencyTag{name: "jni install"}
|
|
|
|
binaryInstallTag = installDependencyTag{name: "binary install"}
|
2022-05-04 13:00:02 +02:00
|
|
|
usesLibReqTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, false)
|
|
|
|
usesLibOptTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, true)
|
|
|
|
usesLibCompat28OptTag = makeUsesLibraryDependencyTag(28, true)
|
|
|
|
usesLibCompat29ReqTag = makeUsesLibraryDependencyTag(29, false)
|
|
|
|
usesLibCompat30OptTag = makeUsesLibraryDependencyTag(30, true)
|
2021-03-17 23:56:23 +01:00
|
|
|
)
|
2017-11-22 22:49:43 +01:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
func IsLibDepTag(depTag blueprint.DependencyTag) bool {
|
2022-09-23 22:50:56 +02:00
|
|
|
return depTag == libTag || depTag == sdkLibTag
|
2021-03-17 23:56:23 +01:00
|
|
|
}
|
2017-11-22 22:49:43 +01:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
func IsStaticLibDepTag(depTag blueprint.DependencyTag) bool {
|
|
|
|
return depTag == staticLibTag
|
|
|
|
}
|
2017-11-22 22:49:43 +01:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
type sdkDep struct {
|
|
|
|
useModule, useFiles, invalidVersion bool
|
2017-11-22 22:49:43 +01:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
// The modules that will be added to the bootclasspath when targeting 1.8 or lower
|
|
|
|
bootclasspath []string
|
2017-11-22 22:49:43 +01:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
// The default system modules to use. Will be an empty string if no system
|
|
|
|
// modules are to be used.
|
|
|
|
systemModules string
|
2017-11-22 22:49:43 +01:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
// The modules that will be added to the classpath regardless of the Java language level targeted
|
|
|
|
classpath []string
|
2017-10-19 22:06:22 +02:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
// The modules that will be added ot the classpath when targeting 1.9 or higher
|
|
|
|
// (normally these will be on the bootclasspath when targeting 1.8 or lower)
|
|
|
|
java9Classpath []string
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
frameworkResModule string
|
2019-01-31 23:12:44 +01:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
jars android.Paths
|
|
|
|
aidl android.OptionalPath
|
2020-06-09 15:31:19 +02:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
noStandardLibs, noFrameworksLibs bool
|
2018-08-16 05:40:52 +02:00
|
|
|
}
|
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
func (s sdkDep) hasStandardLibs() bool {
|
|
|
|
return !s.noStandardLibs
|
2015-04-08 22:03:43 +02:00
|
|
|
}
|
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
func (s sdkDep) hasFrameworkLibs() bool {
|
|
|
|
return !s.noStandardLibs && !s.noFrameworksLibs
|
2018-05-28 11:02:19 +02:00
|
|
|
}
|
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
type jniLib struct {
|
|
|
|
name string
|
|
|
|
path android.Path
|
|
|
|
target android.Target
|
|
|
|
coverageFile android.OptionalPath
|
|
|
|
unstrippedFile android.Path
|
2022-09-02 00:47:07 +02:00
|
|
|
partition string
|
2015-04-11 02:45:20 +02:00
|
|
|
}
|
|
|
|
|
2021-03-29 13:11:58 +02:00
|
|
|
func sdkDeps(ctx android.BottomUpMutatorContext, sdkContext android.SdkContext, d dexer) {
|
2021-03-17 23:56:23 +01:00
|
|
|
sdkDep := decodeSdkDep(ctx, sdkContext)
|
|
|
|
if sdkDep.useModule {
|
|
|
|
ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
|
|
|
|
ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
|
2022-09-23 22:50:56 +02:00
|
|
|
ctx.AddVariationDependencies(nil, sdkLibTag, sdkDep.classpath...)
|
2021-03-17 23:56:23 +01:00
|
|
|
if d.effectiveOptimizeEnabled() && sdkDep.hasStandardLibs() {
|
2023-03-30 01:25:49 +02:00
|
|
|
ctx.AddVariationDependencies(nil, proguardRaiseTag,
|
2023-06-15 00:43:25 +02:00
|
|
|
config.LegacyCorePlatformBootclasspathLibraries...,
|
2023-03-30 01:25:49 +02:00
|
|
|
)
|
2021-03-17 23:56:23 +01:00
|
|
|
}
|
|
|
|
if d.effectiveOptimizeEnabled() && sdkDep.hasFrameworkLibs() {
|
|
|
|
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.FrameworkLibraries...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if sdkDep.systemModules != "" {
|
|
|
|
ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
|
2018-08-16 00:35:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
type deps struct {
|
2022-03-17 19:12:32 +01:00
|
|
|
// bootClasspath is the list of jars that form the boot classpath (generally the java.* and
|
|
|
|
// android.* classes) for tools that still use it. javac targeting 1.9 or higher uses
|
|
|
|
// systemModules and java9Classpath instead.
|
|
|
|
bootClasspath classpath
|
|
|
|
|
|
|
|
// classpath is the list of jars that form the classpath for javac and kotlinc rules. It
|
|
|
|
// contains header jars for all static and non-static dependencies.
|
|
|
|
classpath classpath
|
|
|
|
|
|
|
|
// dexClasspath is the list of jars that form the classpath for d8 and r8 rules. It contains
|
|
|
|
// header jars for all non-static dependencies. Static dependencies have already been
|
|
|
|
// combined into the program jar.
|
|
|
|
dexClasspath classpath
|
|
|
|
|
|
|
|
// java9Classpath is the list of jars that will be added to the classpath when targeting
|
|
|
|
// 1.9 or higher. It generally contains the android.* classes, while the java.* classes
|
|
|
|
// are provided by systemModules.
|
|
|
|
java9Classpath classpath
|
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
processorPath classpath
|
|
|
|
errorProneProcessorPath classpath
|
|
|
|
processorClasses []string
|
|
|
|
staticJars android.Paths
|
|
|
|
staticHeaderJars android.Paths
|
|
|
|
staticResourceJars android.Paths
|
|
|
|
aidlIncludeDirs android.Paths
|
|
|
|
srcs android.Paths
|
|
|
|
srcJars android.Paths
|
|
|
|
systemModules *systemModules
|
|
|
|
aidlPreprocess android.OptionalPath
|
|
|
|
kotlinStdlib android.Paths
|
|
|
|
kotlinAnnotations android.Paths
|
2021-09-17 23:11:52 +02:00
|
|
|
kotlinPlugins android.Paths
|
2023-12-19 02:13:16 +01:00
|
|
|
aconfigProtoFiles android.Paths
|
2018-08-16 00:35:38 +02:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
disableTurbine bool
|
2019-05-31 00:51:14 +02:00
|
|
|
}
|
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
|
|
|
|
for _, f := range dep.Srcs() {
|
|
|
|
if f.Ext() != ".jar" {
|
|
|
|
ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
|
|
|
|
ctx.OtherModuleName(dep.(blueprint.Module)))
|
|
|
|
}
|
|
|
|
}
|
2019-10-15 08:20:07 +02:00
|
|
|
}
|
|
|
|
|
2021-03-29 13:11:58 +02:00
|
|
|
func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext android.SdkContext) javaVersion {
|
2021-03-17 23:56:23 +01:00
|
|
|
if javaVersion != "" {
|
|
|
|
return normalizeJavaVersion(ctx, javaVersion)
|
|
|
|
} else if ctx.Device() {
|
2021-04-02 01:45:46 +02:00
|
|
|
return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion(ctx))
|
2023-02-02 18:56:19 +01:00
|
|
|
} else {
|
2023-02-15 18:52:27 +01:00
|
|
|
return JAVA_VERSION_17
|
2020-04-15 04:03:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-22 22:26:06 +01:00
|
|
|
// Java version for stubs generation
|
|
|
|
func getStubsJavaVersion() javaVersion {
|
|
|
|
return JAVA_VERSION_8
|
|
|
|
}
|
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
type javaVersion int
|
2019-10-29 03:23:10 +01:00
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
const (
|
|
|
|
JAVA_VERSION_UNSUPPORTED = 0
|
|
|
|
JAVA_VERSION_6 = 6
|
|
|
|
JAVA_VERSION_7 = 7
|
|
|
|
JAVA_VERSION_8 = 8
|
|
|
|
JAVA_VERSION_9 = 9
|
2021-11-26 18:26:33 +01:00
|
|
|
JAVA_VERSION_11 = 11
|
2022-05-24 13:13:50 +02:00
|
|
|
JAVA_VERSION_17 = 17
|
2021-03-17 23:56:23 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func (v javaVersion) String() string {
|
|
|
|
switch v {
|
|
|
|
case JAVA_VERSION_6:
|
2024-01-15 17:38:46 +01:00
|
|
|
// Java version 1.6 no longer supported, bumping to 1.8
|
|
|
|
return "1.8"
|
2021-03-17 23:56:23 +01:00
|
|
|
case JAVA_VERSION_7:
|
2024-01-15 17:38:46 +01:00
|
|
|
// Java version 1.7 no longer supported, bumping to 1.8
|
|
|
|
return "1.8"
|
2021-03-17 23:56:23 +01:00
|
|
|
case JAVA_VERSION_8:
|
|
|
|
return "1.8"
|
|
|
|
case JAVA_VERSION_9:
|
|
|
|
return "1.9"
|
2021-11-26 18:26:33 +01:00
|
|
|
case JAVA_VERSION_11:
|
|
|
|
return "11"
|
2022-05-24 13:13:50 +02:00
|
|
|
case JAVA_VERSION_17:
|
|
|
|
return "17"
|
2021-03-17 23:56:23 +01:00
|
|
|
default:
|
|
|
|
return "unsupported"
|
|
|
|
}
|
2020-06-24 17:22:38 +02:00
|
|
|
}
|
|
|
|
|
Use the current java version for -jvm-target
This is a partial revert of aosp/541879.
In that cl, the kotlin jvm version was always
set to 1.8 because that's what the kotlin
complier supported at the time, but now
it supports more versions:
$ ./external/kotlinc/bin/kotlinc -jvm-target foo
error: unknown JVM target version: foo
Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17
Bug: 69160377
Bug: 236431222
Test: Treehugger
Change-Id: I273e0b4d1f484013889e17c60bc1b299a3f975a1
2022-06-28 23:41:27 +02:00
|
|
|
func (v javaVersion) StringForKotlinc() string {
|
|
|
|
// $ ./external/kotlinc/bin/kotlinc -jvm-target foo
|
|
|
|
// error: unknown JVM target version: foo
|
2024-01-15 17:38:46 +01:00
|
|
|
// Supported versions: 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17
|
Use the current java version for -jvm-target
This is a partial revert of aosp/541879.
In that cl, the kotlin jvm version was always
set to 1.8 because that's what the kotlin
complier supported at the time, but now
it supports more versions:
$ ./external/kotlinc/bin/kotlinc -jvm-target foo
error: unknown JVM target version: foo
Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17
Bug: 69160377
Bug: 236431222
Test: Treehugger
Change-Id: I273e0b4d1f484013889e17c60bc1b299a3f975a1
2022-06-28 23:41:27 +02:00
|
|
|
switch v {
|
2024-01-15 17:38:46 +01:00
|
|
|
case JAVA_VERSION_6:
|
|
|
|
return "1.8"
|
Use the current java version for -jvm-target
This is a partial revert of aosp/541879.
In that cl, the kotlin jvm version was always
set to 1.8 because that's what the kotlin
complier supported at the time, but now
it supports more versions:
$ ./external/kotlinc/bin/kotlinc -jvm-target foo
error: unknown JVM target version: foo
Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17
Bug: 69160377
Bug: 236431222
Test: Treehugger
Change-Id: I273e0b4d1f484013889e17c60bc1b299a3f975a1
2022-06-28 23:41:27 +02:00
|
|
|
case JAVA_VERSION_7:
|
2024-01-15 17:38:46 +01:00
|
|
|
return "1.8"
|
Use the current java version for -jvm-target
This is a partial revert of aosp/541879.
In that cl, the kotlin jvm version was always
set to 1.8 because that's what the kotlin
complier supported at the time, but now
it supports more versions:
$ ./external/kotlinc/bin/kotlinc -jvm-target foo
error: unknown JVM target version: foo
Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17
Bug: 69160377
Bug: 236431222
Test: Treehugger
Change-Id: I273e0b4d1f484013889e17c60bc1b299a3f975a1
2022-06-28 23:41:27 +02:00
|
|
|
case JAVA_VERSION_9:
|
|
|
|
return "9"
|
|
|
|
default:
|
|
|
|
return v.String()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
// Returns true if javac targeting this version uses system modules instead of a bootclasspath.
|
|
|
|
func (v javaVersion) usesJavaModules() bool {
|
|
|
|
return v >= 9
|
2020-01-08 05:35:43 +01:00
|
|
|
}
|
|
|
|
|
2021-03-17 23:56:23 +01:00
|
|
|
func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) javaVersion {
|
|
|
|
switch javaVersion {
|
|
|
|
case "1.6", "6":
|
2024-01-15 17:38:46 +01:00
|
|
|
// Java version 1.6 no longer supported, bumping to 1.8
|
|
|
|
return JAVA_VERSION_8
|
2021-03-17 23:56:23 +01:00
|
|
|
case "1.7", "7":
|
2024-01-15 17:38:46 +01:00
|
|
|
// Java version 1.7 no longer supported, bumping to 1.8
|
|
|
|
return JAVA_VERSION_8
|
2021-03-17 23:56:23 +01:00
|
|
|
case "1.8", "8":
|
|
|
|
return JAVA_VERSION_8
|
|
|
|
case "1.9", "9":
|
|
|
|
return JAVA_VERSION_9
|
2021-11-26 18:26:33 +01:00
|
|
|
case "11":
|
|
|
|
return JAVA_VERSION_11
|
2022-05-24 13:13:50 +02:00
|
|
|
case "17":
|
2022-06-22 13:53:51 +02:00
|
|
|
return JAVA_VERSION_17
|
2022-05-24 13:13:50 +02:00
|
|
|
case "10", "12", "13", "14", "15", "16":
|
|
|
|
ctx.PropertyErrorf("java_version", "Java language level %s is not supported", javaVersion)
|
2021-03-17 23:56:23 +01:00
|
|
|
return JAVA_VERSION_UNSUPPORTED
|
|
|
|
default:
|
|
|
|
ctx.PropertyErrorf("java_version", "Unrecognized Java language level")
|
|
|
|
return JAVA_VERSION_UNSUPPORTED
|
|
|
|
}
|
2020-01-31 18:10:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-31 02:20:39 +02:00
|
|
|
//
|
|
|
|
// Java libraries (.jar file)
|
|
|
|
//
|
|
|
|
|
2017-07-20 00:53:04 +02:00
|
|
|
type Library struct {
|
2017-06-23 01:51:17 +02:00
|
|
|
Module
|
2019-10-16 01:36:40 +02:00
|
|
|
|
2023-11-22 00:13:56 +01:00
|
|
|
combinedExportedProguardFlagsFile android.Path
|
2022-12-19 22:08:39 +01:00
|
|
|
|
2023-11-15 21:29:33 +01:00
|
|
|
InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.InstallPaths)
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2020-12-15 14:29:02 +01:00
|
|
|
var _ android.ApexModule = (*Library)(nil)
|
|
|
|
|
2021-07-21 15:23:52 +02:00
|
|
|
// Provides access to the list of permitted packages from apex boot jars.
|
2020-05-29 12:24:51 +02:00
|
|
|
type PermittedPackagesForUpdatableBootJars interface {
|
|
|
|
PermittedPackagesForUpdatableBootJars() []string
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ PermittedPackagesForUpdatableBootJars = (*Library)(nil)
|
|
|
|
|
|
|
|
func (j *Library) PermittedPackagesForUpdatableBootJars() []string {
|
|
|
|
return j.properties.Permitted_packages
|
|
|
|
}
|
|
|
|
|
2024-01-24 00:56:29 +01:00
|
|
|
func shouldUncompressDex(ctx android.ModuleContext, libName string, dexpreopter *dexpreopter) bool {
|
2020-01-24 13:19:45 +01:00
|
|
|
// Store uncompressed (and aligned) any dex files from jars in APEXes.
|
2023-12-14 00:54:49 +01:00
|
|
|
if apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider); !apexInfo.IsForPlatform() {
|
2020-01-24 13:19:45 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-02-12 14:12:16 +01:00
|
|
|
// Store uncompressed (and do not strip) dex files from boot class path jars.
|
|
|
|
if inList(ctx.ModuleName(), ctx.Config().BootJars()) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-02-09 19:45:24 +01:00
|
|
|
// Store uncompressed dex files that are preopted on /system or /system_other.
|
|
|
|
if !dexpreopter.dexpreoptDisabled(ctx, libName) {
|
2018-12-21 16:54:16 +01:00
|
|
|
return true
|
|
|
|
}
|
2024-02-09 19:45:24 +01:00
|
|
|
|
2019-02-07 01:37:12 +01:00
|
|
|
if ctx.Config().UncompressPrivAppDex() &&
|
|
|
|
inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-12-21 21:59:54 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-10-11 05:05:20 +02:00
|
|
|
// Sets `dexer.dexProperties.Uncompress_dex` to the proper value.
|
|
|
|
func setUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter, dexer *dexer) {
|
|
|
|
if dexer.dexProperties.Uncompress_dex == nil {
|
|
|
|
// If the value was not force-set by the user, use reasonable default based on the module.
|
2024-01-24 00:56:29 +01:00
|
|
|
dexer.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), dexpreopter))
|
2021-10-11 05:05:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-20 17:47:07 +01:00
|
|
|
// list of java_library modules that set platform_apis: true
|
|
|
|
// this property is a no-op for java_library
|
|
|
|
// TODO (b/215379393): Remove this allowlist
|
|
|
|
var (
|
|
|
|
aospPlatformApiAllowlist = map[string]bool{
|
|
|
|
"adservices-test-scenarios": true,
|
|
|
|
"aidl-cpp-java-test-interface-java": true,
|
|
|
|
"aidl-test-extras-java": true,
|
|
|
|
"aidl-test-interface-java": true,
|
|
|
|
"aidl-test-interface-permission-java": true,
|
|
|
|
"aidl_test_java_client_permission": true,
|
|
|
|
"aidl_test_java_client_sdk1": true,
|
|
|
|
"aidl_test_java_client_sdk29": true,
|
|
|
|
"aidl_test_java_client": true,
|
|
|
|
"aidl_test_java_service_permission": true,
|
|
|
|
"aidl_test_java_service_sdk1": true,
|
|
|
|
"aidl_test_java_service_sdk29": true,
|
|
|
|
"aidl_test_java_service": true,
|
|
|
|
"aidl_test_loggable_interface-java": true,
|
|
|
|
"aidl_test_nonvintf_parcelable-V1-java": true,
|
|
|
|
"aidl_test_nonvintf_parcelable-V2-java": true,
|
|
|
|
"aidl_test_unstable_parcelable-java": true,
|
|
|
|
"aidl_test_vintf_parcelable-V1-java": true,
|
|
|
|
"aidl_test_vintf_parcelable-V2-java": true,
|
|
|
|
"android.aidl.test.trunk-V1-java": true,
|
|
|
|
"android.aidl.test.trunk-V2-java": true,
|
|
|
|
"android.frameworks.location.altitude-V1-java": true,
|
|
|
|
"android.frameworks.location.altitude-V2-java": true,
|
|
|
|
"android.frameworks.stats-V1-java": true,
|
|
|
|
"android.frameworks.stats-V2-java": true,
|
|
|
|
"android.frameworks.stats-V3-java": true,
|
|
|
|
"android.hardware.authsecret-V1-java": true,
|
|
|
|
"android.hardware.authsecret-V2-java": true,
|
|
|
|
"android.hardware.biometrics.common-V1-java": true,
|
|
|
|
"android.hardware.biometrics.common-V2-java": true,
|
|
|
|
"android.hardware.biometrics.common-V3-java": true,
|
|
|
|
"android.hardware.biometrics.common-V4-java": true,
|
|
|
|
"android.hardware.biometrics.face-V1-java": true,
|
|
|
|
"android.hardware.biometrics.face-V2-java": true,
|
|
|
|
"android.hardware.biometrics.face-V3-java": true,
|
|
|
|
"android.hardware.biometrics.face-V4-java": true,
|
|
|
|
"android.hardware.biometrics.fingerprint-V1-java": true,
|
|
|
|
"android.hardware.biometrics.fingerprint-V2-java": true,
|
|
|
|
"android.hardware.biometrics.fingerprint-V3-java": true,
|
|
|
|
"android.hardware.biometrics.fingerprint-V4-java": true,
|
|
|
|
"android.hardware.bluetooth.lmp_event-V1-java": true,
|
|
|
|
"android.hardware.confirmationui-V1-java": true,
|
|
|
|
"android.hardware.confirmationui-V2-java": true,
|
|
|
|
"android.hardware.gatekeeper-V1-java": true,
|
|
|
|
"android.hardware.gatekeeper-V2-java": true,
|
|
|
|
"android.hardware.gnss-V1-java": true,
|
|
|
|
"android.hardware.gnss-V2-java": true,
|
|
|
|
"android.hardware.gnss-V3-java": true,
|
|
|
|
"android.hardware.gnss-V4-java": true,
|
|
|
|
"android.hardware.graphics.common-V1-java": true,
|
|
|
|
"android.hardware.graphics.common-V2-java": true,
|
|
|
|
"android.hardware.graphics.common-V3-java": true,
|
|
|
|
"android.hardware.graphics.common-V4-java": true,
|
|
|
|
"android.hardware.graphics.common-V5-java": true,
|
|
|
|
"android.hardware.identity-V1-java": true,
|
|
|
|
"android.hardware.identity-V2-java": true,
|
|
|
|
"android.hardware.identity-V3-java": true,
|
|
|
|
"android.hardware.identity-V4-java": true,
|
|
|
|
"android.hardware.identity-V5-java": true,
|
|
|
|
"android.hardware.identity-V6-java": true,
|
|
|
|
"android.hardware.keymaster-V1-java": true,
|
|
|
|
"android.hardware.keymaster-V2-java": true,
|
|
|
|
"android.hardware.keymaster-V3-java": true,
|
|
|
|
"android.hardware.keymaster-V4-java": true,
|
|
|
|
"android.hardware.keymaster-V5-java": true,
|
|
|
|
"android.hardware.oemlock-V1-java": true,
|
|
|
|
"android.hardware.oemlock-V2-java": true,
|
|
|
|
"android.hardware.power.stats-V1-java": true,
|
|
|
|
"android.hardware.power.stats-V2-java": true,
|
|
|
|
"android.hardware.power.stats-V3-java": true,
|
|
|
|
"android.hardware.power-V1-java": true,
|
|
|
|
"android.hardware.power-V2-java": true,
|
|
|
|
"android.hardware.power-V3-java": true,
|
|
|
|
"android.hardware.power-V4-java": true,
|
|
|
|
"android.hardware.power-V5-java": true,
|
|
|
|
"android.hardware.rebootescrow-V1-java": true,
|
|
|
|
"android.hardware.rebootescrow-V2-java": true,
|
|
|
|
"android.hardware.security.authgraph-V1-java": true,
|
|
|
|
"android.hardware.security.keymint-V1-java": true,
|
|
|
|
"android.hardware.security.keymint-V2-java": true,
|
|
|
|
"android.hardware.security.keymint-V3-java": true,
|
|
|
|
"android.hardware.security.keymint-V4-java": true,
|
|
|
|
"android.hardware.security.secureclock-V1-java": true,
|
|
|
|
"android.hardware.security.secureclock-V2-java": true,
|
|
|
|
"android.hardware.thermal-V1-java": true,
|
|
|
|
"android.hardware.thermal-V2-java": true,
|
|
|
|
"android.hardware.threadnetwork-V1-java": true,
|
|
|
|
"android.hardware.weaver-V1-java": true,
|
|
|
|
"android.hardware.weaver-V2-java": true,
|
|
|
|
"android.hardware.weaver-V3-java": true,
|
|
|
|
"android.security.attestationmanager-java": true,
|
|
|
|
"android.security.authorization-java": true,
|
|
|
|
"android.security.compat-java": true,
|
|
|
|
"android.security.legacykeystore-java": true,
|
|
|
|
"android.security.maintenance-java": true,
|
|
|
|
"android.security.metrics-java": true,
|
|
|
|
"android.system.keystore2-V1-java": true,
|
|
|
|
"android.system.keystore2-V2-java": true,
|
|
|
|
"android.system.keystore2-V3-java": true,
|
|
|
|
"android.system.keystore2-V4-java": true,
|
|
|
|
"binderReadParcelIface-java": true,
|
|
|
|
"binderRecordReplayTestIface-java": true,
|
|
|
|
"car-experimental-api-static-lib": true,
|
|
|
|
"collector-device-lib-platform": true,
|
|
|
|
"com.android.car.oem": true,
|
|
|
|
"com.google.hardware.pixel.display-V10-java": true,
|
|
|
|
"com.google.hardware.pixel.display-V1-java": true,
|
|
|
|
"com.google.hardware.pixel.display-V2-java": true,
|
|
|
|
"com.google.hardware.pixel.display-V3-java": true,
|
|
|
|
"com.google.hardware.pixel.display-V4-java": true,
|
|
|
|
"com.google.hardware.pixel.display-V5-java": true,
|
|
|
|
"com.google.hardware.pixel.display-V6-java": true,
|
|
|
|
"com.google.hardware.pixel.display-V7-java": true,
|
|
|
|
"com.google.hardware.pixel.display-V8-java": true,
|
|
|
|
"com.google.hardware.pixel.display-V9-java": true,
|
|
|
|
"conscrypt-support": true,
|
|
|
|
"cts-keystore-test-util": true,
|
|
|
|
"cts-keystore-user-auth-helper-library": true,
|
|
|
|
"ctsmediautil": true,
|
|
|
|
"CtsNetTestsNonUpdatableLib": true,
|
|
|
|
"DpmWrapper": true,
|
|
|
|
"flickerlib-apphelpers": true,
|
|
|
|
"flickerlib-helpers": true,
|
|
|
|
"flickerlib-parsers": true,
|
|
|
|
"flickerlib": true,
|
|
|
|
"hardware.google.bluetooth.ccc-V1-java": true,
|
|
|
|
"hardware.google.bluetooth.sar-V1-java": true,
|
|
|
|
"monet": true,
|
|
|
|
"pixel-power-ext-V1-java": true,
|
|
|
|
"pixel-power-ext-V2-java": true,
|
|
|
|
"pixel_stateresidency_provider_aidl_interface-java": true,
|
|
|
|
"pixel-thermal-ext-V1-java": true,
|
|
|
|
"protolog-lib": true,
|
|
|
|
"RkpRegistrationCheck": true,
|
|
|
|
"rotary-service-javastream-protos": true,
|
|
|
|
"service_based_camera_extensions": true,
|
|
|
|
"statsd-helper-test": true,
|
|
|
|
"statsd-helper": true,
|
|
|
|
"test-piece-2-V1-java": true,
|
|
|
|
"test-piece-2-V2-java": true,
|
|
|
|
"test-piece-3-V1-java": true,
|
|
|
|
"test-piece-3-V2-java": true,
|
|
|
|
"test-piece-3-V3-java": true,
|
|
|
|
"test-piece-4-V1-java": true,
|
|
|
|
"test-piece-4-V2-java": true,
|
|
|
|
"test-root-package-V1-java": true,
|
|
|
|
"test-root-package-V2-java": true,
|
|
|
|
"test-root-package-V3-java": true,
|
|
|
|
"test-root-package-V4-java": true,
|
|
|
|
"testServiceIface-java": true,
|
|
|
|
"wm-flicker-common-app-helpers": true,
|
|
|
|
"wm-flicker-common-assertions": true,
|
|
|
|
"wm-shell-flicker-utils": true,
|
|
|
|
"wycheproof-keystore": true,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Union of aosp and internal allowlists
|
|
|
|
PlatformApiAllowlist = map[string]bool{}
|
|
|
|
)
|
2022-07-27 18:27:42 +02:00
|
|
|
|
2024-02-20 17:47:07 +01:00
|
|
|
func init() {
|
|
|
|
for k, v := range aospPlatformApiAllowlist {
|
|
|
|
PlatformApiAllowlist[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2022-07-27 18:27:42 +02:00
|
|
|
j.provideHiddenAPIPropertyInfo(ctx)
|
|
|
|
|
2021-04-02 01:45:46 +02:00
|
|
|
j.sdkVersion = j.SdkVersion(ctx)
|
|
|
|
j.minSdkVersion = j.MinSdkVersion(ctx)
|
2021-11-29 18:25:52 +01:00
|
|
|
j.maxSdkVersion = j.MaxSdkVersion(ctx)
|
2021-04-02 01:45:46 +02:00
|
|
|
|
2024-02-12 23:49:21 +01:00
|
|
|
// SdkLibrary.GenerateAndroidBuildActions(ctx) sets the stubsLinkType to Unknown.
|
|
|
|
// If the stubsLinkType has already been set to Unknown, the stubsLinkType should
|
|
|
|
// not be overridden.
|
|
|
|
if j.stubsLinkType != Unknown {
|
|
|
|
if proptools.Bool(j.properties.Is_stubs_module) {
|
|
|
|
j.stubsLinkType = Stubs
|
|
|
|
} else {
|
|
|
|
j.stubsLinkType = Implementation
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-01 02:13:47 +02:00
|
|
|
j.stem = proptools.StringDefault(j.overridableDeviceProperties.Stem, ctx.ModuleName())
|
|
|
|
|
2023-10-31 18:27:02 +01:00
|
|
|
proguardSpecInfo := j.collectProguardSpecInfo(ctx)
|
2023-12-14 00:19:49 +01:00
|
|
|
android.SetProvider(ctx, ProguardSpecInfoProvider, proguardSpecInfo)
|
2023-11-22 00:13:56 +01:00
|
|
|
exportedProguardFlagsFiles := proguardSpecInfo.ProguardFlagsFiles.ToList()
|
|
|
|
j.extraProguardFlagsFiles = append(j.extraProguardFlagsFiles, exportedProguardFlagsFiles...)
|
|
|
|
|
|
|
|
combinedExportedProguardFlagFile := android.PathForModuleOut(ctx, "export_proguard_flags")
|
|
|
|
writeCombinedProguardFlagsFile(ctx, combinedExportedProguardFlagFile, exportedProguardFlagsFiles)
|
|
|
|
j.combinedExportedProguardFlagsFile = combinedExportedProguardFlagFile
|
2023-10-31 18:27:02 +01:00
|
|
|
|
2023-12-14 00:54:49 +01:00
|
|
|
apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
|
2020-09-16 03:30:11 +02:00
|
|
|
if !apexInfo.IsForPlatform() {
|
|
|
|
j.hideApexVariantFromMake = true
|
|
|
|
}
|
|
|
|
|
2020-04-08 20:09:30 +02:00
|
|
|
j.checkSdkVersions(ctx)
|
2023-08-22 23:28:11 +02:00
|
|
|
j.checkHeadersOnly(ctx)
|
2021-12-01 22:04:46 +01:00
|
|
|
if ctx.Device() {
|
|
|
|
j.dexpreopter.installPath = j.dexpreopter.getInstallPath(
|
2024-01-24 00:56:29 +01:00
|
|
|
ctx, j.Name(), android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar"))
|
2021-12-01 22:04:46 +01:00
|
|
|
j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
|
|
|
|
setUncompressDex(ctx, &j.dexpreopter, &j.dexer)
|
|
|
|
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
|
|
|
|
j.classLoaderContexts = j.usesLibrary.classLoaderContextForUsesLibDeps(ctx)
|
2024-02-13 17:37:43 +01:00
|
|
|
if j.usesLibrary.shouldDisableDexpreopt {
|
|
|
|
j.dexpreopter.disableDexpreopt()
|
|
|
|
}
|
2021-12-01 22:04:46 +01:00
|
|
|
}
|
2023-06-21 07:40:02 +02:00
|
|
|
j.compile(ctx, nil, nil, nil)
|
2015-04-16 23:09:14 +02:00
|
|
|
|
2020-09-16 03:30:11 +02:00
|
|
|
exclusivelyForApex := !apexInfo.IsForPlatform()
|
2019-07-25 15:02:35 +02:00
|
|
|
if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex {
|
2023-11-15 21:29:33 +01:00
|
|
|
var extraInstallDeps android.InstallPaths
|
2019-10-16 01:36:40 +02:00
|
|
|
if j.InstallMixin != nil {
|
|
|
|
extraInstallDeps = j.InstallMixin(ctx, j.outputFile)
|
|
|
|
}
|
2021-11-03 22:08:20 +01:00
|
|
|
hostDexNeeded := Bool(j.deviceProperties.Hostdex) && !ctx.Host()
|
|
|
|
if hostDexNeeded {
|
2021-11-10 23:38:50 +01:00
|
|
|
j.hostdexInstallFile = ctx.InstallFile(
|
|
|
|
android.PathForHostDexInstall(ctx, "framework"),
|
2021-11-03 22:08:20 +01:00
|
|
|
j.Stem()+"-hostdex.jar", j.outputFile)
|
|
|
|
}
|
|
|
|
var installDir android.InstallPath
|
|
|
|
if ctx.InstallInTestcases() {
|
|
|
|
var archDir string
|
|
|
|
if !ctx.Host() {
|
|
|
|
archDir = ctx.DeviceConfig().DeviceArch()
|
|
|
|
}
|
|
|
|
installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir)
|
|
|
|
} else {
|
|
|
|
installDir = android.PathForModuleInstall(ctx, "framework")
|
|
|
|
}
|
|
|
|
j.installFile = ctx.InstallFile(installDir, j.Stem()+".jar", j.outputFile, extraInstallDeps...)
|
2017-09-01 01:45:16 +02:00
|
|
|
}
|
2015-04-16 23:09:14 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 00:53:04 +02:00
|
|
|
func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2017-06-23 01:51:17 +02:00
|
|
|
j.deps(ctx)
|
2021-08-18 17:57:11 +02:00
|
|
|
j.usesLibrary.deps(ctx, false)
|
2017-06-23 01:51:17 +02:00
|
|
|
}
|
|
|
|
|
2019-11-12 20:39:25 +01:00
|
|
|
const (
|
2019-12-03 19:06:47 +01:00
|
|
|
aidlIncludeDir = "aidl"
|
|
|
|
javaDir = "java"
|
|
|
|
jarFileSuffix = ".jar"
|
|
|
|
testConfigSuffix = "-AndroidTest.xml"
|
2019-11-12 20:39:25 +01:00
|
|
|
)
|
|
|
|
|
2019-12-05 12:25:53 +01:00
|
|
|
// path to the jar file of a java library. Relative to <sdk_root>/<api_dir>
|
2022-07-15 15:12:35 +02:00
|
|
|
func sdkSnapshotFilePathForJar(_ android.SdkMemberContext, osPrefix, name string) string {
|
2020-03-02 11:16:35 +01:00
|
|
|
return sdkSnapshotFilePathForMember(osPrefix, name, jarFileSuffix)
|
2019-12-03 19:06:47 +01:00
|
|
|
}
|
|
|
|
|
2020-03-02 11:16:35 +01:00
|
|
|
func sdkSnapshotFilePathForMember(osPrefix, name string, suffix string) string {
|
|
|
|
return filepath.Join(javaDir, osPrefix, name+suffix)
|
2019-11-12 20:39:25 +01:00
|
|
|
}
|
|
|
|
|
2019-11-28 15:31:38 +01:00
|
|
|
type librarySdkMemberType struct {
|
2019-12-13 12:22:16 +01:00
|
|
|
android.SdkMemberTypeBase
|
2020-02-28 15:39:53 +01:00
|
|
|
|
|
|
|
// Function to retrieve the appropriate output jar (implementation or header) from
|
2022-11-21 11:57:30 +01:00
|
|
|
// the library.
|
2020-12-08 18:48:25 +01:00
|
|
|
jarToExportGetter func(ctx android.SdkMemberContext, j *Library) android.Path
|
|
|
|
|
|
|
|
// Function to compute the snapshot relative path to which the named library's
|
|
|
|
// jar should be copied.
|
2022-07-15 15:12:35 +02:00
|
|
|
snapshotPathGetter func(ctx android.SdkMemberContext, osPrefix, name string) string
|
2020-12-08 18:48:25 +01:00
|
|
|
|
|
|
|
// True if only the jar should be copied to the snapshot, false if the jar plus any additional
|
|
|
|
// files like aidl files should also be copied.
|
|
|
|
onlyCopyJarToSnapshot bool
|
2019-11-28 15:31:38 +01:00
|
|
|
}
|
|
|
|
|
2020-12-08 18:48:25 +01:00
|
|
|
const (
|
|
|
|
onlyCopyJarToSnapshot = true
|
|
|
|
copyEverythingToSnapshot = false
|
|
|
|
)
|
|
|
|
|
2021-07-14 11:29:36 +02:00
|
|
|
func (mt *librarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
|
|
|
|
ctx.AddVariationDependencies(nil, dependencyTag, names...)
|
2019-11-28 15:31:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
|
|
|
|
_, ok := module.(*Library)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2020-03-19 17:11:18 +01:00
|
|
|
func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
|
|
|
|
return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_import")
|
2020-03-02 12:33:02 +01:00
|
|
|
}
|
2019-12-05 12:25:53 +01:00
|
|
|
|
2020-03-02 12:33:02 +01:00
|
|
|
func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
|
2020-03-17 22:04:24 +01:00
|
|
|
return &librarySdkMemberProperties{}
|
2020-03-02 12:33:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type librarySdkMemberProperties struct {
|
|
|
|
android.SdkMemberPropertiesBase
|
|
|
|
|
2022-11-21 11:57:30 +01:00
|
|
|
JarToExport android.Path `android:"arch_variant"`
|
2020-03-17 22:04:24 +01:00
|
|
|
AidlIncludeDirs android.Paths
|
2021-07-15 15:14:41 +02:00
|
|
|
|
|
|
|
// The list of permitted packages that need to be passed to the prebuilts as they are used to
|
|
|
|
// create the updatable-bcp-packages.txt file.
|
|
|
|
PermittedPackages []string
|
2022-11-26 14:36:38 +01:00
|
|
|
|
|
|
|
// The value of the min_sdk_version property, translated into a number where possible.
|
|
|
|
MinSdkVersion *string `supported_build_releases:"Tiramisu+"`
|
2023-02-08 17:09:24 +01:00
|
|
|
|
|
|
|
DexPreoptProfileGuided *bool `supported_build_releases:"UpsideDownCake+"`
|
2020-03-02 12:33:02 +01:00
|
|
|
}
|
|
|
|
|
2020-03-19 17:11:18 +01:00
|
|
|
func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
|
2019-11-28 15:31:38 +01:00
|
|
|
j := variant.(*Library)
|
|
|
|
|
2022-11-21 11:57:30 +01:00
|
|
|
p.JarToExport = ctx.MemberType().(*librarySdkMemberType).jarToExportGetter(ctx, j)
|
2020-12-08 18:48:25 +01:00
|
|
|
|
2020-03-17 22:04:24 +01:00
|
|
|
p.AidlIncludeDirs = j.AidlIncludeDirs()
|
2021-07-15 15:14:41 +02:00
|
|
|
|
|
|
|
p.PermittedPackages = j.PermittedPackagesForUpdatableBootJars()
|
2022-11-26 14:36:38 +01:00
|
|
|
|
|
|
|
// If the min_sdk_version was set then add the canonical representation of the API level to the
|
|
|
|
// snapshot.
|
|
|
|
if j.deviceProperties.Min_sdk_version != nil {
|
2023-04-28 21:32:27 +02:00
|
|
|
canonical, err := android.ReplaceFinalizedCodenames(ctx.SdkModuleContext().Config(), j.minSdkVersion.String())
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("%s", err)
|
|
|
|
}
|
2022-11-26 14:36:38 +01:00
|
|
|
p.MinSdkVersion = proptools.StringPtr(canonical)
|
|
|
|
}
|
2023-02-08 17:09:24 +01:00
|
|
|
|
|
|
|
if j.dexpreopter.dexpreoptProperties.Dex_preopt_result.Profile_guided {
|
|
|
|
p.DexPreoptProfileGuided = proptools.BoolPtr(true)
|
|
|
|
}
|
2020-03-02 12:33:02 +01:00
|
|
|
}
|
|
|
|
|
2020-03-19 17:11:18 +01:00
|
|
|
func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
|
2020-03-17 22:04:24 +01:00
|
|
|
builder := ctx.SnapshotBuilder()
|
2020-03-19 17:11:18 +01:00
|
|
|
|
2020-12-08 18:48:25 +01:00
|
|
|
memberType := ctx.MemberType().(*librarySdkMemberType)
|
|
|
|
|
2020-03-17 22:04:24 +01:00
|
|
|
exportedJar := p.JarToExport
|
|
|
|
if exportedJar != nil {
|
2020-12-08 18:48:25 +01:00
|
|
|
// Delegate the creation of the snapshot relative path to the member type.
|
2022-07-15 15:12:35 +02:00
|
|
|
snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(ctx, p.OsPrefix(), ctx.Name())
|
2020-12-08 18:48:25 +01:00
|
|
|
|
|
|
|
// Copy the exported jar to the snapshot.
|
2020-03-02 12:33:02 +01:00
|
|
|
builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
|
2019-11-12 20:39:25 +01:00
|
|
|
|
2020-03-17 22:04:24 +01:00
|
|
|
propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
|
|
|
|
}
|
|
|
|
|
2022-11-26 14:36:38 +01:00
|
|
|
if p.MinSdkVersion != nil {
|
|
|
|
propertySet.AddProperty("min_sdk_version", *p.MinSdkVersion)
|
|
|
|
}
|
|
|
|
|
2021-07-15 15:14:41 +02:00
|
|
|
if len(p.PermittedPackages) > 0 {
|
|
|
|
propertySet.AddProperty("permitted_packages", p.PermittedPackages)
|
|
|
|
}
|
|
|
|
|
2023-02-08 17:09:24 +01:00
|
|
|
dexPreoptSet := propertySet.AddPropertySet("dex_preopt")
|
|
|
|
if p.DexPreoptProfileGuided != nil {
|
|
|
|
dexPreoptSet.AddProperty("profile_guided", proptools.Bool(p.DexPreoptProfileGuided))
|
|
|
|
}
|
|
|
|
|
2020-12-08 18:48:25 +01:00
|
|
|
// Do not copy anything else to the snapshot.
|
|
|
|
if memberType.onlyCopyJarToSnapshot {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-03-17 22:04:24 +01:00
|
|
|
aidlIncludeDirs := p.AidlIncludeDirs
|
|
|
|
if len(aidlIncludeDirs) != 0 {
|
|
|
|
sdkModuleContext := ctx.SdkModuleContext()
|
|
|
|
for _, dir := range aidlIncludeDirs {
|
2020-03-02 12:33:02 +01:00
|
|
|
// TODO(jiyong): copy parcelable declarations only
|
|
|
|
aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil)
|
|
|
|
for _, file := range aidlFiles {
|
|
|
|
builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file))
|
|
|
|
}
|
2019-11-12 20:39:25 +01:00
|
|
|
}
|
|
|
|
|
2020-03-17 22:04:24 +01:00
|
|
|
// TODO(b/151933053) - add aidl include dirs property
|
2020-03-02 12:33:02 +01:00
|
|
|
}
|
2019-11-12 20:39:25 +01:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
|
|
|
|
//
|
|
|
|
// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
|
|
|
|
// compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used
|
|
|
|
// as a `static_libs` dependency of another module.
|
|
|
|
//
|
|
|
|
// Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on
|
|
|
|
// a device.
|
|
|
|
//
|
|
|
|
// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
|
|
|
|
// compiled against the host bootclasspath.
|
2018-06-27 02:59:05 +02:00
|
|
|
func LibraryFactory() android.Module {
|
|
|
|
module := &Library{}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2020-06-16 01:09:53 +02:00
|
|
|
module.addHostAndDeviceProperties()
|
2017-06-24 00:06:31 +02:00
|
|
|
|
2021-06-23 12:39:47 +02:00
|
|
|
module.initModuleAndImport(module)
|
2020-05-15 11:20:31 +02:00
|
|
|
|
2019-07-25 15:02:35 +02:00
|
|
|
android.InitApexModule(module)
|
2019-11-13 02:50:48 +01:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
2018-06-27 02:59:05 +02:00
|
|
|
return module
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_library_static is an obsolete alias for java_library.
|
|
|
|
func LibraryStaticFactory() android.Module {
|
|
|
|
return LibraryFactory()
|
|
|
|
}
|
|
|
|
|
|
|
|
// java_library_host builds and links sources into a `.jar` file for the host.
|
|
|
|
//
|
|
|
|
// A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were
|
|
|
|
// compiled against the host bootclasspath.
|
2017-07-20 00:53:04 +02:00
|
|
|
func LibraryHostFactory() android.Module {
|
|
|
|
module := &Library{}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2020-06-16 01:09:53 +02:00
|
|
|
module.addHostProperties()
|
2017-06-24 00:06:31 +02:00
|
|
|
|
2018-06-27 02:59:05 +02:00
|
|
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
|
2019-07-25 15:02:35 +02:00
|
|
|
android.InitApexModule(module)
|
2019-11-13 02:50:48 +01:00
|
|
|
InitJavaModule(module, android.HostSupported)
|
2017-06-24 00:06:31 +02:00
|
|
|
return module
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2018-04-10 03:40:24 +02:00
|
|
|
//
|
2018-08-15 01:42:33 +02:00
|
|
|
// Java Tests
|
2018-04-10 03:40:24 +02:00
|
|
|
//
|
|
|
|
|
2020-08-15 21:24:26 +02:00
|
|
|
// Test option struct.
|
|
|
|
type TestOptions struct {
|
2022-08-12 12:49:20 +02:00
|
|
|
android.CommonTestOptions
|
|
|
|
|
2020-08-15 21:24:26 +02:00
|
|
|
// a list of extra test configuration files that should be installed with the module.
|
|
|
|
Extra_test_configs []string `android:"path,arch_variant"`
|
2022-12-08 03:18:37 +01:00
|
|
|
|
|
|
|
// Extra <option> tags to add to the auto generated test xml file. The "key"
|
|
|
|
// is optional in each of these.
|
|
|
|
Tradefed_options []tradefed.Option
|
2023-05-26 06:21:44 +02:00
|
|
|
|
|
|
|
// Extra <option> tags to add to the auto generated test xml file under the test runner, e.g., AndroidJunitTest.
|
|
|
|
// The "key" is optional in each of these.
|
|
|
|
Test_runner_options []tradefed.Option
|
2020-08-15 21:24:26 +02:00
|
|
|
}
|
|
|
|
|
2018-04-10 03:40:24 +02:00
|
|
|
type testProperties struct {
|
|
|
|
// list of compatibility suites (for example "cts", "vts") that the module should be
|
|
|
|
// installed into.
|
|
|
|
Test_suites []string `android:"arch_variant"`
|
2018-08-03 00:00:46 +02:00
|
|
|
|
|
|
|
// the name of the test configuration (for example "AndroidTest.xml") that should be
|
|
|
|
// installed with the module.
|
2019-03-05 07:35:41 +01:00
|
|
|
Test_config *string `android:"path,arch_variant"`
|
2018-08-11 01:06:24 +02:00
|
|
|
|
2018-09-19 11:21:28 +02:00
|
|
|
// the name of the test configuration template (for example "AndroidTestTemplate.xml") that
|
|
|
|
// should be installed with the module.
|
2019-03-05 07:35:41 +01:00
|
|
|
Test_config_template *string `android:"path,arch_variant"`
|
2018-09-19 11:21:28 +02:00
|
|
|
|
2018-08-11 01:06:24 +02:00
|
|
|
// list of files or filegroup modules that provide data that should be installed alongside
|
|
|
|
// the test
|
2021-02-15 22:52:39 +01:00
|
|
|
Data []string `android:"path"`
|
2019-09-26 20:41:36 +02:00
|
|
|
|
|
|
|
// Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
|
|
|
|
// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
|
|
|
|
// explicitly.
|
|
|
|
Auto_gen_config *bool
|
2020-04-30 08:57:06 +02:00
|
|
|
|
|
|
|
// Add parameterized mainline modules to auto generated test config. The options will be
|
|
|
|
// handled by TradeFed to do downloading and installing the specified modules on the device.
|
|
|
|
Test_mainline_modules []string
|
2020-08-15 21:24:26 +02:00
|
|
|
|
|
|
|
// Test options.
|
|
|
|
Test_options TestOptions
|
2021-01-26 20:01:43 +01:00
|
|
|
|
|
|
|
// Names of modules containing JNI libraries that should be installed alongside the test.
|
|
|
|
Jni_libs []string
|
2021-09-25 00:47:17 +02:00
|
|
|
|
|
|
|
// Install the test into a folder named for the module in all test suites.
|
|
|
|
Per_testcase_directory *bool
|
2018-04-10 03:40:24 +02:00
|
|
|
}
|
|
|
|
|
2020-06-13 01:38:45 +02:00
|
|
|
type hostTestProperties struct {
|
|
|
|
// list of native binary modules that should be installed alongside the test
|
|
|
|
Data_native_bins []string `android:"arch_variant"`
|
2022-01-20 22:10:28 +01:00
|
|
|
|
|
|
|
// list of device binary modules that should be installed alongside the test
|
2022-06-01 17:45:02 +02:00
|
|
|
// This property only adds the first variant of the dependency
|
|
|
|
Data_device_bins_first []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of device binary modules that should be installed alongside the test
|
|
|
|
// This property adds 64bit AND 32bit variants of the dependency
|
|
|
|
Data_device_bins_both []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of device binary modules that should be installed alongside the test
|
|
|
|
// This property only adds 64bit variants of the dependency
|
|
|
|
Data_device_bins_64 []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of device binary modules that should be installed alongside the test
|
|
|
|
// This property adds 32bit variants of the dependency if available, or else
|
|
|
|
// defaults to the 64bit variant
|
|
|
|
Data_device_bins_prefer32 []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of device binary modules that should be installed alongside the test
|
|
|
|
// This property only adds 32bit variants of the dependency
|
|
|
|
Data_device_bins_32 []string `android:"arch_variant"`
|
2020-06-13 01:38:45 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 13:45:53 +01:00
|
|
|
type testHelperLibraryProperties struct {
|
|
|
|
// list of compatibility suites (for example "cts", "vts") that the module should be
|
|
|
|
// installed into.
|
|
|
|
Test_suites []string `android:"arch_variant"`
|
2021-09-25 00:47:17 +02:00
|
|
|
|
|
|
|
// Install the test into a folder named for the module in all test suites.
|
|
|
|
Per_testcase_directory *bool
|
2019-03-20 13:45:53 +01:00
|
|
|
}
|
|
|
|
|
2019-12-03 19:06:47 +01:00
|
|
|
type prebuiltTestProperties struct {
|
|
|
|
// list of compatibility suites (for example "cts", "vts") that the module should be
|
|
|
|
// installed into.
|
|
|
|
Test_suites []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// the name of the test configuration (for example "AndroidTest.xml") that should be
|
|
|
|
// installed with the module.
|
|
|
|
Test_config *string `android:"path,arch_variant"`
|
|
|
|
}
|
|
|
|
|
2018-04-10 03:40:24 +02:00
|
|
|
type Test struct {
|
|
|
|
Library
|
|
|
|
|
|
|
|
testProperties testProperties
|
2018-08-08 01:49:25 +02:00
|
|
|
|
2020-08-15 21:24:26 +02:00
|
|
|
testConfig android.Path
|
|
|
|
extraTestConfigs android.Paths
|
|
|
|
data android.Paths
|
2018-08-08 01:49:25 +02:00
|
|
|
}
|
|
|
|
|
2020-06-13 01:38:45 +02:00
|
|
|
type TestHost struct {
|
|
|
|
Test
|
|
|
|
|
|
|
|
testHostProperties hostTestProperties
|
|
|
|
}
|
|
|
|
|
2019-03-20 13:45:53 +01:00
|
|
|
type TestHelperLibrary struct {
|
|
|
|
Library
|
|
|
|
|
|
|
|
testHelperLibraryProperties testHelperLibraryProperties
|
|
|
|
}
|
|
|
|
|
2019-12-03 19:06:47 +01:00
|
|
|
type JavaTestImport struct {
|
|
|
|
Import
|
|
|
|
|
|
|
|
prebuiltTestProperties prebuiltTestProperties
|
|
|
|
|
|
|
|
testConfig android.Path
|
2020-08-06 00:40:41 +02:00
|
|
|
dexJarFile android.Path
|
2019-12-03 19:06:47 +01:00
|
|
|
}
|
|
|
|
|
2021-11-03 22:09:41 +01:00
|
|
|
func (j *Test) InstallInTestcases() bool {
|
|
|
|
// Host java tests install into $(HOST_OUT_JAVA_LIBRARIES), and then are copied into
|
|
|
|
// testcases by base_rules.mk.
|
|
|
|
return !j.Host()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *TestHelperLibrary) InstallInTestcases() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *JavaTestImport) InstallInTestcases() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-01-20 00:41:48 +01:00
|
|
|
func (j *TestHost) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool {
|
2023-10-05 20:40:06 +02:00
|
|
|
return ctx.DeviceConfig().NativeCoverageEnabled()
|
|
|
|
}
|
|
|
|
|
2022-06-01 17:45:02 +02:00
|
|
|
func (j *TestHost) addDataDeviceBinsDeps(ctx android.BottomUpMutatorContext) {
|
|
|
|
if len(j.testHostProperties.Data_device_bins_first) > 0 {
|
|
|
|
deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations()
|
|
|
|
ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_first...)
|
|
|
|
}
|
|
|
|
|
|
|
|
var maybeAndroid32Target *android.Target
|
|
|
|
var maybeAndroid64Target *android.Target
|
|
|
|
android32TargetList := android.FirstTarget(ctx.Config().Targets[android.Android], "lib32")
|
|
|
|
android64TargetList := android.FirstTarget(ctx.Config().Targets[android.Android], "lib64")
|
|
|
|
if len(android32TargetList) > 0 {
|
|
|
|
maybeAndroid32Target = &android32TargetList[0]
|
|
|
|
}
|
|
|
|
if len(android64TargetList) > 0 {
|
|
|
|
maybeAndroid64Target = &android64TargetList[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(j.testHostProperties.Data_device_bins_both) > 0 {
|
|
|
|
if maybeAndroid32Target == nil && maybeAndroid64Target == nil {
|
|
|
|
ctx.PropertyErrorf("data_device_bins_both", "no device targets available. Targets: %q", ctx.Config().Targets)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if maybeAndroid32Target != nil {
|
|
|
|
ctx.AddFarVariationDependencies(
|
|
|
|
maybeAndroid32Target.Variations(),
|
|
|
|
dataDeviceBinsTag,
|
|
|
|
j.testHostProperties.Data_device_bins_both...,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
if maybeAndroid64Target != nil {
|
|
|
|
ctx.AddFarVariationDependencies(
|
|
|
|
maybeAndroid64Target.Variations(),
|
|
|
|
dataDeviceBinsTag,
|
|
|
|
j.testHostProperties.Data_device_bins_both...,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(j.testHostProperties.Data_device_bins_prefer32) > 0 {
|
|
|
|
if maybeAndroid32Target != nil {
|
|
|
|
ctx.AddFarVariationDependencies(
|
|
|
|
maybeAndroid32Target.Variations(),
|
|
|
|
dataDeviceBinsTag,
|
|
|
|
j.testHostProperties.Data_device_bins_prefer32...,
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
if maybeAndroid64Target == nil {
|
|
|
|
ctx.PropertyErrorf("data_device_bins_prefer32", "no device targets available. Targets: %q", ctx.Config().Targets)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.AddFarVariationDependencies(
|
|
|
|
maybeAndroid64Target.Variations(),
|
|
|
|
dataDeviceBinsTag,
|
|
|
|
j.testHostProperties.Data_device_bins_prefer32...,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(j.testHostProperties.Data_device_bins_32) > 0 {
|
|
|
|
if maybeAndroid32Target == nil {
|
|
|
|
ctx.PropertyErrorf("data_device_bins_32", "cannot find 32bit device target. Targets: %q", ctx.Config().Targets)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
deviceVariations := maybeAndroid32Target.Variations()
|
|
|
|
ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_32...)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(j.testHostProperties.Data_device_bins_64) > 0 {
|
|
|
|
if maybeAndroid64Target == nil {
|
|
|
|
ctx.PropertyErrorf("data_device_bins_64", "cannot find 64bit device target. Targets: %q", ctx.Config().Targets)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
deviceVariations := maybeAndroid64Target.Variations()
|
|
|
|
ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_64...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-13 01:38:45 +02:00
|
|
|
func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
if len(j.testHostProperties.Data_native_bins) > 0 {
|
|
|
|
for _, target := range ctx.MultiTargets() {
|
|
|
|
ctx.AddVariationDependencies(target.Variations(), dataNativeBinsTag, j.testHostProperties.Data_native_bins...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-26 20:01:43 +01:00
|
|
|
if len(j.testProperties.Jni_libs) > 0 {
|
|
|
|
for _, target := range ctx.MultiTargets() {
|
|
|
|
sharedLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
|
|
|
|
ctx.AddFarVariationDependencies(sharedLibVariations, jniLibTag, j.testProperties.Jni_libs...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-01 17:45:02 +02:00
|
|
|
j.addDataDeviceBinsDeps(ctx)
|
2020-06-13 01:38:45 +02:00
|
|
|
j.deps(ctx)
|
|
|
|
}
|
|
|
|
|
2021-03-04 22:47:56 +01:00
|
|
|
func (j *TestHost) AddExtraResource(p android.Path) {
|
|
|
|
j.extraResources = append(j.extraResources, p)
|
|
|
|
}
|
|
|
|
|
2022-06-01 17:45:02 +02:00
|
|
|
func (j *TestHost) dataDeviceBins() []string {
|
|
|
|
ret := make([]string, 0,
|
|
|
|
len(j.testHostProperties.Data_device_bins_first)+
|
|
|
|
len(j.testHostProperties.Data_device_bins_both)+
|
|
|
|
len(j.testHostProperties.Data_device_bins_prefer32)+
|
|
|
|
len(j.testHostProperties.Data_device_bins_32)+
|
|
|
|
len(j.testHostProperties.Data_device_bins_64),
|
|
|
|
)
|
|
|
|
|
|
|
|
ret = append(ret, j.testHostProperties.Data_device_bins_first...)
|
|
|
|
ret = append(ret, j.testHostProperties.Data_device_bins_both...)
|
|
|
|
ret = append(ret, j.testHostProperties.Data_device_bins_prefer32...)
|
|
|
|
ret = append(ret, j.testHostProperties.Data_device_bins_32...)
|
|
|
|
ret = append(ret, j.testHostProperties.Data_device_bins_64...)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2022-01-20 22:10:28 +01:00
|
|
|
func (j *TestHost) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
var configs []tradefed.Config
|
2022-06-01 17:45:02 +02:00
|
|
|
dataDeviceBins := j.dataDeviceBins()
|
|
|
|
if len(dataDeviceBins) > 0 {
|
2022-01-20 22:10:28 +01:00
|
|
|
// add Tradefed configuration to push device bins to device for testing
|
|
|
|
remoteDir := filepath.Join("/data/local/tests/unrestricted/", j.Name())
|
|
|
|
options := []tradefed.Option{{Name: "cleanup", Value: "true"}}
|
2022-06-01 17:45:02 +02:00
|
|
|
for _, bin := range dataDeviceBins {
|
2022-01-20 22:10:28 +01:00
|
|
|
fullPath := filepath.Join(remoteDir, bin)
|
|
|
|
options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: fullPath})
|
|
|
|
}
|
2022-06-01 17:45:02 +02:00
|
|
|
configs = append(configs, tradefed.Object{
|
|
|
|
Type: "target_preparer",
|
|
|
|
Class: "com.android.tradefed.targetprep.PushFilePreparer",
|
|
|
|
Options: options,
|
|
|
|
})
|
2022-01-20 22:10:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
j.Test.generateAndroidBuildActionsWithConfig(ctx, configs)
|
2023-12-14 00:19:49 +01:00
|
|
|
android.SetProvider(ctx, testing.TestModuleProviderKey, testing.TestModuleProviderData{})
|
2022-01-20 22:10:28 +01:00
|
|
|
}
|
|
|
|
|
2018-08-08 01:49:25 +02:00
|
|
|
func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2022-01-20 22:10:28 +01:00
|
|
|
j.generateAndroidBuildActionsWithConfig(ctx, nil)
|
2023-12-14 00:19:49 +01:00
|
|
|
android.SetProvider(ctx, testing.TestModuleProviderKey, testing.TestModuleProviderData{})
|
2022-01-20 22:10:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (j *Test) generateAndroidBuildActionsWithConfig(ctx android.ModuleContext, configs []tradefed.Config) {
|
2021-03-05 19:08:36 +01:00
|
|
|
if j.testProperties.Test_options.Unit_test == nil && ctx.Host() {
|
|
|
|
// TODO(b/): Clean temporary heuristic to avoid unexpected onboarding.
|
2021-03-15 21:07:53 +01:00
|
|
|
defaultUnitTest := !inList("tradefed", j.properties.Libs) && !inList("cts", j.testProperties.Test_suites)
|
2021-03-05 19:08:36 +01:00
|
|
|
j.testProperties.Test_options.Unit_test = proptools.BoolPtr(defaultUnitTest)
|
|
|
|
}
|
2022-12-08 03:18:37 +01:00
|
|
|
j.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{
|
|
|
|
TestConfigProp: j.testProperties.Test_config,
|
|
|
|
TestConfigTemplateProp: j.testProperties.Test_config_template,
|
|
|
|
TestSuites: j.testProperties.Test_suites,
|
|
|
|
Config: configs,
|
|
|
|
OptionsForAutogenerated: j.testProperties.Test_options.Tradefed_options,
|
2023-05-26 06:21:44 +02:00
|
|
|
TestRunnerOptions: j.testProperties.Test_options.Test_runner_options,
|
2022-12-08 03:18:37 +01:00
|
|
|
AutoGenConfig: j.testProperties.Auto_gen_config,
|
|
|
|
UnitTest: j.testProperties.Test_options.Unit_test,
|
|
|
|
DeviceTemplate: "${JavaTestConfigTemplate}",
|
|
|
|
HostTemplate: "${JavaHostTestConfigTemplate}",
|
|
|
|
HostUnitTestTemplate: "${JavaHostUnitTestConfigTemplate}",
|
|
|
|
})
|
2020-06-13 01:38:45 +02:00
|
|
|
|
2019-03-06 07:25:09 +01:00
|
|
|
j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data)
|
2018-08-08 01:49:25 +02:00
|
|
|
|
2020-08-15 21:24:26 +02:00
|
|
|
j.extraTestConfigs = android.PathsForModuleSrc(ctx, j.testProperties.Test_options.Extra_test_configs)
|
|
|
|
|
2020-06-13 01:38:45 +02:00
|
|
|
ctx.VisitDirectDepsWithTag(dataNativeBinsTag, func(dep android.Module) {
|
|
|
|
j.data = append(j.data, android.OutputFileForModule(ctx, dep, ""))
|
|
|
|
})
|
|
|
|
|
2022-01-20 22:10:28 +01:00
|
|
|
ctx.VisitDirectDepsWithTag(dataDeviceBinsTag, func(dep android.Module) {
|
|
|
|
j.data = append(j.data, android.OutputFileForModule(ctx, dep, ""))
|
|
|
|
})
|
|
|
|
|
2021-01-26 20:01:43 +01:00
|
|
|
ctx.VisitDirectDepsWithTag(jniLibTag, func(dep android.Module) {
|
2023-12-13 22:47:44 +01:00
|
|
|
sharedLibInfo, _ := android.OtherModuleProvider(ctx, dep, cc.SharedLibraryInfoProvider)
|
2021-01-26 20:01:43 +01:00
|
|
|
if sharedLibInfo.SharedLibrary != nil {
|
|
|
|
// Copy to an intermediate output directory to append "lib[64]" to the path,
|
|
|
|
// so that it's compatible with the default rpath values.
|
|
|
|
var relPath string
|
|
|
|
if sharedLibInfo.Target.Arch.ArchType.Multilib == "lib64" {
|
|
|
|
relPath = filepath.Join("lib64", sharedLibInfo.SharedLibrary.Base())
|
|
|
|
} else {
|
|
|
|
relPath = filepath.Join("lib", sharedLibInfo.SharedLibrary.Base())
|
|
|
|
}
|
|
|
|
relocatedLib := android.PathForModuleOut(ctx, "relocated").Join(ctx, relPath)
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Cp,
|
|
|
|
Input: sharedLibInfo.SharedLibrary,
|
|
|
|
Output: relocatedLib,
|
|
|
|
})
|
|
|
|
j.data = append(j.data, relocatedLib)
|
|
|
|
} else {
|
|
|
|
ctx.PropertyErrorf("jni_libs", "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-08-08 01:49:25 +02:00
|
|
|
j.Library.GenerateAndroidBuildActions(ctx)
|
2018-04-10 03:40:24 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 13:45:53 +01:00
|
|
|
func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
j.Library.GenerateAndroidBuildActions(ctx)
|
|
|
|
}
|
|
|
|
|
2019-12-03 19:06:47 +01:00
|
|
|
func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2022-12-08 03:18:37 +01:00
|
|
|
j.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{
|
|
|
|
TestConfigProp: j.prebuiltTestProperties.Test_config,
|
|
|
|
TestSuites: j.prebuiltTestProperties.Test_suites,
|
|
|
|
DeviceTemplate: "${JavaTestConfigTemplate}",
|
|
|
|
HostTemplate: "${JavaHostTestConfigTemplate}",
|
|
|
|
HostUnitTestTemplate: "${JavaHostUnitTestConfigTemplate}",
|
|
|
|
})
|
2019-12-03 19:06:47 +01:00
|
|
|
|
|
|
|
j.Import.GenerateAndroidBuildActions(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
type testSdkMemberType struct {
|
|
|
|
android.SdkMemberTypeBase
|
|
|
|
}
|
|
|
|
|
2021-07-14 11:29:36 +02:00
|
|
|
func (mt *testSdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
|
|
|
|
ctx.AddVariationDependencies(nil, dependencyTag, names...)
|
2019-12-03 19:06:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mt *testSdkMemberType) IsInstance(module android.Module) bool {
|
|
|
|
_, ok := module.(*Test)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2020-03-19 17:11:18 +01:00
|
|
|
func (mt *testSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
|
|
|
|
return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_test_import")
|
2020-03-02 12:33:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
|
|
|
|
return &testSdkMemberProperties{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type testSdkMemberProperties struct {
|
|
|
|
android.SdkMemberPropertiesBase
|
2019-12-03 19:06:47 +01:00
|
|
|
|
2020-03-17 22:04:24 +01:00
|
|
|
JarToExport android.Path
|
|
|
|
TestConfig android.Path
|
2020-03-02 12:33:02 +01:00
|
|
|
}
|
|
|
|
|
2020-03-19 17:11:18 +01:00
|
|
|
func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
|
2020-03-02 12:33:02 +01:00
|
|
|
test := variant.(*Test)
|
|
|
|
|
|
|
|
implementationJars := test.ImplementationJars()
|
2019-12-03 19:06:47 +01:00
|
|
|
if len(implementationJars) != 1 {
|
2020-03-02 12:33:02 +01:00
|
|
|
panic(fmt.Errorf("there must be only one implementation jar from %q", test.Name()))
|
2019-12-03 19:06:47 +01:00
|
|
|
}
|
|
|
|
|
2020-03-17 22:04:24 +01:00
|
|
|
p.JarToExport = implementationJars[0]
|
|
|
|
p.TestConfig = test.testConfig
|
2020-03-02 12:33:02 +01:00
|
|
|
}
|
|
|
|
|
2020-03-19 17:11:18 +01:00
|
|
|
func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
|
2020-03-17 22:04:24 +01:00
|
|
|
builder := ctx.SnapshotBuilder()
|
2019-12-03 19:06:47 +01:00
|
|
|
|
2020-03-17 22:04:24 +01:00
|
|
|
exportedJar := p.JarToExport
|
|
|
|
if exportedJar != nil {
|
2022-07-15 15:12:35 +02:00
|
|
|
snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(ctx, p.OsPrefix(), ctx.Name())
|
2020-03-17 22:04:24 +01:00
|
|
|
builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
|
2019-12-03 19:06:47 +01:00
|
|
|
|
2020-03-02 12:33:02 +01:00
|
|
|
propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
|
2020-03-17 22:04:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
testConfig := p.TestConfig
|
|
|
|
if testConfig != nil {
|
|
|
|
snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(p.OsPrefix(), ctx.Name(), testConfigSuffix)
|
|
|
|
builder.CopyToSnapshot(testConfig, snapshotRelativeTestConfigPath)
|
2020-03-02 12:33:02 +01:00
|
|
|
propertySet.AddProperty("test_config", snapshotRelativeTestConfigPath)
|
|
|
|
}
|
2019-12-03 19:06:47 +01:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
|
|
|
|
// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
|
|
|
|
//
|
|
|
|
// By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were
|
|
|
|
// compiled against the device bootclasspath.
|
|
|
|
//
|
|
|
|
// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
|
|
|
|
// compiled against the host bootclasspath.
|
2018-04-10 03:40:24 +02:00
|
|
|
func TestFactory() android.Module {
|
|
|
|
module := &Test{}
|
|
|
|
|
2020-06-16 01:09:53 +02:00
|
|
|
module.addHostAndDeviceProperties()
|
|
|
|
module.AddProperties(&module.testProperties)
|
2018-04-10 03:40:24 +02:00
|
|
|
|
2018-06-27 02:59:05 +02:00
|
|
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
2019-01-06 07:30:13 +01:00
|
|
|
module.Module.dexpreopter.isTest = true
|
2022-08-11 20:59:04 +02:00
|
|
|
module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
|
2018-06-27 02:59:05 +02:00
|
|
|
|
2018-04-10 03:40:24 +02:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2019-03-20 13:45:53 +01:00
|
|
|
// java_test_helper_library creates a java library and makes sure that it is added to the appropriate test suite.
|
|
|
|
func TestHelperLibraryFactory() android.Module {
|
|
|
|
module := &TestHelperLibrary{}
|
|
|
|
|
2020-06-16 01:09:53 +02:00
|
|
|
module.addHostAndDeviceProperties()
|
|
|
|
module.AddProperties(&module.testHelperLibraryProperties)
|
2019-03-20 13:45:53 +01:00
|
|
|
|
2019-04-24 22:19:28 +02:00
|
|
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
module.Module.dexpreopter.isTest = true
|
2022-08-11 20:59:04 +02:00
|
|
|
module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
|
2019-04-24 22:19:28 +02:00
|
|
|
|
2019-03-20 13:45:53 +01:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2019-12-03 19:06:47 +01:00
|
|
|
// java_test_import imports one or more `.jar` files into the build graph as if they were built by a java_test module
|
|
|
|
// and makes sure that it is added to the appropriate test suite.
|
|
|
|
//
|
|
|
|
// By default, a java_test_import has a single variant that expects a `.jar` file containing `.class` files that were
|
|
|
|
// compiled against an Android classpath.
|
|
|
|
//
|
|
|
|
// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
|
|
|
|
// for host modules.
|
|
|
|
func JavaTestImportFactory() android.Module {
|
|
|
|
module := &JavaTestImport{}
|
|
|
|
|
|
|
|
module.AddProperties(
|
|
|
|
&module.Import.properties,
|
|
|
|
&module.prebuiltTestProperties)
|
|
|
|
|
|
|
|
module.Import.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
|
|
|
|
android.InitPrebuiltModule(module, &module.properties.Jars)
|
|
|
|
android.InitApexModule(module)
|
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to
|
|
|
|
// allow running the test with `atest` or a `TEST_MAPPING` file.
|
|
|
|
//
|
|
|
|
// A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
|
|
|
|
// compiled against the host bootclasspath.
|
2018-04-10 03:40:24 +02:00
|
|
|
func TestHostFactory() android.Module {
|
2020-06-13 01:38:45 +02:00
|
|
|
module := &TestHost{}
|
2018-04-10 03:40:24 +02:00
|
|
|
|
2020-06-16 01:09:53 +02:00
|
|
|
module.addHostProperties()
|
|
|
|
module.AddProperties(&module.testProperties)
|
2020-06-13 01:38:45 +02:00
|
|
|
module.AddProperties(&module.testHostProperties)
|
2018-04-10 03:40:24 +02:00
|
|
|
|
2021-03-04 22:47:56 +01:00
|
|
|
InitTestHost(
|
|
|
|
module,
|
|
|
|
proptools.BoolPtr(true),
|
|
|
|
nil,
|
|
|
|
nil)
|
2018-06-27 02:59:05 +02:00
|
|
|
|
2020-06-13 01:38:45 +02:00
|
|
|
InitJavaModuleMultiTargets(module, android.HostSupported)
|
2021-03-05 19:08:36 +01:00
|
|
|
|
2018-04-10 03:40:24 +02:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2021-03-04 22:47:56 +01:00
|
|
|
func InitTestHost(th *TestHost, installable *bool, testSuites []string, autoGenConfig *bool) {
|
|
|
|
th.properties.Installable = installable
|
|
|
|
th.testProperties.Auto_gen_config = autoGenConfig
|
|
|
|
th.testProperties.Test_suites = testSuites
|
|
|
|
}
|
|
|
|
|
2015-03-31 02:20:39 +02:00
|
|
|
//
|
|
|
|
// Java Binaries (.jar file plus wrapper script)
|
|
|
|
//
|
|
|
|
|
2017-07-20 00:53:04 +02:00
|
|
|
type binaryProperties struct {
|
2015-05-11 22:39:40 +02:00
|
|
|
// installable script to execute the resulting jar
|
2021-09-21 08:11:24 +02:00
|
|
|
Wrapper *string `android:"path,arch_variant"`
|
2018-10-18 00:10:48 +02:00
|
|
|
|
|
|
|
// Name of the class containing main to be inserted into the manifest as Main-Class.
|
|
|
|
Main_class *string
|
2020-10-10 04:00:54 +02:00
|
|
|
|
|
|
|
// Names of modules containing JNI libraries that should be installed alongside the host
|
|
|
|
// variant of the binary.
|
2021-09-21 08:11:24 +02:00
|
|
|
Jni_libs []string `android:"arch_variant"`
|
2015-05-11 22:39:40 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 00:53:04 +02:00
|
|
|
type Binary struct {
|
|
|
|
Library
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2017-07-20 00:53:04 +02:00
|
|
|
binaryProperties binaryProperties
|
2017-08-11 02:09:43 +02:00
|
|
|
|
2017-12-05 22:42:45 +01:00
|
|
|
isWrapperVariant bool
|
|
|
|
|
2017-12-09 04:12:36 +01:00
|
|
|
wrapperFile android.Path
|
2019-10-02 07:05:35 +02:00
|
|
|
binaryFile android.InstallPath
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2017-10-26 18:46:21 +02:00
|
|
|
func (j *Binary) HostToolPath() android.OptionalPath {
|
|
|
|
return android.OptionalPathForPath(j.binaryFile)
|
|
|
|
}
|
|
|
|
|
2017-07-20 00:53:04 +02:00
|
|
|
func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2023-07-01 02:13:47 +02:00
|
|
|
j.stem = proptools.StringDefault(j.overridableDeviceProperties.Stem, ctx.ModuleName())
|
|
|
|
|
2017-12-05 22:42:45 +01:00
|
|
|
if ctx.Arch().ArchType == android.Common {
|
|
|
|
// Compile the jar
|
2018-10-18 00:10:48 +02:00
|
|
|
if j.binaryProperties.Main_class != nil {
|
|
|
|
if j.properties.Manifest != nil {
|
|
|
|
ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set")
|
|
|
|
}
|
|
|
|
manifestFile := android.PathForModuleOut(ctx, "manifest.txt")
|
|
|
|
GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class))
|
|
|
|
j.overrideManifest = android.OptionalPathForPath(manifestFile)
|
|
|
|
}
|
|
|
|
|
2017-12-05 22:42:45 +01:00
|
|
|
j.Library.GenerateAndroidBuildActions(ctx)
|
2017-11-03 22:53:31 +01:00
|
|
|
} else {
|
2017-12-05 22:42:45 +01:00
|
|
|
// Handle the binary wrapper
|
|
|
|
j.isWrapperVariant = true
|
|
|
|
|
2017-12-12 01:29:02 +01:00
|
|
|
if j.binaryProperties.Wrapper != nil {
|
2019-03-06 07:25:09 +01:00
|
|
|
j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper)
|
2017-12-05 22:42:45 +01:00
|
|
|
} else {
|
2021-09-21 08:11:24 +02:00
|
|
|
if ctx.Windows() {
|
|
|
|
ctx.PropertyErrorf("wrapper", "wrapper is required for Windows")
|
|
|
|
}
|
|
|
|
|
2022-10-10 22:45:06 +02:00
|
|
|
if ctx.Device() {
|
|
|
|
// device binary should have a main_class property if it does not
|
|
|
|
// have a specific wrapper, so that a default wrapper can
|
|
|
|
// be generated for it.
|
|
|
|
if j.binaryProperties.Main_class == nil {
|
|
|
|
ctx.PropertyErrorf("main_class", "main_class property "+
|
|
|
|
"is required for device binary if no default wrapper is assigned")
|
|
|
|
} else {
|
|
|
|
wrapper := android.PathForModuleOut(ctx, ctx.ModuleName()+".sh")
|
|
|
|
jarName := j.Stem() + ".jar"
|
|
|
|
partition := j.PartitionTag(ctx.DeviceConfig())
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: deviceBinaryWrapper,
|
|
|
|
Output: wrapper,
|
|
|
|
Args: map[string]string{
|
|
|
|
"jar_name": jarName,
|
|
|
|
"partition": partition,
|
|
|
|
"main_class": String(j.binaryProperties.Main_class),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
j.wrapperFile = wrapper
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
|
|
|
|
}
|
2017-12-05 22:42:45 +01:00
|
|
|
}
|
|
|
|
|
2021-09-21 08:11:24 +02:00
|
|
|
ext := ""
|
|
|
|
if ctx.Windows() {
|
|
|
|
ext = ".bat"
|
|
|
|
}
|
|
|
|
|
2020-10-09 19:54:15 +02:00
|
|
|
// The host installation rules make the installed wrapper depend on all the dependencies
|
2020-10-10 04:00:54 +02:00
|
|
|
// of the wrapper variant, which will include the common variant's jar file and any JNI
|
|
|
|
// libraries. This is verified by TestBinary.
|
2017-12-05 22:42:45 +01:00
|
|
|
j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
|
2021-09-21 08:11:24 +02:00
|
|
|
ctx.ModuleName()+ext, j.wrapperFile)
|
|
|
|
}
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 00:53:04 +02:00
|
|
|
func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2022-04-26 15:38:20 +02:00
|
|
|
if ctx.Arch().ArchType == android.Common {
|
2017-12-05 22:42:45 +01:00
|
|
|
j.deps(ctx)
|
2021-01-26 15:18:53 +01:00
|
|
|
}
|
2022-04-26 15:38:20 +02:00
|
|
|
if ctx.Arch().ArchType != android.Common {
|
2020-11-11 03:12:15 +01:00
|
|
|
// These dependencies ensure the host installation rules will install the jar file and
|
|
|
|
// the jni libraries when the wrapper is installed.
|
|
|
|
ctx.AddVariationDependencies(nil, jniInstallTag, j.binaryProperties.Jni_libs...)
|
|
|
|
ctx.AddVariationDependencies(
|
|
|
|
[]blueprint.Variation{{Mutator: "arch", Variation: android.CommonArch.String()}},
|
|
|
|
binaryInstallTag, ctx.ModuleName())
|
2017-12-05 22:42:45 +01:00
|
|
|
}
|
2017-06-23 01:51:17 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host
|
|
|
|
// as well.
|
|
|
|
//
|
|
|
|
// By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were
|
|
|
|
// compiled against the device bootclasspath.
|
|
|
|
//
|
|
|
|
// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
|
|
|
|
// compiled against the host bootclasspath.
|
2017-07-20 00:53:04 +02:00
|
|
|
func BinaryFactory() android.Module {
|
|
|
|
module := &Binary{}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2020-06-16 01:09:53 +02:00
|
|
|
module.addHostAndDeviceProperties()
|
|
|
|
module.AddProperties(&module.binaryProperties)
|
2017-06-24 00:06:31 +02:00
|
|
|
|
2018-06-27 02:59:05 +02:00
|
|
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
|
2017-12-05 22:42:45 +01:00
|
|
|
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
|
|
|
|
android.InitDefaultableModule(module)
|
2021-12-10 12:14:59 +01:00
|
|
|
|
2017-06-24 00:06:31 +02:00
|
|
|
return module
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_binary_host builds a `.jar` file and a shell script that executes it for the host.
|
|
|
|
//
|
|
|
|
// A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were
|
|
|
|
// compiled against the host bootclasspath.
|
2017-07-20 00:53:04 +02:00
|
|
|
func BinaryHostFactory() android.Module {
|
|
|
|
module := &Binary{}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2020-06-16 01:09:53 +02:00
|
|
|
module.addHostProperties()
|
|
|
|
module.AddProperties(&module.binaryProperties)
|
2017-06-24 00:06:31 +02:00
|
|
|
|
2018-06-27 02:59:05 +02:00
|
|
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
|
2017-12-05 22:42:45 +01:00
|
|
|
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
|
|
|
|
android.InitDefaultableModule(module)
|
2017-06-24 00:06:31 +02:00
|
|
|
return module
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2022-11-15 20:06:14 +01:00
|
|
|
type JavaApiContribution struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultableModuleBase
|
2023-10-27 19:21:52 +02:00
|
|
|
embeddableInModuleAndImport
|
2022-11-15 20:06:14 +01:00
|
|
|
|
|
|
|
properties struct {
|
|
|
|
// name of the API surface
|
|
|
|
Api_surface *string
|
|
|
|
|
|
|
|
// relative path to the API signature text file
|
|
|
|
Api_file *string `android:"path"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ApiContributionFactory() android.Module {
|
|
|
|
module := &JavaApiContribution{}
|
|
|
|
android.InitAndroidModule(module)
|
|
|
|
android.InitDefaultableModule(module)
|
|
|
|
module.AddProperties(&module.properties)
|
2023-10-27 19:21:52 +02:00
|
|
|
module.initModuleAndImport(module)
|
2022-11-15 20:06:14 +01:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
type JavaApiImportInfo struct {
|
2023-09-14 08:27:36 +02:00
|
|
|
ApiFile android.Path
|
|
|
|
ApiSurface string
|
2022-11-15 20:06:14 +01:00
|
|
|
}
|
|
|
|
|
2023-12-13 01:39:03 +01:00
|
|
|
var JavaApiImportProvider = blueprint.NewProvider[JavaApiImportInfo]()
|
2022-11-15 20:06:14 +01:00
|
|
|
|
|
|
|
func (ap *JavaApiContribution) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2023-01-26 09:08:52 +01:00
|
|
|
var apiFile android.Path = nil
|
|
|
|
if apiFileString := ap.properties.Api_file; apiFileString != nil {
|
|
|
|
apiFile = android.PathForModuleSrc(ctx, String(apiFileString))
|
|
|
|
}
|
|
|
|
|
2023-12-14 00:19:49 +01:00
|
|
|
android.SetProvider(ctx, JavaApiImportProvider, JavaApiImportInfo{
|
2023-09-14 08:27:36 +02:00
|
|
|
ApiFile: apiFile,
|
|
|
|
ApiSurface: proptools.String(ap.properties.Api_surface),
|
2022-11-15 20:06:14 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type ApiLibrary struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultableModuleBase
|
|
|
|
|
2023-03-22 05:27:05 +01:00
|
|
|
hiddenAPI
|
|
|
|
dexer
|
2023-10-27 19:21:52 +02:00
|
|
|
embeddableInModuleAndImport
|
2023-03-22 05:27:05 +01:00
|
|
|
|
2022-11-15 20:06:14 +01:00
|
|
|
properties JavaApiLibraryProperties
|
|
|
|
|
2023-03-14 02:09:34 +01:00
|
|
|
stubsSrcJar android.WritablePath
|
|
|
|
stubsJar android.WritablePath
|
|
|
|
stubsJarWithoutStaticLibs android.WritablePath
|
|
|
|
extractedSrcJar android.WritablePath
|
2023-03-22 05:27:05 +01:00
|
|
|
// .dex of stubs, used for hiddenapi processing
|
|
|
|
dexJarFile OptionalDexJarPath
|
2023-06-28 03:16:23 +02:00
|
|
|
|
|
|
|
validationPaths android.Paths
|
2024-02-15 22:53:49 +01:00
|
|
|
|
|
|
|
stubsType StubsType
|
|
|
|
|
|
|
|
aconfigProtoFiles android.Paths
|
2022-11-15 20:06:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type JavaApiLibraryProperties struct {
|
|
|
|
// name of the API surface
|
|
|
|
Api_surface *string
|
|
|
|
|
2022-11-18 00:47:43 +01:00
|
|
|
// list of Java API contribution modules that consists this API surface
|
2022-12-01 22:43:06 +01:00
|
|
|
// This is a list of Soong modules
|
2022-11-18 00:47:43 +01:00
|
|
|
Api_contributions []string
|
2022-11-15 20:06:14 +01:00
|
|
|
|
|
|
|
// List of flags to be passed to the javac compiler to generate jar file
|
|
|
|
Javacflags []string
|
2023-01-20 20:44:07 +01:00
|
|
|
|
|
|
|
// List of shared java libs that this module has dependencies to and
|
|
|
|
// should be passed as classpath in javac invocation
|
|
|
|
Libs []string
|
2023-02-14 21:18:20 +01:00
|
|
|
|
|
|
|
// List of java libs that this module has static dependencies to and will be
|
2023-03-14 02:09:34 +01:00
|
|
|
// merge zipped after metalava invocation
|
2023-02-14 21:18:20 +01:00
|
|
|
Static_libs []string
|
2023-03-14 02:09:34 +01:00
|
|
|
|
2023-06-23 01:13:51 +02:00
|
|
|
// Java Api library to provide the full API surface stub jar file.
|
|
|
|
// If this property is set, the stub jar of this module is created by
|
|
|
|
// extracting the compiled class files provided by the
|
|
|
|
// full_api_surface_stub module.
|
|
|
|
Full_api_surface_stub *string
|
2023-08-01 08:28:51 +02:00
|
|
|
|
|
|
|
// Version of previously released API file for compatibility check.
|
|
|
|
Previous_api *string `android:"path"`
|
2023-10-05 19:26:09 +02:00
|
|
|
|
|
|
|
// java_system_modules module providing the jar to be added to the
|
|
|
|
// bootclasspath when compiling the stubs.
|
|
|
|
// The jar will also be passed to metalava as a classpath to
|
|
|
|
// generate compilable stubs.
|
|
|
|
System_modules *string
|
2023-06-28 03:16:23 +02:00
|
|
|
|
|
|
|
// If true, the module runs validation on the API signature files provided
|
|
|
|
// by the modules passed via api_contributions by checking if the files are
|
|
|
|
// in sync with the source Java files. However, the environment variable
|
|
|
|
// DISABLE_STUB_VALIDATION has precedence over this property.
|
|
|
|
Enable_validation *bool
|
2024-02-15 22:53:49 +01:00
|
|
|
|
|
|
|
// Type of stubs the module should generate. Must be one of "everything", "runtime" or
|
|
|
|
// "exportable". Defaults to "everything".
|
|
|
|
// - "everything" stubs include all non-flagged apis and flagged apis, regardless of the state
|
|
|
|
// of the flag.
|
|
|
|
// - "runtime" stubs include all non-flagged apis and flagged apis that are ENABLED or
|
|
|
|
// READ_WRITE, and all other flagged apis are stripped.
|
|
|
|
// - "exportable" stubs include all non-flagged apis and flagged apis that are ENABLED and
|
|
|
|
// READ_ONLY, and all other flagged apis are stripped.
|
|
|
|
Stubs_type *string
|
|
|
|
|
|
|
|
// List of aconfig_declarations module names that the stubs generated in this module
|
|
|
|
// depend on.
|
|
|
|
Aconfig_declarations []string
|
2022-11-15 20:06:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func ApiLibraryFactory() android.Module {
|
|
|
|
module := &ApiLibrary{}
|
|
|
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
|
|
|
|
module.AddProperties(&module.properties)
|
2023-10-27 19:21:52 +02:00
|
|
|
module.initModuleAndImport(module)
|
2023-01-10 00:42:40 +01:00
|
|
|
android.InitDefaultableModule(module)
|
2022-11-15 20:06:14 +01:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func (al *ApiLibrary) ApiSurface() *string {
|
|
|
|
return al.properties.Api_surface
|
|
|
|
}
|
|
|
|
|
|
|
|
func (al *ApiLibrary) StubsJar() android.Path {
|
|
|
|
return al.stubsJar
|
|
|
|
}
|
|
|
|
|
|
|
|
func metalavaStubCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
|
2023-10-05 19:26:09 +02:00
|
|
|
srcs android.Paths, homeDir android.WritablePath,
|
|
|
|
classpath android.Paths) *android.RuleBuilderCommand {
|
2022-11-15 20:06:14 +01:00
|
|
|
rule.Command().Text("rm -rf").Flag(homeDir.String())
|
|
|
|
rule.Command().Text("mkdir -p").Flag(homeDir.String())
|
|
|
|
|
|
|
|
cmd := rule.Command()
|
|
|
|
cmd.FlagWithArg("ANDROID_PREFS_ROOT=", homeDir.String())
|
|
|
|
|
|
|
|
if metalavaUseRbe(ctx) {
|
|
|
|
rule.Remoteable(android.RemoteRuleSupports{RBE: true})
|
|
|
|
execStrategy := ctx.Config().GetenvWithDefault("RBE_METALAVA_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
|
|
|
|
labels := map[string]string{"type": "tool", "name": "metalava"}
|
|
|
|
|
|
|
|
pool := ctx.Config().GetenvWithDefault("RBE_METALAVA_POOL", "java16")
|
|
|
|
rule.Rewrapper(&remoteexec.REParams{
|
|
|
|
Labels: labels,
|
|
|
|
ExecStrategy: execStrategy,
|
|
|
|
ToolchainInputs: []string{config.JavaCmd(ctx).String()},
|
|
|
|
Platform: map[string]string{remoteexec.PoolKey: pool},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.BuiltTool("metalava").ImplicitTool(ctx.Config().HostJavaToolPath(ctx, "metalava.jar")).
|
|
|
|
Flag(config.JavacVmFlags).
|
|
|
|
Flag("-J--add-opens=java.base/java.util=ALL-UNNAMED").
|
|
|
|
FlagWithInputList("--source-files ", srcs, " ")
|
|
|
|
|
2023-07-12 14:01:49 +02:00
|
|
|
cmd.Flag("--color").
|
2022-11-15 20:06:14 +01:00
|
|
|
Flag("--quiet").
|
2023-01-17 21:40:22 +01:00
|
|
|
Flag("--include-annotations").
|
|
|
|
// The flag makes nullability issues as warnings rather than errors by replacing
|
|
|
|
// @Nullable/@NonNull in the listed packages APIs with @RecentlyNullable/@RecentlyNonNull,
|
|
|
|
// and these packages are meant to have everything annotated
|
|
|
|
// @RecentlyNullable/@RecentlyNonNull.
|
|
|
|
FlagWithArg("--force-convert-to-warning-nullability-annotations ", "+*:-android.*:+android.icu.*:-dalvik.*").
|
2022-11-15 20:06:14 +01:00
|
|
|
FlagWithArg("--repeat-errors-max ", "10").
|
|
|
|
FlagWithArg("--hide ", "UnresolvedImport").
|
|
|
|
FlagWithArg("--hide ", "InvalidNullabilityOverride").
|
|
|
|
FlagWithArg("--hide ", "ChangedDefault")
|
|
|
|
|
2023-10-05 19:26:09 +02:00
|
|
|
if len(classpath) == 0 {
|
|
|
|
// The main purpose of the `--api-class-resolution api` option is to force metalava to ignore
|
|
|
|
// classes on the classpath when an API file contains missing classes. However, as this command
|
|
|
|
// does not specify `--classpath` this is not needed for that. However, this is also used as a
|
|
|
|
// signal to the special metalava code for generating stubs from text files that it needs to add
|
|
|
|
// some additional items into the API (e.g. default constructors).
|
|
|
|
cmd.FlagWithArg("--api-class-resolution ", "api")
|
|
|
|
} else {
|
|
|
|
cmd.FlagWithArg("--api-class-resolution ", "api:classpath")
|
|
|
|
cmd.FlagWithInputList("--classpath ", classpath, ":")
|
|
|
|
}
|
2023-05-31 18:51:33 +02:00
|
|
|
|
2022-11-15 20:06:14 +01:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2023-01-17 21:40:22 +01:00
|
|
|
func (al *ApiLibrary) HeaderJars() android.Paths {
|
|
|
|
return android.Paths{al.stubsJar}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (al *ApiLibrary) OutputDirAndDeps() (android.Path, android.Paths) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:06:14 +01:00
|
|
|
func (al *ApiLibrary) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath) {
|
|
|
|
if stubsDir.Valid() {
|
|
|
|
cmd.FlagWithArg("--stubs ", stubsDir.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-28 03:16:23 +02:00
|
|
|
func (al *ApiLibrary) addValidation(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, validationPaths android.Paths) {
|
|
|
|
for _, validationPath := range validationPaths {
|
|
|
|
cmd.Validation(validationPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-23 01:13:51 +02:00
|
|
|
// This method extracts the stub class files from the stub jar file provided
|
|
|
|
// from full_api_surface_stub module instead of compiling the srcjar generated from invoking metalava.
|
2023-03-14 02:09:34 +01:00
|
|
|
// This method is used because metalava can generate compilable from-text stubs only when
|
2023-06-23 01:13:51 +02:00
|
|
|
// the codebase encompasses all classes listed in the input API text file, and a class can extend
|
2023-03-14 02:09:34 +01:00
|
|
|
// a class that is not within the same API domain.
|
2023-06-23 01:13:51 +02:00
|
|
|
func (al *ApiLibrary) extractApiSrcs(ctx android.ModuleContext, rule *android.RuleBuilder, stubsDir android.OptionalPath, fullApiSurfaceStubJar android.Path) {
|
|
|
|
classFilesList := android.PathForModuleOut(ctx, "metalava", "classes.txt")
|
2023-03-14 02:09:34 +01:00
|
|
|
unzippedSrcJarDir := android.PathForModuleOut(ctx, "metalava", "unzipDir")
|
|
|
|
|
|
|
|
rule.Command().
|
|
|
|
BuiltTool("list_files").
|
|
|
|
Text(stubsDir.String()).
|
2023-06-23 01:13:51 +02:00
|
|
|
FlagWithOutput("--out ", classFilesList).
|
2023-03-14 02:09:34 +01:00
|
|
|
FlagWithArg("--extensions ", ".java").
|
2023-06-23 01:13:51 +02:00
|
|
|
FlagWithArg("--root ", unzippedSrcJarDir.String()).
|
|
|
|
Flag("--classes")
|
2023-03-14 02:09:34 +01:00
|
|
|
|
|
|
|
rule.Command().
|
|
|
|
Text("unzip").
|
|
|
|
Flag("-q").
|
2023-06-23 01:13:51 +02:00
|
|
|
Input(fullApiSurfaceStubJar).
|
2023-03-14 02:09:34 +01:00
|
|
|
FlagWithArg("-d ", unzippedSrcJarDir.String())
|
|
|
|
|
|
|
|
rule.Command().
|
|
|
|
BuiltTool("soong_zip").
|
2023-06-23 01:13:51 +02:00
|
|
|
Flag("-jar").
|
2023-03-14 02:09:34 +01:00
|
|
|
Flag("-write_if_changed").
|
2023-06-23 01:13:51 +02:00
|
|
|
Flag("-ignore_missing_files").
|
2023-09-13 01:54:43 +02:00
|
|
|
Flag("-quiet").
|
2023-03-14 02:09:34 +01:00
|
|
|
FlagWithArg("-C ", unzippedSrcJarDir.String()).
|
2023-06-23 01:13:51 +02:00
|
|
|
FlagWithInput("-l ", classFilesList).
|
|
|
|
FlagWithOutput("-o ", al.stubsJarWithoutStaticLibs)
|
2023-03-14 02:09:34 +01:00
|
|
|
}
|
2022-11-15 20:06:14 +01:00
|
|
|
|
|
|
|
func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2022-11-18 00:47:43 +01:00
|
|
|
apiContributions := al.properties.Api_contributions
|
2023-06-28 03:16:23 +02:00
|
|
|
addValidations := !ctx.Config().IsEnvTrue("DISABLE_STUB_VALIDATION") &&
|
2024-01-30 03:30:06 +01:00
|
|
|
!ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") &&
|
2023-06-28 03:16:23 +02:00
|
|
|
proptools.BoolDefault(al.properties.Enable_validation, true)
|
2022-11-18 00:47:43 +01:00
|
|
|
for _, apiContributionName := range apiContributions {
|
|
|
|
ctx.AddDependency(ctx.Module(), javaApiContributionTag, apiContributionName)
|
2023-06-28 03:16:23 +02:00
|
|
|
|
|
|
|
// Add the java_api_contribution module generating droidstubs module
|
|
|
|
// as dependency when validation adding conditions are met and
|
|
|
|
// the java_api_contribution module name has ".api.contribution" suffix.
|
|
|
|
// All droidstubs-generated modules possess the suffix in the name,
|
|
|
|
// but there is no such guarantee for tests.
|
|
|
|
if addValidations {
|
|
|
|
if strings.HasSuffix(apiContributionName, ".api.contribution") {
|
|
|
|
ctx.AddDependency(ctx.Module(), metalavaCurrentApiTimestampTag, strings.TrimSuffix(apiContributionName, ".api.contribution"))
|
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("Validation is enabled for module %s but a "+
|
|
|
|
"current timestamp provider is not found for the api "+
|
|
|
|
"contribution %s",
|
|
|
|
ctx.ModuleName(),
|
|
|
|
apiContributionName,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2022-11-15 20:06:14 +01:00
|
|
|
}
|
2023-01-20 20:44:07 +01:00
|
|
|
ctx.AddVariationDependencies(nil, libTag, al.properties.Libs...)
|
2023-02-14 21:18:20 +01:00
|
|
|
ctx.AddVariationDependencies(nil, staticLibTag, al.properties.Static_libs...)
|
2023-06-23 01:13:51 +02:00
|
|
|
if al.properties.Full_api_surface_stub != nil {
|
|
|
|
ctx.AddVariationDependencies(nil, depApiSrcsTag, String(al.properties.Full_api_surface_stub))
|
2023-03-14 02:09:34 +01:00
|
|
|
}
|
2023-10-05 19:26:09 +02:00
|
|
|
if al.properties.System_modules != nil {
|
|
|
|
ctx.AddVariationDependencies(nil, systemModulesTag, String(al.properties.System_modules))
|
|
|
|
}
|
2024-02-15 22:53:49 +01:00
|
|
|
for _, aconfigDeclarationsName := range al.properties.Aconfig_declarations {
|
|
|
|
ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfigDeclarationsName)
|
|
|
|
}
|
2022-11-15 20:06:14 +01:00
|
|
|
}
|
|
|
|
|
2023-09-21 01:43:32 +02:00
|
|
|
// Map where key is the api scope name and value is the int value
|
|
|
|
// representing the order of the api scope, narrowest to the widest
|
|
|
|
var scopeOrderMap = allApiScopes.MapToIndex(
|
|
|
|
func(s *apiScope) string { return s.name })
|
2023-09-14 08:27:36 +02:00
|
|
|
|
2023-09-21 01:43:32 +02:00
|
|
|
func (al *ApiLibrary) sortApiFilesByApiScope(ctx android.ModuleContext, srcFilesInfo []JavaApiImportInfo) []JavaApiImportInfo {
|
|
|
|
for _, srcFileInfo := range srcFilesInfo {
|
|
|
|
if srcFileInfo.ApiSurface == "" {
|
|
|
|
ctx.ModuleErrorf("Api surface not defined for the associated api file %s", srcFileInfo.ApiFile)
|
2023-09-14 08:27:36 +02:00
|
|
|
}
|
2023-08-12 00:36:33 +02:00
|
|
|
}
|
2023-09-21 01:43:32 +02:00
|
|
|
sort.Slice(srcFilesInfo, func(i, j int) bool {
|
|
|
|
return scopeOrderMap[srcFilesInfo[i].ApiSurface] < scopeOrderMap[srcFilesInfo[j].ApiSurface]
|
|
|
|
})
|
2023-08-12 00:36:33 +02:00
|
|
|
|
2023-09-21 01:43:32 +02:00
|
|
|
return srcFilesInfo
|
2023-08-12 00:36:33 +02:00
|
|
|
}
|
|
|
|
|
2024-02-15 22:53:49 +01:00
|
|
|
var validstubsType = []StubsType{Everything, Runtime, Exportable}
|
|
|
|
|
|
|
|
func (al *ApiLibrary) validateProperties(ctx android.ModuleContext) {
|
|
|
|
if al.properties.Stubs_type == nil {
|
|
|
|
ctx.ModuleErrorf("java_api_library module type must specify stubs_type property.")
|
|
|
|
} else {
|
|
|
|
al.stubsType = StringToStubsType(proptools.String(al.properties.Stubs_type))
|
|
|
|
}
|
|
|
|
|
|
|
|
if !android.InList(al.stubsType, validstubsType) {
|
|
|
|
ctx.PropertyErrorf("stubs_type", "%s is not a valid stubs_type property value. "+
|
|
|
|
"Must be one of %s.", proptools.String(al.properties.Stubs_type), validstubsType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:06:14 +01:00
|
|
|
func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2024-02-15 22:53:49 +01:00
|
|
|
al.validateProperties(ctx)
|
2022-11-15 20:06:14 +01:00
|
|
|
|
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
|
|
|
|
|
|
|
rule.Sbox(android.PathForModuleOut(ctx, "metalava"),
|
|
|
|
android.PathForModuleOut(ctx, "metalava.sbox.textproto")).
|
|
|
|
SandboxInputs()
|
|
|
|
|
2023-06-28 03:16:23 +02:00
|
|
|
stubsDir := android.OptionalPathForPath(android.PathForModuleOut(ctx, "metalava", "stubsDir"))
|
2022-11-15 20:06:14 +01:00
|
|
|
rule.Command().Text("rm -rf").Text(stubsDir.String())
|
|
|
|
rule.Command().Text("mkdir -p").Text(stubsDir.String())
|
|
|
|
|
|
|
|
homeDir := android.PathForModuleOut(ctx, "metalava", "home")
|
|
|
|
|
2023-09-14 08:27:36 +02:00
|
|
|
var srcFilesInfo []JavaApiImportInfo
|
2023-01-20 20:44:07 +01:00
|
|
|
var classPaths android.Paths
|
2023-02-14 21:18:20 +01:00
|
|
|
var staticLibs android.Paths
|
2023-06-23 01:13:51 +02:00
|
|
|
var depApiSrcsStubsJar android.Path
|
2023-10-05 19:26:09 +02:00
|
|
|
var systemModulesPaths android.Paths
|
2023-01-20 20:44:07 +01:00
|
|
|
ctx.VisitDirectDeps(func(dep android.Module) {
|
|
|
|
tag := ctx.OtherModuleDependencyTag(dep)
|
|
|
|
switch tag {
|
|
|
|
case javaApiContributionTag:
|
2023-12-13 22:47:44 +01:00
|
|
|
provider, _ := android.OtherModuleProvider(ctx, dep, JavaApiImportProvider)
|
2023-09-14 08:27:36 +02:00
|
|
|
if provider.ApiFile == nil && !ctx.Config().AllowMissingDependencies() {
|
2023-01-26 09:08:52 +01:00
|
|
|
ctx.ModuleErrorf("Error: %s has an empty api file.", dep.Name())
|
|
|
|
}
|
2023-09-14 08:27:36 +02:00
|
|
|
srcFilesInfo = append(srcFilesInfo, provider)
|
2023-01-20 20:44:07 +01:00
|
|
|
case libTag:
|
2023-12-13 22:47:44 +01:00
|
|
|
provider, _ := android.OtherModuleProvider(ctx, dep, JavaInfoProvider)
|
2023-01-20 20:44:07 +01:00
|
|
|
classPaths = append(classPaths, provider.HeaderJars...)
|
2023-02-14 21:18:20 +01:00
|
|
|
case staticLibTag:
|
2023-12-13 22:47:44 +01:00
|
|
|
provider, _ := android.OtherModuleProvider(ctx, dep, JavaInfoProvider)
|
2023-02-14 21:18:20 +01:00
|
|
|
staticLibs = append(staticLibs, provider.HeaderJars...)
|
2023-03-14 02:09:34 +01:00
|
|
|
case depApiSrcsTag:
|
2023-12-13 22:47:44 +01:00
|
|
|
provider, _ := android.OtherModuleProvider(ctx, dep, JavaInfoProvider)
|
2023-06-23 01:13:51 +02:00
|
|
|
depApiSrcsStubsJar = provider.HeaderJars[0]
|
2023-10-05 19:26:09 +02:00
|
|
|
case systemModulesTag:
|
|
|
|
module := dep.(SystemModulesProvider)
|
|
|
|
systemModulesPaths = append(systemModulesPaths, module.HeaderJars()...)
|
2023-06-28 03:16:23 +02:00
|
|
|
case metalavaCurrentApiTimestampTag:
|
|
|
|
if currentApiTimestampProvider, ok := dep.(currentApiTimestampProvider); ok {
|
|
|
|
al.validationPaths = append(al.validationPaths, currentApiTimestampProvider.CurrentApiTimestamp())
|
|
|
|
}
|
2024-02-15 22:53:49 +01:00
|
|
|
case aconfigDeclarationTag:
|
|
|
|
if provider, ok := android.OtherModuleProvider(ctx, dep, android.AconfigDeclarationsProviderKey); ok {
|
|
|
|
al.aconfigProtoFiles = append(al.aconfigProtoFiles, provider.IntermediateCacheOutputPath)
|
2024-03-05 01:36:31 +01:00
|
|
|
} else if provider, ok := android.OtherModuleProvider(ctx, dep, android.CodegenInfoProvider); ok {
|
2024-02-15 22:53:49 +01:00
|
|
|
al.aconfigProtoFiles = append(al.aconfigProtoFiles, provider.IntermediateCacheOutputPaths...)
|
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("Only aconfig_declarations and aconfig_declarations_group "+
|
|
|
|
"module type is allowed for flags_packages property, but %s is neither "+
|
|
|
|
"of these supported module types",
|
|
|
|
dep.Name(),
|
|
|
|
)
|
|
|
|
}
|
2023-01-20 20:44:07 +01:00
|
|
|
}
|
2022-11-18 00:47:43 +01:00
|
|
|
})
|
2022-11-15 20:06:14 +01:00
|
|
|
|
2023-09-21 01:43:32 +02:00
|
|
|
srcFilesInfo = al.sortApiFilesByApiScope(ctx, srcFilesInfo)
|
|
|
|
var srcFiles android.Paths
|
|
|
|
for _, srcFileInfo := range srcFilesInfo {
|
|
|
|
srcFiles = append(srcFiles, android.PathForSource(ctx, srcFileInfo.ApiFile.String()))
|
2022-12-01 22:43:06 +01:00
|
|
|
}
|
|
|
|
|
2023-05-25 07:28:29 +02:00
|
|
|
if srcFiles == nil && !ctx.Config().AllowMissingDependencies() {
|
2023-03-14 02:09:34 +01:00
|
|
|
ctx.ModuleErrorf("Error: %s has an empty api file.", ctx.ModuleName())
|
|
|
|
}
|
|
|
|
|
2023-10-05 19:26:09 +02:00
|
|
|
cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir, systemModulesPaths)
|
2022-11-15 20:06:14 +01:00
|
|
|
|
|
|
|
al.stubsFlags(ctx, cmd, stubsDir)
|
|
|
|
|
2023-08-01 08:28:51 +02:00
|
|
|
migratingNullability := String(al.properties.Previous_api) != ""
|
|
|
|
if migratingNullability {
|
|
|
|
previousApi := android.PathForModuleSrc(ctx, String(al.properties.Previous_api))
|
|
|
|
cmd.FlagWithInput("--migrate-nullness ", previousApi)
|
|
|
|
}
|
|
|
|
|
2023-06-28 03:16:23 +02:00
|
|
|
al.addValidation(ctx, cmd, al.validationPaths)
|
|
|
|
|
2024-02-15 22:53:49 +01:00
|
|
|
generateRevertAnnotationArgs(ctx, cmd, al.stubsType, al.aconfigProtoFiles)
|
|
|
|
|
2022-11-15 20:06:14 +01:00
|
|
|
al.stubsSrcJar = android.PathForModuleOut(ctx, "metalava", ctx.ModuleName()+"-"+"stubs.srcjar")
|
2023-06-23 01:13:51 +02:00
|
|
|
al.stubsJarWithoutStaticLibs = android.PathForModuleOut(ctx, "metalava", "stubs.jar")
|
|
|
|
al.stubsJar = android.PathForModuleOut(ctx, ctx.ModuleName(), fmt.Sprintf("%s.jar", ctx.ModuleName()))
|
2023-03-14 02:09:34 +01:00
|
|
|
|
2023-06-23 01:13:51 +02:00
|
|
|
if depApiSrcsStubsJar != nil {
|
|
|
|
al.extractApiSrcs(ctx, rule, stubsDir, depApiSrcsStubsJar)
|
2023-03-14 02:09:34 +01:00
|
|
|
}
|
2023-06-23 01:13:51 +02:00
|
|
|
rule.Command().
|
|
|
|
BuiltTool("soong_zip").
|
|
|
|
Flag("-write_if_changed").
|
|
|
|
Flag("-jar").
|
|
|
|
FlagWithOutput("-o ", al.stubsSrcJar).
|
|
|
|
FlagWithArg("-C ", stubsDir.String()).
|
|
|
|
FlagWithArg("-D ", stubsDir.String())
|
2022-11-15 20:06:14 +01:00
|
|
|
|
2023-08-16 00:10:13 +02:00
|
|
|
rule.Build("metalava", "metalava merged text")
|
2023-03-14 02:09:34 +01:00
|
|
|
|
2023-06-23 01:13:51 +02:00
|
|
|
if depApiSrcsStubsJar == nil {
|
|
|
|
var flags javaBuilderFlags
|
|
|
|
flags.javaVersion = getStubsJavaVersion()
|
|
|
|
flags.javacFlags = strings.Join(al.properties.Javacflags, " ")
|
|
|
|
flags.classpath = classpath(classPaths)
|
2023-10-05 19:26:09 +02:00
|
|
|
flags.bootClasspath = classpath(systemModulesPaths)
|
2022-11-15 20:06:14 +01:00
|
|
|
|
2023-06-08 08:14:59 +02:00
|
|
|
annoSrcJar := android.PathForModuleOut(ctx, ctx.ModuleName(), "anno.srcjar")
|
|
|
|
|
2023-06-23 01:13:51 +02:00
|
|
|
TransformJavaToClasses(ctx, al.stubsJarWithoutStaticLibs, 0, android.Paths{},
|
2023-06-08 08:14:59 +02:00
|
|
|
android.Paths{al.stubsSrcJar}, annoSrcJar, flags, android.Paths{})
|
2023-06-23 01:13:51 +02:00
|
|
|
}
|
2022-11-30 00:10:10 +01:00
|
|
|
|
2023-02-14 21:18:20 +01:00
|
|
|
builder := android.NewRuleBuilder(pctx, ctx)
|
|
|
|
builder.Command().
|
|
|
|
BuiltTool("merge_zips").
|
|
|
|
Output(al.stubsJar).
|
2023-03-14 02:09:34 +01:00
|
|
|
Inputs(android.Paths{al.stubsJarWithoutStaticLibs}).
|
2023-02-14 21:18:20 +01:00
|
|
|
Inputs(staticLibs)
|
|
|
|
builder.Build("merge_zips", "merge jar files")
|
|
|
|
|
2023-03-22 05:27:05 +01:00
|
|
|
// compile stubs to .dex for hiddenapi processing
|
|
|
|
dexParams := &compileDexParams{
|
|
|
|
flags: javaBuilderFlags{},
|
|
|
|
sdkVersion: al.SdkVersion(ctx),
|
|
|
|
minSdkVersion: al.MinSdkVersion(ctx),
|
|
|
|
classesJar: al.stubsJar,
|
|
|
|
jarName: ctx.ModuleName() + ".jar",
|
|
|
|
}
|
|
|
|
dexOutputFile := al.dexer.compileDex(ctx, dexParams)
|
|
|
|
uncompressed := true
|
|
|
|
al.initHiddenAPI(ctx, makeDexJarPathFromPath(dexOutputFile), al.stubsJar, &uncompressed)
|
|
|
|
dexOutputFile = al.hiddenAPIEncodeDex(ctx, dexOutputFile)
|
|
|
|
al.dexJarFile = makeDexJarPathFromPath(dexOutputFile)
|
|
|
|
|
2022-11-30 00:10:10 +01:00
|
|
|
ctx.Phony(ctx.ModuleName(), al.stubsJar)
|
2023-01-20 20:44:07 +01:00
|
|
|
|
2023-12-14 00:19:49 +01:00
|
|
|
android.SetProvider(ctx, JavaInfoProvider, JavaInfo{
|
2023-01-17 21:40:22 +01:00
|
|
|
HeaderJars: android.PathsIfNonNil(al.stubsJar),
|
|
|
|
ImplementationAndResourcesJars: android.PathsIfNonNil(al.stubsJar),
|
|
|
|
ImplementationJars: android.PathsIfNonNil(al.stubsJar),
|
|
|
|
AidlIncludeDirs: android.Paths{},
|
2024-02-12 23:49:21 +01:00
|
|
|
StubsLinkType: Stubs,
|
2023-07-16 22:20:33 +02:00
|
|
|
// No aconfig libraries on api libraries
|
2023-01-20 20:44:07 +01:00
|
|
|
})
|
2022-11-15 20:06:14 +01:00
|
|
|
}
|
|
|
|
|
2024-01-09 22:35:56 +01:00
|
|
|
func (al *ApiLibrary) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath {
|
2023-03-22 05:27:05 +01:00
|
|
|
return al.dexJarFile
|
|
|
|
}
|
|
|
|
|
|
|
|
func (al *ApiLibrary) DexJarInstallPath() android.Path {
|
|
|
|
return al.dexJarFile.Path()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (al *ApiLibrary) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// java_api_library constitutes the sdk, and does not build against one
|
|
|
|
func (al *ApiLibrary) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
|
|
|
|
return android.SdkSpecNone
|
|
|
|
}
|
|
|
|
|
|
|
|
// java_api_library is always at "current". Return FutureApiLevel
|
|
|
|
func (al *ApiLibrary) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
|
|
|
|
return android.FutureApiLevel
|
|
|
|
}
|
|
|
|
|
|
|
|
// implement the following interfaces for hiddenapi processing
|
|
|
|
var _ hiddenAPIModule = (*ApiLibrary)(nil)
|
|
|
|
var _ UsesLibraryDependency = (*ApiLibrary)(nil)
|
|
|
|
|
2015-03-31 02:20:39 +02:00
|
|
|
//
|
|
|
|
// Java prebuilts
|
|
|
|
//
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
type ImportProperties struct {
|
2020-03-02 11:16:35 +01:00
|
|
|
Jars []string `android:"path,arch_variant"`
|
2017-10-20 22:59:18 +02:00
|
|
|
|
2021-04-02 02:38:25 +02:00
|
|
|
// The version of the SDK that the source prebuilt file was built against. Defaults to the
|
|
|
|
// current version if not specified.
|
2017-11-09 06:20:04 +01:00
|
|
|
Sdk_version *string
|
2017-10-21 02:57:49 +02:00
|
|
|
|
2021-04-02 02:38:25 +02:00
|
|
|
// The minimum version of the SDK that this module supports. Defaults to sdk_version if not
|
|
|
|
// specified.
|
|
|
|
Min_sdk_version *string
|
|
|
|
|
2022-05-17 22:21:50 +02:00
|
|
|
// The max sdk version placeholder used to replace maxSdkVersion attributes on permission
|
|
|
|
// and uses-permission tags in manifest_fixer.
|
|
|
|
Replace_max_sdk_version_placeholder *string
|
|
|
|
|
2017-10-21 02:57:49 +02:00
|
|
|
Installable *bool
|
2018-05-28 11:02:19 +02:00
|
|
|
|
2021-07-15 15:14:41 +02:00
|
|
|
// If not empty, classes are restricted to the specified packages and their sub-packages.
|
|
|
|
Permitted_packages []string
|
|
|
|
|
2018-05-28 11:02:19 +02:00
|
|
|
// List of shared java libs that this module has dependencies to
|
|
|
|
Libs []string
|
2018-07-12 21:28:41 +02:00
|
|
|
|
|
|
|
// List of files to remove from the jar file(s)
|
|
|
|
Exclude_files []string
|
|
|
|
|
|
|
|
// List of directories to remove from the jar file(s)
|
|
|
|
Exclude_dirs []string
|
2018-08-28 03:31:46 +02:00
|
|
|
|
|
|
|
// if set to true, run Jetifier against .jar file. Defaults to false.
|
2019-03-22 06:21:39 +01:00
|
|
|
Jetifier *bool
|
2019-10-21 07:53:15 +02:00
|
|
|
|
|
|
|
// set the name of the output
|
|
|
|
Stem *string
|
2020-03-24 08:44:11 +01:00
|
|
|
|
|
|
|
Aidl struct {
|
|
|
|
// directories that should be added as include directories for any aidl sources of modules
|
|
|
|
// that depend on this module, as well as to aidl for this module.
|
|
|
|
Export_include_dirs []string
|
|
|
|
}
|
2024-01-19 01:22:22 +01:00
|
|
|
|
|
|
|
// Name of the source soong module that gets shadowed by this prebuilt
|
|
|
|
// If unspecified, follows the naming convention that the source module of
|
|
|
|
// the prebuilt is Name() without "prebuilt_" prefix
|
|
|
|
Source_module_name *string
|
2024-01-19 01:22:22 +01:00
|
|
|
|
|
|
|
// Non-nil if this java_import module was dynamically created by a java_sdk_library_import
|
|
|
|
// The name is the undecorated name of the java_sdk_library as it appears in the blueprint file
|
|
|
|
// (without any prebuilt_ prefix)
|
|
|
|
Created_by_java_sdk_library_name *string `blueprint:"mutated"`
|
2024-02-12 23:49:21 +01:00
|
|
|
|
|
|
|
// Property signifying whether the module provides stubs jar or not.
|
|
|
|
Is_stubs_module *bool
|
2017-08-02 20:05:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type Import struct {
|
2016-05-19 00:37:25 +02:00
|
|
|
android.ModuleBase
|
2018-10-02 22:53:33 +02:00
|
|
|
android.DefaultableModuleBase
|
2019-07-25 15:02:35 +02:00
|
|
|
android.ApexModuleBase
|
2017-07-07 23:47:12 +02:00
|
|
|
prebuilt android.Prebuilt
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2020-05-17 09:34:50 +02:00
|
|
|
// Functionality common to Module and Import.
|
|
|
|
embeddableInModuleAndImport
|
|
|
|
|
2020-08-06 00:40:41 +02:00
|
|
|
hiddenAPI
|
|
|
|
dexer
|
2020-12-24 01:13:04 +01:00
|
|
|
dexpreopter
|
2020-08-06 00:40:41 +02:00
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
properties ImportProperties
|
|
|
|
|
2020-08-06 00:40:41 +02:00
|
|
|
// output file containing classes.dex and resources
|
2021-09-15 04:34:04 +02:00
|
|
|
dexJarFile OptionalDexJarPath
|
2023-12-13 00:23:53 +01:00
|
|
|
dexJarFileErr error
|
2021-07-07 18:13:11 +02:00
|
|
|
dexJarInstallFile android.Path
|
2020-08-06 00:40:41 +02:00
|
|
|
|
2017-08-30 23:24:55 +02:00
|
|
|
combinedClasspathFile android.Path
|
2020-10-08 13:53:58 +02:00
|
|
|
classLoaderContexts dexpreopt.ClassLoaderContextMap
|
2020-03-24 08:44:11 +01:00
|
|
|
exportAidlIncludeDirs android.Paths
|
2020-09-16 03:30:11 +02:00
|
|
|
|
|
|
|
hideApexVariantFromMake bool
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2021-04-02 01:45:46 +02:00
|
|
|
sdkVersion android.SdkSpec
|
2023-03-03 22:20:36 +01:00
|
|
|
minSdkVersion android.ApiLevel
|
2024-02-12 23:49:21 +01:00
|
|
|
|
|
|
|
stubsLinkType StubsLinkType
|
2018-06-26 00:48:06 +02:00
|
|
|
}
|
|
|
|
|
2021-07-15 14:35:26 +02:00
|
|
|
var _ PermittedPackagesForUpdatableBootJars = (*Import)(nil)
|
|
|
|
|
|
|
|
func (j *Import) PermittedPackagesForUpdatableBootJars() []string {
|
|
|
|
return j.properties.Permitted_packages
|
|
|
|
}
|
|
|
|
|
2021-04-02 01:45:46 +02:00
|
|
|
func (j *Import) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
|
|
|
|
return android.SdkSpecFrom(ctx, String(j.properties.Sdk_version))
|
2020-08-12 23:42:30 +02:00
|
|
|
}
|
|
|
|
|
2021-03-29 13:11:58 +02:00
|
|
|
func (j *Import) SystemModules() string {
|
2020-08-06 00:40:41 +02:00
|
|
|
return "none"
|
|
|
|
}
|
|
|
|
|
2023-03-03 22:20:36 +01:00
|
|
|
func (j *Import) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
|
2021-04-02 02:38:25 +02:00
|
|
|
if j.properties.Min_sdk_version != nil {
|
2023-03-03 22:20:36 +01:00
|
|
|
return android.ApiLevelFrom(ctx, *j.properties.Min_sdk_version)
|
2021-04-02 02:38:25 +02:00
|
|
|
}
|
2023-03-03 22:20:36 +01:00
|
|
|
return j.SdkVersion(ctx).ApiLevel
|
2018-06-26 00:48:06 +02:00
|
|
|
}
|
|
|
|
|
2023-03-02 01:56:06 +01:00
|
|
|
func (j *Import) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.ApiLevel {
|
2022-05-17 22:21:50 +02:00
|
|
|
if j.properties.Replace_max_sdk_version_placeholder != nil {
|
2023-03-02 01:56:06 +01:00
|
|
|
return android.ApiLevelFrom(ctx, *j.properties.Replace_max_sdk_version_placeholder)
|
2022-05-17 22:21:50 +02:00
|
|
|
}
|
2023-03-02 01:56:06 +01:00
|
|
|
// Default is PrivateApiLevel
|
|
|
|
return android.SdkSpecPrivate.ApiLevel
|
2022-05-17 22:21:50 +02:00
|
|
|
}
|
|
|
|
|
2023-03-02 00:38:49 +01:00
|
|
|
func (j *Import) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
|
|
|
|
return j.SdkVersion(ctx).ApiLevel
|
2020-04-27 19:53:18 +02:00
|
|
|
}
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
func (j *Import) Prebuilt() *android.Prebuilt {
|
2017-07-07 23:47:12 +02:00
|
|
|
return &j.prebuilt
|
|
|
|
}
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
func (j *Import) PrebuiltSrcs() []string {
|
|
|
|
return j.properties.Jars
|
|
|
|
}
|
|
|
|
|
2024-01-19 01:22:22 +01:00
|
|
|
func (j *Import) BaseModuleName() string {
|
|
|
|
return proptools.StringDefault(j.properties.Source_module_name, j.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
func (j *Import) Name() string {
|
2017-07-28 00:41:32 +02:00
|
|
|
return j.prebuilt.Name(j.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
2019-10-29 03:23:10 +01:00
|
|
|
func (j *Import) Stem() string {
|
2024-01-19 01:22:22 +01:00
|
|
|
return proptools.StringDefault(j.properties.Stem, j.BaseModuleName())
|
2019-10-29 03:23:10 +01:00
|
|
|
}
|
|
|
|
|
2024-01-19 01:22:22 +01:00
|
|
|
func (j *Import) CreatedByJavaSdkLibraryName() *string {
|
|
|
|
return j.properties.Created_by_java_sdk_library_name
|
|
|
|
}
|
|
|
|
|
2020-01-08 05:35:43 +01:00
|
|
|
func (a *Import) JacocoReportClassesFile() android.Path {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-01-11 19:58:54 +01:00
|
|
|
func (j *Import) LintDepSets() LintDepSets {
|
|
|
|
return LintDepSets{}
|
|
|
|
}
|
|
|
|
|
2021-05-11 00:30:00 +02:00
|
|
|
func (j *Import) getStrictUpdatabilityLinting() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *Import) setStrictUpdatabilityLinting(bool) {
|
|
|
|
}
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2018-08-29 23:10:52 +02:00
|
|
|
ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
|
2020-08-06 00:40:41 +02:00
|
|
|
|
|
|
|
if ctx.Device() && Bool(j.dexProperties.Compile_dex) {
|
2021-03-29 13:11:58 +02:00
|
|
|
sdkDeps(ctx, android.SdkContext(j), j.dexer)
|
2020-08-06 00:40:41 +02:00
|
|
|
}
|
2016-10-12 23:38:15 +02:00
|
|
|
}
|
|
|
|
|
2022-02-25 18:04:37 +01:00
|
|
|
func (j *Import) commonBuildActions(ctx android.ModuleContext) {
|
2021-04-02 01:45:46 +02:00
|
|
|
j.sdkVersion = j.SdkVersion(ctx)
|
|
|
|
j.minSdkVersion = j.MinSdkVersion(ctx)
|
|
|
|
|
2023-12-14 00:54:49 +01:00
|
|
|
apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
|
|
|
|
if !apexInfo.IsForPlatform() {
|
2020-09-16 03:30:11 +02:00
|
|
|
j.hideApexVariantFromMake = true
|
|
|
|
}
|
|
|
|
|
2021-09-21 08:11:24 +02:00
|
|
|
if ctx.Windows() {
|
|
|
|
j.HideFromMake()
|
|
|
|
}
|
2024-02-12 23:49:21 +01:00
|
|
|
|
|
|
|
if proptools.Bool(j.properties.Is_stubs_module) {
|
|
|
|
j.stubsLinkType = Stubs
|
|
|
|
} else {
|
|
|
|
j.stubsLinkType = Implementation
|
|
|
|
}
|
2022-02-25 18:04:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
j.commonBuildActions(ctx)
|
2021-09-21 08:11:24 +02:00
|
|
|
|
2019-03-06 07:25:09 +01:00
|
|
|
jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
|
2017-08-02 20:05:49 +02:00
|
|
|
|
2019-10-29 03:23:10 +01:00
|
|
|
jarName := j.Stem() + ".jar"
|
2018-08-28 03:31:46 +02:00
|
|
|
outputFile := android.PathForModuleOut(ctx, "combined", jarName)
|
2018-07-12 21:28:41 +02:00
|
|
|
TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
|
|
|
|
false, j.properties.Exclude_files, j.properties.Exclude_dirs)
|
2019-03-22 06:21:39 +01:00
|
|
|
if Bool(j.properties.Jetifier) {
|
2018-08-28 03:31:46 +02:00
|
|
|
inputFile := outputFile
|
|
|
|
outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
|
|
|
|
TransformJetifier(ctx, outputFile, inputFile)
|
|
|
|
}
|
2017-10-17 02:09:48 +02:00
|
|
|
j.combinedClasspathFile = outputFile
|
2020-10-08 13:53:58 +02:00
|
|
|
j.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap)
|
2020-05-15 11:20:31 +02:00
|
|
|
|
2020-08-06 00:40:41 +02:00
|
|
|
var flags javaBuilderFlags
|
|
|
|
|
2022-11-29 17:19:37 +01:00
|
|
|
j.collectTransitiveHeaderJars(ctx)
|
2018-05-28 11:02:19 +02:00
|
|
|
ctx.VisitDirectDeps(func(module android.Module) {
|
|
|
|
tag := ctx.OtherModuleDependencyTag(module)
|
2023-12-13 22:47:44 +01:00
|
|
|
if dep, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok {
|
2018-05-28 11:02:19 +02:00
|
|
|
switch tag {
|
2022-09-23 22:50:56 +02:00
|
|
|
case libTag, sdkLibTag:
|
2022-03-17 19:12:32 +01:00
|
|
|
flags.classpath = append(flags.classpath, dep.HeaderJars...)
|
|
|
|
flags.dexClasspath = append(flags.dexClasspath, dep.HeaderJars...)
|
|
|
|
case staticLibTag:
|
2021-02-01 22:59:03 +01:00
|
|
|
flags.classpath = append(flags.classpath, dep.HeaderJars...)
|
2020-08-06 00:40:41 +02:00
|
|
|
case bootClasspathTag:
|
2021-02-01 22:59:03 +01:00
|
|
|
flags.bootClasspath = append(flags.bootClasspath, dep.HeaderJars...)
|
2018-05-28 11:02:19 +02:00
|
|
|
}
|
2021-02-01 22:59:03 +01:00
|
|
|
} else if dep, ok := module.(SdkLibraryDependency); ok {
|
2018-05-28 11:02:19 +02:00
|
|
|
switch tag {
|
2022-09-23 22:50:56 +02:00
|
|
|
case libTag, sdkLibTag:
|
2021-04-02 01:45:46 +02:00
|
|
|
flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...)
|
2018-05-28 11:02:19 +02:00
|
|
|
}
|
|
|
|
}
|
2020-12-03 17:50:22 +01:00
|
|
|
|
2020-12-16 17:16:11 +01:00
|
|
|
addCLCFromDep(ctx, module, j.classLoaderContexts)
|
2018-05-28 11:02:19 +02:00
|
|
|
})
|
|
|
|
|
2022-02-25 18:04:37 +01:00
|
|
|
j.maybeInstall(ctx, jarName, outputFile)
|
2020-03-24 08:44:11 +01:00
|
|
|
|
|
|
|
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs)
|
2020-08-06 00:40:41 +02:00
|
|
|
|
2020-11-02 18:32:38 +01:00
|
|
|
if ctx.Device() {
|
|
|
|
// If this is a variant created for a prebuilt_apex then use the dex implementation jar
|
|
|
|
// obtained from the associated deapexer module.
|
2023-12-14 00:54:49 +01:00
|
|
|
ai, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
|
2020-11-02 18:32:38 +01:00
|
|
|
if ai.ForPrebuiltApex {
|
|
|
|
// Get the path of the dex implementation jar from the `deapexer` module.
|
2023-12-13 00:23:53 +01:00
|
|
|
di, err := android.FindDeapexerProviderForModule(ctx)
|
|
|
|
if err != nil {
|
|
|
|
// An error was found, possibly due to multiple apexes in the tree that export this library
|
|
|
|
// Defer the error till a client tries to call DexJarBuildPath
|
|
|
|
j.dexJarFileErr = err
|
2024-01-17 19:26:27 +01:00
|
|
|
j.initHiddenAPIError(err)
|
2023-12-13 00:23:53 +01:00
|
|
|
return
|
2021-09-17 02:44:12 +02:00
|
|
|
}
|
2023-12-13 01:06:32 +01:00
|
|
|
dexJarFileApexRootRelative := ApexRootRelativePathToJavaLib(j.BaseModuleName())
|
2023-02-08 14:56:07 +01:00
|
|
|
if dexOutputPath := di.PrebuiltExportPath(dexJarFileApexRootRelative); dexOutputPath != nil {
|
2021-09-15 04:34:04 +02:00
|
|
|
dexJarFile := makeDexJarPathFromPath(dexOutputPath)
|
|
|
|
j.dexJarFile = dexJarFile
|
2023-12-13 01:06:32 +01:00
|
|
|
installPath := android.PathForModuleInPartitionInstall(ctx, "apex", ai.ApexVariationName, ApexRootRelativePathToJavaLib(j.BaseModuleName()))
|
2021-09-30 11:32:57 +02:00
|
|
|
j.dexJarInstallFile = installPath
|
2021-05-14 15:18:47 +02:00
|
|
|
|
2024-01-24 00:56:29 +01:00
|
|
|
j.dexpreopter.installPath = j.dexpreopter.getInstallPath(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), installPath)
|
2021-10-11 05:05:20 +02:00
|
|
|
setUncompressDex(ctx, &j.dexpreopter, &j.dexer)
|
2021-09-30 11:32:57 +02:00
|
|
|
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
|
2023-02-08 14:56:07 +01:00
|
|
|
|
|
|
|
if profilePath := di.PrebuiltExportPath(dexJarFileApexRootRelative + ".prof"); profilePath != nil {
|
|
|
|
j.dexpreopter.inputProfilePathOnHost = profilePath
|
|
|
|
}
|
|
|
|
|
2021-10-11 05:05:20 +02:00
|
|
|
// Initialize the hiddenapi structure.
|
|
|
|
j.initHiddenAPI(ctx, dexJarFile, outputFile, j.dexProperties.Uncompress_dex)
|
2021-02-03 21:06:33 +01:00
|
|
|
} else {
|
2020-11-02 18:32:38 +01:00
|
|
|
// This should never happen as a variant for a prebuilt_apex is only created if the
|
|
|
|
// prebuilt_apex has been configured to export the java library dex file.
|
2021-09-17 02:44:12 +02:00
|
|
|
ctx.ModuleErrorf("internal error: no dex implementation jar available from prebuilt APEX %s", di.ApexModuleName())
|
2020-11-02 18:32:38 +01:00
|
|
|
}
|
|
|
|
} else if Bool(j.dexProperties.Compile_dex) {
|
2021-03-29 13:11:58 +02:00
|
|
|
sdkDep := decodeSdkDep(ctx, android.SdkContext(j))
|
2020-11-02 18:32:38 +01:00
|
|
|
if sdkDep.invalidVersion {
|
|
|
|
ctx.AddMissingDependencies(sdkDep.bootclasspath)
|
|
|
|
ctx.AddMissingDependencies(sdkDep.java9Classpath)
|
|
|
|
} else if sdkDep.useFiles {
|
|
|
|
// sdkDep.jar is actually equivalent to turbine header.jar.
|
|
|
|
flags.classpath = append(flags.classpath, sdkDep.jars...)
|
|
|
|
}
|
2020-12-24 01:13:04 +01:00
|
|
|
|
2020-11-02 18:32:38 +01:00
|
|
|
// Dex compilation
|
2020-12-24 01:13:04 +01:00
|
|
|
|
2021-09-16 08:15:39 +02:00
|
|
|
j.dexpreopter.installPath = j.dexpreopter.getInstallPath(
|
2024-01-24 00:56:29 +01:00
|
|
|
ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), android.PathForModuleInstall(ctx, "framework", jarName))
|
2021-10-11 05:05:20 +02:00
|
|
|
setUncompressDex(ctx, &j.dexpreopter, &j.dexer)
|
2020-11-02 18:32:38 +01:00
|
|
|
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
|
2020-08-06 00:40:41 +02:00
|
|
|
|
2021-02-02 14:38:13 +01:00
|
|
|
var dexOutputFile android.OutputPath
|
2023-02-23 19:05:05 +01:00
|
|
|
dexParams := &compileDexParams{
|
|
|
|
flags: flags,
|
|
|
|
sdkVersion: j.SdkVersion(ctx),
|
|
|
|
minSdkVersion: j.MinSdkVersion(ctx),
|
|
|
|
classesJar: outputFile,
|
|
|
|
jarName: jarName,
|
|
|
|
}
|
|
|
|
|
|
|
|
dexOutputFile = j.dexer.compileDex(ctx, dexParams)
|
2020-11-02 18:32:38 +01:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2020-08-06 00:40:41 +02:00
|
|
|
|
2021-05-14 15:18:47 +02:00
|
|
|
// Initialize the hiddenapi structure.
|
2021-09-15 04:34:04 +02:00
|
|
|
j.initHiddenAPI(ctx, makeDexJarPathFromPath(dexOutputFile), outputFile, j.dexProperties.Uncompress_dex)
|
2021-05-14 14:04:04 +02:00
|
|
|
|
|
|
|
// Encode hidden API flags in dex file.
|
2021-05-14 16:52:25 +02:00
|
|
|
dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile)
|
2020-11-02 18:32:38 +01:00
|
|
|
|
2021-09-15 04:34:04 +02:00
|
|
|
j.dexJarFile = makeDexJarPathFromPath(dexOutputFile)
|
2021-07-07 18:13:11 +02:00
|
|
|
j.dexJarInstallFile = android.PathForModuleInstall(ctx, "framework", jarName)
|
2020-11-02 18:32:38 +01:00
|
|
|
}
|
2020-08-06 00:40:41 +02:00
|
|
|
}
|
2021-02-01 22:59:03 +01:00
|
|
|
|
2023-12-14 00:19:49 +01:00
|
|
|
android.SetProvider(ctx, JavaInfoProvider, JavaInfo{
|
2021-02-01 22:59:03 +01:00
|
|
|
HeaderJars: android.PathsIfNonNil(j.combinedClasspathFile),
|
2022-11-29 17:19:37 +01:00
|
|
|
TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars,
|
|
|
|
TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars,
|
2021-02-01 22:59:03 +01:00
|
|
|
ImplementationAndResourcesJars: android.PathsIfNonNil(j.combinedClasspathFile),
|
|
|
|
ImplementationJars: android.PathsIfNonNil(j.combinedClasspathFile),
|
|
|
|
AidlIncludeDirs: j.exportAidlIncludeDirs,
|
2024-02-12 23:49:21 +01:00
|
|
|
StubsLinkType: j.stubsLinkType,
|
2023-07-16 22:20:33 +02:00
|
|
|
// TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
|
2021-02-01 22:59:03 +01:00
|
|
|
})
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2022-02-25 18:04:37 +01:00
|
|
|
func (j *Import) maybeInstall(ctx android.ModuleContext, jarName string, outputFile android.Path) {
|
|
|
|
if !Bool(j.properties.Installable) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var installDir android.InstallPath
|
|
|
|
if ctx.InstallInTestcases() {
|
|
|
|
var archDir string
|
|
|
|
if !ctx.Host() {
|
|
|
|
archDir = ctx.DeviceConfig().DeviceArch()
|
|
|
|
}
|
|
|
|
installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir)
|
|
|
|
} else {
|
|
|
|
installDir = android.PathForModuleInstall(ctx, "framework")
|
|
|
|
}
|
|
|
|
ctx.InstallFile(installDir, jarName, outputFile)
|
|
|
|
}
|
|
|
|
|
2020-10-06 18:20:13 +02:00
|
|
|
func (j *Import) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
switch tag {
|
2020-10-15 19:54:40 +02:00
|
|
|
case "", ".jar":
|
2020-10-06 18:20:13 +02:00
|
|
|
return android.Paths{j.combinedClasspathFile}, nil
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ android.OutputFileProducer = (*Import)(nil)
|
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
func (j *Import) HeaderJars() android.Paths {
|
2018-12-25 07:35:23 +01:00
|
|
|
if j.combinedClasspathFile == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2018-07-12 21:28:41 +02:00
|
|
|
return android.Paths{j.combinedClasspathFile}
|
2017-10-19 22:06:22 +02:00
|
|
|
}
|
|
|
|
|
2018-08-16 05:40:52 +02:00
|
|
|
func (j *Import) ImplementationAndResourcesJars() android.Paths {
|
2018-12-25 07:35:23 +01:00
|
|
|
if j.combinedClasspathFile == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2018-08-16 05:40:52 +02:00
|
|
|
return android.Paths{j.combinedClasspathFile}
|
|
|
|
}
|
|
|
|
|
2024-01-09 22:35:56 +01:00
|
|
|
func (j *Import) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath {
|
2023-12-13 00:23:53 +01:00
|
|
|
if j.dexJarFileErr != nil {
|
2024-01-09 22:35:56 +01:00
|
|
|
ctx.ModuleErrorf(j.dexJarFileErr.Error())
|
2023-12-13 00:23:53 +01:00
|
|
|
}
|
2020-08-06 00:40:41 +02:00
|
|
|
return j.dexJarFile
|
2019-01-31 23:12:44 +01:00
|
|
|
}
|
|
|
|
|
2020-06-09 15:31:19 +02:00
|
|
|
func (j *Import) DexJarInstallPath() android.Path {
|
2021-07-07 18:13:11 +02:00
|
|
|
return j.dexJarInstallFile
|
2020-06-09 15:31:19 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 13:53:58 +02:00
|
|
|
func (j *Import) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
|
|
|
|
return j.classLoaderContexts
|
2018-05-28 11:02:19 +02:00
|
|
|
}
|
|
|
|
|
2020-12-15 14:29:02 +01:00
|
|
|
var _ android.ApexModule = (*Import)(nil)
|
|
|
|
|
|
|
|
// Implements android.ApexModule
|
apex_available tracks static dependencies
This change fixes a bug that apex_available is not enforced for static
dependencies. For example, a module with 'apex_available:
["//apex_available:platform"]' was able to be statically linked to any
APEX. This was happening because the check was done on the modules that
are actually installed to an APEX. Static dependencies of the modules
were not counted as they are not installed to the APEX as files.
Fixing this bug by doing the check by traversing the tree in the method
checkApexAvailability.
This change includes a few number of related changes:
1) DepIsInSameApex implementation for cc.Module was changed as well.
Previuosly, it returned false only when the dependency is actually a
stub variant of a lib. Now, it returns false when the dependency has one
or more stub variants. To understand why, we need to recall that when
there is a dependency to a lib having stubs, we actually create two
dependencies: to the non-stub variant and to the stub variant during the
DepsMutator phase. And later in the build action generation phase, we
choose one of them depending on the context. Also recall that an APEX
variant is created only when DepIsInSameApex returns true. Given these,
with the previous implementatin of DepIsInSameApex, we did create apex
variants of the non-stub variant of the dependency, while not creating
the apex variant for the stub variant. This is not right; we needlessly
created the apex variant. The extra apex variant has caused no harm so
far, but since the apex_available check became more correct, it actually
breaks the build. To fix the issue, we stop creating the APEX variant
both for non-stub and stub variants.
2) platform variant is created regardless of the apex_available value.
This is required for the case when a library X that provides stub is in
an APEX A and is configured to be available only for A. In that case,
libs in other APEX can't use the stub library since the stub library is
mutated only for apex A. By creating the platform variant for the stub
library, it can be used from outside as the default dependency variation
is set to the platform variant when creating the APEX variations.
3) The ApexAvailableWhitelist is added with the dependencies that were
revealed with this change.
Exempt-From-Owner-Approval: cherry-pick from internal
Bug: 147671264
Test: m
Merged-In: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
(cherry picked from commit fa89944c79f19552e906b41fd03a4981903eee7e)
Change-Id: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
2020-01-30 18:49:53 +01:00
|
|
|
func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
|
2020-05-17 09:34:50 +02:00
|
|
|
return j.depIsInSameApex(ctx, dep)
|
apex_available tracks static dependencies
This change fixes a bug that apex_available is not enforced for static
dependencies. For example, a module with 'apex_available:
["//apex_available:platform"]' was able to be statically linked to any
APEX. This was happening because the check was done on the modules that
are actually installed to an APEX. Static dependencies of the modules
were not counted as they are not installed to the APEX as files.
Fixing this bug by doing the check by traversing the tree in the method
checkApexAvailability.
This change includes a few number of related changes:
1) DepIsInSameApex implementation for cc.Module was changed as well.
Previuosly, it returned false only when the dependency is actually a
stub variant of a lib. Now, it returns false when the dependency has one
or more stub variants. To understand why, we need to recall that when
there is a dependency to a lib having stubs, we actually create two
dependencies: to the non-stub variant and to the stub variant during the
DepsMutator phase. And later in the build action generation phase, we
choose one of them depending on the context. Also recall that an APEX
variant is created only when DepIsInSameApex returns true. Given these,
with the previous implementatin of DepIsInSameApex, we did create apex
variants of the non-stub variant of the dependency, while not creating
the apex variant for the stub variant. This is not right; we needlessly
created the apex variant. The extra apex variant has caused no harm so
far, but since the apex_available check became more correct, it actually
breaks the build. To fix the issue, we stop creating the APEX variant
both for non-stub and stub variants.
2) platform variant is created regardless of the apex_available value.
This is required for the case when a library X that provides stub is in
an APEX A and is configured to be available only for A. In that case,
libs in other APEX can't use the stub library since the stub library is
mutated only for apex A. By creating the platform variant for the stub
library, it can be used from outside as the default dependency variation
is set to the platform variant when creating the APEX variations.
3) The ApexAvailableWhitelist is added with the dependencies that were
revealed with this change.
Exempt-From-Owner-Approval: cherry-pick from internal
Bug: 147671264
Test: m
Merged-In: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
(cherry picked from commit fa89944c79f19552e906b41fd03a4981903eee7e)
Change-Id: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
2020-01-30 18:49:53 +01:00
|
|
|
}
|
|
|
|
|
2020-12-15 14:29:02 +01:00
|
|
|
// Implements android.ApexModule
|
2020-07-23 07:32:17 +02:00
|
|
|
func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
|
|
|
|
sdkVersion android.ApiLevel) error {
|
2023-02-24 19:38:56 +01:00
|
|
|
sdkVersionSpec := j.SdkVersion(ctx)
|
2023-03-03 22:20:36 +01:00
|
|
|
minSdkVersion := j.MinSdkVersion(ctx)
|
|
|
|
if !minSdkVersion.Specified() {
|
2021-04-02 02:38:25 +02:00
|
|
|
return fmt.Errorf("min_sdk_version is not specified")
|
|
|
|
}
|
2023-02-24 19:38:56 +01:00
|
|
|
// If the module is compiling against core (via sdk_version), skip comparison check.
|
|
|
|
if sdkVersionSpec.Kind == android.SdkCore {
|
2021-04-02 02:38:25 +02:00
|
|
|
return nil
|
|
|
|
}
|
2023-02-24 19:38:56 +01:00
|
|
|
if minSdkVersion.GreaterThan(sdkVersion) {
|
|
|
|
return fmt.Errorf("newer SDK(%v)", minSdkVersion)
|
2021-04-02 02:38:25 +02:00
|
|
|
}
|
2020-04-15 04:03:39 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-06-17 15:56:05 +02:00
|
|
|
// requiredFilesFromPrebuiltApexForImport returns information about the files that a java_import or
|
|
|
|
// java_sdk_library_import with the specified base module name requires to be exported from a
|
|
|
|
// prebuilt_apex/apex_set.
|
2023-02-08 14:56:07 +01:00
|
|
|
func requiredFilesFromPrebuiltApexForImport(name string, d *dexpreopter) []string {
|
2023-12-13 01:06:32 +01:00
|
|
|
dexJarFileApexRootRelative := ApexRootRelativePathToJavaLib(name)
|
2021-06-17 16:59:07 +02:00
|
|
|
// Add the dex implementation jar to the set of exported files.
|
2023-02-08 14:56:07 +01:00
|
|
|
files := []string{
|
|
|
|
dexJarFileApexRootRelative,
|
|
|
|
}
|
|
|
|
if BoolDefault(d.importDexpreoptProperties.Dex_preopt.Profile_guided, false) {
|
|
|
|
files = append(files, dexJarFileApexRootRelative+".prof")
|
2021-06-17 15:56:05 +02:00
|
|
|
}
|
2023-02-08 14:56:07 +01:00
|
|
|
return files
|
2021-06-17 15:56:05 +02:00
|
|
|
}
|
|
|
|
|
2023-12-13 01:06:32 +01:00
|
|
|
// ApexRootRelativePathToJavaLib returns the path, relative to the root of the apex's contents, for
|
2021-06-17 16:59:07 +02:00
|
|
|
// the java library with the specified name.
|
2023-12-13 01:06:32 +01:00
|
|
|
func ApexRootRelativePathToJavaLib(name string) string {
|
2021-06-17 16:59:07 +02:00
|
|
|
return filepath.Join("javalib", name+".jar")
|
|
|
|
}
|
|
|
|
|
2021-06-17 15:56:05 +02:00
|
|
|
var _ android.RequiredFilesFromPrebuiltApex = (*Import)(nil)
|
|
|
|
|
2021-06-17 16:59:07 +02:00
|
|
|
func (j *Import) RequiredFilesFromPrebuiltApex(_ android.BaseModuleContext) []string {
|
2021-06-17 15:56:05 +02:00
|
|
|
name := j.BaseModuleName()
|
2023-02-08 14:56:07 +01:00
|
|
|
return requiredFilesFromPrebuiltApexForImport(name, &j.dexpreopter)
|
2021-06-17 15:56:05 +02:00
|
|
|
}
|
|
|
|
|
2024-01-25 23:12:50 +01:00
|
|
|
func (j *Import) UseProfileGuidedDexpreopt() bool {
|
|
|
|
return proptools.Bool(j.importDexpreoptProperties.Dex_preopt.Profile_guided)
|
|
|
|
}
|
|
|
|
|
2018-12-25 07:35:23 +01:00
|
|
|
// Add compile time check for interface implementation
|
|
|
|
var _ android.IDEInfo = (*Import)(nil)
|
|
|
|
var _ android.IDECustomizedModuleName = (*Import)(nil)
|
|
|
|
|
2018-08-16 00:35:38 +02:00
|
|
|
// Collect information for opening IDE project files in java/jdeps.go.
|
|
|
|
|
|
|
|
func (j *Import) IDEInfo(dpInfo *android.IdeInfo) {
|
|
|
|
dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *Import) IDECustomizedModuleName() string {
|
|
|
|
// TODO(b/113562217): Extract the base module name from the Import name, often the Import name
|
|
|
|
// has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better
|
|
|
|
// solution to get the Import name.
|
2021-07-14 17:35:33 +02:00
|
|
|
return android.RemoveOptionalPrebuiltPrefix(j.Name())
|
2018-08-16 00:35:38 +02:00
|
|
|
}
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
var _ android.PrebuiltInterface = (*Import)(nil)
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2020-12-24 01:13:04 +01:00
|
|
|
func (j *Import) IsInstallable() bool {
|
|
|
|
return Bool(j.properties.Installable)
|
|
|
|
}
|
|
|
|
|
2021-09-16 08:15:39 +02:00
|
|
|
var _ DexpreopterInterface = (*Import)(nil)
|
2020-12-24 01:13:04 +01:00
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module.
|
|
|
|
//
|
|
|
|
// By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were
|
|
|
|
// compiled against an Android classpath.
|
|
|
|
//
|
|
|
|
// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
|
|
|
|
// for host modules.
|
2017-08-02 20:05:49 +02:00
|
|
|
func ImportFactory() android.Module {
|
|
|
|
module := &Import{}
|
2017-06-24 00:06:31 +02:00
|
|
|
|
2020-08-06 00:40:41 +02:00
|
|
|
module.AddProperties(
|
|
|
|
&module.properties,
|
|
|
|
&module.dexer.dexProperties,
|
2023-02-08 17:09:24 +01:00
|
|
|
&module.importDexpreoptProperties,
|
2020-08-06 00:40:41 +02:00
|
|
|
)
|
2017-08-02 20:05:49 +02:00
|
|
|
|
2021-06-23 12:39:47 +02:00
|
|
|
module.initModuleAndImport(module)
|
2020-05-15 11:20:31 +02:00
|
|
|
|
2020-08-06 00:40:41 +02:00
|
|
|
module.dexProperties.Optimize.EnabledByDefault = false
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
android.InitPrebuiltModule(module, &module.properties.Jars)
|
2019-07-25 15:02:35 +02:00
|
|
|
android.InitApexModule(module)
|
2019-11-13 02:50:48 +01:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
2017-06-24 00:06:31 +02:00
|
|
|
return module
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host
|
|
|
|
// module.
|
|
|
|
//
|
|
|
|
// A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were
|
|
|
|
// compiled against a host bootclasspath.
|
2017-08-02 20:05:49 +02:00
|
|
|
func ImportFactoryHost() android.Module {
|
|
|
|
module := &Import{}
|
|
|
|
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
|
|
|
|
android.InitPrebuiltModule(module, &module.properties.Jars)
|
2019-07-25 15:02:35 +02:00
|
|
|
android.InitApexModule(module)
|
2019-11-13 02:50:48 +01:00
|
|
|
InitJavaModule(module, android.HostSupported)
|
2017-08-02 20:05:49 +02:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2019-02-22 03:12:14 +01:00
|
|
|
// dex_import module
|
|
|
|
|
|
|
|
type DexImportProperties struct {
|
2019-07-15 22:36:55 +02:00
|
|
|
Jars []string `android:"path"`
|
2019-10-21 07:53:15 +02:00
|
|
|
|
|
|
|
// set the name of the output
|
|
|
|
Stem *string
|
2019-02-22 03:12:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type DexImport struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultableModuleBase
|
2019-07-25 15:02:35 +02:00
|
|
|
android.ApexModuleBase
|
2019-02-22 03:12:14 +01:00
|
|
|
prebuilt android.Prebuilt
|
|
|
|
|
|
|
|
properties DexImportProperties
|
|
|
|
|
2021-09-15 04:34:04 +02:00
|
|
|
dexJarFile OptionalDexJarPath
|
2019-02-22 03:12:14 +01:00
|
|
|
|
|
|
|
dexpreopter
|
2020-09-16 03:30:11 +02:00
|
|
|
|
|
|
|
hideApexVariantFromMake bool
|
2019-02-22 03:12:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (j *DexImport) Prebuilt() *android.Prebuilt {
|
|
|
|
return &j.prebuilt
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *DexImport) PrebuiltSrcs() []string {
|
|
|
|
return j.properties.Jars
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *DexImport) Name() string {
|
|
|
|
return j.prebuilt.Name(j.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
2019-10-29 03:23:10 +01:00
|
|
|
func (j *DexImport) Stem() string {
|
|
|
|
return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
2020-06-01 14:39:15 +02:00
|
|
|
func (a *DexImport) JacocoReportClassesFile() android.Path {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-22 05:31:17 +02:00
|
|
|
func (a *DexImport) LintDepSets() LintDepSets {
|
|
|
|
return LintDepSets{}
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:10:36 +01:00
|
|
|
func (j *DexImport) IsInstallable() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-05-11 00:30:00 +02:00
|
|
|
func (j *DexImport) getStrictUpdatabilityLinting() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *DexImport) setStrictUpdatabilityLinting(bool) {
|
|
|
|
}
|
|
|
|
|
2019-02-22 03:12:14 +01:00
|
|
|
func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
if len(j.properties.Jars) != 1 {
|
|
|
|
ctx.PropertyErrorf("jars", "exactly one jar must be provided")
|
|
|
|
}
|
|
|
|
|
2023-12-14 00:54:49 +01:00
|
|
|
apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
|
2020-09-16 03:30:11 +02:00
|
|
|
if !apexInfo.IsForPlatform() {
|
|
|
|
j.hideApexVariantFromMake = true
|
|
|
|
}
|
|
|
|
|
2021-09-16 08:15:39 +02:00
|
|
|
j.dexpreopter.installPath = j.dexpreopter.getInstallPath(
|
2024-01-24 00:56:29 +01:00
|
|
|
ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar"))
|
|
|
|
j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), &j.dexpreopter)
|
2019-02-22 03:12:14 +01:00
|
|
|
|
|
|
|
inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars")
|
|
|
|
dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar")
|
|
|
|
|
|
|
|
if j.dexpreopter.uncompressedDex {
|
2020-11-17 02:32:30 +01:00
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
2019-02-22 03:12:14 +01:00
|
|
|
|
|
|
|
temporary := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar.unaligned")
|
|
|
|
rule.Temporary(temporary)
|
|
|
|
|
|
|
|
// use zip2zip to uncompress classes*.dex files
|
|
|
|
rule.Command().
|
2020-11-17 02:32:30 +01:00
|
|
|
BuiltTool("zip2zip").
|
2019-02-22 03:12:14 +01:00
|
|
|
FlagWithInput("-i ", inputJar).
|
|
|
|
FlagWithOutput("-o ", temporary).
|
|
|
|
FlagWithArg("-0 ", "'classes*.dex'")
|
|
|
|
|
|
|
|
// use zipalign to align uncompressed classes*.dex files
|
|
|
|
rule.Command().
|
2020-11-17 02:32:30 +01:00
|
|
|
BuiltTool("zipalign").
|
2019-02-22 03:12:14 +01:00
|
|
|
Flag("-f").
|
|
|
|
Text("4").
|
|
|
|
Input(temporary).
|
|
|
|
Output(dexOutputFile)
|
|
|
|
|
|
|
|
rule.DeleteTemporaryFiles()
|
|
|
|
|
2020-11-17 02:32:30 +01:00
|
|
|
rule.Build("uncompress_dex", "uncompress dex")
|
2019-02-22 03:12:14 +01:00
|
|
|
} else {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Cp,
|
|
|
|
Input: inputJar,
|
|
|
|
Output: dexOutputFile,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-15 04:34:04 +02:00
|
|
|
j.dexJarFile = makeDexJarPathFromPath(dexOutputFile)
|
2019-02-22 03:12:14 +01:00
|
|
|
|
2024-01-24 00:56:29 +01:00
|
|
|
j.dexpreopt(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), dexOutputFile)
|
2019-02-22 03:12:14 +01:00
|
|
|
|
2020-09-16 03:30:11 +02:00
|
|
|
if apexInfo.IsForPlatform() {
|
2020-06-08 12:24:09 +02:00
|
|
|
ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
|
|
|
|
j.Stem()+".jar", dexOutputFile)
|
|
|
|
}
|
2019-02-22 03:12:14 +01:00
|
|
|
}
|
|
|
|
|
2024-01-09 22:35:56 +01:00
|
|
|
func (j *DexImport) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath {
|
2019-02-22 03:12:14 +01:00
|
|
|
return j.dexJarFile
|
|
|
|
}
|
|
|
|
|
2020-12-15 14:29:02 +01:00
|
|
|
var _ android.ApexModule = (*DexImport)(nil)
|
|
|
|
|
|
|
|
// Implements android.ApexModule
|
2020-07-23 07:32:17 +02:00
|
|
|
func (j *DexImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
|
|
|
|
sdkVersion android.ApiLevel) error {
|
2020-04-15 04:03:39 +02:00
|
|
|
// we don't check prebuilt modules for sdk_version
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-02-22 03:12:14 +01:00
|
|
|
// dex_import imports a `.jar` file containing classes.dex files.
|
|
|
|
//
|
|
|
|
// A dex_import module cannot be used as a dependency of a java_* or android_* module, it can only be installed
|
|
|
|
// to the device.
|
|
|
|
func DexImportFactory() android.Module {
|
|
|
|
module := &DexImport{}
|
|
|
|
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
|
|
|
|
android.InitPrebuiltModule(module, &module.properties.Jars)
|
2019-07-25 15:02:35 +02:00
|
|
|
android.InitApexModule(module)
|
2019-11-13 02:50:48 +01:00
|
|
|
InitJavaModule(module, android.DeviceSupported)
|
2019-02-22 03:12:14 +01:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2017-07-07 23:35:50 +02:00
|
|
|
// Defaults
|
|
|
|
type Defaults struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultsModuleBase
|
2019-07-25 15:02:35 +02:00
|
|
|
android.ApexModuleBase
|
2017-07-07 23:35:50 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_defaults provides a set of properties that can be inherited by other java or android modules.
|
|
|
|
//
|
|
|
|
// A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each
|
|
|
|
// property in the defaults module that exists in the depending module will be prepended to the depending module's
|
|
|
|
// value for that property.
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
2022-02-25 18:04:37 +01:00
|
|
|
// java_defaults {
|
|
|
|
// name: "example_defaults",
|
|
|
|
// srcs: ["common/**/*.java"],
|
|
|
|
// javacflags: ["-Xlint:all"],
|
|
|
|
// aaptflags: ["--auto-add-overlay"],
|
|
|
|
// }
|
2019-02-12 23:41:32 +01:00
|
|
|
//
|
2022-02-25 18:04:37 +01:00
|
|
|
// java_library {
|
|
|
|
// name: "example",
|
|
|
|
// defaults: ["example_defaults"],
|
|
|
|
// srcs: ["example/**/*.java"],
|
|
|
|
// }
|
2019-02-12 23:41:32 +01:00
|
|
|
//
|
|
|
|
// is functionally identical to:
|
|
|
|
//
|
2022-02-25 18:04:37 +01:00
|
|
|
// java_library {
|
|
|
|
// name: "example",
|
|
|
|
// srcs: [
|
|
|
|
// "common/**/*.java",
|
|
|
|
// "example/**/*.java",
|
|
|
|
// ],
|
|
|
|
// javacflags: ["-Xlint:all"],
|
|
|
|
// }
|
2019-12-05 15:07:14 +01:00
|
|
|
func DefaultsFactory() android.Module {
|
2017-07-07 23:35:50 +02:00
|
|
|
module := &Defaults{}
|
|
|
|
|
|
|
|
module.AddProperties(
|
2021-03-11 02:02:43 +01:00
|
|
|
&CommonProperties{},
|
|
|
|
&DeviceProperties{},
|
2022-01-08 04:16:32 +01:00
|
|
|
&OverridableDeviceProperties{},
|
2020-07-10 00:16:41 +02:00
|
|
|
&DexProperties{},
|
2018-11-12 19:13:39 +01:00
|
|
|
&DexpreoptProperties{},
|
2018-03-08 22:27:59 +01:00
|
|
|
&android.ProtoProperties{},
|
2018-10-02 22:53:33 +02:00
|
|
|
&aaptProperties{},
|
|
|
|
&androidLibraryProperties{},
|
|
|
|
&appProperties{},
|
|
|
|
&appTestProperties{},
|
2019-03-01 00:35:54 +01:00
|
|
|
&overridableAppProperties{},
|
2023-05-23 19:51:44 +02:00
|
|
|
&hostTestProperties{},
|
2020-02-04 16:45:49 +01:00
|
|
|
&testProperties{},
|
2018-10-02 22:53:33 +02:00
|
|
|
&ImportProperties{},
|
|
|
|
&AARImportProperties{},
|
|
|
|
&sdkLibraryProperties{},
|
2020-05-08 14:44:43 +02:00
|
|
|
&commonToSdkLibraryAndImportProperties{},
|
2019-02-22 03:12:14 +01:00
|
|
|
&DexImportProperties{},
|
2019-11-13 02:50:48 +01:00
|
|
|
&android.ApexProperties{},
|
2020-04-27 00:10:51 +02:00
|
|
|
&RuntimeResourceOverlayProperties{},
|
2020-06-03 05:09:13 +02:00
|
|
|
&LintProperties{},
|
2021-02-09 19:38:30 +01:00
|
|
|
&appTestHelperAppProperties{},
|
2023-01-10 00:42:40 +01:00
|
|
|
&JavaApiLibraryProperties{},
|
2024-01-12 01:08:30 +01:00
|
|
|
&bootclasspathFragmentProperties{},
|
|
|
|
&SourceOnlyBootclasspathProperties{},
|
2017-07-07 23:35:50 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
android.InitDefaultsModule(module)
|
|
|
|
return module
|
|
|
|
}
|
2017-11-09 06:20:04 +01:00
|
|
|
|
2018-11-06 01:49:08 +01:00
|
|
|
func kytheExtractJavaFactory() android.Singleton {
|
|
|
|
return &kytheExtractJavaSingleton{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type kytheExtractJavaSingleton struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
|
|
|
var xrefTargets android.Paths
|
|
|
|
ctx.VisitAllModules(func(module android.Module) {
|
|
|
|
if javaModule, ok := module.(xref); ok {
|
|
|
|
xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets
|
|
|
|
if len(xrefTargets) > 0 {
|
2020-06-04 22:25:17 +02:00
|
|
|
ctx.Phony("xref_java", xrefTargets...)
|
2018-11-06 01:49:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-09 06:20:04 +01:00
|
|
|
var Bool = proptools.Bool
|
2018-04-11 01:14:46 +02:00
|
|
|
var BoolDefault = proptools.BoolDefault
|
2017-11-09 06:20:04 +01:00
|
|
|
var String = proptools.String
|
2023-07-18 21:07:24 +02:00
|
|
|
var inList = android.InList[string]
|
2020-12-03 17:50:22 +01:00
|
|
|
|
2020-12-16 17:16:11 +01:00
|
|
|
// Add class loader context (CLC) of a given dependency to the current CLC.
|
|
|
|
func addCLCFromDep(ctx android.ModuleContext, depModule android.Module,
|
|
|
|
clcMap dexpreopt.ClassLoaderContextMap) {
|
|
|
|
|
|
|
|
dep, ok := depModule.(UsesLibraryDependency)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-15 15:34:40 +02:00
|
|
|
depName := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(depModule))
|
|
|
|
|
|
|
|
var sdkLib *string
|
|
|
|
if lib, ok := depModule.(SdkLibraryDependency); ok && lib.sharedLibrary() {
|
|
|
|
// A shared SDK library. This should be added as a top-level CLC element.
|
|
|
|
sdkLib = &depName
|
|
|
|
} else if ulib, ok := depModule.(ProvidesUsesLib); ok {
|
|
|
|
// A non-SDK library disguised as an SDK library by the means of `provides_uses_lib`
|
|
|
|
// property. This should be handled in the same way as a shared SDK library.
|
|
|
|
sdkLib = ulib.ProvidesUsesLib()
|
2020-12-16 17:16:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
depTag := ctx.OtherModuleDependencyTag(depModule)
|
2022-09-23 22:50:56 +02:00
|
|
|
if IsLibDepTag(depTag) {
|
2020-12-16 17:16:11 +01:00
|
|
|
// Ok, propagate <uses-library> through non-static library dependencies.
|
2022-05-04 13:00:02 +02:00
|
|
|
} else if tag, ok := depTag.(usesLibraryDependencyTag); ok && tag.sdkVersion == dexpreopt.AnySdkVersion {
|
|
|
|
// Ok, propagate <uses-library> through non-compatibility <uses-library> dependencies.
|
2020-12-16 17:16:11 +01:00
|
|
|
} else if depTag == staticLibTag {
|
|
|
|
// Propagate <uses-library> through static library dependencies, unless it is a component
|
|
|
|
// library (such as stubs). Component libraries have a dependency on their SDK library,
|
|
|
|
// which should not be pulled just because of a static component library.
|
2021-07-15 15:34:40 +02:00
|
|
|
if sdkLib != nil {
|
2020-12-16 17:16:11 +01:00
|
|
|
return
|
2020-12-03 17:50:22 +01:00
|
|
|
}
|
2020-12-16 17:16:11 +01:00
|
|
|
} else {
|
|
|
|
// Don't propagate <uses-library> for other dependency tags.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-15 15:34:40 +02:00
|
|
|
// If this is an SDK (or SDK-like) library, then it should be added as a node in the CLC tree,
|
|
|
|
// and its CLC should be added as subtree of that node. Otherwise the library is not a
|
|
|
|
// <uses_library> and should not be added to CLC, but the transitive <uses-library> dependencies
|
|
|
|
// from its CLC should be added to the current CLC.
|
|
|
|
if sdkLib != nil {
|
2022-05-04 13:00:02 +02:00
|
|
|
clcMap.AddContext(ctx, dexpreopt.AnySdkVersion, *sdkLib, false,
|
2024-01-09 22:35:56 +01:00
|
|
|
dep.DexJarBuildPath(ctx).PathOrNil(), dep.DexJarInstallPath(), dep.ClassLoaderContexts())
|
2020-12-16 17:16:11 +01:00
|
|
|
} else {
|
|
|
|
clcMap.AddContextMap(dep.ClassLoaderContexts(), depName)
|
2020-12-03 17:50:22 +01:00
|
|
|
}
|
|
|
|
}
|
2021-12-10 12:14:59 +01:00
|
|
|
|
2023-09-12 02:36:43 +02:00
|
|
|
type JavaApiContributionImport struct {
|
|
|
|
JavaApiContribution
|
|
|
|
|
2024-01-19 01:22:22 +01:00
|
|
|
prebuilt android.Prebuilt
|
|
|
|
prebuiltProperties javaApiContributionImportProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
type javaApiContributionImportProperties struct {
|
|
|
|
// Name of the source soong module that gets shadowed by this prebuilt
|
|
|
|
// If unspecified, follows the naming convention that the source module of
|
|
|
|
// the prebuilt is Name() without "prebuilt_" prefix
|
|
|
|
Source_module_name *string
|
|
|
|
|
|
|
|
// Non-nil if this java_import module was dynamically created by a java_sdk_library_import
|
|
|
|
// The name is the undecorated name of the java_sdk_library as it appears in the blueprint file
|
|
|
|
// (without any prebuilt_ prefix)
|
|
|
|
Created_by_java_sdk_library_name *string `blueprint:"mutated"`
|
2023-09-12 02:36:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func ApiContributionImportFactory() android.Module {
|
|
|
|
module := &JavaApiContributionImport{}
|
|
|
|
android.InitAndroidModule(module)
|
|
|
|
android.InitDefaultableModule(module)
|
|
|
|
android.InitPrebuiltModule(module, &[]string{""})
|
2024-01-19 01:22:22 +01:00
|
|
|
module.AddProperties(&module.properties, &module.prebuiltProperties)
|
2023-10-27 19:21:52 +02:00
|
|
|
module.AddProperties(&module.sdkLibraryComponentProperties)
|
2023-09-12 02:36:43 +02:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func (module *JavaApiContributionImport) Prebuilt() *android.Prebuilt {
|
|
|
|
return &module.prebuilt
|
|
|
|
}
|
|
|
|
|
|
|
|
func (module *JavaApiContributionImport) Name() string {
|
|
|
|
return module.prebuilt.Name(module.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
2024-01-19 01:22:22 +01:00
|
|
|
func (j *JavaApiContributionImport) BaseModuleName() string {
|
|
|
|
return proptools.StringDefault(j.prebuiltProperties.Source_module_name, j.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *JavaApiContributionImport) CreatedByJavaSdkLibraryName() *string {
|
|
|
|
return j.prebuiltProperties.Created_by_java_sdk_library_name
|
|
|
|
}
|
|
|
|
|
2023-09-12 02:36:43 +02:00
|
|
|
func (ap *JavaApiContributionImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
ap.JavaApiContribution.GenerateAndroidBuildActions(ctx)
|
|
|
|
}
|