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 | 0607cf7 | 2015-04-28 13:28:51 -0700 | [diff] [blame] | 31 | "android/soong/genrule" |
Colin Cross | 3e3e72d | 2017-06-22 17:20:19 -0700 | [diff] [blame] | 32 | "android/soong/java/config" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 33 | ) |
| 34 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 35 | func init() { |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 36 | android.RegisterModuleType("java_defaults", defaultsFactory) |
| 37 | |
Colin Cross | a60ead8 | 2017-10-02 18:10:21 -0700 | [diff] [blame^] | 38 | android.RegisterModuleType("java_library", LibraryFactory(true)) |
| 39 | android.RegisterModuleType("java_library_static", LibraryFactory(false)) |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 40 | android.RegisterModuleType("java_library_host", LibraryHostFactory) |
| 41 | android.RegisterModuleType("java_binary", BinaryFactory) |
| 42 | android.RegisterModuleType("java_binary_host", BinaryHostFactory) |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 43 | android.RegisterModuleType("java_import", ImportFactory) |
| 44 | android.RegisterModuleType("java_import_host", ImportFactoryHost) |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 45 | android.RegisterModuleType("android_app", AndroidAppFactory) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 46 | |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 47 | android.RegisterSingletonType("logtags", LogtagsSingleton) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 50 | // TODO: |
| 51 | // Autogenerated files: |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 52 | // Proto |
| 53 | // Renderscript |
| 54 | // Post-jar passes: |
| 55 | // Proguard |
Colin Cross | ba21113 | 2017-06-22 15:36:39 -0700 | [diff] [blame] | 56 | // Jacoco |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 57 | // Jarjar |
| 58 | // Dex |
| 59 | // Rmtypedefs |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 60 | // DroidDoc |
| 61 | // Findbugs |
| 62 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 63 | type CompilerProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 64 | // list of source files used to compile the Java module. May be .java, .logtags, .proto, |
| 65 | // or .aidl files. |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 66 | Srcs []string `android:"arch_variant"` |
| 67 | |
| 68 | // list of source files that should not be used to build the Java module. |
| 69 | // This is most useful in the arch/multilib variants to remove non-common files |
| 70 | Exclude_srcs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 71 | |
| 72 | // list of directories containing Java resources |
Colin Cross | 86a63ff | 2017-09-27 17:33:10 -0700 | [diff] [blame] | 73 | Java_resource_dirs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 74 | |
Colin Cross | 86a63ff | 2017-09-27 17:33:10 -0700 | [diff] [blame] | 75 | // list of directories that should be excluded from java_resource_dirs |
| 76 | Exclude_java_resource_dirs []string `android:"arch_variant"` |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 77 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 78 | // list of files to use as Java resources |
| 79 | Java_resources []string `android:"arch_variant"` |
| 80 | |
| 81 | // list of files that should be excluded from java_resources |
| 82 | Exclude_java_resources []string `android:"arch_variant"` |
| 83 | |
Colin Cross | fa5eb23 | 2017-10-01 20:33:03 -0700 | [diff] [blame] | 84 | // don't build against the default libraries (bootclasspath, legacy-test, core-junit, |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 85 | // ext, and framework for device targets) |
Colin Cross | 76b5f0c | 2017-08-29 16:02:06 -0700 | [diff] [blame] | 86 | No_standard_libs *bool |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 87 | |
Colin Cross | fa5eb23 | 2017-10-01 20:33:03 -0700 | [diff] [blame] | 88 | // don't build against the framework libraries (legacy-test, core-junit, |
| 89 | // ext, and framework for device targets) |
| 90 | No_framework_libs *bool |
| 91 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 92 | // list of module-specific flags that will be used for javac compiles |
| 93 | Javacflags []string `android:"arch_variant"` |
| 94 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 95 | // list of of java libraries that will be in the classpath |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 96 | Libs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 97 | |
| 98 | // list of java libraries that will be compiled into the resulting jar |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 99 | Static_libs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 100 | |
| 101 | // manifest file to be included in resulting jar |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 102 | Manifest *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 103 | |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 104 | // if not blank, run jarjar using the specified rules file |
| 105 | Jarjar_rules *string |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 106 | |
| 107 | // If not blank, set the java version passed to javac as -source and -target |
| 108 | Java_version *string |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 109 | |
| 110 | // If set to false, don't allow this module to be installed. Defaults to true. |
| 111 | Installable *bool |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 112 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 113 | // If set to true, include sources used to compile the module in to the final jar |
| 114 | Include_srcs *bool |
| 115 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 116 | // List of modules to use as annotation processors |
| 117 | Annotation_processors []string |
| 118 | |
| 119 | // List of classes to pass to javac to use as annotation processors |
| 120 | Annotation_processor_classes []string |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 123 | type CompilerDeviceProperties struct { |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 124 | // list of module-specific flags that will be used for dex compiles |
| 125 | Dxflags []string `android:"arch_variant"` |
| 126 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 127 | // if not blank, set to the version of the sdk to compile against |
| 128 | Sdk_version string |
| 129 | |
| 130 | // Set for device java libraries, and for host versions of device java libraries |
| 131 | // built for testing |
| 132 | Dex bool `blueprint:"mutated"` |
| 133 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 134 | // directories to pass to aidl tool |
| 135 | Aidl_includes []string |
| 136 | |
| 137 | // directories that should be added as include directories |
| 138 | // for any aidl sources of modules that depend on this module |
| 139 | Export_aidl_include_dirs []string |
| 140 | } |
| 141 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 142 | // Module contains the properties and members used by all java module types |
| 143 | type Module struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 144 | android.ModuleBase |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 145 | android.DefaultableModuleBase |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 146 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 147 | properties CompilerProperties |
| 148 | deviceProperties CompilerDeviceProperties |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 149 | |
| 150 | // output file suitable for inserting into the classpath of another compile |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 151 | classpathFile android.Path |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 152 | |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 153 | // output file containing classes.dex |
| 154 | dexJarFile android.Path |
| 155 | |
| 156 | // output files containing resources |
| 157 | resourceJarFiles android.Paths |
| 158 | |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 159 | // output file suitable for installing or running |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 160 | outputFile android.Path |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 161 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 162 | exportAidlIncludeDirs android.Paths |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 163 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 164 | logtagsSrcs android.Paths |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 165 | |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 166 | // filelists of extra source files that should be included in the javac command line, |
| 167 | // for example R.java generated by aapt for android apps |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 168 | ExtraSrcLists android.Paths |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 169 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 170 | // installed file for binary dependency |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 171 | installFile android.Path |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 174 | type Dependency interface { |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 175 | ClasspathFiles() android.Paths |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 176 | ResourceJarFiles() android.Paths |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 177 | AidlIncludeDirs() android.Paths |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 180 | func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { |
| 181 | android.InitAndroidArchModule(module, hod, android.MultilibCommon) |
| 182 | android.InitDefaultableModule(module) |
| 183 | } |
| 184 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 185 | type dependencyTag struct { |
| 186 | blueprint.BaseDependencyTag |
| 187 | name string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 190 | var ( |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 191 | staticLibTag = dependencyTag{name: "staticlib"} |
| 192 | libTag = dependencyTag{name: "javalib"} |
| 193 | bootClasspathTag = dependencyTag{name: "bootclasspath"} |
| 194 | frameworkResTag = dependencyTag{name: "framework-res"} |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 195 | ) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 196 | |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 197 | type sdkDep struct { |
| 198 | useModule, useFiles, useDefaultLibs bool |
| 199 | module string |
| 200 | jar android.Path |
| 201 | aidl android.Path |
| 202 | } |
| 203 | |
| 204 | func decodeSdkDep(ctx android.BaseContext, v string) sdkDep { |
| 205 | switch v { |
| 206 | case "", "current", "system_current", "test_current": |
| 207 | // OK |
| 208 | default: |
| 209 | if _, err := strconv.Atoi(v); err != nil { |
| 210 | ctx.PropertyErrorf("sdk_version", "invalid sdk version") |
| 211 | return sdkDep{} |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | toFile := func(v string) sdkDep { |
| 216 | dir := filepath.Join("prebuilts/sdk", v) |
| 217 | jar := filepath.Join(dir, "android.jar") |
| 218 | aidl := filepath.Join(dir, "framework.aidl") |
| 219 | jarPath := android.ExistentPathForSource(ctx, "sdkdir", jar) |
| 220 | aidlPath := android.ExistentPathForSource(ctx, "sdkdir", aidl) |
| 221 | if !jarPath.Valid() { |
| 222 | ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar) |
| 223 | return sdkDep{} |
| 224 | } |
| 225 | if !aidlPath.Valid() { |
| 226 | ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl) |
| 227 | return sdkDep{} |
| 228 | } |
| 229 | return sdkDep{ |
| 230 | useFiles: true, |
| 231 | jar: jarPath.Path(), |
| 232 | aidl: aidlPath.Path(), |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | toModule := func(m string) sdkDep { |
| 237 | return sdkDep{ |
| 238 | useModule: true, |
| 239 | module: m, |
| 240 | } |
| 241 | } |
| 242 | |
Colin Cross | 8b9d37b | 2017-09-22 15:30:06 -0700 | [diff] [blame] | 243 | if ctx.AConfig().UnbundledBuild() && v != "" { |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 244 | return toFile(v) |
| 245 | } |
| 246 | |
| 247 | switch v { |
| 248 | case "": |
| 249 | return sdkDep{ |
| 250 | useDefaultLibs: true, |
| 251 | } |
| 252 | case "current": |
| 253 | return toModule("android_stubs_current") |
| 254 | case "system_current": |
| 255 | return toModule("android_system_stubs_current") |
| 256 | case "test_current": |
| 257 | return toModule("android_test_stubs_current") |
| 258 | default: |
| 259 | return toFile(v) |
| 260 | } |
| 261 | } |
| 262 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 263 | func (j *Module) deps(ctx android.BottomUpMutatorContext) { |
Colin Cross | 76b5f0c | 2017-08-29 16:02:06 -0700 | [diff] [blame] | 264 | if !proptools.Bool(j.properties.No_standard_libs) { |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 265 | if ctx.Device() { |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 266 | sdkDep := decodeSdkDep(ctx, j.deviceProperties.Sdk_version) |
| 267 | if sdkDep.useDefaultLibs { |
Colin Cross | cb2c929 | 2017-09-23 19:57:16 -0700 | [diff] [blame] | 268 | ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...) |
Colin Cross | fa5eb23 | 2017-10-01 20:33:03 -0700 | [diff] [blame] | 269 | if !proptools.Bool(j.properties.No_framework_libs) { |
| 270 | ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...) |
| 271 | } |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 272 | } |
| 273 | if sdkDep.useModule { |
| 274 | ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.module) |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 275 | } |
| 276 | } else { |
| 277 | if j.deviceProperties.Dex { |
Colin Cross | cb2c929 | 2017-09-23 19:57:16 -0700 | [diff] [blame] | 278 | ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...) |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 279 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 280 | } |
| 281 | } |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 282 | ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...) |
| 283 | ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...) |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 284 | ctx.AddDependency(ctx.Module(), libTag, j.properties.Annotation_processors...) |
Colin Cross | 7f9036c | 2017-08-30 13:27:57 -0700 | [diff] [blame] | 285 | |
| 286 | android.ExtractSourcesDeps(ctx, j.properties.Srcs) |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 287 | android.ExtractSourcesDeps(ctx, j.properties.Java_resources) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 290 | func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 291 | aidlIncludeDirs android.Paths) []string { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 292 | |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 293 | localAidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl_includes) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 294 | |
| 295 | var flags []string |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 296 | if aidlPreprocess.Valid() { |
| 297 | flags = append(flags, "-p"+aidlPreprocess.String()) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 298 | } else { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 299 | flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I")) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 302 | flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I")) |
| 303 | flags = append(flags, android.JoinWithPrefix(localAidlIncludes.Strings(), "-I")) |
| 304 | flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String()) |
Colin Cross | d48633a | 2017-07-13 14:41:17 -0700 | [diff] [blame] | 305 | if src := android.ExistentPathForSource(ctx, "", "src"); src.Valid() { |
| 306 | flags = append(flags, "-I"+src.String()) |
| 307 | } |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 308 | |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 309 | return flags |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 312 | type deps struct { |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 313 | classpath android.Paths |
| 314 | bootClasspath android.Paths |
| 315 | staticJars android.Paths |
| 316 | staticJarResources android.Paths |
| 317 | aidlIncludeDirs android.Paths |
| 318 | srcFileLists android.Paths |
| 319 | aidlPreprocess android.OptionalPath |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 320 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 321 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 322 | func (j *Module) collectDeps(ctx android.ModuleContext) deps { |
| 323 | var deps deps |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 324 | |
| 325 | sdkDep := decodeSdkDep(ctx, j.deviceProperties.Sdk_version) |
| 326 | if sdkDep.useFiles { |
| 327 | deps.classpath = append(deps.classpath, sdkDep.jar) |
| 328 | deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl) |
| 329 | } |
| 330 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 331 | ctx.VisitDirectDeps(func(module blueprint.Module) { |
| 332 | otherName := ctx.OtherModuleName(module) |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 333 | tag := ctx.OtherModuleDependencyTag(module) |
| 334 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 335 | dep, _ := module.(Dependency) |
| 336 | if dep == nil { |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 337 | switch tag { |
| 338 | case android.DefaultsDepTag, android.SourceDepTag: |
Dan Willemsen | d6ba0d5 | 2017-09-13 15:46:47 -0700 | [diff] [blame] | 339 | // Nothing to do |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 340 | default: |
| 341 | ctx.ModuleErrorf("depends on non-java module %q", otherName) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 342 | } |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 343 | return |
| 344 | } |
| 345 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 346 | switch tag { |
| 347 | case bootClasspathTag: |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 348 | deps.bootClasspath = append(deps.bootClasspath, dep.ClasspathFiles()...) |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 349 | case libTag: |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 350 | deps.classpath = append(deps.classpath, dep.ClasspathFiles()...) |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 351 | case staticLibTag: |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 352 | deps.classpath = append(deps.classpath, dep.ClasspathFiles()...) |
| 353 | deps.staticJars = append(deps.staticJars, dep.ClasspathFiles()...) |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 354 | deps.staticJarResources = append(deps.staticJarResources, dep.ResourceJarFiles()...) |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 355 | case frameworkResTag: |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 356 | if ctx.ModuleName() == "framework" { |
| 357 | // framework.jar has a one-off dependency on the R.java and Manifest.java files |
| 358 | // generated by framework-res.apk |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 359 | deps.srcFileLists = append(deps.srcFileLists, module.(*AndroidApp).aaptJavaFileList) |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 360 | } |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 361 | default: |
| 362 | panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 363 | } |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 364 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 365 | deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 366 | }) |
| 367 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 368 | return deps |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 371 | func (j *Module) compile(ctx android.ModuleContext) { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 372 | |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 373 | j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Export_aidl_include_dirs) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 374 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 375 | deps := j.collectDeps(ctx) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 376 | |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 377 | var flags javaBuilderFlags |
| 378 | |
| 379 | javacFlags := j.properties.Javacflags |
Colin Cross | 4f26bc0 | 2017-09-06 12:52:16 -0700 | [diff] [blame] | 380 | if ctx.AConfig().Getenv("EXPERIMENTAL_USE_OPENJDK9") == "" { |
| 381 | javacFlags = config.StripJavac9Flags(javacFlags) |
| 382 | } |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 383 | |
| 384 | if j.properties.Java_version != nil { |
| 385 | flags.javaVersion = *j.properties.Java_version |
| 386 | } else { |
| 387 | flags.javaVersion = "${config.DefaultJavaVersion}" |
| 388 | } |
| 389 | |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 390 | flags.bootClasspath.AddPaths(deps.bootClasspath) |
| 391 | flags.classpath.AddPaths(deps.classpath) |
| 392 | |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 393 | if len(javacFlags) > 0 { |
| 394 | ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " ")) |
| 395 | flags.javacFlags = "$javacFlags" |
| 396 | } |
| 397 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 398 | aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs) |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 399 | if len(aidlFlags) > 0 { |
| 400 | ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " ")) |
| 401 | flags.aidlFlags = "$aidlFlags" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 404 | srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 405 | |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 406 | srcFiles = j.genSources(ctx, srcFiles, flags) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 407 | |
Colin Cross | 0607cf7 | 2015-04-28 13:28:51 -0700 | [diff] [blame] | 408 | ctx.VisitDirectDeps(func(module blueprint.Module) { |
| 409 | if gen, ok := module.(genrule.SourceFileGenerator); ok { |
| 410 | srcFiles = append(srcFiles, gen.GeneratedSourceFiles()...) |
| 411 | } |
| 412 | }) |
| 413 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 414 | deps.srcFileLists = append(deps.srcFileLists, j.ExtraSrcLists...) |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 415 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 416 | var jars android.Paths |
| 417 | |
Colin Cross | 8cf1334 | 2015-04-10 15:41:49 -0700 | [diff] [blame] | 418 | if len(srcFiles) > 0 { |
Colin Cross | d689143 | 2017-09-27 17:39:56 -0700 | [diff] [blame] | 419 | var extraJarDeps android.Paths |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 420 | if ctx.AConfig().IsEnvTrue("RUN_ERROR_PRONE") { |
| 421 | // If error-prone is enabled, add an additional rule to compile the java files into |
| 422 | // 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] | 423 | // a rebuild when error-prone is turned off). |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 424 | // TODO(ccross): Once we always compile with javac9 we may be able to conditionally |
| 425 | // enable error-prone without affecting the output class files. |
Colin Cross | d689143 | 2017-09-27 17:39:56 -0700 | [diff] [blame] | 426 | errorprone := RunErrorProne(ctx, srcFiles, deps.srcFileLists, flags, nil) |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 427 | extraJarDeps = append(extraJarDeps, errorprone) |
| 428 | } |
| 429 | |
Colin Cross | d689143 | 2017-09-27 17:39:56 -0700 | [diff] [blame] | 430 | // Compile java sources into .class files |
| 431 | classes := TransformJavaToClasses(ctx, srcFiles, deps.srcFileLists, flags, extraJarDeps) |
| 432 | if ctx.Failed() { |
| 433 | return |
| 434 | } |
| 435 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 436 | jars = append(jars, classes) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 439 | dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs) |
| 440 | fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources) |
| 441 | |
| 442 | var resArgs []string |
| 443 | var resDeps android.Paths |
| 444 | |
| 445 | resArgs = append(resArgs, dirArgs...) |
| 446 | resDeps = append(resDeps, dirDeps...) |
| 447 | |
| 448 | resArgs = append(resArgs, fileArgs...) |
| 449 | resDeps = append(resDeps, fileDeps...) |
| 450 | |
| 451 | if proptools.Bool(j.properties.Include_srcs) { |
| 452 | srcArgs, srcDeps := ResourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs) |
| 453 | resArgs = append(resArgs, srcArgs...) |
| 454 | resDeps = append(resDeps, srcDeps...) |
| 455 | } |
Colin Cross | 40a3671 | 2017-09-27 17:41:35 -0700 | [diff] [blame] | 456 | |
| 457 | if len(resArgs) > 0 { |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 458 | // Combine classes + resources into classes-full-debug.jar |
Colin Cross | 40a3671 | 2017-09-27 17:41:35 -0700 | [diff] [blame] | 459 | resourceJar := TransformResourcesToJar(ctx, resArgs, resDeps) |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 460 | if ctx.Failed() { |
| 461 | return |
| 462 | } |
Colin Cross | 2097830 | 2015-04-10 17:05:07 -0700 | [diff] [blame] | 463 | |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 464 | j.resourceJarFiles = append(j.resourceJarFiles, resourceJar) |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 465 | jars = append(jars, resourceJar) |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 468 | // Propagate the resources from the transitive closure of static dependencies for copying |
| 469 | // into dex jars |
| 470 | j.resourceJarFiles = append(j.resourceJarFiles, deps.staticJarResources...) |
| 471 | |
| 472 | // 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] | 473 | jars = append(jars, deps.staticJars...) |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 474 | |
Colin Cross | 635acc9 | 2017-09-12 22:50:46 -0700 | [diff] [blame] | 475 | manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest) |
| 476 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 477 | // 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] | 478 | // classes.jar. If there is only one input jar this step will be skipped. |
Colin Cross | 635acc9 | 2017-09-12 22:50:46 -0700 | [diff] [blame] | 479 | outputFile := TransformJarsToJar(ctx, "classes.jar", jars, manifest, false) |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 480 | |
| 481 | if j.properties.Jarjar_rules != nil { |
| 482 | jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules) |
Colin Cross | 8649b26 | 2017-09-27 18:03:17 -0700 | [diff] [blame] | 483 | // Transform classes.jar into classes-jarjar.jar |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 484 | outputFile = TransformJarJar(ctx, outputFile, jarjar_rules) |
| 485 | if ctx.Failed() { |
| 486 | return |
| 487 | } |
| 488 | } |
| 489 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 490 | j.classpathFile = outputFile |
| 491 | |
Colin Cross | a713a6f | 2017-09-20 18:04:44 -0700 | [diff] [blame] | 492 | // TODO(ccross): handle hostdex |
Colin Cross | 59f1bb6 | 2017-09-27 17:59:10 -0700 | [diff] [blame] | 493 | if ctx.Device() && len(srcFiles) > 0 && j.installable() { |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 494 | dxFlags := j.deviceProperties.Dxflags |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 495 | if false /* emma enabled */ { |
| 496 | // If you instrument class files that have local variable debug information in |
| 497 | // them emma does not correctly maintain the local variable table. |
| 498 | // This will cause an error when you try to convert the class files for Android. |
| 499 | // The workaround here is to build different dex file here based on emma switch |
| 500 | // then later copy into classes.dex. When emma is on, dx is run with --no-locals |
| 501 | // option to remove local variable information |
| 502 | dxFlags = append(dxFlags, "--no-locals") |
| 503 | } |
| 504 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 505 | if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 506 | dxFlags = append(dxFlags, "--no-optimize") |
| 507 | } |
| 508 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 509 | if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 510 | dxFlags = append(dxFlags, |
| 511 | "--debug", |
| 512 | "--verbose", |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 513 | "--dump-to="+android.PathForModuleOut(ctx, "classes.lst").String(), |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 514 | "--dump-width=1000") |
| 515 | } |
| 516 | |
Colin Cross | 595a406 | 2017-08-31 12:30:37 -0700 | [diff] [blame] | 517 | var minSdkVersion string |
| 518 | switch j.deviceProperties.Sdk_version { |
| 519 | case "", "current", "test_current", "system_current": |
| 520 | minSdkVersion = strconv.Itoa(ctx.AConfig().DefaultAppTargetSdkInt()) |
| 521 | default: |
| 522 | minSdkVersion = j.deviceProperties.Sdk_version |
| 523 | } |
| 524 | |
| 525 | dxFlags = append(dxFlags, "--min-sdk-version="+minSdkVersion) |
| 526 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 527 | flags.dxFlags = strings.Join(dxFlags, " ") |
| 528 | |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 529 | desugarFlags := []string{ |
| 530 | "--min_sdk_version " + minSdkVersion, |
| 531 | "--desugar_try_with_resources_if_needed=false", |
| 532 | "--allow_empty_bootclasspath", |
| 533 | } |
| 534 | |
| 535 | if inList("--core-library", dxFlags) { |
| 536 | desugarFlags = append(desugarFlags, "--core_library") |
| 537 | } |
| 538 | |
| 539 | flags.desugarFlags = strings.Join(desugarFlags, " ") |
| 540 | |
| 541 | desugarJar := TransformDesugar(ctx, outputFile, flags) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 542 | if ctx.Failed() { |
| 543 | return |
| 544 | } |
| 545 | |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 546 | // Compile classes.jar into classes.dex |
| 547 | dexJarFile := TransformClassesJarToDexJar(ctx, desugarJar, flags) |
| 548 | if ctx.Failed() { |
| 549 | return |
| 550 | } |
| 551 | |
| 552 | jars := android.Paths{dexJarFile} |
| 553 | jars = append(jars, j.resourceJarFiles...) |
| 554 | |
| 555 | outputFile = TransformJarsToJar(ctx, "javalib.jar", jars, android.OptionalPath{}, true) |
| 556 | |
| 557 | j.dexJarFile = outputFile |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 558 | } |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 559 | ctx.CheckbuildFile(outputFile) |
| 560 | j.outputFile = outputFile |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Colin Cross | 59f1bb6 | 2017-09-27 17:59:10 -0700 | [diff] [blame] | 563 | func (j *Module) installable() bool { |
| 564 | return j.properties.Installable == nil || *j.properties.Installable |
| 565 | } |
| 566 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 567 | var _ Dependency = (*Library)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 568 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 569 | func (j *Module) ClasspathFiles() android.Paths { |
| 570 | return android.Paths{j.classpathFile} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 573 | func (j *Module) ResourceJarFiles() android.Paths { |
| 574 | return j.resourceJarFiles |
| 575 | } |
| 576 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 577 | func (j *Module) AidlIncludeDirs() android.Paths { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 578 | return j.exportAidlIncludeDirs |
| 579 | } |
| 580 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 581 | var _ logtagsProducer = (*Module)(nil) |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 582 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 583 | func (j *Module) logtags() android.Paths { |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 584 | return j.logtagsSrcs |
| 585 | } |
| 586 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 587 | // |
| 588 | // Java libraries (.jar file) |
| 589 | // |
| 590 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 591 | type Library struct { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 592 | Module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 595 | func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 596 | j.compile(ctx) |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 597 | |
Colin Cross | 59f1bb6 | 2017-09-27 17:59:10 -0700 | [diff] [blame] | 598 | if j.installable() { |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 599 | j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), |
| 600 | ctx.ModuleName()+".jar", j.outputFile) |
| 601 | } |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 604 | func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 605 | j.deps(ctx) |
| 606 | } |
| 607 | |
Colin Cross | a60ead8 | 2017-10-02 18:10:21 -0700 | [diff] [blame^] | 608 | func LibraryFactory(installable bool) func() android.Module { |
| 609 | return func() android.Module { |
| 610 | module := &Library{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 611 | |
Colin Cross | a60ead8 | 2017-10-02 18:10:21 -0700 | [diff] [blame^] | 612 | if !installable { |
| 613 | module.properties.Installable = proptools.BoolPtr(false) |
| 614 | } |
| 615 | module.deviceProperties.Dex = true |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 616 | |
Colin Cross | a60ead8 | 2017-10-02 18:10:21 -0700 | [diff] [blame^] | 617 | module.AddProperties( |
| 618 | &module.Module.properties, |
| 619 | &module.Module.deviceProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 620 | |
Colin Cross | a60ead8 | 2017-10-02 18:10:21 -0700 | [diff] [blame^] | 621 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 622 | return module |
| 623 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 626 | func LibraryHostFactory() android.Module { |
| 627 | module := &Library{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 628 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 629 | module.AddProperties(&module.Module.properties) |
| 630 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 631 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 632 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | // |
| 636 | // Java Binaries (.jar file plus wrapper script) |
| 637 | // |
| 638 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 639 | type binaryProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 640 | // installable script to execute the resulting jar |
| 641 | Wrapper string |
| 642 | } |
| 643 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 644 | type Binary struct { |
| 645 | Library |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 646 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 647 | binaryProperties binaryProperties |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 648 | |
| 649 | wrapperFile android.ModuleSrcPath |
| 650 | binaryFile android.OutputPath |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 653 | func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 654 | j.Library.GenerateAndroidBuildActions(ctx) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 655 | |
| 656 | // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by |
| 657 | // another build rule before the jar has been installed. |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 658 | j.wrapperFile = android.PathForModuleSrc(ctx, j.binaryProperties.Wrapper) |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 659 | j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"), |
| 660 | ctx.ModuleName(), j.wrapperFile, j.installFile) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 661 | } |
| 662 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 663 | func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 664 | j.deps(ctx) |
| 665 | } |
| 666 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 667 | func BinaryFactory() android.Module { |
| 668 | module := &Binary{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 669 | |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 670 | module.deviceProperties.Dex = true |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 671 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 672 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 673 | &module.Module.properties, |
| 674 | &module.Module.deviceProperties, |
| 675 | &module.binaryProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 676 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 677 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 678 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 681 | func BinaryHostFactory() android.Module { |
| 682 | module := &Binary{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 683 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 684 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 685 | &module.Module.properties, |
| 686 | &module.Module.deviceProperties, |
| 687 | &module.binaryProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 688 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 689 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 690 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | // |
| 694 | // Java prebuilts |
| 695 | // |
| 696 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 697 | type ImportProperties struct { |
| 698 | Jars []string |
| 699 | } |
| 700 | |
| 701 | type Import struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 702 | android.ModuleBase |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 703 | prebuilt android.Prebuilt |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 704 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 705 | properties ImportProperties |
| 706 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 707 | classpathFiles android.Paths |
| 708 | combinedClasspathFile android.Path |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 709 | } |
| 710 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 711 | func (j *Import) Prebuilt() *android.Prebuilt { |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 712 | return &j.prebuilt |
| 713 | } |
| 714 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 715 | func (j *Import) PrebuiltSrcs() []string { |
| 716 | return j.properties.Jars |
| 717 | } |
| 718 | |
| 719 | func (j *Import) Name() string { |
Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 720 | return j.prebuilt.Name(j.ModuleBase.Name()) |
| 721 | } |
| 722 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 723 | func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 726 | func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 727 | j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars) |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 728 | |
Colin Cross | 635acc9 | 2017-09-12 22:50:46 -0700 | [diff] [blame] | 729 | j.combinedClasspathFile = TransformJarsToJar(ctx, "classes.jar", j.classpathFiles, android.OptionalPath{}, false) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 732 | var _ Dependency = (*Import)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 733 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 734 | func (j *Import) ClasspathFiles() android.Paths { |
| 735 | return j.classpathFiles |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 738 | func (j *Import) ResourceJarFiles() android.Paths { |
| 739 | // resources are in the ClasspathFiles |
| 740 | return nil |
| 741 | } |
| 742 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 743 | func (j *Import) AidlIncludeDirs() android.Paths { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 744 | return nil |
| 745 | } |
| 746 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 747 | var _ android.PrebuiltInterface = (*Import)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 748 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 749 | func ImportFactory() android.Module { |
| 750 | module := &Import{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 751 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 752 | module.AddProperties(&module.properties) |
| 753 | |
| 754 | android.InitPrebuiltModule(module, &module.properties.Jars) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 755 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) |
| 756 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 759 | func ImportFactoryHost() android.Module { |
| 760 | module := &Import{} |
| 761 | |
| 762 | module.AddProperties(&module.properties) |
| 763 | |
| 764 | android.InitPrebuiltModule(module, &module.properties.Jars) |
| 765 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon) |
| 766 | return module |
| 767 | } |
| 768 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 769 | func inList(s string, l []string) bool { |
| 770 | for _, e := range l { |
| 771 | if e == s { |
| 772 | return true |
| 773 | } |
| 774 | } |
| 775 | return false |
| 776 | } |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 777 | |
| 778 | // |
| 779 | // Defaults |
| 780 | // |
| 781 | type Defaults struct { |
| 782 | android.ModuleBase |
| 783 | android.DefaultsModuleBase |
| 784 | } |
| 785 | |
| 786 | func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 787 | } |
| 788 | |
| 789 | func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 790 | } |
| 791 | |
| 792 | func defaultsFactory() android.Module { |
| 793 | return DefaultsFactory() |
| 794 | } |
| 795 | |
| 796 | func DefaultsFactory(props ...interface{}) android.Module { |
| 797 | module := &Defaults{} |
| 798 | |
| 799 | module.AddProperties(props...) |
| 800 | module.AddProperties( |
| 801 | &CompilerProperties{}, |
| 802 | &CompilerDeviceProperties{}, |
| 803 | ) |
| 804 | |
| 805 | android.InitDefaultsModule(module) |
| 806 | |
| 807 | return module |
| 808 | } |