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