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