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 | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 38 | android.RegisterModuleType("java_library", LibraryFactory) |
| 39 | android.RegisterModuleType("java_library_static", LibraryFactory) |
| 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 | |
Paul Duffin | 2b67e3b | 2016-11-30 16:13:09 +0000 | [diff] [blame] | 84 | // don't build against the default libraries (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 | |
| 88 | // list of module-specific flags that will be used for javac compiles |
| 89 | Javacflags []string `android:"arch_variant"` |
| 90 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 91 | // list of of java libraries that will be in the classpath |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 92 | Libs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 93 | |
| 94 | // list of java libraries that will be compiled into the resulting jar |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 95 | Static_libs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 96 | |
| 97 | // manifest file to be included in resulting jar |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 98 | Manifest *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 99 | |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 100 | // if not blank, run jarjar using the specified rules file |
| 101 | Jarjar_rules *string |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 102 | |
| 103 | // If not blank, set the java version passed to javac as -source and -target |
| 104 | Java_version *string |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 105 | |
| 106 | // If set to false, don't allow this module to be installed. Defaults to true. |
| 107 | Installable *bool |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 108 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame^] | 109 | // If set to true, include sources used to compile the module in to the final jar |
| 110 | Include_srcs *bool |
| 111 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 112 | // List of modules to use as annotation processors |
| 113 | Annotation_processors []string |
| 114 | |
| 115 | // List of classes to pass to javac to use as annotation processors |
| 116 | Annotation_processor_classes []string |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 119 | type CompilerDeviceProperties struct { |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 120 | // list of module-specific flags that will be used for dex compiles |
| 121 | Dxflags []string `android:"arch_variant"` |
| 122 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 123 | // if not blank, set to the version of the sdk to compile against |
| 124 | Sdk_version string |
| 125 | |
| 126 | // Set for device java libraries, and for host versions of device java libraries |
| 127 | // built for testing |
| 128 | Dex bool `blueprint:"mutated"` |
| 129 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 130 | // directories to pass to aidl tool |
| 131 | Aidl_includes []string |
| 132 | |
| 133 | // directories that should be added as include directories |
| 134 | // for any aidl sources of modules that depend on this module |
| 135 | Export_aidl_include_dirs []string |
| 136 | } |
| 137 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 138 | // Module contains the properties and members used by all java module types |
| 139 | type Module struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 140 | android.ModuleBase |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 141 | android.DefaultableModuleBase |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 142 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 143 | properties CompilerProperties |
| 144 | deviceProperties CompilerDeviceProperties |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 145 | |
| 146 | // output file suitable for inserting into the classpath of another compile |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 147 | classpathFile android.Path |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 148 | |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 149 | // output file containing classes.dex |
| 150 | dexJarFile android.Path |
| 151 | |
| 152 | // output files containing resources |
| 153 | resourceJarFiles android.Paths |
| 154 | |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 155 | // output file suitable for installing or running |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 156 | outputFile android.Path |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 157 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 158 | exportAidlIncludeDirs android.Paths |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 159 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 160 | logtagsSrcs android.Paths |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 161 | |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 162 | // filelists of extra source files that should be included in the javac command line, |
| 163 | // for example R.java generated by aapt for android apps |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 164 | ExtraSrcLists android.Paths |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 165 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 166 | // installed file for binary dependency |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 167 | installFile android.Path |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 170 | type Dependency interface { |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 171 | ClasspathFiles() android.Paths |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 172 | ResourceJarFiles() android.Paths |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 173 | AidlIncludeDirs() android.Paths |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 176 | func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { |
| 177 | android.InitAndroidArchModule(module, hod, android.MultilibCommon) |
| 178 | android.InitDefaultableModule(module) |
| 179 | } |
| 180 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 181 | type dependencyTag struct { |
| 182 | blueprint.BaseDependencyTag |
| 183 | name string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 186 | var ( |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 187 | staticLibTag = dependencyTag{name: "staticlib"} |
| 188 | libTag = dependencyTag{name: "javalib"} |
| 189 | bootClasspathTag = dependencyTag{name: "bootclasspath"} |
| 190 | frameworkResTag = dependencyTag{name: "framework-res"} |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 191 | ) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 192 | |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 193 | type sdkDep struct { |
| 194 | useModule, useFiles, useDefaultLibs bool |
| 195 | module string |
| 196 | jar android.Path |
| 197 | aidl android.Path |
| 198 | } |
| 199 | |
| 200 | func decodeSdkDep(ctx android.BaseContext, v string) sdkDep { |
| 201 | switch v { |
| 202 | case "", "current", "system_current", "test_current": |
| 203 | // OK |
| 204 | default: |
| 205 | if _, err := strconv.Atoi(v); err != nil { |
| 206 | ctx.PropertyErrorf("sdk_version", "invalid sdk version") |
| 207 | return sdkDep{} |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | toFile := func(v string) sdkDep { |
| 212 | dir := filepath.Join("prebuilts/sdk", v) |
| 213 | jar := filepath.Join(dir, "android.jar") |
| 214 | aidl := filepath.Join(dir, "framework.aidl") |
| 215 | jarPath := android.ExistentPathForSource(ctx, "sdkdir", jar) |
| 216 | aidlPath := android.ExistentPathForSource(ctx, "sdkdir", aidl) |
| 217 | if !jarPath.Valid() { |
| 218 | ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar) |
| 219 | return sdkDep{} |
| 220 | } |
| 221 | if !aidlPath.Valid() { |
| 222 | ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl) |
| 223 | return sdkDep{} |
| 224 | } |
| 225 | return sdkDep{ |
| 226 | useFiles: true, |
| 227 | jar: jarPath.Path(), |
| 228 | aidl: aidlPath.Path(), |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | toModule := func(m string) sdkDep { |
| 233 | return sdkDep{ |
| 234 | useModule: true, |
| 235 | module: m, |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | if ctx.AConfig().UnbundledBuild() { |
| 240 | if v == "" { |
| 241 | if ctx, ok := ctx.(android.ModuleContext); ok { |
| 242 | ctx.AddMissingDependencies([]string{"sdk_version_must_be_set_for_modules_used_in_unbundled_builds"}) |
| 243 | } |
| 244 | return sdkDep{} |
| 245 | } |
| 246 | return toFile(v) |
| 247 | } |
| 248 | |
| 249 | switch v { |
| 250 | case "": |
| 251 | return sdkDep{ |
| 252 | useDefaultLibs: true, |
| 253 | } |
| 254 | case "current": |
| 255 | return toModule("android_stubs_current") |
| 256 | case "system_current": |
| 257 | return toModule("android_system_stubs_current") |
| 258 | case "test_current": |
| 259 | return toModule("android_test_stubs_current") |
| 260 | default: |
| 261 | return toFile(v) |
| 262 | } |
| 263 | } |
| 264 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 265 | func (j *Module) deps(ctx android.BottomUpMutatorContext) { |
Colin Cross | 76b5f0c | 2017-08-29 16:02:06 -0700 | [diff] [blame] | 266 | if !proptools.Bool(j.properties.No_standard_libs) { |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 267 | if ctx.Device() { |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 268 | sdkDep := decodeSdkDep(ctx, j.deviceProperties.Sdk_version) |
| 269 | if sdkDep.useDefaultLibs { |
Colin Cross | cb2c929 | 2017-09-23 19:57:16 -0700 | [diff] [blame] | 270 | ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...) |
Colin Cross | 227d436 | 2017-08-30 14:14:52 -0700 | [diff] [blame] | 271 | ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...) |
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 | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 608 | func LibraryFactory() android.Module { |
| 609 | module := &Library{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 610 | |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 611 | module.deviceProperties.Dex = true |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 612 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 613 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 614 | &module.Module.properties, |
| 615 | &module.Module.deviceProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 616 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 617 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 618 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 621 | func LibraryHostFactory() android.Module { |
| 622 | module := &Library{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 623 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 624 | module.AddProperties(&module.Module.properties) |
| 625 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 626 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 627 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | // |
| 631 | // Java Binaries (.jar file plus wrapper script) |
| 632 | // |
| 633 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 634 | type binaryProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 635 | // installable script to execute the resulting jar |
| 636 | Wrapper string |
| 637 | } |
| 638 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 639 | type Binary struct { |
| 640 | Library |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 641 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 642 | binaryProperties binaryProperties |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 643 | |
| 644 | wrapperFile android.ModuleSrcPath |
| 645 | binaryFile android.OutputPath |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 648 | func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 649 | j.Library.GenerateAndroidBuildActions(ctx) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 650 | |
| 651 | // Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by |
| 652 | // another build rule before the jar has been installed. |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 653 | j.wrapperFile = android.PathForModuleSrc(ctx, j.binaryProperties.Wrapper) |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 654 | j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"), |
| 655 | ctx.ModuleName(), j.wrapperFile, j.installFile) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 658 | func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 659 | j.deps(ctx) |
| 660 | } |
| 661 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 662 | func BinaryFactory() android.Module { |
| 663 | module := &Binary{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 664 | |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 665 | module.deviceProperties.Dex = true |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 666 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 667 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 668 | &module.Module.properties, |
| 669 | &module.Module.deviceProperties, |
| 670 | &module.binaryProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 671 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 672 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 673 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 676 | func BinaryHostFactory() android.Module { |
| 677 | module := &Binary{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 678 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 679 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 680 | &module.Module.properties, |
| 681 | &module.Module.deviceProperties, |
| 682 | &module.binaryProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 683 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 684 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 685 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | // |
| 689 | // Java prebuilts |
| 690 | // |
| 691 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 692 | type ImportProperties struct { |
| 693 | Jars []string |
| 694 | } |
| 695 | |
| 696 | type Import struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 697 | android.ModuleBase |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 698 | prebuilt android.Prebuilt |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 699 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 700 | properties ImportProperties |
| 701 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 702 | classpathFiles android.Paths |
| 703 | combinedClasspathFile android.Path |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 704 | } |
| 705 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 706 | func (j *Import) Prebuilt() *android.Prebuilt { |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 707 | return &j.prebuilt |
| 708 | } |
| 709 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 710 | func (j *Import) PrebuiltSrcs() []string { |
| 711 | return j.properties.Jars |
| 712 | } |
| 713 | |
| 714 | func (j *Import) Name() string { |
Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 715 | return j.prebuilt.Name(j.ModuleBase.Name()) |
| 716 | } |
| 717 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 718 | func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 721 | func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 722 | j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars) |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 723 | |
Colin Cross | 635acc9 | 2017-09-12 22:50:46 -0700 | [diff] [blame] | 724 | j.combinedClasspathFile = TransformJarsToJar(ctx, "classes.jar", j.classpathFiles, android.OptionalPath{}, false) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 727 | var _ Dependency = (*Import)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 728 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 729 | func (j *Import) ClasspathFiles() android.Paths { |
| 730 | return j.classpathFiles |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 733 | func (j *Import) ResourceJarFiles() android.Paths { |
| 734 | // resources are in the ClasspathFiles |
| 735 | return nil |
| 736 | } |
| 737 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 738 | func (j *Import) AidlIncludeDirs() android.Paths { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 739 | return nil |
| 740 | } |
| 741 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 742 | var _ android.PrebuiltInterface = (*Import)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 743 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 744 | func ImportFactory() android.Module { |
| 745 | module := &Import{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 746 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 747 | module.AddProperties(&module.properties) |
| 748 | |
| 749 | android.InitPrebuiltModule(module, &module.properties.Jars) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 750 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) |
| 751 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 754 | func ImportFactoryHost() android.Module { |
| 755 | module := &Import{} |
| 756 | |
| 757 | module.AddProperties(&module.properties) |
| 758 | |
| 759 | android.InitPrebuiltModule(module, &module.properties.Jars) |
| 760 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon) |
| 761 | return module |
| 762 | } |
| 763 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 764 | func inList(s string, l []string) bool { |
| 765 | for _, e := range l { |
| 766 | if e == s { |
| 767 | return true |
| 768 | } |
| 769 | } |
| 770 | return false |
| 771 | } |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 772 | |
| 773 | // |
| 774 | // Defaults |
| 775 | // |
| 776 | type Defaults struct { |
| 777 | android.ModuleBase |
| 778 | android.DefaultsModuleBase |
| 779 | } |
| 780 | |
| 781 | func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 782 | } |
| 783 | |
| 784 | func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 785 | } |
| 786 | |
| 787 | func defaultsFactory() android.Module { |
| 788 | return DefaultsFactory() |
| 789 | } |
| 790 | |
| 791 | func DefaultsFactory(props ...interface{}) android.Module { |
| 792 | module := &Defaults{} |
| 793 | |
| 794 | module.AddProperties(props...) |
| 795 | module.AddProperties( |
| 796 | &CompilerProperties{}, |
| 797 | &CompilerDeviceProperties{}, |
| 798 | ) |
| 799 | |
| 800 | android.InitDefaultsModule(module) |
| 801 | |
| 802 | return module |
| 803 | } |