2015-03-31 02:20:39 +02:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package java
|
|
|
|
|
|
|
|
// This file contains the module types for compiling Java for Android, and converts the properties
|
2017-06-23 01:51:17 +02:00
|
|
|
// into the flags and filenames necessary to pass to the Module. The final creation of the rules
|
2015-03-31 02:20:39 +02:00
|
|
|
// is handled in builder.go
|
|
|
|
|
|
|
|
import (
|
2018-03-26 23:42:44 +02:00
|
|
|
"fmt"
|
2017-09-19 02:41:52 +02:00
|
|
|
"path/filepath"
|
2017-08-02 20:05:49 +02:00
|
|
|
"strconv"
|
2015-03-31 02:20:39 +02:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2019-09-06 01:44:18 +02:00
|
|
|
"github.com/google/blueprint/pathtools"
|
2017-08-30 01:02:06 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
"android/soong/android"
|
2020-08-14 18:32:16 +02:00
|
|
|
"android/soong/dexpreopt"
|
2017-06-23 02:20:19 +02:00
|
|
|
"android/soong/java/config"
|
2018-08-08 01:49:25 +02:00
|
|
|
"android/soong/tradefed"
|
2015-03-31 02:20:39 +02:00
|
|
|
)
|
|
|
|
|
2015-06-17 23:20:06 +02:00
|
|
|
func init() {
|
2019-12-18 20:51:55 +01:00
|
|
|
RegisterJavaBuildComponents(android.InitRegistrationContext)
|
2019-12-13 12:22:16 +01:00
|
|
|
|
|
|
|
// Register sdk member types.
|
2020-01-13 22:03:22 +01:00
|
|
|
android.RegisterSdkMemberType(javaHeaderLibsSdkMemberType)
|
2019-12-13 12:22:16 +01:00
|
|
|
|
2021-02-04 12:15:34 +01:00
|
|
|
// Export implementation classes jar as part of the sdk.
|
|
|
|
exportImplementationClassesJar := func(_ android.SdkMemberContext, j *Library) android.Path {
|
|
|
|
implementationJars := j.ImplementationAndResourcesJars()
|
|
|
|
if len(implementationJars) != 1 {
|
|
|
|
panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name()))
|
|
|
|
}
|
|
|
|
return implementationJars[0]
|
|
|
|
}
|
|
|
|
|
2020-12-08 18:48:25 +01:00
|
|
|
// Register java implementation libraries for use only in module_exports (not sdk).
|
2020-02-28 15:39:53 +01:00
|
|
|
android.RegisterSdkMemberType(&librarySdkMemberType{
|
|
|
|
android.SdkMemberTypeBase{
|
|
|
|
PropertyName: "java_libs",
|
|
|
|
},
|
2021-02-04 12:15:34 +01:00
|
|
|
exportImplementationClassesJar,
|
2020-12-08 18:48:25 +01:00
|
|
|
sdkSnapshotFilePathForJar,
|
|
|
|
copyEverythingToSnapshot,
|
2019-12-13 12:22:16 +01:00
|
|
|
})
|
2019-12-03 19:06:47 +01:00
|
|
|
|
2020-12-08 18:48:25 +01:00
|
|
|
// Register java boot libraries for use in sdk.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
android.RegisterSdkMemberType(&librarySdkMemberType{
|
|
|
|
android.SdkMemberTypeBase{
|
|
|
|
PropertyName: "java_boot_libs",
|
|
|
|
SupportsSdk: true,
|
|
|
|
},
|
2021-02-04 12:15:34 +01: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-08 18:48:25 +01:00
|
|
|
onlyCopyJarToSnapshot,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Register java test libraries for use only in module_exports (not sdk).
|
2019-12-03 19:06:47 +01:00
|
|
|
android.RegisterSdkMemberType(&testSdkMemberType{
|
|
|
|
SdkMemberTypeBase: android.SdkMemberTypeBase{
|
|
|
|
PropertyName: "java_tests",
|
|
|
|
},
|
|
|
|
})
|
2015-06-17 23:20:06 +02:00
|
|
|
}
|
|
|
|
|
2019-12-18 20:51:55 +01:00
|
|
|
func RegisterJavaBuildComponents(ctx android.RegistrationContext) {
|
|
|
|
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)
|
2019-12-03 19:06:47 +01:00
|
|
|
ctx.RegisterModuleType("java_test_import", JavaTestImportFactory)
|
2019-12-18 20:51:55 +01:00
|
|
|
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)
|
|
|
|
|
2020-01-31 18:10:36 +01:00
|
|
|
ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) {
|
|
|
|
ctx.BottomUp("dexpreopt_tool_deps", dexpreoptToolDepsMutator).Parallel()
|
|
|
|
})
|
2020-01-11 01:37:30 +01:00
|
|
|
|
2019-12-18 20:51:55 +01:00
|
|
|
ctx.RegisterSingletonType("logtags", LogtagsSingleton)
|
|
|
|
ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
|
|
|
|
}
|
|
|
|
|
2020-04-15 18:29:42 +02:00
|
|
|
func (j *Module) CheckStableSdkVersion() error {
|
|
|
|
sdkVersion := j.sdkVersion()
|
|
|
|
if sdkVersion.stable() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return fmt.Errorf("non stable SDK %v", sdkVersion)
|
|
|
|
}
|
|
|
|
|
2020-04-08 20:09:30 +02:00
|
|
|
func (j *Module) checkSdkVersions(ctx android.ModuleContext) {
|
2020-05-13 20:05:02 +02:00
|
|
|
if j.RequiresStableAPIs(ctx) {
|
2019-10-29 07:44:45 +01:00
|
|
|
if sc, ok := ctx.Module().(sdkContext); ok {
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
if !sc.sdkVersion().specified() {
|
2019-10-29 07:44:45 +01:00
|
|
|
ctx.PropertyErrorf("sdk_version",
|
|
|
|
"sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-08 20:09:30 +02:00
|
|
|
|
|
|
|
ctx.VisitDirectDeps(func(module android.Module) {
|
|
|
|
tag := ctx.OtherModuleDependencyTag(module)
|
|
|
|
switch module.(type) {
|
|
|
|
// TODO(satayev): cover other types as well, e.g. imports
|
|
|
|
case *Library, *AndroidLibrary:
|
|
|
|
switch tag {
|
|
|
|
case bootClasspathTag, libTag, staticLibTag, java9LibTag:
|
|
|
|
checkLinkType(ctx, j, module.(linkTypeContext), tag.(dependencyTag))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2019-10-29 07:44:45 +01:00
|
|
|
}
|
|
|
|
|
2019-07-11 08:54:27 +02:00
|
|
|
func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
|
|
|
|
if sc, ok := ctx.Module().(sdkContext); ok {
|
|
|
|
usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
sdkVersionSpecified := sc.sdkVersion().specified()
|
|
|
|
if usePlatformAPI && sdkVersionSpecified {
|
|
|
|
ctx.PropertyErrorf("platform_apis", "platform_apis must be false when sdk_version is not empty.")
|
|
|
|
} else if !usePlatformAPI && !sdkVersionSpecified {
|
|
|
|
ctx.PropertyErrorf("platform_apis", "platform_apis must be true when sdk_version is empty.")
|
2019-07-11 08:54:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-31 02:20:39 +02:00
|
|
|
// TODO:
|
|
|
|
// Autogenerated files:
|
|
|
|
// Renderscript
|
|
|
|
// Post-jar passes:
|
|
|
|
// Proguard
|
|
|
|
// Rmtypedefs
|
|
|
|
// DroidDoc
|
|
|
|
// Findbugs
|
|
|
|
|
2017-07-07 23:35:50 +02:00
|
|
|
type CompilerProperties struct {
|
2020-06-26 02:13:36 +02:00
|
|
|
// list of source files used to compile the Java module. May be .java, .kt, .logtags, .proto,
|
2015-05-11 22:39:40 +02:00
|
|
|
// or .aidl files.
|
2019-03-05 07:35:41 +01:00
|
|
|
Srcs []string `android:"path,arch_variant"`
|
2015-07-01 03:15:24 +02:00
|
|
|
|
2020-06-26 02:13:36 +02:00
|
|
|
// list Kotlin of source files containing Kotlin code that should be treated as common code in
|
|
|
|
// a codebase that supports Kotlin multiplatform. See
|
|
|
|
// https://kotlinlang.org/docs/reference/multiplatform.html. May be only be .kt files.
|
|
|
|
Common_srcs []string `android:"path,arch_variant"`
|
|
|
|
|
2015-07-01 03:15:24 +02:00
|
|
|
// list of source files that should not be used to build the Java module.
|
|
|
|
// This is most useful in the arch/multilib variants to remove non-common files
|
2019-03-05 07:35:41 +01:00
|
|
|
Exclude_srcs []string `android:"path,arch_variant"`
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of directories containing Java resources
|
2017-09-28 02:33:10 +02:00
|
|
|
Java_resource_dirs []string `android:"arch_variant"`
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2017-09-28 02:33:10 +02:00
|
|
|
// list of directories that should be excluded from java_resource_dirs
|
|
|
|
Exclude_java_resource_dirs []string `android:"arch_variant"`
|
2015-07-01 03:15:24 +02:00
|
|
|
|
2017-09-28 02:42:05 +02:00
|
|
|
// list of files to use as Java resources
|
2019-03-05 07:35:41 +01:00
|
|
|
Java_resources []string `android:"path,arch_variant"`
|
2017-09-28 02:42:05 +02:00
|
|
|
|
2018-09-13 20:26:19 +02:00
|
|
|
// list of files that should be excluded from java_resources and java_resource_dirs
|
2019-03-05 07:35:41 +01:00
|
|
|
Exclude_java_resources []string `android:"path,arch_variant"`
|
2017-09-28 02:42:05 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of module-specific flags that will be used for javac compiles
|
|
|
|
Javacflags []string `android:"arch_variant"`
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2018-08-21 17:10:29 +02:00
|
|
|
// list of module-specific flags that will be used for kotlinc compiles
|
|
|
|
Kotlincflags []string `android:"arch_variant"`
|
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of of java libraries that will be in the classpath
|
2017-07-19 20:22:16 +02:00
|
|
|
Libs []string `android:"arch_variant"`
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of java libraries that will be compiled into the resulting jar
|
2017-07-19 20:22:16 +02:00
|
|
|
Static_libs []string `android:"arch_variant"`
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// manifest file to be included in resulting jar
|
2019-03-05 07:35:41 +01:00
|
|
|
Manifest *string `android:"path"`
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2017-06-23 02:01:52 +02:00
|
|
|
// if not blank, run jarjar using the specified rules file
|
2019-03-05 07:35:41 +01:00
|
|
|
Jarjar_rules *string `android:"path,arch_variant"`
|
2017-08-08 22:17:59 +02:00
|
|
|
|
|
|
|
// If not blank, set the java version passed to javac as -source and -target
|
|
|
|
Java_version *string
|
2017-09-01 01:45:16 +02:00
|
|
|
|
2018-06-27 02:59:05 +02:00
|
|
|
// If set to true, allow this module to be dexed and installed on devices. Has no
|
|
|
|
// effect on host modules, which are always considered installable.
|
2017-09-01 01:45:16 +02:00
|
|
|
Installable *bool
|
2017-09-06 22:41:06 +02:00
|
|
|
|
2017-09-28 02:42:05 +02:00
|
|
|
// If set to true, include sources used to compile the module in to the final jar
|
|
|
|
Include_srcs *bool
|
|
|
|
|
2019-04-02 11:29:55 +02:00
|
|
|
// If not empty, classes are restricted to the specified packages and their sub-packages.
|
|
|
|
// This restriction is checked after applying jarjar rules and including static libs.
|
|
|
|
Permitted_packages []string
|
|
|
|
|
2019-01-22 06:37:16 +01:00
|
|
|
// List of modules to use as annotation processors
|
|
|
|
Plugins []string
|
2017-09-30 02:58:17 +02:00
|
|
|
|
2020-11-20 03:06:03 +01:00
|
|
|
// List of modules to export to libraries that directly depend on this library as annotation
|
|
|
|
// processors. Note that if the plugins set generates_api: true this will disable the turbine
|
|
|
|
// optimization on modules that depend on this module, which will reduce parallelism and cause
|
|
|
|
// more recompilation.
|
2019-11-26 19:08:34 +01:00
|
|
|
Exported_plugins []string
|
|
|
|
|
2017-11-02 21:28:15 +01:00
|
|
|
// The number of Java source entries each Javac instance can process
|
|
|
|
Javac_shard_size *int64
|
|
|
|
|
2018-02-06 19:34:32 +01:00
|
|
|
// Add host jdk tools.jar to bootclasspath
|
|
|
|
Use_tools_jar *bool
|
|
|
|
|
2017-09-30 02:58:17 +02:00
|
|
|
Openjdk9 struct {
|
2019-10-17 23:23:50 +02:00
|
|
|
// List of source files that should only be used when passing -source 1.9 or higher
|
2019-03-05 07:35:41 +01:00
|
|
|
Srcs []string `android:"path"`
|
2017-09-30 02:58:17 +02:00
|
|
|
|
2019-10-17 23:23:50 +02:00
|
|
|
// List of javac flags that should only be used when passing -source 1.9 or higher
|
2017-09-30 02:58:17 +02:00
|
|
|
Javacflags []string
|
|
|
|
}
|
2017-11-22 22:49:43 +01:00
|
|
|
|
2018-08-16 05:21:55 +02:00
|
|
|
// When compiling language level 9+ .java code in packages that are part of
|
|
|
|
// a system module, patch_module names the module that your sources and
|
|
|
|
// dependencies should be patched into. The Android runtime currently
|
|
|
|
// doesn't implement the JEP 261 module system so this option is only
|
|
|
|
// supported at compile time. It should only be needed to compile tests in
|
|
|
|
// packages that exist in libcore and which are inconvenient to move
|
|
|
|
// elsewhere.
|
2018-09-19 17:16:19 +02:00
|
|
|
Patch_module *string `android:"arch_variant"`
|
2018-08-16 05:21:55 +02:00
|
|
|
|
2017-11-22 22:49:43 +01:00
|
|
|
Jacoco struct {
|
|
|
|
// List of classes to include for instrumentation with jacoco to collect coverage
|
|
|
|
// information at runtime when building with coverage enabled. If unset defaults to all
|
|
|
|
// classes.
|
|
|
|
// Supports '*' as the last character of an entry in the list as a wildcard match.
|
|
|
|
// If preceded by '.' it matches all classes in the package and subpackages, otherwise
|
|
|
|
// it matches classes in the package that have the class name as a prefix.
|
|
|
|
Include_filter []string
|
|
|
|
|
|
|
|
// List of classes to exclude from instrumentation with jacoco to collect coverage
|
|
|
|
// information at runtime when building with coverage enabled. Overrides classes selected
|
|
|
|
// by the include_filter property.
|
|
|
|
// Supports '*' as the last character of an entry in the list as a wildcard match.
|
|
|
|
// If preceded by '.' it matches all classes in the package and subpackages, otherwise
|
|
|
|
// it matches classes in the package that have the class name as a prefix.
|
|
|
|
Exclude_filter []string
|
|
|
|
}
|
|
|
|
|
2018-01-23 06:27:21 +01:00
|
|
|
Errorprone struct {
|
|
|
|
// List of javac flags that should only be used when running errorprone.
|
|
|
|
Javacflags []string
|
2020-11-19 22:52:06 +01:00
|
|
|
|
|
|
|
// List of java_plugin modules that provide extra errorprone checks.
|
|
|
|
Extra_check_modules []string
|
2018-01-23 06:27:21 +01:00
|
|
|
}
|
|
|
|
|
2017-12-15 00:22:43 +01:00
|
|
|
Proto struct {
|
|
|
|
// List of extra options that will be passed to the proto generator.
|
|
|
|
Output_params []string
|
|
|
|
}
|
|
|
|
|
2017-11-22 22:49:43 +01:00
|
|
|
Instrument bool `blueprint:"mutated"`
|
2019-02-21 22:27:37 +01:00
|
|
|
|
|
|
|
// List of files to include in the META-INF/services folder of the resulting jar.
|
2019-03-05 07:35:41 +01:00
|
|
|
Services []string `android:"path,arch_variant"`
|
2020-06-19 00:52:01 +02:00
|
|
|
|
|
|
|
// If true, package the kotlin stdlib into the jar. Defaults to true.
|
|
|
|
Static_kotlin_stdlib *bool `android:"arch_variant"`
|
2021-02-12 12:46:42 +01:00
|
|
|
|
|
|
|
// A list of java_library instances that provide additional hiddenapi annotations for the library.
|
|
|
|
Hiddenapi_additional_annotations []string
|
2017-06-23 02:01:52 +02:00
|
|
|
}
|
|
|
|
|
2017-07-07 23:35:50 +02:00
|
|
|
type CompilerDeviceProperties struct {
|
2019-07-11 08:54:27 +02:00
|
|
|
// if not blank, set to the version of the sdk to compile against.
|
|
|
|
// Defaults to compiling against the current platform.
|
2017-11-09 06:20:04 +01:00
|
|
|
Sdk_version *string
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2018-06-26 00:48:06 +02:00
|
|
|
// if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
|
|
|
|
// Defaults to sdk_version if not set.
|
|
|
|
Min_sdk_version *string
|
|
|
|
|
2018-10-31 23:28:47 +01:00
|
|
|
// if not blank, set the targetSdkVersion in the AndroidManifest.xml.
|
|
|
|
// Defaults to sdk_version if not set.
|
|
|
|
Target_sdk_version *string
|
|
|
|
|
2019-08-19 07:09:52 +02:00
|
|
|
// Whether to compile against the platform APIs instead of an SDK.
|
|
|
|
// If true, then sdk_version must be empty. The value of this field
|
|
|
|
// is ignored when module's type isn't android_app.
|
2018-05-22 20:12:33 +02:00
|
|
|
Platform_apis *bool
|
|
|
|
|
2017-11-14 22:12:14 +01:00
|
|
|
Aidl struct {
|
|
|
|
// Top level directories to pass to aidl tool
|
|
|
|
Include_dirs []string
|
2015-04-08 22:03:43 +02:00
|
|
|
|
2017-11-14 22:12:14 +01:00
|
|
|
// Directories rooted at the Android.bp file to pass to aidl tool
|
|
|
|
Local_include_dirs []string
|
|
|
|
|
|
|
|
// 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
|
2018-03-09 09:29:59 +01:00
|
|
|
|
|
|
|
// whether to generate traces (for systrace) for this interface
|
|
|
|
Generate_traces *bool
|
2018-07-17 00:37:03 +02:00
|
|
|
|
|
|
|
// whether to generate Binder#GetTransaction name method.
|
|
|
|
Generate_get_transaction_name *bool
|
2021-01-05 02:33:16 +01:00
|
|
|
|
|
|
|
// list of flags that will be passed to the AIDL compiler
|
|
|
|
Flags []string
|
2017-11-14 22:12:14 +01:00
|
|
|
}
|
2017-10-09 23:59:32 +02:00
|
|
|
|
|
|
|
// If true, export a copy of the module as a -hostdex module for host testing.
|
|
|
|
Hostdex *bool
|
2017-09-30 02:58:17 +02:00
|
|
|
|
2019-04-24 22:41:45 +02:00
|
|
|
Target struct {
|
|
|
|
Hostdex struct {
|
|
|
|
// Additional required dependencies to add to -hostdex modules.
|
|
|
|
Required []string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-11 14:50:28 +02:00
|
|
|
// When targeting 1.9 and above, override the modules to use with --system,
|
|
|
|
// otherwise provides defaults libraries to add to the bootclasspath.
|
2017-09-30 02:58:17 +02:00
|
|
|
System_modules *string
|
2018-10-05 23:20:06 +02:00
|
|
|
|
2020-06-24 17:22:38 +02:00
|
|
|
// The name of the module as used in build configuration.
|
|
|
|
//
|
|
|
|
// Allows a library to separate its actual name from the name used in
|
|
|
|
// build configuration, e.g.ctx.Config().BootJars().
|
|
|
|
ConfigurationName *string `blueprint:"mutated"`
|
|
|
|
|
2019-10-21 07:53:15 +02:00
|
|
|
// set the name of the output
|
|
|
|
Stem *string
|
|
|
|
|
2020-05-20 23:20:28 +02:00
|
|
|
IsSDKLibrary bool `blueprint:"mutated"`
|
2020-03-25 04:32:24 +01:00
|
|
|
|
|
|
|
// If true, generate the signature file of APK Signing Scheme V4, along side the signed APK file.
|
|
|
|
// Defaults to false.
|
|
|
|
V4_signature *bool
|
2021-02-27 01:20:32 +01:00
|
|
|
|
|
|
|
// Only for libraries created by a sysprop_library module, SyspropPublicStub is the name of the
|
|
|
|
// public stubs library.
|
|
|
|
SyspropPublicStub string `blueprint:"mutated"`
|
2015-05-11 22:39:40 +02:00
|
|
|
}
|
2015-04-08 22:03:43 +02:00
|
|
|
|
2020-05-17 09:34:50 +02:00
|
|
|
// Functionality common to Module and Import
|
2020-05-15 11:20:31 +02:00
|
|
|
//
|
|
|
|
// It is embedded in Module so its functionality can be used by methods in Module
|
|
|
|
// but it is currently only initialized by Import and Library.
|
2020-05-17 09:34:50 +02:00
|
|
|
type embeddableInModuleAndImport struct {
|
2020-05-15 11:20:31 +02:00
|
|
|
|
|
|
|
// Functionality related to this being used as a component of a java_sdk_library.
|
|
|
|
EmbeddableSdkLibraryComponent
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *embeddableInModuleAndImport) initModuleAndImport(moduleBase *android.ModuleBase) {
|
|
|
|
e.initSdkLibraryComponent(moduleBase)
|
2020-05-17 09:34:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Module/Import's DepIsInSameApex(...) delegates to this method.
|
|
|
|
//
|
|
|
|
// This cannot implement DepIsInSameApex(...) directly as that leads to ambiguity with
|
|
|
|
// the one provided by ApexModuleBase.
|
|
|
|
func (e *embeddableInModuleAndImport) depIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
|
|
|
|
// dependencies other than the static linkage are all considered crossing APEX boundary
|
|
|
|
if staticLibTag == ctx.OtherModuleDependencyTag(dep) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-06-23 01:51:17 +02:00
|
|
|
// Module contains the properties and members used by all java module types
|
|
|
|
type Module struct {
|
2016-05-19 00:37:25 +02:00
|
|
|
android.ModuleBase
|
2017-07-07 23:35:50 +02:00
|
|
|
android.DefaultableModuleBase
|
2019-07-25 15:02:35 +02:00
|
|
|
android.ApexModuleBase
|
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 13:08:41 +02:00
|
|
|
android.SdkBase
|
2015-05-11 22:39:40 +02:00
|
|
|
|
2020-05-17 09:34:50 +02:00
|
|
|
// Functionality common to Module and Import.
|
|
|
|
embeddableInModuleAndImport
|
|
|
|
|
2017-07-07 23:35:50 +02:00
|
|
|
properties CompilerProperties
|
2017-09-20 21:59:05 +02:00
|
|
|
protoProperties android.ProtoProperties
|
2017-07-07 23:35:50 +02:00
|
|
|
deviceProperties CompilerDeviceProperties
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2018-08-16 05:40:52 +02:00
|
|
|
// jar file containing header classes including static library dependencies, suitable for
|
|
|
|
// inserting into the bootclasspath/classpath of another compile
|
2017-10-19 22:06:22 +02:00
|
|
|
headerJarFile android.Path
|
|
|
|
|
2018-08-16 05:40:52 +02:00
|
|
|
// jar file containing implementation classes including static library dependencies but no
|
|
|
|
// resources
|
2017-10-19 22:06:22 +02:00
|
|
|
implementationJarFile android.Path
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2018-08-16 05:40:52 +02:00
|
|
|
// jar file containing only resources including from static library dependencies
|
|
|
|
resourceJar android.Path
|
|
|
|
|
2019-05-04 00:28:19 +02:00
|
|
|
// args and dependencies to package source files into a srcjar
|
|
|
|
srcJarArgs []string
|
|
|
|
srcJarDeps android.Paths
|
|
|
|
|
2018-08-16 05:40:52 +02:00
|
|
|
// jar file containing implementation classes and resources including static library
|
|
|
|
// dependencies
|
|
|
|
implementationAndResourcesJar android.Path
|
|
|
|
|
|
|
|
// output file containing classes.dex and resources
|
2017-09-15 22:00:47 +02:00
|
|
|
dexJarFile android.Path
|
|
|
|
|
2017-11-22 22:49:43 +01:00
|
|
|
// output file containing uninstrumented classes that will be instrumented by jacoco
|
|
|
|
jacocoReportClassesFile android.Path
|
|
|
|
|
2018-08-16 05:40:52 +02:00
|
|
|
// output file of the module, which may be a classes jar or a dex jar
|
2019-03-20 00:03:11 +01:00
|
|
|
outputFile android.Path
|
|
|
|
extraOutputFiles android.Paths
|
2015-04-16 23:09:14 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
exportAidlIncludeDirs android.Paths
|
2015-04-08 22:03:43 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
logtagsSrcs android.Paths
|
2015-04-11 02:45:20 +02:00
|
|
|
|
2015-03-31 02:20:39 +02:00
|
|
|
// installed file for binary dependency
|
2016-05-19 00:37:25 +02:00
|
|
|
installFile android.Path
|
2017-11-23 01:20:45 +01:00
|
|
|
|
|
|
|
// list of .java files and srcjars that was passed to javac
|
|
|
|
compiledJavaSrcs android.Paths
|
|
|
|
compiledSrcJars android.Paths
|
2017-12-28 21:23:20 +01:00
|
|
|
|
2018-10-18 00:10:48 +02:00
|
|
|
// manifest file to use instead of properties.Manifest
|
|
|
|
overrideManifest android.OptionalPath
|
|
|
|
|
2020-11-03 16:15:46 +01:00
|
|
|
// map of SDK version to class loader context
|
2020-10-08 13:53:58 +02:00
|
|
|
classLoaderContexts dexpreopt.ClassLoaderContextMap
|
2018-08-16 00:35:38 +02:00
|
|
|
|
2019-11-26 19:08:34 +01:00
|
|
|
// list of plugins that this java module is exporting
|
|
|
|
exportedPluginJars android.Paths
|
|
|
|
|
|
|
|
// list of plugins that this java module is exporting
|
|
|
|
exportedPluginClasses []string
|
|
|
|
|
2020-11-20 03:06:03 +01:00
|
|
|
// if true, the exported plugins generate API and require disabling turbine.
|
|
|
|
exportedDisableTurbine bool
|
|
|
|
|
2019-11-26 19:08:34 +01:00
|
|
|
// list of source files, collected from srcFiles with unique java and all kt files,
|
2019-09-24 09:41:30 +02:00
|
|
|
// will be used by android.IDEInfo struct
|
2018-08-16 00:35:38 +02:00
|
|
|
expandIDEInfoCompiledSrcs []string
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2019-01-18 20:51:25 +01:00
|
|
|
// expanded Jarjar_rules
|
|
|
|
expandJarjarRules android.Path
|
|
|
|
|
2019-04-02 11:29:55 +02:00
|
|
|
// list of additional targets for checkbuild
|
|
|
|
additionalCheckedModules android.Paths
|
|
|
|
|
2019-05-06 23:04:11 +02:00
|
|
|
// Extra files generated by the module type to be added as java resources.
|
|
|
|
extraResources android.Paths
|
|
|
|
|
2019-01-31 23:12:44 +01:00
|
|
|
hiddenAPI
|
2020-07-10 00:16:41 +02:00
|
|
|
dexer
|
2018-11-12 19:13:39 +01:00
|
|
|
dexpreopter
|
2020-09-01 18:33:48 +02:00
|
|
|
usesLibrary
|
2020-06-03 05:09:13 +02:00
|
|
|
linter
|
2018-11-06 01:49:08 +01:00
|
|
|
|
|
|
|
// list of the xref extraction files
|
|
|
|
kytheFiles android.Paths
|
2020-03-27 20:39:48 +01:00
|
|
|
|
2020-05-21 04:11:59 +02:00
|
|
|
// Collect the module directory for IDE info in java/jdeps.go.
|
|
|
|
modulePaths []string
|
2020-09-16 03:30:11 +02:00
|
|
|
|
|
|
|
hideApexVariantFromMake bool
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2020-06-16 01:09:53 +02:00
|
|
|
func (j *Module) addHostProperties() {
|
|
|
|
j.AddProperties(
|
|
|
|
&j.properties,
|
|
|
|
&j.protoProperties,
|
2020-09-01 18:33:48 +02:00
|
|
|
&j.usesLibraryProperties,
|
2020-06-16 01:09:53 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *Module) addHostAndDeviceProperties() {
|
|
|
|
j.addHostProperties()
|
|
|
|
j.AddProperties(
|
|
|
|
&j.deviceProperties,
|
2020-07-10 00:16:41 +02:00
|
|
|
&j.dexer.dexProperties,
|
2020-06-16 01:09:53 +02:00
|
|
|
&j.dexpreoptProperties,
|
2020-06-03 05:09:13 +02:00
|
|
|
&j.linter.properties,
|
2020-06-16 01:09:53 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-05-29 23:40:35 +02:00
|
|
|
func (j *Module) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
switch tag {
|
|
|
|
case "":
|
|
|
|
return append(android.Paths{j.outputFile}, j.extraOutputFiles...), nil
|
2020-11-25 17:37:46 +01:00
|
|
|
case android.DefaultDistTag:
|
|
|
|
return android.Paths{j.outputFile}, nil
|
2019-05-29 23:40:58 +02:00
|
|
|
case ".jar":
|
|
|
|
return android.Paths{j.implementationAndResourcesJar}, nil
|
2019-07-30 01:47:42 +02:00
|
|
|
case ".proguard_map":
|
2020-07-10 00:16:41 +02:00
|
|
|
if j.dexer.proguardDictionary.Valid() {
|
|
|
|
return android.Paths{j.dexer.proguardDictionary.Path()}, nil
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("%q was requested, but no output file was found.", tag)
|
2019-05-29 23:40:35 +02:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
|
|
|
|
}
|
2017-12-05 18:28:08 +01:00
|
|
|
}
|
|
|
|
|
2019-05-29 23:40:35 +02:00
|
|
|
var _ android.OutputFileProducer = (*Module)(nil)
|
2017-12-05 18:28:08 +01:00
|
|
|
|
2021-02-01 22:59:03 +01:00
|
|
|
// JavaInfo contains information about a java module for use by modules that depend on it.
|
|
|
|
type JavaInfo struct {
|
|
|
|
// HeaderJars is a list of jars that can be passed as the javac classpath in order to link
|
|
|
|
// against this module. If empty, ImplementationJars should be used instead.
|
|
|
|
HeaderJars android.Paths
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
SrcJarArgs []string
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// ExportedPluginClasses is a list of classes that should be run as annotation processors for
|
|
|
|
// any module that depends on this module.
|
|
|
|
ExportedPluginClasses []string
|
|
|
|
|
|
|
|
// ExportedPluginDisableTurbine is true if this module's annotation processors generate APIs,
|
|
|
|
// requiring disbling turbine for any modules that depend on it.
|
|
|
|
ExportedPluginDisableTurbine bool
|
|
|
|
|
|
|
|
// JacocoReportClassesFile is the path to a jar containing uninstrumented classes that will be
|
|
|
|
// instrumented by jacoco.
|
|
|
|
JacocoReportClassesFile android.Path
|
|
|
|
}
|
|
|
|
|
|
|
|
var JavaInfoProvider = blueprint.NewProvider(JavaInfo{})
|
|
|
|
|
2021-02-27 01:20:32 +01:00
|
|
|
// SyspropPublicStubInfo contains info about the sysprop public stub library that corresponds to
|
|
|
|
// the sysprop implementation library.
|
|
|
|
type SyspropPublicStubInfo struct {
|
|
|
|
// JavaInfo is the JavaInfoProvider of the sysprop public stub library that corresponds to
|
|
|
|
// the sysprop implementation library.
|
|
|
|
JavaInfo JavaInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
var SyspropPublicStubInfoProvider = blueprint.NewProvider(SyspropPublicStubInfo{})
|
|
|
|
|
2020-06-17 17:59:43 +02:00
|
|
|
// Methods that need to be implemented for a module that is added to apex java_libs property.
|
|
|
|
type ApexDependency interface {
|
2017-10-19 22:06:22 +02:00
|
|
|
HeaderJars() android.Paths
|
2020-06-17 17:59:43 +02:00
|
|
|
ImplementationAndResourcesJars() android.Paths
|
|
|
|
}
|
|
|
|
|
2020-08-14 18:32:16 +02:00
|
|
|
// Provides build path and install path to DEX jars.
|
|
|
|
type UsesLibraryDependency interface {
|
|
|
|
DexJarBuildPath() android.Path
|
|
|
|
DexJarInstallPath() android.Path
|
2020-12-17 13:07:54 +01:00
|
|
|
ClassLoaderContexts() dexpreopt.ClassLoaderContextMap
|
2020-08-14 18:32:16 +02:00
|
|
|
}
|
|
|
|
|
2018-11-06 01:49:08 +01:00
|
|
|
type xref interface {
|
|
|
|
XrefJavaFiles() android.Paths
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *Module) XrefJavaFiles() android.Paths {
|
|
|
|
return j.kytheFiles
|
|
|
|
}
|
|
|
|
|
2017-07-07 23:35:50 +02:00
|
|
|
func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
|
2020-06-13 01:38:45 +02:00
|
|
|
initJavaModule(module, hod, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func InitJavaModuleMultiTargets(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
|
|
|
|
initJavaModule(module, hod, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func initJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported, multiTargets bool) {
|
|
|
|
multilib := android.MultilibCommon
|
|
|
|
if multiTargets {
|
|
|
|
android.InitAndroidMultiTargetsArchModule(module, hod, multilib)
|
|
|
|
} else {
|
|
|
|
android.InitAndroidArchModule(module, hod, multilib)
|
|
|
|
}
|
2017-07-07 23:35:50 +02:00
|
|
|
android.InitDefaultableModule(module)
|
|
|
|
}
|
|
|
|
|
2017-07-08 00:59:46 +02:00
|
|
|
type dependencyTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
name string
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2020-11-11 03:12:15 +01:00
|
|
|
// installDependencyTag is a dependency tag that is annotated to cause the installed files of the
|
|
|
|
// dependency to be installed when the parent module is installed.
|
|
|
|
type installDependencyTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
android.InstallAlwaysNeededDependencyTag
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
2020-10-07 16:11:32 +02: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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 07:53:48 +01:00
|
|
|
func IsJniDepTag(depTag blueprint.DependencyTag) bool {
|
2020-10-10 03:59:49 +02:00
|
|
|
return depTag == jniLibTag
|
2019-11-08 07:53:48 +01:00
|
|
|
}
|
|
|
|
|
2017-07-08 00:59:46 +02:00
|
|
|
var (
|
2021-02-27 01:20:32 +01:00
|
|
|
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-07-08 00:59:46 +02:00
|
|
|
)
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2020-01-14 10:38:44 +01:00
|
|
|
func IsLibDepTag(depTag blueprint.DependencyTag) bool {
|
|
|
|
return depTag == libTag
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsStaticLibDepTag(depTag blueprint.DependencyTag) bool {
|
|
|
|
return depTag == staticLibTag
|
|
|
|
}
|
|
|
|
|
2017-09-19 02:41:52 +02:00
|
|
|
type sdkDep struct {
|
Remove the concept of useDefaultLibs from Soong.
This field in the java/sdk structure was used in two of the many
possible configurations, so it wasn't really a "default". It also
meant that, to understand those configurations, the reader had to know
what was considered the default, which was only possibly by reading
the code in java.go and droiddoc.go which implemented special code
paths when useDefaultLibs was true. By eliminating that setting and
explicitly setting the required values, the code is simpler and easier
to understand.
This change is a straight refactoring, in the sense that the output of
the build should be unchanged.
Regarding the changes to the proguardRaiseTag dependency in java.go:
- This is a noop for anything which had sdkDep.useModule = true prior
to this change, because they all had the same value for
hasFrameworkLibs() and hasStandardLibs().
- This is a noop for anything which had sdkDep.useDefaultLibs = true
prior to this change, because they do not use proguard settings.
- Therefore, it is a noop overall.
- Nevertheless, it is required to make sdkCorePlatform work. Without
this change, such modules would pick up a dependency on framework
libs via the (unused) proguardRaiseTag, which creates a circular
dependency, because this is the sdk_version used when building
framework libs themselves.
Bug: 157640067
Test: m java docs droid
Change-Id: I3a83b5edc1bd48c16b55f6f77e3e710fc8fbd8fa
2020-06-29 12:28:51 +02:00
|
|
|
useModule, useFiles, invalidVersion bool
|
2017-10-02 23:22:08 +02:00
|
|
|
|
2019-10-17 23:23:50 +02:00
|
|
|
// The modules that will be added to the bootclasspath when targeting 1.8 or lower
|
|
|
|
bootclasspath []string
|
2019-10-11 14:50:28 +02:00
|
|
|
|
|
|
|
// The default system modules to use. Will be an empty string if no system
|
|
|
|
// modules are to be used.
|
2017-09-30 02:58:17 +02:00
|
|
|
systemModules string
|
|
|
|
|
Remove the concept of useDefaultLibs from Soong.
This field in the java/sdk structure was used in two of the many
possible configurations, so it wasn't really a "default". It also
meant that, to understand those configurations, the reader had to know
what was considered the default, which was only possibly by reading
the code in java.go and droiddoc.go which implemented special code
paths when useDefaultLibs was true. By eliminating that setting and
explicitly setting the required values, the code is simpler and easier
to understand.
This change is a straight refactoring, in the sense that the output of
the build should be unchanged.
Regarding the changes to the proguardRaiseTag dependency in java.go:
- This is a noop for anything which had sdkDep.useModule = true prior
to this change, because they all had the same value for
hasFrameworkLibs() and hasStandardLibs().
- This is a noop for anything which had sdkDep.useDefaultLibs = true
prior to this change, because they do not use proguard settings.
- Therefore, it is a noop overall.
- Nevertheless, it is required to make sdkCorePlatform work. Without
this change, such modules would pick up a dependency on framework
libs via the (unused) proguardRaiseTag, which creates a circular
dependency, because this is the sdk_version used when building
framework libs themselves.
Bug: 157640067
Test: m java docs droid
Change-Id: I3a83b5edc1bd48c16b55f6f77e3e710fc8fbd8fa
2020-06-29 12:28:51 +02:00
|
|
|
// The modules that will be added to the classpath regardless of the Java language level targeted
|
|
|
|
classpath []string
|
|
|
|
|
2019-10-17 23:23:50 +02:00
|
|
|
// The modules that will be added ot the classpath when targeting 1.9 or higher
|
Remove the concept of useDefaultLibs from Soong.
This field in the java/sdk structure was used in two of the many
possible configurations, so it wasn't really a "default". It also
meant that, to understand those configurations, the reader had to know
what was considered the default, which was only possibly by reading
the code in java.go and droiddoc.go which implemented special code
paths when useDefaultLibs was true. By eliminating that setting and
explicitly setting the required values, the code is simpler and easier
to understand.
This change is a straight refactoring, in the sense that the output of
the build should be unchanged.
Regarding the changes to the proguardRaiseTag dependency in java.go:
- This is a noop for anything which had sdkDep.useModule = true prior
to this change, because they all had the same value for
hasFrameworkLibs() and hasStandardLibs().
- This is a noop for anything which had sdkDep.useDefaultLibs = true
prior to this change, because they do not use proguard settings.
- Therefore, it is a noop overall.
- Nevertheless, it is required to make sdkCorePlatform work. Without
this change, such modules would pick up a dependency on framework
libs via the (unused) proguardRaiseTag, which creates a circular
dependency, because this is the sdk_version used when building
framework libs themselves.
Bug: 157640067
Test: m java docs droid
Change-Id: I3a83b5edc1bd48c16b55f6f77e3e710fc8fbd8fa
2020-06-29 12:28:51 +02:00
|
|
|
// (normally these will be on the bootclasspath when targeting 1.8 or lower)
|
2019-10-17 23:23:50 +02:00
|
|
|
java9Classpath []string
|
|
|
|
|
2018-03-28 23:58:31 +02:00
|
|
|
frameworkResModule string
|
|
|
|
|
2018-05-29 23:44:55 +02:00
|
|
|
jars android.Paths
|
2019-04-18 19:56:44 +02:00
|
|
|
aidl android.OptionalPath
|
2019-06-07 11:44:37 +02:00
|
|
|
|
|
|
|
noStandardLibs, noFrameworksLibs bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s sdkDep) hasStandardLibs() bool {
|
|
|
|
return !s.noStandardLibs
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s sdkDep) hasFrameworkLibs() bool {
|
|
|
|
return !s.noStandardLibs && !s.noFrameworksLibs
|
2017-09-19 02:41:52 +02:00
|
|
|
}
|
|
|
|
|
2018-10-03 07:03:40 +02:00
|
|
|
type jniLib struct {
|
2020-07-06 23:15:24 +02:00
|
|
|
name string
|
|
|
|
path android.Path
|
|
|
|
target android.Target
|
|
|
|
coverageFile android.OptionalPath
|
|
|
|
unstrippedFile android.Path
|
2018-10-03 07:03:40 +02:00
|
|
|
}
|
|
|
|
|
2019-06-06 23:33:29 +02:00
|
|
|
func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool {
|
2020-06-09 14:07:36 +02:00
|
|
|
return j.properties.Instrument &&
|
|
|
|
ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") &&
|
|
|
|
ctx.DeviceConfig().JavaCoverageEnabledForPath(ctx.ModuleDir())
|
2018-01-04 00:06:47 +01:00
|
|
|
}
|
|
|
|
|
2019-06-06 23:33:29 +02:00
|
|
|
func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool {
|
2018-01-04 00:06:47 +01:00
|
|
|
return j.shouldInstrument(ctx) &&
|
|
|
|
(ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
|
|
|
|
ctx.Config().UnbundledBuild())
|
|
|
|
}
|
|
|
|
|
2020-05-29 18:01:19 +02:00
|
|
|
func (j *Module) shouldInstrumentInApex(ctx android.BaseModuleContext) bool {
|
|
|
|
// Force enable the instrumentation for java code that is built for APEXes ...
|
|
|
|
// except for the jacocoagent itself (because instrumenting jacocoagent using jacocoagent
|
|
|
|
// doesn't make sense) or framework libraries (e.g. libraries found in the InstrumentFrameworkModules list) unless EMMA_INSTRUMENT_FRAMEWORK is true.
|
2020-09-16 03:30:11 +02:00
|
|
|
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
|
2020-05-29 18:01:19 +02:00
|
|
|
isJacocoAgent := ctx.ModuleName() == "jacocoagent"
|
2020-09-16 03:30:11 +02:00
|
|
|
if j.DirectlyInAnyApex() && !isJacocoAgent && !apexInfo.IsForPlatform() {
|
2020-05-29 18:01:19 +02:00
|
|
|
if !inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
|
|
|
|
return true
|
|
|
|
} else if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
func (j *Module) sdkVersion() sdkSpec {
|
|
|
|
return sdkSpecFrom(String(j.deviceProperties.Sdk_version))
|
2018-06-26 00:48:06 +02:00
|
|
|
}
|
|
|
|
|
2019-10-11 14:50:28 +02:00
|
|
|
func (j *Module) systemModules() string {
|
|
|
|
return proptools.String(j.deviceProperties.System_modules)
|
|
|
|
}
|
|
|
|
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
func (j *Module) minSdkVersion() sdkSpec {
|
2018-06-26 00:48:06 +02:00
|
|
|
if j.deviceProperties.Min_sdk_version != nil {
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
return sdkSpecFrom(*j.deviceProperties.Min_sdk_version)
|
2018-06-26 00:48:06 +02:00
|
|
|
}
|
|
|
|
return j.sdkVersion()
|
|
|
|
}
|
|
|
|
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
func (j *Module) targetSdkVersion() sdkSpec {
|
2018-10-31 23:28:47 +01:00
|
|
|
if j.deviceProperties.Target_sdk_version != nil {
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
return sdkSpecFrom(*j.deviceProperties.Target_sdk_version)
|
2018-10-31 23:28:47 +01:00
|
|
|
}
|
|
|
|
return j.sdkVersion()
|
|
|
|
}
|
|
|
|
|
2020-04-27 19:53:18 +02:00
|
|
|
func (j *Module) MinSdkVersion() string {
|
|
|
|
return j.minSdkVersion().version.String()
|
|
|
|
}
|
|
|
|
|
2019-12-02 16:43:57 +01:00
|
|
|
func (j *Module) AvailableFor(what string) bool {
|
|
|
|
if what == android.AvailableToPlatform && Bool(j.deviceProperties.Hostdex) {
|
|
|
|
// Exception: for hostdex: true libraries, the platform variant is created
|
|
|
|
// even if it's not marked as available to platform. In that case, the platform
|
|
|
|
// variant is used only for the hostdex and not installed to the device.
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return j.ApexModuleBase.AvailableFor(what)
|
|
|
|
}
|
|
|
|
|
2020-08-06 00:40:41 +02:00
|
|
|
func sdkDeps(ctx android.BottomUpMutatorContext, sdkContext sdkContext, d dexer) {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-08 00:59:46 +02:00
|
|
|
func (j *Module) deps(ctx android.BottomUpMutatorContext) {
|
2017-09-30 02:58:17 +02:00
|
|
|
if ctx.Device() {
|
2020-06-19 00:56:48 +02:00
|
|
|
j.linter.deps(ctx)
|
|
|
|
|
2020-08-06 00:40:41 +02:00
|
|
|
sdkDeps(ctx, sdkContext(j), j.dexer)
|
2019-12-09 10:15:47 +01:00
|
|
|
|
2021-02-27 01:20:32 +01:00
|
|
|
if j.deviceProperties.SyspropPublicStub != "" {
|
|
|
|
// This is a sysprop implementation library that has a corresponding sysprop public
|
|
|
|
// stubs library, and a dependency on it so that dependencies on the implementation can
|
|
|
|
// be forwarded to the public stubs library when necessary.
|
|
|
|
ctx.AddVariationDependencies(nil, syspropPublicStubDepTag, j.deviceProperties.SyspropPublicStub)
|
2019-12-09 10:15:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-27 01:20:32 +01:00
|
|
|
libDeps := ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
|
|
|
|
ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
|
2018-10-03 07:03:40 +02:00
|
|
|
|
2021-02-12 12:46:42 +01:00
|
|
|
// Add dependency on libraries that provide additional hidden api annotations.
|
|
|
|
ctx.AddVariationDependencies(nil, hiddenApiAnnotationsTag, j.properties.Hiddenapi_additional_annotations...)
|
|
|
|
|
2020-10-19 10:25:58 +02:00
|
|
|
if ctx.DeviceConfig().VndkVersion() != "" && ctx.Config().EnforceInterPartitionJavaSdkLibrary() {
|
|
|
|
// Require java_sdk_library at inter-partition java dependency to ensure stable
|
|
|
|
// interface between partitions. If inter-partition java_library dependency is detected,
|
|
|
|
// raise build error because java_library doesn't have a stable interface.
|
|
|
|
//
|
|
|
|
// Inputs:
|
|
|
|
// PRODUCT_ENFORCE_INTER_PARTITION_JAVA_SDK_LIBRARY
|
|
|
|
// if true, enable enforcement
|
|
|
|
// PRODUCT_INTER_PARTITION_JAVA_LIBRARY_ALLOWLIST
|
|
|
|
// exception list of java_library names to allow inter-partition dependency
|
2021-02-27 01:20:32 +01:00
|
|
|
for idx := range j.properties.Libs {
|
2020-10-19 10:25:58 +02:00
|
|
|
if libDeps[idx] == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if javaDep, ok := libDeps[idx].(javaSdkLibraryEnforceContext); ok {
|
|
|
|
// java_sdk_library is always allowed at inter-partition dependency.
|
|
|
|
// So, skip check.
|
|
|
|
if _, ok := javaDep.(*SdkLibrary); ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
j.checkPartitionsForJavaDependency(ctx, "libs", javaDep)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-23 17:42:35 +02:00
|
|
|
// For library dependencies that are component libraries (like stubs), add the implementation
|
|
|
|
// as a dependency (dexpreopt needs to be against the implementation library, not stubs).
|
|
|
|
for _, dep := range libDeps {
|
|
|
|
if dep != nil {
|
|
|
|
if component, ok := dep.(SdkLibraryComponentDependency); ok {
|
|
|
|
if lib := component.OptionalSdkLibraryImplementation(); lib != nil {
|
|
|
|
ctx.AddVariationDependencies(nil, usesLibTag, *lib)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-16 20:03:10 +02:00
|
|
|
ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...)
|
2020-11-19 22:52:06 +01:00
|
|
|
ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), errorpronePluginTag, j.properties.Errorprone.Extra_check_modules...)
|
2019-11-26 19:08:34 +01:00
|
|
|
ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...)
|
2019-01-22 06:37:16 +01:00
|
|
|
|
2019-03-29 03:30:56 +01:00
|
|
|
android.ProtoDeps(ctx, &j.protoProperties)
|
2017-09-20 21:59:05 +02:00
|
|
|
if j.hasSrcExt(".proto") {
|
|
|
|
protoDeps(ctx, &j.protoProperties)
|
|
|
|
}
|
2017-08-15 22:34:18 +02:00
|
|
|
|
|
|
|
if j.hasSrcExt(".kt") {
|
|
|
|
// TODO(ccross): move this to a mutator pass that can tell if generated sources contain
|
|
|
|
// Kotlin files
|
2019-05-13 20:06:25 +02:00
|
|
|
ctx.AddVariationDependencies(nil, kotlinStdlibTag,
|
|
|
|
"kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8")
|
2019-01-24 01:14:02 +01:00
|
|
|
if len(j.properties.Plugins) > 0 {
|
2019-01-18 00:42:52 +01:00
|
|
|
ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
|
|
|
|
}
|
2017-08-15 22:34:18 +02:00
|
|
|
}
|
2018-01-04 00:06:47 +01:00
|
|
|
|
2020-01-07 17:37:02 +01:00
|
|
|
// Framework libraries need special handling in static coverage builds: they should not have
|
|
|
|
// static dependency on jacoco, otherwise there would be multiple conflicting definitions of
|
|
|
|
// the same jacoco classes coming from different bootclasspath jars.
|
|
|
|
if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
|
|
|
|
if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
|
|
|
|
j.properties.Instrument = true
|
|
|
|
}
|
|
|
|
} else if j.shouldInstrumentStatic(ctx) {
|
2018-08-29 23:10:52 +02:00
|
|
|
ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
|
2018-01-04 00:06:47 +01:00
|
|
|
}
|
2017-09-20 21:59:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func hasSrcExt(srcs []string, ext string) bool {
|
|
|
|
for _, src := range srcs {
|
|
|
|
if filepath.Ext(src) == ext {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *Module) hasSrcExt(ext string) bool {
|
|
|
|
return hasSrcExt(j.properties.Srcs, ext)
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2017-06-23 01:51:17 +02:00
|
|
|
func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
|
2019-04-18 19:56:44 +02:00
|
|
|
aidlIncludeDirs android.Paths) (string, android.Paths) {
|
2015-04-08 22:03:43 +02:00
|
|
|
|
2017-11-14 22:12:14 +01:00
|
|
|
aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
|
|
|
|
aidlIncludes = append(aidlIncludes,
|
|
|
|
android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
|
|
|
|
aidlIncludes = append(aidlIncludes,
|
|
|
|
android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
|
2015-04-08 22:03:43 +02:00
|
|
|
|
2019-04-18 19:56:44 +02:00
|
|
|
var flags []string
|
|
|
|
var deps android.Paths
|
2018-07-26 21:55:08 +02:00
|
|
|
|
2021-01-05 02:33:16 +01:00
|
|
|
flags = append(flags, j.deviceProperties.Aidl.Flags...)
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
if aidlPreprocess.Valid() {
|
|
|
|
flags = append(flags, "-p"+aidlPreprocess.String())
|
2019-04-18 19:56:44 +02:00
|
|
|
deps = append(deps, aidlPreprocess.Path())
|
|
|
|
} else if len(aidlIncludeDirs) > 0 {
|
2016-05-19 00:37:25 +02:00
|
|
|
flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
|
2015-04-08 22:03:43 +02:00
|
|
|
}
|
|
|
|
|
2019-04-18 19:56:44 +02:00
|
|
|
if len(j.exportAidlIncludeDirs) > 0 {
|
|
|
|
flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(aidlIncludes) > 0 {
|
|
|
|
flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
|
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
|
2018-02-22 20:47:25 +01:00
|
|
|
if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
|
2017-07-13 23:41:17 +02:00
|
|
|
flags = append(flags, "-I"+src.String())
|
|
|
|
}
|
2015-04-08 22:03:43 +02:00
|
|
|
|
2018-03-09 09:29:59 +01:00
|
|
|
if Bool(j.deviceProperties.Aidl.Generate_traces) {
|
|
|
|
flags = append(flags, "-t")
|
|
|
|
}
|
|
|
|
|
2018-07-17 00:37:03 +02:00
|
|
|
if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) {
|
|
|
|
flags = append(flags, "--transaction_names")
|
|
|
|
}
|
|
|
|
|
2019-04-18 19:56:44 +02:00
|
|
|
return strings.Join(flags, " "), deps
|
2015-04-08 22:03:43 +02:00
|
|
|
}
|
|
|
|
|
2017-09-06 22:41:06 +02:00
|
|
|
type deps struct {
|
2020-11-19 22:52:06 +01:00
|
|
|
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
|
2019-01-22 06:37:16 +01:00
|
|
|
|
|
|
|
disableTurbine bool
|
2017-09-06 22:41:06 +02:00
|
|
|
}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2017-12-05 18:28:08 +01:00
|
|
|
func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
|
|
|
|
for _, f := range dep.Srcs() {
|
|
|
|
if f.Ext() != ".jar" {
|
|
|
|
ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
|
|
|
|
ctx.OtherModuleName(dep.(blueprint.Module)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-05 09:44:10 +01:00
|
|
|
type linkType int
|
|
|
|
|
|
|
|
const (
|
2020-01-30 10:00:15 +01:00
|
|
|
// TODO(jiyong) rename these for better readability. Make the allowed
|
|
|
|
// and disallowed link types explicit
|
2021-02-18 12:29:05 +01:00
|
|
|
// order is important here. See rank()
|
2018-03-05 09:44:10 +01:00
|
|
|
javaCore linkType = iota
|
|
|
|
javaSdk
|
|
|
|
javaSystem
|
2020-01-30 10:00:15 +01:00
|
|
|
javaModule
|
2020-02-11 20:36:43 +01:00
|
|
|
javaSystemServer
|
2018-03-05 09:44:10 +01:00
|
|
|
javaPlatform
|
|
|
|
)
|
|
|
|
|
2021-02-18 05:10:18 +01:00
|
|
|
func (lt linkType) String() string {
|
|
|
|
switch lt {
|
|
|
|
case javaCore:
|
|
|
|
return "core Java API"
|
|
|
|
case javaSdk:
|
|
|
|
return "Android API"
|
|
|
|
case javaSystem:
|
|
|
|
return "system API"
|
|
|
|
case javaModule:
|
|
|
|
return "module API"
|
|
|
|
case javaSystemServer:
|
|
|
|
return "system server API"
|
|
|
|
case javaPlatform:
|
|
|
|
return "private API"
|
|
|
|
default:
|
2021-02-23 03:14:31 +01:00
|
|
|
panic(fmt.Errorf("unrecognized linktype: %d", lt))
|
2021-02-18 05:10:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-18 12:29:05 +01:00
|
|
|
// rank determins the total order among linkTypes. A link type of rank A can link to another link
|
|
|
|
// type of rank B only when B <= A
|
|
|
|
func (lt linkType) rank() int {
|
|
|
|
return int(lt)
|
|
|
|
}
|
|
|
|
|
2019-11-01 07:28:00 +01:00
|
|
|
type linkTypeContext interface {
|
|
|
|
android.Module
|
|
|
|
getLinkType(name string) (ret linkType, stubs bool)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) getLinkType(name string) (ret linkType, stubs bool) {
|
2020-05-19 13:06:48 +02:00
|
|
|
switch name {
|
2020-06-02 16:59:45 +02:00
|
|
|
case "core.current.stubs", "legacy.core.platform.api.stubs", "stable.core.platform.api.stubs",
|
|
|
|
"stub-annotations", "private-stub-annotations-jar",
|
|
|
|
"core-lambda-stubs", "core-generated-annotation-stubs":
|
2018-10-20 09:33:17 +02:00
|
|
|
return javaCore, true
|
2020-05-19 13:06:48 +02:00
|
|
|
case "android_stubs_current":
|
|
|
|
return javaSdk, true
|
|
|
|
case "android_system_stubs_current":
|
2018-10-20 09:33:17 +02:00
|
|
|
return javaSystem, true
|
2020-05-19 13:06:48 +02:00
|
|
|
case "android_module_lib_stubs_current":
|
|
|
|
return javaModule, true
|
|
|
|
case "android_system_server_stubs_current":
|
|
|
|
return javaSystemServer, true
|
|
|
|
case "android_test_stubs_current":
|
2018-10-20 09:33:17 +02:00
|
|
|
return javaSystem, true
|
2020-05-19 13:06:48 +02:00
|
|
|
}
|
|
|
|
|
2020-05-25 13:20:51 +02:00
|
|
|
if stub, linkType := moduleStubLinkType(name); stub {
|
|
|
|
return linkType, true
|
|
|
|
}
|
|
|
|
|
2020-05-19 13:06:48 +02:00
|
|
|
ver := m.sdkVersion()
|
|
|
|
switch ver.kind {
|
|
|
|
case sdkCore:
|
|
|
|
return javaCore, false
|
|
|
|
case sdkSystem:
|
|
|
|
return javaSystem, false
|
|
|
|
case sdkPublic:
|
2018-10-20 09:33:17 +02:00
|
|
|
return javaSdk, false
|
2020-05-19 13:06:48 +02:00
|
|
|
case sdkModule:
|
2020-01-30 10:00:15 +01:00
|
|
|
return javaModule, false
|
2020-05-19 13:06:48 +02:00
|
|
|
case sdkSystemServer:
|
2020-02-11 20:36:43 +01:00
|
|
|
return javaSystemServer, false
|
2020-05-19 13:06:48 +02:00
|
|
|
case sdkPrivate, sdkNone, sdkCorePlatform, sdkTest:
|
2018-10-20 09:33:17 +02:00
|
|
|
return javaPlatform, false
|
2020-05-19 13:06:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if !ver.valid() {
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
panic(fmt.Errorf("sdk_version is invalid. got %q", ver.raw))
|
2018-03-05 09:44:10 +01:00
|
|
|
}
|
2020-05-19 13:06:48 +02:00
|
|
|
return javaSdk, false
|
2018-03-05 09:44:10 +01:00
|
|
|
}
|
|
|
|
|
2019-11-01 07:28:00 +01:00
|
|
|
func checkLinkType(ctx android.ModuleContext, from *Module, to linkTypeContext, tag dependencyTag) {
|
2018-03-26 23:42:44 +02:00
|
|
|
if ctx.Host() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-01 07:28:00 +01:00
|
|
|
myLinkType, stubs := from.getLinkType(ctx.ModuleName())
|
2018-10-20 09:33:17 +02:00
|
|
|
if stubs {
|
|
|
|
return
|
|
|
|
}
|
2019-11-01 07:28:00 +01:00
|
|
|
otherLinkType, _ := to.getLinkType(ctx.OtherModuleName(to))
|
2018-03-05 09:44:10 +01:00
|
|
|
|
2021-02-18 12:29:05 +01:00
|
|
|
if myLinkType.rank() < otherLinkType.rank() {
|
2021-02-18 05:10:18 +01:00
|
|
|
ctx.ModuleErrorf("compiles against %v, but dependency %q is compiling against %v. "+
|
|
|
|
"In order to fix this, consider adjusting sdk_version: OR platform_apis: "+
|
|
|
|
"property of the source or target module so that target module is built "+
|
|
|
|
"with the same or smaller API set when compared to the source.",
|
|
|
|
myLinkType, ctx.OtherModuleName(to), otherLinkType)
|
|
|
|
}
|
2018-01-30 16:20:13 +01:00
|
|
|
}
|
|
|
|
|
2017-09-06 22:41:06 +02:00
|
|
|
func (j *Module) collectDeps(ctx android.ModuleContext) deps {
|
|
|
|
var deps deps
|
2017-09-19 02:41:52 +02:00
|
|
|
|
2018-03-06 22:11:51 +01:00
|
|
|
if ctx.Device() {
|
2018-06-26 00:48:06 +02:00
|
|
|
sdkDep := decodeSdkDep(ctx, sdkContext(j))
|
2018-03-06 22:11:51 +01:00
|
|
|
if sdkDep.invalidVersion {
|
2019-10-17 23:23:50 +02:00
|
|
|
ctx.AddMissingDependencies(sdkDep.bootclasspath)
|
|
|
|
ctx.AddMissingDependencies(sdkDep.java9Classpath)
|
2018-03-06 22:11:51 +01:00
|
|
|
} else if sdkDep.useFiles {
|
|
|
|
// sdkDep.jar is actually equivalent to turbine header.jar.
|
2018-05-29 23:44:55 +02:00
|
|
|
deps.classpath = append(deps.classpath, sdkDep.jars...)
|
2019-04-18 19:56:44 +02:00
|
|
|
deps.aidlPreprocess = sdkDep.aidl
|
|
|
|
} else {
|
|
|
|
deps.aidlPreprocess = sdkDep.aidl
|
2018-03-06 22:11:51 +01:00
|
|
|
}
|
2017-09-19 02:41:52 +02:00
|
|
|
}
|
|
|
|
|
2021-02-27 01:20:32 +01:00
|
|
|
linkType, _ := j.getLinkType(ctx.ModuleName())
|
|
|
|
|
2017-10-24 02:59:01 +02:00
|
|
|
ctx.VisitDirectDeps(func(module android.Module) {
|
2015-03-31 02:20:39 +02:00
|
|
|
otherName := ctx.OtherModuleName(module)
|
2017-07-07 23:47:12 +02:00
|
|
|
tag := ctx.OtherModuleDependencyTag(module)
|
|
|
|
|
2020-10-10 03:59:49 +02:00
|
|
|
if IsJniDepTag(tag) {
|
2018-10-05 00:21:03 +02:00
|
|
|
// Handled by AndroidApp.collectAppDeps
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if tag == certificateTag {
|
|
|
|
// Handled by AndroidApp.collectAppDeps
|
2018-10-03 07:03:40 +02:00
|
|
|
return
|
|
|
|
}
|
2020-04-08 20:09:30 +02:00
|
|
|
|
2021-02-01 22:59:03 +01:00
|
|
|
if dep, ok := module.(SdkLibraryDependency); ok {
|
2019-02-11 23:03:51 +01:00
|
|
|
switch tag {
|
|
|
|
case libTag:
|
|
|
|
deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
|
2019-04-17 20:11:46 +02:00
|
|
|
case staticLibTag:
|
2019-02-11 23:03:51 +01:00
|
|
|
ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
|
|
|
|
}
|
2021-02-01 22:59:03 +01:00
|
|
|
} else if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
|
|
|
|
dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
|
2021-02-27 01:20:32 +01:00
|
|
|
if linkType != javaPlatform &&
|
|
|
|
ctx.OtherModuleHasProvider(module, SyspropPublicStubInfoProvider) {
|
|
|
|
// dep is a sysprop implementation library, but this module is not linking against
|
|
|
|
// the platform, so it gets the sysprop public stubs library instead. Replace
|
|
|
|
// dep with the JavaInfo from the SyspropPublicStubInfoProvider.
|
|
|
|
syspropDep := ctx.OtherModuleProvider(module, SyspropPublicStubInfoProvider).(SyspropPublicStubInfo)
|
|
|
|
dep = syspropDep.JavaInfo
|
|
|
|
}
|
2017-12-05 18:28:08 +01:00
|
|
|
switch tag {
|
|
|
|
case bootClasspathTag:
|
2021-02-01 22:59:03 +01:00
|
|
|
deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars...)
|
2018-10-16 01:18:06 +02:00
|
|
|
case libTag, instrumentationForTag:
|
2021-02-01 22:59:03 +01:00
|
|
|
deps.classpath = append(deps.classpath, dep.HeaderJars...)
|
|
|
|
deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs...)
|
|
|
|
addPlugins(&deps, dep.ExportedPlugins, dep.ExportedPluginClasses...)
|
|
|
|
deps.disableTurbine = deps.disableTurbine || dep.ExportedPluginDisableTurbine
|
2019-10-17 23:23:50 +02:00
|
|
|
case java9LibTag:
|
2021-02-01 22:59:03 +01:00
|
|
|
deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars...)
|
2017-12-05 18:28:08 +01:00
|
|
|
case staticLibTag:
|
2021-02-01 22:59:03 +01:00
|
|
|
deps.classpath = append(deps.classpath, dep.HeaderJars...)
|
|
|
|
deps.staticJars = append(deps.staticJars, dep.ImplementationJars...)
|
|
|
|
deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars...)
|
|
|
|
deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars...)
|
|
|
|
deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs...)
|
|
|
|
addPlugins(&deps, dep.ExportedPlugins, dep.ExportedPluginClasses...)
|
2020-11-20 03:06:03 +01:00
|
|
|
// Turbine doesn't run annotation processors, so any module that uses an
|
|
|
|
// annotation processor that generates API is incompatible with the turbine
|
|
|
|
// optimization.
|
2021-02-01 22:59:03 +01:00
|
|
|
deps.disableTurbine = deps.disableTurbine || dep.ExportedPluginDisableTurbine
|
2019-01-22 06:37:16 +01:00
|
|
|
case pluginTag:
|
2021-02-01 22:59:03 +01:00
|
|
|
if plugin, ok := module.(*Plugin); ok {
|
2019-01-22 06:37:16 +01:00
|
|
|
if plugin.pluginProperties.Processor_class != nil {
|
2021-02-01 22:59:03 +01:00
|
|
|
addPlugins(&deps, dep.ImplementationAndResourcesJars, *plugin.pluginProperties.Processor_class)
|
2019-11-26 19:08:34 +01:00
|
|
|
} else {
|
2021-02-01 22:59:03 +01:00
|
|
|
addPlugins(&deps, dep.ImplementationAndResourcesJars)
|
2019-01-22 06:37:16 +01:00
|
|
|
}
|
2020-11-20 03:06:03 +01:00
|
|
|
// Turbine doesn't run annotation processors, so any module that uses an
|
|
|
|
// annotation processor that generates API is incompatible with the turbine
|
|
|
|
// optimization.
|
2019-01-22 06:37:16 +01:00
|
|
|
deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
|
|
|
|
} else {
|
|
|
|
ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
|
|
|
|
}
|
2020-11-19 22:52:06 +01:00
|
|
|
case errorpronePluginTag:
|
2021-02-01 22:59:03 +01:00
|
|
|
if _, ok := module.(*Plugin); ok {
|
|
|
|
deps.errorProneProcessorPath = append(deps.errorProneProcessorPath, dep.ImplementationAndResourcesJars...)
|
2020-11-19 22:52:06 +01:00
|
|
|
} else {
|
|
|
|
ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
|
|
|
|
}
|
2019-11-26 19:08:34 +01:00
|
|
|
case exportedPluginTag:
|
2021-02-01 22:59:03 +01:00
|
|
|
if plugin, ok := module.(*Plugin); ok {
|
|
|
|
j.exportedPluginJars = append(j.exportedPluginJars, dep.ImplementationAndResourcesJars...)
|
2019-11-26 19:08:34 +01:00
|
|
|
if plugin.pluginProperties.Processor_class != nil {
|
|
|
|
j.exportedPluginClasses = append(j.exportedPluginClasses, *plugin.pluginProperties.Processor_class)
|
|
|
|
}
|
2020-11-20 03:06:03 +01:00
|
|
|
// Turbine doesn't run annotation processors, so any module that uses an
|
|
|
|
// annotation processor that generates API is incompatible with the turbine
|
|
|
|
// optimization.
|
|
|
|
j.exportedDisableTurbine = Bool(plugin.pluginProperties.Generates_api)
|
2019-11-26 19:08:34 +01:00
|
|
|
} else {
|
|
|
|
ctx.PropertyErrorf("exported_plugins", "%q is not a java_plugin module", otherName)
|
|
|
|
}
|
2017-12-05 18:28:08 +01:00
|
|
|
case kotlinStdlibTag:
|
2021-02-01 22:59:03 +01:00
|
|
|
deps.kotlinStdlib = append(deps.kotlinStdlib, dep.HeaderJars...)
|
2019-01-18 00:42:52 +01:00
|
|
|
case kotlinAnnotationsTag:
|
2021-02-01 22:59:03 +01:00
|
|
|
deps.kotlinAnnotations = dep.HeaderJars
|
2021-02-27 01:20:32 +01:00
|
|
|
case syspropPublicStubDepTag:
|
|
|
|
// This is a sysprop implementation library, forward the JavaInfoProvider from
|
|
|
|
// the corresponding sysprop public stub library as SyspropPublicStubInfoProvider.
|
|
|
|
ctx.SetProvider(SyspropPublicStubInfoProvider, SyspropPublicStubInfo{
|
|
|
|
JavaInfo: dep,
|
|
|
|
})
|
2017-12-05 18:28:08 +01:00
|
|
|
}
|
2021-02-01 22:59:03 +01:00
|
|
|
} else if dep, ok := module.(android.SourceFileProducer); ok {
|
2017-12-05 18:28:08 +01:00
|
|
|
switch tag {
|
|
|
|
case libTag:
|
|
|
|
checkProducesJars(ctx, dep)
|
|
|
|
deps.classpath = append(deps.classpath, dep.Srcs()...)
|
|
|
|
case staticLibTag:
|
|
|
|
checkProducesJars(ctx, dep)
|
|
|
|
deps.classpath = append(deps.classpath, dep.Srcs()...)
|
|
|
|
deps.staticJars = append(deps.staticJars, dep.Srcs()...)
|
|
|
|
deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
|
|
|
|
}
|
2021-02-01 22:59:03 +01:00
|
|
|
} else {
|
2017-07-07 23:47:12 +02:00
|
|
|
switch tag {
|
2019-09-20 14:50:52 +02:00
|
|
|
case bootClasspathTag:
|
|
|
|
// If a system modules dependency has been added to the bootclasspath
|
|
|
|
// then add its libs to the bootclasspath.
|
2019-11-19 20:44:10 +01:00
|
|
|
sm := module.(SystemModulesProvider)
|
|
|
|
deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...)
|
2019-09-20 14:50:52 +02:00
|
|
|
|
2017-09-30 02:58:17 +02:00
|
|
|
case systemModulesTag:
|
|
|
|
if deps.systemModules != nil {
|
|
|
|
panic("Found two system module dependencies")
|
|
|
|
}
|
2019-11-19 20:44:10 +01:00
|
|
|
sm := module.(SystemModulesProvider)
|
|
|
|
outputDir, outputDeps := sm.OutputDirAndDeps()
|
|
|
|
deps.systemModules = &systemModules{outputDir, outputDeps}
|
2017-07-07 23:47:12 +02:00
|
|
|
}
|
|
|
|
}
|
2020-12-03 17:50:22 +01:00
|
|
|
|
2020-12-16 17:16:11 +01:00
|
|
|
addCLCFromDep(ctx, module, j.classLoaderContexts)
|
2015-03-31 02:20:39 +02:00
|
|
|
})
|
|
|
|
|
2017-09-06 22:41:06 +02:00
|
|
|
return deps
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2019-11-26 19:08:34 +01:00
|
|
|
func addPlugins(deps *deps, pluginJars android.Paths, pluginClasses ...string) {
|
|
|
|
deps.processorPath = append(deps.processorPath, pluginJars...)
|
|
|
|
deps.processorClasses = append(deps.processorClasses, pluginClasses...)
|
|
|
|
}
|
|
|
|
|
2019-10-28 19:37:20 +01:00
|
|
|
func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) javaVersion {
|
2018-04-18 02:38:36 +02:00
|
|
|
if javaVersion != "" {
|
2019-10-28 19:37:20 +01:00
|
|
|
return normalizeJavaVersion(ctx, javaVersion)
|
2020-05-15 03:05:32 +02:00
|
|
|
} else if ctx.Device() {
|
|
|
|
return sdkContext.sdkVersion().defaultJavaLanguageVersion(ctx)
|
2018-04-18 02:38:36 +02:00
|
|
|
} else {
|
2019-10-28 19:37:20 +01:00
|
|
|
return JAVA_VERSION_9
|
2018-04-18 02:38:36 +02:00
|
|
|
}
|
2019-10-28 19:37:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type javaVersion int
|
|
|
|
|
|
|
|
const (
|
|
|
|
JAVA_VERSION_UNSUPPORTED = 0
|
|
|
|
JAVA_VERSION_6 = 6
|
|
|
|
JAVA_VERSION_7 = 7
|
|
|
|
JAVA_VERSION_8 = 8
|
|
|
|
JAVA_VERSION_9 = 9
|
|
|
|
)
|
2018-04-18 02:38:36 +02:00
|
|
|
|
2019-10-28 19:37:20 +01:00
|
|
|
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"
|
|
|
|
}
|
2018-04-18 02:38:36 +02:00
|
|
|
}
|
|
|
|
|
2019-10-28 19:37:20 +01:00
|
|
|
// Returns true if javac targeting this version uses system modules instead of a bootclasspath.
|
|
|
|
func (v javaVersion) usesJavaModules() bool {
|
|
|
|
return v >= 9
|
|
|
|
}
|
|
|
|
|
|
|
|
func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) javaVersion {
|
Normalize and validate the java_version property.
There are two parts to this change.
Normalization: If a module specifies 'java_version: "9"', this is now
normalized into 'java_version: "1.9"'. Users might reasonably assume
that "9" should be valid, since javac treats them as synonyms (and, in
fact, the javac documentation lists "9" as a valid value but doesn't
mention "1.9"). However, the soong code that triggers JPMS support
(i.e. setting -system rather than --boot-class-path) looks for the
string "1.9", so prior to this change modules specifying "9" would
fail with a confusing error ('javac: option --boot-class-path not
allowed with target 1.9'). Normalizing "9" to "1.9" fixes this. (The
change normalizes the other supported values, too, for consistency.)
Validation: This change also makes the build fail-fast with a clear
error message for invalid values. In particular, modules specifying
"10" or "11" fail with an explicit message that this is not supported,
in anticipation of the switch to OpenJDK 11. Prior to this change,
modules setting those values would get the confusing
'--boot-class-path not allowed' error described about since JPMS
support would not be triggered. (That could be fixed by changing the
JPMS logic to trigger on "10" and "11", but that would be dangerous
since support in the rest of the system for v54 and v55 class files is
unproven: it is better to fail explicitly.) (This change also makes it
fail-fast for any unrecognized values.)
Test: make java
Test: make targets with java_version set to "1.8", "8", "1.9", and "9", all succeed ("9" fails without this change)
Test: make targets with java_version set to "10" and "11", fail with the explicit "not supported" message
Test: make target with java_version set to "xxx", fails fast with the "unrecognized" message
Bug: 131683177
Change-Id: I2f5eb496c29d7736c68c01401c3f0967aeae99fc
2019-07-12 14:16:17 +02:00
|
|
|
switch javaVersion {
|
|
|
|
case "1.6", "6":
|
2019-10-28 19:37:20 +01:00
|
|
|
return JAVA_VERSION_6
|
Normalize and validate the java_version property.
There are two parts to this change.
Normalization: If a module specifies 'java_version: "9"', this is now
normalized into 'java_version: "1.9"'. Users might reasonably assume
that "9" should be valid, since javac treats them as synonyms (and, in
fact, the javac documentation lists "9" as a valid value but doesn't
mention "1.9"). However, the soong code that triggers JPMS support
(i.e. setting -system rather than --boot-class-path) looks for the
string "1.9", so prior to this change modules specifying "9" would
fail with a confusing error ('javac: option --boot-class-path not
allowed with target 1.9'). Normalizing "9" to "1.9" fixes this. (The
change normalizes the other supported values, too, for consistency.)
Validation: This change also makes the build fail-fast with a clear
error message for invalid values. In particular, modules specifying
"10" or "11" fail with an explicit message that this is not supported,
in anticipation of the switch to OpenJDK 11. Prior to this change,
modules setting those values would get the confusing
'--boot-class-path not allowed' error described about since JPMS
support would not be triggered. (That could be fixed by changing the
JPMS logic to trigger on "10" and "11", but that would be dangerous
since support in the rest of the system for v54 and v55 class files is
unproven: it is better to fail explicitly.) (This change also makes it
fail-fast for any unrecognized values.)
Test: make java
Test: make targets with java_version set to "1.8", "8", "1.9", and "9", all succeed ("9" fails without this change)
Test: make targets with java_version set to "10" and "11", fail with the explicit "not supported" message
Test: make target with java_version set to "xxx", fails fast with the "unrecognized" message
Bug: 131683177
Change-Id: I2f5eb496c29d7736c68c01401c3f0967aeae99fc
2019-07-12 14:16:17 +02:00
|
|
|
case "1.7", "7":
|
2019-10-28 19:37:20 +01:00
|
|
|
return JAVA_VERSION_7
|
Normalize and validate the java_version property.
There are two parts to this change.
Normalization: If a module specifies 'java_version: "9"', this is now
normalized into 'java_version: "1.9"'. Users might reasonably assume
that "9" should be valid, since javac treats them as synonyms (and, in
fact, the javac documentation lists "9" as a valid value but doesn't
mention "1.9"). However, the soong code that triggers JPMS support
(i.e. setting -system rather than --boot-class-path) looks for the
string "1.9", so prior to this change modules specifying "9" would
fail with a confusing error ('javac: option --boot-class-path not
allowed with target 1.9'). Normalizing "9" to "1.9" fixes this. (The
change normalizes the other supported values, too, for consistency.)
Validation: This change also makes the build fail-fast with a clear
error message for invalid values. In particular, modules specifying
"10" or "11" fail with an explicit message that this is not supported,
in anticipation of the switch to OpenJDK 11. Prior to this change,
modules setting those values would get the confusing
'--boot-class-path not allowed' error described about since JPMS
support would not be triggered. (That could be fixed by changing the
JPMS logic to trigger on "10" and "11", but that would be dangerous
since support in the rest of the system for v54 and v55 class files is
unproven: it is better to fail explicitly.) (This change also makes it
fail-fast for any unrecognized values.)
Test: make java
Test: make targets with java_version set to "1.8", "8", "1.9", and "9", all succeed ("9" fails without this change)
Test: make targets with java_version set to "10" and "11", fail with the explicit "not supported" message
Test: make target with java_version set to "xxx", fails fast with the "unrecognized" message
Bug: 131683177
Change-Id: I2f5eb496c29d7736c68c01401c3f0967aeae99fc
2019-07-12 14:16:17 +02:00
|
|
|
case "1.8", "8":
|
2019-10-28 19:37:20 +01:00
|
|
|
return JAVA_VERSION_8
|
Normalize and validate the java_version property.
There are two parts to this change.
Normalization: If a module specifies 'java_version: "9"', this is now
normalized into 'java_version: "1.9"'. Users might reasonably assume
that "9" should be valid, since javac treats them as synonyms (and, in
fact, the javac documentation lists "9" as a valid value but doesn't
mention "1.9"). However, the soong code that triggers JPMS support
(i.e. setting -system rather than --boot-class-path) looks for the
string "1.9", so prior to this change modules specifying "9" would
fail with a confusing error ('javac: option --boot-class-path not
allowed with target 1.9'). Normalizing "9" to "1.9" fixes this. (The
change normalizes the other supported values, too, for consistency.)
Validation: This change also makes the build fail-fast with a clear
error message for invalid values. In particular, modules specifying
"10" or "11" fail with an explicit message that this is not supported,
in anticipation of the switch to OpenJDK 11. Prior to this change,
modules setting those values would get the confusing
'--boot-class-path not allowed' error described about since JPMS
support would not be triggered. (That could be fixed by changing the
JPMS logic to trigger on "10" and "11", but that would be dangerous
since support in the rest of the system for v54 and v55 class files is
unproven: it is better to fail explicitly.) (This change also makes it
fail-fast for any unrecognized values.)
Test: make java
Test: make targets with java_version set to "1.8", "8", "1.9", and "9", all succeed ("9" fails without this change)
Test: make targets with java_version set to "10" and "11", fail with the explicit "not supported" message
Test: make target with java_version set to "xxx", fails fast with the "unrecognized" message
Bug: 131683177
Change-Id: I2f5eb496c29d7736c68c01401c3f0967aeae99fc
2019-07-12 14:16:17 +02:00
|
|
|
case "1.9", "9":
|
2019-10-28 19:37:20 +01:00
|
|
|
return JAVA_VERSION_9
|
Normalize and validate the java_version property.
There are two parts to this change.
Normalization: If a module specifies 'java_version: "9"', this is now
normalized into 'java_version: "1.9"'. Users might reasonably assume
that "9" should be valid, since javac treats them as synonyms (and, in
fact, the javac documentation lists "9" as a valid value but doesn't
mention "1.9"). However, the soong code that triggers JPMS support
(i.e. setting -system rather than --boot-class-path) looks for the
string "1.9", so prior to this change modules specifying "9" would
fail with a confusing error ('javac: option --boot-class-path not
allowed with target 1.9'). Normalizing "9" to "1.9" fixes this. (The
change normalizes the other supported values, too, for consistency.)
Validation: This change also makes the build fail-fast with a clear
error message for invalid values. In particular, modules specifying
"10" or "11" fail with an explicit message that this is not supported,
in anticipation of the switch to OpenJDK 11. Prior to this change,
modules setting those values would get the confusing
'--boot-class-path not allowed' error described about since JPMS
support would not be triggered. (That could be fixed by changing the
JPMS logic to trigger on "10" and "11", but that would be dangerous
since support in the rest of the system for v54 and v55 class files is
unproven: it is better to fail explicitly.) (This change also makes it
fail-fast for any unrecognized values.)
Test: make java
Test: make targets with java_version set to "1.8", "8", "1.9", and "9", all succeed ("9" fails without this change)
Test: make targets with java_version set to "10" and "11", fail with the explicit "not supported" message
Test: make target with java_version set to "xxx", fails fast with the "unrecognized" message
Bug: 131683177
Change-Id: I2f5eb496c29d7736c68c01401c3f0967aeae99fc
2019-07-12 14:16:17 +02:00
|
|
|
case "10", "11":
|
|
|
|
ctx.PropertyErrorf("java_version", "Java language levels above 9 are not supported")
|
2019-10-28 19:37:20 +01:00
|
|
|
return JAVA_VERSION_UNSUPPORTED
|
Normalize and validate the java_version property.
There are two parts to this change.
Normalization: If a module specifies 'java_version: "9"', this is now
normalized into 'java_version: "1.9"'. Users might reasonably assume
that "9" should be valid, since javac treats them as synonyms (and, in
fact, the javac documentation lists "9" as a valid value but doesn't
mention "1.9"). However, the soong code that triggers JPMS support
(i.e. setting -system rather than --boot-class-path) looks for the
string "1.9", so prior to this change modules specifying "9" would
fail with a confusing error ('javac: option --boot-class-path not
allowed with target 1.9'). Normalizing "9" to "1.9" fixes this. (The
change normalizes the other supported values, too, for consistency.)
Validation: This change also makes the build fail-fast with a clear
error message for invalid values. In particular, modules specifying
"10" or "11" fail with an explicit message that this is not supported,
in anticipation of the switch to OpenJDK 11. Prior to this change,
modules setting those values would get the confusing
'--boot-class-path not allowed' error described about since JPMS
support would not be triggered. (That could be fixed by changing the
JPMS logic to trigger on "10" and "11", but that would be dangerous
since support in the rest of the system for v54 and v55 class files is
unproven: it is better to fail explicitly.) (This change also makes it
fail-fast for any unrecognized values.)
Test: make java
Test: make targets with java_version set to "1.8", "8", "1.9", and "9", all succeed ("9" fails without this change)
Test: make targets with java_version set to "10" and "11", fail with the explicit "not supported" message
Test: make target with java_version set to "xxx", fails fast with the "unrecognized" message
Bug: 131683177
Change-Id: I2f5eb496c29d7736c68c01401c3f0967aeae99fc
2019-07-12 14:16:17 +02:00
|
|
|
default:
|
|
|
|
ctx.PropertyErrorf("java_version", "Unrecognized Java language level")
|
2019-10-28 19:37:20 +01:00
|
|
|
return JAVA_VERSION_UNSUPPORTED
|
Normalize and validate the java_version property.
There are two parts to this change.
Normalization: If a module specifies 'java_version: "9"', this is now
normalized into 'java_version: "1.9"'. Users might reasonably assume
that "9" should be valid, since javac treats them as synonyms (and, in
fact, the javac documentation lists "9" as a valid value but doesn't
mention "1.9"). However, the soong code that triggers JPMS support
(i.e. setting -system rather than --boot-class-path) looks for the
string "1.9", so prior to this change modules specifying "9" would
fail with a confusing error ('javac: option --boot-class-path not
allowed with target 1.9'). Normalizing "9" to "1.9" fixes this. (The
change normalizes the other supported values, too, for consistency.)
Validation: This change also makes the build fail-fast with a clear
error message for invalid values. In particular, modules specifying
"10" or "11" fail with an explicit message that this is not supported,
in anticipation of the switch to OpenJDK 11. Prior to this change,
modules setting those values would get the confusing
'--boot-class-path not allowed' error described about since JPMS
support would not be triggered. (That could be fixed by changing the
JPMS logic to trigger on "10" and "11", but that would be dangerous
since support in the rest of the system for v54 and v55 class files is
unproven: it is better to fail explicitly.) (This change also makes it
fail-fast for any unrecognized values.)
Test: make java
Test: make targets with java_version set to "1.8", "8", "1.9", and "9", all succeed ("9" fails without this change)
Test: make targets with java_version set to "10" and "11", fail with the explicit "not supported" message
Test: make target with java_version set to "xxx", fails fast with the "unrecognized" message
Bug: 131683177
Change-Id: I2f5eb496c29d7736c68c01401c3f0967aeae99fc
2019-07-12 14:16:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
|
2015-04-08 22:03:43 +02:00
|
|
|
|
2015-04-13 22:53:40 +02:00
|
|
|
var flags javaBuilderFlags
|
|
|
|
|
Enable Java 9 language support through java_version: "1.9" alone.
Some logic in java.go was conditional on TargetOpenJDK9(), which in
turn relies on a global build flag (EXPERIMENTAL_USE_OPENJDK9=true).
This CL changes the logic in collectBuilderFlags() to check for
javaVersion greater or equal "1.9" instead, which is true when either
EXPERIMENTAL_USE_OPENJDK9=true (global) or javaVersion "1.9" (a
per-build target attribute).
Because the value of flags.javaVersion isn't available there,
TargetOpenJDK9()-dependent logic in Module.deps() was changed to
be unconditional; as far as I understand, this means that system
modules deps will be built regardless of whether they're needed
later in the build. This will probably slow down the build
unnecessarily until the first user of these system modules appears
(expected soon), but probably not by much.
There is some TargetOpenJDK9() related logic remaining in droiddoc.go,
but this doesn't seem to break the build of Java 9 language sources
and is probably no longer needed now that metalava is used for
generating the stubs (thanks to Nan!), and those do not contain any
Java 9 language features.
Bug: 112443425
Test: Checked that Java 9 language support works on AOSP after
this CL without a need for EXPERIMENTAL_USE_OPENJDK9=true,
ie. after also patching CL http://r.android.com/646840 ,
"make docs droid cts" completes, the device boots and
Java9LanguageFeaturesTest passes.
Change-Id: I393b97a7b3bb4c1c3d06580c639e94ff6cf916ff
2018-09-11 17:21:05 +02:00
|
|
|
// javaVersion flag.
|
|
|
|
flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
|
|
|
|
|
2018-06-20 07:47:35 +02:00
|
|
|
if ctx.Config().RunErrorProne() {
|
2020-11-19 22:52:06 +01:00
|
|
|
if config.ErrorProneClasspath == nil && ctx.Config().TestProductVariables == nil {
|
2018-06-20 07:47:35 +02:00
|
|
|
ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
|
|
|
|
}
|
|
|
|
|
|
|
|
errorProneFlags := []string{
|
|
|
|
"-Xplugin:ErrorProne",
|
|
|
|
"${config.ErrorProneChecks}",
|
|
|
|
}
|
|
|
|
errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
|
|
|
|
|
|
|
|
flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
|
|
|
|
"'" + strings.Join(errorProneFlags, " ") + "'"
|
|
|
|
flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
|
2018-01-23 06:27:21 +01:00
|
|
|
}
|
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
// classpath
|
2018-01-11 01:06:12 +01:00
|
|
|
flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
|
|
|
|
flags.classpath = append(flags.classpath, deps.classpath...)
|
2019-10-17 23:23:50 +02:00
|
|
|
flags.java9Classpath = append(flags.java9Classpath, deps.java9Classpath...)
|
2018-06-20 07:43:34 +02:00
|
|
|
flags.processorPath = append(flags.processorPath, deps.processorPath...)
|
2020-11-19 22:52:06 +01:00
|
|
|
flags.errorProneProcessorPath = append(flags.errorProneProcessorPath, deps.errorProneProcessorPath...)
|
2018-01-03 03:14:25 +01:00
|
|
|
|
2020-04-22 20:44:34 +02:00
|
|
|
flags.processors = append(flags.processors, deps.processorClasses...)
|
|
|
|
flags.processors = android.FirstUniqueStrings(flags.processors)
|
2019-01-22 06:37:16 +01:00
|
|
|
|
2019-10-28 19:37:20 +01:00
|
|
|
if len(flags.bootClasspath) == 0 && ctx.Host() && !flags.javaVersion.usesJavaModules() &&
|
|
|
|
decodeSdkDep(ctx, sdkContext(j)).hasStandardLibs() {
|
2018-01-03 03:14:25 +01:00
|
|
|
// Give host-side tools a version of OpenJDK's standard libraries
|
|
|
|
// close to what they're targeting. As of Dec 2017, AOSP is only
|
|
|
|
// bundling OpenJDK 8 and 9, so nothing < 8 is available.
|
|
|
|
//
|
|
|
|
// When building with OpenJDK 8, the following should have no
|
|
|
|
// effect since those jars would be available by default.
|
|
|
|
//
|
|
|
|
// When building with OpenJDK 9 but targeting a version < 1.8,
|
|
|
|
// putting them on the bootclasspath means that:
|
|
|
|
// a) code can't (accidentally) refer to OpenJDK 9 specific APIs
|
|
|
|
// b) references to existing APIs are not reinterpreted in an
|
|
|
|
// OpenJDK 9-specific way, eg. calls to subclasses of
|
|
|
|
// java.nio.Buffer as in http://b/70862583
|
|
|
|
java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
|
|
|
|
flags.bootClasspath = append(flags.bootClasspath,
|
|
|
|
android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
|
|
|
|
android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
|
2018-02-06 19:34:32 +01:00
|
|
|
if Bool(j.properties.Use_tools_jar) {
|
|
|
|
flags.bootClasspath = append(flags.bootClasspath,
|
|
|
|
android.PathForSource(ctx, java8Home, "lib/tools.jar"))
|
|
|
|
}
|
2018-01-03 03:14:25 +01:00
|
|
|
}
|
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
// systemModules
|
2019-07-16 22:57:13 +02:00
|
|
|
flags.systemModules = deps.systemModules
|
2017-09-30 02:58:17 +02:00
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
// aidl flags.
|
2019-04-18 19:56:44 +02:00
|
|
|
flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2020-10-21 16:06:35 +02:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2020-10-30 06:01:35 +01:00
|
|
|
func (j *Module) collectJavacFlags(
|
|
|
|
ctx android.ModuleContext, flags javaBuilderFlags, srcFiles android.Paths) javaBuilderFlags {
|
2020-10-21 16:06:35 +02:00
|
|
|
// javac flags.
|
|
|
|
javacFlags := j.properties.Javacflags
|
|
|
|
|
|
|
|
if ctx.Config().MinimizeJavaDebugInfo() && !ctx.Host() {
|
|
|
|
// For non-host binaries, override the -g flag passed globally to remove
|
|
|
|
// local variable debug info to reduce disk and memory usage.
|
|
|
|
javacFlags = append(javacFlags, "-g:source,lines")
|
|
|
|
}
|
|
|
|
javacFlags = append(javacFlags, "-Xlint:-dep-ann")
|
|
|
|
|
|
|
|
if flags.javaVersion.usesJavaModules() {
|
|
|
|
javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
|
|
|
|
|
|
|
|
if j.properties.Patch_module != nil {
|
|
|
|
// Manually specify build directory in case it is not under the repo root.
|
2020-10-30 06:01:35 +01:00
|
|
|
// (javac doesn't seem to expand into symbolic links when searching for patch-module targets, so
|
2020-10-21 16:06:35 +02:00
|
|
|
// just adding a symlink under the root doesn't help.)
|
2020-10-30 06:01:35 +01:00
|
|
|
patchPaths := []string{".", ctx.Config().BuildDir()}
|
|
|
|
|
|
|
|
// b/150878007
|
|
|
|
//
|
|
|
|
// Workaround to support *Bazel-executed* JDK9 javac in Bazel's
|
|
|
|
// execution root for --patch-module. If this javac command line is
|
|
|
|
// invoked within Bazel's execution root working directory, the top
|
|
|
|
// level directories (e.g. libcore/, tools/, frameworks/) are all
|
|
|
|
// symlinks. JDK9 javac does not traverse into symlinks, which causes
|
|
|
|
// --patch-module to fail source file lookups when invoked in the
|
|
|
|
// execution root.
|
|
|
|
//
|
|
|
|
// Short of patching javac or enumerating *all* directories as possible
|
|
|
|
// input dirs, manually add the top level dir of the source files to be
|
|
|
|
// compiled.
|
|
|
|
topLevelDirs := map[string]bool{}
|
|
|
|
for _, srcFilePath := range srcFiles {
|
|
|
|
srcFileParts := strings.Split(srcFilePath.String(), "/")
|
|
|
|
// Ignore source files that are already in the top level directory
|
|
|
|
// as well as generated files in the out directory. The out
|
|
|
|
// directory may be an absolute path, which means srcFileParts[0] is the
|
|
|
|
// empty string, so check that as well. Note that "out" in Bazel's execution
|
|
|
|
// root is *not* a symlink, which doesn't cause problems for --patch-modules
|
|
|
|
// anyway, so it's fine to not apply this workaround for generated
|
|
|
|
// source files.
|
|
|
|
if len(srcFileParts) > 1 &&
|
|
|
|
srcFileParts[0] != "" &&
|
|
|
|
srcFileParts[0] != "out" {
|
|
|
|
topLevelDirs[srcFileParts[0]] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
patchPaths = append(patchPaths, android.SortedStringKeys(topLevelDirs)...)
|
|
|
|
|
2020-10-21 16:06:35 +02:00
|
|
|
classPath := flags.classpath.FormJavaClassPath("")
|
|
|
|
if classPath != "" {
|
2020-10-30 06:01:35 +01:00
|
|
|
patchPaths = append(patchPaths, classPath)
|
2020-10-21 16:06:35 +02:00
|
|
|
}
|
2020-10-30 06:01:35 +01:00
|
|
|
javacFlags = append(
|
|
|
|
javacFlags,
|
|
|
|
"--patch-module="+String(j.properties.Patch_module)+"="+strings.Join(patchPaths, ":"))
|
2020-10-21 16:06:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 05:21:55 +02:00
|
|
|
if len(javacFlags) > 0 {
|
|
|
|
// optimization.
|
|
|
|
ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
|
|
|
|
flags.javacFlags = "$javacFlags"
|
|
|
|
}
|
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
return flags
|
|
|
|
}
|
2015-04-08 22:03:43 +02:00
|
|
|
|
2019-05-13 18:23:20 +02:00
|
|
|
func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
2017-11-14 22:12:14 +01:00
|
|
|
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
|
2017-10-19 22:06:22 +02:00
|
|
|
|
|
|
|
deps := j.collectDeps(ctx)
|
|
|
|
flags := j.collectBuilderFlags(ctx, deps)
|
|
|
|
|
2019-10-28 19:37:20 +01:00
|
|
|
if flags.javaVersion.usesJavaModules() {
|
2017-10-19 22:06:22 +02:00
|
|
|
j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
|
|
|
|
}
|
2019-03-06 07:25:09 +01:00
|
|
|
srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
|
2017-09-20 21:59:05 +02:00
|
|
|
if hasSrcExt(srcFiles.Strings(), ".proto") {
|
2017-12-15 00:22:43 +01:00
|
|
|
flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
|
2017-09-20 21:59:05 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 02:13:36 +02:00
|
|
|
kotlinCommonSrcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Common_srcs, nil)
|
|
|
|
if len(kotlinCommonSrcFiles.FilterOutByExt(".kt")) > 0 {
|
|
|
|
ctx.PropertyErrorf("common_srcs", "common_srcs must be .kt files")
|
|
|
|
}
|
|
|
|
|
2017-11-16 08:01:59 +01:00
|
|
|
srcFiles = j.genSources(ctx, srcFiles, flags)
|
|
|
|
|
2020-10-30 06:01:35 +01:00
|
|
|
// Collect javac flags only after computing the full set of srcFiles to
|
|
|
|
// ensure that the --patch-module lookup paths are complete.
|
|
|
|
flags = j.collectJavacFlags(ctx, flags, srcFiles)
|
2020-10-21 16:06:35 +02:00
|
|
|
|
2017-11-16 08:01:59 +01:00
|
|
|
srcJars := srcFiles.FilterByExt(".srcjar")
|
2017-10-17 03:07:29 +02:00
|
|
|
srcJars = append(srcJars, deps.srcJars...)
|
2019-05-13 18:23:20 +02:00
|
|
|
if aaptSrcJar != nil {
|
|
|
|
srcJars = append(srcJars, aaptSrcJar)
|
|
|
|
}
|
2015-04-16 23:09:14 +02:00
|
|
|
|
2019-01-18 20:51:25 +01:00
|
|
|
if j.properties.Jarjar_rules != nil {
|
2019-03-06 07:25:09 +01:00
|
|
|
j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
|
2019-01-18 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
2017-10-18 23:44:18 +02:00
|
|
|
jarName := ctx.ModuleName() + ".jar"
|
|
|
|
|
2018-02-13 15:32:54 +01:00
|
|
|
javaSrcFiles := srcFiles.FilterByExt(".java")
|
|
|
|
var uniqueSrcFiles android.Paths
|
|
|
|
set := make(map[string]bool)
|
|
|
|
for _, v := range javaSrcFiles {
|
|
|
|
if _, found := set[v.String()]; !found {
|
|
|
|
set[v.String()] = true
|
|
|
|
uniqueSrcFiles = append(uniqueSrcFiles, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 09:41:30 +02:00
|
|
|
// Collect .java files for AIDEGen
|
|
|
|
j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, uniqueSrcFiles.Strings()...)
|
|
|
|
|
2018-08-27 21:37:09 +02:00
|
|
|
var kotlinJars android.Paths
|
|
|
|
|
2017-08-15 22:34:18 +02:00
|
|
|
if srcFiles.HasExt(".kt") {
|
2018-08-21 17:10:29 +02:00
|
|
|
// user defined kotlin flags.
|
|
|
|
kotlincFlags := j.properties.Kotlincflags
|
|
|
|
CheckKotlincFlags(ctx, kotlincFlags)
|
|
|
|
|
2020-12-03 12:21:14 +01:00
|
|
|
// Dogfood the JVM_IR backend.
|
|
|
|
kotlincFlags = append(kotlincFlags, "-Xuse-ir")
|
|
|
|
|
2017-08-15 22:34:18 +02:00
|
|
|
// If there are kotlin files, compile them first but pass all the kotlin and java files
|
|
|
|
// kotlinc will use the java files to resolve types referenced by the kotlin files, but
|
|
|
|
// won't emit any classes for them.
|
2018-08-21 17:10:29 +02:00
|
|
|
kotlincFlags = append(kotlincFlags, "-no-stdlib")
|
2017-08-15 22:34:18 +02:00
|
|
|
if ctx.Device() {
|
2018-08-21 17:10:29 +02:00
|
|
|
kotlincFlags = append(kotlincFlags, "-no-jdk")
|
|
|
|
}
|
|
|
|
if len(kotlincFlags) > 0 {
|
|
|
|
// optimization.
|
|
|
|
ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " "))
|
|
|
|
flags.kotlincFlags += "$kotlincFlags"
|
2017-08-15 22:34:18 +02:00
|
|
|
}
|
|
|
|
|
2018-02-13 15:32:54 +01:00
|
|
|
var kotlinSrcFiles android.Paths
|
|
|
|
kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
|
|
|
|
kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
|
|
|
|
|
2019-09-24 09:41:30 +02:00
|
|
|
// Collect .kt files for AIDEGen
|
|
|
|
j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.FilterByExt(".kt").Strings()...)
|
2020-06-26 02:13:36 +02:00
|
|
|
j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, kotlinCommonSrcFiles.Strings()...)
|
2019-09-24 09:41:30 +02:00
|
|
|
|
2019-01-18 00:42:52 +01:00
|
|
|
flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
|
|
|
|
flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)
|
|
|
|
|
|
|
|
flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...)
|
|
|
|
flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...)
|
|
|
|
|
|
|
|
if len(flags.processorPath) > 0 {
|
|
|
|
// Use kapt for annotation processing
|
|
|
|
kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar")
|
2020-06-19 00:46:32 +02:00
|
|
|
kaptResJar := android.PathForModuleOut(ctx, "kapt", "kapt-res.jar")
|
2020-06-26 02:13:36 +02:00
|
|
|
kotlinKapt(ctx, kaptSrcJar, kaptResJar, kotlinSrcFiles, kotlinCommonSrcFiles, srcJars, flags)
|
2019-01-18 00:42:52 +01:00
|
|
|
srcJars = append(srcJars, kaptSrcJar)
|
2020-06-19 00:46:32 +02:00
|
|
|
kotlinJars = append(kotlinJars, kaptResJar)
|
2019-01-18 00:42:52 +01:00
|
|
|
// Disable annotation processing in javac, it's already been handled by kapt
|
|
|
|
flags.processorPath = nil
|
2020-04-22 20:44:34 +02:00
|
|
|
flags.processors = nil
|
2019-01-18 00:42:52 +01:00
|
|
|
}
|
2017-08-15 22:34:18 +02:00
|
|
|
|
2017-10-18 23:44:18 +02:00
|
|
|
kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
|
2020-06-26 02:13:36 +02:00
|
|
|
kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, kotlinCommonSrcFiles, srcJars, flags)
|
2017-08-15 22:34:18 +02:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make javac rule depend on the kotlinc rule
|
|
|
|
flags.classpath = append(flags.classpath, kotlinJar)
|
2018-03-08 14:21:55 +01:00
|
|
|
|
2018-08-27 21:37:09 +02:00
|
|
|
kotlinJars = append(kotlinJars, kotlinJar)
|
2020-06-19 00:52:01 +02:00
|
|
|
// Jar kotlin classes into the final jar after javac
|
|
|
|
if BoolDefault(j.properties.Static_kotlin_stdlib, true) {
|
|
|
|
kotlinJars = append(kotlinJars, deps.kotlinStdlib...)
|
|
|
|
}
|
2017-08-15 22:34:18 +02:00
|
|
|
}
|
|
|
|
|
2018-08-27 21:37:09 +02:00
|
|
|
jars := append(android.Paths(nil), kotlinJars...)
|
|
|
|
|
2017-11-23 01:20:45 +01:00
|
|
|
// Store the list of .java files that was passed to javac
|
|
|
|
j.compiledJavaSrcs = uniqueSrcFiles
|
|
|
|
j.compiledSrcJars = srcJars
|
|
|
|
|
2020-12-21 18:11:10 +01:00
|
|
|
enableSharding := false
|
2020-02-21 17:16:41 +01:00
|
|
|
var headerJarFileWithoutJarjar android.Path
|
2019-01-22 06:37:16 +01:00
|
|
|
if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine {
|
2017-11-02 21:28:15 +01:00
|
|
|
if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
|
2020-12-21 18:11:10 +01:00
|
|
|
enableSharding = true
|
2019-01-16 23:34:08 +01:00
|
|
|
// Formerly, there was a check here that prevented annotation processors
|
|
|
|
// from being used when sharding was enabled, as some annotation processors
|
|
|
|
// do not function correctly in sharded environments. It was removed to
|
|
|
|
// allow for the use of annotation processors that do function correctly
|
|
|
|
// with sharding enabled. See: b/77284273.
|
2017-11-02 21:28:15 +01:00
|
|
|
}
|
2020-02-21 17:16:41 +01:00
|
|
|
headerJarFileWithoutJarjar, j.headerJarFile =
|
|
|
|
j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars)
|
2018-03-26 23:42:44 +02:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
2017-10-19 22:06:22 +02:00
|
|
|
}
|
|
|
|
}
|
2017-10-25 02:46:00 +02:00
|
|
|
if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
|
2017-09-28 02:39:56 +02:00
|
|
|
var extraJarDeps android.Paths
|
2018-06-20 07:47:35 +02:00
|
|
|
if ctx.Config().RunErrorProne() {
|
2017-08-14 23:16:06 +02:00
|
|
|
// If error-prone is enabled, add an additional rule to compile the java files into
|
|
|
|
// a separate set of classes (so that they don't overwrite the normal ones and require
|
2017-09-28 02:39:56 +02:00
|
|
|
// a rebuild when error-prone is turned off).
|
2017-08-14 23:16:06 +02:00
|
|
|
// TODO(ccross): Once we always compile with javac9 we may be able to conditionally
|
|
|
|
// enable error-prone without affecting the output class files.
|
2017-10-18 23:44:18 +02:00
|
|
|
errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
|
2017-11-02 21:28:15 +01:00
|
|
|
RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
|
2017-08-14 23:16:06 +02:00
|
|
|
extraJarDeps = append(extraJarDeps, errorprone)
|
|
|
|
}
|
|
|
|
|
2020-12-21 18:11:10 +01:00
|
|
|
if enableSharding {
|
2020-02-21 17:16:41 +01:00
|
|
|
flags.classpath = append(flags.classpath, headerJarFileWithoutJarjar)
|
2017-11-02 21:28:15 +01:00
|
|
|
shardSize := int(*(j.properties.Javac_shard_size))
|
|
|
|
var shardSrcs []android.Paths
|
|
|
|
if len(uniqueSrcFiles) > 0 {
|
2019-09-23 23:33:09 +02:00
|
|
|
shardSrcs = android.ShardPaths(uniqueSrcFiles, shardSize)
|
2017-11-02 21:28:15 +01:00
|
|
|
for idx, shardSrc := range shardSrcs {
|
2019-09-06 01:44:18 +02:00
|
|
|
classes := j.compileJavaClasses(ctx, jarName, idx, shardSrc,
|
|
|
|
nil, flags, extraJarDeps)
|
2017-11-02 21:28:15 +01:00
|
|
|
jars = append(jars, classes)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(srcJars) > 0 {
|
2019-09-06 01:44:18 +02:00
|
|
|
classes := j.compileJavaClasses(ctx, jarName, len(shardSrcs),
|
|
|
|
nil, srcJars, flags, extraJarDeps)
|
2017-11-02 21:28:15 +01:00
|
|
|
jars = append(jars, classes)
|
|
|
|
}
|
|
|
|
} else {
|
2019-09-06 01:44:18 +02:00
|
|
|
classes := j.compileJavaClasses(ctx, jarName, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
|
2017-11-02 21:28:15 +01:00
|
|
|
jars = append(jars, classes)
|
|
|
|
}
|
2017-09-28 02:39:56 +02:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2019-05-04 00:28:19 +02:00
|
|
|
j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles
|
|
|
|
|
|
|
|
var includeSrcJar android.WritablePath
|
|
|
|
if Bool(j.properties.Include_srcs) {
|
|
|
|
includeSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+".srcjar")
|
|
|
|
TransformResourcesToJar(ctx, includeSrcJar, j.srcJarArgs, j.srcJarDeps)
|
|
|
|
}
|
|
|
|
|
2018-09-13 20:26:19 +02:00
|
|
|
dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
|
|
|
|
j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
|
2017-09-28 02:42:05 +02:00
|
|
|
fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
|
2019-05-06 23:04:11 +02:00
|
|
|
extraArgs, extraDeps := resourcePathsToJarArgs(j.extraResources), j.extraResources
|
2017-09-28 02:42:05 +02:00
|
|
|
|
|
|
|
var resArgs []string
|
|
|
|
var resDeps android.Paths
|
|
|
|
|
|
|
|
resArgs = append(resArgs, dirArgs...)
|
|
|
|
resDeps = append(resDeps, dirDeps...)
|
|
|
|
|
|
|
|
resArgs = append(resArgs, fileArgs...)
|
|
|
|
resDeps = append(resDeps, fileDeps...)
|
|
|
|
|
2019-05-06 23:04:11 +02:00
|
|
|
resArgs = append(resArgs, extraArgs...)
|
|
|
|
resDeps = append(resDeps, extraDeps...)
|
|
|
|
|
2017-09-28 02:41:35 +02:00
|
|
|
if len(resArgs) > 0 {
|
2017-10-18 23:44:18 +02:00
|
|
|
resourceJar := android.PathForModuleOut(ctx, "res", jarName)
|
2017-10-17 02:09:48 +02:00
|
|
|
TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
|
2018-08-16 05:40:52 +02:00
|
|
|
j.resourceJar = resourceJar
|
2017-08-30 23:24:55 +02:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2018-08-16 05:40:52 +02:00
|
|
|
}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2019-05-04 00:28:19 +02:00
|
|
|
var resourceJars android.Paths
|
|
|
|
if j.resourceJar != nil {
|
|
|
|
resourceJars = append(resourceJars, j.resourceJar)
|
|
|
|
}
|
|
|
|
if Bool(j.properties.Include_srcs) {
|
|
|
|
resourceJars = append(resourceJars, includeSrcJar)
|
|
|
|
}
|
|
|
|
resourceJars = append(resourceJars, deps.staticResourceJars...)
|
2018-08-16 05:40:52 +02:00
|
|
|
|
2019-05-04 00:28:19 +02:00
|
|
|
if len(resourceJars) > 1 {
|
2018-08-16 05:40:52 +02:00
|
|
|
combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
|
2019-05-04 00:28:19 +02:00
|
|
|
TransformJarsToJar(ctx, combinedJar, "for resources", resourceJars, android.OptionalPath{},
|
2018-08-16 05:40:52 +02:00
|
|
|
false, nil, nil)
|
|
|
|
j.resourceJar = combinedJar
|
2019-05-04 00:28:19 +02:00
|
|
|
} else if len(resourceJars) == 1 {
|
|
|
|
j.resourceJar = resourceJars[0]
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
2015-04-04 01:54:17 +02:00
|
|
|
|
2019-05-13 18:23:20 +02:00
|
|
|
if len(deps.staticJars) > 0 {
|
|
|
|
jars = append(jars, deps.staticJars...)
|
|
|
|
}
|
2017-08-30 23:24:55 +02:00
|
|
|
|
2018-10-18 00:10:48 +02:00
|
|
|
manifest := j.overrideManifest
|
|
|
|
if !manifest.Valid() && j.properties.Manifest != nil {
|
2019-03-06 07:25:09 +01:00
|
|
|
manifest = android.OptionalPathForPath(android.PathForModuleSrc(ctx, *j.properties.Manifest))
|
2017-12-12 01:29:02 +01:00
|
|
|
}
|
2017-09-13 07:50:46 +02:00
|
|
|
|
2019-03-06 07:25:09 +01:00
|
|
|
services := android.PathsForModuleSrc(ctx, j.properties.Services)
|
2019-02-21 22:27:37 +01:00
|
|
|
if len(services) > 0 {
|
|
|
|
servicesJar := android.PathForModuleOut(ctx, "services", jarName)
|
|
|
|
var zipargs []string
|
|
|
|
for _, file := range services {
|
|
|
|
serviceFile := file.String()
|
|
|
|
zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile)
|
|
|
|
}
|
2020-05-20 20:27:16 +02:00
|
|
|
rule := zip
|
|
|
|
args := map[string]string{
|
|
|
|
"jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "),
|
|
|
|
}
|
2020-09-03 07:29:49 +02:00
|
|
|
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_ZIP") {
|
2020-05-20 20:27:16 +02:00
|
|
|
rule = zipRE
|
|
|
|
args["implicits"] = strings.Join(services.Strings(), ",")
|
|
|
|
}
|
2019-02-21 22:27:37 +01:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2020-05-20 20:27:16 +02:00
|
|
|
Rule: rule,
|
2019-02-21 22:27:37 +01:00
|
|
|
Output: servicesJar,
|
|
|
|
Implicits: services,
|
2020-05-20 20:27:16 +02:00
|
|
|
Args: args,
|
2019-02-21 22:27:37 +01:00
|
|
|
})
|
|
|
|
jars = append(jars, servicesJar)
|
|
|
|
}
|
|
|
|
|
2017-08-30 23:24:55 +02:00
|
|
|
// Combine the classes built from sources, any manifests, and any static libraries into
|
2017-10-19 22:06:22 +02:00
|
|
|
// classes.jar. If there is only one input jar this step will be skipped.
|
2021-02-02 14:38:13 +01:00
|
|
|
var outputFile android.OutputPath
|
2017-10-17 02:09:48 +02:00
|
|
|
|
|
|
|
if len(jars) == 1 && !manifest.Valid() {
|
2021-02-02 14:38:13 +01:00
|
|
|
// Optimization: skip the combine step as there is nothing to do
|
|
|
|
// TODO(ccross): this leaves any module-info.class files, but those should only come from
|
|
|
|
// prebuilt dependencies until we support modules in the platform build, so there shouldn't be
|
|
|
|
// any if len(jars) == 1.
|
|
|
|
|
|
|
|
// Transform the single path to the jar into an OutputPath as that is required by the following
|
|
|
|
// code.
|
2018-08-15 20:19:12 +02:00
|
|
|
if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
|
2021-02-02 14:38:13 +01:00
|
|
|
// The path contains an embedded OutputPath so reuse that.
|
|
|
|
outputFile = moduleOutPath.OutputPath
|
|
|
|
} else if outputPath, ok := jars[0].(android.OutputPath); ok {
|
|
|
|
// The path is an OutputPath so reuse it directly.
|
|
|
|
outputFile = outputPath
|
2018-08-15 20:19:12 +02:00
|
|
|
} else {
|
2021-02-02 14:38:13 +01:00
|
|
|
// The file is not in the out directory so create an OutputPath into which it can be copied
|
|
|
|
// and which the following code can use to refer to it.
|
2018-08-15 20:19:12 +02:00
|
|
|
combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Cp,
|
|
|
|
Input: jars[0],
|
|
|
|
Output: combinedJar,
|
|
|
|
})
|
2021-02-02 14:38:13 +01:00
|
|
|
outputFile = combinedJar.OutputPath
|
2018-08-15 20:19:12 +02:00
|
|
|
}
|
2017-10-17 02:09:48 +02:00
|
|
|
} else {
|
2017-10-18 23:44:18 +02:00
|
|
|
combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
|
2018-07-12 21:28:41 +02:00
|
|
|
TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
|
2018-08-28 00:42:25 +02:00
|
|
|
false, nil, nil)
|
2021-02-02 14:38:13 +01:00
|
|
|
outputFile = combinedJar.OutputPath
|
2017-10-17 02:09:48 +02:00
|
|
|
}
|
2017-08-30 23:24:55 +02:00
|
|
|
|
2018-08-16 05:40:52 +02:00
|
|
|
// jarjar implementation jar if necessary
|
2019-01-18 20:51:25 +01:00
|
|
|
if j.expandJarjarRules != nil {
|
2017-09-28 03:03:17 +02:00
|
|
|
// Transform classes.jar into classes-jarjar.jar
|
2021-02-02 14:38:13 +01:00
|
|
|
jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName).OutputPath
|
2019-01-18 20:51:25 +01:00
|
|
|
TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
|
2017-10-17 02:09:48 +02:00
|
|
|
outputFile = jarjarFile
|
2018-08-16 05:40:52 +02:00
|
|
|
|
|
|
|
// jarjar resource jar if necessary
|
|
|
|
if j.resourceJar != nil {
|
|
|
|
resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
|
2019-01-18 20:51:25 +01:00
|
|
|
TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
|
2018-08-16 05:40:52 +02:00
|
|
|
j.resourceJar = resourceJarJarFile
|
|
|
|
}
|
|
|
|
|
2015-04-04 01:54:17 +02:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2019-04-02 11:29:55 +02:00
|
|
|
|
|
|
|
// Check package restrictions if necessary.
|
|
|
|
if len(j.properties.Permitted_packages) > 0 {
|
|
|
|
// Check packages and copy to package-checked file.
|
|
|
|
pkgckFile := android.PathForModuleOut(ctx, "package-check.stamp")
|
|
|
|
CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages)
|
|
|
|
j.additionalCheckedModules = append(j.additionalCheckedModules, pkgckFile)
|
|
|
|
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
j.implementationJarFile = outputFile
|
|
|
|
if j.headerJarFile == nil {
|
|
|
|
j.headerJarFile = j.implementationJarFile
|
|
|
|
}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2020-05-29 18:01:19 +02:00
|
|
|
if j.shouldInstrumentInApex(ctx) {
|
2020-02-18 13:50:44 +01:00
|
|
|
j.properties.Instrument = true
|
|
|
|
}
|
|
|
|
|
2018-01-04 00:06:47 +01:00
|
|
|
if j.shouldInstrument(ctx) {
|
2017-11-22 22:49:43 +01:00
|
|
|
outputFile = j.instrument(ctx, flags, outputFile, jarName)
|
|
|
|
}
|
|
|
|
|
2018-08-16 05:40:52 +02:00
|
|
|
// merge implementation jar with resources if necessary
|
|
|
|
implementationAndResourcesJar := outputFile
|
|
|
|
if j.resourceJar != nil {
|
2019-04-29 19:22:44 +02:00
|
|
|
jars := android.Paths{j.resourceJar, implementationAndResourcesJar}
|
2021-02-02 14:38:13 +01:00
|
|
|
combinedJar := android.PathForModuleOut(ctx, "withres", jarName).OutputPath
|
2019-04-29 19:22:44 +02:00
|
|
|
TransformJarsToJar(ctx, combinedJar, "for resources", jars, manifest,
|
2018-08-16 05:40:52 +02:00
|
|
|
false, nil, nil)
|
|
|
|
implementationAndResourcesJar = combinedJar
|
|
|
|
}
|
|
|
|
|
|
|
|
j.implementationAndResourcesJar = implementationAndResourcesJar
|
|
|
|
|
2020-02-11 01:16:01 +01:00
|
|
|
// Enable dex compilation for the APEX variants, unless it is disabled explicitly
|
2020-09-16 03:30:11 +02:00
|
|
|
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
|
|
|
|
if j.DirectlyInAnyApex() && !apexInfo.IsForPlatform() {
|
2020-07-10 00:16:41 +02:00
|
|
|
if j.dexProperties.Compile_dex == nil {
|
|
|
|
j.dexProperties.Compile_dex = proptools.BoolPtr(true)
|
2020-02-11 01:16:01 +01:00
|
|
|
}
|
|
|
|
if j.deviceProperties.Hostdex == nil {
|
|
|
|
j.deviceProperties.Hostdex = proptools.BoolPtr(true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-26 23:54:36 +01:00
|
|
|
if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.dexProperties.Compile_dex)) {
|
|
|
|
if j.hasCode(ctx) {
|
|
|
|
if j.shouldInstrumentStatic(ctx) {
|
|
|
|
j.dexer.extraProguardFlagFiles = append(j.dexer.extraProguardFlagFiles,
|
|
|
|
android.PathForSource(ctx, "build/make/core/proguard.jacoco.flags"))
|
|
|
|
}
|
|
|
|
// Dex compilation
|
|
|
|
var dexOutputFile android.OutputPath
|
|
|
|
dexOutputFile = j.dexer.compileDex(ctx, flags, j.minSdkVersion(), outputFile, jarName)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2018-08-16 05:40:52 +02:00
|
|
|
|
2021-02-26 23:54:36 +01:00
|
|
|
// Hidden API CSV generation and dex encoding
|
|
|
|
dexOutputFile = j.hiddenAPIExtractAndEncode(ctx, dexOutputFile, j.implementationJarFile,
|
|
|
|
proptools.Bool(j.dexProperties.Uncompress_dex))
|
2019-01-17 00:15:52 +01:00
|
|
|
|
2021-02-26 23:54:36 +01:00
|
|
|
// merge dex jar with resources if necessary
|
|
|
|
if j.resourceJar != nil {
|
|
|
|
jars := android.Paths{dexOutputFile, j.resourceJar}
|
|
|
|
combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName).OutputPath
|
|
|
|
TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
|
|
|
|
false, nil, nil)
|
|
|
|
if *j.dexProperties.Uncompress_dex {
|
|
|
|
combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName).OutputPath
|
|
|
|
TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
|
|
|
|
dexOutputFile = combinedAlignedJar
|
|
|
|
} else {
|
|
|
|
dexOutputFile = combinedJar
|
|
|
|
}
|
2019-01-23 16:57:21 +01:00
|
|
|
}
|
2018-08-16 05:40:52 +02:00
|
|
|
|
2021-02-26 23:54:36 +01:00
|
|
|
j.dexJarFile = dexOutputFile
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2021-02-26 23:54:36 +01:00
|
|
|
// Dexpreopting
|
|
|
|
j.dexpreopt(ctx, dexOutputFile)
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2021-02-26 23:54:36 +01:00
|
|
|
outputFile = dexOutputFile
|
|
|
|
} else {
|
|
|
|
// There is no code to compile into a dex jar, make sure the resources are propagated
|
|
|
|
// to the APK if this is an app.
|
|
|
|
outputFile = implementationAndResourcesJar
|
|
|
|
j.dexJarFile = j.resourceJar
|
|
|
|
}
|
2018-11-12 19:13:39 +01:00
|
|
|
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2018-08-16 05:40:52 +02:00
|
|
|
} else {
|
|
|
|
outputFile = implementationAndResourcesJar
|
2017-10-19 22:06:22 +02:00
|
|
|
}
|
2018-08-16 05:40:52 +02:00
|
|
|
|
2020-06-03 05:09:13 +02:00
|
|
|
if ctx.Device() {
|
|
|
|
lintSDKVersionString := func(sdkSpec sdkSpec) string {
|
|
|
|
if v := sdkSpec.version; v.isNumbered() {
|
|
|
|
return v.String()
|
|
|
|
} else {
|
2020-07-24 02:32:15 +02:00
|
|
|
return ctx.Config().DefaultAppTargetSdk(ctx).String()
|
2020-06-03 05:09:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
j.linter.name = ctx.ModuleName()
|
|
|
|
j.linter.srcs = srcFiles
|
|
|
|
j.linter.srcJars = srcJars
|
|
|
|
j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...)
|
|
|
|
j.linter.classes = j.implementationJarFile
|
|
|
|
j.linter.minSdkVersion = lintSDKVersionString(j.minSdkVersion())
|
|
|
|
j.linter.targetSdkVersion = lintSDKVersionString(j.targetSdkVersion())
|
|
|
|
j.linter.compileSdkVersion = lintSDKVersionString(j.sdkVersion())
|
|
|
|
j.linter.javaLanguageLevel = flags.javaVersion.String()
|
|
|
|
j.linter.kotlinLanguageLevel = "1.3"
|
2020-09-16 03:30:11 +02:00
|
|
|
if !apexInfo.IsForPlatform() && ctx.Config().UnbundledBuildApps() {
|
2020-07-22 05:31:17 +02:00
|
|
|
j.linter.buildModuleReportZip = true
|
|
|
|
}
|
2020-06-03 05:09:13 +02:00
|
|
|
j.linter.lint(ctx)
|
|
|
|
}
|
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
ctx.CheckbuildFile(outputFile)
|
2018-08-15 20:19:12 +02:00
|
|
|
|
2021-02-01 22:59:03 +01:00
|
|
|
ctx.SetProvider(JavaInfoProvider, JavaInfo{
|
|
|
|
HeaderJars: android.PathsIfNonNil(j.headerJarFile),
|
|
|
|
ImplementationAndResourcesJars: android.PathsIfNonNil(j.implementationAndResourcesJar),
|
|
|
|
ImplementationJars: android.PathsIfNonNil(j.implementationJarFile),
|
|
|
|
ResourceJars: android.PathsIfNonNil(j.resourceJar),
|
|
|
|
AidlIncludeDirs: j.exportAidlIncludeDirs,
|
|
|
|
SrcJarArgs: j.srcJarArgs,
|
|
|
|
SrcJarDeps: j.srcJarDeps,
|
|
|
|
ExportedPlugins: j.exportedPluginJars,
|
|
|
|
ExportedPluginClasses: j.exportedPluginClasses,
|
|
|
|
ExportedPluginDisableTurbine: j.exportedDisableTurbine,
|
|
|
|
JacocoReportClassesFile: j.jacocoReportClassesFile,
|
|
|
|
})
|
|
|
|
|
2018-08-15 20:19:12 +02:00
|
|
|
// Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
|
|
|
|
j.outputFile = outputFile.WithoutRel()
|
2017-10-19 22:06:22 +02:00
|
|
|
}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2019-09-06 01:44:18 +02:00
|
|
|
func (j *Module) compileJavaClasses(ctx android.ModuleContext, jarName string, idx int,
|
|
|
|
srcFiles, srcJars android.Paths, flags javaBuilderFlags, extraJarDeps android.Paths) android.WritablePath {
|
|
|
|
|
|
|
|
kzipName := pathtools.ReplaceExtension(jarName, "kzip")
|
|
|
|
if idx >= 0 {
|
|
|
|
kzipName = strings.TrimSuffix(jarName, filepath.Ext(jarName)) + strconv.Itoa(idx) + ".kzip"
|
|
|
|
jarName += strconv.Itoa(idx)
|
|
|
|
}
|
|
|
|
|
2021-02-02 14:38:13 +01:00
|
|
|
classes := android.PathForModuleOut(ctx, "javac", jarName).OutputPath
|
2019-09-06 01:44:18 +02:00
|
|
|
TransformJavaToClasses(ctx, classes, idx, srcFiles, srcJars, flags, extraJarDeps)
|
|
|
|
|
|
|
|
if ctx.Config().EmitXrefRules() {
|
|
|
|
extractionFile := android.PathForModuleOut(ctx, kzipName)
|
|
|
|
emitXrefRule(ctx, extractionFile, idx, srcFiles, srcJars, flags, extraJarDeps)
|
|
|
|
j.kytheFiles = append(j.kytheFiles, extractionFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
return classes
|
|
|
|
}
|
|
|
|
|
2018-08-21 17:10:29 +02:00
|
|
|
// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user,
|
|
|
|
// since some of these flags may be used internally.
|
|
|
|
func CheckKotlincFlags(ctx android.ModuleContext, flags []string) {
|
|
|
|
for _, flag := range flags {
|
|
|
|
flag = strings.TrimSpace(flag)
|
|
|
|
|
|
|
|
if !strings.HasPrefix(flag, "-") {
|
|
|
|
ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag)
|
|
|
|
} else if strings.HasPrefix(flag, "-Xintellij-plugin-root") {
|
|
|
|
ctx.PropertyErrorf("kotlincflags",
|
|
|
|
"Bad flag: `%s`, only use internal compiler for consistency.", flag)
|
|
|
|
} else if inList(flag, config.KotlincIllegalFlags) {
|
|
|
|
ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag)
|
|
|
|
} else if flag == "-include-runtime" {
|
|
|
|
ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag)
|
|
|
|
} else {
|
|
|
|
args := strings.Split(flag, " ")
|
|
|
|
if args[0] == "-kotlin-home" {
|
|
|
|
ctx.PropertyErrorf("kotlincflags",
|
|
|
|
"Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-25 02:46:00 +02:00
|
|
|
func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
|
2020-02-21 17:16:41 +01:00
|
|
|
deps deps, flags javaBuilderFlags, jarName string,
|
|
|
|
extraJars android.Paths) (headerJar, jarjarHeaderJar android.Path) {
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
var jars android.Paths
|
2017-10-25 02:46:00 +02:00
|
|
|
if len(srcFiles) > 0 || len(srcJars) > 0 {
|
2017-10-19 22:06:22 +02:00
|
|
|
// Compile java sources into turbine.jar.
|
|
|
|
turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
|
|
|
|
TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
|
|
|
|
if ctx.Failed() {
|
2020-02-21 17:16:41 +01:00
|
|
|
return nil, nil
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
2017-10-19 22:06:22 +02:00
|
|
|
jars = append(jars, turbineJar)
|
|
|
|
}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2018-08-27 21:37:09 +02:00
|
|
|
jars = append(jars, extraJars...)
|
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
// Combine any static header libraries into classes-header.jar. If there is only
|
|
|
|
// one input jar this step will be skipped.
|
|
|
|
jars = append(jars, deps.staticHeaderJars...)
|
|
|
|
|
2017-10-24 03:12:27 +02:00
|
|
|
// we cannot skip the combine step for now if there is only one jar
|
|
|
|
// since we have to strip META-INF/TRANSITIVE dir from turbine.jar
|
|
|
|
combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
|
2018-07-12 21:28:41 +02:00
|
|
|
TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
|
2019-05-08 23:30:12 +02:00
|
|
|
false, nil, []string{"META-INF/TRANSITIVE"})
|
2017-10-24 03:12:27 +02:00
|
|
|
headerJar = combinedJar
|
2020-02-21 17:16:41 +01:00
|
|
|
jarjarHeaderJar = combinedJar
|
2017-10-19 22:06:22 +02:00
|
|
|
|
2019-01-18 20:51:25 +01:00
|
|
|
if j.expandJarjarRules != nil {
|
2017-10-19 22:06:22 +02:00
|
|
|
// Transform classes.jar into classes-jarjar.jar
|
|
|
|
jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
|
2019-01-18 20:51:25 +01:00
|
|
|
TransformJarJar(ctx, jarjarFile, headerJar, j.expandJarjarRules)
|
2020-02-21 17:16:41 +01:00
|
|
|
jarjarHeaderJar = jarjarFile
|
2017-10-19 22:06:22 +02:00
|
|
|
if ctx.Failed() {
|
2020-02-21 17:16:41 +01:00
|
|
|
return nil, nil
|
2017-08-31 21:30:37 +02:00
|
|
|
}
|
2017-10-19 22:06:22 +02:00
|
|
|
}
|
2017-08-31 21:30:37 +02:00
|
|
|
|
2020-02-21 17:16:41 +01:00
|
|
|
return headerJar, jarjarHeaderJar
|
2017-10-19 22:06:22 +02:00
|
|
|
}
|
2017-08-31 21:30:37 +02:00
|
|
|
|
2017-11-22 22:49:43 +01:00
|
|
|
func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
|
2021-02-02 14:38:13 +01:00
|
|
|
classesJar android.Path, jarName string) android.OutputPath {
|
2017-11-22 22:49:43 +01:00
|
|
|
|
2017-12-19 22:57:50 +01:00
|
|
|
specs := j.jacocoModuleToZipCommand(ctx)
|
2017-11-22 22:49:43 +01:00
|
|
|
|
2018-01-04 00:59:46 +01:00
|
|
|
jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
|
2021-02-02 14:38:13 +01:00
|
|
|
instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName).OutputPath
|
2017-11-22 22:49:43 +01:00
|
|
|
|
|
|
|
jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
|
|
|
|
|
|
|
|
j.jacocoReportClassesFile = jacocoReportClassesFile
|
|
|
|
|
|
|
|
return instrumentedJar
|
|
|
|
}
|
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
func (j *Module) HeaderJars() android.Paths {
|
2018-12-25 07:35:23 +01:00
|
|
|
if j.headerJarFile == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2017-10-19 22:06:22 +02:00
|
|
|
return android.Paths{j.headerJarFile}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *Module) ImplementationJars() android.Paths {
|
2018-12-24 08:41:04 +01:00
|
|
|
if j.implementationJarFile == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2017-10-19 22:06:22 +02:00
|
|
|
return android.Paths{j.implementationJarFile}
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2020-06-04 16:08:17 +02:00
|
|
|
func (j *Module) DexJarBuildPath() android.Path {
|
2019-01-31 23:12:44 +01:00
|
|
|
return j.dexJarFile
|
|
|
|
}
|
|
|
|
|
2020-06-09 15:31:19 +02:00
|
|
|
func (j *Module) DexJarInstallPath() android.Path {
|
|
|
|
return j.installFile
|
|
|
|
}
|
|
|
|
|
2018-08-16 05:40:52 +02:00
|
|
|
func (j *Module) ImplementationAndResourcesJars() android.Paths {
|
2018-12-25 07:35:23 +01:00
|
|
|
if j.implementationAndResourcesJar == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2018-08-16 05:40:52 +02:00
|
|
|
return android.Paths{j.implementationAndResourcesJar}
|
|
|
|
}
|
|
|
|
|
2017-06-23 01:51:17 +02:00
|
|
|
func (j *Module) AidlIncludeDirs() android.Paths {
|
2018-12-25 07:35:23 +01:00
|
|
|
// exportAidlIncludeDirs is type android.Paths already
|
2015-04-08 22:03:43 +02:00
|
|
|
return j.exportAidlIncludeDirs
|
|
|
|
}
|
|
|
|
|
2020-10-08 13:53:58 +02:00
|
|
|
func (j *Module) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
|
|
|
|
return j.classLoaderContexts
|
2018-05-28 11:02:19 +02:00
|
|
|
}
|
|
|
|
|
2017-06-23 01:51:17 +02:00
|
|
|
var _ logtagsProducer = (*Module)(nil)
|
2015-04-11 02:45:20 +02:00
|
|
|
|
2017-06-23 01:51:17 +02:00
|
|
|
func (j *Module) logtags() android.Paths {
|
2015-04-11 02:45:20 +02:00
|
|
|
return j.logtagsSrcs
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:35:38 +02:00
|
|
|
// Collect information for opening IDE project files in java/jdeps.go.
|
|
|
|
func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
|
|
|
|
dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
|
|
|
|
dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
|
2019-05-10 09:48:50 +02:00
|
|
|
dpInfo.SrcJars = append(dpInfo.SrcJars, j.compiledSrcJars.Strings()...)
|
2018-08-16 00:35:38 +02:00
|
|
|
dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
|
2019-01-18 20:51:25 +01:00
|
|
|
if j.expandJarjarRules != nil {
|
|
|
|
dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
|
2018-08-16 00:35:38 +02:00
|
|
|
}
|
2020-05-21 04:11:59 +02:00
|
|
|
dpInfo.Paths = append(dpInfo.Paths, j.modulePaths...)
|
2018-08-16 00:35:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (j *Module) CompilerDeps() []string {
|
|
|
|
jdeps := []string{}
|
|
|
|
jdeps = append(jdeps, j.properties.Libs...)
|
|
|
|
jdeps = append(jdeps, j.properties.Static_libs...)
|
|
|
|
return jdeps
|
|
|
|
}
|
|
|
|
|
2019-05-31 00:51:14 +02:00
|
|
|
func (j *Module) hasCode(ctx android.ModuleContext) bool {
|
|
|
|
srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
|
|
|
|
return len(srcFiles) > 0 || len(ctx.GetDirectDepsWithTag(staticLibTag)) > 0
|
|
|
|
}
|
|
|
|
|
2020-12-15 14:29:02 +01:00
|
|
|
// Implements android.ApexModule
|
2019-10-15 08:20:07 +02:00
|
|
|
func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
|
2020-05-17 09:34:50 +02:00
|
|
|
return j.depIsInSameApex(ctx, dep)
|
2019-10-15 08:20:07 +02:00
|
|
|
}
|
|
|
|
|
2020-12-15 14:29:02 +01:00
|
|
|
// Implements android.ApexModule
|
2020-07-23 07:32:17 +02:00
|
|
|
func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
|
|
|
|
sdkVersion android.ApiLevel) error {
|
2020-04-15 04:03:39 +02:00
|
|
|
sdkSpec := j.minSdkVersion()
|
|
|
|
if !sdkSpec.specified() {
|
|
|
|
return fmt.Errorf("min_sdk_version is not specified")
|
|
|
|
}
|
|
|
|
if sdkSpec.kind == sdkCore {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ver, err := sdkSpec.effectiveVersion(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-07-23 07:32:17 +02:00
|
|
|
if ver.ApiLevel(ctx).GreaterThan(sdkVersion) {
|
2020-04-15 04:03:39 +02:00
|
|
|
return fmt.Errorf("newer SDK(%v)", ver)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-29 03:23:10 +01:00
|
|
|
func (j *Module) Stem() string {
|
|
|
|
return proptools.StringDefault(j.deviceProperties.Stem, j.Name())
|
|
|
|
}
|
|
|
|
|
2021-02-01 20:01:34 +01:00
|
|
|
// ConfigurationName returns the name of the module as used in build configuration.
|
|
|
|
//
|
|
|
|
// This is usually the same as BaseModuleName() except for the <x>.impl libraries created by
|
|
|
|
// java_sdk_library in which case this is the BaseModuleName() without the ".impl" suffix,
|
|
|
|
// i.e. just <x>.
|
2020-06-24 17:22:38 +02:00
|
|
|
func (j *Module) ConfigurationName() string {
|
|
|
|
return proptools.StringDefault(j.deviceProperties.ConfigurationName, j.BaseModuleName())
|
|
|
|
}
|
|
|
|
|
2020-01-08 05:35:43 +01:00
|
|
|
func (j *Module) JacocoReportClassesFile() android.Path {
|
|
|
|
return j.jacocoReportClassesFile
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:10:36 +01:00
|
|
|
func (j *Module) IsInstallable() bool {
|
|
|
|
return Bool(j.properties.Installable)
|
|
|
|
}
|
|
|
|
|
2015-03-31 02:20:39 +02:00
|
|
|
//
|
|
|
|
// Java libraries (.jar file)
|
|
|
|
//
|
|
|
|
|
2017-07-20 00:53:04 +02:00
|
|
|
type Library struct {
|
2017-06-23 01:51:17 +02:00
|
|
|
Module
|
2019-10-16 01:36:40 +02:00
|
|
|
|
|
|
|
InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths)
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2020-12-15 14:29:02 +01:00
|
|
|
var _ android.ApexModule = (*Library)(nil)
|
|
|
|
|
2020-05-29 12:24:51 +02: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 03:12:14 +01:00
|
|
|
func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool {
|
2020-01-24 13:19:45 +01:00
|
|
|
// Store uncompressed (and aligned) any dex files from jars in APEXes.
|
2020-09-16 03:30:11 +02:00
|
|
|
if apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo); !apexInfo.IsForPlatform() {
|
2020-01-24 13:19:45 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-02-12 14:12:16 +01:00
|
|
|
// Store uncompressed (and do not strip) dex files from boot class path jars.
|
|
|
|
if inList(ctx.ModuleName(), ctx.Config().BootJars()) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store uncompressed dex files that are preopted on /system.
|
2019-02-22 03:12:14 +01:00
|
|
|
if !dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, dexpreopter.installPath)) {
|
2018-12-21 16:54:16 +01:00
|
|
|
return true
|
|
|
|
}
|
2019-02-07 01:37:12 +01:00
|
|
|
if ctx.Config().UncompressPrivAppDex() &&
|
|
|
|
inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-12-21 21:59:54 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-07-20 00:53:04 +02:00
|
|
|
func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2021-02-01 20:01:34 +01: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())
|
|
|
|
|
2020-09-16 03:30:11 +02:00
|
|
|
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
|
|
|
|
if !apexInfo.IsForPlatform() {
|
|
|
|
j.hideApexVariantFromMake = true
|
|
|
|
}
|
|
|
|
|
2020-04-08 20:09:30 +02:00
|
|
|
j.checkSdkVersions(ctx)
|
2019-10-29 03:23:10 +01:00
|
|
|
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
|
2018-11-12 19:13:39 +01:00
|
|
|
j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
|
2020-07-10 00:16:41 +02:00
|
|
|
if j.dexProperties.Uncompress_dex == nil {
|
2020-05-20 23:20:28 +02:00
|
|
|
// If the value was not force-set by the user, use reasonable default based on the module.
|
2020-07-10 00:16:41 +02:00
|
|
|
j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter))
|
2020-05-20 23:20:28 +02:00
|
|
|
}
|
2020-07-10 00:16:41 +02:00
|
|
|
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
|
2020-10-08 13:53:58 +02:00
|
|
|
j.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap)
|
2019-05-13 18:23:20 +02:00
|
|
|
j.compile(ctx, nil)
|
2015-04-16 23:09:14 +02:00
|
|
|
|
2020-05-21 04:11:59 +02:00
|
|
|
// Collect the module directory for IDE info in java/jdeps.go.
|
|
|
|
j.modulePaths = append(j.modulePaths, ctx.ModuleDir())
|
|
|
|
|
2020-09-16 03:30:11 +02:00
|
|
|
exclusivelyForApex := !apexInfo.IsForPlatform()
|
2019-07-25 15:02:35 +02:00
|
|
|
if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex {
|
2019-10-16 01:36:40 +02:00
|
|
|
var extraInstallDeps android.Paths
|
|
|
|
if j.InstallMixin != nil {
|
|
|
|
extraInstallDeps = j.InstallMixin(ctx, j.outputFile)
|
|
|
|
}
|
2017-09-01 01:45:16 +02:00
|
|
|
j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
|
2020-05-28 16:46:55 +02:00
|
|
|
j.Stem()+".jar", j.outputFile, extraInstallDeps...)
|
2017-09-01 01:45:16 +02:00
|
|
|
}
|
2015-04-16 23:09:14 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 00:53:04 +02:00
|
|
|
func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2017-06-23 01:51:17 +02:00
|
|
|
j.deps(ctx)
|
|
|
|
}
|
|
|
|
|
2019-11-12 20:39:25 +01:00
|
|
|
const (
|
2019-12-03 19:06:47 +01:00
|
|
|
aidlIncludeDir = "aidl"
|
|
|
|
javaDir = "java"
|
|
|
|
jarFileSuffix = ".jar"
|
|
|
|
testConfigSuffix = "-AndroidTest.xml"
|
2019-11-12 20:39:25 +01:00
|
|
|
)
|
|
|
|
|
2019-12-05 12:25:53 +01:00
|
|
|
// path to the jar file of a java library. Relative to <sdk_root>/<api_dir>
|
2020-03-02 11:16:35 +01:00
|
|
|
func sdkSnapshotFilePathForJar(osPrefix, name string) string {
|
|
|
|
return sdkSnapshotFilePathForMember(osPrefix, name, jarFileSuffix)
|
2019-12-03 19:06:47 +01:00
|
|
|
}
|
|
|
|
|
2020-03-02 11:16:35 +01:00
|
|
|
func sdkSnapshotFilePathForMember(osPrefix, name string, suffix string) string {
|
|
|
|
return filepath.Join(javaDir, osPrefix, name+suffix)
|
2019-11-12 20:39:25 +01:00
|
|
|
}
|
|
|
|
|
2019-11-28 15:31:38 +01:00
|
|
|
type librarySdkMemberType struct {
|
2019-12-13 12:22:16 +01:00
|
|
|
android.SdkMemberTypeBase
|
2020-02-28 15:39:53 +01:00
|
|
|
|
|
|
|
// Function to retrieve the appropriate output jar (implementation or header) from
|
|
|
|
// the library.
|
2020-12-08 18:48:25 +01:00
|
|
|
jarToExportGetter func(ctx android.SdkMemberContext, j *Library) android.Path
|
|
|
|
|
|
|
|
// Function to compute the snapshot relative path to which the named library's
|
|
|
|
// jar should be copied.
|
|
|
|
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 15:31:38 +01:00
|
|
|
}
|
|
|
|
|
2020-12-08 18:48:25 +01:00
|
|
|
const (
|
|
|
|
onlyCopyJarToSnapshot = true
|
|
|
|
copyEverythingToSnapshot = false
|
|
|
|
)
|
|
|
|
|
2019-11-28 15:31:38 +01: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-19 17:11:18 +01:00
|
|
|
func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
|
|
|
|
return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_import")
|
2020-03-02 12:33:02 +01:00
|
|
|
}
|
2019-12-05 12:25:53 +01:00
|
|
|
|
2020-03-02 12:33:02 +01:00
|
|
|
func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
|
2020-03-17 22:04:24 +01:00
|
|
|
return &librarySdkMemberProperties{}
|
2020-03-02 12:33:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type librarySdkMemberProperties struct {
|
|
|
|
android.SdkMemberPropertiesBase
|
|
|
|
|
2020-05-06 11:23:19 +02:00
|
|
|
JarToExport android.Path `android:"arch_variant"`
|
2020-03-17 22:04:24 +01:00
|
|
|
AidlIncludeDirs android.Paths
|
2020-03-02 12:33:02 +01:00
|
|
|
}
|
|
|
|
|
2020-03-19 17:11:18 +01:00
|
|
|
func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
|
2019-11-28 15:31:38 +01:00
|
|
|
j := variant.(*Library)
|
|
|
|
|
2020-12-08 18:48:25 +01:00
|
|
|
p.JarToExport = ctx.MemberType().(*librarySdkMemberType).jarToExportGetter(ctx, j)
|
|
|
|
|
2020-03-17 22:04:24 +01:00
|
|
|
p.AidlIncludeDirs = j.AidlIncludeDirs()
|
2020-03-02 12:33:02 +01:00
|
|
|
}
|
|
|
|
|
2020-03-19 17:11:18 +01:00
|
|
|
func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
|
2020-03-17 22:04:24 +01:00
|
|
|
builder := ctx.SnapshotBuilder()
|
2020-03-19 17:11:18 +01:00
|
|
|
|
2020-12-08 18:48:25 +01:00
|
|
|
memberType := ctx.MemberType().(*librarySdkMemberType)
|
|
|
|
|
2020-03-17 22:04:24 +01:00
|
|
|
exportedJar := p.JarToExport
|
|
|
|
if exportedJar != nil {
|
2020-12-08 18:48:25 +01:00
|
|
|
// Delegate the creation of the snapshot relative path to the member type.
|
|
|
|
snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(p.OsPrefix(), ctx.Name())
|
|
|
|
|
|
|
|
// Copy the exported jar to the snapshot.
|
2020-03-02 12:33:02 +01:00
|
|
|
builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
|
2019-11-12 20:39:25 +01:00
|
|
|
|
2020-03-17 22:04:24 +01:00
|
|
|
propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
|
|
|
|
}
|
|
|
|
|
2020-12-08 18:48:25 +01:00
|
|
|
// Do not copy anything else to the snapshot.
|
|
|
|
if memberType.onlyCopyJarToSnapshot {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-03-17 22:04:24 +01:00
|
|
|
aidlIncludeDirs := p.AidlIncludeDirs
|
|
|
|
if len(aidlIncludeDirs) != 0 {
|
|
|
|
sdkModuleContext := ctx.SdkModuleContext()
|
|
|
|
for _, dir := range aidlIncludeDirs {
|
2020-03-02 12:33:02 +01:00
|
|
|
// TODO(jiyong): copy parcelable declarations only
|
|
|
|
aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil)
|
|
|
|
for _, file := range aidlFiles {
|
|
|
|
builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file))
|
|
|
|
}
|
2019-11-12 20:39:25 +01:00
|
|
|
}
|
|
|
|
|
2020-03-17 22:04:24 +01:00
|
|
|
// TODO(b/151933053) - add aidl include dirs property
|
2020-03-02 12:33:02 +01:00
|
|
|
}
|
2019-11-12 20:39:25 +01:00
|
|
|
}
|
|
|
|
|
2020-02-28 15:39:53 +01:00
|
|
|
var javaHeaderLibsSdkMemberType android.SdkMemberType = &librarySdkMemberType{
|
|
|
|
android.SdkMemberTypeBase{
|
|
|
|
PropertyName: "java_header_libs",
|
|
|
|
SupportsSdk: true,
|
2020-01-13 22:03:22 +01:00
|
|
|
},
|
2020-12-08 18:48:25 +01:00
|
|
|
func(_ android.SdkMemberContext, j *Library) android.Path {
|
2019-12-05 12:25:53 +01:00
|
|
|
headerJars := j.HeaderJars()
|
|
|
|
if len(headerJars) != 1 {
|
|
|
|
panic(fmt.Errorf("there must be only one header jar from %q", j.Name()))
|
|
|
|
}
|
|
|
|
|
|
|
|
return headerJars[0]
|
2020-02-28 15:39:53 +01:00
|
|
|
},
|
2020-12-08 18:48:25 +01:00
|
|
|
sdkSnapshotFilePathForJar,
|
|
|
|
copyEverythingToSnapshot,
|
2019-12-05 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
|
|
|
|
//
|
|
|
|
// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
|
|
|
|
// compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used
|
|
|
|
// as a `static_libs` dependency of another module.
|
|
|
|
//
|
|
|
|
// Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on
|
|
|
|
// a device.
|
|
|
|
//
|
|
|
|
// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
|
|
|
|
// compiled against the host bootclasspath.
|
2018-06-27 02:59:05 +02:00
|
|
|
func LibraryFactory() android.Module {
|
|
|
|
module := &Library{}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2020-06-16 01:09:53 +02:00
|
|
|
module.addHostAndDeviceProperties()
|
2017-06-24 00:06:31 +02:00
|
|
|
|
2020-05-15 11:20:31 +02:00
|
|
|
module.initModuleAndImport(&module.ModuleBase)
|
|
|
|
|
2019-07-25 15:02:35 +02: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 13:08:41 +02:00
|
|
|
android.InitSdkAwareModule(module)
|
2019-11-13 02:50:48 +01:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
2018-06-27 02:59:05 +02:00
|
|
|
return module
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_library_static is an obsolete alias for java_library.
|
|
|
|
func LibraryStaticFactory() android.Module {
|
|
|
|
return LibraryFactory()
|
|
|
|
}
|
|
|
|
|
|
|
|
// java_library_host builds and links sources into a `.jar` file for the host.
|
|
|
|
//
|
|
|
|
// A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were
|
|
|
|
// compiled against the host bootclasspath.
|
2017-07-20 00:53:04 +02:00
|
|
|
func LibraryHostFactory() android.Module {
|
|
|
|
module := &Library{}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2020-06-16 01:09:53 +02:00
|
|
|
module.addHostProperties()
|
2017-06-24 00:06:31 +02:00
|
|
|
|
2018-06-27 02:59:05 +02:00
|
|
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
|
2019-07-25 15:02:35 +02:00
|
|
|
android.InitApexModule(module)
|
2019-11-13 02:50:48 +01:00
|
|
|
InitJavaModule(module, android.HostSupported)
|
2017-06-24 00:06:31 +02:00
|
|
|
return module
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2018-04-10 03:40:24 +02:00
|
|
|
//
|
2018-08-15 01:42:33 +02:00
|
|
|
// Java Tests
|
2018-04-10 03:40:24 +02:00
|
|
|
//
|
|
|
|
|
2020-08-15 21:24:26 +02:00
|
|
|
// Test option struct.
|
|
|
|
type TestOptions struct {
|
|
|
|
// a list of extra test configuration files that should be installed with the module.
|
|
|
|
Extra_test_configs []string `android:"path,arch_variant"`
|
2020-11-13 23:33:46 +01:00
|
|
|
|
|
|
|
// If the test is a hostside(no device required) unittest that shall be run during presubmit check.
|
|
|
|
Unit_test *bool
|
2020-08-15 21:24:26 +02:00
|
|
|
}
|
|
|
|
|
2018-04-10 03:40:24 +02:00
|
|
|
type testProperties struct {
|
|
|
|
// list of compatibility suites (for example "cts", "vts") that the module should be
|
|
|
|
// installed into.
|
|
|
|
Test_suites []string `android:"arch_variant"`
|
2018-08-03 00:00:46 +02:00
|
|
|
|
|
|
|
// the name of the test configuration (for example "AndroidTest.xml") that should be
|
|
|
|
// installed with the module.
|
2019-03-05 07:35:41 +01:00
|
|
|
Test_config *string `android:"path,arch_variant"`
|
2018-08-11 01:06:24 +02:00
|
|
|
|
2018-09-19 11:21:28 +02:00
|
|
|
// the name of the test configuration template (for example "AndroidTestTemplate.xml") that
|
|
|
|
// should be installed with the module.
|
2019-03-05 07:35:41 +01:00
|
|
|
Test_config_template *string `android:"path,arch_variant"`
|
2018-09-19 11:21:28 +02:00
|
|
|
|
2018-08-11 01:06:24 +02:00
|
|
|
// list of files or filegroup modules that provide data that should be installed alongside
|
|
|
|
// the test
|
2021-02-15 22:52:39 +01:00
|
|
|
Data []string `android:"path"`
|
2019-09-26 20:41:36 +02:00
|
|
|
|
|
|
|
// Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
|
|
|
|
// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
|
|
|
|
// explicitly.
|
|
|
|
Auto_gen_config *bool
|
2020-04-30 08:57:06 +02:00
|
|
|
|
|
|
|
// Add parameterized mainline modules to auto generated test config. The options will be
|
|
|
|
// handled by TradeFed to do downloading and installing the specified modules on the device.
|
|
|
|
Test_mainline_modules []string
|
2020-08-15 21:24:26 +02:00
|
|
|
|
|
|
|
// Test options.
|
|
|
|
Test_options TestOptions
|
2018-04-10 03:40:24 +02:00
|
|
|
}
|
|
|
|
|
2020-06-13 01:38:45 +02:00
|
|
|
type hostTestProperties struct {
|
|
|
|
// list of native binary modules that should be installed alongside the test
|
|
|
|
Data_native_bins []string `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
|
2019-03-20 13:45:53 +01:00
|
|
|
type testHelperLibraryProperties struct {
|
|
|
|
// list of compatibility suites (for example "cts", "vts") that the module should be
|
|
|
|
// installed into.
|
|
|
|
Test_suites []string `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
|
2019-12-03 19:06:47 +01:00
|
|
|
type prebuiltTestProperties struct {
|
|
|
|
// list of compatibility suites (for example "cts", "vts") that the module should be
|
|
|
|
// installed into.
|
|
|
|
Test_suites []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// the name of the test configuration (for example "AndroidTest.xml") that should be
|
|
|
|
// installed with the module.
|
|
|
|
Test_config *string `android:"path,arch_variant"`
|
|
|
|
}
|
|
|
|
|
2018-04-10 03:40:24 +02:00
|
|
|
type Test struct {
|
|
|
|
Library
|
|
|
|
|
|
|
|
testProperties testProperties
|
2018-08-08 01:49:25 +02:00
|
|
|
|
2020-08-15 21:24:26 +02:00
|
|
|
testConfig android.Path
|
|
|
|
extraTestConfigs android.Paths
|
|
|
|
data android.Paths
|
2018-08-08 01:49:25 +02:00
|
|
|
}
|
|
|
|
|
2020-06-13 01:38:45 +02:00
|
|
|
type TestHost struct {
|
|
|
|
Test
|
|
|
|
|
|
|
|
testHostProperties hostTestProperties
|
|
|
|
}
|
|
|
|
|
2019-03-20 13:45:53 +01:00
|
|
|
type TestHelperLibrary struct {
|
|
|
|
Library
|
|
|
|
|
|
|
|
testHelperLibraryProperties testHelperLibraryProperties
|
|
|
|
}
|
|
|
|
|
2019-12-03 19:06:47 +01:00
|
|
|
type JavaTestImport struct {
|
|
|
|
Import
|
|
|
|
|
|
|
|
prebuiltTestProperties prebuiltTestProperties
|
|
|
|
|
|
|
|
testConfig android.Path
|
2020-08-06 00:40:41 +02:00
|
|
|
dexJarFile android.Path
|
2019-12-03 19:06:47 +01:00
|
|
|
}
|
|
|
|
|
2020-06-13 01:38:45 +02:00
|
|
|
func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
if len(j.testHostProperties.Data_native_bins) > 0 {
|
|
|
|
for _, target := range ctx.MultiTargets() {
|
|
|
|
ctx.AddVariationDependencies(target.Variations(), dataNativeBinsTag, j.testHostProperties.Data_native_bins...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
j.deps(ctx)
|
|
|
|
}
|
|
|
|
|
2018-08-08 01:49:25 +02:00
|
|
|
func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2019-09-26 20:41:36 +02:00
|
|
|
j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template,
|
2020-11-19 18:43:45 +01:00
|
|
|
j.testProperties.Test_suites, j.testProperties.Auto_gen_config, j.testProperties.Test_options.Unit_test)
|
2020-06-13 01:38:45 +02:00
|
|
|
|
2019-03-06 07:25:09 +01:00
|
|
|
j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data)
|
2018-08-08 01:49:25 +02:00
|
|
|
|
2020-08-15 21:24:26 +02:00
|
|
|
j.extraTestConfigs = android.PathsForModuleSrc(ctx, j.testProperties.Test_options.Extra_test_configs)
|
|
|
|
|
2020-06-13 01:38:45 +02:00
|
|
|
ctx.VisitDirectDepsWithTag(dataNativeBinsTag, func(dep android.Module) {
|
|
|
|
j.data = append(j.data, android.OutputFileForModule(ctx, dep, ""))
|
|
|
|
})
|
|
|
|
|
2018-08-08 01:49:25 +02:00
|
|
|
j.Library.GenerateAndroidBuildActions(ctx)
|
2018-04-10 03:40:24 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 13:45:53 +01:00
|
|
|
func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
j.Library.GenerateAndroidBuildActions(ctx)
|
|
|
|
}
|
|
|
|
|
2019-12-03 19:06:47 +01:00
|
|
|
func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.prebuiltTestProperties.Test_config, nil,
|
2020-11-19 18:43:45 +01:00
|
|
|
j.prebuiltTestProperties.Test_suites, nil, nil)
|
2019-12-03 19:06:47 +01: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-19 17:11:18 +01:00
|
|
|
func (mt *testSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
|
|
|
|
return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_test_import")
|
2020-03-02 12:33:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
|
|
|
|
return &testSdkMemberProperties{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type testSdkMemberProperties struct {
|
|
|
|
android.SdkMemberPropertiesBase
|
2019-12-03 19:06:47 +01:00
|
|
|
|
2020-03-17 22:04:24 +01:00
|
|
|
JarToExport android.Path
|
|
|
|
TestConfig android.Path
|
2020-03-02 12:33:02 +01:00
|
|
|
}
|
|
|
|
|
2020-03-19 17:11:18 +01:00
|
|
|
func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
|
2020-03-02 12:33:02 +01:00
|
|
|
test := variant.(*Test)
|
|
|
|
|
|
|
|
implementationJars := test.ImplementationJars()
|
2019-12-03 19:06:47 +01:00
|
|
|
if len(implementationJars) != 1 {
|
2020-03-02 12:33:02 +01:00
|
|
|
panic(fmt.Errorf("there must be only one implementation jar from %q", test.Name()))
|
2019-12-03 19:06:47 +01:00
|
|
|
}
|
|
|
|
|
2020-03-17 22:04:24 +01:00
|
|
|
p.JarToExport = implementationJars[0]
|
|
|
|
p.TestConfig = test.testConfig
|
2020-03-02 12:33:02 +01:00
|
|
|
}
|
|
|
|
|
2020-03-19 17:11:18 +01:00
|
|
|
func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
|
2020-03-17 22:04:24 +01:00
|
|
|
builder := ctx.SnapshotBuilder()
|
2019-12-03 19:06:47 +01:00
|
|
|
|
2020-03-17 22:04:24 +01:00
|
|
|
exportedJar := p.JarToExport
|
|
|
|
if exportedJar != nil {
|
|
|
|
snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name())
|
|
|
|
builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
|
2019-12-03 19:06:47 +01:00
|
|
|
|
2020-03-02 12:33:02 +01:00
|
|
|
propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
|
2020-03-17 22:04:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
testConfig := p.TestConfig
|
|
|
|
if testConfig != nil {
|
|
|
|
snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(p.OsPrefix(), ctx.Name(), testConfigSuffix)
|
|
|
|
builder.CopyToSnapshot(testConfig, snapshotRelativeTestConfigPath)
|
2020-03-02 12:33:02 +01:00
|
|
|
propertySet.AddProperty("test_config", snapshotRelativeTestConfigPath)
|
|
|
|
}
|
2019-12-03 19:06:47 +01:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
|
|
|
|
// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
|
|
|
|
//
|
|
|
|
// By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were
|
|
|
|
// compiled against the device bootclasspath.
|
|
|
|
//
|
|
|
|
// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
|
|
|
|
// compiled against the host bootclasspath.
|
2018-04-10 03:40:24 +02:00
|
|
|
func TestFactory() android.Module {
|
|
|
|
module := &Test{}
|
|
|
|
|
2020-06-16 01:09:53 +02:00
|
|
|
module.addHostAndDeviceProperties()
|
|
|
|
module.AddProperties(&module.testProperties)
|
2018-04-10 03:40:24 +02:00
|
|
|
|
2018-06-27 02:59:05 +02:00
|
|
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
2019-01-06 07:30:13 +01:00
|
|
|
module.Module.dexpreopter.isTest = true
|
2020-06-03 05:09:13 +02:00
|
|
|
module.Module.linter.test = true
|
2018-06-27 02:59:05 +02:00
|
|
|
|
2018-04-10 03:40:24 +02:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2019-03-20 13:45:53 +01:00
|
|
|
// java_test_helper_library creates a java library and makes sure that it is added to the appropriate test suite.
|
|
|
|
func TestHelperLibraryFactory() android.Module {
|
|
|
|
module := &TestHelperLibrary{}
|
|
|
|
|
2020-06-16 01:09:53 +02:00
|
|
|
module.addHostAndDeviceProperties()
|
|
|
|
module.AddProperties(&module.testHelperLibraryProperties)
|
2019-03-20 13:45:53 +01:00
|
|
|
|
2019-04-24 22:19:28 +02:00
|
|
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
module.Module.dexpreopter.isTest = true
|
2020-06-03 05:09:13 +02:00
|
|
|
module.Module.linter.test = true
|
2019-04-24 22:19:28 +02:00
|
|
|
|
2019-03-20 13:45:53 +01:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2019-12-03 19:06:47 +01:00
|
|
|
// java_test_import imports one or more `.jar` files into the build graph as if they were built by a java_test module
|
|
|
|
// and makes sure that it is added to the appropriate test suite.
|
|
|
|
//
|
|
|
|
// By default, a java_test_import has a single variant that expects a `.jar` file containing `.class` files that were
|
|
|
|
// compiled against an Android classpath.
|
|
|
|
//
|
|
|
|
// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
|
|
|
|
// for host modules.
|
|
|
|
func JavaTestImportFactory() android.Module {
|
|
|
|
module := &JavaTestImport{}
|
|
|
|
|
|
|
|
module.AddProperties(
|
|
|
|
&module.Import.properties,
|
|
|
|
&module.prebuiltTestProperties)
|
|
|
|
|
|
|
|
module.Import.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
|
|
|
|
android.InitPrebuiltModule(module, &module.properties.Jars)
|
|
|
|
android.InitApexModule(module)
|
|
|
|
android.InitSdkAwareModule(module)
|
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to
|
|
|
|
// allow running the test with `atest` or a `TEST_MAPPING` file.
|
|
|
|
//
|
|
|
|
// A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
|
|
|
|
// compiled against the host bootclasspath.
|
2018-04-10 03:40:24 +02:00
|
|
|
func TestHostFactory() android.Module {
|
2020-06-13 01:38:45 +02:00
|
|
|
module := &TestHost{}
|
2018-04-10 03:40:24 +02:00
|
|
|
|
2020-06-16 01:09:53 +02:00
|
|
|
module.addHostProperties()
|
|
|
|
module.AddProperties(&module.testProperties)
|
2020-06-13 01:38:45 +02:00
|
|
|
module.AddProperties(&module.testHostProperties)
|
2018-04-10 03:40:24 +02:00
|
|
|
|
2018-06-27 02:59:05 +02:00
|
|
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
|
2020-06-13 01:38:45 +02:00
|
|
|
InitJavaModuleMultiTargets(module, android.HostSupported)
|
2018-04-10 03:40:24 +02:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2015-03-31 02:20:39 +02:00
|
|
|
//
|
|
|
|
// Java Binaries (.jar file plus wrapper script)
|
|
|
|
//
|
|
|
|
|
2017-07-20 00:53:04 +02:00
|
|
|
type binaryProperties struct {
|
2015-05-11 22:39:40 +02:00
|
|
|
// installable script to execute the resulting jar
|
2019-03-05 07:35:41 +01:00
|
|
|
Wrapper *string `android:"path"`
|
2018-10-18 00:10:48 +02:00
|
|
|
|
|
|
|
// Name of the class containing main to be inserted into the manifest as Main-Class.
|
|
|
|
Main_class *string
|
2020-10-10 04:00:54 +02:00
|
|
|
|
|
|
|
// Names of modules containing JNI libraries that should be installed alongside the host
|
|
|
|
// variant of the binary.
|
|
|
|
Jni_libs []string
|
2015-05-11 22:39:40 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 00:53:04 +02:00
|
|
|
type Binary struct {
|
|
|
|
Library
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2017-07-20 00:53:04 +02:00
|
|
|
binaryProperties binaryProperties
|
2017-08-11 02:09:43 +02:00
|
|
|
|
2017-12-05 22:42:45 +01:00
|
|
|
isWrapperVariant bool
|
|
|
|
|
2017-12-09 04:12:36 +01:00
|
|
|
wrapperFile android.Path
|
2019-10-02 07:05:35 +02:00
|
|
|
binaryFile android.InstallPath
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2017-10-26 18:46:21 +02:00
|
|
|
func (j *Binary) HostToolPath() android.OptionalPath {
|
|
|
|
return android.OptionalPathForPath(j.binaryFile)
|
|
|
|
}
|
|
|
|
|
2017-07-20 00:53:04 +02:00
|
|
|
func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2017-12-05 22:42:45 +01:00
|
|
|
if ctx.Arch().ArchType == android.Common {
|
|
|
|
// Compile the jar
|
2018-10-18 00:10:48 +02:00
|
|
|
if j.binaryProperties.Main_class != nil {
|
|
|
|
if j.properties.Manifest != nil {
|
|
|
|
ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set")
|
|
|
|
}
|
|
|
|
manifestFile := android.PathForModuleOut(ctx, "manifest.txt")
|
|
|
|
GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class))
|
|
|
|
j.overrideManifest = android.OptionalPathForPath(manifestFile)
|
|
|
|
}
|
|
|
|
|
2017-12-05 22:42:45 +01:00
|
|
|
j.Library.GenerateAndroidBuildActions(ctx)
|
2017-11-03 22:53:31 +01:00
|
|
|
} else {
|
2017-12-05 22:42:45 +01:00
|
|
|
// Handle the binary wrapper
|
|
|
|
j.isWrapperVariant = true
|
|
|
|
|
2017-12-12 01:29:02 +01:00
|
|
|
if j.binaryProperties.Wrapper != nil {
|
2019-03-06 07:25:09 +01:00
|
|
|
j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper)
|
2017-12-05 22:42:45 +01:00
|
|
|
} else {
|
|
|
|
j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
|
|
|
|
}
|
|
|
|
|
2020-10-09 19:54:15 +02:00
|
|
|
// The host installation rules make the installed wrapper depend on all the dependencies
|
2020-10-10 04:00:54 +02:00
|
|
|
// of the wrapper variant, which will include the common variant's jar file and any JNI
|
|
|
|
// libraries. This is verified by TestBinary.
|
2017-12-05 22:42:45 +01:00
|
|
|
j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
|
2020-10-09 19:54:15 +02:00
|
|
|
ctx.ModuleName(), j.wrapperFile)
|
2017-11-03 22:53:31 +01:00
|
|
|
}
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 00:53:04 +02:00
|
|
|
func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2021-01-26 15:18:53 +01:00
|
|
|
if ctx.Arch().ArchType == android.Common || ctx.BazelConversionMode() {
|
2017-12-05 22:42:45 +01:00
|
|
|
j.deps(ctx)
|
2021-01-26 15:18:53 +01:00
|
|
|
}
|
|
|
|
if ctx.Arch().ArchType != android.Common || ctx.BazelConversionMode() {
|
2020-11-11 03:12:15 +01:00
|
|
|
// These dependencies ensure the host installation rules will install the jar file and
|
|
|
|
// the jni libraries when the wrapper is installed.
|
|
|
|
ctx.AddVariationDependencies(nil, jniInstallTag, j.binaryProperties.Jni_libs...)
|
|
|
|
ctx.AddVariationDependencies(
|
|
|
|
[]blueprint.Variation{{Mutator: "arch", Variation: android.CommonArch.String()}},
|
|
|
|
binaryInstallTag, ctx.ModuleName())
|
2017-12-05 22:42:45 +01:00
|
|
|
}
|
2017-06-23 01:51:17 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host
|
|
|
|
// as well.
|
|
|
|
//
|
|
|
|
// By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were
|
|
|
|
// compiled against the device bootclasspath.
|
|
|
|
//
|
|
|
|
// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
|
|
|
|
// compiled against the host bootclasspath.
|
2017-07-20 00:53:04 +02:00
|
|
|
func BinaryFactory() android.Module {
|
|
|
|
module := &Binary{}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2020-06-16 01:09:53 +02:00
|
|
|
module.addHostAndDeviceProperties()
|
|
|
|
module.AddProperties(&module.binaryProperties)
|
2017-06-24 00:06:31 +02:00
|
|
|
|
2018-06-27 02:59:05 +02:00
|
|
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
|
2017-12-05 22:42:45 +01:00
|
|
|
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
|
|
|
|
android.InitDefaultableModule(module)
|
2017-06-24 00:06:31 +02:00
|
|
|
return module
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_binary_host builds a `.jar` file and a shell script that executes it for the host.
|
|
|
|
//
|
|
|
|
// A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were
|
|
|
|
// compiled against the host bootclasspath.
|
2017-07-20 00:53:04 +02:00
|
|
|
func BinaryHostFactory() android.Module {
|
|
|
|
module := &Binary{}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2020-06-16 01:09:53 +02:00
|
|
|
module.addHostProperties()
|
|
|
|
module.AddProperties(&module.binaryProperties)
|
2017-06-24 00:06:31 +02:00
|
|
|
|
2018-06-27 02:59:05 +02:00
|
|
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
|
2017-12-05 22:42:45 +01:00
|
|
|
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
|
|
|
|
android.InitDefaultableModule(module)
|
2017-06-24 00:06:31 +02:00
|
|
|
return module
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Java prebuilts
|
|
|
|
//
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
type ImportProperties struct {
|
2020-03-02 11:16:35 +01:00
|
|
|
Jars []string `android:"path,arch_variant"`
|
2017-10-20 22:59:18 +02:00
|
|
|
|
2017-11-09 06:20:04 +01:00
|
|
|
Sdk_version *string
|
2017-10-21 02:57:49 +02:00
|
|
|
|
|
|
|
Installable *bool
|
2018-05-28 11:02:19 +02:00
|
|
|
|
|
|
|
// List of shared java libs that this module has dependencies to
|
|
|
|
Libs []string
|
2018-07-12 21:28:41 +02:00
|
|
|
|
|
|
|
// List of files to remove from the jar file(s)
|
|
|
|
Exclude_files []string
|
|
|
|
|
|
|
|
// List of directories to remove from the jar file(s)
|
|
|
|
Exclude_dirs []string
|
2018-08-28 03:31:46 +02:00
|
|
|
|
|
|
|
// if set to true, run Jetifier against .jar file. Defaults to false.
|
2019-03-22 06:21:39 +01:00
|
|
|
Jetifier *bool
|
2019-10-21 07:53:15 +02:00
|
|
|
|
|
|
|
// set the name of the output
|
|
|
|
Stem *string
|
2020-03-24 08:44:11 +01:00
|
|
|
|
|
|
|
Aidl struct {
|
|
|
|
// directories that should be added as include directories for any aidl sources of modules
|
|
|
|
// that depend on this module, as well as to aidl for this module.
|
|
|
|
Export_include_dirs []string
|
|
|
|
}
|
2017-08-02 20:05:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type Import struct {
|
2016-05-19 00:37:25 +02:00
|
|
|
android.ModuleBase
|
2018-10-02 22:53:33 +02:00
|
|
|
android.DefaultableModuleBase
|
2019-07-25 15:02:35 +02:00
|
|
|
android.ApexModuleBase
|
2017-07-07 23:47:12 +02:00
|
|
|
prebuilt android.Prebuilt
|
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 13:08:41 +02:00
|
|
|
android.SdkBase
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2020-05-17 09:34:50 +02:00
|
|
|
// Functionality common to Module and Import.
|
|
|
|
embeddableInModuleAndImport
|
|
|
|
|
2020-08-06 00:40:41 +02:00
|
|
|
hiddenAPI
|
|
|
|
dexer
|
2020-12-24 01:13:04 +01:00
|
|
|
dexpreopter
|
2020-08-06 00:40:41 +02:00
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
properties ImportProperties
|
|
|
|
|
2020-08-06 00:40:41 +02:00
|
|
|
// output file containing classes.dex and resources
|
|
|
|
dexJarFile android.Path
|
|
|
|
|
2017-08-30 23:24:55 +02:00
|
|
|
combinedClasspathFile android.Path
|
2020-10-08 13:53:58 +02:00
|
|
|
classLoaderContexts dexpreopt.ClassLoaderContextMap
|
2020-03-24 08:44:11 +01:00
|
|
|
exportAidlIncludeDirs android.Paths
|
2020-09-16 03:30:11 +02:00
|
|
|
|
|
|
|
hideApexVariantFromMake bool
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
func (j *Import) sdkVersion() sdkSpec {
|
|
|
|
return sdkSpecFrom(String(j.properties.Sdk_version))
|
2018-06-26 00:48:06 +02:00
|
|
|
}
|
|
|
|
|
2020-08-12 23:42:30 +02:00
|
|
|
func (j *Import) makeSdkVersion() string {
|
|
|
|
return j.sdkVersion().raw
|
|
|
|
}
|
|
|
|
|
2020-08-06 00:40:41 +02:00
|
|
|
func (j *Import) systemModules() string {
|
|
|
|
return "none"
|
|
|
|
}
|
|
|
|
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
func (j *Import) minSdkVersion() sdkSpec {
|
2018-06-26 00:48:06 +02:00
|
|
|
return j.sdkVersion()
|
|
|
|
}
|
|
|
|
|
2020-08-06 00:40:41 +02:00
|
|
|
func (j *Import) targetSdkVersion() sdkSpec {
|
|
|
|
return j.sdkVersion()
|
|
|
|
}
|
|
|
|
|
2020-04-27 19:53:18 +02:00
|
|
|
func (j *Import) MinSdkVersion() string {
|
|
|
|
return j.minSdkVersion().version.String()
|
|
|
|
}
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
func (j *Import) Prebuilt() *android.Prebuilt {
|
2017-07-07 23:47:12 +02:00
|
|
|
return &j.prebuilt
|
|
|
|
}
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
func (j *Import) PrebuiltSrcs() []string {
|
|
|
|
return j.properties.Jars
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *Import) Name() string {
|
2017-07-28 00:41:32 +02:00
|
|
|
return j.prebuilt.Name(j.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
2019-10-29 03:23:10 +01:00
|
|
|
func (j *Import) Stem() string {
|
|
|
|
return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
2020-01-08 05:35:43 +01:00
|
|
|
func (a *Import) JacocoReportClassesFile() android.Path {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-01-11 19:58:54 +01:00
|
|
|
func (j *Import) LintDepSets() LintDepSets {
|
|
|
|
return LintDepSets{}
|
|
|
|
}
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2018-08-29 23:10:52 +02:00
|
|
|
ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
|
2020-08-06 00:40:41 +02:00
|
|
|
|
|
|
|
if ctx.Device() && Bool(j.dexProperties.Compile_dex) {
|
|
|
|
sdkDeps(ctx, sdkContext(j), j.dexer)
|
|
|
|
}
|
2016-10-12 23:38:15 +02:00
|
|
|
}
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2021-02-01 20:01:34 +01:00
|
|
|
// Initialize the hiddenapi structure.
|
|
|
|
j.initHiddenAPI(ctx, j.BaseModuleName())
|
|
|
|
|
2020-09-16 03:30:11 +02:00
|
|
|
if !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() {
|
|
|
|
j.hideApexVariantFromMake = true
|
|
|
|
}
|
|
|
|
|
2019-03-06 07:25:09 +01:00
|
|
|
jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
|
2017-08-02 20:05:49 +02:00
|
|
|
|
2019-10-29 03:23:10 +01:00
|
|
|
jarName := j.Stem() + ".jar"
|
2018-08-28 03:31:46 +02:00
|
|
|
outputFile := android.PathForModuleOut(ctx, "combined", jarName)
|
2018-07-12 21:28:41 +02:00
|
|
|
TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
|
|
|
|
false, j.properties.Exclude_files, j.properties.Exclude_dirs)
|
2019-03-22 06:21:39 +01:00
|
|
|
if Bool(j.properties.Jetifier) {
|
2018-08-28 03:31:46 +02:00
|
|
|
inputFile := outputFile
|
|
|
|
outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
|
|
|
|
TransformJetifier(ctx, outputFile, inputFile)
|
|
|
|
}
|
2017-10-17 02:09:48 +02:00
|
|
|
j.combinedClasspathFile = outputFile
|
2020-10-08 13:53:58 +02:00
|
|
|
j.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap)
|
2020-05-15 11:20:31 +02:00
|
|
|
|
2020-08-06 00:40:41 +02:00
|
|
|
var flags javaBuilderFlags
|
2020-11-02 18:32:38 +01:00
|
|
|
var deapexerModule android.Module
|
2020-08-06 00:40:41 +02:00
|
|
|
|
2018-05-28 11:02:19 +02:00
|
|
|
ctx.VisitDirectDeps(func(module android.Module) {
|
|
|
|
tag := ctx.OtherModuleDependencyTag(module)
|
|
|
|
|
2021-02-01 22:59:03 +01:00
|
|
|
if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
|
|
|
|
dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
|
2018-05-28 11:02:19 +02:00
|
|
|
switch tag {
|
|
|
|
case libTag, staticLibTag:
|
2021-02-01 22:59:03 +01:00
|
|
|
flags.classpath = append(flags.classpath, dep.HeaderJars...)
|
2020-08-06 00:40:41 +02:00
|
|
|
case bootClasspathTag:
|
2021-02-01 22:59:03 +01:00
|
|
|
flags.bootClasspath = append(flags.bootClasspath, dep.HeaderJars...)
|
2018-05-28 11:02:19 +02:00
|
|
|
}
|
2021-02-01 22:59:03 +01:00
|
|
|
} else if dep, ok := module.(SdkLibraryDependency); ok {
|
2018-05-28 11:02:19 +02:00
|
|
|
switch tag {
|
|
|
|
case libTag:
|
2020-08-06 00:40:41 +02:00
|
|
|
flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
|
2018-05-28 11:02:19 +02:00
|
|
|
}
|
|
|
|
}
|
2020-12-03 17:50:22 +01:00
|
|
|
|
2020-12-16 17:16:11 +01:00
|
|
|
addCLCFromDep(ctx, module, j.classLoaderContexts)
|
2020-11-02 18:32:38 +01:00
|
|
|
|
|
|
|
// Save away the `deapexer` module on which this depends, if any.
|
|
|
|
if tag == android.DeapexerTag {
|
|
|
|
deapexerModule = module
|
|
|
|
}
|
2018-05-28 11:02:19 +02:00
|
|
|
})
|
|
|
|
|
2018-08-10 22:42:12 +02:00
|
|
|
if Bool(j.properties.Installable) {
|
2020-12-16 17:16:11 +01:00
|
|
|
ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
|
2019-10-21 07:53:15 +02:00
|
|
|
jarName, outputFile)
|
2018-08-10 22:42:12 +02:00
|
|
|
}
|
2020-03-24 08:44:11 +01:00
|
|
|
|
|
|
|
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs)
|
2020-08-06 00:40:41 +02:00
|
|
|
|
2020-11-02 18:32:38 +01:00
|
|
|
if ctx.Device() {
|
|
|
|
// If this is a variant created for a prebuilt_apex then use the dex implementation jar
|
|
|
|
// obtained from the associated deapexer module.
|
|
|
|
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 00:40:41 +02:00
|
|
|
|
2020-11-02 18:32:38 +01:00
|
|
|
// Get the path of the dex implementation jar from the `deapexer` module.
|
|
|
|
di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo)
|
2021-02-03 21:06:33 +01:00
|
|
|
if dexOutputPath := di.PrebuiltExportPath(j.BaseModuleName(), ".dexjar"); dexOutputPath != nil {
|
|
|
|
j.dexJarFile = dexOutputPath
|
2021-02-09 15:34:25 +01:00
|
|
|
j.hiddenAPIExtractInformation(ctx, dexOutputPath, outputFile)
|
2021-02-03 21:06:33 +01:00
|
|
|
} else {
|
2020-11-02 18:32:38 +01:00
|
|
|
// This should never happen as a variant for a prebuilt_apex is only created if the
|
|
|
|
// prebuilt_apex has been configured to export the java library dex file.
|
|
|
|
ctx.ModuleErrorf("internal error: no dex implementation jar available from prebuilt_apex %q", deapexerModule.Name())
|
|
|
|
}
|
|
|
|
} else if Bool(j.dexProperties.Compile_dex) {
|
|
|
|
sdkDep := decodeSdkDep(ctx, sdkContext(j))
|
|
|
|
if sdkDep.invalidVersion {
|
|
|
|
ctx.AddMissingDependencies(sdkDep.bootclasspath)
|
|
|
|
ctx.AddMissingDependencies(sdkDep.java9Classpath)
|
|
|
|
} else if sdkDep.useFiles {
|
|
|
|
// sdkDep.jar is actually equivalent to turbine header.jar.
|
|
|
|
flags.classpath = append(flags.classpath, sdkDep.jars...)
|
|
|
|
}
|
2020-12-24 01:13:04 +01:00
|
|
|
|
2020-11-02 18:32:38 +01:00
|
|
|
// Dex compilation
|
2020-12-24 01:13:04 +01:00
|
|
|
|
2020-11-02 18:32:38 +01: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 00:40:41 +02:00
|
|
|
|
2021-02-02 14:38:13 +01:00
|
|
|
var dexOutputFile android.OutputPath
|
2020-11-02 18:32:38 +01:00
|
|
|
dexOutputFile = j.dexer.compileDex(ctx, flags, j.minSdkVersion(), outputFile, jarName)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2020-08-06 00:40:41 +02:00
|
|
|
|
2020-11-02 18:32:38 +01:00
|
|
|
// Hidden API CSV generation and dex encoding
|
2021-02-09 15:34:25 +01:00
|
|
|
dexOutputFile = j.hiddenAPIExtractAndEncode(ctx, dexOutputFile, outputFile,
|
2020-11-02 18:32:38 +01:00
|
|
|
proptools.Bool(j.dexProperties.Uncompress_dex))
|
|
|
|
|
|
|
|
j.dexJarFile = dexOutputFile
|
|
|
|
}
|
2020-08-06 00:40:41 +02:00
|
|
|
}
|
2021-02-01 22:59:03 +01: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 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2020-10-06 18:20:13 +02:00
|
|
|
func (j *Import) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
switch tag {
|
2020-10-15 19:54:40 +02:00
|
|
|
case "", ".jar":
|
2020-10-06 18:20:13 +02:00
|
|
|
return android.Paths{j.combinedClasspathFile}, nil
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ android.OutputFileProducer = (*Import)(nil)
|
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
func (j *Import) HeaderJars() android.Paths {
|
2018-12-25 07:35:23 +01:00
|
|
|
if j.combinedClasspathFile == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2018-07-12 21:28:41 +02:00
|
|
|
return android.Paths{j.combinedClasspathFile}
|
2017-10-19 22:06:22 +02:00
|
|
|
}
|
|
|
|
|
2018-08-16 05:40:52 +02:00
|
|
|
func (j *Import) ImplementationAndResourcesJars() android.Paths {
|
2018-12-25 07:35:23 +01:00
|
|
|
if j.combinedClasspathFile == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2018-08-16 05:40:52 +02:00
|
|
|
return android.Paths{j.combinedClasspathFile}
|
|
|
|
}
|
|
|
|
|
2020-06-04 16:08:17 +02:00
|
|
|
func (j *Import) DexJarBuildPath() android.Path {
|
2020-08-06 00:40:41 +02:00
|
|
|
return j.dexJarFile
|
2019-01-31 23:12:44 +01:00
|
|
|
}
|
|
|
|
|
2020-06-09 15:31:19 +02:00
|
|
|
func (j *Import) DexJarInstallPath() android.Path {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-10-08 13:53:58 +02:00
|
|
|
func (j *Import) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
|
|
|
|
return j.classLoaderContexts
|
2018-05-28 11:02:19 +02:00
|
|
|
}
|
|
|
|
|
2020-12-15 14:29:02 +01:00
|
|
|
var _ android.ApexModule = (*Import)(nil)
|
|
|
|
|
|
|
|
// Implements android.ApexModule
|
apex_available tracks static dependencies
This change fixes a bug that apex_available is not enforced for static
dependencies. For example, a module with 'apex_available:
["//apex_available:platform"]' was able to be statically linked to any
APEX. This was happening because the check was done on the modules that
are actually installed to an APEX. Static dependencies of the modules
were not counted as they are not installed to the APEX as files.
Fixing this bug by doing the check by traversing the tree in the method
checkApexAvailability.
This change includes a few number of related changes:
1) DepIsInSameApex implementation for cc.Module was changed as well.
Previuosly, it returned false only when the dependency is actually a
stub variant of a lib. Now, it returns false when the dependency has one
or more stub variants. To understand why, we need to recall that when
there is a dependency to a lib having stubs, we actually create two
dependencies: to the non-stub variant and to the stub variant during the
DepsMutator phase. And later in the build action generation phase, we
choose one of them depending on the context. Also recall that an APEX
variant is created only when DepIsInSameApex returns true. Given these,
with the previous implementatin of DepIsInSameApex, we did create apex
variants of the non-stub variant of the dependency, while not creating
the apex variant for the stub variant. This is not right; we needlessly
created the apex variant. The extra apex variant has caused no harm so
far, but since the apex_available check became more correct, it actually
breaks the build. To fix the issue, we stop creating the APEX variant
both for non-stub and stub variants.
2) platform variant is created regardless of the apex_available value.
This is required for the case when a library X that provides stub is in
an APEX A and is configured to be available only for A. In that case,
libs in other APEX can't use the stub library since the stub library is
mutated only for apex A. By creating the platform variant for the stub
library, it can be used from outside as the default dependency variation
is set to the platform variant when creating the APEX variations.
3) The ApexAvailableWhitelist is added with the dependencies that were
revealed with this change.
Exempt-From-Owner-Approval: cherry-pick from internal
Bug: 147671264
Test: m
Merged-In: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
(cherry picked from commit fa89944c79f19552e906b41fd03a4981903eee7e)
Change-Id: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
2020-01-30 18:49:53 +01:00
|
|
|
func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
|
2020-05-17 09:34:50 +02:00
|
|
|
return j.depIsInSameApex(ctx, dep)
|
apex_available tracks static dependencies
This change fixes a bug that apex_available is not enforced for static
dependencies. For example, a module with 'apex_available:
["//apex_available:platform"]' was able to be statically linked to any
APEX. This was happening because the check was done on the modules that
are actually installed to an APEX. Static dependencies of the modules
were not counted as they are not installed to the APEX as files.
Fixing this bug by doing the check by traversing the tree in the method
checkApexAvailability.
This change includes a few number of related changes:
1) DepIsInSameApex implementation for cc.Module was changed as well.
Previuosly, it returned false only when the dependency is actually a
stub variant of a lib. Now, it returns false when the dependency has one
or more stub variants. To understand why, we need to recall that when
there is a dependency to a lib having stubs, we actually create two
dependencies: to the non-stub variant and to the stub variant during the
DepsMutator phase. And later in the build action generation phase, we
choose one of them depending on the context. Also recall that an APEX
variant is created only when DepIsInSameApex returns true. Given these,
with the previous implementatin of DepIsInSameApex, we did create apex
variants of the non-stub variant of the dependency, while not creating
the apex variant for the stub variant. This is not right; we needlessly
created the apex variant. The extra apex variant has caused no harm so
far, but since the apex_available check became more correct, it actually
breaks the build. To fix the issue, we stop creating the APEX variant
both for non-stub and stub variants.
2) platform variant is created regardless of the apex_available value.
This is required for the case when a library X that provides stub is in
an APEX A and is configured to be available only for A. In that case,
libs in other APEX can't use the stub library since the stub library is
mutated only for apex A. By creating the platform variant for the stub
library, it can be used from outside as the default dependency variation
is set to the platform variant when creating the APEX variations.
3) The ApexAvailableWhitelist is added with the dependencies that were
revealed with this change.
Exempt-From-Owner-Approval: cherry-pick from internal
Bug: 147671264
Test: m
Merged-In: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
(cherry picked from commit fa89944c79f19552e906b41fd03a4981903eee7e)
Change-Id: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
2020-01-30 18:49:53 +01:00
|
|
|
}
|
|
|
|
|
2020-12-15 14:29:02 +01:00
|
|
|
// Implements android.ApexModule
|
2020-07-23 07:32:17 +02:00
|
|
|
func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
|
|
|
|
sdkVersion android.ApiLevel) error {
|
2020-04-15 04:03:39 +02:00
|
|
|
// Do not check for prebuilts against the min_sdk_version of enclosing APEX
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-12-25 07:35:23 +01:00
|
|
|
// Add compile time check for interface implementation
|
|
|
|
var _ android.IDEInfo = (*Import)(nil)
|
|
|
|
var _ android.IDECustomizedModuleName = (*Import)(nil)
|
|
|
|
|
2018-08-16 00:35:38 +02:00
|
|
|
// Collect information for opening IDE project files in java/jdeps.go.
|
|
|
|
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 12:33:16 +02:00
|
|
|
name = strings.TrimPrefix(name, removedPrefix)
|
2018-08-16 00:35:38 +02:00
|
|
|
}
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
var _ android.PrebuiltInterface = (*Import)(nil)
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2020-12-24 01:13:04 +01:00
|
|
|
func (j *Import) IsInstallable() bool {
|
|
|
|
return Bool(j.properties.Installable)
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ dexpreopterInterface = (*Import)(nil)
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module.
|
|
|
|
//
|
|
|
|
// By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were
|
|
|
|
// compiled against an Android classpath.
|
|
|
|
//
|
|
|
|
// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
|
|
|
|
// for host modules.
|
2017-08-02 20:05:49 +02:00
|
|
|
func ImportFactory() android.Module {
|
|
|
|
module := &Import{}
|
2017-06-24 00:06:31 +02:00
|
|
|
|
2020-08-06 00:40:41 +02:00
|
|
|
module.AddProperties(
|
|
|
|
&module.properties,
|
|
|
|
&module.dexer.dexProperties,
|
|
|
|
)
|
2017-08-02 20:05:49 +02:00
|
|
|
|
2020-05-15 11:20:31 +02:00
|
|
|
module.initModuleAndImport(&module.ModuleBase)
|
|
|
|
|
2020-08-06 00:40:41 +02:00
|
|
|
module.dexProperties.Optimize.EnabledByDefault = false
|
|
|
|
|
2017-08-02 20:05:49 +02:00
|
|
|
android.InitPrebuiltModule(module, &module.properties.Jars)
|
2019-07-25 15:02:35 +02:00
|
|
|
android.InitApexModule(module)
|
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 13:08:41 +02:00
|
|
|
android.InitSdkAwareModule(module)
|
2019-11-13 02:50:48 +01:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
2017-06-24 00:06:31 +02:00
|
|
|
return module
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host
|
|
|
|
// module.
|
|
|
|
//
|
|
|
|
// A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were
|
|
|
|
// compiled against a host bootclasspath.
|
2017-08-02 20:05:49 +02:00
|
|
|
func ImportFactoryHost() android.Module {
|
|
|
|
module := &Import{}
|
|
|
|
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
|
|
|
|
android.InitPrebuiltModule(module, &module.properties.Jars)
|
2019-07-25 15:02:35 +02:00
|
|
|
android.InitApexModule(module)
|
2019-11-13 02:50:48 +01:00
|
|
|
InitJavaModule(module, android.HostSupported)
|
2017-08-02 20:05:49 +02:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2019-02-22 03:12:14 +01:00
|
|
|
// dex_import module
|
|
|
|
|
|
|
|
type DexImportProperties struct {
|
2019-07-15 22:36:55 +02:00
|
|
|
Jars []string `android:"path"`
|
2019-10-21 07:53:15 +02:00
|
|
|
|
|
|
|
// set the name of the output
|
|
|
|
Stem *string
|
2019-02-22 03:12:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type DexImport struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultableModuleBase
|
2019-07-25 15:02:35 +02:00
|
|
|
android.ApexModuleBase
|
2019-02-22 03:12:14 +01:00
|
|
|
prebuilt android.Prebuilt
|
|
|
|
|
|
|
|
properties DexImportProperties
|
|
|
|
|
2021-02-26 23:54:36 +01:00
|
|
|
dexJarFile android.Path
|
2019-02-22 03:12:14 +01:00
|
|
|
|
|
|
|
dexpreopter
|
2020-09-16 03:30:11 +02:00
|
|
|
|
|
|
|
hideApexVariantFromMake bool
|
2019-02-22 03:12:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (j *DexImport) Prebuilt() *android.Prebuilt {
|
|
|
|
return &j.prebuilt
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *DexImport) PrebuiltSrcs() []string {
|
|
|
|
return j.properties.Jars
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *DexImport) Name() string {
|
|
|
|
return j.prebuilt.Name(j.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
2019-10-29 03:23:10 +01:00
|
|
|
func (j *DexImport) Stem() string {
|
|
|
|
return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
2020-06-01 14:39:15 +02:00
|
|
|
func (a *DexImport) JacocoReportClassesFile() android.Path {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-22 05:31:17 +02:00
|
|
|
func (a *DexImport) LintDepSets() LintDepSets {
|
|
|
|
return LintDepSets{}
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:10:36 +01:00
|
|
|
func (j *DexImport) IsInstallable() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-02-22 03:12:14 +01:00
|
|
|
func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
if len(j.properties.Jars) != 1 {
|
|
|
|
ctx.PropertyErrorf("jars", "exactly one jar must be provided")
|
|
|
|
}
|
|
|
|
|
2020-09-16 03:30:11 +02:00
|
|
|
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
|
|
|
|
if !apexInfo.IsForPlatform() {
|
|
|
|
j.hideApexVariantFromMake = true
|
|
|
|
}
|
|
|
|
|
2019-10-29 03:23:10 +01:00
|
|
|
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
|
2019-02-22 03:12:14 +01: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 02:32:30 +01:00
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
2019-02-22 03:12:14 +01:00
|
|
|
|
|
|
|
temporary := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar.unaligned")
|
|
|
|
rule.Temporary(temporary)
|
|
|
|
|
|
|
|
// use zip2zip to uncompress classes*.dex files
|
|
|
|
rule.Command().
|
2020-11-17 02:32:30 +01:00
|
|
|
BuiltTool("zip2zip").
|
2019-02-22 03:12:14 +01:00
|
|
|
FlagWithInput("-i ", inputJar).
|
|
|
|
FlagWithOutput("-o ", temporary).
|
|
|
|
FlagWithArg("-0 ", "'classes*.dex'")
|
|
|
|
|
|
|
|
// use zipalign to align uncompressed classes*.dex files
|
|
|
|
rule.Command().
|
2020-11-17 02:32:30 +01:00
|
|
|
BuiltTool("zipalign").
|
2019-02-22 03:12:14 +01:00
|
|
|
Flag("-f").
|
|
|
|
Text("4").
|
|
|
|
Input(temporary).
|
|
|
|
Output(dexOutputFile)
|
|
|
|
|
|
|
|
rule.DeleteTemporaryFiles()
|
|
|
|
|
2020-11-17 02:32:30 +01:00
|
|
|
rule.Build("uncompress_dex", "uncompress dex")
|
2019-02-22 03:12:14 +01:00
|
|
|
} else {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Cp,
|
|
|
|
Input: inputJar,
|
|
|
|
Output: dexOutputFile,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
j.dexJarFile = dexOutputFile
|
|
|
|
|
2020-12-17 18:43:28 +01:00
|
|
|
j.dexpreopt(ctx, dexOutputFile)
|
2019-02-22 03:12:14 +01:00
|
|
|
|
2020-09-16 03:30:11 +02:00
|
|
|
if apexInfo.IsForPlatform() {
|
2020-06-08 12:24:09 +02:00
|
|
|
ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
|
|
|
|
j.Stem()+".jar", dexOutputFile)
|
|
|
|
}
|
2019-02-22 03:12:14 +01:00
|
|
|
}
|
|
|
|
|
2020-06-04 16:08:17 +02:00
|
|
|
func (j *DexImport) DexJarBuildPath() android.Path {
|
2019-02-22 03:12:14 +01:00
|
|
|
return j.dexJarFile
|
|
|
|
}
|
|
|
|
|
2020-12-15 14:29:02 +01:00
|
|
|
var _ android.ApexModule = (*DexImport)(nil)
|
|
|
|
|
|
|
|
// Implements android.ApexModule
|
2020-07-23 07:32:17 +02:00
|
|
|
func (j *DexImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
|
|
|
|
sdkVersion android.ApiLevel) error {
|
2020-04-15 04:03:39 +02:00
|
|
|
// we don't check prebuilt modules for sdk_version
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-02-22 03:12:14 +01:00
|
|
|
// dex_import imports a `.jar` file containing classes.dex files.
|
|
|
|
//
|
|
|
|
// A dex_import module cannot be used as a dependency of a java_* or android_* module, it can only be installed
|
|
|
|
// to the device.
|
|
|
|
func DexImportFactory() android.Module {
|
|
|
|
module := &DexImport{}
|
|
|
|
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
|
|
|
|
android.InitPrebuiltModule(module, &module.properties.Jars)
|
2019-07-25 15:02:35 +02:00
|
|
|
android.InitApexModule(module)
|
2019-11-13 02:50:48 +01:00
|
|
|
InitJavaModule(module, android.DeviceSupported)
|
2019-02-22 03:12:14 +01:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2017-07-07 23:35:50 +02:00
|
|
|
//
|
|
|
|
// Defaults
|
|
|
|
//
|
|
|
|
type Defaults struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultsModuleBase
|
2019-07-25 15:02:35 +02:00
|
|
|
android.ApexModuleBase
|
2017-07-07 23:35:50 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// java_defaults provides a set of properties that can be inherited by other java or android modules.
|
|
|
|
//
|
|
|
|
// A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each
|
|
|
|
// property in the defaults module that exists in the depending module will be prepended to the depending module's
|
|
|
|
// value for that property.
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// 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"],
|
|
|
|
// }
|
2017-07-07 23:35:50 +02:00
|
|
|
func defaultsFactory() android.Module {
|
|
|
|
return DefaultsFactory()
|
|
|
|
}
|
|
|
|
|
2019-12-05 15:07:14 +01:00
|
|
|
func DefaultsFactory() android.Module {
|
2017-07-07 23:35:50 +02:00
|
|
|
module := &Defaults{}
|
|
|
|
|
|
|
|
module.AddProperties(
|
|
|
|
&CompilerProperties{},
|
|
|
|
&CompilerDeviceProperties{},
|
2020-07-10 00:16:41 +02:00
|
|
|
&DexProperties{},
|
2018-11-12 19:13:39 +01:00
|
|
|
&DexpreoptProperties{},
|
2018-03-08 22:27:59 +01:00
|
|
|
&android.ProtoProperties{},
|
2018-10-02 22:53:33 +02:00
|
|
|
&aaptProperties{},
|
|
|
|
&androidLibraryProperties{},
|
|
|
|
&appProperties{},
|
|
|
|
&appTestProperties{},
|
2019-03-01 00:35:54 +01:00
|
|
|
&overridableAppProperties{},
|
2020-02-04 16:45:49 +01:00
|
|
|
&testProperties{},
|
2018-10-02 22:53:33 +02:00
|
|
|
&ImportProperties{},
|
|
|
|
&AARImportProperties{},
|
|
|
|
&sdkLibraryProperties{},
|
2020-05-08 14:44:43 +02:00
|
|
|
&commonToSdkLibraryAndImportProperties{},
|
2019-02-22 03:12:14 +01:00
|
|
|
&DexImportProperties{},
|
2019-11-13 02:50:48 +01:00
|
|
|
&android.ApexProperties{},
|
2020-04-27 00:10:51 +02:00
|
|
|
&RuntimeResourceOverlayProperties{},
|
2020-06-03 05:09:13 +02:00
|
|
|
&LintProperties{},
|
2021-02-09 19:38:30 +01:00
|
|
|
&appTestHelperAppProperties{},
|
2017-07-07 23:35:50 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
android.InitDefaultsModule(module)
|
|
|
|
return module
|
|
|
|
}
|
2017-11-09 06:20:04 +01:00
|
|
|
|
2018-11-06 01:49:08 +01:00
|
|
|
func kytheExtractJavaFactory() android.Singleton {
|
|
|
|
return &kytheExtractJavaSingleton{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type kytheExtractJavaSingleton struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
|
|
|
var xrefTargets android.Paths
|
|
|
|
ctx.VisitAllModules(func(module android.Module) {
|
|
|
|
if javaModule, ok := module.(xref); ok {
|
|
|
|
xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets
|
|
|
|
if len(xrefTargets) > 0 {
|
2020-06-04 22:25:17 +02:00
|
|
|
ctx.Phony("xref_java", xrefTargets...)
|
2018-11-06 01:49:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-09 06:20:04 +01:00
|
|
|
var Bool = proptools.Bool
|
2018-04-11 01:14:46 +02:00
|
|
|
var BoolDefault = proptools.BoolDefault
|
2017-11-09 06:20:04 +01:00
|
|
|
var String = proptools.String
|
2018-02-20 22:33:42 +01:00
|
|
|
var inList = android.InList
|
2020-12-03 17:50:22 +01:00
|
|
|
|
2020-12-16 17:16:11 +01:00
|
|
|
// TODO(b/132357300) Generalize SdkLibrarComponentDependency to non-SDK libraries and merge with
|
|
|
|
// this interface.
|
|
|
|
type ProvidesUsesLib interface {
|
|
|
|
ProvidesUsesLib() *string
|
|
|
|
}
|
2020-12-03 17:50:22 +01:00
|
|
|
|
2020-12-16 17:16:11 +01:00
|
|
|
func (j *Module) ProvidesUsesLib() *string {
|
|
|
|
return j.usesLibraryProperties.Provides_uses_lib
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-03 17:50:22 +01:00
|
|
|
}
|
2020-12-16 17:16:11 +01:00
|
|
|
} else {
|
|
|
|
// Don't propagate <uses-library> for other dependency tags.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if implicitSdkLib != nil {
|
2021-01-05 16:41:55 +01:00
|
|
|
clcMap.AddContext(ctx, dexpreopt.AnySdkVersion, *implicitSdkLib,
|
2020-12-16 17:16:11 +01:00
|
|
|
dep.DexJarBuildPath(), dep.DexJarInstallPath(), dep.ClassLoaderContexts())
|
|
|
|
} else {
|
|
|
|
depName := ctx.OtherModuleName(depModule)
|
|
|
|
clcMap.AddContextMap(dep.ClassLoaderContexts(), depName)
|
2020-12-03 17:50:22 +01:00
|
|
|
}
|
|
|
|
}
|