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