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