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"
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"
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 ( ) {
2017-07-07 23:35:50 +02:00
android . RegisterModuleType ( "java_defaults" , defaultsFactory )
2018-06-27 02:59:05 +02:00
android . RegisterModuleType ( "java_library" , LibraryFactory )
android . RegisterModuleType ( "java_library_static" , LibraryFactory )
2017-07-20 00:53:04 +02:00
android . RegisterModuleType ( "java_library_host" , LibraryHostFactory )
android . RegisterModuleType ( "java_binary" , BinaryFactory )
android . RegisterModuleType ( "java_binary_host" , BinaryHostFactory )
2018-04-10 03:40:24 +02:00
android . RegisterModuleType ( "java_test" , TestFactory )
android . RegisterModuleType ( "java_test_host" , TestHostFactory )
2017-08-02 20:05:49 +02:00
android . RegisterModuleType ( "java_import" , ImportFactory )
android . RegisterModuleType ( "java_import_host" , ImportFactoryHost )
2016-10-12 23:28:16 +02:00
android . RegisterSingletonType ( "logtags" , LogtagsSingleton )
2015-06-17 23:20:06 +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 {
2015-05-11 22:39:40 +02:00
// list of source files used to compile the Java module. May be .java, .logtags, .proto,
// or .aidl files.
2015-07-01 03:15:24 +02:00
Srcs [ ] string ` android:"arch_variant" `
// 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
Exclude_srcs [ ] string ` android:"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
Java_resources [ ] string ` android:"arch_variant" `
2018-09-13 20:26:19 +02:00
// list of files that should be excluded from java_resources and java_resource_dirs
2017-09-28 02:42:05 +02:00
Exclude_java_resources [ ] string ` android:"arch_variant" `
2017-10-02 05:33:03 +02:00
// don't build against the default libraries (bootclasspath, legacy-test, core-junit,
2015-05-11 22:39:40 +02:00
// ext, and framework for device targets)
2017-08-30 01:02:06 +02:00
No_standard_libs * bool
2015-03-31 02:20:39 +02:00
2017-10-02 05:33:03 +02:00
// don't build against the framework libraries (legacy-test, core-junit,
// ext, and framework for device targets)
No_framework_libs * bool
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
2015-09-24 00:26:20 +02:00
Manifest * string
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
2017-10-17 22:55:55 +02:00
Jarjar_rules * string ` android:"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
2017-09-06 22:41:06 +02:00
// List of modules to use as annotation processors
Annotation_processors [ ] string
// List of classes to pass to javac to use as annotation processors
Annotation_processor_classes [ ] string
2017-09-30 02:58:17 +02:00
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 {
// List of source files that should only be used when passing -source 1.9
Srcs [ ] string
// List of javac flags that should only be used when passing -source 1.9
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
}
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" `
2017-06-23 02:01:52 +02:00
}
2017-07-07 23:35:50 +02:00
type CompilerDeviceProperties struct {
2017-06-23 02:01:52 +02:00
// list of module-specific flags that will be used for dex compiles
Dxflags [ ] string ` android:"arch_variant" `
2018-06-26 00:48:06 +02:00
// if not blank, set to the version of the sdk to compile against. Defaults to compiling against the current
// sdk if platform_apis is not set.
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
2018-05-22 20:12:33 +02:00
// if true, compile against the platform APIs instead of an SDK.
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
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
2018-06-27 11:27:45 +02:00
// If set to true, compile dex regardless of installable. Defaults to false.
Compile_dex * bool
2017-12-28 21:23:20 +01:00
Optimize struct {
2018-05-22 20:11:52 +02:00
// If false, disable all optimization. Defaults to true for android_app and android_test
// modules, false for java_library and java_test modules.
2017-12-28 21:23:20 +01:00
Enabled * bool
// If true, optimize for size by removing unused code. Defaults to true for apps,
// false for libraries and tests.
Shrink * bool
// If true, optimize bytecode. Defaults to false.
Optimize * bool
// If true, obfuscate bytecode. Defaults to false.
Obfuscate * bool
// If true, do not use the flag files generated by aapt that automatically keep
// classes referenced by the app manifest. Defaults to false.
No_aapt_flags * bool
// Flags to pass to proguard.
Proguard_flags [ ] string
// Specifies the locations of files containing proguard flags.
Proguard_flags_files [ ] string
}
2017-09-30 02:58:17 +02:00
// When targeting 1.9, override the modules to use with --system
System_modules * string
2018-10-05 23:20:06 +02:00
UncompressDex bool ` blueprint:"mutated" `
2018-11-12 19:13:39 +01:00
IsSDKLibrary bool ` blueprint:"mutated" `
2015-05-11 22:39:40 +02:00
}
2015-04-08 22:03:43 +02:00
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
2015-05-11 22:39:40 +02:00
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
// 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
2018-11-12 19:13:39 +01:00
// output file that contains classes.dex if it should be in the output file
maybeStrippedDexJarFile android . Path
2017-11-22 22:49:43 +01:00
// output file containing uninstrumented classes that will be instrumented by jacoco
jacocoReportClassesFile android . Path
2017-12-28 21:23:20 +01:00
// output file containing mapping of obfuscated names
proguardDictionary 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
2016-05-19 00:37:25 +02:00
outputFile android . Path
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
// list of extra progurad flag files
extraProguardFlagFiles android . Paths
2018-05-28 11:02:19 +02:00
2018-10-18 00:10:48 +02:00
// manifest file to use instead of properties.Manifest
overrideManifest android . OptionalPath
2018-05-28 11:02:19 +02:00
// list of SDK lib names that this java moudule is exporting
exportedSdkLibs [ ] string
2018-08-16 00:35:38 +02:00
// list of source files, collected from compiledJavaSrcs and compiledSrcJars
// filter out Exclude_srcs, will be used by android.IDEInfo struct
expandIDEInfoCompiledSrcs [ ] string
2018-11-12 19:13:39 +01:00
dexpreopter
2015-03-31 02:20:39 +02:00
}
2017-12-05 18:28:08 +01:00
func ( j * Module ) Srcs ( ) android . Paths {
2018-08-15 20:19:12 +02:00
return android . Paths { j . outputFile }
2017-12-05 18:28:08 +01:00
}
2018-11-07 18:50:25 +01:00
func ( j * Module ) DexJarFile ( ) android . Path {
return j . dexJarFile
}
2017-12-05 18:28:08 +01:00
var _ android . SourceFileProducer = ( * Module ) ( nil )
2017-07-20 00:53:04 +02:00
type Dependency interface {
2017-10-19 22:06:22 +02:00
HeaderJars ( ) android . Paths
ImplementationJars ( ) android . Paths
2018-08-16 05:40:52 +02:00
ResourceJars ( ) android . Paths
ImplementationAndResourcesJars ( ) android . Paths
2016-05-19 00:37:25 +02:00
AidlIncludeDirs ( ) android . Paths
2018-05-28 11:02:19 +02:00
ExportedSdkLibs ( ) [ ] string
2015-03-31 02:20:39 +02:00
}
2018-04-10 06:07:10 +02:00
type SdkLibraryDependency interface {
HeaderJars ( linkType linkType ) android . Paths
2018-07-13 09:16:44 +02:00
ImplementationJars ( linkType linkType ) android . Paths
2018-04-10 06:07:10 +02:00
}
2018-02-23 20:18:47 +01:00
type SrcDependency interface {
CompiledSrcs ( ) android . Paths
CompiledSrcJars ( ) android . Paths
}
func ( j * Module ) CompiledSrcs ( ) android . Paths {
return j . compiledJavaSrcs
}
func ( j * Module ) CompiledSrcJars ( ) android . Paths {
return j . compiledSrcJars
}
var _ SrcDependency = ( * Module ) ( nil )
2017-07-07 23:35:50 +02:00
func InitJavaModule ( module android . DefaultableModule , hod android . HostOrDeviceSupported ) {
android . InitAndroidArchModule ( module , hod , android . MultilibCommon )
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
}
2018-10-03 07:03:40 +02:00
type jniDependencyTag struct {
blueprint . BaseDependencyTag
target android . Target
}
2017-07-08 00:59:46 +02:00
var (
2018-10-16 01:18:06 +02:00
staticLibTag = dependencyTag { name : "staticlib" }
libTag = dependencyTag { name : "javalib" }
annoTag = dependencyTag { name : "annotation processor" }
bootClasspathTag = dependencyTag { name : "bootclasspath" }
systemModulesTag = dependencyTag { name : "system modules" }
frameworkResTag = dependencyTag { name : "framework-res" }
frameworkApkTag = dependencyTag { name : "framework-apk" }
kotlinStdlibTag = dependencyTag { name : "kotlin-stdlib" }
proguardRaiseTag = dependencyTag { name : "proguard-raise" }
certificateTag = dependencyTag { name : "certificate" }
instrumentationForTag = dependencyTag { name : "instrumentation_for" }
2017-07-08 00:59:46 +02:00
)
2015-03-31 02:20:39 +02:00
2017-09-19 02:41:52 +02:00
type sdkDep struct {
2017-10-02 23:22:08 +02:00
useModule , useFiles , useDefaultLibs , invalidVersion bool
2018-05-29 23:44:55 +02:00
modules [ ] string
2017-09-30 02:58:17 +02:00
systemModules string
2018-03-28 23:58:31 +02:00
frameworkResModule string
2018-05-29 23:44:55 +02:00
jars android . Paths
2017-09-30 02:58:17 +02:00
aidl android . Path
2017-09-19 02:41:52 +02:00
}
2018-10-03 07:03:40 +02:00
type jniLib struct {
name string
path android . Path
target android . Target
}
2018-01-04 00:06:47 +01:00
func ( j * Module ) shouldInstrument ( ctx android . BaseContext ) bool {
return j . properties . Instrument && ctx . Config ( ) . IsEnvTrue ( "EMMA_INSTRUMENT" )
}
func ( j * Module ) shouldInstrumentStatic ( ctx android . BaseContext ) bool {
return j . shouldInstrument ( ctx ) &&
( ctx . Config ( ) . IsEnvTrue ( "EMMA_INSTRUMENT_STATIC" ) ||
ctx . Config ( ) . UnbundledBuild ( ) )
}
2018-06-26 00:48:06 +02:00
func ( j * Module ) sdkVersion ( ) string {
return String ( j . deviceProperties . Sdk_version )
}
func ( j * Module ) minSdkVersion ( ) string {
if j . deviceProperties . Min_sdk_version != nil {
return * j . deviceProperties . Min_sdk_version
}
return j . sdkVersion ( )
}
2018-10-31 23:28:47 +01:00
func ( j * Module ) targetSdkVersion ( ) string {
if j . deviceProperties . Target_sdk_version != nil {
return * j . deviceProperties . Target_sdk_version
}
return j . sdkVersion ( )
}
2018-06-26 00:48:06 +02:00
type sdkContext interface {
// sdkVersion eturns the sdk_version property of the current module, or an empty string if it is not set.
sdkVersion ( ) string
// minSdkVersion returns the min_sdk_version property of the current module, or sdkVersion() if it is not set.
minSdkVersion ( ) string
2018-10-31 23:28:47 +01:00
// targetSdkVersion returns the target_sdk_version property of the current module, or sdkVersion() if it is not set.
targetSdkVersion ( ) string
2018-06-26 00:48:06 +02:00
}
func sdkVersionOrDefault ( ctx android . BaseContext , v string ) string {
switch v {
2018-10-18 20:48:58 +02:00
case "" , "current" , "system_current" , "test_current" , "core_current" :
2018-06-26 00:48:06 +02:00
return ctx . Config ( ) . DefaultAppTargetSdk ( )
default :
return v
}
}
// Returns a sdk version as a number. For modules targeting an unreleased SDK (meaning it does not yet have a number)
// it returns android.FutureApiLevel (10000).
func sdkVersionToNumber ( ctx android . BaseContext , v string ) ( int , error ) {
switch v {
2018-10-18 20:48:58 +02:00
case "" , "current" , "test_current" , "system_current" , "core_current" :
2018-06-26 00:48:06 +02:00
return ctx . Config ( ) . DefaultAppTargetSdkInt ( ) , nil
default :
n := android . GetNumericSdkVersion ( v )
if i , err := strconv . Atoi ( n ) ; err != nil {
return - 1 , fmt . Errorf ( "invalid sdk version %q" , n )
} else {
return i , nil
}
}
}
func sdkVersionToNumberAsString ( ctx android . BaseContext , v string ) ( string , error ) {
n , err := sdkVersionToNumber ( ctx , v )
if err != nil {
return "" , err
}
return strconv . Itoa ( n ) , nil
}
func decodeSdkDep ( ctx android . BaseContext , sdkContext sdkContext ) sdkDep {
v := sdkContext . sdkVersion ( )
i , err := sdkVersionToNumber ( ctx , v )
if err != nil {
ctx . PropertyErrorf ( "sdk_version" , "%s" , err )
2017-09-30 02:58:17 +02:00
return sdkDep { }
}
2017-09-19 02:41:52 +02:00
2018-01-15 07:05:10 +01:00
// Ensures that the specificed system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor apks)
// or PRODUCT_SYSTEMSDK_VERSIONS (for other apks or when BOARD_SYSTEMSDK_VERSIONS is not set)
if strings . HasPrefix ( v , "system_" ) && i != android . FutureApiLevel {
allowed_versions := ctx . DeviceConfig ( ) . PlatformSystemSdkVersions ( )
if ctx . DeviceSpecific ( ) || ctx . SocSpecific ( ) {
if len ( ctx . DeviceConfig ( ) . SystemSdkVersions ( ) ) > 0 {
allowed_versions = ctx . DeviceConfig ( ) . SystemSdkVersions ( )
}
}
version := strings . TrimPrefix ( v , "system_" )
if len ( allowed_versions ) > 0 && ! android . InList ( version , allowed_versions ) {
ctx . PropertyErrorf ( "sdk_version" , "incompatible sdk version %q. System SDK version should be one of %q" ,
v , allowed_versions )
}
}
2018-04-11 14:57:30 +02:00
toPrebuilt := func ( sdk string ) sdkDep {
var api , v string
if strings . Contains ( sdk , "_" ) {
t := strings . Split ( sdk , "_" )
api = t [ 0 ]
v = t [ 1 ]
} else {
api = "public"
v = sdk
2018-01-30 16:20:13 +01:00
}
2018-04-11 14:57:30 +02:00
dir := filepath . Join ( "prebuilts" , "sdk" , v , api )
2017-09-19 02:41:52 +02:00
jar := filepath . Join ( dir , "android.jar" )
2018-04-11 14:57:30 +02:00
// There's no aidl for other SDKs yet.
// TODO(77525052): Add aidl files for other SDKs too.
public_dir := filepath . Join ( "prebuilts" , "sdk" , v , "public" )
aidl := filepath . Join ( public_dir , "framework.aidl" )
2018-02-22 20:47:25 +01:00
jarPath := android . ExistentPathForSource ( ctx , jar )
aidlPath := android . ExistentPathForSource ( ctx , aidl )
2018-05-29 23:44:55 +02:00
lambdaStubsPath := android . PathForSource ( ctx , config . SdkLambdaStubsPath )
2017-10-02 23:22:08 +02:00
2017-11-29 09:27:14 +01:00
if ( ! jarPath . Valid ( ) || ! aidlPath . Valid ( ) ) && ctx . Config ( ) . AllowMissingDependencies ( ) {
2017-10-02 23:22:08 +02:00
return sdkDep {
invalidVersion : true ,
2018-05-29 23:44:55 +02:00
modules : [ ] string { fmt . Sprintf ( "sdk_%s_%s_android" , api , v ) } ,
2017-10-02 23:22:08 +02:00
}
}
2017-09-19 02:41:52 +02:00
if ! jarPath . Valid ( ) {
ctx . PropertyErrorf ( "sdk_version" , "invalid sdk version %q, %q does not exist" , v , jar )
return sdkDep { }
}
2017-10-02 23:22:08 +02:00
2017-09-19 02:41:52 +02:00
if ! aidlPath . Valid ( ) {
ctx . PropertyErrorf ( "sdk_version" , "invalid sdk version %q, %q does not exist" , v , aidl )
return sdkDep { }
}
2017-10-02 23:22:08 +02:00
2017-09-19 02:41:52 +02:00
return sdkDep {
useFiles : true ,
2018-05-29 23:44:55 +02:00
jars : android . Paths { jarPath . Path ( ) , lambdaStubsPath } ,
2017-09-19 02:41:52 +02:00
aidl : aidlPath . Path ( ) ,
}
}
2018-03-28 23:58:31 +02:00
toModule := func ( m , r string ) sdkDep {
2018-03-26 23:42:44 +02:00
ret := sdkDep {
2018-03-28 23:58:31 +02:00
useModule : true ,
2018-05-29 23:44:55 +02:00
modules : [ ] string { m , config . DefaultLambdaStubsLibrary } ,
2018-03-28 23:58:31 +02:00
systemModules : m + "_system_modules" ,
frameworkResModule : r ,
2018-03-26 23:42:44 +02:00
}
if m == "core.current.stubs" {
ret . systemModules = "core-system-modules"
2018-09-11 10:29:31 +02:00
} else if m == "core.platform.api.stubs" {
ret . systemModules = "core-platform-api-stubs-system-modules"
2018-03-26 23:42:44 +02:00
}
return ret
}
2017-09-19 02:41:52 +02:00
2017-11-29 09:27:14 +01:00
if ctx . Config ( ) . UnbundledBuild ( ) && v != "" {
2018-04-11 14:57:30 +02:00
return toPrebuilt ( v )
2017-09-19 02:41:52 +02:00
}
switch v {
case "" :
return sdkDep {
2018-03-28 23:58:31 +02:00
useDefaultLibs : true ,
frameworkResModule : "framework-res" ,
2017-09-19 02:41:52 +02:00
}
2018-03-26 23:42:44 +02:00
case "current" :
2018-03-28 23:58:31 +02:00
return toModule ( "android_stubs_current" , "framework-res" )
2018-03-26 23:42:44 +02:00
case "system_current" :
2018-03-28 23:58:31 +02:00
return toModule ( "android_system_stubs_current" , "framework-res" )
2018-03-26 23:42:44 +02:00
case "test_current" :
2018-03-28 23:58:31 +02:00
return toModule ( "android_test_stubs_current" , "framework-res" )
2018-03-26 23:42:44 +02:00
case "core_current" :
2018-03-28 23:58:31 +02:00
return toModule ( "core.current.stubs" , "" )
2017-09-19 02:41:52 +02:00
default :
2018-04-11 14:57:30 +02:00
return toPrebuilt ( v )
2017-09-19 02:41:52 +02:00
}
}
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 ( ) {
2018-04-11 01:15:18 +02:00
if ! Bool ( j . properties . No_standard_libs ) {
2018-06-26 00:48:06 +02:00
sdkDep := decodeSdkDep ( ctx , sdkContext ( j ) )
2017-09-19 02:41:52 +02:00
if sdkDep . useDefaultLibs {
2018-08-29 23:10:52 +02:00
ctx . AddVariationDependencies ( nil , bootClasspathTag , config . DefaultBootclasspathLibraries ... )
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
ctx . AddVariationDependencies ( nil , systemModulesTag , config . DefaultSystemModules )
2018-04-11 01:15:18 +02:00
if ! Bool ( j . properties . No_framework_libs ) {
2018-08-29 23:10:52 +02:00
ctx . AddVariationDependencies ( nil , libTag , config . DefaultLibraries ... )
2017-10-02 05:33:03 +02:00
}
2017-09-30 02:58:17 +02:00
} else if sdkDep . useModule {
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
ctx . AddVariationDependencies ( nil , systemModulesTag , sdkDep . systemModules )
2018-08-29 23:10:52 +02:00
ctx . AddVariationDependencies ( nil , bootClasspathTag , sdkDep . modules ... )
2017-12-28 21:23:20 +01:00
if Bool ( j . deviceProperties . Optimize . Enabled ) {
2018-08-29 23:10:52 +02:00
ctx . AddVariationDependencies ( nil , proguardRaiseTag , config . DefaultBootclasspathLibraries ... )
ctx . AddVariationDependencies ( nil , proguardRaiseTag , config . DefaultLibraries ... )
2017-12-28 21:23:20 +01:00
}
2017-07-08 00:59:46 +02:00
}
2017-09-30 02:58:17 +02:00
} else if j . deviceProperties . System_modules == nil {
ctx . PropertyErrorf ( "no_standard_libs" ,
"system_modules is required to be set when no_standard_libs is true, did you mean no_framework_libs?" )
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
} else if * j . deviceProperties . System_modules != "none" {
2018-08-29 23:10:52 +02:00
ctx . AddVariationDependencies ( nil , systemModulesTag , * j . deviceProperties . System_modules )
2015-03-31 02:20:39 +02:00
}
2018-09-04 15:26:19 +02:00
if ( ctx . ModuleName ( ) == "framework" ) || ( ctx . ModuleName ( ) == "framework-annotation-proc" ) {
2018-08-29 23:10:52 +02:00
ctx . AddVariationDependencies ( nil , frameworkResTag , "framework-res" )
2017-11-23 01:20:45 +01:00
}
2018-02-23 20:18:47 +01:00
if ctx . ModuleName ( ) == "android_stubs_current" ||
ctx . ModuleName ( ) == "android_system_stubs_current" ||
2018-08-07 22:41:10 +02:00
ctx . ModuleName ( ) == "android_test_stubs_current" {
2018-08-29 23:10:52 +02:00
ctx . AddVariationDependencies ( nil , frameworkApkTag , "framework-res" )
2018-02-23 20:18:47 +01:00
}
2015-03-31 02:20:39 +02:00
}
2017-09-30 02:58:17 +02:00
2018-08-29 23:10:52 +02:00
ctx . AddVariationDependencies ( nil , libTag , j . properties . Libs ... )
ctx . AddVariationDependencies ( nil , staticLibTag , j . properties . Static_libs ... )
2018-07-02 17:34:51 +02:00
ctx . AddFarVariationDependencies ( [ ] blueprint . Variation {
2018-07-23 06:18:45 +02:00
{ Mutator : "arch" , Variation : ctx . Config ( ) . BuildOsCommonVariant } ,
2018-07-02 17:34:51 +02:00
} , annoTag , j . properties . Annotation_processors ... )
2018-10-03 07:03:40 +02:00
2017-08-30 22:27:57 +02:00
android . ExtractSourcesDeps ( ctx , j . properties . Srcs )
2018-02-09 22:03:53 +01:00
android . ExtractSourcesDeps ( ctx , j . properties . Exclude_srcs )
2017-09-28 02:42:05 +02:00
android . ExtractSourcesDeps ( ctx , j . properties . Java_resources )
2017-12-12 01:29:02 +01:00
android . ExtractSourceDeps ( ctx , j . properties . Manifest )
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
2018-08-29 23:10:52 +02:00
ctx . AddVariationDependencies ( nil , kotlinStdlibTag , "kotlin-stdlib" )
2017-08-15 22:34:18 +02:00
}
2018-01-04 00:06:47 +01:00
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
}
2017-11-02 21:28:15 +01:00
func shardPaths ( paths android . Paths , shardSize int ) [ ] android . Paths {
ret := make ( [ ] android . Paths , 0 , ( len ( paths ) + shardSize - 1 ) / shardSize )
for len ( paths ) > shardSize {
ret = append ( ret , paths [ 0 : shardSize ] )
paths = paths [ shardSize : ]
}
if len ( paths ) > 0 {
ret = append ( ret , paths )
}
return ret
}
2017-09-20 21:59:05 +02:00
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 ,
2016-05-19 00:37:25 +02:00
aidlIncludeDirs android . Paths ) [ ] string {
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
2018-07-26 21:55:08 +02:00
flags := [ ] string { "-b" }
2015-09-24 00:26:20 +02:00
if aidlPreprocess . Valid ( ) {
flags = append ( flags , "-p" + aidlPreprocess . String ( ) )
2015-04-08 22:03:43 +02:00
} else {
2016-05-19 00:37:25 +02:00
flags = append ( flags , android . JoinWithPrefix ( aidlIncludeDirs . Strings ( ) , "-I" ) )
2015-04-08 22:03:43 +02:00
}
2016-05-19 00:37:25 +02:00
flags = append ( flags , android . JoinWithPrefix ( j . exportAidlIncludeDirs . Strings ( ) , "-I" ) )
2017-11-14 22:12:14 +01:00
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" )
}
2015-04-13 22:53:40 +02:00
return flags
2015-04-08 22:03:43 +02:00
}
2017-09-06 22:41:06 +02:00
type deps struct {
2018-01-11 01:06:12 +01:00
classpath classpath
bootClasspath classpath
2018-06-20 07:43:34 +02:00
processorPath classpath
2017-09-15 22:00:47 +02:00
staticJars android . Paths
2017-10-19 22:06:22 +02:00
staticHeaderJars android . Paths
2018-08-16 05:40:52 +02:00
staticResourceJars android . Paths
2017-09-15 22:00:47 +02:00
aidlIncludeDirs android . Paths
2018-02-23 20:18:47 +01:00
srcs android . Paths
2017-10-17 03:07:29 +02:00
srcJars android . Paths
2017-09-30 02:58:17 +02:00
systemModules android . Path
2017-09-15 22:00:47 +02:00
aidlPreprocess android . OptionalPath
2017-08-15 22:34:18 +02:00
kotlinStdlib android . Paths
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 (
javaCore linkType = iota
javaSdk
javaSystem
javaPlatform
)
2018-10-20 09:33:17 +02:00
func getLinkType ( m * Module , name string ) ( ret linkType , stubs bool ) {
2018-06-26 00:48:06 +02:00
ver := m . sdkVersion ( )
2018-03-26 23:42:44 +02:00
switch {
2018-10-20 09:33:17 +02:00
case name == "core.current.stubs" || name == "core.platform.api.stubs" ||
name == "stub-annotations" || name == "private-stub-annotations-jar" ||
name == "core-lambda-stubs" :
return javaCore , true
2018-10-18 20:48:58 +02:00
case ver == "core_current" :
2018-10-20 09:33:17 +02:00
return javaCore , false
case name == "android_system_stubs_current" :
return javaSystem , true
case strings . HasPrefix ( ver , "system_" ) :
return javaSystem , false
case name == "android_test_stubs_current" :
return javaSystem , true
case strings . HasPrefix ( ver , "test_" ) :
return javaPlatform , false
case name == "android_stubs_current" :
return javaSdk , true
case ver == "current" :
return javaSdk , false
2018-03-26 23:42:44 +02:00
case ver == "" :
2018-10-20 09:33:17 +02:00
return javaPlatform , false
2018-03-26 23:42:44 +02:00
default :
if _ , err := strconv . Atoi ( ver ) ; err != nil {
panic ( fmt . Errorf ( "expected sdk_version to be a number, got %q" , ver ) )
}
2018-10-20 09:33:17 +02:00
return javaSdk , false
2018-03-05 09:44:10 +01:00
}
}
2018-01-30 16:20:13 +01:00
func checkLinkType ( ctx android . ModuleContext , from * Module , to * Library , tag dependencyTag ) {
2018-03-26 23:42:44 +02:00
if ctx . Host ( ) {
return
}
2018-10-20 09:33:17 +02:00
myLinkType , stubs := getLinkType ( from , ctx . ModuleName ( ) )
if stubs {
return
}
otherLinkType , _ := getLinkType ( & to . Module , ctx . OtherModuleName ( to ) )
2018-03-05 09:44:10 +01:00
commonMessage := "Adjust sdk_version: property of the source or target module so that target module is built with the same or smaller API set than the source."
switch myLinkType {
case javaCore :
if otherLinkType != javaCore {
ctx . ModuleErrorf ( "compiles against core Java API, but dependency %q is compiling against non-core Java APIs." + commonMessage ,
ctx . OtherModuleName ( to ) )
}
break
case javaSdk :
if otherLinkType != javaCore && otherLinkType != javaSdk {
ctx . ModuleErrorf ( "compiles against Android API, but dependency %q is compiling against non-public Android API." + commonMessage ,
ctx . OtherModuleName ( to ) )
}
break
case javaSystem :
if otherLinkType == javaPlatform {
ctx . ModuleErrorf ( "compiles against system API, but dependency %q is compiling against private API." + commonMessage ,
2018-01-30 16:20:13 +01:00
ctx . OtherModuleName ( to ) )
}
2018-03-05 09:44:10 +01:00
break
case javaPlatform :
// no restriction on link-type
break
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 {
2018-05-29 23:44:55 +02:00
ctx . AddMissingDependencies ( sdkDep . modules )
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 ... )
2018-03-06 22:11:51 +01:00
deps . aidlIncludeDirs = append ( deps . aidlIncludeDirs , sdkDep . aidl )
}
2017-09-19 02:41:52 +02:00
}
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 )
2018-10-03 07:03:40 +02:00
if _ , ok := tag . ( * jniDependencyTag ) ; ok {
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
}
2018-01-30 16:20:13 +01:00
if to , ok := module . ( * Library ) ; ok {
2018-03-28 23:58:31 +02:00
switch tag {
case bootClasspathTag , libTag , staticLibTag :
checkLinkType ( ctx , j , to , tag . ( dependencyTag ) )
}
2018-01-30 16:20:13 +01:00
}
2017-12-05 18:28:08 +01:00
switch dep := module . ( type ) {
case Dependency :
switch tag {
case bootClasspathTag :
deps . bootClasspath = append ( deps . bootClasspath , dep . HeaderJars ( ) ... )
2018-10-16 01:18:06 +02:00
case libTag , instrumentationForTag :
2017-12-05 18:28:08 +01:00
deps . classpath = append ( deps . classpath , dep . HeaderJars ( ) ... )
2018-05-28 11:02:19 +02:00
// sdk lib names from dependencies are re-exported
j . exportedSdkLibs = append ( j . exportedSdkLibs , dep . ExportedSdkLibs ( ) ... )
2017-12-05 18:28:08 +01:00
case staticLibTag :
deps . classpath = append ( deps . classpath , dep . HeaderJars ( ) ... )
deps . staticJars = append ( deps . staticJars , dep . ImplementationJars ( ) ... )
deps . staticHeaderJars = append ( deps . staticHeaderJars , dep . HeaderJars ( ) ... )
2018-08-16 05:40:52 +02:00
deps . staticResourceJars = append ( deps . staticResourceJars , dep . ResourceJars ( ) ... )
2018-05-28 11:02:19 +02:00
// sdk lib names from dependencies are re-exported
j . exportedSdkLibs = append ( j . exportedSdkLibs , dep . ExportedSdkLibs ( ) ... )
2018-06-20 07:43:34 +02:00
case annoTag :
2018-08-16 05:40:52 +02:00
deps . processorPath = append ( deps . processorPath , dep . ImplementationAndResourcesJars ( ) ... )
2017-12-05 18:28:08 +01:00
case frameworkResTag :
2018-09-04 15:26:19 +02:00
if ( ctx . ModuleName ( ) == "framework" ) || ( ctx . ModuleName ( ) == "framework-annotation-proc" ) {
2017-12-05 18:28:08 +01:00
// framework.jar has a one-off dependency on the R.java and Manifest.java files
// generated by framework-res.apk
deps . srcJars = append ( deps . srcJars , dep . ( * AndroidApp ) . aaptSrcJar )
}
2018-02-23 20:18:47 +01:00
case frameworkApkTag :
if ctx . ModuleName ( ) == "android_stubs_current" ||
ctx . ModuleName ( ) == "android_system_stubs_current" ||
2018-08-07 22:41:10 +02:00
ctx . ModuleName ( ) == "android_test_stubs_current" {
2018-02-23 20:18:47 +01:00
// framework stubs.jar need to depend on framework-res.apk, in order to pull the
// resource files out of there for aapt.
//
// Normally the package rule runs aapt, which includes the resource,
// but we're not running that in our package rule so just copy in the
// resource files here.
2018-08-16 05:40:52 +02:00
deps . staticResourceJars = append ( deps . staticResourceJars , dep . ( * AndroidApp ) . exportPackage )
2018-02-23 20:18:47 +01:00
}
2017-12-05 18:28:08 +01:00
case kotlinStdlibTag :
deps . kotlinStdlib = dep . HeaderJars ( )
}
deps . aidlIncludeDirs = append ( deps . aidlIncludeDirs , dep . AidlIncludeDirs ( ) ... )
2018-04-10 06:07:10 +02:00
case SdkLibraryDependency :
switch tag {
case libTag :
2018-10-20 09:33:17 +02:00
linkType , _ := getLinkType ( j , ctx . ModuleName ( ) )
deps . classpath = append ( deps . classpath , dep . HeaderJars ( linkType ) ... )
2018-05-28 11:02:19 +02:00
// names of sdk libs that are directly depended are exported
j . exportedSdkLibs = append ( j . exportedSdkLibs , otherName )
2018-04-10 06:07:10 +02:00
default :
ctx . ModuleErrorf ( "dependency on java_sdk_library %q can only be in libs" , otherName )
}
2017-12-05 18:28:08 +01:00
case android . SourceFileProducer :
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 ( ) ... )
case android . DefaultsDepTag , android . SourceDepTag :
// Nothing to do
default :
ctx . ModuleErrorf ( "dependency on genrule %q may only be in srcs, libs, or static_libs" , otherName )
}
default :
2017-07-07 23:47:12 +02:00
switch tag {
case android . DefaultsDepTag , android . SourceDepTag :
2017-09-14 00:46:47 +02:00
// Nothing to do
2017-09-30 02:58:17 +02:00
case systemModulesTag :
if deps . systemModules != nil {
panic ( "Found two system module dependencies" )
}
sm := module . ( * SystemModules )
if sm . outputFile == nil {
panic ( "Missing directory for system module dependency" )
}
deps . systemModules = sm . outputFile
2017-07-07 23:47:12 +02:00
default :
ctx . ModuleErrorf ( "depends on non-java module %q" , otherName )
}
}
2015-03-31 02:20:39 +02:00
} )
2018-05-28 11:02:19 +02:00
j . exportedSdkLibs = android . FirstUniqueStrings ( j . exportedSdkLibs )
2017-09-06 22:41:06 +02:00
return deps
2015-03-31 02:20:39 +02:00
}
2018-06-26 00:48:06 +02:00
func getJavaVersion ( ctx android . ModuleContext , javaVersion string , sdkContext sdkContext ) string {
2018-04-18 02:38:36 +02:00
var ret string
2018-06-26 00:48:06 +02:00
sdk , err := sdkVersionToNumber ( ctx , sdkContext . sdkVersion ( ) )
if err != nil {
ctx . PropertyErrorf ( "sdk_version" , "%s" , err )
}
2018-04-18 02:38:36 +02:00
if javaVersion != "" {
ret = javaVersion
} else if ctx . Device ( ) && sdk <= 23 {
ret = "1.7"
2018-10-03 11:05:04 +02:00
} else if ctx . Device ( ) && sdk <= 28 || ! ctx . Config ( ) . TargetOpenJDK9 ( ) {
2018-04-18 02:38:36 +02:00
ret = "1.8"
2018-06-26 00:48:06 +02:00
} else if ctx . Device ( ) && sdkContext . sdkVersion ( ) != "" && sdk == android . FutureApiLevel {
2018-04-18 02:38:36 +02:00
// TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
ret = "1.8"
} else {
ret = "1.9"
}
return ret
}
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 ) )
2017-10-19 22:06:22 +02:00
// javac flags.
2015-04-13 22:53:40 +02:00
javacFlags := j . properties . Javacflags
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
if flags . javaVersion == "1.9" {
2017-09-30 02:58:17 +02:00
javacFlags = append ( javacFlags , j . properties . Openjdk9 . Javacflags ... )
2017-10-19 22:06:22 +02:00
}
2017-11-29 09:27:14 +01:00
if ctx . Config ( ) . MinimizeJavaDebugInfo ( ) {
2017-10-31 21:55:34 +01:00
// Override the -g flag passed globally to remove local variable debug info to reduce
// disk and memory usage.
javacFlags = append ( javacFlags , "-g:source,lines" )
}
2017-08-08 22:17:59 +02:00
2018-06-20 07:47:35 +02:00
if ctx . Config ( ) . RunErrorProne ( ) {
if config . ErrorProneClasspath == nil {
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 ... )
2018-06-20 07:43:34 +02:00
flags . processorPath = append ( flags . processorPath , deps . processorPath ... )
2018-01-03 03:14:25 +01:00
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
if len ( flags . bootClasspath ) == 0 && ctx . Host ( ) && flags . javaVersion != "1.9" &&
2018-01-03 03:14:25 +01:00
! Bool ( j . properties . No_standard_libs ) &&
inList ( flags . javaVersion , [ ] string { "1.6" , "1.7" , "1.8" } ) {
// 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
}
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
if j . properties . Patch_module != nil && flags . javaVersion == "1.9" {
2018-08-16 05:21:55 +02:00
patchClasspath := ".:" + flags . classpath . FormJavaClassPath ( "" )
javacFlags = append ( javacFlags , "--patch-module=" + String ( j . properties . Patch_module ) + "=" + patchClasspath )
}
2017-10-19 22:06:22 +02:00
// systemModules
2017-09-30 02:58:17 +02:00
if deps . systemModules != nil {
flags . systemModules = append ( flags . systemModules , deps . systemModules )
}
2017-10-19 22:06:22 +02:00
// aidl flags.
2017-09-06 22:41:06 +02:00
aidlFlags := j . aidlFlags ( ctx , deps . aidlPreprocess , deps . aidlIncludeDirs )
2015-04-13 22:53:40 +02:00
if len ( aidlFlags ) > 0 {
2017-10-19 22:06:22 +02:00
// optimization.
2015-04-13 22:53:40 +02:00
ctx . Variable ( pctx , "aidlFlags" , strings . Join ( aidlFlags , " " ) )
flags . aidlFlags = "$aidlFlags"
2015-03-31 02:20:39 +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
2017-11-23 01:19:37 +01:00
func ( j * Module ) compile ( ctx android . ModuleContext , extraSrcJars ... android . Path ) {
2017-10-19 22:06:22 +02:00
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 )
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
if flags . javaVersion == "1.9" {
2017-10-19 22:06:22 +02:00
j . properties . Srcs = append ( j . properties . Srcs , j . properties . Openjdk9 . Srcs ... )
}
srcFiles := ctx . ExpandSources ( 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
}
2017-11-16 08:01:59 +01:00
srcFiles = j . genSources ( ctx , srcFiles , flags )
srcJars := srcFiles . FilterByExt ( ".srcjar" )
2017-10-17 03:07:29 +02:00
srcJars = append ( srcJars , deps . srcJars ... )
2017-11-23 01:19:37 +01:00
srcJars = append ( srcJars , extraSrcJars ... )
2015-04-16 23:09:14 +02:00
2018-08-16 00:35:38 +02:00
// Collect source files from compiledJavaSrcs, compiledSrcJars and filter out Exclude_srcs
// that IDEInfo struct will use
j . expandIDEInfoCompiledSrcs = append ( j . expandIDEInfoCompiledSrcs , srcFiles . Strings ( ) ... )
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 )
}
}
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 )
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" ) ... )
2018-03-05 17:06:42 +01:00
flags . kotlincClasspath = append ( flags . kotlincClasspath , deps . bootClasspath ... )
2017-08-15 22:34:18 +02:00
flags . kotlincClasspath = append ( flags . kotlincClasspath , deps . kotlinStdlib ... )
flags . kotlincClasspath = append ( flags . kotlincClasspath , deps . classpath ... )
2017-10-18 23:44:18 +02:00
kotlinJar := android . PathForModuleOut ( ctx , "kotlin" , jarName )
2018-02-13 15:32:54 +01:00
TransformKotlinToClasses ( ctx , kotlinJar , kotlinSrcFiles , srcJars , flags )
2017-08-15 22:34:18 +02:00
if ctx . Failed ( ) {
return
}
// Make javac rule depend on the kotlinc rule
2018-06-06 02:22:57 +02:00
flags . classpath = append ( flags . classpath , deps . kotlinStdlib ... )
2017-08-15 22:34:18 +02:00
flags . classpath = append ( flags . classpath , kotlinJar )
2018-03-08 14:21:55 +01:00
2017-08-15 22:34:18 +02:00
// Jar kotlin classes into the final jar after javac
2018-08-27 21:37:09 +02:00
kotlinJars = append ( kotlinJars , kotlinJar )
2018-08-28 00:42:25 +02:00
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
2017-11-02 21:28:15 +01:00
enable_sharding := false
2017-11-29 09:27:14 +01:00
if ctx . Device ( ) && ! ctx . Config ( ) . IsEnvFalse ( "TURBINE_ENABLED" ) {
2017-11-02 21:28:15 +01:00
if j . properties . Javac_shard_size != nil && * ( j . properties . Javac_shard_size ) > 0 {
enable_sharding = true
if len ( j . properties . Annotation_processors ) != 0 ||
len ( j . properties . Annotation_processor_classes ) != 0 {
ctx . PropertyErrorf ( "javac_shard_size" ,
"%q cannot be set when annotation processors are enabled." ,
j . properties . Javac_shard_size )
}
}
2018-08-27 21:37:09 +02:00
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 )
}
2017-11-02 21:28:15 +01:00
if enable_sharding {
2018-01-11 01:06:12 +01:00
flags . classpath = append ( flags . classpath , j . headerJarFile )
2017-11-02 21:28:15 +01:00
shardSize := int ( * ( j . properties . Javac_shard_size ) )
var shardSrcs [ ] android . Paths
if len ( uniqueSrcFiles ) > 0 {
shardSrcs = shardPaths ( uniqueSrcFiles , shardSize )
for idx , shardSrc := range shardSrcs {
classes := android . PathForModuleOut ( ctx , "javac" , jarName + strconv . Itoa ( idx ) )
TransformJavaToClasses ( ctx , classes , idx , shardSrc , nil , flags , extraJarDeps )
jars = append ( jars , classes )
}
}
if len ( srcJars ) > 0 {
classes := android . PathForModuleOut ( ctx , "javac" , jarName + strconv . Itoa ( len ( shardSrcs ) ) )
TransformJavaToClasses ( ctx , classes , len ( shardSrcs ) , nil , srcJars , flags , extraJarDeps )
jars = append ( jars , classes )
}
} else {
classes := android . PathForModuleOut ( ctx , "javac" , jarName )
TransformJavaToClasses ( ctx , classes , - 1 , uniqueSrcFiles , srcJars , flags , extraJarDeps )
jars = append ( jars , classes )
}
2017-09-28 02:39:56 +02:00
if ctx . Failed ( ) {
return
}
2015-03-31 02:20:39 +02:00
}
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 )
var resArgs [ ] string
var resDeps android . Paths
resArgs = append ( resArgs , dirArgs ... )
resDeps = append ( resDeps , dirDeps ... )
resArgs = append ( resArgs , fileArgs ... )
resDeps = append ( resDeps , fileDeps ... )
2018-04-11 01:15:18 +02:00
if Bool ( j . properties . Include_srcs ) {
2017-10-03 22:14:07 +02:00
srcArgs , srcDeps := SourceFilesToJarArgs ( ctx , j . properties . Srcs , j . properties . Exclude_srcs )
2017-09-28 02:42:05 +02:00
resArgs = append ( resArgs , srcArgs ... )
resDeps = append ( resDeps , srcDeps ... )
}
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
2018-08-16 05:40:52 +02:00
if len ( deps . staticResourceJars ) > 0 {
var jars android . Paths
if j . resourceJar != nil {
jars = append ( jars , j . resourceJar )
}
jars = append ( jars , deps . staticResourceJars ... )
combinedJar := android . PathForModuleOut ( ctx , "res-combined" , jarName )
TransformJarsToJar ( ctx , combinedJar , "for resources" , jars , android . OptionalPath { } ,
false , nil , nil )
j . resourceJar = combinedJar
2015-03-31 02:20:39 +02:00
}
2015-04-04 01:54:17 +02:00
2017-09-06 22:41:06 +02:00
jars = append ( jars , deps . staticJars ... )
2018-08-16 05:40:52 +02:00
jars = append ( jars , deps . staticResourceJars ... )
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 {
2017-12-12 01:29:02 +01:00
manifest = android . OptionalPathForPath ( ctx . ExpandSource ( * j . properties . Manifest , "manifest" ) )
}
2017-09-13 07:50:46 +02:00
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.
2018-08-15 20:19:12 +02:00
var outputFile android . ModuleOutPath
2017-10-17 02:09:48 +02:00
if len ( jars ) == 1 && ! manifest . Valid ( ) {
2018-08-15 20:19:12 +02:00
if moduleOutPath , ok := jars [ 0 ] . ( android . ModuleOutPath ) ; ok {
// Optimization: skip the combine step if 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.
outputFile = moduleOutPath
} else {
combinedJar := android . PathForModuleOut ( ctx , "combined" , jarName )
ctx . Build ( pctx , android . BuildParams {
Rule : android . Cp ,
Input : jars [ 0 ] ,
Output : combinedJar ,
} )
outputFile = combinedJar
}
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 )
2017-10-17 02:09:48 +02:00
outputFile = combinedJar
}
2017-08-30 23:24:55 +02:00
2018-08-16 05:40:52 +02:00
// jarjar implementation jar if necessary
2015-09-24 00:26:20 +02:00
if j . properties . Jarjar_rules != nil {
2016-05-19 00:37:25 +02:00
jarjar_rules := android . PathForModuleSrc ( ctx , * j . properties . Jarjar_rules )
2017-09-28 03:03:17 +02:00
// Transform classes.jar into classes-jarjar.jar
2017-10-18 23:44:18 +02:00
jarjarFile := android . PathForModuleOut ( ctx , "jarjar" , jarName )
2017-10-17 02:09:48 +02:00
TransformJarJar ( ctx , jarjarFile , outputFile , jarjar_rules )
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 )
TransformJarJar ( ctx , resourceJarJarFile , j . resourceJar , jarjar_rules )
j . resourceJar = resourceJarJarFile
}
2015-04-04 01:54:17 +02:00
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
2017-11-29 09:27:14 +01:00
if ctx . Config ( ) . IsEnvTrue ( "EMMA_INSTRUMENT_FRAMEWORK" ) {
2017-11-22 22:49:43 +01:00
if inList ( ctx . ModuleName ( ) , config . InstrumentFrameworkModules ) {
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 {
jars := android . Paths { implementationAndResourcesJar , j . resourceJar }
combinedJar := android . PathForModuleOut ( ctx , "withres" , jarName )
TransformJarsToJar ( ctx , combinedJar , "for resources" , jars , android . OptionalPath { } ,
false , nil , nil )
implementationAndResourcesJar = combinedJar
}
j . implementationAndResourcesJar = implementationAndResourcesJar
2018-06-27 02:59:05 +02:00
if ctx . Device ( ) && ( Bool ( j . properties . Installable ) || Bool ( j . deviceProperties . Compile_dex ) ) {
2018-08-15 20:19:12 +02:00
var dexOutputFile android . ModuleOutPath
2018-06-27 11:27:45 +02:00
dexOutputFile = j . compileDex ( ctx , flags , outputFile , jarName )
2017-10-19 22:06:22 +02:00
if ctx . Failed ( ) {
return
2015-03-31 02:20:39 +02:00
}
2018-08-16 05:40:52 +02: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 )
TransformJarsToJar ( ctx , combinedJar , "for dex resources" , jars , android . OptionalPath { } ,
false , nil , nil )
dexOutputFile = combinedJar
}
j . dexJarFile = dexOutputFile
2018-11-12 19:13:39 +01:00
dexOutputFile = j . dexpreopt ( ctx , dexOutputFile )
j . maybeStrippedDexJarFile = dexOutputFile
2018-08-15 20:19:12 +02:00
outputFile = dexOutputFile
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
2017-10-19 22:06:22 +02:00
ctx . CheckbuildFile ( outputFile )
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
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 ,
2018-08-27 21:37:09 +02:00
deps deps , flags javaBuilderFlags , jarName string , extraJars android . Paths ) 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 ( ) {
return 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.
var headerJar android . Path
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 { } ,
false , nil , [ ] string { "META-INF" } )
2017-10-24 03:12:27 +02:00
headerJar = combinedJar
2017-10-19 22:06:22 +02:00
if j . properties . Jarjar_rules != nil {
jarjar_rules := android . PathForModuleSrc ( ctx , * j . properties . Jarjar_rules )
// Transform classes.jar into classes-jarjar.jar
jarjarFile := android . PathForModuleOut ( ctx , "turbine-jarjar" , jarName )
TransformJarJar ( ctx , jarjarFile , headerJar , jarjar_rules )
headerJar = jarjarFile
if ctx . Failed ( ) {
return 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
2017-10-19 22:06:22 +02:00
return headerJar
}
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 ,
2018-08-15 20:19:12 +02:00
classesJar android . Path , jarName string ) android . ModuleOutPath {
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 )
2017-11-22 22:49:43 +01:00
instrumentedJar := android . PathForModuleOut ( ctx , "jacoco" , jarName )
jacocoInstrumentJar ( ctx , instrumentedJar , jacocoReportClassesFile , classesJar , specs )
j . jacocoReportClassesFile = jacocoReportClassesFile
return instrumentedJar
}
2017-07-20 00:53:04 +02:00
var _ Dependency = ( * Library ) ( nil )
2015-03-31 02:20:39 +02:00
2017-10-19 22:06:22 +02:00
func ( j * Module ) HeaderJars ( ) android . Paths {
return android . Paths { j . headerJarFile }
}
func ( j * Module ) ImplementationJars ( ) android . Paths {
return android . Paths { j . implementationJarFile }
2015-03-31 02:20:39 +02:00
}
2018-08-16 05:40:52 +02:00
func ( j * Module ) ResourceJars ( ) android . Paths {
if j . resourceJar == nil {
return nil
}
return android . Paths { j . resourceJar }
}
func ( j * Module ) ImplementationAndResourcesJars ( ) android . Paths {
return android . Paths { j . implementationAndResourcesJar }
}
2017-06-23 01:51:17 +02:00
func ( j * Module ) AidlIncludeDirs ( ) android . Paths {
2015-04-08 22:03:43 +02:00
return j . exportAidlIncludeDirs
}
2018-05-28 11:02:19 +02:00
func ( j * Module ) ExportedSdkLibs ( ) [ ] string {
return j . exportedSdkLibs
}
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 ... )
dpInfo . Aidl_include_dirs = append ( dpInfo . Aidl_include_dirs , j . deviceProperties . Aidl . Include_dirs ... )
if j . properties . Jarjar_rules != nil {
dpInfo . Jarjar_rules = append ( dpInfo . Jarjar_rules , * j . properties . Jarjar_rules )
}
}
func ( j * Module ) CompilerDeps ( ) [ ] string {
jdeps := [ ] string { }
jdeps = append ( jdeps , j . properties . Libs ... )
jdeps = append ( jdeps , j . properties . Static_libs ... )
return jdeps
}
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
2015-03-31 02:20:39 +02:00
}
2017-07-20 00:53:04 +02:00
func ( j * Library ) GenerateAndroidBuildActions ( ctx android . ModuleContext ) {
2018-11-12 19:13:39 +01:00
j . dexpreopter . installPath = android . PathForModuleInstall ( ctx , "framework" , ctx . ModuleName ( ) + ".jar" )
j . dexpreopter . isSDKLibrary = j . deviceProperties . IsSDKLibrary
2017-06-23 01:51:17 +02:00
j . compile ( ctx )
2015-04-16 23:09:14 +02:00
2018-06-27 02:59:05 +02:00
if Bool ( j . properties . Installable ) || ctx . Host ( ) {
2018-11-12 19:13:39 +01:00
if j . deviceProperties . UncompressDex {
alignedOutputFile := android . PathForModuleOut ( ctx , "aligned" , ctx . ModuleName ( ) + ".jar" )
TransformZipAlign ( ctx , alignedOutputFile , j . outputFile )
j . outputFile = alignedOutputFile
}
2017-09-01 01:45:16 +02:00
j . installFile = ctx . InstallFile ( android . PathForModuleInstall ( ctx , "framework" ) ,
ctx . ModuleName ( ) + ".jar" , j . outputFile )
}
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 )
}
2018-06-27 02:59:05 +02:00
func LibraryFactory ( ) android . Module {
module := & Library { }
2015-03-31 02:20:39 +02:00
2018-06-27 02:59:05 +02:00
module . AddProperties (
& module . Module . properties ,
& module . Module . deviceProperties ,
2018-11-12 19:13:39 +01:00
& module . Module . dexpreoptProperties ,
2018-06-27 02:59:05 +02:00
& module . Module . protoProperties )
2017-06-24 00:06:31 +02:00
2018-06-27 02:59:05 +02:00
InitJavaModule ( module , android . HostAndDeviceSupported )
return module
2015-03-31 02:20:39 +02:00
}
2017-07-20 00:53:04 +02:00
func LibraryHostFactory ( ) android . Module {
module := & Library { }
2015-03-31 02:20:39 +02:00
2017-09-20 21:59:05 +02:00
module . AddProperties (
& module . Module . properties ,
& module . Module . protoProperties )
2017-06-24 00:06:31 +02:00
2018-06-27 02:59:05 +02:00
module . Module . properties . Installable = proptools . BoolPtr ( true )
2017-07-07 23:35:50 +02: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
//
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.
Test_config * string ` android:"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.
Test_config_template * string ` android:"arch_variant" `
2018-08-11 01:06:24 +02:00
// list of files or filegroup modules that provide data that should be installed alongside
// the test
Data [ ] string
2018-04-10 03:40:24 +02:00
}
type Test struct {
Library
testProperties testProperties
2018-08-08 01:49:25 +02:00
testConfig android . Path
2018-08-11 01:06:24 +02:00
data android . Paths
2018-08-08 01:49:25 +02:00
}
func ( j * Test ) GenerateAndroidBuildActions ( ctx android . ModuleContext ) {
2018-09-19 11:21:28 +02:00
j . testConfig = tradefed . AutoGenJavaTestConfig ( ctx , j . testProperties . Test_config , j . testProperties . Test_config_template )
2018-08-11 01:06:24 +02:00
j . data = ctx . ExpandSources ( j . testProperties . Data , nil )
2018-08-08 01:49:25 +02:00
j . Library . GenerateAndroidBuildActions ( ctx )
2018-04-10 03:40:24 +02:00
}
func ( j * Test ) DepsMutator ( ctx android . BottomUpMutatorContext ) {
j . deps ( ctx )
2018-08-08 01:49:25 +02:00
android . ExtractSourceDeps ( ctx , j . testProperties . Test_config )
2018-09-19 11:21:28 +02:00
android . ExtractSourceDeps ( ctx , j . testProperties . Test_config_template )
2018-08-11 01:06:24 +02:00
android . ExtractSourcesDeps ( ctx , j . testProperties . Data )
2018-04-10 03:40:24 +02:00
}
func TestFactory ( ) android . Module {
module := & Test { }
module . AddProperties (
& module . Module . properties ,
& module . Module . deviceProperties ,
2018-11-12 19:13:39 +01:00
& module . Module . dexpreoptProperties ,
2018-04-10 03:40:24 +02:00
& module . Module . protoProperties ,
& module . testProperties )
2018-06-27 02:59:05 +02:00
module . Module . properties . Installable = proptools . BoolPtr ( true )
2018-04-10 03:40:24 +02:00
InitJavaModule ( module , android . HostAndDeviceSupported )
return module
}
func TestHostFactory ( ) android . Module {
module := & Test { }
module . AddProperties (
& module . Module . properties ,
& module . Module . protoProperties ,
& module . testProperties )
2018-06-27 02:59:05 +02:00
module . Module . properties . Installable = proptools . BoolPtr ( true )
2018-04-10 03:40:24 +02:00
InitJavaModule ( module , android . HostSupported )
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
2017-11-09 06:20:04 +01:00
Wrapper * string
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
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
2017-08-11 02:09:43 +02:00
binaryFile android . OutputPath
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 {
j . wrapperFile = ctx . ExpandSource ( * j . binaryProperties . Wrapper , "wrapper" )
2017-12-05 22:42:45 +01:00
} else {
j . wrapperFile = android . PathForSource ( ctx , "build/soong/scripts/jar-wrapper.sh" )
}
// Depend on the installed jar so that the wrapper doesn't get executed by
// another build rule before the jar has been installed.
jarFile := ctx . PrimaryModule ( ) . ( * Binary ) . installFile
j . binaryFile = ctx . InstallExecutable ( android . PathForModuleInstall ( ctx , "bin" ) ,
ctx . ModuleName ( ) , j . wrapperFile , jarFile )
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 ) {
2017-12-05 22:42:45 +01:00
if ctx . Arch ( ) . ArchType == android . Common {
j . deps ( ctx )
2017-12-09 04:12:36 +01:00
} else {
2017-12-12 01:29:02 +01:00
android . ExtractSourceDeps ( ctx , j . binaryProperties . Wrapper )
2017-12-05 22:42:45 +01:00
}
2017-06-23 01:51:17 +02:00
}
2017-07-20 00:53:04 +02:00
func BinaryFactory ( ) android . Module {
module := & Binary { }
2015-03-31 02:20:39 +02:00
2017-06-24 00:06:31 +02:00
module . AddProperties (
2017-06-23 02:01:52 +02:00
& module . Module . properties ,
& module . Module . deviceProperties ,
2018-11-12 19:13:39 +01:00
& module . Module . dexpreoptProperties ,
2017-09-20 21:59:05 +02:00
& module . Module . protoProperties ,
2017-06-23 02:01:52 +02:00
& 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
}
2017-07-20 00:53:04 +02:00
func BinaryHostFactory ( ) android . Module {
module := & Binary { }
2015-03-31 02:20:39 +02:00
2017-06-24 00:06:31 +02:00
module . AddProperties (
2017-06-23 02:01:52 +02:00
& module . Module . properties ,
2017-09-20 21:59:05 +02:00
& module . Module . protoProperties ,
2017-06-23 02:01:52 +02:00
& 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 {
Jars [ ] string
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.
Jetifier_enabled * bool
2017-08-02 20:05:49 +02:00
}
type Import struct {
2016-05-19 00:37:25 +02:00
android . ModuleBase
2018-10-02 22:53:33 +02:00
android . DefaultableModuleBase
2017-07-07 23:47:12 +02:00
prebuilt android . Prebuilt
2015-03-31 02:20:39 +02:00
2017-08-02 20:05:49 +02:00
properties ImportProperties
2017-08-30 23:24:55 +02:00
combinedClasspathFile android . Path
2018-05-28 11:02:19 +02:00
exportedSdkLibs [ ] string
2015-03-31 02:20:39 +02:00
}
2018-06-26 00:48:06 +02:00
func ( j * Import ) sdkVersion ( ) string {
return String ( j . properties . Sdk_version )
}
func ( j * Import ) minSdkVersion ( ) string {
return j . sdkVersion ( )
}
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 ( ) )
}
2017-08-02 20:05:49 +02:00
func ( j * Import ) DepsMutator ( ctx android . BottomUpMutatorContext ) {
2018-07-12 21:28:41 +02:00
android . ExtractSourcesDeps ( ctx , j . properties . Jars )
2018-08-29 23:10:52 +02:00
ctx . AddVariationDependencies ( nil , libTag , j . properties . Libs ... )
2016-10-12 23:38:15 +02:00
}
2017-08-02 20:05:49 +02:00
func ( j * Import ) GenerateAndroidBuildActions ( ctx android . ModuleContext ) {
2018-07-12 21:28:41 +02:00
jars := ctx . ExpandSources ( j . properties . Jars , nil )
2017-08-02 20:05:49 +02:00
2018-08-28 03:31:46 +02:00
jarName := ctx . ModuleName ( ) + ".jar"
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 )
2018-08-28 03:31:46 +02:00
if Bool ( j . properties . Jetifier_enabled ) {
inputFile := outputFile
outputFile = android . PathForModuleOut ( ctx , "jetifier" , jarName )
TransformJetifier ( ctx , outputFile , inputFile )
}
2017-10-17 02:09:48 +02:00
j . combinedClasspathFile = outputFile
2018-05-28 11:02:19 +02:00
ctx . VisitDirectDeps ( func ( module android . Module ) {
otherName := ctx . OtherModuleName ( module )
tag := ctx . OtherModuleDependencyTag ( module )
switch dep := module . ( type ) {
case Dependency :
switch tag {
case libTag , staticLibTag :
// sdk lib names from dependencies are re-exported
j . exportedSdkLibs = append ( j . exportedSdkLibs , dep . ExportedSdkLibs ( ) ... )
}
case SdkLibraryDependency :
switch tag {
case libTag :
// names of sdk libs that are directly depended are exported
j . exportedSdkLibs = append ( j . exportedSdkLibs , otherName )
}
}
} )
j . exportedSdkLibs = android . FirstUniqueStrings ( j . exportedSdkLibs )
2018-08-10 22:42:12 +02:00
if Bool ( j . properties . Installable ) {
ctx . InstallFile ( android . PathForModuleInstall ( ctx , "framework" ) ,
ctx . ModuleName ( ) + ".jar" , outputFile )
}
2015-03-31 02:20:39 +02:00
}
2017-08-02 20:05:49 +02:00
var _ Dependency = ( * Import ) ( nil )
2015-03-31 02:20:39 +02:00
2017-10-19 22:06:22 +02:00
func ( j * Import ) HeaderJars ( ) android . Paths {
2018-07-12 21:28:41 +02:00
return android . Paths { j . combinedClasspathFile }
2017-10-19 22:06:22 +02:00
}
func ( j * Import ) ImplementationJars ( ) android . Paths {
2018-07-12 21:28:41 +02:00
return android . Paths { j . combinedClasspathFile }
2015-03-31 02:20:39 +02:00
}
2018-08-16 05:40:52 +02:00
func ( j * Import ) ResourceJars ( ) android . Paths {
return nil
}
func ( j * Import ) ImplementationAndResourcesJars ( ) android . Paths {
return android . Paths { j . combinedClasspathFile }
}
2017-08-02 20:05:49 +02:00
func ( j * Import ) AidlIncludeDirs ( ) android . Paths {
2015-04-08 22:03:43 +02:00
return nil
}
2018-05-28 11:02:19 +02:00
func ( j * Import ) ExportedSdkLibs ( ) [ ] string {
return j . exportedSdkLibs
}
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
2017-08-02 20:05:49 +02:00
func ImportFactory ( ) android . Module {
module := & Import { }
2017-06-24 00:06:31 +02:00
2017-08-02 20:05:49 +02:00
module . AddProperties ( & module . properties )
android . InitPrebuiltModule ( module , & module . properties . Jars )
2018-10-02 22:53:33 +02:00
InitJavaModule ( module , android . HostAndDeviceSupported )
2017-06-24 00:06:31 +02:00
return module
2015-03-31 02:20:39 +02:00
}
2017-08-02 20:05:49 +02:00
func ImportFactoryHost ( ) android . Module {
module := & Import { }
module . AddProperties ( & module . properties )
android . InitPrebuiltModule ( module , & module . properties . Jars )
2018-10-02 22:53:33 +02:00
InitJavaModule ( module , android . HostSupported )
2017-08-02 20:05:49 +02:00
return module
}
2017-07-07 23:35:50 +02:00
//
// Defaults
//
type Defaults struct {
android . ModuleBase
android . DefaultsModuleBase
}
func ( * Defaults ) GenerateAndroidBuildActions ( ctx android . ModuleContext ) {
}
func ( d * Defaults ) DepsMutator ( ctx android . BottomUpMutatorContext ) {
}
func defaultsFactory ( ) android . Module {
return DefaultsFactory ( )
}
func DefaultsFactory ( props ... interface { } ) android . Module {
module := & Defaults { }
module . AddProperties ( props ... )
module . AddProperties (
& CompilerProperties { } ,
& CompilerDeviceProperties { } ,
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 { } ,
& ImportProperties { } ,
& AARImportProperties { } ,
& sdkLibraryProperties { } ,
2017-07-07 23:35:50 +02:00
)
android . InitDefaultsModule ( module )
return module
}
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