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