Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package java |
| 16 | |
| 17 | // This file contains the module types for compiling Java for Android, and converts the properties |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 18 | // into the flags and filenames necessary to pass to the Module. The final creation of the rules |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 19 | // is handled in builder.go |
| 20 | |
| 21 | import ( |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 22 | "fmt" |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 23 | "path/filepath" |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 24 | "strconv" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 25 | "strings" |
| 26 | |
| 27 | "github.com/google/blueprint" |
Colin Cross | 76b5f0c | 2017-08-29 16:02:06 -0700 | [diff] [blame] | 28 | "github.com/google/blueprint/proptools" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 29 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 30 | "android/soong/android" |
Colin Cross | 3e3e72d | 2017-06-22 17:20:19 -0700 | [diff] [blame] | 31 | "android/soong/java/config" |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 32 | "android/soong/tradefed" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 33 | ) |
| 34 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 35 | func init() { |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 36 | android.RegisterModuleType("java_defaults", defaultsFactory) |
| 37 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 38 | android.RegisterModuleType("java_library", LibraryFactory) |
| 39 | android.RegisterModuleType("java_library_static", LibraryFactory) |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 40 | android.RegisterModuleType("java_library_host", LibraryHostFactory) |
| 41 | android.RegisterModuleType("java_binary", BinaryFactory) |
| 42 | android.RegisterModuleType("java_binary_host", BinaryHostFactory) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 43 | android.RegisterModuleType("java_test", TestFactory) |
| 44 | android.RegisterModuleType("java_test_host", TestHostFactory) |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 45 | android.RegisterModuleType("java_import", ImportFactory) |
| 46 | android.RegisterModuleType("java_import_host", ImportFactoryHost) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 47 | |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 48 | android.RegisterSingletonType("logtags", LogtagsSingleton) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 51 | // TODO: |
| 52 | // Autogenerated files: |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 53 | // Renderscript |
| 54 | // Post-jar passes: |
| 55 | // Proguard |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 56 | // Rmtypedefs |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 57 | // DroidDoc |
| 58 | // Findbugs |
| 59 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 60 | type CompilerProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 61 | // list of source files used to compile the Java module. May be .java, .logtags, .proto, |
| 62 | // or .aidl files. |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 63 | Srcs []string `android:"arch_variant"` |
| 64 | |
| 65 | // list of source files that should not be used to build the Java module. |
| 66 | // This is most useful in the arch/multilib variants to remove non-common files |
| 67 | Exclude_srcs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 68 | |
| 69 | // list of directories containing Java resources |
Colin Cross | 86a63ff | 2017-09-27 17:33:10 -0700 | [diff] [blame] | 70 | Java_resource_dirs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 71 | |
Colin Cross | 86a63ff | 2017-09-27 17:33:10 -0700 | [diff] [blame] | 72 | // list of directories that should be excluded from java_resource_dirs |
| 73 | Exclude_java_resource_dirs []string `android:"arch_variant"` |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 74 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 75 | // list of files to use as Java resources |
| 76 | Java_resources []string `android:"arch_variant"` |
| 77 | |
Colin Cross | cedd476 | 2018-09-13 11:26:19 -0700 | [diff] [blame] | 78 | // list of files that should be excluded from java_resources and java_resource_dirs |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 79 | Exclude_java_resources []string `android:"arch_variant"` |
| 80 | |
Colin Cross | fa5eb23 | 2017-10-01 20:33:03 -0700 | [diff] [blame] | 81 | // don't build against the default libraries (bootclasspath, legacy-test, core-junit, |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 82 | // ext, and framework for device targets) |
Colin Cross | 76b5f0c | 2017-08-29 16:02:06 -0700 | [diff] [blame] | 83 | No_standard_libs *bool |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 84 | |
Colin Cross | fa5eb23 | 2017-10-01 20:33:03 -0700 | [diff] [blame] | 85 | // don't build against the framework libraries (legacy-test, core-junit, |
| 86 | // ext, and framework for device targets) |
| 87 | No_framework_libs *bool |
| 88 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 89 | // list of module-specific flags that will be used for javac compiles |
| 90 | Javacflags []string `android:"arch_variant"` |
| 91 | |
Zoran Jovanovic | 8736ce2 | 2018-08-21 17:10:29 +0200 | [diff] [blame] | 92 | // list of module-specific flags that will be used for kotlinc compiles |
| 93 | Kotlincflags []string `android:"arch_variant"` |
| 94 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 95 | // list of of java libraries that will be in the classpath |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 96 | Libs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 97 | |
| 98 | // list of java libraries that will be compiled into the resulting jar |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 99 | Static_libs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 100 | |
| 101 | // manifest file to be included in resulting jar |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 102 | Manifest *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 103 | |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 104 | // if not blank, run jarjar using the specified rules file |
Colin Cross | 975f9f7 | 2017-10-17 13:55:55 -0700 | [diff] [blame] | 105 | Jarjar_rules *string `android:"arch_variant"` |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 106 | |
| 107 | // If not blank, set the java version passed to javac as -source and -target |
| 108 | Java_version *string |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 109 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 110 | // If set to true, allow this module to be dexed and installed on devices. Has no |
| 111 | // effect on host modules, which are always considered installable. |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 112 | Installable *bool |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 113 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 114 | // If set to true, include sources used to compile the module in to the final jar |
| 115 | Include_srcs *bool |
| 116 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 117 | // List of modules to use as annotation processors |
| 118 | Annotation_processors []string |
| 119 | |
| 120 | // List of classes to pass to javac to use as annotation processors |
| 121 | Annotation_processor_classes []string |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 122 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 123 | // The number of Java source entries each Javac instance can process |
| 124 | Javac_shard_size *int64 |
| 125 | |
Nan Zhang | 5f8cb42 | 2018-02-06 10:34:32 -0800 | [diff] [blame] | 126 | // Add host jdk tools.jar to bootclasspath |
| 127 | Use_tools_jar *bool |
| 128 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 129 | Openjdk9 struct { |
| 130 | // List of source files that should only be used when passing -source 1.9 |
| 131 | Srcs []string |
| 132 | |
| 133 | // List of javac flags that should only be used when passing -source 1.9 |
| 134 | Javacflags []string |
| 135 | } |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 136 | |
Colin Cross | 8144008 | 2018-08-15 20:21:55 -0700 | [diff] [blame] | 137 | // When compiling language level 9+ .java code in packages that are part of |
| 138 | // a system module, patch_module names the module that your sources and |
| 139 | // dependencies should be patched into. The Android runtime currently |
| 140 | // doesn't implement the JEP 261 module system so this option is only |
| 141 | // supported at compile time. It should only be needed to compile tests in |
| 142 | // packages that exist in libcore and which are inconvenient to move |
| 143 | // elsewhere. |
Tobias Thierer | dda713d | 2018-09-19 16:16:19 +0100 | [diff] [blame] | 144 | Patch_module *string `android:"arch_variant"` |
Colin Cross | 8144008 | 2018-08-15 20:21:55 -0700 | [diff] [blame] | 145 | |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 146 | Jacoco struct { |
| 147 | // List of classes to include for instrumentation with jacoco to collect coverage |
| 148 | // information at runtime when building with coverage enabled. If unset defaults to all |
| 149 | // classes. |
| 150 | // Supports '*' as the last character of an entry in the list as a wildcard match. |
| 151 | // If preceded by '.' it matches all classes in the package and subpackages, otherwise |
| 152 | // it matches classes in the package that have the class name as a prefix. |
| 153 | Include_filter []string |
| 154 | |
| 155 | // List of classes to exclude from instrumentation with jacoco to collect coverage |
| 156 | // information at runtime when building with coverage enabled. Overrides classes selected |
| 157 | // by the include_filter property. |
| 158 | // Supports '*' as the last character of an entry in the list as a wildcard match. |
| 159 | // If preceded by '.' it matches all classes in the package and subpackages, otherwise |
| 160 | // it matches classes in the package that have the class name as a prefix. |
| 161 | Exclude_filter []string |
| 162 | } |
| 163 | |
Andreas Gampe | f3e5b55 | 2018-01-22 21:27:21 -0800 | [diff] [blame] | 164 | Errorprone struct { |
| 165 | // List of javac flags that should only be used when running errorprone. |
| 166 | Javacflags []string |
| 167 | } |
| 168 | |
Colin Cross | 0f2ee15 | 2017-12-14 15:22:43 -0800 | [diff] [blame] | 169 | Proto struct { |
| 170 | // List of extra options that will be passed to the proto generator. |
| 171 | Output_params []string |
| 172 | } |
| 173 | |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 174 | Instrument bool `blueprint:"mutated"` |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 177 | type CompilerDeviceProperties struct { |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 178 | // list of module-specific flags that will be used for dex compiles |
| 179 | Dxflags []string `android:"arch_variant"` |
| 180 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 181 | // if not blank, set to the version of the sdk to compile against. Defaults to compiling against the current |
| 182 | // sdk if platform_apis is not set. |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 183 | Sdk_version *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 184 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 185 | // if not blank, set the minimum version of the sdk that the compiled artifacts will run against. |
| 186 | // Defaults to sdk_version if not set. |
| 187 | Min_sdk_version *string |
| 188 | |
Dan Willemsen | 419290a | 2018-10-31 15:28:47 -0700 | [diff] [blame] | 189 | // if not blank, set the targetSdkVersion in the AndroidManifest.xml. |
| 190 | // Defaults to sdk_version if not set. |
| 191 | Target_sdk_version *string |
| 192 | |
Colin Cross | 6af2e49 | 2018-05-22 11:12:33 -0700 | [diff] [blame] | 193 | // if true, compile against the platform APIs instead of an SDK. |
| 194 | Platform_apis *bool |
| 195 | |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 196 | Aidl struct { |
| 197 | // Top level directories to pass to aidl tool |
| 198 | Include_dirs []string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 199 | |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 200 | // Directories rooted at the Android.bp file to pass to aidl tool |
| 201 | Local_include_dirs []string |
| 202 | |
| 203 | // directories that should be added as include directories for any aidl sources of modules |
| 204 | // that depend on this module, as well as to aidl for this module. |
| 205 | Export_include_dirs []string |
Martijn Coenen | eab1564 | 2018-03-09 09:29:59 +0100 | [diff] [blame] | 206 | |
| 207 | // whether to generate traces (for systrace) for this interface |
| 208 | Generate_traces *bool |
Olivier Gaillard | 0a4cfbc | 2018-07-16 23:37:03 +0100 | [diff] [blame] | 209 | |
| 210 | // whether to generate Binder#GetTransaction name method. |
| 211 | Generate_get_transaction_name *bool |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 212 | } |
Colin Cross | 9243010 | 2017-10-09 14:59:32 -0700 | [diff] [blame] | 213 | |
| 214 | // If true, export a copy of the module as a -hostdex module for host testing. |
| 215 | Hostdex *bool |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 216 | |
David Brazdil | 17ef563 | 2018-06-27 10:27:45 +0100 | [diff] [blame] | 217 | // If set to true, compile dex regardless of installable. Defaults to false. |
| 218 | Compile_dex *bool |
| 219 | |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 220 | Optimize struct { |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 221 | // If false, disable all optimization. Defaults to true for android_app and android_test |
| 222 | // modules, false for java_library and java_test modules. |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 223 | Enabled *bool |
| 224 | |
| 225 | // If true, optimize for size by removing unused code. Defaults to true for apps, |
| 226 | // false for libraries and tests. |
| 227 | Shrink *bool |
| 228 | |
| 229 | // If true, optimize bytecode. Defaults to false. |
| 230 | Optimize *bool |
| 231 | |
| 232 | // If true, obfuscate bytecode. Defaults to false. |
| 233 | Obfuscate *bool |
| 234 | |
| 235 | // If true, do not use the flag files generated by aapt that automatically keep |
| 236 | // classes referenced by the app manifest. Defaults to false. |
| 237 | No_aapt_flags *bool |
| 238 | |
| 239 | // Flags to pass to proguard. |
| 240 | Proguard_flags []string |
| 241 | |
| 242 | // Specifies the locations of files containing proguard flags. |
| 243 | Proguard_flags_files []string |
| 244 | } |
| 245 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 246 | // When targeting 1.9, override the modules to use with --system |
| 247 | System_modules *string |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 248 | |
| 249 | UncompressDex bool `blueprint:"mutated"` |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 250 | IsSDKLibrary bool `blueprint:"mutated"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 253 | // Module contains the properties and members used by all java module types |
| 254 | type Module struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 255 | android.ModuleBase |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 256 | android.DefaultableModuleBase |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 257 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 258 | properties CompilerProperties |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 259 | protoProperties android.ProtoProperties |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 260 | deviceProperties CompilerDeviceProperties |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 261 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 262 | // jar file containing header classes including static library dependencies, suitable for |
| 263 | // inserting into the bootclasspath/classpath of another compile |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 264 | headerJarFile android.Path |
| 265 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 266 | // jar file containing implementation classes including static library dependencies but no |
| 267 | // resources |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 268 | implementationJarFile android.Path |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 269 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 270 | // jar file containing only resources including from static library dependencies |
| 271 | resourceJar android.Path |
| 272 | |
| 273 | // jar file containing implementation classes and resources including static library |
| 274 | // dependencies |
| 275 | implementationAndResourcesJar android.Path |
| 276 | |
| 277 | // output file containing classes.dex and resources |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 278 | dexJarFile android.Path |
| 279 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 280 | // output file that contains classes.dex if it should be in the output file |
| 281 | maybeStrippedDexJarFile android.Path |
| 282 | |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 283 | // output file containing uninstrumented classes that will be instrumented by jacoco |
| 284 | jacocoReportClassesFile android.Path |
| 285 | |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 286 | // output file containing mapping of obfuscated names |
| 287 | proguardDictionary android.Path |
| 288 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 289 | // output file of the module, which may be a classes jar or a dex jar |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 290 | outputFile android.Path |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 291 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 292 | exportAidlIncludeDirs android.Paths |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 293 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 294 | logtagsSrcs android.Paths |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 295 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 296 | // installed file for binary dependency |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 297 | installFile android.Path |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 298 | |
| 299 | // list of .java files and srcjars that was passed to javac |
| 300 | compiledJavaSrcs android.Paths |
| 301 | compiledSrcJars android.Paths |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 302 | |
| 303 | // list of extra progurad flag files |
| 304 | extraProguardFlagFiles android.Paths |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 305 | |
Colin Cross | 094054a | 2018-10-17 15:10:48 -0700 | [diff] [blame] | 306 | // manifest file to use instead of properties.Manifest |
| 307 | overrideManifest android.OptionalPath |
| 308 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 309 | // list of SDK lib names that this java moudule is exporting |
| 310 | exportedSdkLibs []string |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 311 | |
| 312 | // list of source files, collected from compiledJavaSrcs and compiledSrcJars |
| 313 | // filter out Exclude_srcs, will be used by android.IDEInfo struct |
| 314 | expandIDEInfoCompiledSrcs []string |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 315 | |
| 316 | dexpreopter |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 319 | func (j *Module) Srcs() android.Paths { |
Colin Cross | 3063b78 | 2018-08-15 11:19:12 -0700 | [diff] [blame] | 320 | return android.Paths{j.outputFile} |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 321 | } |
| 322 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 323 | func (j *Module) DexJarFile() android.Path { |
| 324 | return j.dexJarFile |
| 325 | } |
| 326 | |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 327 | var _ android.SourceFileProducer = (*Module)(nil) |
| 328 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 329 | type Dependency interface { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 330 | HeaderJars() android.Paths |
| 331 | ImplementationJars() android.Paths |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 332 | ResourceJars() android.Paths |
| 333 | ImplementationAndResourcesJars() android.Paths |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 334 | AidlIncludeDirs() android.Paths |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 335 | ExportedSdkLibs() []string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 338 | type SdkLibraryDependency interface { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 339 | HeaderJars(ctx android.BaseContext, sdkVersion string) android.Paths |
| 340 | ImplementationJars(ctx android.BaseContext, sdkVersion string) android.Paths |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 341 | } |
| 342 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 343 | type SrcDependency interface { |
| 344 | CompiledSrcs() android.Paths |
| 345 | CompiledSrcJars() android.Paths |
| 346 | } |
| 347 | |
| 348 | func (j *Module) CompiledSrcs() android.Paths { |
| 349 | return j.compiledJavaSrcs |
| 350 | } |
| 351 | |
| 352 | func (j *Module) CompiledSrcJars() android.Paths { |
| 353 | return j.compiledSrcJars |
| 354 | } |
| 355 | |
| 356 | var _ SrcDependency = (*Module)(nil) |
| 357 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 358 | func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { |
| 359 | android.InitAndroidArchModule(module, hod, android.MultilibCommon) |
| 360 | android.InitDefaultableModule(module) |
| 361 | } |
| 362 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 363 | type dependencyTag struct { |
| 364 | blueprint.BaseDependencyTag |
| 365 | name string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 368 | type jniDependencyTag struct { |
| 369 | blueprint.BaseDependencyTag |
| 370 | target android.Target |
| 371 | } |
| 372 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 373 | var ( |
Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 374 | staticLibTag = dependencyTag{name: "staticlib"} |
| 375 | libTag = dependencyTag{name: "javalib"} |
| 376 | annoTag = dependencyTag{name: "annotation processor"} |
| 377 | bootClasspathTag = dependencyTag{name: "bootclasspath"} |
| 378 | systemModulesTag = dependencyTag{name: "system modules"} |
| 379 | frameworkResTag = dependencyTag{name: "framework-res"} |
| 380 | frameworkApkTag = dependencyTag{name: "framework-apk"} |
| 381 | kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"} |
| 382 | proguardRaiseTag = dependencyTag{name: "proguard-raise"} |
| 383 | certificateTag = dependencyTag{name: "certificate"} |
| 384 | instrumentationForTag = dependencyTag{name: "instrumentation_for"} |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 385 | ) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 386 | |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 387 | type sdkDep struct { |
Colin Cross | 47ff252 | 2017-10-02 14:22:08 -0700 | [diff] [blame] | 388 | useModule, useFiles, useDefaultLibs, invalidVersion bool |
| 389 | |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 390 | modules []string |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 391 | systemModules string |
| 392 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 393 | frameworkResModule string |
| 394 | |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 395 | jars android.Paths |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 396 | aidl android.Path |
| 397 | } |
| 398 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 399 | type jniLib struct { |
| 400 | name string |
| 401 | path android.Path |
| 402 | target android.Target |
| 403 | } |
| 404 | |
Colin Cross | 3144dfc | 2018-01-03 15:06:47 -0800 | [diff] [blame] | 405 | func (j *Module) shouldInstrument(ctx android.BaseContext) bool { |
| 406 | return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") |
| 407 | } |
| 408 | |
| 409 | func (j *Module) shouldInstrumentStatic(ctx android.BaseContext) bool { |
| 410 | return j.shouldInstrument(ctx) && |
| 411 | (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") || |
| 412 | ctx.Config().UnbundledBuild()) |
| 413 | } |
| 414 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 415 | func (j *Module) sdkVersion() string { |
| 416 | return String(j.deviceProperties.Sdk_version) |
| 417 | } |
| 418 | |
| 419 | func (j *Module) minSdkVersion() string { |
| 420 | if j.deviceProperties.Min_sdk_version != nil { |
| 421 | return *j.deviceProperties.Min_sdk_version |
| 422 | } |
| 423 | return j.sdkVersion() |
| 424 | } |
| 425 | |
Dan Willemsen | 419290a | 2018-10-31 15:28:47 -0700 | [diff] [blame] | 426 | func (j *Module) targetSdkVersion() string { |
| 427 | if j.deviceProperties.Target_sdk_version != nil { |
| 428 | return *j.deviceProperties.Target_sdk_version |
| 429 | } |
| 430 | return j.sdkVersion() |
| 431 | } |
| 432 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 433 | func (j *Module) deps(ctx android.BottomUpMutatorContext) { |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 434 | if ctx.Device() { |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 435 | if !Bool(j.properties.No_standard_libs) { |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 436 | sdkDep := decodeSdkDep(ctx, sdkContext(j)) |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 437 | if sdkDep.useDefaultLibs { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 438 | ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...) |
Tobias Thierer | 06dd04f | 2018-09-11 16:21:05 +0100 | [diff] [blame] | 439 | ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules) |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 440 | if !Bool(j.properties.No_framework_libs) { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 441 | ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...) |
Colin Cross | fa5eb23 | 2017-10-01 20:33:03 -0700 | [diff] [blame] | 442 | } |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 443 | } else if sdkDep.useModule { |
Tobias Thierer | 06dd04f | 2018-09-11 16:21:05 +0100 | [diff] [blame] | 444 | ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules) |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 445 | ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...) |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 446 | if Bool(j.deviceProperties.Optimize.Enabled) { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 447 | ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...) |
| 448 | ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...) |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 449 | } |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 450 | } |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 451 | } else if j.deviceProperties.System_modules == nil { |
| 452 | ctx.PropertyErrorf("no_standard_libs", |
| 453 | "system_modules is required to be set when no_standard_libs is true, did you mean no_framework_libs?") |
Tobias Thierer | 06dd04f | 2018-09-11 16:21:05 +0100 | [diff] [blame] | 454 | } else if *j.deviceProperties.System_modules != "none" { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 455 | ctx.AddVariationDependencies(nil, systemModulesTag, *j.deviceProperties.System_modules) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 456 | } |
Mathew Inwood | ebe29ce | 2018-09-04 14:26:19 +0100 | [diff] [blame] | 457 | if (ctx.ModuleName() == "framework") || (ctx.ModuleName() == "framework-annotation-proc") { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 458 | ctx.AddVariationDependencies(nil, frameworkResTag, "framework-res") |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 459 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 460 | if ctx.ModuleName() == "android_stubs_current" || |
| 461 | ctx.ModuleName() == "android_system_stubs_current" || |
Nan Zhang | 863f05b | 2018-08-07 13:41:10 -0700 | [diff] [blame] | 462 | ctx.ModuleName() == "android_test_stubs_current" { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 463 | ctx.AddVariationDependencies(nil, frameworkApkTag, "framework-res") |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 464 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 465 | } |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 466 | |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 467 | ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) |
| 468 | ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...) |
Mathew Inwood | 878c662 | 2018-07-02 16:34:51 +0100 | [diff] [blame] | 469 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 470 | {Mutator: "arch", Variation: ctx.Config().BuildOsCommonVariant}, |
Mathew Inwood | 878c662 | 2018-07-02 16:34:51 +0100 | [diff] [blame] | 471 | }, annoTag, j.properties.Annotation_processors...) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 472 | |
Colin Cross | 7f9036c | 2017-08-30 13:27:57 -0700 | [diff] [blame] | 473 | android.ExtractSourcesDeps(ctx, j.properties.Srcs) |
Nan Zhang | 27e284d | 2018-02-09 21:03:53 +0000 | [diff] [blame] | 474 | android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs) |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 475 | android.ExtractSourcesDeps(ctx, j.properties.Java_resources) |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 476 | android.ExtractSourceDeps(ctx, j.properties.Manifest) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 477 | |
| 478 | if j.hasSrcExt(".proto") { |
| 479 | protoDeps(ctx, &j.protoProperties) |
| 480 | } |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 481 | |
| 482 | if j.hasSrcExt(".kt") { |
| 483 | // TODO(ccross): move this to a mutator pass that can tell if generated sources contain |
| 484 | // Kotlin files |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 485 | ctx.AddVariationDependencies(nil, kotlinStdlibTag, "kotlin-stdlib") |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 486 | } |
Colin Cross | 3144dfc | 2018-01-03 15:06:47 -0800 | [diff] [blame] | 487 | |
| 488 | if j.shouldInstrumentStatic(ctx) { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 489 | ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent") |
Colin Cross | 3144dfc | 2018-01-03 15:06:47 -0800 | [diff] [blame] | 490 | } |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | func hasSrcExt(srcs []string, ext string) bool { |
| 494 | for _, src := range srcs { |
| 495 | if filepath.Ext(src) == ext { |
| 496 | return true |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | return false |
| 501 | } |
| 502 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 503 | func shardPaths(paths android.Paths, shardSize int) []android.Paths { |
| 504 | ret := make([]android.Paths, 0, (len(paths)+shardSize-1)/shardSize) |
| 505 | for len(paths) > shardSize { |
| 506 | ret = append(ret, paths[0:shardSize]) |
| 507 | paths = paths[shardSize:] |
| 508 | } |
| 509 | if len(paths) > 0 { |
| 510 | ret = append(ret, paths) |
| 511 | } |
| 512 | return ret |
| 513 | } |
| 514 | |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 515 | func (j *Module) hasSrcExt(ext string) bool { |
| 516 | return hasSrcExt(j.properties.Srcs, ext) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 519 | func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 520 | aidlIncludeDirs android.Paths) []string { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 521 | |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 522 | aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs) |
| 523 | aidlIncludes = append(aidlIncludes, |
| 524 | android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...) |
| 525 | aidlIncludes = append(aidlIncludes, |
| 526 | android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 527 | |
Steven Moreland | 667f688 | 2018-07-26 12:55:08 -0700 | [diff] [blame] | 528 | flags := []string{"-b"} |
| 529 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 530 | if aidlPreprocess.Valid() { |
| 531 | flags = append(flags, "-p"+aidlPreprocess.String()) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 532 | } else { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 533 | flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I")) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 536 | flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I")) |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 537 | flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I")) |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 538 | flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String()) |
Colin Cross | 32f3898 | 2018-02-22 11:47:25 -0800 | [diff] [blame] | 539 | if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() { |
Colin Cross | d48633a | 2017-07-13 14:41:17 -0700 | [diff] [blame] | 540 | flags = append(flags, "-I"+src.String()) |
| 541 | } |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 542 | |
Martijn Coenen | eab1564 | 2018-03-09 09:29:59 +0100 | [diff] [blame] | 543 | if Bool(j.deviceProperties.Aidl.Generate_traces) { |
| 544 | flags = append(flags, "-t") |
| 545 | } |
| 546 | |
Olivier Gaillard | 0a4cfbc | 2018-07-16 23:37:03 +0100 | [diff] [blame] | 547 | if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) { |
| 548 | flags = append(flags, "--transaction_names") |
| 549 | } |
| 550 | |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 551 | return flags |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 554 | type deps struct { |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 555 | classpath classpath |
| 556 | bootClasspath classpath |
Colin Cross | 6a77c98 | 2018-06-19 22:43:34 -0700 | [diff] [blame] | 557 | processorPath classpath |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 558 | staticJars android.Paths |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 559 | staticHeaderJars android.Paths |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 560 | staticResourceJars android.Paths |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 561 | aidlIncludeDirs android.Paths |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 562 | srcs android.Paths |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 563 | srcJars android.Paths |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 564 | systemModules android.Path |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 565 | aidlPreprocess android.OptionalPath |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 566 | kotlinStdlib android.Paths |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 567 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 568 | |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 569 | func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) { |
| 570 | for _, f := range dep.Srcs() { |
| 571 | if f.Ext() != ".jar" { |
| 572 | ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency", |
| 573 | ctx.OtherModuleName(dep.(blueprint.Module))) |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 578 | type linkType int |
| 579 | |
| 580 | const ( |
| 581 | javaCore linkType = iota |
| 582 | javaSdk |
| 583 | javaSystem |
| 584 | javaPlatform |
| 585 | ) |
| 586 | |
Jiyong Park | 46f78fb | 2018-10-20 16:33:17 +0900 | [diff] [blame] | 587 | func getLinkType(m *Module, name string) (ret linkType, stubs bool) { |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 588 | ver := m.sdkVersion() |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 589 | switch { |
Jiyong Park | 46f78fb | 2018-10-20 16:33:17 +0900 | [diff] [blame] | 590 | case name == "core.current.stubs" || name == "core.platform.api.stubs" || |
| 591 | name == "stub-annotations" || name == "private-stub-annotations-jar" || |
| 592 | name == "core-lambda-stubs": |
| 593 | return javaCore, true |
Neil Fuller | 401eeba | 2018-10-18 19:48:58 +0100 | [diff] [blame] | 594 | case ver == "core_current": |
Jiyong Park | 46f78fb | 2018-10-20 16:33:17 +0900 | [diff] [blame] | 595 | return javaCore, false |
| 596 | case name == "android_system_stubs_current": |
| 597 | return javaSystem, true |
| 598 | case strings.HasPrefix(ver, "system_"): |
| 599 | return javaSystem, false |
| 600 | case name == "android_test_stubs_current": |
| 601 | return javaSystem, true |
| 602 | case strings.HasPrefix(ver, "test_"): |
| 603 | return javaPlatform, false |
| 604 | case name == "android_stubs_current": |
| 605 | return javaSdk, true |
| 606 | case ver == "current": |
| 607 | return javaSdk, false |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 608 | case ver == "": |
Jiyong Park | 46f78fb | 2018-10-20 16:33:17 +0900 | [diff] [blame] | 609 | return javaPlatform, false |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 610 | default: |
| 611 | if _, err := strconv.Atoi(ver); err != nil { |
| 612 | panic(fmt.Errorf("expected sdk_version to be a number, got %q", ver)) |
| 613 | } |
Jiyong Park | 46f78fb | 2018-10-20 16:33:17 +0900 | [diff] [blame] | 614 | return javaSdk, false |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 618 | func checkLinkType(ctx android.ModuleContext, from *Module, to *Library, tag dependencyTag) { |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 619 | if ctx.Host() { |
| 620 | return |
| 621 | } |
| 622 | |
Jiyong Park | 46f78fb | 2018-10-20 16:33:17 +0900 | [diff] [blame] | 623 | myLinkType, stubs := getLinkType(from, ctx.ModuleName()) |
| 624 | if stubs { |
| 625 | return |
| 626 | } |
| 627 | otherLinkType, _ := getLinkType(&to.Module, ctx.OtherModuleName(to)) |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 628 | 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." |
| 629 | |
| 630 | switch myLinkType { |
| 631 | case javaCore: |
| 632 | if otherLinkType != javaCore { |
| 633 | ctx.ModuleErrorf("compiles against core Java API, but dependency %q is compiling against non-core Java APIs."+commonMessage, |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 634 | ctx.OtherModuleName(to)) |
| 635 | } |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 636 | break |
| 637 | case javaSdk: |
| 638 | if otherLinkType != javaCore && otherLinkType != javaSdk { |
| 639 | ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage, |
| 640 | ctx.OtherModuleName(to)) |
| 641 | } |
| 642 | break |
| 643 | case javaSystem: |
| 644 | if otherLinkType == javaPlatform { |
| 645 | ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage, |
| 646 | ctx.OtherModuleName(to)) |
| 647 | } |
| 648 | break |
| 649 | case javaPlatform: |
| 650 | // no restriction on link-type |
| 651 | break |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 652 | } |
| 653 | } |
| 654 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 655 | func (j *Module) collectDeps(ctx android.ModuleContext) deps { |
| 656 | var deps deps |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 657 | |
Colin Cross | 300f038 | 2018-03-06 13:11:51 -0800 | [diff] [blame] | 658 | if ctx.Device() { |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 659 | sdkDep := decodeSdkDep(ctx, sdkContext(j)) |
Colin Cross | 300f038 | 2018-03-06 13:11:51 -0800 | [diff] [blame] | 660 | if sdkDep.invalidVersion { |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 661 | ctx.AddMissingDependencies(sdkDep.modules) |
Colin Cross | 300f038 | 2018-03-06 13:11:51 -0800 | [diff] [blame] | 662 | } else if sdkDep.useFiles { |
| 663 | // sdkDep.jar is actually equivalent to turbine header.jar. |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 664 | deps.classpath = append(deps.classpath, sdkDep.jars...) |
Colin Cross | 300f038 | 2018-03-06 13:11:51 -0800 | [diff] [blame] | 665 | deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl) |
| 666 | } |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 669 | ctx.VisitDirectDeps(func(module android.Module) { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 670 | otherName := ctx.OtherModuleName(module) |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 671 | tag := ctx.OtherModuleDependencyTag(module) |
| 672 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 673 | if _, ok := tag.(*jniDependencyTag); ok { |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 674 | // Handled by AndroidApp.collectAppDeps |
| 675 | return |
| 676 | } |
| 677 | if tag == certificateTag { |
| 678 | // Handled by AndroidApp.collectAppDeps |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 679 | return |
| 680 | } |
| 681 | |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 682 | if to, ok := module.(*Library); ok { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 683 | switch tag { |
| 684 | case bootClasspathTag, libTag, staticLibTag: |
| 685 | checkLinkType(ctx, j, to, tag.(dependencyTag)) |
| 686 | } |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 687 | } |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 688 | switch dep := module.(type) { |
| 689 | case Dependency: |
| 690 | switch tag { |
| 691 | case bootClasspathTag: |
| 692 | deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...) |
Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 693 | case libTag, instrumentationForTag: |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 694 | deps.classpath = append(deps.classpath, dep.HeaderJars()...) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 695 | // sdk lib names from dependencies are re-exported |
| 696 | j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...) |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 697 | case staticLibTag: |
| 698 | deps.classpath = append(deps.classpath, dep.HeaderJars()...) |
| 699 | deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...) |
| 700 | deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...) |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 701 | deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 702 | // sdk lib names from dependencies are re-exported |
| 703 | j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...) |
Colin Cross | 6a77c98 | 2018-06-19 22:43:34 -0700 | [diff] [blame] | 704 | case annoTag: |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 705 | deps.processorPath = append(deps.processorPath, dep.ImplementationAndResourcesJars()...) |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 706 | case frameworkResTag: |
Mathew Inwood | ebe29ce | 2018-09-04 14:26:19 +0100 | [diff] [blame] | 707 | if (ctx.ModuleName() == "framework") || (ctx.ModuleName() == "framework-annotation-proc") { |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 708 | // framework.jar has a one-off dependency on the R.java and Manifest.java files |
| 709 | // generated by framework-res.apk |
| 710 | deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar) |
| 711 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 712 | case frameworkApkTag: |
| 713 | if ctx.ModuleName() == "android_stubs_current" || |
| 714 | ctx.ModuleName() == "android_system_stubs_current" || |
Nan Zhang | 863f05b | 2018-08-07 13:41:10 -0700 | [diff] [blame] | 715 | ctx.ModuleName() == "android_test_stubs_current" { |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 716 | // framework stubs.jar need to depend on framework-res.apk, in order to pull the |
| 717 | // resource files out of there for aapt. |
| 718 | // |
| 719 | // Normally the package rule runs aapt, which includes the resource, |
| 720 | // but we're not running that in our package rule so just copy in the |
| 721 | // resource files here. |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 722 | deps.staticResourceJars = append(deps.staticResourceJars, dep.(*AndroidApp).exportPackage) |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 723 | } |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 724 | case kotlinStdlibTag: |
| 725 | deps.kotlinStdlib = dep.HeaderJars() |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 729 | case SdkLibraryDependency: |
| 730 | switch tag { |
| 731 | case libTag: |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 732 | deps.classpath = append(deps.classpath, dep.HeaderJars(ctx, j.sdkVersion())...) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 733 | // names of sdk libs that are directly depended are exported |
| 734 | j.exportedSdkLibs = append(j.exportedSdkLibs, otherName) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 735 | default: |
| 736 | ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName) |
| 737 | } |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 738 | case android.SourceFileProducer: |
| 739 | switch tag { |
| 740 | case libTag: |
| 741 | checkProducesJars(ctx, dep) |
| 742 | deps.classpath = append(deps.classpath, dep.Srcs()...) |
| 743 | case staticLibTag: |
| 744 | checkProducesJars(ctx, dep) |
| 745 | deps.classpath = append(deps.classpath, dep.Srcs()...) |
| 746 | deps.staticJars = append(deps.staticJars, dep.Srcs()...) |
| 747 | deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...) |
| 748 | case android.DefaultsDepTag, android.SourceDepTag: |
| 749 | // Nothing to do |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 750 | case publicApiFileTag, systemApiFileTag, testApiFileTag: |
| 751 | // Nothing to do |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 752 | default: |
| 753 | ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName) |
| 754 | } |
| 755 | default: |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 756 | switch tag { |
| 757 | case android.DefaultsDepTag, android.SourceDepTag: |
Dan Willemsen | d6ba0d5 | 2017-09-13 15:46:47 -0700 | [diff] [blame] | 758 | // Nothing to do |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 759 | case systemModulesTag: |
| 760 | if deps.systemModules != nil { |
| 761 | panic("Found two system module dependencies") |
| 762 | } |
| 763 | sm := module.(*SystemModules) |
| 764 | if sm.outputFile == nil { |
| 765 | panic("Missing directory for system module dependency") |
| 766 | } |
| 767 | deps.systemModules = sm.outputFile |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 768 | default: |
| 769 | ctx.ModuleErrorf("depends on non-java module %q", otherName) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 770 | } |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 771 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 772 | }) |
| 773 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 774 | j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs) |
| 775 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 776 | return deps |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 779 | func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) string { |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 780 | var ret string |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 781 | v := sdkContext.sdkVersion() |
| 782 | // For PDK builds, use the latest SDK version instead of "current" |
| 783 | if ctx.Config().IsPdkBuild() && (v == "" || v == "current") { |
| 784 | sdkVersions := ctx.Config().Get(sdkSingletonKey).([]int) |
| 785 | latestSdkVersion := 0 |
| 786 | if len(sdkVersions) > 0 { |
| 787 | latestSdkVersion = sdkVersions[len(sdkVersions)-1] |
| 788 | } |
| 789 | v = strconv.Itoa(latestSdkVersion) |
| 790 | } |
| 791 | |
| 792 | sdk, err := sdkVersionToNumber(ctx, v) |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 793 | if err != nil { |
| 794 | ctx.PropertyErrorf("sdk_version", "%s", err) |
| 795 | } |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 796 | if javaVersion != "" { |
| 797 | ret = javaVersion |
| 798 | } else if ctx.Device() && sdk <= 23 { |
| 799 | ret = "1.7" |
Jiyong Park | 4584a8a | 2018-10-03 18:05:04 +0900 | [diff] [blame] | 800 | } else if ctx.Device() && sdk <= 28 || !ctx.Config().TargetOpenJDK9() { |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 801 | ret = "1.8" |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 802 | } else if ctx.Device() && sdkContext.sdkVersion() != "" && sdk == android.FutureApiLevel { |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 803 | // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current" |
| 804 | ret = "1.8" |
| 805 | } else { |
| 806 | ret = "1.9" |
| 807 | } |
| 808 | |
| 809 | return ret |
| 810 | } |
| 811 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 812 | func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 813 | |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 814 | var flags javaBuilderFlags |
| 815 | |
Tobias Thierer | 06dd04f | 2018-09-11 16:21:05 +0100 | [diff] [blame] | 816 | // javaVersion flag. |
| 817 | flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j)) |
| 818 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 819 | // javac flags. |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 820 | javacFlags := j.properties.Javacflags |
Tobias Thierer | 06dd04f | 2018-09-11 16:21:05 +0100 | [diff] [blame] | 821 | if flags.javaVersion == "1.9" { |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 822 | javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 823 | } |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 824 | if ctx.Config().MinimizeJavaDebugInfo() { |
Colin Cross | 126a25c | 2017-10-31 13:55:34 -0700 | [diff] [blame] | 825 | // Override the -g flag passed globally to remove local variable debug info to reduce |
| 826 | // disk and memory usage. |
| 827 | javacFlags = append(javacFlags, "-g:source,lines") |
| 828 | } |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 829 | |
Colin Cross | 6654810 | 2018-06-19 22:47:35 -0700 | [diff] [blame] | 830 | if ctx.Config().RunErrorProne() { |
| 831 | if config.ErrorProneClasspath == nil { |
| 832 | ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?") |
| 833 | } |
| 834 | |
| 835 | errorProneFlags := []string{ |
| 836 | "-Xplugin:ErrorProne", |
| 837 | "${config.ErrorProneChecks}", |
| 838 | } |
| 839 | errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...) |
| 840 | |
| 841 | flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " + |
| 842 | "'" + strings.Join(errorProneFlags, " ") + "'" |
| 843 | flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath)) |
Andreas Gampe | f3e5b55 | 2018-01-22 21:27:21 -0800 | [diff] [blame] | 844 | } |
| 845 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 846 | // classpath |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 847 | flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...) |
| 848 | flags.classpath = append(flags.classpath, deps.classpath...) |
Colin Cross | 6a77c98 | 2018-06-19 22:43:34 -0700 | [diff] [blame] | 849 | flags.processorPath = append(flags.processorPath, deps.processorPath...) |
Colin Cross | 7fdd2b7 | 2018-01-02 18:14:25 -0800 | [diff] [blame] | 850 | |
Tobias Thierer | 06dd04f | 2018-09-11 16:21:05 +0100 | [diff] [blame] | 851 | if len(flags.bootClasspath) == 0 && ctx.Host() && flags.javaVersion != "1.9" && |
Colin Cross | 7fdd2b7 | 2018-01-02 18:14:25 -0800 | [diff] [blame] | 852 | !Bool(j.properties.No_standard_libs) && |
| 853 | inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) { |
| 854 | // Give host-side tools a version of OpenJDK's standard libraries |
| 855 | // close to what they're targeting. As of Dec 2017, AOSP is only |
| 856 | // bundling OpenJDK 8 and 9, so nothing < 8 is available. |
| 857 | // |
| 858 | // When building with OpenJDK 8, the following should have no |
| 859 | // effect since those jars would be available by default. |
| 860 | // |
| 861 | // When building with OpenJDK 9 but targeting a version < 1.8, |
| 862 | // putting them on the bootclasspath means that: |
| 863 | // a) code can't (accidentally) refer to OpenJDK 9 specific APIs |
| 864 | // b) references to existing APIs are not reinterpreted in an |
| 865 | // OpenJDK 9-specific way, eg. calls to subclasses of |
| 866 | // java.nio.Buffer as in http://b/70862583 |
| 867 | java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME") |
| 868 | flags.bootClasspath = append(flags.bootClasspath, |
| 869 | android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"), |
| 870 | android.PathForSource(ctx, java8Home, "jre/lib/rt.jar")) |
Nan Zhang | 5f8cb42 | 2018-02-06 10:34:32 -0800 | [diff] [blame] | 871 | if Bool(j.properties.Use_tools_jar) { |
| 872 | flags.bootClasspath = append(flags.bootClasspath, |
| 873 | android.PathForSource(ctx, java8Home, "lib/tools.jar")) |
| 874 | } |
Colin Cross | 7fdd2b7 | 2018-01-02 18:14:25 -0800 | [diff] [blame] | 875 | } |
| 876 | |
Tobias Thierer | 06dd04f | 2018-09-11 16:21:05 +0100 | [diff] [blame] | 877 | if j.properties.Patch_module != nil && flags.javaVersion == "1.9" { |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 878 | // Manually specify build directory in case it is not under the repo root. |
| 879 | // (javac doesn't seem to expand into symbolc links when searching for patch-module targets, so |
| 880 | // just adding a symlink under the root doesn't help.) |
| 881 | patchPaths := ".:" + ctx.Config().BuildDir() |
| 882 | classPath := flags.classpath.FormJavaClassPath("") |
| 883 | if classPath != "" { |
| 884 | patchPaths += ":" + classPath |
| 885 | } |
| 886 | javacFlags = append(javacFlags, "--patch-module="+String(j.properties.Patch_module)+"="+patchPaths) |
Colin Cross | 8144008 | 2018-08-15 20:21:55 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 889 | // systemModules |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 890 | if deps.systemModules != nil { |
| 891 | flags.systemModules = append(flags.systemModules, deps.systemModules) |
| 892 | } |
| 893 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 894 | // aidl flags. |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 895 | aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs) |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 896 | if len(aidlFlags) > 0 { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 897 | // optimization. |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 898 | ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " ")) |
| 899 | flags.aidlFlags = "$aidlFlags" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 900 | } |
| 901 | |
Colin Cross | 8144008 | 2018-08-15 20:21:55 -0700 | [diff] [blame] | 902 | if len(javacFlags) > 0 { |
| 903 | // optimization. |
| 904 | ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " ")) |
| 905 | flags.javacFlags = "$javacFlags" |
| 906 | } |
| 907 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 908 | return flags |
| 909 | } |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 910 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 911 | func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path) { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 912 | |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 913 | j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 914 | |
| 915 | deps := j.collectDeps(ctx) |
| 916 | flags := j.collectBuilderFlags(ctx, deps) |
| 917 | |
Tobias Thierer | 06dd04f | 2018-09-11 16:21:05 +0100 | [diff] [blame] | 918 | if flags.javaVersion == "1.9" { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 919 | j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...) |
| 920 | } |
| 921 | srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 922 | if hasSrcExt(srcFiles.Strings(), ".proto") { |
Colin Cross | 0f2ee15 | 2017-12-14 15:22:43 -0800 | [diff] [blame] | 923 | flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 924 | } |
| 925 | |
Colin Cross | af05017 | 2017-11-15 23:01:59 -0800 | [diff] [blame] | 926 | srcFiles = j.genSources(ctx, srcFiles, flags) |
| 927 | |
| 928 | srcJars := srcFiles.FilterByExt(".srcjar") |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 929 | srcJars = append(srcJars, deps.srcJars...) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 930 | srcJars = append(srcJars, extraSrcJars...) |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 931 | |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 932 | // Collect source files from compiledJavaSrcs, compiledSrcJars and filter out Exclude_srcs |
| 933 | // that IDEInfo struct will use |
| 934 | j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.Strings()...) |
| 935 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 936 | jarName := ctx.ModuleName() + ".jar" |
| 937 | |
Przemyslaw Szczepaniak | 4b5fe9d | 2018-02-13 14:32:54 +0000 | [diff] [blame] | 938 | javaSrcFiles := srcFiles.FilterByExt(".java") |
| 939 | var uniqueSrcFiles android.Paths |
| 940 | set := make(map[string]bool) |
| 941 | for _, v := range javaSrcFiles { |
| 942 | if _, found := set[v.String()]; !found { |
| 943 | set[v.String()] = true |
| 944 | uniqueSrcFiles = append(uniqueSrcFiles, v) |
| 945 | } |
| 946 | } |
| 947 | |
Colin Cross | 55f63ea | 2018-08-27 12:37:09 -0700 | [diff] [blame] | 948 | var kotlinJars android.Paths |
| 949 | |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 950 | if srcFiles.HasExt(".kt") { |
Zoran Jovanovic | 8736ce2 | 2018-08-21 17:10:29 +0200 | [diff] [blame] | 951 | // user defined kotlin flags. |
| 952 | kotlincFlags := j.properties.Kotlincflags |
| 953 | CheckKotlincFlags(ctx, kotlincFlags) |
| 954 | |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 955 | // If there are kotlin files, compile them first but pass all the kotlin and java files |
| 956 | // kotlinc will use the java files to resolve types referenced by the kotlin files, but |
| 957 | // won't emit any classes for them. |
Zoran Jovanovic | 8736ce2 | 2018-08-21 17:10:29 +0200 | [diff] [blame] | 958 | kotlincFlags = append(kotlincFlags, "-no-stdlib") |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 959 | if ctx.Device() { |
Zoran Jovanovic | 8736ce2 | 2018-08-21 17:10:29 +0200 | [diff] [blame] | 960 | kotlincFlags = append(kotlincFlags, "-no-jdk") |
| 961 | } |
| 962 | if len(kotlincFlags) > 0 { |
| 963 | // optimization. |
| 964 | ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " ")) |
| 965 | flags.kotlincFlags += "$kotlincFlags" |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 966 | } |
| 967 | |
Przemyslaw Szczepaniak | 4b5fe9d | 2018-02-13 14:32:54 +0000 | [diff] [blame] | 968 | var kotlinSrcFiles android.Paths |
| 969 | kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...) |
| 970 | kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...) |
| 971 | |
Przemyslaw Szczepaniak | e3d26bf | 2018-03-05 16:06:42 +0000 | [diff] [blame] | 972 | flags.kotlincClasspath = append(flags.kotlincClasspath, deps.bootClasspath...) |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 973 | flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...) |
| 974 | flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...) |
| 975 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 976 | kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName) |
Colin Cross | 21fc9bb | 2019-01-18 15:05:09 -0800 | [diff] [blame^] | 977 | kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags) |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 978 | if ctx.Failed() { |
| 979 | return |
| 980 | } |
| 981 | |
| 982 | // Make javac rule depend on the kotlinc rule |
Colin Cross | 49da275 | 2018-06-05 17:22:57 -0700 | [diff] [blame] | 983 | flags.classpath = append(flags.classpath, deps.kotlinStdlib...) |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 984 | flags.classpath = append(flags.classpath, kotlinJar) |
Przemyslaw Szczepaniak | 66c0c40 | 2018-03-08 13:21:55 +0000 | [diff] [blame] | 985 | |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 986 | // Jar kotlin classes into the final jar after javac |
Colin Cross | 55f63ea | 2018-08-27 12:37:09 -0700 | [diff] [blame] | 987 | kotlinJars = append(kotlinJars, kotlinJar) |
Colin Cross | 9b38aef | 2018-08-27 15:42:25 -0700 | [diff] [blame] | 988 | kotlinJars = append(kotlinJars, deps.kotlinStdlib...) |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Colin Cross | 55f63ea | 2018-08-27 12:37:09 -0700 | [diff] [blame] | 991 | jars := append(android.Paths(nil), kotlinJars...) |
| 992 | |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 993 | // Store the list of .java files that was passed to javac |
| 994 | j.compiledJavaSrcs = uniqueSrcFiles |
| 995 | j.compiledSrcJars = srcJars |
| 996 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 997 | enable_sharding := false |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 998 | if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") { |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 999 | if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 { |
| 1000 | enable_sharding = true |
Ashley Rose | e36efcf | 2019-01-16 17:34:08 -0500 | [diff] [blame] | 1001 | // Formerly, there was a check here that prevented annotation processors |
| 1002 | // from being used when sharding was enabled, as some annotation processors |
| 1003 | // do not function correctly in sharded environments. It was removed to |
| 1004 | // allow for the use of annotation processors that do function correctly |
| 1005 | // with sharding enabled. See: b/77284273. |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1006 | } |
Colin Cross | 55f63ea | 2018-08-27 12:37:09 -0700 | [diff] [blame] | 1007 | j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars) |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 1008 | if ctx.Failed() { |
| 1009 | return |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1010 | } |
| 1011 | } |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 1012 | if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 { |
Colin Cross | d689143 | 2017-09-27 17:39:56 -0700 | [diff] [blame] | 1013 | var extraJarDeps android.Paths |
Colin Cross | 6654810 | 2018-06-19 22:47:35 -0700 | [diff] [blame] | 1014 | if ctx.Config().RunErrorProne() { |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 1015 | // If error-prone is enabled, add an additional rule to compile the java files into |
| 1016 | // a separate set of classes (so that they don't overwrite the normal ones and require |
Colin Cross | d689143 | 2017-09-27 17:39:56 -0700 | [diff] [blame] | 1017 | // a rebuild when error-prone is turned off). |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 1018 | // TODO(ccross): Once we always compile with javac9 we may be able to conditionally |
| 1019 | // enable error-prone without affecting the output class files. |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 1020 | errorprone := android.PathForModuleOut(ctx, "errorprone", jarName) |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1021 | RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags) |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 1022 | extraJarDeps = append(extraJarDeps, errorprone) |
| 1023 | } |
| 1024 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1025 | if enable_sharding { |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1026 | flags.classpath = append(flags.classpath, j.headerJarFile) |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1027 | shardSize := int(*(j.properties.Javac_shard_size)) |
| 1028 | var shardSrcs []android.Paths |
| 1029 | if len(uniqueSrcFiles) > 0 { |
| 1030 | shardSrcs = shardPaths(uniqueSrcFiles, shardSize) |
| 1031 | for idx, shardSrc := range shardSrcs { |
| 1032 | classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx)) |
| 1033 | TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps) |
| 1034 | jars = append(jars, classes) |
| 1035 | } |
| 1036 | } |
| 1037 | if len(srcJars) > 0 { |
| 1038 | classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs))) |
| 1039 | TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps) |
| 1040 | jars = append(jars, classes) |
| 1041 | } |
| 1042 | } else { |
| 1043 | classes := android.PathForModuleOut(ctx, "javac", jarName) |
| 1044 | TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps) |
| 1045 | jars = append(jars, classes) |
| 1046 | } |
Colin Cross | d689143 | 2017-09-27 17:39:56 -0700 | [diff] [blame] | 1047 | if ctx.Failed() { |
| 1048 | return |
| 1049 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
Colin Cross | cedd476 | 2018-09-13 11:26:19 -0700 | [diff] [blame] | 1052 | dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, |
| 1053 | j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources) |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 1054 | fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources) |
| 1055 | |
| 1056 | var resArgs []string |
| 1057 | var resDeps android.Paths |
| 1058 | |
| 1059 | resArgs = append(resArgs, dirArgs...) |
| 1060 | resDeps = append(resDeps, dirDeps...) |
| 1061 | |
| 1062 | resArgs = append(resArgs, fileArgs...) |
| 1063 | resDeps = append(resDeps, fileDeps...) |
| 1064 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1065 | if Bool(j.properties.Include_srcs) { |
Colin Cross | 2372923 | 2017-10-03 13:14:07 -0700 | [diff] [blame] | 1066 | srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs) |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 1067 | resArgs = append(resArgs, srcArgs...) |
| 1068 | resDeps = append(resDeps, srcDeps...) |
| 1069 | } |
Colin Cross | 40a3671 | 2017-09-27 17:41:35 -0700 | [diff] [blame] | 1070 | |
| 1071 | if len(resArgs) > 0 { |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 1072 | resourceJar := android.PathForModuleOut(ctx, "res", jarName) |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1073 | TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps) |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1074 | j.resourceJar = resourceJar |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 1075 | if ctx.Failed() { |
| 1076 | return |
| 1077 | } |
| 1078 | } |
| 1079 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1080 | if len(deps.staticResourceJars) > 0 { |
| 1081 | var jars android.Paths |
| 1082 | if j.resourceJar != nil { |
| 1083 | jars = append(jars, j.resourceJar) |
| 1084 | } |
| 1085 | jars = append(jars, deps.staticResourceJars...) |
| 1086 | |
| 1087 | combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName) |
| 1088 | TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{}, |
| 1089 | false, nil, nil) |
| 1090 | j.resourceJar = combinedJar |
| 1091 | } |
| 1092 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 1093 | jars = append(jars, deps.staticJars...) |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1094 | jars = append(jars, deps.staticResourceJars...) |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1095 | |
Colin Cross | 094054a | 2018-10-17 15:10:48 -0700 | [diff] [blame] | 1096 | manifest := j.overrideManifest |
| 1097 | if !manifest.Valid() && j.properties.Manifest != nil { |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 1098 | manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest")) |
| 1099 | } |
Colin Cross | 635acc9 | 2017-09-12 22:50:46 -0700 | [diff] [blame] | 1100 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1101 | // Combine the classes built from sources, any manifests, and any static libraries into |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1102 | // classes.jar. If there is only one input jar this step will be skipped. |
Colin Cross | 3063b78 | 2018-08-15 11:19:12 -0700 | [diff] [blame] | 1103 | var outputFile android.ModuleOutPath |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1104 | |
| 1105 | if len(jars) == 1 && !manifest.Valid() { |
Colin Cross | 3063b78 | 2018-08-15 11:19:12 -0700 | [diff] [blame] | 1106 | if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok { |
| 1107 | // Optimization: skip the combine step if there is nothing to do |
| 1108 | // TODO(ccross): this leaves any module-info.class files, but those should only come from |
| 1109 | // prebuilt dependencies until we support modules in the platform build, so there shouldn't be |
| 1110 | // any if len(jars) == 1. |
| 1111 | outputFile = moduleOutPath |
| 1112 | } else { |
| 1113 | combinedJar := android.PathForModuleOut(ctx, "combined", jarName) |
| 1114 | ctx.Build(pctx, android.BuildParams{ |
| 1115 | Rule: android.Cp, |
| 1116 | Input: jars[0], |
| 1117 | Output: combinedJar, |
| 1118 | }) |
| 1119 | outputFile = combinedJar |
| 1120 | } |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1121 | } else { |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 1122 | combinedJar := android.PathForModuleOut(ctx, "combined", jarName) |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1123 | TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest, |
Colin Cross | 9b38aef | 2018-08-27 15:42:25 -0700 | [diff] [blame] | 1124 | false, nil, nil) |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1125 | outputFile = combinedJar |
| 1126 | } |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1127 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1128 | // jarjar implementation jar if necessary |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1129 | if j.properties.Jarjar_rules != nil { |
| 1130 | jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules) |
Colin Cross | 8649b26 | 2017-09-27 18:03:17 -0700 | [diff] [blame] | 1131 | // Transform classes.jar into classes-jarjar.jar |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 1132 | jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName) |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1133 | TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules) |
| 1134 | outputFile = jarjarFile |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1135 | |
| 1136 | // jarjar resource jar if necessary |
| 1137 | if j.resourceJar != nil { |
| 1138 | resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName) |
| 1139 | TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, jarjar_rules) |
| 1140 | j.resourceJar = resourceJarJarFile |
| 1141 | } |
| 1142 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1143 | if ctx.Failed() { |
| 1144 | return |
| 1145 | } |
| 1146 | } |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1147 | j.implementationJarFile = outputFile |
| 1148 | if j.headerJarFile == nil { |
| 1149 | j.headerJarFile = j.implementationJarFile |
| 1150 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1151 | |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 1152 | if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") { |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 1153 | if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) { |
| 1154 | j.properties.Instrument = true |
| 1155 | } |
| 1156 | } |
| 1157 | |
Colin Cross | 3144dfc | 2018-01-03 15:06:47 -0800 | [diff] [blame] | 1158 | if j.shouldInstrument(ctx) { |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 1159 | outputFile = j.instrument(ctx, flags, outputFile, jarName) |
| 1160 | } |
| 1161 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1162 | // merge implementation jar with resources if necessary |
| 1163 | implementationAndResourcesJar := outputFile |
| 1164 | if j.resourceJar != nil { |
| 1165 | jars := android.Paths{implementationAndResourcesJar, j.resourceJar} |
| 1166 | combinedJar := android.PathForModuleOut(ctx, "withres", jarName) |
| 1167 | TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{}, |
| 1168 | false, nil, nil) |
| 1169 | implementationAndResourcesJar = combinedJar |
| 1170 | } |
| 1171 | |
| 1172 | j.implementationAndResourcesJar = implementationAndResourcesJar |
| 1173 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1174 | if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) { |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 1175 | // Dex compilation |
Colin Cross | 3063b78 | 2018-08-15 11:19:12 -0700 | [diff] [blame] | 1176 | var dexOutputFile android.ModuleOutPath |
David Brazdil | 17ef563 | 2018-06-27 10:27:45 +0100 | [diff] [blame] | 1177 | dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1178 | if ctx.Failed() { |
| 1179 | return |
| 1180 | } |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1181 | |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 1182 | // Hidden API CSV generation and dex encoding |
David Brazdil | 9fc36a6 | 2019-01-18 11:12:05 +0000 | [diff] [blame] | 1183 | if !ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
| 1184 | isBootJar := inList(ctx.ModuleName(), ctx.Config().BootJars()) |
| 1185 | if isBootJar || inList(ctx.ModuleName(), ctx.Config().HiddenAPIExtraAppUsageJars()) { |
| 1186 | // Derive the greylist from classes jar. |
| 1187 | hiddenAPIGenerateCSV(ctx, j.implementationJarFile) |
| 1188 | } |
| 1189 | if isBootJar { |
| 1190 | hiddenAPIJar := android.PathForModuleOut(ctx, "hiddenapi", jarName) |
Colin Cross | cd964b3 | 2019-01-18 22:03:02 -0800 | [diff] [blame] | 1191 | hiddenAPIEncodeDex(ctx, hiddenAPIJar, dexOutputFile, j.deviceProperties.UncompressDex) |
David Brazdil | 9fc36a6 | 2019-01-18 11:12:05 +0000 | [diff] [blame] | 1192 | dexOutputFile = hiddenAPIJar |
| 1193 | } |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 1194 | } |
| 1195 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1196 | // merge dex jar with resources if necessary |
| 1197 | if j.resourceJar != nil { |
| 1198 | jars := android.Paths{dexOutputFile, j.resourceJar} |
| 1199 | combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName) |
| 1200 | TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{}, |
| 1201 | false, nil, nil) |
| 1202 | dexOutputFile = combinedJar |
| 1203 | } |
| 1204 | |
| 1205 | j.dexJarFile = dexOutputFile |
| 1206 | |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 1207 | // Dexpreopting |
Colin Cross | dc2da91 | 2019-01-05 22:13:05 -0800 | [diff] [blame] | 1208 | j.dexpreopter.isInstallable = Bool(j.properties.Installable) |
Colin Cross | 2fc72f6 | 2018-12-21 12:59:54 -0800 | [diff] [blame] | 1209 | j.dexpreopter.uncompressedDex = j.deviceProperties.UncompressDex |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1210 | dexOutputFile = j.dexpreopt(ctx, dexOutputFile) |
| 1211 | |
| 1212 | j.maybeStrippedDexJarFile = dexOutputFile |
| 1213 | |
Colin Cross | 3063b78 | 2018-08-15 11:19:12 -0700 | [diff] [blame] | 1214 | outputFile = dexOutputFile |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1215 | |
| 1216 | if ctx.Failed() { |
| 1217 | return |
| 1218 | } |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1219 | } else { |
| 1220 | outputFile = implementationAndResourcesJar |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1221 | } |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1222 | |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 1223 | ctx.CheckbuildFile(outputFile) |
Colin Cross | 3063b78 | 2018-08-15 11:19:12 -0700 | [diff] [blame] | 1224 | |
| 1225 | // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource |
| 1226 | j.outputFile = outputFile.WithoutRel() |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
Zoran Jovanovic | 8736ce2 | 2018-08-21 17:10:29 +0200 | [diff] [blame] | 1229 | // Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user, |
| 1230 | // since some of these flags may be used internally. |
| 1231 | func CheckKotlincFlags(ctx android.ModuleContext, flags []string) { |
| 1232 | for _, flag := range flags { |
| 1233 | flag = strings.TrimSpace(flag) |
| 1234 | |
| 1235 | if !strings.HasPrefix(flag, "-") { |
| 1236 | ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag) |
| 1237 | } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") { |
| 1238 | ctx.PropertyErrorf("kotlincflags", |
| 1239 | "Bad flag: `%s`, only use internal compiler for consistency.", flag) |
| 1240 | } else if inList(flag, config.KotlincIllegalFlags) { |
| 1241 | ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag) |
| 1242 | } else if flag == "-include-runtime" { |
| 1243 | ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag) |
| 1244 | } else { |
| 1245 | args := strings.Split(flag, " ") |
| 1246 | if args[0] == "-kotlin-home" { |
| 1247 | ctx.PropertyErrorf("kotlincflags", |
| 1248 | "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag) |
| 1249 | } |
| 1250 | } |
| 1251 | } |
| 1252 | } |
| 1253 | |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 1254 | func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths, |
Colin Cross | 55f63ea | 2018-08-27 12:37:09 -0700 | [diff] [blame] | 1255 | deps deps, flags javaBuilderFlags, jarName string, extraJars android.Paths) android.Path { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1256 | |
| 1257 | var jars android.Paths |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 1258 | if len(srcFiles) > 0 || len(srcJars) > 0 { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1259 | // Compile java sources into turbine.jar. |
| 1260 | turbineJar := android.PathForModuleOut(ctx, "turbine", jarName) |
| 1261 | TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags) |
| 1262 | if ctx.Failed() { |
| 1263 | return nil |
| 1264 | } |
| 1265 | jars = append(jars, turbineJar) |
| 1266 | } |
| 1267 | |
Colin Cross | 55f63ea | 2018-08-27 12:37:09 -0700 | [diff] [blame] | 1268 | jars = append(jars, extraJars...) |
| 1269 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1270 | // Combine any static header libraries into classes-header.jar. If there is only |
| 1271 | // one input jar this step will be skipped. |
| 1272 | var headerJar android.Path |
| 1273 | jars = append(jars, deps.staticHeaderJars...) |
| 1274 | |
Colin Cross | 5c6ecc1 | 2017-10-23 18:12:27 -0700 | [diff] [blame] | 1275 | // we cannot skip the combine step for now if there is only one jar |
| 1276 | // since we have to strip META-INF/TRANSITIVE dir from turbine.jar |
| 1277 | combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName) |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1278 | TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, |
| 1279 | false, nil, []string{"META-INF"}) |
Colin Cross | 5c6ecc1 | 2017-10-23 18:12:27 -0700 | [diff] [blame] | 1280 | headerJar = combinedJar |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1281 | |
| 1282 | if j.properties.Jarjar_rules != nil { |
| 1283 | jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules) |
| 1284 | // Transform classes.jar into classes-jarjar.jar |
| 1285 | jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName) |
| 1286 | TransformJarJar(ctx, jarjarFile, headerJar, jarjar_rules) |
| 1287 | headerJar = jarjarFile |
| 1288 | if ctx.Failed() { |
| 1289 | return nil |
| 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | return headerJar |
| 1294 | } |
| 1295 | |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 1296 | func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags, |
Colin Cross | 3063b78 | 2018-08-15 11:19:12 -0700 | [diff] [blame] | 1297 | classesJar android.Path, jarName string) android.ModuleOutPath { |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 1298 | |
Colin Cross | 7a3139e | 2017-12-19 13:57:50 -0800 | [diff] [blame] | 1299 | specs := j.jacocoModuleToZipCommand(ctx) |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 1300 | |
Colin Cross | 84c3882 | 2018-01-03 15:59:46 -0800 | [diff] [blame] | 1301 | jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName) |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 1302 | instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName) |
| 1303 | |
| 1304 | jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs) |
| 1305 | |
| 1306 | j.jacocoReportClassesFile = jacocoReportClassesFile |
| 1307 | |
| 1308 | return instrumentedJar |
| 1309 | } |
| 1310 | |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1311 | var _ Dependency = (*Module)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1312 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1313 | func (j *Module) HeaderJars() android.Paths { |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1314 | if j.headerJarFile == nil { |
| 1315 | return nil |
| 1316 | } |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1317 | return android.Paths{j.headerJarFile} |
| 1318 | } |
| 1319 | |
| 1320 | func (j *Module) ImplementationJars() android.Paths { |
shinwang | 9e4c07a | 2018-12-24 15:41:04 +0800 | [diff] [blame] | 1321 | if j.implementationJarFile == nil { |
| 1322 | return nil |
| 1323 | } |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1324 | return android.Paths{j.implementationJarFile} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1327 | func (j *Module) ResourceJars() android.Paths { |
| 1328 | if j.resourceJar == nil { |
| 1329 | return nil |
| 1330 | } |
| 1331 | return android.Paths{j.resourceJar} |
| 1332 | } |
| 1333 | |
| 1334 | func (j *Module) ImplementationAndResourcesJars() android.Paths { |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1335 | if j.implementationAndResourcesJar == nil { |
| 1336 | return nil |
| 1337 | } |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1338 | return android.Paths{j.implementationAndResourcesJar} |
| 1339 | } |
| 1340 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1341 | func (j *Module) AidlIncludeDirs() android.Paths { |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1342 | // exportAidlIncludeDirs is type android.Paths already |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 1343 | return j.exportAidlIncludeDirs |
| 1344 | } |
| 1345 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1346 | func (j *Module) ExportedSdkLibs() []string { |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1347 | // exportedSdkLibs is type []string |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1348 | return j.exportedSdkLibs |
| 1349 | } |
| 1350 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1351 | var _ logtagsProducer = (*Module)(nil) |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 1352 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1353 | func (j *Module) logtags() android.Paths { |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 1354 | return j.logtagsSrcs |
| 1355 | } |
| 1356 | |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 1357 | // Collect information for opening IDE project files in java/jdeps.go. |
| 1358 | func (j *Module) IDEInfo(dpInfo *android.IdeInfo) { |
| 1359 | dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...) |
| 1360 | dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...) |
| 1361 | dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...) |
| 1362 | if j.properties.Jarjar_rules != nil { |
| 1363 | dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, *j.properties.Jarjar_rules) |
| 1364 | } |
| 1365 | } |
| 1366 | |
| 1367 | func (j *Module) CompilerDeps() []string { |
| 1368 | jdeps := []string{} |
| 1369 | jdeps = append(jdeps, j.properties.Libs...) |
| 1370 | jdeps = append(jdeps, j.properties.Static_libs...) |
| 1371 | return jdeps |
| 1372 | } |
| 1373 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1374 | // |
| 1375 | // Java libraries (.jar file) |
| 1376 | // |
| 1377 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1378 | type Library struct { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1379 | Module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1380 | } |
| 1381 | |
Colin Cross | 2fc72f6 | 2018-12-21 12:59:54 -0800 | [diff] [blame] | 1382 | func (j *Library) shouldUncompressDex(ctx android.ModuleContext) bool { |
Vladimir Marko | e8b00d6 | 2018-12-21 15:54:16 +0000 | [diff] [blame] | 1383 | // Store uncompressed (and do not strip) dex files from boot class path jars that are not |
| 1384 | // part of the boot image. |
| 1385 | if inList(ctx.ModuleName(), ctx.Config().BootJars()) && |
| 1386 | !inList(ctx.ModuleName(), ctx.Config().PreoptBootJars()) { |
| 1387 | return true |
| 1388 | } |
Colin Cross | 2fc72f6 | 2018-12-21 12:59:54 -0800 | [diff] [blame] | 1389 | return false |
| 1390 | } |
| 1391 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1392 | func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1393 | j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", ctx.ModuleName()+".jar") |
| 1394 | j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary |
Colin Cross | 2fc72f6 | 2018-12-21 12:59:54 -0800 | [diff] [blame] | 1395 | j.deviceProperties.UncompressDex = j.shouldUncompressDex(ctx) |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1396 | j.compile(ctx) |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 1397 | |
Nicolas Geoffray | 4bdea39 | 2019-01-15 11:48:08 +0000 | [diff] [blame] | 1398 | if (Bool(j.properties.Installable) || ctx.Host()) && !android.DirectlyInAnyApex(ctx, ctx.ModuleName()) { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1399 | if j.deviceProperties.UncompressDex { |
| 1400 | alignedOutputFile := android.PathForModuleOut(ctx, "aligned", ctx.ModuleName()+".jar") |
| 1401 | TransformZipAlign(ctx, alignedOutputFile, j.outputFile) |
| 1402 | j.outputFile = alignedOutputFile |
| 1403 | } |
| 1404 | |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 1405 | j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), |
| 1406 | ctx.ModuleName()+".jar", j.outputFile) |
| 1407 | } |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1410 | func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1411 | j.deps(ctx) |
| 1412 | } |
| 1413 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1414 | func LibraryFactory() android.Module { |
| 1415 | module := &Library{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1416 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1417 | module.AddProperties( |
| 1418 | &module.Module.properties, |
| 1419 | &module.Module.deviceProperties, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1420 | &module.Module.dexpreoptProperties, |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1421 | &module.Module.protoProperties) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1422 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1423 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 1424 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1427 | func LibraryHostFactory() android.Module { |
| 1428 | module := &Library{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1429 | |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 1430 | module.AddProperties( |
| 1431 | &module.Module.properties, |
| 1432 | &module.Module.protoProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1433 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1434 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 1435 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 1436 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1437 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | // |
Colin Cross | b628ea5 | 2018-08-14 16:42:33 -0700 | [diff] [blame] | 1441 | // Java Tests |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1442 | // |
| 1443 | |
| 1444 | type testProperties struct { |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1445 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 1446 | // installed into. |
| 1447 | Test_suites []string `android:"arch_variant"` |
Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame] | 1448 | |
| 1449 | // the name of the test configuration (for example "AndroidTest.xml") that should be |
| 1450 | // installed with the module. |
| 1451 | Test_config *string `android:"arch_variant"` |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 1452 | |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 1453 | // the name of the test configuration template (for example "AndroidTestTemplate.xml") that |
| 1454 | // should be installed with the module. |
| 1455 | Test_config_template *string `android:"arch_variant"` |
| 1456 | |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 1457 | // list of files or filegroup modules that provide data that should be installed alongside |
| 1458 | // the test |
| 1459 | Data []string |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | type Test struct { |
| 1463 | Library |
| 1464 | |
| 1465 | testProperties testProperties |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1466 | |
| 1467 | testConfig android.Path |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 1468 | data android.Paths |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 1472 | j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template) |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 1473 | j.data = ctx.ExpandSources(j.testProperties.Data, nil) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1474 | |
| 1475 | j.Library.GenerateAndroidBuildActions(ctx) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | func (j *Test) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1479 | j.deps(ctx) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1480 | android.ExtractSourceDeps(ctx, j.testProperties.Test_config) |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 1481 | android.ExtractSourceDeps(ctx, j.testProperties.Test_config_template) |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 1482 | android.ExtractSourcesDeps(ctx, j.testProperties.Data) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | func TestFactory() android.Module { |
| 1486 | module := &Test{} |
| 1487 | |
| 1488 | module.AddProperties( |
| 1489 | &module.Module.properties, |
| 1490 | &module.Module.deviceProperties, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1491 | &module.Module.dexpreoptProperties, |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1492 | &module.Module.protoProperties, |
| 1493 | &module.testProperties) |
| 1494 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1495 | module.Module.properties.Installable = proptools.BoolPtr(true) |
Colin Cross | e302687 | 2019-01-05 22:30:13 -0800 | [diff] [blame] | 1496 | module.Module.dexpreopter.isTest = true |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1497 | |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1498 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1499 | return module |
| 1500 | } |
| 1501 | |
| 1502 | func TestHostFactory() android.Module { |
| 1503 | module := &Test{} |
| 1504 | |
| 1505 | module.AddProperties( |
| 1506 | &module.Module.properties, |
| 1507 | &module.Module.protoProperties, |
| 1508 | &module.testProperties) |
| 1509 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1510 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 1511 | |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1512 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1513 | return module |
| 1514 | } |
| 1515 | |
| 1516 | // |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1517 | // Java Binaries (.jar file plus wrapper script) |
| 1518 | // |
| 1519 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1520 | type binaryProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1521 | // installable script to execute the resulting jar |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 1522 | Wrapper *string |
Colin Cross | 094054a | 2018-10-17 15:10:48 -0700 | [diff] [blame] | 1523 | |
| 1524 | // Name of the class containing main to be inserted into the manifest as Main-Class. |
| 1525 | Main_class *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1526 | } |
| 1527 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1528 | type Binary struct { |
| 1529 | Library |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1530 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1531 | binaryProperties binaryProperties |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 1532 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1533 | isWrapperVariant bool |
| 1534 | |
Colin Cross | c331599 | 2017-12-08 19:12:36 -0800 | [diff] [blame] | 1535 | wrapperFile android.Path |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 1536 | binaryFile android.OutputPath |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
Alex Light | 2423717 | 2017-10-26 09:46:21 -0700 | [diff] [blame] | 1539 | func (j *Binary) HostToolPath() android.OptionalPath { |
| 1540 | return android.OptionalPathForPath(j.binaryFile) |
| 1541 | } |
| 1542 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1543 | func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1544 | if ctx.Arch().ArchType == android.Common { |
| 1545 | // Compile the jar |
Colin Cross | 094054a | 2018-10-17 15:10:48 -0700 | [diff] [blame] | 1546 | if j.binaryProperties.Main_class != nil { |
| 1547 | if j.properties.Manifest != nil { |
| 1548 | ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set") |
| 1549 | } |
| 1550 | manifestFile := android.PathForModuleOut(ctx, "manifest.txt") |
| 1551 | GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class)) |
| 1552 | j.overrideManifest = android.OptionalPathForPath(manifestFile) |
| 1553 | } |
| 1554 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1555 | j.Library.GenerateAndroidBuildActions(ctx) |
Nan Zhang | 3c807db | 2017-11-03 14:53:31 -0700 | [diff] [blame] | 1556 | } else { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1557 | // Handle the binary wrapper |
| 1558 | j.isWrapperVariant = true |
| 1559 | |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 1560 | if j.binaryProperties.Wrapper != nil { |
| 1561 | j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1562 | } else { |
| 1563 | j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh") |
| 1564 | } |
| 1565 | |
| 1566 | // Depend on the installed jar so that the wrapper doesn't get executed by |
| 1567 | // another build rule before the jar has been installed. |
| 1568 | jarFile := ctx.PrimaryModule().(*Binary).installFile |
| 1569 | |
| 1570 | j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"), |
| 1571 | ctx.ModuleName(), j.wrapperFile, jarFile) |
Nan Zhang | 3c807db | 2017-11-03 14:53:31 -0700 | [diff] [blame] | 1572 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1573 | } |
| 1574 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1575 | func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1576 | if ctx.Arch().ArchType == android.Common { |
| 1577 | j.deps(ctx) |
Colin Cross | c331599 | 2017-12-08 19:12:36 -0800 | [diff] [blame] | 1578 | } else { |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 1579 | android.ExtractSourceDeps(ctx, j.binaryProperties.Wrapper) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1580 | } |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1581 | } |
| 1582 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1583 | func BinaryFactory() android.Module { |
| 1584 | module := &Binary{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1585 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1586 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 1587 | &module.Module.properties, |
| 1588 | &module.Module.deviceProperties, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1589 | &module.Module.dexpreoptProperties, |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 1590 | &module.Module.protoProperties, |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 1591 | &module.binaryProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1592 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1593 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 1594 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1595 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst) |
| 1596 | android.InitDefaultableModule(module) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1597 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1600 | func BinaryHostFactory() android.Module { |
| 1601 | module := &Binary{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1602 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1603 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 1604 | &module.Module.properties, |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 1605 | &module.Module.protoProperties, |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 1606 | &module.binaryProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1607 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1608 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 1609 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1610 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst) |
| 1611 | android.InitDefaultableModule(module) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1612 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | // |
| 1616 | // Java prebuilts |
| 1617 | // |
| 1618 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1619 | type ImportProperties struct { |
| 1620 | Jars []string |
Colin Cross | 461bd1a | 2017-10-20 13:59:18 -0700 | [diff] [blame] | 1621 | |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 1622 | Sdk_version *string |
Colin Cross | 535e2cf | 2017-10-20 17:57:49 -0700 | [diff] [blame] | 1623 | |
| 1624 | Installable *bool |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1625 | |
| 1626 | // List of shared java libs that this module has dependencies to |
| 1627 | Libs []string |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1628 | |
| 1629 | // List of files to remove from the jar file(s) |
| 1630 | Exclude_files []string |
| 1631 | |
| 1632 | // List of directories to remove from the jar file(s) |
| 1633 | Exclude_dirs []string |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 1634 | |
| 1635 | // if set to true, run Jetifier against .jar file. Defaults to false. |
| 1636 | Jetifier_enabled *bool |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | type Import struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1640 | android.ModuleBase |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 1641 | android.DefaultableModuleBase |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 1642 | prebuilt android.Prebuilt |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1643 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1644 | properties ImportProperties |
| 1645 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1646 | combinedClasspathFile android.Path |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1647 | exportedSdkLibs []string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1648 | } |
| 1649 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 1650 | func (j *Import) sdkVersion() string { |
| 1651 | return String(j.properties.Sdk_version) |
| 1652 | } |
| 1653 | |
| 1654 | func (j *Import) minSdkVersion() string { |
| 1655 | return j.sdkVersion() |
| 1656 | } |
| 1657 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1658 | func (j *Import) Prebuilt() *android.Prebuilt { |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 1659 | return &j.prebuilt |
| 1660 | } |
| 1661 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1662 | func (j *Import) PrebuiltSrcs() []string { |
| 1663 | return j.properties.Jars |
| 1664 | } |
| 1665 | |
| 1666 | func (j *Import) Name() string { |
Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 1667 | return j.prebuilt.Name(j.ModuleBase.Name()) |
| 1668 | } |
| 1669 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1670 | func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1671 | android.ExtractSourcesDeps(ctx, j.properties.Jars) |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 1672 | ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1675 | func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1676 | jars := ctx.ExpandSources(j.properties.Jars, nil) |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 1677 | |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 1678 | jarName := ctx.ModuleName() + ".jar" |
| 1679 | outputFile := android.PathForModuleOut(ctx, "combined", jarName) |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1680 | TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{}, |
| 1681 | false, j.properties.Exclude_files, j.properties.Exclude_dirs) |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 1682 | if Bool(j.properties.Jetifier_enabled) { |
| 1683 | inputFile := outputFile |
| 1684 | outputFile = android.PathForModuleOut(ctx, "jetifier", jarName) |
| 1685 | TransformJetifier(ctx, outputFile, inputFile) |
| 1686 | } |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1687 | j.combinedClasspathFile = outputFile |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1688 | |
| 1689 | ctx.VisitDirectDeps(func(module android.Module) { |
| 1690 | otherName := ctx.OtherModuleName(module) |
| 1691 | tag := ctx.OtherModuleDependencyTag(module) |
| 1692 | |
| 1693 | switch dep := module.(type) { |
| 1694 | case Dependency: |
| 1695 | switch tag { |
| 1696 | case libTag, staticLibTag: |
| 1697 | // sdk lib names from dependencies are re-exported |
| 1698 | j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...) |
| 1699 | } |
| 1700 | case SdkLibraryDependency: |
| 1701 | switch tag { |
| 1702 | case libTag: |
| 1703 | // names of sdk libs that are directly depended are exported |
| 1704 | j.exportedSdkLibs = append(j.exportedSdkLibs, otherName) |
| 1705 | } |
| 1706 | } |
| 1707 | }) |
| 1708 | |
| 1709 | j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs) |
Nan Zhang | 4973ecf | 2018-08-10 13:42:12 -0700 | [diff] [blame] | 1710 | if Bool(j.properties.Installable) { |
| 1711 | ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), |
| 1712 | ctx.ModuleName()+".jar", outputFile) |
| 1713 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1716 | var _ Dependency = (*Import)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1717 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1718 | func (j *Import) HeaderJars() android.Paths { |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1719 | if j.combinedClasspathFile == nil { |
| 1720 | return nil |
| 1721 | } |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1722 | return android.Paths{j.combinedClasspathFile} |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | func (j *Import) ImplementationJars() android.Paths { |
shinwang | 9e4c07a | 2018-12-24 15:41:04 +0800 | [diff] [blame] | 1726 | if j.combinedClasspathFile == nil { |
| 1727 | return nil |
| 1728 | } |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1729 | return android.Paths{j.combinedClasspathFile} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1732 | func (j *Import) ResourceJars() android.Paths { |
| 1733 | return nil |
| 1734 | } |
| 1735 | |
| 1736 | func (j *Import) ImplementationAndResourcesJars() android.Paths { |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1737 | if j.combinedClasspathFile == nil { |
| 1738 | return nil |
| 1739 | } |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1740 | return android.Paths{j.combinedClasspathFile} |
| 1741 | } |
| 1742 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1743 | func (j *Import) AidlIncludeDirs() android.Paths { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 1744 | return nil |
| 1745 | } |
| 1746 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1747 | func (j *Import) ExportedSdkLibs() []string { |
| 1748 | return j.exportedSdkLibs |
| 1749 | } |
| 1750 | |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1751 | // Add compile time check for interface implementation |
| 1752 | var _ android.IDEInfo = (*Import)(nil) |
| 1753 | var _ android.IDECustomizedModuleName = (*Import)(nil) |
| 1754 | |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 1755 | // Collect information for opening IDE project files in java/jdeps.go. |
| 1756 | const ( |
| 1757 | removedPrefix = "prebuilt_" |
| 1758 | ) |
| 1759 | |
| 1760 | func (j *Import) IDEInfo(dpInfo *android.IdeInfo) { |
| 1761 | dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...) |
| 1762 | } |
| 1763 | |
| 1764 | func (j *Import) IDECustomizedModuleName() string { |
| 1765 | // TODO(b/113562217): Extract the base module name from the Import name, often the Import name |
| 1766 | // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better |
| 1767 | // solution to get the Import name. |
| 1768 | name := j.Name() |
| 1769 | if strings.HasPrefix(name, removedPrefix) { |
patricktu | bb640e0 | 2018-10-11 18:33:16 +0800 | [diff] [blame] | 1770 | name = strings.TrimPrefix(name, removedPrefix) |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 1771 | } |
| 1772 | return name |
| 1773 | } |
| 1774 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1775 | var _ android.PrebuiltInterface = (*Import)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1776 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1777 | func ImportFactory() android.Module { |
| 1778 | module := &Import{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1779 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1780 | module.AddProperties(&module.properties) |
| 1781 | |
| 1782 | android.InitPrebuiltModule(module, &module.properties.Jars) |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 1783 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1784 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1787 | func ImportFactoryHost() android.Module { |
| 1788 | module := &Import{} |
| 1789 | |
| 1790 | module.AddProperties(&module.properties) |
| 1791 | |
| 1792 | android.InitPrebuiltModule(module, &module.properties.Jars) |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 1793 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1794 | return module |
| 1795 | } |
| 1796 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 1797 | // |
| 1798 | // Defaults |
| 1799 | // |
| 1800 | type Defaults struct { |
| 1801 | android.ModuleBase |
| 1802 | android.DefaultsModuleBase |
| 1803 | } |
| 1804 | |
| 1805 | func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1806 | } |
| 1807 | |
| 1808 | func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1809 | } |
| 1810 | |
| 1811 | func defaultsFactory() android.Module { |
| 1812 | return DefaultsFactory() |
| 1813 | } |
| 1814 | |
| 1815 | func DefaultsFactory(props ...interface{}) android.Module { |
| 1816 | module := &Defaults{} |
| 1817 | |
| 1818 | module.AddProperties(props...) |
| 1819 | module.AddProperties( |
| 1820 | &CompilerProperties{}, |
| 1821 | &CompilerDeviceProperties{}, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1822 | &DexpreoptProperties{}, |
Dan Willemsen | 6424d17 | 2018-03-08 13:27:59 -0800 | [diff] [blame] | 1823 | &android.ProtoProperties{}, |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 1824 | &aaptProperties{}, |
| 1825 | &androidLibraryProperties{}, |
| 1826 | &appProperties{}, |
| 1827 | &appTestProperties{}, |
| 1828 | &ImportProperties{}, |
| 1829 | &AARImportProperties{}, |
| 1830 | &sdkLibraryProperties{}, |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 1831 | ) |
| 1832 | |
| 1833 | android.InitDefaultsModule(module) |
| 1834 | |
| 1835 | return module |
| 1836 | } |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 1837 | |
| 1838 | var Bool = proptools.Bool |
Colin Cross | 38b40df | 2018-04-10 16:14:46 -0700 | [diff] [blame] | 1839 | var BoolDefault = proptools.BoolDefault |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 1840 | var String = proptools.String |
Colin Cross | 0d0ba59 | 2018-02-20 13:33:42 -0800 | [diff] [blame] | 1841 | var inList = android.InList |