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