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