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