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