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