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