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