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