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