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