2015-03-31 08:20:39 +08: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 07:51:17 +08:00
|
|
|
// into the flags and filenames necessary to pass to the Module. The final creation of the rules
|
2015-03-31 08:20:39 +08:00
|
|
|
// is handled in builder.go
|
|
|
|
|
|
|
|
import (
|
2018-03-27 05:42:44 +08:00
|
|
|
"fmt"
|
2017-09-19 08:41:52 +08:00
|
|
|
"path/filepath"
|
2015-03-31 08:20:39 +08:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2017-08-30 07:02:06 +08:00
|
|
|
"github.com/google/blueprint/proptools"
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
"android/soong/android"
|
2021-01-27 03:01:43 +08:00
|
|
|
"android/soong/cc"
|
2020-08-15 00:32:16 +08:00
|
|
|
"android/soong/dexpreopt"
|
2017-06-23 08:20:19 +08:00
|
|
|
"android/soong/java/config"
|
2018-08-08 07:49:25 +08:00
|
|
|
"android/soong/tradefed"
|
2015-03-31 08:20:39 +08:00
|
|
|
)
|
|
|
|
|
2015-06-18 05:20:06 +08:00
|
|
|
func init() {
|
2021-03-31 06:34:32 +08:00
|
|
|
registerJavaBuildComponents(android.InitRegistrationContext)
|
2019-12-13 19:22:16 +08:00
|
|
|
|
2021-03-11 09:02:43 +08:00
|
|
|
RegisterJavaSdkMemberTypes()
|
|
|
|
}
|
|
|
|
|
2021-03-31 06:34:32 +08:00
|
|
|
func registerJavaBuildComponents(ctx android.RegistrationContext) {
|
2021-03-11 09:02:43 +08: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)
|
|
|
|
|
|
|
|
ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) {
|
|
|
|
ctx.BottomUp("dexpreopt_tool_deps", dexpreoptToolDepsMutator).Parallel()
|
|
|
|
})
|
|
|
|
|
|
|
|
ctx.RegisterSingletonType("logtags", LogtagsSingleton)
|
|
|
|
ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
|
|
|
|
}
|
|
|
|
|
|
|
|
func RegisterJavaSdkMemberTypes() {
|
2019-12-13 19:22:16 +08:00
|
|
|
// Register sdk member types.
|
2020-01-14 05:03:22 +08:00
|
|
|
android.RegisterSdkMemberType(javaHeaderLibsSdkMemberType)
|
2021-04-24 02:43:28 +08:00
|
|
|
android.RegisterSdkMemberType(javaLibsSdkMemberType)
|
|
|
|
android.RegisterSdkMemberType(javaBootLibsSdkMemberType)
|
|
|
|
android.RegisterSdkMemberType(javaTestSdkMemberType)
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
// Supports adding java header libraries to module_exports and sdk.
|
|
|
|
javaHeaderLibsSdkMemberType = &librarySdkMemberType{
|
|
|
|
android.SdkMemberTypeBase{
|
|
|
|
PropertyName: "java_header_libs",
|
|
|
|
SupportsSdk: true,
|
|
|
|
},
|
|
|
|
func(_ android.SdkMemberContext, j *Library) android.Path {
|
|
|
|
headerJars := j.HeaderJars()
|
|
|
|
if len(headerJars) != 1 {
|
|
|
|
panic(fmt.Errorf("there must be only one header jar from %q", j.Name()))
|
|
|
|
}
|
|
|
|
|
|
|
|
return headerJars[0]
|
|
|
|
},
|
|
|
|
sdkSnapshotFilePathForJar,
|
|
|
|
copyEverythingToSnapshot,
|
|
|
|
}
|
2019-12-13 19:22:16 +08:00
|
|
|
|
2021-02-04 19:15:34 +08:00
|
|
|
// Export implementation classes jar as part of the sdk.
|
2021-04-24 02:43:28 +08:00
|
|
|
exportImplementationClassesJar = func(_ android.SdkMemberContext, j *Library) android.Path {
|
2021-02-04 19:15:34 +08: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-24 02:43:28 +08:00
|
|
|
// Supports adding java implementation libraries to module_exports but not sdk.
|
|
|
|
javaLibsSdkMemberType = &librarySdkMemberType{
|
2020-02-28 22:39:53 +08:00
|
|
|
android.SdkMemberTypeBase{
|
|
|
|
PropertyName: "java_libs",
|
|
|
|
},
|
2021-02-04 19:15:34 +08:00
|
|
|
exportImplementationClassesJar,
|
2020-12-09 01:48:25 +08:00
|
|
|
sdkSnapshotFilePathForJar,
|
|
|
|
copyEverythingToSnapshot,
|
2021-04-24 02:43:28 +08:00
|
|
|
}
|
2019-12-04 02:06:47 +08:00
|
|
|
|
2021-04-24 02:43:28 +08:00
|
|
|
// Supports adding java boot libraries to module_exports and sdk.
|
2020-12-09 01:48:25 +08: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-24 02:43:28 +08:00
|
|
|
javaBootLibsSdkMemberType = &librarySdkMemberType{
|
2020-12-09 01:48:25 +08:00
|
|
|
android.SdkMemberTypeBase{
|
|
|
|
PropertyName: "java_boot_libs",
|
|
|
|
SupportsSdk: true,
|
|
|
|
},
|
2021-02-04 19:15:34 +08:00
|
|
|
// Temporarily export implementation classes jar for java_boot_libs as it is required for the
|
|
|
|
// hiddenapi processing.
|
|
|
|
// TODO(b/179354495): Revert once hiddenapi processing has been modularized.
|
|
|
|
exportImplementationClassesJar,
|
|
|
|
sdkSnapshotFilePathForJar,
|
2020-12-09 01:48:25 +08:00
|
|
|
onlyCopyJarToSnapshot,
|
2021-04-24 02:43:28 +08:00
|
|
|
}
|
2020-12-09 01:48:25 +08:00
|
|
|
|
2021-04-24 02:43:28 +08:00
|
|
|
// Supports adding java test libraries to module_exports but not sdk.
|
|
|
|
javaTestSdkMemberType = &testSdkMemberType{
|
2019-12-04 02:06:47 +08:00
|
|
|
SdkMemberTypeBase: android.SdkMemberTypeBase{
|
|
|
|
PropertyName: "java_tests",
|
|
|
|
},
|
2021-04-24 02:43:28 +08:00
|
|
|
}
|
|
|
|
)
|
2019-07-11 14:54:27 +08:00
|
|
|
|
2021-02-02 05:59:03 +08: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
|
|
|
|
|
|
|
|
// 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
|
|
|
|
//module.
|
|
|
|
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-18 06:56:23 +08:00
|
|
|
SrcJarArgs []string
|
2020-06-03 11:09:13 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
// SrcJarDeps is a list of paths to depend on when packaging the sources of this module.
|
|
|
|
SrcJarDeps android.Paths
|
|
|
|
|
|
|
|
// 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 11:09:13 +08:00
|
|
|
|
2021-03-18 06:56:23 +08: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-16 02:19:12 +08:00
|
|
|
|
2021-03-18 06:56:23 +08: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-02 05:59:03 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
// JacocoReportClassesFile is the path to a jar containing uninstrumented classes that will be
|
|
|
|
// instrumented by jacoco.
|
|
|
|
JacocoReportClassesFile android.Path
|
2017-10-20 04:06:22 +08:00
|
|
|
}
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
var JavaInfoProvider = blueprint.NewProvider(JavaInfo{})
|
2019-09-06 07:44:18 +08:00
|
|
|
|
2021-03-18 06:56:23 +08: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 07:44:18 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
var SyspropPublicStubInfoProvider = blueprint.NewProvider(SyspropPublicStubInfo{})
|
2019-09-06 07:44:18 +08:00
|
|
|
|
2021-03-18 06:56:23 +08: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 07:44:18 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
// Provides build path and install path to DEX jars.
|
|
|
|
type UsesLibraryDependency interface {
|
|
|
|
DexJarBuildPath() android.Path
|
|
|
|
DexJarInstallPath() android.Path
|
|
|
|
ClassLoaderContexts() dexpreopt.ClassLoaderContextMap
|
2019-09-06 07:44:18 +08:00
|
|
|
}
|
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
// TODO(jungjw): Move this to kythe.go once it's created.
|
|
|
|
type xref interface {
|
|
|
|
XrefJavaFiles() android.Paths
|
|
|
|
}
|
2018-08-21 23:10:29 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
func (j *Module) XrefJavaFiles() android.Paths {
|
|
|
|
return j.kytheFiles
|
2018-08-21 23:10:29 +08:00
|
|
|
}
|
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
type dependencyTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
name string
|
|
|
|
}
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2021-03-18 06:56:23 +08: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 08:20:39 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
type usesLibraryDependencyTag struct {
|
|
|
|
dependencyTag
|
|
|
|
sdkVersion int // SDK version in which the library appared as a standalone library.
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeUsesLibraryDependencyTag(sdkVersion int) usesLibraryDependencyTag {
|
|
|
|
return usesLibraryDependencyTag{
|
|
|
|
dependencyTag: dependencyTag{name: fmt.Sprintf("uses-library-%d", sdkVersion)},
|
|
|
|
sdkVersion: sdkVersion,
|
2017-10-20 04:06:22 +08:00
|
|
|
}
|
2021-03-18 06:56:23 +08:00
|
|
|
}
|
2017-09-01 03:30:37 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
func IsJniDepTag(depTag blueprint.DependencyTag) bool {
|
|
|
|
return depTag == jniLibTag
|
2017-10-20 04:06:22 +08:00
|
|
|
}
|
2017-09-01 03:30:37 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
var (
|
|
|
|
dataNativeBinsTag = dependencyTag{name: "dataNativeBins"}
|
|
|
|
staticLibTag = dependencyTag{name: "staticlib"}
|
|
|
|
libTag = dependencyTag{name: "javalib"}
|
|
|
|
java9LibTag = dependencyTag{name: "java9lib"}
|
|
|
|
pluginTag = dependencyTag{name: "plugin"}
|
|
|
|
errorpronePluginTag = dependencyTag{name: "errorprone-plugin"}
|
|
|
|
exportedPluginTag = dependencyTag{name: "exported-plugin"}
|
|
|
|
bootClasspathTag = dependencyTag{name: "bootclasspath"}
|
|
|
|
systemModulesTag = dependencyTag{name: "system modules"}
|
|
|
|
frameworkResTag = dependencyTag{name: "framework-res"}
|
|
|
|
kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
|
|
|
|
kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations"}
|
|
|
|
proguardRaiseTag = dependencyTag{name: "proguard-raise"}
|
|
|
|
certificateTag = dependencyTag{name: "certificate"}
|
|
|
|
instrumentationForTag = dependencyTag{name: "instrumentation_for"}
|
|
|
|
extraLintCheckTag = dependencyTag{name: "extra-lint-check"}
|
|
|
|
jniLibTag = dependencyTag{name: "jnilib"}
|
|
|
|
syspropPublicStubDepTag = dependencyTag{name: "sysprop public stub"}
|
|
|
|
jniInstallTag = installDependencyTag{name: "jni install"}
|
|
|
|
binaryInstallTag = installDependencyTag{name: "binary install"}
|
|
|
|
usesLibTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion)
|
|
|
|
usesLibCompat28Tag = makeUsesLibraryDependencyTag(28)
|
|
|
|
usesLibCompat29Tag = makeUsesLibraryDependencyTag(29)
|
|
|
|
usesLibCompat30Tag = makeUsesLibraryDependencyTag(30)
|
|
|
|
)
|
2017-11-23 05:49:43 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
func IsLibDepTag(depTag blueprint.DependencyTag) bool {
|
|
|
|
return depTag == libTag
|
|
|
|
}
|
2017-11-23 05:49:43 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
func IsStaticLibDepTag(depTag blueprint.DependencyTag) bool {
|
|
|
|
return depTag == staticLibTag
|
|
|
|
}
|
2017-11-23 05:49:43 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
type sdkDep struct {
|
|
|
|
useModule, useFiles, invalidVersion bool
|
2017-11-23 05:49:43 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
// The modules that will be added to the bootclasspath when targeting 1.8 or lower
|
|
|
|
bootclasspath []string
|
2017-11-23 05:49:43 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
// The default system modules to use. Will be an empty string if no system
|
|
|
|
// modules are to be used.
|
|
|
|
systemModules string
|
2017-11-23 05:49:43 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
// The modules that will be added to the classpath regardless of the Java language level targeted
|
|
|
|
classpath []string
|
2017-10-20 04:06:22 +08:00
|
|
|
|
2021-03-18 06:56:23 +08: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 08:20:39 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
frameworkResModule string
|
2019-02-01 06:12:44 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
jars android.Paths
|
|
|
|
aidl android.OptionalPath
|
2020-06-09 21:31:19 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
noStandardLibs, noFrameworksLibs bool
|
2018-08-16 11:40:52 +08:00
|
|
|
}
|
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
func (s sdkDep) hasStandardLibs() bool {
|
|
|
|
return !s.noStandardLibs
|
2015-04-09 04:03:43 +08:00
|
|
|
}
|
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
func (s sdkDep) hasFrameworkLibs() bool {
|
|
|
|
return !s.noStandardLibs && !s.noFrameworksLibs
|
2018-05-28 17:02:19 +08:00
|
|
|
}
|
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
type jniLib struct {
|
|
|
|
name string
|
|
|
|
path android.Path
|
|
|
|
target android.Target
|
|
|
|
coverageFile android.OptionalPath
|
|
|
|
unstrippedFile android.Path
|
2015-04-11 08:45:20 +08:00
|
|
|
}
|
|
|
|
|
2021-03-29 19:11:58 +08:00
|
|
|
func sdkDeps(ctx android.BottomUpMutatorContext, sdkContext android.SdkContext, d dexer) {
|
2021-03-18 06:56:23 +08:00
|
|
|
sdkDep := decodeSdkDep(ctx, sdkContext)
|
|
|
|
if sdkDep.useModule {
|
|
|
|
ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
|
|
|
|
ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
|
|
|
|
ctx.AddVariationDependencies(nil, libTag, sdkDep.classpath...)
|
|
|
|
if d.effectiveOptimizeEnabled() && sdkDep.hasStandardLibs() {
|
|
|
|
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.LegacyCorePlatformBootclasspathLibraries...)
|
|
|
|
}
|
|
|
|
if d.effectiveOptimizeEnabled() && sdkDep.hasFrameworkLibs() {
|
|
|
|
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.FrameworkLibraries...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if sdkDep.systemModules != "" {
|
|
|
|
ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
|
2018-08-16 06:35:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
type deps struct {
|
|
|
|
classpath classpath
|
|
|
|
java9Classpath classpath
|
|
|
|
bootClasspath classpath
|
|
|
|
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
|
2018-08-16 06:35:38 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
disableTurbine bool
|
2019-05-31 06:51:14 +08:00
|
|
|
}
|
|
|
|
|
2021-03-18 06:56:23 +08: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 14:20:07 +08:00
|
|
|
}
|
|
|
|
|
2021-03-29 19:11:58 +08:00
|
|
|
func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext android.SdkContext) javaVersion {
|
2021-03-18 06:56:23 +08:00
|
|
|
if javaVersion != "" {
|
|
|
|
return normalizeJavaVersion(ctx, javaVersion)
|
|
|
|
} else if ctx.Device() {
|
2021-04-02 07:45:46 +08:00
|
|
|
return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion(ctx))
|
2021-03-18 06:56:23 +08:00
|
|
|
} else {
|
|
|
|
return JAVA_VERSION_9
|
2020-04-15 10:03:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
type javaVersion int
|
2019-10-29 10:23:10 +08:00
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
const (
|
|
|
|
JAVA_VERSION_UNSUPPORTED = 0
|
|
|
|
JAVA_VERSION_6 = 6
|
|
|
|
JAVA_VERSION_7 = 7
|
|
|
|
JAVA_VERSION_8 = 8
|
|
|
|
JAVA_VERSION_9 = 9
|
|
|
|
)
|
|
|
|
|
|
|
|
func (v javaVersion) String() string {
|
|
|
|
switch v {
|
|
|
|
case JAVA_VERSION_6:
|
|
|
|
return "1.6"
|
|
|
|
case JAVA_VERSION_7:
|
|
|
|
return "1.7"
|
|
|
|
case JAVA_VERSION_8:
|
|
|
|
return "1.8"
|
|
|
|
case JAVA_VERSION_9:
|
|
|
|
return "1.9"
|
|
|
|
default:
|
|
|
|
return "unsupported"
|
|
|
|
}
|
2020-06-24 23:22:38 +08:00
|
|
|
}
|
|
|
|
|
2021-03-18 06:56:23 +08: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 12:35:43 +08:00
|
|
|
}
|
|
|
|
|
2021-03-18 06:56:23 +08:00
|
|
|
func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) javaVersion {
|
|
|
|
switch javaVersion {
|
|
|
|
case "1.6", "6":
|
|
|
|
return JAVA_VERSION_6
|
|
|
|
case "1.7", "7":
|
|
|
|
return JAVA_VERSION_7
|
|
|
|
case "1.8", "8":
|
|
|
|
return JAVA_VERSION_8
|
|
|
|
case "1.9", "9":
|
|
|
|
return JAVA_VERSION_9
|
|
|
|
case "10", "11":
|
|
|
|
ctx.PropertyErrorf("java_version", "Java language levels above 9 are not supported")
|
|
|
|
return JAVA_VERSION_UNSUPPORTED
|
|
|
|
default:
|
|
|
|
ctx.PropertyErrorf("java_version", "Unrecognized Java language level")
|
|
|
|
return JAVA_VERSION_UNSUPPORTED
|
|
|
|
}
|
2020-02-01 01:10:36 +08:00
|
|
|
}
|
|
|
|
|
2015-03-31 08:20:39 +08:00
|
|
|
//
|
|
|
|
// Java libraries (.jar file)
|
|
|
|
//
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
type Library struct {
|
2017-06-23 07:51:17 +08:00
|
|
|
Module
|
2019-10-16 07:36:40 +08:00
|
|
|
|
|
|
|
InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths)
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2020-12-15 21:29:02 +08:00
|
|
|
var _ android.ApexModule = (*Library)(nil)
|
|
|
|
|
2020-05-29 18:24:51 +08:00
|
|
|
// Provides access to the list of permitted packages from updatable boot jars.
|
|
|
|
type PermittedPackagesForUpdatableBootJars interface {
|
|
|
|
PermittedPackagesForUpdatableBootJars() []string
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ PermittedPackagesForUpdatableBootJars = (*Library)(nil)
|
|
|
|
|
|
|
|
func (j *Library) PermittedPackagesForUpdatableBootJars() []string {
|
|
|
|
return j.properties.Permitted_packages
|
|
|
|
}
|
|
|
|
|
2019-02-22 10:12:14 +08:00
|
|
|
func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool {
|
2020-01-24 20:19:45 +08:00
|
|
|
// Store uncompressed (and aligned) any dex files from jars in APEXes.
|
2020-09-16 09:30:11 +08:00
|
|
|
if apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo); !apexInfo.IsForPlatform() {
|
2020-01-24 20:19:45 +08:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-02-12 21:12:16 +08:00
|
|
|
// Store uncompressed (and do not strip) dex files from boot class path jars.
|
|
|
|
if inList(ctx.ModuleName(), ctx.Config().BootJars()) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store uncompressed dex files that are preopted on /system.
|
2019-02-22 10:12:14 +08:00
|
|
|
if !dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, dexpreopter.installPath)) {
|
2018-12-21 23:54:16 +08:00
|
|
|
return true
|
|
|
|
}
|
2019-02-07 08:37:12 +08:00
|
|
|
if ctx.Config().UncompressPrivAppDex() &&
|
|
|
|
inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-12-22 04:59:54 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2021-02-02 03:01:34 +08:00
|
|
|
// Initialize the hiddenapi structure. Pass in the configuration name rather than the module name
|
|
|
|
// so the hidden api will encode the <x>.impl java_ library created by java_sdk_library just as it
|
|
|
|
// would the <x> library if <x> was configured as a boot jar.
|
|
|
|
j.initHiddenAPI(ctx, j.ConfigurationName())
|
|
|
|
|
2021-04-02 07:45:46 +08:00
|
|
|
j.sdkVersion = j.SdkVersion(ctx)
|
|
|
|
j.minSdkVersion = j.MinSdkVersion(ctx)
|
|
|
|
|
2020-09-16 09:30:11 +08:00
|
|
|
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
|
|
|
|
if !apexInfo.IsForPlatform() {
|
|
|
|
j.hideApexVariantFromMake = true
|
|
|
|
}
|
|
|
|
|
2020-04-09 02:09:30 +08:00
|
|
|
j.checkSdkVersions(ctx)
|
2019-10-29 10:23:10 +08:00
|
|
|
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
|
2018-11-13 02:13:39 +08:00
|
|
|
j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
|
2020-07-10 06:16:41 +08:00
|
|
|
if j.dexProperties.Uncompress_dex == nil {
|
2020-05-21 05:20:28 +08:00
|
|
|
// If the value was not force-set by the user, use reasonable default based on the module.
|
2020-07-10 06:16:41 +08:00
|
|
|
j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter))
|
2020-05-21 05:20:28 +08:00
|
|
|
}
|
2020-07-10 06:16:41 +08:00
|
|
|
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
|
2020-10-08 19:53:58 +08:00
|
|
|
j.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap)
|
2019-05-14 00:23:20 +08:00
|
|
|
j.compile(ctx, nil)
|
2015-04-17 05:09:14 +08:00
|
|
|
|
2020-05-21 10:11:59 +08:00
|
|
|
// Collect the module directory for IDE info in java/jdeps.go.
|
|
|
|
j.modulePaths = append(j.modulePaths, ctx.ModuleDir())
|
|
|
|
|
2020-09-16 09:30:11 +08:00
|
|
|
exclusivelyForApex := !apexInfo.IsForPlatform()
|
2019-07-25 21:02:35 +08:00
|
|
|
if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex {
|
2019-10-16 07:36:40 +08:00
|
|
|
var extraInstallDeps android.Paths
|
|
|
|
if j.InstallMixin != nil {
|
|
|
|
extraInstallDeps = j.InstallMixin(ctx, j.outputFile)
|
|
|
|
}
|
2017-09-01 07:45:16 +08:00
|
|
|
j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
|
2020-05-28 22:46:55 +08:00
|
|
|
j.Stem()+".jar", j.outputFile, extraInstallDeps...)
|
2017-09-01 07:45:16 +08:00
|
|
|
}
|
2015-04-17 05:09:14 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2017-06-23 07:51:17 +08:00
|
|
|
j.deps(ctx)
|
|
|
|
}
|
|
|
|
|
2019-11-13 03:39:25 +08:00
|
|
|
const (
|
2019-12-04 02:06:47 +08:00
|
|
|
aidlIncludeDir = "aidl"
|
|
|
|
javaDir = "java"
|
|
|
|
jarFileSuffix = ".jar"
|
|
|
|
testConfigSuffix = "-AndroidTest.xml"
|
2019-11-13 03:39:25 +08:00
|
|
|
)
|
|
|
|
|
2019-12-05 19:25:53 +08:00
|
|
|
// path to the jar file of a java library. Relative to <sdk_root>/<api_dir>
|
2020-03-02 18:16:35 +08:00
|
|
|
func sdkSnapshotFilePathForJar(osPrefix, name string) string {
|
|
|
|
return sdkSnapshotFilePathForMember(osPrefix, name, jarFileSuffix)
|
2019-12-04 02:06:47 +08:00
|
|
|
}
|
|
|
|
|
2020-03-02 18:16:35 +08:00
|
|
|
func sdkSnapshotFilePathForMember(osPrefix, name string, suffix string) string {
|
|
|
|
return filepath.Join(javaDir, osPrefix, name+suffix)
|
2019-11-13 03:39:25 +08:00
|
|
|
}
|
|
|
|
|
2019-11-28 22:31:38 +08:00
|
|
|
type librarySdkMemberType struct {
|
2019-12-13 19:22:16 +08:00
|
|
|
android.SdkMemberTypeBase
|
2020-02-28 22:39:53 +08:00
|
|
|
|
|
|
|
// Function to retrieve the appropriate output jar (implementation or header) from
|
|
|
|
// the library.
|
2020-12-09 01:48:25 +08: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.
|
|
|
|
snapshotPathGetter func(osPrefix, name string) string
|
|
|
|
|
|
|
|
// 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 22:31:38 +08:00
|
|
|
}
|
|
|
|
|
2020-12-09 01:48:25 +08:00
|
|
|
const (
|
|
|
|
onlyCopyJarToSnapshot = true
|
|
|
|
copyEverythingToSnapshot = false
|
|
|
|
)
|
|
|
|
|
2019-11-28 22:31:38 +08:00
|
|
|
func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
|
|
|
|
mctx.AddVariationDependencies(nil, dependencyTag, names...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
|
|
|
|
_, ok := module.(*Library)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2020-03-20 00:11:18 +08:00
|
|
|
func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
|
|
|
|
return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_import")
|
2020-03-02 19:33:02 +08:00
|
|
|
}
|
2019-12-05 19:25:53 +08:00
|
|
|
|
2020-03-02 19:33:02 +08:00
|
|
|
func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
|
2020-03-18 05:04:24 +08:00
|
|
|
return &librarySdkMemberProperties{}
|
2020-03-02 19:33:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type librarySdkMemberProperties struct {
|
|
|
|
android.SdkMemberPropertiesBase
|
|
|
|
|
2020-05-06 17:23:19 +08:00
|
|
|
JarToExport android.Path `android:"arch_variant"`
|
2020-03-18 05:04:24 +08:00
|
|
|
AidlIncludeDirs android.Paths
|
2020-03-02 19:33:02 +08:00
|
|
|
}
|
|
|
|
|
2020-03-20 00:11:18 +08:00
|
|
|
func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
|
2019-11-28 22:31:38 +08:00
|
|
|
j := variant.(*Library)
|
|
|
|
|
2020-12-09 01:48:25 +08:00
|
|
|
p.JarToExport = ctx.MemberType().(*librarySdkMemberType).jarToExportGetter(ctx, j)
|
|
|
|
|
2020-03-18 05:04:24 +08:00
|
|
|
p.AidlIncludeDirs = j.AidlIncludeDirs()
|
2020-03-02 19:33:02 +08:00
|
|
|
}
|
|
|
|
|
2020-03-20 00:11:18 +08:00
|
|
|
func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
|
2020-03-18 05:04:24 +08:00
|
|
|
builder := ctx.SnapshotBuilder()
|
2020-03-20 00:11:18 +08:00
|
|
|
|
2020-12-09 01:48:25 +08:00
|
|
|
memberType := ctx.MemberType().(*librarySdkMemberType)
|
|
|
|
|
2020-03-18 05:04:24 +08:00
|
|
|
exportedJar := p.JarToExport
|
|
|
|
if exportedJar != nil {
|
2020-12-09 01:48:25 +08:00
|
|
|
// Delegate the creation of the snapshot relative path to the member type.
|
|
|
|
snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(p.OsPrefix(), ctx.Name())
|
|
|
|
|
|
|
|
// Copy the exported jar to the snapshot.
|
2020-03-02 19:33:02 +08:00
|
|
|
builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
|
2019-11-13 03:39:25 +08:00
|
|
|
|
2020-03-18 05:04:24 +08:00
|
|
|
propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
|
|
|
|
}
|
|
|
|
|
2020-12-09 01:48:25 +08:00
|
|
|
// Do not copy anything else to the snapshot.
|
|
|
|
if memberType.onlyCopyJarToSnapshot {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-03-18 05:04:24 +08:00
|
|
|
aidlIncludeDirs := p.AidlIncludeDirs
|
|
|
|
if len(aidlIncludeDirs) != 0 {
|
|
|
|
sdkModuleContext := ctx.SdkModuleContext()
|
|
|
|
for _, dir := range aidlIncludeDirs {
|
2020-03-02 19:33:02 +08: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-13 03:39:25 +08:00
|
|
|
}
|
|
|
|
|
2020-03-18 05:04:24 +08:00
|
|
|
// TODO(b/151933053) - add aidl include dirs property
|
2020-03-02 19:33:02 +08:00
|
|
|
}
|
2019-11-13 03:39:25 +08:00
|
|
|
}
|
|
|
|
|
2019-02-13 06:41:32 +08: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 08:59:05 +08:00
|
|
|
func LibraryFactory() android.Module {
|
|
|
|
module := &Library{}
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2020-06-16 07:09:53 +08:00
|
|
|
module.addHostAndDeviceProperties()
|
2017-06-24 06:06:31 +08:00
|
|
|
|
2020-05-15 17:20:31 +08:00
|
|
|
module.initModuleAndImport(&module.ModuleBase)
|
|
|
|
|
2019-07-25 21:02:35 +08:00
|
|
|
android.InitApexModule(module)
|
Introduce module type 'sdk'
This change introduces a new module type named 'sdk'. It is a logical
group of prebuilt modules that together provide a context (e.g. APIs)
in which Mainline modules (such as APEXes) are built.
A prebuilt module (e.g. java_import) can join an sdk by adding it to the
sdk module as shown below:
sdk {
name: "mysdk#20",
java_libs: ["myjavalib_mysdk_20"],
}
java_import {
name: "myjavalib_mysdk_20",
srcs: ["myjavalib-v20.jar"],
sdk_member_name: "myjavalib",
}
sdk {
name: "mysdk#21",
java_libs: ["myjavalib_mysdk_21"],
}
java_import {
name: "myjavalib_mysdk_21",
srcs: ["myjavalib-v21.jar"],
sdk_member_name: "myjavalib",
}
java_library {
name: "myjavalib",
srcs: ["**/*/*.java"],
}
An APEX can specify the SDK(s) that it wants to build with via the new
'uses_sdks' property.
apex {
name: "myapex",
java_libs: ["libX", "libY"],
uses_sdks: ["mysdk#20"],
}
With this, libX, libY, and their transitive dependencies are all built
with the version 20 of myjavalib (the first java_import module) instead
of the other one (which is for version 21) and java_library having the
same name (which is for ToT).
Bug: 138182343
Test: m (sdk_test.go added)
Change-Id: I7e14c524a7d6a0d9f575fb20822080f39818c01e
2019-07-17 19:08:41 +08:00
|
|
|
android.InitSdkAwareModule(module)
|
2019-11-13 09:50:48 +08:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
2018-06-27 08:59:05 +08:00
|
|
|
return module
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2019-02-13 06:41:32 +08: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 06:53:04 +08:00
|
|
|
func LibraryHostFactory() android.Module {
|
|
|
|
module := &Library{}
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2020-06-16 07:09:53 +08:00
|
|
|
module.addHostProperties()
|
2017-06-24 06:06:31 +08:00
|
|
|
|
2018-06-27 08:59:05 +08:00
|
|
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
|
2019-07-25 21:02:35 +08:00
|
|
|
android.InitApexModule(module)
|
2019-11-13 09:50:48 +08:00
|
|
|
InitJavaModule(module, android.HostSupported)
|
2017-06-24 06:06:31 +08:00
|
|
|
return module
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2018-04-10 09:40:24 +08:00
|
|
|
//
|
2018-08-15 07:42:33 +08:00
|
|
|
// Java Tests
|
2018-04-10 09:40:24 +08:00
|
|
|
//
|
|
|
|
|
2020-08-16 03:24:26 +08:00
|
|
|
// Test option struct.
|
|
|
|
type TestOptions struct {
|
|
|
|
// a list of extra test configuration files that should be installed with the module.
|
|
|
|
Extra_test_configs []string `android:"path,arch_variant"`
|
2020-11-14 06:33:46 +08:00
|
|
|
|
|
|
|
// If the test is a hostside(no device required) unittest that shall be run during presubmit check.
|
|
|
|
Unit_test *bool
|
2020-08-16 03:24:26 +08:00
|
|
|
}
|
|
|
|
|
2018-04-10 09:40:24 +08: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 06:00:46 +08:00
|
|
|
|
|
|
|
// the name of the test configuration (for example "AndroidTest.xml") that should be
|
|
|
|
// installed with the module.
|
2019-03-05 14:35:41 +08:00
|
|
|
Test_config *string `android:"path,arch_variant"`
|
2018-08-11 07:06:24 +08:00
|
|
|
|
2018-09-19 17:21:28 +08:00
|
|
|
// the name of the test configuration template (for example "AndroidTestTemplate.xml") that
|
|
|
|
// should be installed with the module.
|
2019-03-05 14:35:41 +08:00
|
|
|
Test_config_template *string `android:"path,arch_variant"`
|
2018-09-19 17:21:28 +08:00
|
|
|
|
2018-08-11 07:06:24 +08:00
|
|
|
// list of files or filegroup modules that provide data that should be installed alongside
|
|
|
|
// the test
|
2021-02-16 05:52:39 +08:00
|
|
|
Data []string `android:"path"`
|
2019-09-27 02:41:36 +08: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 14:57:06 +08: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-16 03:24:26 +08:00
|
|
|
|
|
|
|
// Test options.
|
|
|
|
Test_options TestOptions
|
2021-01-27 03:01:43 +08:00
|
|
|
|
|
|
|
// Names of modules containing JNI libraries that should be installed alongside the test.
|
|
|
|
Jni_libs []string
|
2018-04-10 09:40:24 +08:00
|
|
|
}
|
|
|
|
|
2020-06-13 07:38:45 +08:00
|
|
|
type hostTestProperties struct {
|
|
|
|
// list of native binary modules that should be installed alongside the test
|
|
|
|
Data_native_bins []string `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
|
2019-03-20 20:45:53 +08: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"`
|
|
|
|
}
|
|
|
|
|
2019-12-04 02:06:47 +08: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 09:40:24 +08:00
|
|
|
type Test struct {
|
|
|
|
Library
|
|
|
|
|
|
|
|
testProperties testProperties
|
2018-08-08 07:49:25 +08:00
|
|
|
|
2020-08-16 03:24:26 +08:00
|
|
|
testConfig android.Path
|
|
|
|
extraTestConfigs android.Paths
|
|
|
|
data android.Paths
|
2018-08-08 07:49:25 +08:00
|
|
|
}
|
|
|
|
|
2020-06-13 07:38:45 +08:00
|
|
|
type TestHost struct {
|
|
|
|
Test
|
|
|
|
|
|
|
|
testHostProperties hostTestProperties
|
|
|
|
}
|
|
|
|
|
2019-03-20 20:45:53 +08:00
|
|
|
type TestHelperLibrary struct {
|
|
|
|
Library
|
|
|
|
|
|
|
|
testHelperLibraryProperties testHelperLibraryProperties
|
|
|
|
}
|
|
|
|
|
2019-12-04 02:06:47 +08:00
|
|
|
type JavaTestImport struct {
|
|
|
|
Import
|
|
|
|
|
|
|
|
prebuiltTestProperties prebuiltTestProperties
|
|
|
|
|
|
|
|
testConfig android.Path
|
2020-08-06 06:40:41 +08:00
|
|
|
dexJarFile android.Path
|
2019-12-04 02:06:47 +08:00
|
|
|
}
|
|
|
|
|
2020-06-13 07:38:45 +08: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-27 03:01:43 +08: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...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-13 07:38:45 +08:00
|
|
|
j.deps(ctx)
|
|
|
|
}
|
|
|
|
|
2021-03-05 05:47:56 +08:00
|
|
|
func (j *TestHost) AddExtraResource(p android.Path) {
|
|
|
|
j.extraResources = append(j.extraResources, p)
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:49:25 +08:00
|
|
|
func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2021-03-06 02:08:36 +08:00
|
|
|
if j.testProperties.Test_options.Unit_test == nil && ctx.Host() {
|
|
|
|
// TODO(b/): Clean temporary heuristic to avoid unexpected onboarding.
|
2021-03-16 04:07:53 +08:00
|
|
|
defaultUnitTest := !inList("tradefed", j.properties.Libs) && !inList("cts", j.testProperties.Test_suites)
|
2021-03-06 02:08:36 +08:00
|
|
|
j.testProperties.Test_options.Unit_test = proptools.BoolPtr(defaultUnitTest)
|
|
|
|
}
|
2019-09-27 02:41:36 +08:00
|
|
|
j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template,
|
2020-11-20 01:43:45 +08:00
|
|
|
j.testProperties.Test_suites, j.testProperties.Auto_gen_config, j.testProperties.Test_options.Unit_test)
|
2020-06-13 07:38:45 +08:00
|
|
|
|
2019-03-06 14:25:09 +08:00
|
|
|
j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data)
|
2018-08-08 07:49:25 +08:00
|
|
|
|
2020-08-16 03:24:26 +08:00
|
|
|
j.extraTestConfigs = android.PathsForModuleSrc(ctx, j.testProperties.Test_options.Extra_test_configs)
|
|
|
|
|
2020-06-13 07:38:45 +08:00
|
|
|
ctx.VisitDirectDepsWithTag(dataNativeBinsTag, func(dep android.Module) {
|
|
|
|
j.data = append(j.data, android.OutputFileForModule(ctx, dep, ""))
|
|
|
|
})
|
|
|
|
|
2021-01-27 03:01:43 +08:00
|
|
|
ctx.VisitDirectDepsWithTag(jniLibTag, func(dep android.Module) {
|
|
|
|
sharedLibInfo := ctx.OtherModuleProvider(dep, cc.SharedLibraryInfoProvider).(cc.SharedLibraryInfo)
|
|
|
|
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 07:49:25 +08:00
|
|
|
j.Library.GenerateAndroidBuildActions(ctx)
|
2018-04-10 09:40:24 +08:00
|
|
|
}
|
|
|
|
|
2019-03-20 20:45:53 +08:00
|
|
|
func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
j.Library.GenerateAndroidBuildActions(ctx)
|
|
|
|
}
|
|
|
|
|
2019-12-04 02:06:47 +08:00
|
|
|
func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.prebuiltTestProperties.Test_config, nil,
|
2020-11-20 01:43:45 +08:00
|
|
|
j.prebuiltTestProperties.Test_suites, nil, nil)
|
2019-12-04 02:06:47 +08:00
|
|
|
|
|
|
|
j.Import.GenerateAndroidBuildActions(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
type testSdkMemberType struct {
|
|
|
|
android.SdkMemberTypeBase
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mt *testSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
|
|
|
|
mctx.AddVariationDependencies(nil, dependencyTag, names...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mt *testSdkMemberType) IsInstance(module android.Module) bool {
|
|
|
|
_, ok := module.(*Test)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2020-03-20 00:11:18 +08:00
|
|
|
func (mt *testSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
|
|
|
|
return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_test_import")
|
2020-03-02 19:33:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
|
|
|
|
return &testSdkMemberProperties{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type testSdkMemberProperties struct {
|
|
|
|
android.SdkMemberPropertiesBase
|
2019-12-04 02:06:47 +08:00
|
|
|
|
2020-03-18 05:04:24 +08:00
|
|
|
JarToExport android.Path
|
|
|
|
TestConfig android.Path
|
2020-03-02 19:33:02 +08:00
|
|
|
}
|
|
|
|
|
2020-03-20 00:11:18 +08:00
|
|
|
func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
|
2020-03-02 19:33:02 +08:00
|
|
|
test := variant.(*Test)
|
|
|
|
|
|
|
|
implementationJars := test.ImplementationJars()
|
2019-12-04 02:06:47 +08:00
|
|
|
if len(implementationJars) != 1 {
|
2020-03-02 19:33:02 +08:00
|
|
|
panic(fmt.Errorf("there must be only one implementation jar from %q", test.Name()))
|
2019-12-04 02:06:47 +08:00
|
|
|
}
|
|
|
|
|
2020-03-18 05:04:24 +08:00
|
|
|
p.JarToExport = implementationJars[0]
|
|
|
|
p.TestConfig = test.testConfig
|
2020-03-02 19:33:02 +08:00
|
|
|
}
|
|
|
|
|
2020-03-20 00:11:18 +08:00
|
|
|
func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
|
2020-03-18 05:04:24 +08:00
|
|
|
builder := ctx.SnapshotBuilder()
|
2019-12-04 02:06:47 +08:00
|
|
|
|
2020-03-18 05:04:24 +08:00
|
|
|
exportedJar := p.JarToExport
|
|
|
|
if exportedJar != nil {
|
|
|
|
snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name())
|
|
|
|
builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
|
2019-12-04 02:06:47 +08:00
|
|
|
|
2020-03-02 19:33:02 +08:00
|
|
|
propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
|
2020-03-18 05:04:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
testConfig := p.TestConfig
|
|
|
|
if testConfig != nil {
|
|
|
|
snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(p.OsPrefix(), ctx.Name(), testConfigSuffix)
|
|
|
|
builder.CopyToSnapshot(testConfig, snapshotRelativeTestConfigPath)
|
2020-03-02 19:33:02 +08:00
|
|
|
propertySet.AddProperty("test_config", snapshotRelativeTestConfigPath)
|
|
|
|
}
|
2019-12-04 02:06:47 +08:00
|
|
|
}
|
|
|
|
|
2019-02-13 06:41:32 +08: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 09:40:24 +08:00
|
|
|
func TestFactory() android.Module {
|
|
|
|
module := &Test{}
|
|
|
|
|
2020-06-16 07:09:53 +08:00
|
|
|
module.addHostAndDeviceProperties()
|
|
|
|
module.AddProperties(&module.testProperties)
|
2018-04-10 09:40:24 +08:00
|
|
|
|
2018-06-27 08:59:05 +08:00
|
|
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
2019-01-06 14:30:13 +08:00
|
|
|
module.Module.dexpreopter.isTest = true
|
2020-06-03 11:09:13 +08:00
|
|
|
module.Module.linter.test = true
|
2018-06-27 08:59:05 +08:00
|
|
|
|
2018-04-10 09:40:24 +08:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2019-03-20 20:45:53 +08: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 07:09:53 +08:00
|
|
|
module.addHostAndDeviceProperties()
|
|
|
|
module.AddProperties(&module.testHelperLibraryProperties)
|
2019-03-20 20:45:53 +08:00
|
|
|
|
2019-04-25 04:19:28 +08:00
|
|
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
module.Module.dexpreopter.isTest = true
|
2020-06-03 11:09:13 +08:00
|
|
|
module.Module.linter.test = true
|
2019-04-25 04:19:28 +08:00
|
|
|
|
2019-03-20 20:45:53 +08:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2019-12-04 02:06:47 +08: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)
|
|
|
|
android.InitSdkAwareModule(module)
|
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2019-02-13 06:41:32 +08: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 09:40:24 +08:00
|
|
|
func TestHostFactory() android.Module {
|
2020-06-13 07:38:45 +08:00
|
|
|
module := &TestHost{}
|
2018-04-10 09:40:24 +08:00
|
|
|
|
2020-06-16 07:09:53 +08:00
|
|
|
module.addHostProperties()
|
|
|
|
module.AddProperties(&module.testProperties)
|
2020-06-13 07:38:45 +08:00
|
|
|
module.AddProperties(&module.testHostProperties)
|
2018-04-10 09:40:24 +08:00
|
|
|
|
2021-03-05 05:47:56 +08:00
|
|
|
InitTestHost(
|
|
|
|
module,
|
|
|
|
proptools.BoolPtr(true),
|
|
|
|
nil,
|
|
|
|
nil)
|
2018-06-27 08:59:05 +08:00
|
|
|
|
2020-06-13 07:38:45 +08:00
|
|
|
InitJavaModuleMultiTargets(module, android.HostSupported)
|
2021-03-06 02:08:36 +08:00
|
|
|
|
2018-04-10 09:40:24 +08:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2021-03-05 05:47:56 +08: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 08:20:39 +08:00
|
|
|
//
|
|
|
|
// Java Binaries (.jar file plus wrapper script)
|
|
|
|
//
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
type binaryProperties struct {
|
2015-05-12 04:39:40 +08:00
|
|
|
// installable script to execute the resulting jar
|
2019-03-05 14:35:41 +08:00
|
|
|
Wrapper *string `android:"path"`
|
2018-10-18 06:10:48 +08:00
|
|
|
|
|
|
|
// Name of the class containing main to be inserted into the manifest as Main-Class.
|
|
|
|
Main_class *string
|
2020-10-10 10:00:54 +08:00
|
|
|
|
|
|
|
// Names of modules containing JNI libraries that should be installed alongside the host
|
|
|
|
// variant of the binary.
|
|
|
|
Jni_libs []string
|
2015-05-12 04:39:40 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
type Binary struct {
|
|
|
|
Library
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
binaryProperties binaryProperties
|
2017-08-11 08:09:43 +08:00
|
|
|
|
2017-12-06 05:42:45 +08:00
|
|
|
isWrapperVariant bool
|
|
|
|
|
2017-12-09 11:12:36 +08:00
|
|
|
wrapperFile android.Path
|
2019-10-02 13:05:35 +08:00
|
|
|
binaryFile android.InstallPath
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-10-27 00:46:21 +08:00
|
|
|
func (j *Binary) HostToolPath() android.OptionalPath {
|
|
|
|
return android.OptionalPathForPath(j.binaryFile)
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2017-12-06 05:42:45 +08:00
|
|
|
if ctx.Arch().ArchType == android.Common {
|
|
|
|
// Compile the jar
|
2018-10-18 06:10:48 +08: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-06 05:42:45 +08:00
|
|
|
j.Library.GenerateAndroidBuildActions(ctx)
|
2017-11-04 05:53:31 +08:00
|
|
|
} else {
|
2017-12-06 05:42:45 +08:00
|
|
|
// Handle the binary wrapper
|
|
|
|
j.isWrapperVariant = true
|
|
|
|
|
2017-12-12 08:29:02 +08:00
|
|
|
if j.binaryProperties.Wrapper != nil {
|
2019-03-06 14:25:09 +08:00
|
|
|
j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper)
|
2017-12-06 05:42:45 +08:00
|
|
|
} else {
|
|
|
|
j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
|
|
|
|
}
|
|
|
|
|
2020-10-10 01:54:15 +08:00
|
|
|
// The host installation rules make the installed wrapper depend on all the dependencies
|
2020-10-10 10:00:54 +08: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-06 05:42:45 +08:00
|
|
|
j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
|
2020-10-10 01:54:15 +08:00
|
|
|
ctx.ModuleName(), j.wrapperFile)
|
2017-11-04 05:53:31 +08:00
|
|
|
}
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:53:04 +08:00
|
|
|
func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2021-01-26 22:18:53 +08:00
|
|
|
if ctx.Arch().ArchType == android.Common || ctx.BazelConversionMode() {
|
2017-12-06 05:42:45 +08:00
|
|
|
j.deps(ctx)
|
2021-01-26 22:18:53 +08:00
|
|
|
}
|
|
|
|
if ctx.Arch().ArchType != android.Common || ctx.BazelConversionMode() {
|
2020-11-11 10:12:15 +08: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-06 05:42:45 +08:00
|
|
|
}
|
2017-06-23 07:51:17 +08:00
|
|
|
}
|
|
|
|
|
2019-02-13 06:41:32 +08: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 06:53:04 +08:00
|
|
|
func BinaryFactory() android.Module {
|
|
|
|
module := &Binary{}
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2020-06-16 07:09:53 +08:00
|
|
|
module.addHostAndDeviceProperties()
|
|
|
|
module.AddProperties(&module.binaryProperties)
|
2017-06-24 06:06:31 +08:00
|
|
|
|
2018-06-27 08:59:05 +08:00
|
|
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
|
2017-12-06 05:42:45 +08:00
|
|
|
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
|
|
|
|
android.InitDefaultableModule(module)
|
2017-06-24 06:06:31 +08:00
|
|
|
return module
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2019-02-13 06:41:32 +08: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 06:53:04 +08:00
|
|
|
func BinaryHostFactory() android.Module {
|
|
|
|
module := &Binary{}
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2020-06-16 07:09:53 +08:00
|
|
|
module.addHostProperties()
|
|
|
|
module.AddProperties(&module.binaryProperties)
|
2017-06-24 06:06:31 +08:00
|
|
|
|
2018-06-27 08:59:05 +08:00
|
|
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
|
2017-12-06 05:42:45 +08:00
|
|
|
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
|
|
|
|
android.InitDefaultableModule(module)
|
2017-06-24 06:06:31 +08:00
|
|
|
return module
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Java prebuilts
|
|
|
|
//
|
|
|
|
|
2017-08-03 02:05:49 +08:00
|
|
|
type ImportProperties struct {
|
2020-03-02 18:16:35 +08:00
|
|
|
Jars []string `android:"path,arch_variant"`
|
2017-10-21 04:59:18 +08:00
|
|
|
|
2021-04-02 08:38:25 +08: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 13:20:04 +08:00
|
|
|
Sdk_version *string
|
2017-10-21 08:57:49 +08:00
|
|
|
|
2021-04-02 08:38:25 +08:00
|
|
|
// The minimum version of the SDK that this module supports. Defaults to sdk_version if not
|
|
|
|
// specified.
|
|
|
|
Min_sdk_version *string
|
|
|
|
|
2017-10-21 08:57:49 +08:00
|
|
|
Installable *bool
|
2018-05-28 17:02:19 +08:00
|
|
|
|
|
|
|
// List of shared java libs that this module has dependencies to
|
|
|
|
Libs []string
|
2018-07-13 03:28:41 +08: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 09:31:46 +08:00
|
|
|
|
|
|
|
// if set to true, run Jetifier against .jar file. Defaults to false.
|
2019-03-22 13:21:39 +08:00
|
|
|
Jetifier *bool
|
2019-10-21 13:53:15 +08:00
|
|
|
|
|
|
|
// set the name of the output
|
|
|
|
Stem *string
|
2020-03-24 15:44:11 +08: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
|
|
|
|
}
|
2017-08-03 02:05:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type Import struct {
|
2016-05-19 06:37:25 +08:00
|
|
|
android.ModuleBase
|
2018-10-03 04:53:33 +08:00
|
|
|
android.DefaultableModuleBase
|
2019-07-25 21:02:35 +08:00
|
|
|
android.ApexModuleBase
|
2017-07-08 05:47:12 +08:00
|
|
|
prebuilt android.Prebuilt
|
Introduce module type 'sdk'
This change introduces a new module type named 'sdk'. It is a logical
group of prebuilt modules that together provide a context (e.g. APIs)
in which Mainline modules (such as APEXes) are built.
A prebuilt module (e.g. java_import) can join an sdk by adding it to the
sdk module as shown below:
sdk {
name: "mysdk#20",
java_libs: ["myjavalib_mysdk_20"],
}
java_import {
name: "myjavalib_mysdk_20",
srcs: ["myjavalib-v20.jar"],
sdk_member_name: "myjavalib",
}
sdk {
name: "mysdk#21",
java_libs: ["myjavalib_mysdk_21"],
}
java_import {
name: "myjavalib_mysdk_21",
srcs: ["myjavalib-v21.jar"],
sdk_member_name: "myjavalib",
}
java_library {
name: "myjavalib",
srcs: ["**/*/*.java"],
}
An APEX can specify the SDK(s) that it wants to build with via the new
'uses_sdks' property.
apex {
name: "myapex",
java_libs: ["libX", "libY"],
uses_sdks: ["mysdk#20"],
}
With this, libX, libY, and their transitive dependencies are all built
with the version 20 of myjavalib (the first java_import module) instead
of the other one (which is for version 21) and java_library having the
same name (which is for ToT).
Bug: 138182343
Test: m (sdk_test.go added)
Change-Id: I7e14c524a7d6a0d9f575fb20822080f39818c01e
2019-07-17 19:08:41 +08:00
|
|
|
android.SdkBase
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2020-05-17 15:34:50 +08:00
|
|
|
// Functionality common to Module and Import.
|
|
|
|
embeddableInModuleAndImport
|
|
|
|
|
2020-08-06 06:40:41 +08:00
|
|
|
hiddenAPI
|
|
|
|
dexer
|
2020-12-24 08:13:04 +08:00
|
|
|
dexpreopter
|
2020-08-06 06:40:41 +08:00
|
|
|
|
2017-08-03 02:05:49 +08:00
|
|
|
properties ImportProperties
|
|
|
|
|
2020-08-06 06:40:41 +08:00
|
|
|
// output file containing classes.dex and resources
|
|
|
|
dexJarFile android.Path
|
|
|
|
|
2017-08-31 05:24:55 +08:00
|
|
|
combinedClasspathFile android.Path
|
2020-10-08 19:53:58 +08:00
|
|
|
classLoaderContexts dexpreopt.ClassLoaderContextMap
|
2020-03-24 15:44:11 +08:00
|
|
|
exportAidlIncludeDirs android.Paths
|
2020-09-16 09:30:11 +08:00
|
|
|
|
|
|
|
hideApexVariantFromMake bool
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2021-04-02 07:45:46 +08:00
|
|
|
sdkVersion android.SdkSpec
|
|
|
|
minSdkVersion android.SdkSpec
|
2018-06-26 06:48:06 +08:00
|
|
|
}
|
|
|
|
|
2021-04-02 07:45:46 +08:00
|
|
|
func (j *Import) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
|
|
|
|
return android.SdkSpecFrom(ctx, String(j.properties.Sdk_version))
|
2020-08-13 05:42:30 +08:00
|
|
|
}
|
|
|
|
|
2021-03-29 19:11:58 +08:00
|
|
|
func (j *Import) SystemModules() string {
|
2020-08-06 06:40:41 +08:00
|
|
|
return "none"
|
|
|
|
}
|
|
|
|
|
2021-04-02 07:45:46 +08:00
|
|
|
func (j *Import) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
|
2021-04-02 08:38:25 +08:00
|
|
|
if j.properties.Min_sdk_version != nil {
|
2021-04-02 07:45:46 +08:00
|
|
|
return android.SdkSpecFrom(ctx, *j.properties.Min_sdk_version)
|
2021-04-02 08:38:25 +08:00
|
|
|
}
|
2021-04-02 07:45:46 +08:00
|
|
|
return j.SdkVersion(ctx)
|
2018-06-26 06:48:06 +08:00
|
|
|
}
|
|
|
|
|
2021-04-02 07:45:46 +08:00
|
|
|
func (j *Import) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
|
|
|
|
return j.SdkVersion(ctx)
|
2020-04-28 01:53:18 +08:00
|
|
|
}
|
|
|
|
|
2017-08-03 02:05:49 +08:00
|
|
|
func (j *Import) Prebuilt() *android.Prebuilt {
|
2017-07-08 05:47:12 +08:00
|
|
|
return &j.prebuilt
|
|
|
|
}
|
|
|
|
|
2017-08-03 02:05:49 +08:00
|
|
|
func (j *Import) PrebuiltSrcs() []string {
|
|
|
|
return j.properties.Jars
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *Import) Name() string {
|
2017-07-28 06:41:32 +08:00
|
|
|
return j.prebuilt.Name(j.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
2019-10-29 10:23:10 +08:00
|
|
|
func (j *Import) Stem() string {
|
|
|
|
return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
2020-01-08 12:35:43 +08:00
|
|
|
func (a *Import) JacocoReportClassesFile() android.Path {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-01-12 02:58:54 +08:00
|
|
|
func (j *Import) LintDepSets() LintDepSets {
|
|
|
|
return LintDepSets{}
|
|
|
|
}
|
|
|
|
|
2017-08-03 02:05:49 +08:00
|
|
|
func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2018-08-30 05:10:52 +08:00
|
|
|
ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
|
2020-08-06 06:40:41 +08:00
|
|
|
|
|
|
|
if ctx.Device() && Bool(j.dexProperties.Compile_dex) {
|
2021-03-29 19:11:58 +08:00
|
|
|
sdkDeps(ctx, android.SdkContext(j), j.dexer)
|
2020-08-06 06:40:41 +08:00
|
|
|
}
|
2016-10-13 05:38:15 +08:00
|
|
|
}
|
|
|
|
|
2017-08-03 02:05:49 +08:00
|
|
|
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2021-04-02 07:45:46 +08:00
|
|
|
j.sdkVersion = j.SdkVersion(ctx)
|
|
|
|
j.minSdkVersion = j.MinSdkVersion(ctx)
|
|
|
|
|
2021-02-02 03:01:34 +08:00
|
|
|
// Initialize the hiddenapi structure.
|
|
|
|
j.initHiddenAPI(ctx, j.BaseModuleName())
|
|
|
|
|
2020-09-16 09:30:11 +08:00
|
|
|
if !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() {
|
|
|
|
j.hideApexVariantFromMake = true
|
|
|
|
}
|
|
|
|
|
2019-03-06 14:25:09 +08:00
|
|
|
jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
|
2017-08-03 02:05:49 +08:00
|
|
|
|
2019-10-29 10:23:10 +08:00
|
|
|
jarName := j.Stem() + ".jar"
|
2018-08-28 09:31:46 +08:00
|
|
|
outputFile := android.PathForModuleOut(ctx, "combined", jarName)
|
2018-07-13 03:28:41 +08:00
|
|
|
TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
|
|
|
|
false, j.properties.Exclude_files, j.properties.Exclude_dirs)
|
2019-03-22 13:21:39 +08:00
|
|
|
if Bool(j.properties.Jetifier) {
|
2018-08-28 09:31:46 +08:00
|
|
|
inputFile := outputFile
|
|
|
|
outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
|
|
|
|
TransformJetifier(ctx, outputFile, inputFile)
|
|
|
|
}
|
2017-10-17 08:09:48 +08:00
|
|
|
j.combinedClasspathFile = outputFile
|
2020-10-08 19:53:58 +08:00
|
|
|
j.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap)
|
2020-05-15 17:20:31 +08:00
|
|
|
|
2020-08-06 06:40:41 +08:00
|
|
|
var flags javaBuilderFlags
|
2020-11-03 01:32:38 +08:00
|
|
|
var deapexerModule android.Module
|
2020-08-06 06:40:41 +08:00
|
|
|
|
2018-05-28 17:02:19 +08:00
|
|
|
ctx.VisitDirectDeps(func(module android.Module) {
|
|
|
|
tag := ctx.OtherModuleDependencyTag(module)
|
|
|
|
|
2021-02-02 05:59:03 +08:00
|
|
|
if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
|
|
|
|
dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
|
2018-05-28 17:02:19 +08:00
|
|
|
switch tag {
|
|
|
|
case libTag, staticLibTag:
|
2021-02-02 05:59:03 +08:00
|
|
|
flags.classpath = append(flags.classpath, dep.HeaderJars...)
|
2020-08-06 06:40:41 +08:00
|
|
|
case bootClasspathTag:
|
2021-02-02 05:59:03 +08:00
|
|
|
flags.bootClasspath = append(flags.bootClasspath, dep.HeaderJars...)
|
2018-05-28 17:02:19 +08:00
|
|
|
}
|
2021-02-02 05:59:03 +08:00
|
|
|
} else if dep, ok := module.(SdkLibraryDependency); ok {
|
2018-05-28 17:02:19 +08:00
|
|
|
switch tag {
|
|
|
|
case libTag:
|
2021-04-02 07:45:46 +08:00
|
|
|
flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...)
|
2018-05-28 17:02:19 +08:00
|
|
|
}
|
|
|
|
}
|
2020-12-04 00:50:22 +08:00
|
|
|
|
2020-12-17 00:16:11 +08:00
|
|
|
addCLCFromDep(ctx, module, j.classLoaderContexts)
|
2020-11-03 01:32:38 +08:00
|
|
|
|
|
|
|
// Save away the `deapexer` module on which this depends, if any.
|
|
|
|
if tag == android.DeapexerTag {
|
|
|
|
deapexerModule = module
|
|
|
|
}
|
2018-05-28 17:02:19 +08:00
|
|
|
})
|
|
|
|
|
2018-08-11 04:42:12 +08:00
|
|
|
if Bool(j.properties.Installable) {
|
2020-12-17 00:16:11 +08:00
|
|
|
ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
|
2019-10-21 13:53:15 +08:00
|
|
|
jarName, outputFile)
|
2018-08-11 04:42:12 +08:00
|
|
|
}
|
2020-03-24 15:44:11 +08:00
|
|
|
|
|
|
|
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs)
|
2020-08-06 06:40:41 +08:00
|
|
|
|
2020-11-03 01:32:38 +08: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.
|
|
|
|
ai := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
|
|
|
|
if ai.ForPrebuiltApex {
|
|
|
|
if deapexerModule == nil {
|
|
|
|
// This should never happen as a variant for a prebuilt_apex is only created if the
|
|
|
|
// deapxer module has been configured to export the dex implementation jar for this module.
|
|
|
|
ctx.ModuleErrorf("internal error: module %q does not depend on a `deapexer` module for prebuilt_apex %q",
|
|
|
|
j.Name(), ai.ApexVariationName)
|
|
|
|
}
|
2020-08-06 06:40:41 +08:00
|
|
|
|
2020-11-03 01:32:38 +08:00
|
|
|
// Get the path of the dex implementation jar from the `deapexer` module.
|
|
|
|
di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo)
|
2021-02-04 04:06:33 +08:00
|
|
|
if dexOutputPath := di.PrebuiltExportPath(j.BaseModuleName(), ".dexjar"); dexOutputPath != nil {
|
|
|
|
j.dexJarFile = dexOutputPath
|
2021-02-09 22:34:25 +08:00
|
|
|
j.hiddenAPIExtractInformation(ctx, dexOutputPath, outputFile)
|
2021-02-04 04:06:33 +08:00
|
|
|
} else {
|
2020-11-03 01:32:38 +08: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.
|
|
|
|
ctx.ModuleErrorf("internal error: no dex implementation jar available from prebuilt_apex %q", deapexerModule.Name())
|
|
|
|
}
|
|
|
|
} else if Bool(j.dexProperties.Compile_dex) {
|
2021-03-29 19:11:58 +08:00
|
|
|
sdkDep := decodeSdkDep(ctx, android.SdkContext(j))
|
2020-11-03 01:32:38 +08: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 08:13:04 +08:00
|
|
|
|
2020-11-03 01:32:38 +08:00
|
|
|
// Dex compilation
|
2020-12-24 08:13:04 +08:00
|
|
|
|
2020-11-03 01:32:38 +08:00
|
|
|
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", jarName)
|
|
|
|
if j.dexProperties.Uncompress_dex == nil {
|
|
|
|
// If the value was not force-set by the user, use reasonable default based on the module.
|
|
|
|
j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter))
|
|
|
|
}
|
|
|
|
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
|
2020-08-06 06:40:41 +08:00
|
|
|
|
2021-02-02 21:38:13 +08:00
|
|
|
var dexOutputFile android.OutputPath
|
2021-04-02 07:45:46 +08:00
|
|
|
dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(ctx), outputFile, jarName)
|
2020-11-03 01:32:38 +08:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2020-08-06 06:40:41 +08:00
|
|
|
|
2020-11-03 01:32:38 +08:00
|
|
|
// Hidden API CSV generation and dex encoding
|
2021-02-09 22:34:25 +08:00
|
|
|
dexOutputFile = j.hiddenAPIExtractAndEncode(ctx, dexOutputFile, outputFile,
|
2020-11-03 01:32:38 +08:00
|
|
|
proptools.Bool(j.dexProperties.Uncompress_dex))
|
|
|
|
|
|
|
|
j.dexJarFile = dexOutputFile
|
|
|
|
}
|
2020-08-06 06:40:41 +08:00
|
|
|
}
|
2021-02-02 05:59:03 +08:00
|
|
|
|
|
|
|
ctx.SetProvider(JavaInfoProvider, JavaInfo{
|
|
|
|
HeaderJars: android.PathsIfNonNil(j.combinedClasspathFile),
|
|
|
|
ImplementationAndResourcesJars: android.PathsIfNonNil(j.combinedClasspathFile),
|
|
|
|
ImplementationJars: android.PathsIfNonNil(j.combinedClasspathFile),
|
|
|
|
AidlIncludeDirs: j.exportAidlIncludeDirs,
|
|
|
|
})
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2020-10-07 00:20:13 +08:00
|
|
|
func (j *Import) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
switch tag {
|
2020-10-16 01:54:40 +08:00
|
|
|
case "", ".jar":
|
2020-10-07 00:20:13 +08: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-20 04:06:22 +08:00
|
|
|
func (j *Import) HeaderJars() android.Paths {
|
2018-12-25 14:35:23 +08:00
|
|
|
if j.combinedClasspathFile == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2018-07-13 03:28:41 +08:00
|
|
|
return android.Paths{j.combinedClasspathFile}
|
2017-10-20 04:06:22 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 11:40:52 +08:00
|
|
|
func (j *Import) ImplementationAndResourcesJars() android.Paths {
|
2018-12-25 14:35:23 +08:00
|
|
|
if j.combinedClasspathFile == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2018-08-16 11:40:52 +08:00
|
|
|
return android.Paths{j.combinedClasspathFile}
|
|
|
|
}
|
|
|
|
|
2020-06-04 22:08:17 +08:00
|
|
|
func (j *Import) DexJarBuildPath() android.Path {
|
2020-08-06 06:40:41 +08:00
|
|
|
return j.dexJarFile
|
2019-02-01 06:12:44 +08:00
|
|
|
}
|
|
|
|
|
2020-06-09 21:31:19 +08:00
|
|
|
func (j *Import) DexJarInstallPath() android.Path {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-10-08 19:53:58 +08:00
|
|
|
func (j *Import) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
|
|
|
|
return j.classLoaderContexts
|
2018-05-28 17:02:19 +08:00
|
|
|
}
|
|
|
|
|
2020-12-15 21:29:02 +08: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-31 01:49:53 +08:00
|
|
|
func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
|
2020-05-17 15:34:50 +08: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-31 01:49:53 +08:00
|
|
|
}
|
|
|
|
|
2020-12-15 21:29:02 +08:00
|
|
|
// Implements android.ApexModule
|
2020-07-23 13:32:17 +08:00
|
|
|
func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
|
|
|
|
sdkVersion android.ApiLevel) error {
|
2021-04-02 07:45:46 +08:00
|
|
|
sdkSpec := j.MinSdkVersion(ctx)
|
2021-03-29 19:11:58 +08:00
|
|
|
if !sdkSpec.Specified() {
|
2021-04-02 08:38:25 +08:00
|
|
|
return fmt.Errorf("min_sdk_version is not specified")
|
|
|
|
}
|
2021-03-29 19:11:58 +08:00
|
|
|
if sdkSpec.Kind == android.SdkCore {
|
2021-04-02 08:38:25 +08:00
|
|
|
return nil
|
|
|
|
}
|
2021-03-29 19:11:58 +08:00
|
|
|
ver, err := sdkSpec.EffectiveVersion(ctx)
|
2021-04-02 08:38:25 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-03-31 17:17:53 +08:00
|
|
|
if ver.GreaterThan(sdkVersion) {
|
2021-04-02 08:38:25 +08:00
|
|
|
return fmt.Errorf("newer SDK(%v)", ver)
|
|
|
|
}
|
2020-04-15 10:03:39 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-12-25 14:35:23 +08:00
|
|
|
// Add compile time check for interface implementation
|
|
|
|
var _ android.IDEInfo = (*Import)(nil)
|
|
|
|
var _ android.IDECustomizedModuleName = (*Import)(nil)
|
|
|
|
|
2018-08-16 06:35:38 +08:00
|
|
|
// Collect information for opening IDE project files in java/jdeps.go.
|
|
|
|
const (
|
|
|
|
removedPrefix = "prebuilt_"
|
|
|
|
)
|
|
|
|
|
|
|
|
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.
|
|
|
|
name := j.Name()
|
|
|
|
if strings.HasPrefix(name, removedPrefix) {
|
2018-10-11 18:33:16 +08:00
|
|
|
name = strings.TrimPrefix(name, removedPrefix)
|
2018-08-16 06:35:38 +08:00
|
|
|
}
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
2017-08-03 02:05:49 +08:00
|
|
|
var _ android.PrebuiltInterface = (*Import)(nil)
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2020-12-24 08:13:04 +08:00
|
|
|
func (j *Import) IsInstallable() bool {
|
|
|
|
return Bool(j.properties.Installable)
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ dexpreopterInterface = (*Import)(nil)
|
|
|
|
|
2019-02-13 06:41:32 +08: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-03 02:05:49 +08:00
|
|
|
func ImportFactory() android.Module {
|
|
|
|
module := &Import{}
|
2017-06-24 06:06:31 +08:00
|
|
|
|
2020-08-06 06:40:41 +08:00
|
|
|
module.AddProperties(
|
|
|
|
&module.properties,
|
|
|
|
&module.dexer.dexProperties,
|
|
|
|
)
|
2017-08-03 02:05:49 +08:00
|
|
|
|
2020-05-15 17:20:31 +08:00
|
|
|
module.initModuleAndImport(&module.ModuleBase)
|
|
|
|
|
2020-08-06 06:40:41 +08:00
|
|
|
module.dexProperties.Optimize.EnabledByDefault = false
|
|
|
|
|
2017-08-03 02:05:49 +08:00
|
|
|
android.InitPrebuiltModule(module, &module.properties.Jars)
|
2019-07-25 21:02:35 +08:00
|
|
|
android.InitApexModule(module)
|
Introduce module type 'sdk'
This change introduces a new module type named 'sdk'. It is a logical
group of prebuilt modules that together provide a context (e.g. APIs)
in which Mainline modules (such as APEXes) are built.
A prebuilt module (e.g. java_import) can join an sdk by adding it to the
sdk module as shown below:
sdk {
name: "mysdk#20",
java_libs: ["myjavalib_mysdk_20"],
}
java_import {
name: "myjavalib_mysdk_20",
srcs: ["myjavalib-v20.jar"],
sdk_member_name: "myjavalib",
}
sdk {
name: "mysdk#21",
java_libs: ["myjavalib_mysdk_21"],
}
java_import {
name: "myjavalib_mysdk_21",
srcs: ["myjavalib-v21.jar"],
sdk_member_name: "myjavalib",
}
java_library {
name: "myjavalib",
srcs: ["**/*/*.java"],
}
An APEX can specify the SDK(s) that it wants to build with via the new
'uses_sdks' property.
apex {
name: "myapex",
java_libs: ["libX", "libY"],
uses_sdks: ["mysdk#20"],
}
With this, libX, libY, and their transitive dependencies are all built
with the version 20 of myjavalib (the first java_import module) instead
of the other one (which is for version 21) and java_library having the
same name (which is for ToT).
Bug: 138182343
Test: m (sdk_test.go added)
Change-Id: I7e14c524a7d6a0d9f575fb20822080f39818c01e
2019-07-17 19:08:41 +08:00
|
|
|
android.InitSdkAwareModule(module)
|
2019-11-13 09:50:48 +08:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
2017-06-24 06:06:31 +08:00
|
|
|
return module
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2019-02-13 06:41:32 +08: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-03 02:05:49 +08:00
|
|
|
func ImportFactoryHost() android.Module {
|
|
|
|
module := &Import{}
|
|
|
|
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
|
|
|
|
android.InitPrebuiltModule(module, &module.properties.Jars)
|
2019-07-25 21:02:35 +08:00
|
|
|
android.InitApexModule(module)
|
2019-11-13 09:50:48 +08:00
|
|
|
InitJavaModule(module, android.HostSupported)
|
2017-08-03 02:05:49 +08:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2019-02-22 10:12:14 +08:00
|
|
|
// dex_import module
|
|
|
|
|
|
|
|
type DexImportProperties struct {
|
2019-07-16 04:36:55 +08:00
|
|
|
Jars []string `android:"path"`
|
2019-10-21 13:53:15 +08:00
|
|
|
|
|
|
|
// set the name of the output
|
|
|
|
Stem *string
|
2019-02-22 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type DexImport struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultableModuleBase
|
2019-07-25 21:02:35 +08:00
|
|
|
android.ApexModuleBase
|
2019-02-22 10:12:14 +08:00
|
|
|
prebuilt android.Prebuilt
|
|
|
|
|
|
|
|
properties DexImportProperties
|
|
|
|
|
2021-02-27 06:54:36 +08:00
|
|
|
dexJarFile android.Path
|
2019-02-22 10:12:14 +08:00
|
|
|
|
|
|
|
dexpreopter
|
2020-09-16 09:30:11 +08:00
|
|
|
|
|
|
|
hideApexVariantFromMake bool
|
2019-02-22 10:12:14 +08: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 10:23:10 +08:00
|
|
|
func (j *DexImport) Stem() string {
|
|
|
|
return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
2020-06-01 20:39:15 +08:00
|
|
|
func (a *DexImport) JacocoReportClassesFile() android.Path {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-22 11:31:17 +08:00
|
|
|
func (a *DexImport) LintDepSets() LintDepSets {
|
|
|
|
return LintDepSets{}
|
|
|
|
}
|
|
|
|
|
2020-02-01 01:10:36 +08:00
|
|
|
func (j *DexImport) IsInstallable() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-02-22 10:12:14 +08:00
|
|
|
func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
if len(j.properties.Jars) != 1 {
|
|
|
|
ctx.PropertyErrorf("jars", "exactly one jar must be provided")
|
|
|
|
}
|
|
|
|
|
2020-09-16 09:30:11 +08:00
|
|
|
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
|
|
|
|
if !apexInfo.IsForPlatform() {
|
|
|
|
j.hideApexVariantFromMake = true
|
|
|
|
}
|
|
|
|
|
2019-10-29 10:23:10 +08:00
|
|
|
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
|
2019-02-22 10:12:14 +08:00
|
|
|
j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
|
|
|
|
|
|
|
|
inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars")
|
|
|
|
dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar")
|
|
|
|
|
|
|
|
if j.dexpreopter.uncompressedDex {
|
2020-11-17 09:32:30 +08:00
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
2019-02-22 10:12:14 +08:00
|
|
|
|
|
|
|
temporary := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar.unaligned")
|
|
|
|
rule.Temporary(temporary)
|
|
|
|
|
|
|
|
// use zip2zip to uncompress classes*.dex files
|
|
|
|
rule.Command().
|
2020-11-17 09:32:30 +08:00
|
|
|
BuiltTool("zip2zip").
|
2019-02-22 10:12:14 +08:00
|
|
|
FlagWithInput("-i ", inputJar).
|
|
|
|
FlagWithOutput("-o ", temporary).
|
|
|
|
FlagWithArg("-0 ", "'classes*.dex'")
|
|
|
|
|
|
|
|
// use zipalign to align uncompressed classes*.dex files
|
|
|
|
rule.Command().
|
2020-11-17 09:32:30 +08:00
|
|
|
BuiltTool("zipalign").
|
2019-02-22 10:12:14 +08:00
|
|
|
Flag("-f").
|
|
|
|
Text("4").
|
|
|
|
Input(temporary).
|
|
|
|
Output(dexOutputFile)
|
|
|
|
|
|
|
|
rule.DeleteTemporaryFiles()
|
|
|
|
|
2020-11-17 09:32:30 +08:00
|
|
|
rule.Build("uncompress_dex", "uncompress dex")
|
2019-02-22 10:12:14 +08:00
|
|
|
} else {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Cp,
|
|
|
|
Input: inputJar,
|
|
|
|
Output: dexOutputFile,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
j.dexJarFile = dexOutputFile
|
|
|
|
|
2020-12-18 01:43:28 +08:00
|
|
|
j.dexpreopt(ctx, dexOutputFile)
|
2019-02-22 10:12:14 +08:00
|
|
|
|
2020-09-16 09:30:11 +08:00
|
|
|
if apexInfo.IsForPlatform() {
|
2020-06-08 18:24:09 +08:00
|
|
|
ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
|
|
|
|
j.Stem()+".jar", dexOutputFile)
|
|
|
|
}
|
2019-02-22 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2020-06-04 22:08:17 +08:00
|
|
|
func (j *DexImport) DexJarBuildPath() android.Path {
|
2019-02-22 10:12:14 +08:00
|
|
|
return j.dexJarFile
|
|
|
|
}
|
|
|
|
|
2020-12-15 21:29:02 +08:00
|
|
|
var _ android.ApexModule = (*DexImport)(nil)
|
|
|
|
|
|
|
|
// Implements android.ApexModule
|
2020-07-23 13:32:17 +08:00
|
|
|
func (j *DexImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
|
|
|
|
sdkVersion android.ApiLevel) error {
|
2020-04-15 10:03:39 +08:00
|
|
|
// we don't check prebuilt modules for sdk_version
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-02-22 10:12:14 +08: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 21:02:35 +08:00
|
|
|
android.InitApexModule(module)
|
2019-11-13 09:50:48 +08:00
|
|
|
InitJavaModule(module, android.DeviceSupported)
|
2019-02-22 10:12:14 +08:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2017-07-08 05:35:50 +08:00
|
|
|
//
|
|
|
|
// Defaults
|
|
|
|
//
|
|
|
|
type Defaults struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultsModuleBase
|
2019-07-25 21:02:35 +08:00
|
|
|
android.ApexModuleBase
|
2017-07-08 05:35:50 +08:00
|
|
|
}
|
|
|
|
|
2019-02-13 06:41:32 +08: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:
|
|
|
|
//
|
|
|
|
// java_defaults {
|
|
|
|
// name: "example_defaults",
|
|
|
|
// srcs: ["common/**/*.java"],
|
|
|
|
// javacflags: ["-Xlint:all"],
|
|
|
|
// aaptflags: ["--auto-add-overlay"],
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// java_library {
|
|
|
|
// name: "example",
|
|
|
|
// defaults: ["example_defaults"],
|
|
|
|
// srcs: ["example/**/*.java"],
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// is functionally identical to:
|
|
|
|
//
|
|
|
|
// java_library {
|
|
|
|
// name: "example",
|
|
|
|
// srcs: [
|
|
|
|
// "common/**/*.java",
|
|
|
|
// "example/**/*.java",
|
|
|
|
// ],
|
|
|
|
// javacflags: ["-Xlint:all"],
|
|
|
|
// }
|
2019-12-05 22:07:14 +08:00
|
|
|
func DefaultsFactory() android.Module {
|
2017-07-08 05:35:50 +08:00
|
|
|
module := &Defaults{}
|
|
|
|
|
|
|
|
module.AddProperties(
|
2021-03-11 09:02:43 +08:00
|
|
|
&CommonProperties{},
|
|
|
|
&DeviceProperties{},
|
2020-07-10 06:16:41 +08:00
|
|
|
&DexProperties{},
|
2018-11-13 02:13:39 +08:00
|
|
|
&DexpreoptProperties{},
|
2018-03-09 05:27:59 +08:00
|
|
|
&android.ProtoProperties{},
|
2018-10-03 04:53:33 +08:00
|
|
|
&aaptProperties{},
|
|
|
|
&androidLibraryProperties{},
|
|
|
|
&appProperties{},
|
|
|
|
&appTestProperties{},
|
2019-03-01 07:35:54 +08:00
|
|
|
&overridableAppProperties{},
|
2020-02-04 23:45:49 +08:00
|
|
|
&testProperties{},
|
2018-10-03 04:53:33 +08:00
|
|
|
&ImportProperties{},
|
|
|
|
&AARImportProperties{},
|
|
|
|
&sdkLibraryProperties{},
|
2020-05-08 20:44:43 +08:00
|
|
|
&commonToSdkLibraryAndImportProperties{},
|
2019-02-22 10:12:14 +08:00
|
|
|
&DexImportProperties{},
|
2019-11-13 09:50:48 +08:00
|
|
|
&android.ApexProperties{},
|
2020-04-27 06:10:51 +08:00
|
|
|
&RuntimeResourceOverlayProperties{},
|
2020-06-03 11:09:13 +08:00
|
|
|
&LintProperties{},
|
2021-02-10 02:38:30 +08:00
|
|
|
&appTestHelperAppProperties{},
|
2017-07-08 05:35:50 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
android.InitDefaultsModule(module)
|
|
|
|
return module
|
|
|
|
}
|
2017-11-09 13:20:04 +08:00
|
|
|
|
2018-11-06 08:49:08 +08: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-05 04:25:17 +08:00
|
|
|
ctx.Phony("xref_java", xrefTargets...)
|
2018-11-06 08:49:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-09 13:20:04 +08:00
|
|
|
var Bool = proptools.Bool
|
2018-04-11 07:14:46 +08:00
|
|
|
var BoolDefault = proptools.BoolDefault
|
2017-11-09 13:20:04 +08:00
|
|
|
var String = proptools.String
|
2018-02-21 05:33:42 +08:00
|
|
|
var inList = android.InList
|
2020-12-04 00:50:22 +08:00
|
|
|
|
2020-12-17 00:16:11 +08: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
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find out if the dependency is either an SDK library or an ordinary library that is disguised
|
|
|
|
// as an SDK library by the means of `provides_uses_lib` property. If yes, the library is itself
|
|
|
|
// a <uses-library> and 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.
|
|
|
|
var implicitSdkLib *string
|
|
|
|
comp, isComp := depModule.(SdkLibraryComponentDependency)
|
|
|
|
if isComp {
|
|
|
|
implicitSdkLib = comp.OptionalImplicitSdkLibrary()
|
|
|
|
// OptionalImplicitSdkLibrary() may be nil so need to fall through to ProvidesUsesLib().
|
|
|
|
}
|
|
|
|
if implicitSdkLib == nil {
|
|
|
|
if ulib, ok := depModule.(ProvidesUsesLib); ok {
|
|
|
|
implicitSdkLib = ulib.ProvidesUsesLib()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
depTag := ctx.OtherModuleDependencyTag(depModule)
|
|
|
|
if depTag == libTag || depTag == usesLibTag {
|
|
|
|
// Ok, propagate <uses-library> through non-static library dependencies.
|
|
|
|
} 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.
|
|
|
|
if implicitSdkLib != nil {
|
|
|
|
return
|
2020-12-04 00:50:22 +08:00
|
|
|
}
|
2020-12-17 00:16:11 +08:00
|
|
|
} else {
|
|
|
|
// Don't propagate <uses-library> for other dependency tags.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if implicitSdkLib != nil {
|
2021-01-05 23:41:55 +08:00
|
|
|
clcMap.AddContext(ctx, dexpreopt.AnySdkVersion, *implicitSdkLib,
|
2020-12-17 00:16:11 +08:00
|
|
|
dep.DexJarBuildPath(), dep.DexJarInstallPath(), dep.ClassLoaderContexts())
|
|
|
|
} else {
|
|
|
|
depName := ctx.OtherModuleName(depModule)
|
|
|
|
clcMap.AddContextMap(dep.ClassLoaderContexts(), depName)
|
2020-12-04 00:50:22 +08:00
|
|
|
}
|
|
|
|
}
|