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