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 | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 44 | android.RegisterModuleType("android_app", AndroidAppFactory) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 45 | |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 46 | android.RegisterSingletonType("logtags", LogtagsSingleton) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 49 | // TODO: |
| 50 | // Autogenerated files: |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 51 | // Renderscript |
| 52 | // Post-jar passes: |
| 53 | // Proguard |
Colin Cross | ba21113 | 2017-06-22 15:36:39 -0700 | [diff] [blame] | 54 | // Jacoco |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 55 | // Jarjar |
| 56 | // Dex |
| 57 | // Rmtypedefs |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 58 | // DroidDoc |
| 59 | // Findbugs |
| 60 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 61 | type CompilerProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 62 | // list of source files used to compile the Java module. May be .java, .logtags, .proto, |
| 63 | // or .aidl files. |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 64 | Srcs []string `android:"arch_variant"` |
| 65 | |
| 66 | // list of source files that should not be used to build the Java module. |
| 67 | // This is most useful in the arch/multilib variants to remove non-common files |
| 68 | Exclude_srcs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 69 | |
| 70 | // list of directories containing Java resources |
Colin Cross | 86a63ff | 2017-09-27 17:33:10 -0700 | [diff] [blame] | 71 | Java_resource_dirs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 72 | |
Colin Cross | 86a63ff | 2017-09-27 17:33:10 -0700 | [diff] [blame] | 73 | // list of directories that should be excluded from java_resource_dirs |
| 74 | Exclude_java_resource_dirs []string `android:"arch_variant"` |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 75 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 76 | // list of files to use as Java resources |
| 77 | Java_resources []string `android:"arch_variant"` |
| 78 | |
| 79 | // list of files that should be excluded from java_resources |
| 80 | Exclude_java_resources []string `android:"arch_variant"` |
| 81 | |
Colin Cross | fa5eb23 | 2017-10-01 20:33:03 -0700 | [diff] [blame] | 82 | // don't build against the default libraries (bootclasspath, legacy-test, core-junit, |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 83 | // ext, and framework for device targets) |
Colin Cross | 76b5f0c | 2017-08-29 16:02:06 -0700 | [diff] [blame] | 84 | No_standard_libs *bool |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 85 | |
Colin Cross | fa5eb23 | 2017-10-01 20:33:03 -0700 | [diff] [blame] | 86 | // don't build against the framework libraries (legacy-test, core-junit, |
| 87 | // ext, and framework for device targets) |
| 88 | No_framework_libs *bool |
| 89 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 90 | // list of module-specific flags that will be used for javac compiles |
| 91 | Javacflags []string `android:"arch_variant"` |
| 92 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 93 | // list of of java libraries that will be in the classpath |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 94 | Libs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 95 | |
| 96 | // list of java libraries that will be compiled into the resulting jar |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 97 | Static_libs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 98 | |
| 99 | // manifest file to be included in resulting jar |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 100 | Manifest *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 101 | |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 102 | // if not blank, run jarjar using the specified rules file |
Colin Cross | 975f9f7 | 2017-10-17 13:55:55 -0700 | [diff] [blame] | 103 | Jarjar_rules *string `android:"arch_variant"` |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 104 | |
| 105 | // If not blank, set the java version passed to javac as -source and -target |
| 106 | Java_version *string |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 107 | |
| 108 | // If set to false, don't allow this module to be installed. Defaults to true. |
| 109 | Installable *bool |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 110 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 111 | // If set to true, include sources used to compile the module in to the final jar |
| 112 | Include_srcs *bool |
| 113 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 114 | // List of modules to use as annotation processors |
| 115 | Annotation_processors []string |
| 116 | |
| 117 | // List of classes to pass to javac to use as annotation processors |
| 118 | Annotation_processor_classes []string |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 119 | |
| 120 | Openjdk9 struct { |
| 121 | // List of source files that should only be used when passing -source 1.9 |
| 122 | Srcs []string |
| 123 | |
| 124 | // List of javac flags that should only be used when passing -source 1.9 |
| 125 | Javacflags []string |
| 126 | } |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 129 | type CompilerDeviceProperties struct { |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 130 | // list of module-specific flags that will be used for dex compiles |
| 131 | Dxflags []string `android:"arch_variant"` |
| 132 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 133 | // if not blank, set to the version of the sdk to compile against |
| 134 | Sdk_version string |
| 135 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 136 | // directories to pass to aidl tool |
| 137 | Aidl_includes []string |
| 138 | |
| 139 | // directories that should be added as include directories |
| 140 | // for any aidl sources of modules that depend on this module |
| 141 | Export_aidl_include_dirs []string |
Colin Cross | 9243010 | 2017-10-09 14:59:32 -0700 | [diff] [blame] | 142 | |
| 143 | // If true, export a copy of the module as a -hostdex module for host testing. |
| 144 | Hostdex *bool |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 145 | |
Colin Cross | a22116e | 2017-10-19 14:18:58 -0700 | [diff] [blame] | 146 | // If false, prevent dexpreopting and stripping the dex file from the final jar. Defaults to |
| 147 | // true. |
| 148 | Dex_preopt *bool |
| 149 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 150 | // When targeting 1.9, override the modules to use with --system |
| 151 | System_modules *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 154 | // Module contains the properties and members used by all java module types |
| 155 | type Module struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 156 | android.ModuleBase |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 157 | android.DefaultableModuleBase |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 158 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 159 | properties CompilerProperties |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 160 | protoProperties android.ProtoProperties |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 161 | deviceProperties CompilerDeviceProperties |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 162 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 163 | // header jar file suitable for inserting into the bootclasspath/classpath of another compile |
| 164 | headerJarFile android.Path |
| 165 | |
| 166 | // full implementation jar file suitable for static dependency of another module compile |
| 167 | implementationJarFile android.Path |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 168 | |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 169 | // output file containing classes.dex |
| 170 | dexJarFile android.Path |
| 171 | |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 172 | // output file suitable for installing or running |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 173 | outputFile android.Path |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 174 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 175 | exportAidlIncludeDirs android.Paths |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 176 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 177 | logtagsSrcs android.Paths |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 178 | |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 179 | // jars containing source files that should be included in the javac command line, |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 180 | // for example R.java generated by aapt for android apps |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 181 | ExtraSrcJars android.Paths |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 182 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 183 | // installed file for binary dependency |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 184 | installFile android.Path |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 187 | type Dependency interface { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 188 | HeaderJars() android.Paths |
| 189 | ImplementationJars() android.Paths |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 190 | AidlIncludeDirs() android.Paths |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 193 | func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { |
| 194 | android.InitAndroidArchModule(module, hod, android.MultilibCommon) |
| 195 | android.InitDefaultableModule(module) |
| 196 | } |
| 197 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 198 | type dependencyTag struct { |
| 199 | blueprint.BaseDependencyTag |
| 200 | name string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 203 | var ( |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 204 | staticLibTag = dependencyTag{name: "staticlib"} |
| 205 | libTag = dependencyTag{name: "javalib"} |
| 206 | bootClasspathTag = dependencyTag{name: "bootclasspath"} |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 207 | systemModulesTag = dependencyTag{name: "system modules"} |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 208 | frameworkResTag = dependencyTag{name: "framework-res"} |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 209 | kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"} |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 210 | ) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 211 | |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 212 | type sdkDep struct { |
Colin Cross | 47ff252 | 2017-10-02 14:22:08 -0700 | [diff] [blame] | 213 | useModule, useFiles, useDefaultLibs, invalidVersion bool |
| 214 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 215 | module string |
| 216 | systemModules string |
| 217 | |
| 218 | jar android.Path |
| 219 | aidl android.Path |
| 220 | } |
| 221 | |
| 222 | func sdkStringToNumber(ctx android.BaseContext, v string) int { |
| 223 | switch v { |
| 224 | case "", "current", "system_current", "test_current": |
| 225 | return 10000 |
| 226 | default: |
| 227 | if i, err := strconv.Atoi(v); err != nil { |
| 228 | ctx.PropertyErrorf("sdk_version", "invalid sdk version") |
| 229 | return -1 |
| 230 | } else { |
| 231 | return i |
| 232 | } |
| 233 | } |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | func decodeSdkDep(ctx android.BaseContext, v string) sdkDep { |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 237 | i := sdkStringToNumber(ctx, v) |
| 238 | if i == -1 { |
| 239 | // Invalid sdk version, error handled by sdkStringToNumber. |
| 240 | return sdkDep{} |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | toFile := func(v string) sdkDep { |
| 244 | dir := filepath.Join("prebuilts/sdk", v) |
| 245 | jar := filepath.Join(dir, "android.jar") |
| 246 | aidl := filepath.Join(dir, "framework.aidl") |
| 247 | jarPath := android.ExistentPathForSource(ctx, "sdkdir", jar) |
| 248 | aidlPath := android.ExistentPathForSource(ctx, "sdkdir", aidl) |
Colin Cross | 47ff252 | 2017-10-02 14:22:08 -0700 | [diff] [blame] | 249 | |
| 250 | if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.AConfig().AllowMissingDependencies() { |
| 251 | return sdkDep{ |
| 252 | invalidVersion: true, |
| 253 | module: "sdk_v" + v, |
| 254 | } |
| 255 | } |
| 256 | |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 257 | if !jarPath.Valid() { |
| 258 | ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar) |
| 259 | return sdkDep{} |
| 260 | } |
Colin Cross | 47ff252 | 2017-10-02 14:22:08 -0700 | [diff] [blame] | 261 | |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 262 | if !aidlPath.Valid() { |
| 263 | ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl) |
| 264 | return sdkDep{} |
| 265 | } |
Colin Cross | 47ff252 | 2017-10-02 14:22:08 -0700 | [diff] [blame] | 266 | |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 267 | return sdkDep{ |
| 268 | useFiles: true, |
| 269 | jar: jarPath.Path(), |
| 270 | aidl: aidlPath.Path(), |
| 271 | } |
| 272 | } |
| 273 | |
Colin Cross | 2ebc476 | 2017-10-20 14:00:31 -0700 | [diff] [blame] | 274 | //toModule := func(m string) sdkDep { |
| 275 | // return sdkDep{ |
| 276 | // useModule: true, |
| 277 | // module: m, |
| 278 | // systemModules: m + "_system_modules", |
| 279 | // } |
| 280 | //} |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 281 | |
Colin Cross | 8b9d37b | 2017-09-22 15:30:06 -0700 | [diff] [blame] | 282 | if ctx.AConfig().UnbundledBuild() && v != "" { |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 283 | return toFile(v) |
| 284 | } |
| 285 | |
| 286 | switch v { |
| 287 | case "": |
| 288 | return sdkDep{ |
| 289 | useDefaultLibs: true, |
| 290 | } |
Colin Cross | 2ebc476 | 2017-10-20 14:00:31 -0700 | [diff] [blame] | 291 | // TODO(ccross): re-enable these once we generate stubs, until then |
| 292 | // use the stubs in prebuilts/sdk/*current |
| 293 | //case "current": |
| 294 | // return toModule("android_stubs_current") |
| 295 | //case "system_current": |
| 296 | // return toModule("android_system_stubs_current") |
| 297 | //case "test_current": |
| 298 | // return toModule("android_test_stubs_current") |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 299 | default: |
| 300 | return toFile(v) |
| 301 | } |
| 302 | } |
| 303 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 304 | func (j *Module) deps(ctx android.BottomUpMutatorContext) { |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 305 | if ctx.Device() { |
| 306 | if !proptools.Bool(j.properties.No_standard_libs) { |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 307 | sdkDep := decodeSdkDep(ctx, j.deviceProperties.Sdk_version) |
| 308 | if sdkDep.useDefaultLibs { |
Colin Cross | cb2c929 | 2017-09-23 19:57:16 -0700 | [diff] [blame] | 309 | ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...) |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 310 | if ctx.AConfig().TargetOpenJDK9() { |
| 311 | ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules) |
| 312 | } |
Colin Cross | fa5eb23 | 2017-10-01 20:33:03 -0700 | [diff] [blame] | 313 | if !proptools.Bool(j.properties.No_framework_libs) { |
| 314 | ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...) |
| 315 | } |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 316 | } else if sdkDep.useModule { |
| 317 | if ctx.AConfig().TargetOpenJDK9() { |
| 318 | ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules) |
| 319 | } |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 320 | ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.module) |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 321 | } |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 322 | } else if j.deviceProperties.System_modules == nil { |
| 323 | ctx.PropertyErrorf("no_standard_libs", |
| 324 | "system_modules is required to be set when no_standard_libs is true, did you mean no_framework_libs?") |
| 325 | } else if *j.deviceProperties.System_modules != "none" && ctx.AConfig().TargetOpenJDK9() { |
| 326 | ctx.AddDependency(ctx.Module(), systemModulesTag, *j.deviceProperties.System_modules) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 327 | } |
| 328 | } |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 329 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 330 | ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...) |
| 331 | ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...) |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 332 | ctx.AddDependency(ctx.Module(), libTag, j.properties.Annotation_processors...) |
Colin Cross | 7f9036c | 2017-08-30 13:27:57 -0700 | [diff] [blame] | 333 | |
| 334 | android.ExtractSourcesDeps(ctx, j.properties.Srcs) |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 335 | android.ExtractSourcesDeps(ctx, j.properties.Java_resources) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 336 | |
| 337 | if j.hasSrcExt(".proto") { |
| 338 | protoDeps(ctx, &j.protoProperties) |
| 339 | } |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 340 | |
| 341 | if j.hasSrcExt(".kt") { |
| 342 | // TODO(ccross): move this to a mutator pass that can tell if generated sources contain |
| 343 | // Kotlin files |
| 344 | ctx.AddDependency(ctx.Module(), kotlinStdlibTag, "kotlin-stdlib") |
| 345 | } |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | func hasSrcExt(srcs []string, ext string) bool { |
| 349 | for _, src := range srcs { |
| 350 | if filepath.Ext(src) == ext { |
| 351 | return true |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | return false |
| 356 | } |
| 357 | |
| 358 | func (j *Module) hasSrcExt(ext string) bool { |
| 359 | return hasSrcExt(j.properties.Srcs, ext) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 362 | func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 363 | aidlIncludeDirs android.Paths) []string { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 364 | |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 365 | localAidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl_includes) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 366 | |
| 367 | var flags []string |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 368 | if aidlPreprocess.Valid() { |
| 369 | flags = append(flags, "-p"+aidlPreprocess.String()) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 370 | } else { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 371 | flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I")) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 374 | flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I")) |
| 375 | flags = append(flags, android.JoinWithPrefix(localAidlIncludes.Strings(), "-I")) |
| 376 | flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String()) |
Colin Cross | e243c23 | 2017-10-21 15:16:37 -0700 | [diff] [blame] | 377 | if src := android.ExistentPathForSource(ctx, "", ctx.ModuleDir(), "src"); src.Valid() { |
Colin Cross | d48633a | 2017-07-13 14:41:17 -0700 | [diff] [blame] | 378 | flags = append(flags, "-I"+src.String()) |
| 379 | } |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 380 | |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 381 | return flags |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 384 | type deps struct { |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 385 | classpath android.Paths |
| 386 | bootClasspath android.Paths |
| 387 | staticJars android.Paths |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 388 | staticHeaderJars android.Paths |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 389 | staticJarResources android.Paths |
| 390 | aidlIncludeDirs android.Paths |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 391 | srcJars android.Paths |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 392 | systemModules android.Path |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 393 | aidlPreprocess android.OptionalPath |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 394 | kotlinStdlib android.Paths |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 395 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 396 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 397 | func (j *Module) collectDeps(ctx android.ModuleContext) deps { |
| 398 | var deps deps |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 399 | |
| 400 | sdkDep := decodeSdkDep(ctx, j.deviceProperties.Sdk_version) |
Colin Cross | 47ff252 | 2017-10-02 14:22:08 -0700 | [diff] [blame] | 401 | if sdkDep.invalidVersion { |
| 402 | ctx.AddMissingDependencies([]string{sdkDep.module}) |
| 403 | } else if sdkDep.useFiles { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 404 | // sdkDep.jar is actually equivalent to turbine header.jar. |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 405 | deps.classpath = append(deps.classpath, sdkDep.jar) |
| 406 | deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl) |
| 407 | } |
| 408 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 409 | ctx.VisitDirectDeps(func(module android.Module) { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 410 | otherName := ctx.OtherModuleName(module) |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 411 | tag := ctx.OtherModuleDependencyTag(module) |
| 412 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 413 | dep, _ := module.(Dependency) |
| 414 | if dep == nil { |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 415 | switch tag { |
| 416 | case android.DefaultsDepTag, android.SourceDepTag: |
Dan Willemsen | d6ba0d5 | 2017-09-13 15:46:47 -0700 | [diff] [blame] | 417 | // Nothing to do |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 418 | case systemModulesTag: |
| 419 | if deps.systemModules != nil { |
| 420 | panic("Found two system module dependencies") |
| 421 | } |
| 422 | sm := module.(*SystemModules) |
| 423 | if sm.outputFile == nil { |
| 424 | panic("Missing directory for system module dependency") |
| 425 | } |
| 426 | deps.systemModules = sm.outputFile |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 427 | default: |
| 428 | ctx.ModuleErrorf("depends on non-java module %q", otherName) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 429 | } |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 430 | return |
| 431 | } |
| 432 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 433 | switch tag { |
| 434 | case bootClasspathTag: |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 435 | deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...) |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 436 | case libTag: |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 437 | deps.classpath = append(deps.classpath, dep.HeaderJars()...) |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 438 | case staticLibTag: |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 439 | deps.classpath = append(deps.classpath, dep.HeaderJars()...) |
| 440 | deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...) |
| 441 | deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...) |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 442 | case frameworkResTag: |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 443 | if ctx.ModuleName() == "framework" { |
| 444 | // framework.jar has a one-off dependency on the R.java and Manifest.java files |
| 445 | // generated by framework-res.apk |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 446 | // TODO(ccross): aapt java files should go in a src jar |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 447 | } |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 448 | case kotlinStdlibTag: |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 449 | deps.kotlinStdlib = dep.HeaderJars() |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 450 | default: |
| 451 | panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 452 | } |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 453 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 454 | deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 455 | }) |
| 456 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 457 | return deps |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 460 | func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 461 | |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 462 | var flags javaBuilderFlags |
| 463 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 464 | // javac flags. |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 465 | javacFlags := j.properties.Javacflags |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 466 | if ctx.AConfig().TargetOpenJDK9() { |
| 467 | javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 468 | } |
| 469 | if len(javacFlags) > 0 { |
| 470 | // optimization. |
| 471 | ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " ")) |
| 472 | flags.javacFlags = "$javacFlags" |
Colin Cross | 4f26bc0 | 2017-09-06 12:52:16 -0700 | [diff] [blame] | 473 | } |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 474 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 475 | // javaVersion flag. |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 476 | sdk := sdkStringToNumber(ctx, j.deviceProperties.Sdk_version) |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 477 | if j.properties.Java_version != nil { |
| 478 | flags.javaVersion = *j.properties.Java_version |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 479 | } else if ctx.Device() && sdk <= 23 { |
| 480 | flags.javaVersion = "1.7" |
| 481 | } else if ctx.Device() && sdk <= 26 || !ctx.AConfig().TargetOpenJDK9() { |
| 482 | flags.javaVersion = "1.8" |
Colin Cross | 2ebc476 | 2017-10-20 14:00:31 -0700 | [diff] [blame] | 483 | } else if ctx.Device() && j.deviceProperties.Sdk_version != "" && sdk == 10000 { |
| 484 | // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current" |
| 485 | flags.javaVersion = "1.8" |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 486 | } else { |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 487 | flags.javaVersion = "1.9" |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 490 | // classpath |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 491 | flags.bootClasspath.AddPaths(deps.bootClasspath) |
| 492 | flags.classpath.AddPaths(deps.classpath) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 493 | // systemModules |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 494 | if deps.systemModules != nil { |
| 495 | flags.systemModules = append(flags.systemModules, deps.systemModules) |
| 496 | } |
| 497 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 498 | // aidl flags. |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 499 | aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs) |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 500 | if len(aidlFlags) > 0 { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 501 | // optimization. |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 502 | ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " ")) |
| 503 | flags.aidlFlags = "$aidlFlags" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 506 | return flags |
| 507 | } |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 508 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 509 | func (j *Module) compile(ctx android.ModuleContext) { |
| 510 | |
| 511 | j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Export_aidl_include_dirs) |
| 512 | |
| 513 | deps := j.collectDeps(ctx) |
| 514 | flags := j.collectBuilderFlags(ctx, deps) |
| 515 | |
| 516 | if ctx.AConfig().TargetOpenJDK9() { |
| 517 | j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...) |
| 518 | } |
| 519 | srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 520 | if hasSrcExt(srcFiles.Strings(), ".proto") { |
| 521 | flags = protoFlags(ctx, &j.protoProperties, flags) |
| 522 | } |
| 523 | |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame^] | 524 | var srcJars android.Paths |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 525 | srcFiles, srcJars = j.genSources(ctx, srcFiles, flags) |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 526 | srcJars = append(srcJars, deps.srcJars...) |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 527 | srcJars = append(srcJars, j.ExtraSrcJars...) |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 528 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 529 | var jars android.Paths |
| 530 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 531 | jarName := ctx.ModuleName() + ".jar" |
| 532 | |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 533 | if srcFiles.HasExt(".kt") { |
| 534 | // If there are kotlin files, compile them first but pass all the kotlin and java files |
| 535 | // kotlinc will use the java files to resolve types referenced by the kotlin files, but |
| 536 | // won't emit any classes for them. |
| 537 | |
| 538 | flags.kotlincFlags = "-no-stdlib" |
| 539 | if ctx.Device() { |
| 540 | flags.kotlincFlags += " -no-jdk" |
| 541 | } |
| 542 | |
| 543 | flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...) |
| 544 | flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...) |
| 545 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 546 | kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName) |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 547 | TransformKotlinToClasses(ctx, kotlinJar, srcFiles, srcJars, flags) |
| 548 | if ctx.Failed() { |
| 549 | return |
| 550 | } |
| 551 | |
| 552 | // Make javac rule depend on the kotlinc rule |
| 553 | flags.classpath = append(flags.classpath, kotlinJar) |
| 554 | // Jar kotlin classes into the final jar after javac |
| 555 | jars = append(jars, kotlinJar) |
| 556 | jars = append(jars, deps.kotlinStdlib...) |
| 557 | } |
| 558 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 559 | javaSrcFiles := srcFiles.FilterByExt(".java") |
| 560 | var uniqueSrcFiles android.Paths |
| 561 | set := make(map[string]bool) |
| 562 | for _, v := range javaSrcFiles { |
| 563 | if _, found := set[v.String()]; !found { |
| 564 | set[v.String()] = true |
| 565 | uniqueSrcFiles = append(uniqueSrcFiles, v) |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | if ctx.Device() && !ctx.AConfig().IsEnvFalse("TURBINE_ENABLED") { |
| 570 | // If sdk jar is java module, then directly return classesJar as header.jar |
| 571 | if j.Name() != "android_stubs_current" && j.Name() != "android_system_stubs_current" && |
| 572 | j.Name() != "android_test_stubs_current" { |
| 573 | j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName) |
| 574 | if ctx.Failed() { |
| 575 | return |
| 576 | } |
| 577 | } |
| 578 | } |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame^] | 579 | if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 { |
Colin Cross | d689143 | 2017-09-27 17:39:56 -0700 | [diff] [blame] | 580 | var extraJarDeps android.Paths |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 581 | if ctx.AConfig().IsEnvTrue("RUN_ERROR_PRONE") { |
| 582 | // If error-prone is enabled, add an additional rule to compile the java files into |
| 583 | // 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] | 584 | // a rebuild when error-prone is turned off). |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 585 | // TODO(ccross): Once we always compile with javac9 we may be able to conditionally |
| 586 | // enable error-prone without affecting the output class files. |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 587 | errorprone := android.PathForModuleOut(ctx, "errorprone", jarName) |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 588 | RunErrorProne(ctx, errorprone, javaSrcFiles, srcJars, flags) |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 589 | extraJarDeps = append(extraJarDeps, errorprone) |
| 590 | } |
| 591 | |
Colin Cross | d689143 | 2017-09-27 17:39:56 -0700 | [diff] [blame] | 592 | // Compile java sources into .class files |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 593 | classes := android.PathForModuleOut(ctx, "javac", jarName) |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 594 | TransformJavaToClasses(ctx, classes, javaSrcFiles, srcJars, flags, extraJarDeps) |
Colin Cross | d689143 | 2017-09-27 17:39:56 -0700 | [diff] [blame] | 595 | if ctx.Failed() { |
| 596 | return |
| 597 | } |
| 598 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 599 | jars = append(jars, classes) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 602 | dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs) |
| 603 | fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources) |
| 604 | |
| 605 | var resArgs []string |
| 606 | var resDeps android.Paths |
| 607 | |
| 608 | resArgs = append(resArgs, dirArgs...) |
| 609 | resDeps = append(resDeps, dirDeps...) |
| 610 | |
| 611 | resArgs = append(resArgs, fileArgs...) |
| 612 | resDeps = append(resDeps, fileDeps...) |
| 613 | |
| 614 | if proptools.Bool(j.properties.Include_srcs) { |
Colin Cross | 2372923 | 2017-10-03 13:14:07 -0700 | [diff] [blame] | 615 | srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs) |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 616 | resArgs = append(resArgs, srcArgs...) |
| 617 | resDeps = append(resDeps, srcDeps...) |
| 618 | } |
Colin Cross | 40a3671 | 2017-09-27 17:41:35 -0700 | [diff] [blame] | 619 | |
| 620 | if len(resArgs) > 0 { |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 621 | resourceJar := android.PathForModuleOut(ctx, "res", jarName) |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 622 | TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps) |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 623 | if ctx.Failed() { |
| 624 | return |
| 625 | } |
Colin Cross | 2097830 | 2015-04-10 17:05:07 -0700 | [diff] [blame] | 626 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 627 | jars = append(jars, resourceJar) |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 630 | // 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] | 631 | jars = append(jars, deps.staticJars...) |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 632 | |
Colin Cross | 635acc9 | 2017-09-12 22:50:46 -0700 | [diff] [blame] | 633 | manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest) |
| 634 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 635 | // 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] | 636 | // 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] | 637 | var outputFile android.Path |
| 638 | |
| 639 | if len(jars) == 1 && !manifest.Valid() { |
| 640 | // Optimization: skip the combine step if there is nothing to do |
| 641 | outputFile = jars[0] |
| 642 | } else { |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 643 | combinedJar := android.PathForModuleOut(ctx, "combined", jarName) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 644 | TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest, false, nil) |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 645 | outputFile = combinedJar |
| 646 | } |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 647 | |
| 648 | if j.properties.Jarjar_rules != nil { |
| 649 | jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules) |
Colin Cross | 8649b26 | 2017-09-27 18:03:17 -0700 | [diff] [blame] | 650 | // Transform classes.jar into classes-jarjar.jar |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 651 | jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName) |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 652 | TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules) |
| 653 | outputFile = jarjarFile |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 654 | if ctx.Failed() { |
| 655 | return |
| 656 | } |
| 657 | } |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 658 | j.implementationJarFile = outputFile |
| 659 | if j.headerJarFile == nil { |
| 660 | j.headerJarFile = j.implementationJarFile |
| 661 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 662 | |
Colin Cross | c157a8d | 2017-10-03 17:17:07 -0700 | [diff] [blame] | 663 | if ctx.Device() && j.installable() { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 664 | outputFile = j.compileDex(ctx, flags, outputFile, jarName) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 665 | if ctx.Failed() { |
| 666 | return |
| 667 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 668 | } |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 669 | ctx.CheckbuildFile(outputFile) |
| 670 | j.outputFile = outputFile |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame^] | 673 | func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths, |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 674 | deps deps, flags javaBuilderFlags, jarName string) android.Path { |
| 675 | |
| 676 | var jars android.Paths |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame^] | 677 | if len(srcFiles) > 0 || len(srcJars) > 0 { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 678 | // Compile java sources into turbine.jar. |
| 679 | turbineJar := android.PathForModuleOut(ctx, "turbine", jarName) |
| 680 | TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags) |
| 681 | if ctx.Failed() { |
| 682 | return nil |
| 683 | } |
| 684 | jars = append(jars, turbineJar) |
| 685 | } |
| 686 | |
| 687 | // Combine any static header libraries into classes-header.jar. If there is only |
| 688 | // one input jar this step will be skipped. |
| 689 | var headerJar android.Path |
| 690 | jars = append(jars, deps.staticHeaderJars...) |
| 691 | |
Colin Cross | 5c6ecc1 | 2017-10-23 18:12:27 -0700 | [diff] [blame] | 692 | // we cannot skip the combine step for now if there is only one jar |
| 693 | // since we have to strip META-INF/TRANSITIVE dir from turbine.jar |
| 694 | combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName) |
| 695 | TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, false, []string{"META-INF"}) |
| 696 | headerJar = combinedJar |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 697 | |
| 698 | if j.properties.Jarjar_rules != nil { |
| 699 | jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules) |
| 700 | // Transform classes.jar into classes-jarjar.jar |
| 701 | jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName) |
| 702 | TransformJarJar(ctx, jarjarFile, headerJar, jarjar_rules) |
| 703 | headerJar = jarjarFile |
| 704 | if ctx.Failed() { |
| 705 | return nil |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | return headerJar |
| 710 | } |
| 711 | |
| 712 | func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, |
| 713 | classesJar android.Path, jarName string) android.Path { |
| 714 | |
| 715 | dxFlags := j.deviceProperties.Dxflags |
| 716 | if false /* emma enabled */ { |
| 717 | // If you instrument class files that have local variable debug information in |
| 718 | // them emma does not correctly maintain the local variable table. |
| 719 | // This will cause an error when you try to convert the class files for Android. |
| 720 | // The workaround here is to build different dex file here based on emma switch |
| 721 | // then later copy into classes.dex. When emma is on, dx is run with --no-locals |
| 722 | // option to remove local variable information |
| 723 | dxFlags = append(dxFlags, "--no-locals") |
| 724 | } |
| 725 | |
| 726 | if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" { |
| 727 | dxFlags = append(dxFlags, "--no-optimize") |
| 728 | } |
| 729 | |
| 730 | if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" { |
| 731 | dxFlags = append(dxFlags, |
| 732 | "--debug", |
| 733 | "--verbose", |
| 734 | "--dump-to="+android.PathForModuleOut(ctx, "classes.lst").String(), |
| 735 | "--dump-width=1000") |
| 736 | } |
| 737 | |
| 738 | var minSdkVersion string |
| 739 | switch j.deviceProperties.Sdk_version { |
| 740 | case "", "current", "test_current", "system_current": |
| 741 | minSdkVersion = strconv.Itoa(ctx.AConfig().DefaultAppTargetSdkInt()) |
| 742 | default: |
| 743 | minSdkVersion = j.deviceProperties.Sdk_version |
| 744 | } |
| 745 | |
| 746 | dxFlags = append(dxFlags, "--min-sdk-version="+minSdkVersion) |
| 747 | |
| 748 | flags.dxFlags = strings.Join(dxFlags, " ") |
| 749 | |
| 750 | desugarFlags := []string{ |
| 751 | "--min_sdk_version " + minSdkVersion, |
| 752 | "--desugar_try_with_resources_if_needed=false", |
| 753 | "--allow_empty_bootclasspath", |
| 754 | } |
| 755 | |
| 756 | if inList("--core-library", dxFlags) { |
| 757 | desugarFlags = append(desugarFlags, "--core_library") |
| 758 | } |
| 759 | |
| 760 | flags.desugarFlags = strings.Join(desugarFlags, " ") |
| 761 | |
| 762 | desugarJar := android.PathForModuleOut(ctx, "desugar", jarName) |
| 763 | TransformDesugar(ctx, desugarJar, classesJar, flags) |
| 764 | if ctx.Failed() { |
| 765 | return nil |
| 766 | } |
| 767 | |
| 768 | // Compile classes.jar into classes.dex and then javalib.jar |
| 769 | javalibJar := android.PathForModuleOut(ctx, "dex", jarName) |
| 770 | TransformClassesJarToDexJar(ctx, javalibJar, desugarJar, flags) |
| 771 | if ctx.Failed() { |
| 772 | return nil |
| 773 | } |
| 774 | |
| 775 | j.dexJarFile = javalibJar |
| 776 | return javalibJar |
| 777 | } |
| 778 | |
Colin Cross | 59f1bb6 | 2017-09-27 17:59:10 -0700 | [diff] [blame] | 779 | func (j *Module) installable() bool { |
| 780 | return j.properties.Installable == nil || *j.properties.Installable |
| 781 | } |
| 782 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 783 | var _ Dependency = (*Library)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 784 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 785 | func (j *Module) HeaderJars() android.Paths { |
| 786 | return android.Paths{j.headerJarFile} |
| 787 | } |
| 788 | |
| 789 | func (j *Module) ImplementationJars() android.Paths { |
| 790 | return android.Paths{j.implementationJarFile} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 793 | func (j *Module) AidlIncludeDirs() android.Paths { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 794 | return j.exportAidlIncludeDirs |
| 795 | } |
| 796 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 797 | var _ logtagsProducer = (*Module)(nil) |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 798 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 799 | func (j *Module) logtags() android.Paths { |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 800 | return j.logtagsSrcs |
| 801 | } |
| 802 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 803 | // |
| 804 | // Java libraries (.jar file) |
| 805 | // |
| 806 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 807 | type Library struct { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 808 | Module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 809 | } |
| 810 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 811 | func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 812 | j.compile(ctx) |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 813 | |
Colin Cross | 59f1bb6 | 2017-09-27 17:59:10 -0700 | [diff] [blame] | 814 | if j.installable() { |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 815 | j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), |
| 816 | ctx.ModuleName()+".jar", j.outputFile) |
| 817 | } |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 820 | func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 821 | j.deps(ctx) |
| 822 | } |
| 823 | |
Colin Cross | a60ead8 | 2017-10-02 18:10:21 -0700 | [diff] [blame] | 824 | func LibraryFactory(installable bool) func() android.Module { |
| 825 | return func() android.Module { |
| 826 | module := &Library{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 827 | |
Colin Cross | a60ead8 | 2017-10-02 18:10:21 -0700 | [diff] [blame] | 828 | if !installable { |
| 829 | module.properties.Installable = proptools.BoolPtr(false) |
| 830 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 831 | |
Colin Cross | a60ead8 | 2017-10-02 18:10:21 -0700 | [diff] [blame] | 832 | module.AddProperties( |
| 833 | &module.Module.properties, |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 834 | &module.Module.deviceProperties, |
| 835 | &module.Module.protoProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 836 | |
Colin Cross | a60ead8 | 2017-10-02 18:10:21 -0700 | [diff] [blame] | 837 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 838 | return module |
| 839 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 842 | func LibraryHostFactory() android.Module { |
| 843 | module := &Library{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 844 | |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 845 | module.AddProperties( |
| 846 | &module.Module.properties, |
| 847 | &module.Module.protoProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 848 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 849 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 850 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | // |
| 854 | // Java Binaries (.jar file plus wrapper script) |
| 855 | // |
| 856 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 857 | type binaryProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 858 | // installable script to execute the resulting jar |
| 859 | Wrapper string |
| 860 | } |
| 861 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 862 | type Binary struct { |
| 863 | Library |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 864 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 865 | binaryProperties binaryProperties |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 866 | |
| 867 | wrapperFile android.ModuleSrcPath |
| 868 | binaryFile android.OutputPath |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 871 | func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 872 | j.Library.GenerateAndroidBuildActions(ctx) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 873 | |
| 874 | // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by |
| 875 | // another build rule before the jar has been installed. |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 876 | j.wrapperFile = android.PathForModuleSrc(ctx, j.binaryProperties.Wrapper) |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 877 | j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"), |
| 878 | ctx.ModuleName(), j.wrapperFile, j.installFile) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 881 | func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 882 | j.deps(ctx) |
| 883 | } |
| 884 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 885 | func BinaryFactory() android.Module { |
| 886 | module := &Binary{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 887 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 888 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 889 | &module.Module.properties, |
| 890 | &module.Module.deviceProperties, |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 891 | &module.Module.protoProperties, |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 892 | &module.binaryProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 893 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 894 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 895 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 896 | } |
| 897 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 898 | func BinaryHostFactory() android.Module { |
| 899 | module := &Binary{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 900 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 901 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 902 | &module.Module.properties, |
| 903 | &module.Module.deviceProperties, |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 904 | &module.Module.protoProperties, |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 905 | &module.binaryProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 906 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 907 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 908 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | // |
| 912 | // Java prebuilts |
| 913 | // |
| 914 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 915 | type ImportProperties struct { |
| 916 | Jars []string |
Colin Cross | 461bd1a | 2017-10-20 13:59:18 -0700 | [diff] [blame] | 917 | |
| 918 | Sdk_version string |
Colin Cross | 535e2cf | 2017-10-20 17:57:49 -0700 | [diff] [blame] | 919 | |
| 920 | Installable *bool |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | type Import struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 924 | android.ModuleBase |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 925 | prebuilt android.Prebuilt |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 926 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 927 | properties ImportProperties |
| 928 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 929 | classpathFiles android.Paths |
| 930 | combinedClasspathFile android.Path |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 931 | } |
| 932 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 933 | func (j *Import) Prebuilt() *android.Prebuilt { |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 934 | return &j.prebuilt |
| 935 | } |
| 936 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 937 | func (j *Import) PrebuiltSrcs() []string { |
| 938 | return j.properties.Jars |
| 939 | } |
| 940 | |
| 941 | func (j *Import) Name() string { |
Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 942 | return j.prebuilt.Name(j.ModuleBase.Name()) |
| 943 | } |
| 944 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 945 | func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 946 | } |
| 947 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 948 | func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 949 | j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars) |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 950 | |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 951 | outputFile := android.PathForModuleOut(ctx, "classes.jar") |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 952 | TransformJarsToJar(ctx, outputFile, "for prebuilts", j.classpathFiles, android.OptionalPath{}, false, nil) |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 953 | j.combinedClasspathFile = outputFile |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 954 | } |
| 955 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 956 | var _ Dependency = (*Import)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 957 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 958 | func (j *Import) HeaderJars() android.Paths { |
| 959 | return j.classpathFiles |
| 960 | } |
| 961 | |
| 962 | func (j *Import) ImplementationJars() android.Paths { |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 963 | return j.classpathFiles |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 964 | } |
| 965 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 966 | func (j *Import) AidlIncludeDirs() android.Paths { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 967 | return nil |
| 968 | } |
| 969 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 970 | var _ android.PrebuiltInterface = (*Import)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 971 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 972 | func ImportFactory() android.Module { |
| 973 | module := &Import{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 974 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 975 | module.AddProperties(&module.properties) |
| 976 | |
| 977 | android.InitPrebuiltModule(module, &module.properties.Jars) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 978 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) |
| 979 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 980 | } |
| 981 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 982 | func ImportFactoryHost() android.Module { |
| 983 | module := &Import{} |
| 984 | |
| 985 | module.AddProperties(&module.properties) |
| 986 | |
| 987 | android.InitPrebuiltModule(module, &module.properties.Jars) |
| 988 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon) |
| 989 | return module |
| 990 | } |
| 991 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 992 | func inList(s string, l []string) bool { |
| 993 | for _, e := range l { |
| 994 | if e == s { |
| 995 | return true |
| 996 | } |
| 997 | } |
| 998 | return false |
| 999 | } |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 1000 | |
| 1001 | // |
| 1002 | // Defaults |
| 1003 | // |
| 1004 | type Defaults struct { |
| 1005 | android.ModuleBase |
| 1006 | android.DefaultsModuleBase |
| 1007 | } |
| 1008 | |
| 1009 | func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1010 | } |
| 1011 | |
| 1012 | func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1013 | } |
| 1014 | |
| 1015 | func defaultsFactory() android.Module { |
| 1016 | return DefaultsFactory() |
| 1017 | } |
| 1018 | |
| 1019 | func DefaultsFactory(props ...interface{}) android.Module { |
| 1020 | module := &Defaults{} |
| 1021 | |
| 1022 | module.AddProperties(props...) |
| 1023 | module.AddProperties( |
| 1024 | &CompilerProperties{}, |
| 1025 | &CompilerDeviceProperties{}, |
| 1026 | ) |
| 1027 | |
| 1028 | android.InitDefaultsModule(module) |
| 1029 | |
| 1030 | return module |
| 1031 | } |