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