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 ( |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 22 | "fmt" |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 23 | "path/filepath" |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 24 | "strconv" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 25 | "strings" |
| 26 | |
| 27 | "github.com/google/blueprint" |
Colin Cross | 76b5f0c | 2017-08-29 16:02:06 -0700 | [diff] [blame] | 28 | "github.com/google/blueprint/proptools" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 29 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 30 | "android/soong/android" |
Colin Cross | 3e3e72d | 2017-06-22 17:20:19 -0700 | [diff] [blame] | 31 | "android/soong/java/config" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 32 | ) |
| 33 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 34 | func init() { |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 35 | android.RegisterModuleType("java_defaults", defaultsFactory) |
| 36 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 37 | android.RegisterModuleType("java_library", LibraryFactory) |
| 38 | android.RegisterModuleType("java_library_static", LibraryFactory) |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 39 | android.RegisterModuleType("java_library_host", LibraryHostFactory) |
| 40 | android.RegisterModuleType("java_binary", BinaryFactory) |
| 41 | android.RegisterModuleType("java_binary_host", BinaryHostFactory) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 42 | android.RegisterModuleType("java_test", TestFactory) |
| 43 | android.RegisterModuleType("java_test_host", TestHostFactory) |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 44 | android.RegisterModuleType("java_import", ImportFactory) |
| 45 | android.RegisterModuleType("java_import_host", ImportFactoryHost) |
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 | // Renderscript |
| 53 | // Post-jar passes: |
| 54 | // Proguard |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 55 | // Rmtypedefs |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 56 | // DroidDoc |
| 57 | // Findbugs |
| 58 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 59 | type CompilerProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 60 | // list of source files used to compile the Java module. May be .java, .logtags, .proto, |
| 61 | // or .aidl files. |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 62 | Srcs []string `android:"arch_variant"` |
| 63 | |
| 64 | // list of source files that should not be used to build the Java module. |
| 65 | // This is most useful in the arch/multilib variants to remove non-common files |
| 66 | Exclude_srcs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 67 | |
| 68 | // list of directories containing Java resources |
Colin Cross | 86a63ff | 2017-09-27 17:33:10 -0700 | [diff] [blame] | 69 | Java_resource_dirs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 70 | |
Colin Cross | 86a63ff | 2017-09-27 17:33:10 -0700 | [diff] [blame] | 71 | // list of directories that should be excluded from java_resource_dirs |
| 72 | Exclude_java_resource_dirs []string `android:"arch_variant"` |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 73 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 74 | // list of files to use as Java resources |
| 75 | Java_resources []string `android:"arch_variant"` |
| 76 | |
| 77 | // list of files that should be excluded from java_resources |
| 78 | Exclude_java_resources []string `android:"arch_variant"` |
| 79 | |
Colin Cross | fa5eb23 | 2017-10-01 20:33:03 -0700 | [diff] [blame] | 80 | // don't build against the default libraries (bootclasspath, legacy-test, core-junit, |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 81 | // ext, and framework for device targets) |
Colin Cross | 76b5f0c | 2017-08-29 16:02:06 -0700 | [diff] [blame] | 82 | No_standard_libs *bool |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 83 | |
Colin Cross | fa5eb23 | 2017-10-01 20:33:03 -0700 | [diff] [blame] | 84 | // don't build against the framework libraries (legacy-test, core-junit, |
| 85 | // ext, and framework for device targets) |
| 86 | No_framework_libs *bool |
| 87 | |
Przemyslaw Szczepaniak | 66c0c40 | 2018-03-08 13:21:55 +0000 | [diff] [blame] | 88 | // Use renamed kotlin stdlib (com.android.kotlin.*). This allows kotlin usage without colliding |
| 89 | // with app-provided kotlin stdlib. |
| 90 | Renamed_kotlin_stdlib *bool |
| 91 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 92 | // list of module-specific flags that will be used for javac compiles |
| 93 | Javacflags []string `android:"arch_variant"` |
| 94 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 95 | // list of of java libraries that will be in the classpath |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 96 | Libs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 97 | |
| 98 | // list of java libraries that will be compiled into the resulting jar |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 99 | Static_libs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 100 | |
| 101 | // manifest file to be included in resulting jar |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 102 | Manifest *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 103 | |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 104 | // if not blank, run jarjar using the specified rules file |
Colin Cross | 975f9f7 | 2017-10-17 13:55:55 -0700 | [diff] [blame] | 105 | Jarjar_rules *string `android:"arch_variant"` |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 106 | |
| 107 | // If not blank, set the java version passed to javac as -source and -target |
| 108 | Java_version *string |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 109 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 110 | // If set to true, allow this module to be dexed and installed on devices. Has no |
| 111 | // effect on host modules, which are always considered installable. |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 112 | Installable *bool |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 113 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 114 | // If set to true, include sources used to compile the module in to the final jar |
| 115 | Include_srcs *bool |
| 116 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 117 | // List of modules to use as annotation processors |
| 118 | Annotation_processors []string |
| 119 | |
| 120 | // List of classes to pass to javac to use as annotation processors |
| 121 | Annotation_processor_classes []string |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 122 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 123 | // The number of Java source entries each Javac instance can process |
| 124 | Javac_shard_size *int64 |
| 125 | |
Nan Zhang | 5f8cb42 | 2018-02-06 10:34:32 -0800 | [diff] [blame] | 126 | // Add host jdk tools.jar to bootclasspath |
| 127 | Use_tools_jar *bool |
| 128 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 129 | Openjdk9 struct { |
| 130 | // List of source files that should only be used when passing -source 1.9 |
| 131 | Srcs []string |
| 132 | |
| 133 | // List of javac flags that should only be used when passing -source 1.9 |
| 134 | Javacflags []string |
| 135 | } |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 136 | |
| 137 | Jacoco struct { |
| 138 | // List of classes to include for instrumentation with jacoco to collect coverage |
| 139 | // information at runtime when building with coverage enabled. If unset defaults to all |
| 140 | // classes. |
| 141 | // Supports '*' as the last character of an entry in the list as a wildcard match. |
| 142 | // If preceded by '.' it matches all classes in the package and subpackages, otherwise |
| 143 | // it matches classes in the package that have the class name as a prefix. |
| 144 | Include_filter []string |
| 145 | |
| 146 | // List of classes to exclude from instrumentation with jacoco to collect coverage |
| 147 | // information at runtime when building with coverage enabled. Overrides classes selected |
| 148 | // by the include_filter property. |
| 149 | // Supports '*' as the last character of an entry in the list as a wildcard match. |
| 150 | // If preceded by '.' it matches all classes in the package and subpackages, otherwise |
| 151 | // it matches classes in the package that have the class name as a prefix. |
| 152 | Exclude_filter []string |
| 153 | } |
| 154 | |
Andreas Gampe | f3e5b55 | 2018-01-22 21:27:21 -0800 | [diff] [blame] | 155 | Errorprone struct { |
| 156 | // List of javac flags that should only be used when running errorprone. |
| 157 | Javacflags []string |
| 158 | } |
| 159 | |
Colin Cross | 0f2ee15 | 2017-12-14 15:22:43 -0800 | [diff] [blame] | 160 | Proto struct { |
| 161 | // List of extra options that will be passed to the proto generator. |
| 162 | Output_params []string |
| 163 | } |
| 164 | |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 165 | Instrument bool `blueprint:"mutated"` |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 168 | type CompilerDeviceProperties struct { |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 169 | // list of module-specific flags that will be used for dex compiles |
| 170 | Dxflags []string `android:"arch_variant"` |
| 171 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 172 | // if not blank, set to the version of the sdk to compile against. Defaults to compiling against the current |
| 173 | // sdk if platform_apis is not set. |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 174 | Sdk_version *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 175 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 176 | // if not blank, set the minimum version of the sdk that the compiled artifacts will run against. |
| 177 | // Defaults to sdk_version if not set. |
| 178 | Min_sdk_version *string |
| 179 | |
Colin Cross | 6af2e49 | 2018-05-22 11:12:33 -0700 | [diff] [blame] | 180 | // if true, compile against the platform APIs instead of an SDK. |
| 181 | Platform_apis *bool |
| 182 | |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 183 | Aidl struct { |
| 184 | // Top level directories to pass to aidl tool |
| 185 | Include_dirs []string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 186 | |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 187 | // Directories rooted at the Android.bp file to pass to aidl tool |
| 188 | Local_include_dirs []string |
| 189 | |
| 190 | // directories that should be added as include directories for any aidl sources of modules |
| 191 | // that depend on this module, as well as to aidl for this module. |
| 192 | Export_include_dirs []string |
Martijn Coenen | eab1564 | 2018-03-09 09:29:59 +0100 | [diff] [blame] | 193 | |
| 194 | // whether to generate traces (for systrace) for this interface |
| 195 | Generate_traces *bool |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 196 | } |
Colin Cross | 9243010 | 2017-10-09 14:59:32 -0700 | [diff] [blame] | 197 | |
| 198 | // If true, export a copy of the module as a -hostdex module for host testing. |
| 199 | Hostdex *bool |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 200 | |
David Brazdil | 17ef563 | 2018-06-27 10:27:45 +0100 | [diff] [blame] | 201 | // If set to true, compile dex regardless of installable. Defaults to false. |
| 202 | Compile_dex *bool |
| 203 | |
Colin Cross | 1bd8780 | 2017-12-05 15:31:19 -0800 | [diff] [blame] | 204 | Dex_preopt struct { |
| 205 | // If false, prevent dexpreopting and stripping the dex file from the final jar. Defaults to |
| 206 | // true. |
| 207 | Enabled *bool |
| 208 | |
| 209 | // If true, generate an app image (.art file) for this module. |
| 210 | App_image *bool |
| 211 | |
| 212 | // If true, use a checked-in profile to guide optimization. Defaults to false unless |
| 213 | // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR |
| 214 | // that matches the name of this module, in which case it is defaulted to true. |
| 215 | Profile_guided *bool |
| 216 | |
| 217 | // If set, provides the path to profile relative to the Android.bp file. If not set, |
| 218 | // defaults to searching for a file that matches the name of this module in the default |
| 219 | // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found. |
| 220 | Profile *string |
| 221 | } |
Colin Cross | a22116e | 2017-10-19 14:18:58 -0700 | [diff] [blame] | 222 | |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 223 | Optimize struct { |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 224 | // If false, disable all optimization. Defaults to true for android_app and android_test |
| 225 | // modules, false for java_library and java_test modules. |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 226 | Enabled *bool |
| 227 | |
| 228 | // If true, optimize for size by removing unused code. Defaults to true for apps, |
| 229 | // false for libraries and tests. |
| 230 | Shrink *bool |
| 231 | |
| 232 | // If true, optimize bytecode. Defaults to false. |
| 233 | Optimize *bool |
| 234 | |
| 235 | // If true, obfuscate bytecode. Defaults to false. |
| 236 | Obfuscate *bool |
| 237 | |
| 238 | // If true, do not use the flag files generated by aapt that automatically keep |
| 239 | // classes referenced by the app manifest. Defaults to false. |
| 240 | No_aapt_flags *bool |
| 241 | |
| 242 | // Flags to pass to proguard. |
| 243 | Proguard_flags []string |
| 244 | |
| 245 | // Specifies the locations of files containing proguard flags. |
| 246 | Proguard_flags_files []string |
| 247 | } |
| 248 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 249 | // When targeting 1.9, override the modules to use with --system |
| 250 | System_modules *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 253 | // Module contains the properties and members used by all java module types |
| 254 | type Module struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 255 | android.ModuleBase |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 256 | android.DefaultableModuleBase |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 257 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 258 | properties CompilerProperties |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 259 | protoProperties android.ProtoProperties |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 260 | deviceProperties CompilerDeviceProperties |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 261 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 262 | // header jar file suitable for inserting into the bootclasspath/classpath of another compile |
| 263 | headerJarFile android.Path |
| 264 | |
| 265 | // full implementation jar file suitable for static dependency of another module compile |
| 266 | implementationJarFile android.Path |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 267 | |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 268 | // output file containing classes.dex |
| 269 | dexJarFile android.Path |
| 270 | |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 271 | // output file containing uninstrumented classes that will be instrumented by jacoco |
| 272 | jacocoReportClassesFile android.Path |
| 273 | |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 274 | // output file containing mapping of obfuscated names |
| 275 | proguardDictionary android.Path |
| 276 | |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 277 | // output file suitable for installing or running |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 278 | outputFile android.Path |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 279 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 280 | exportAidlIncludeDirs android.Paths |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 281 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 282 | logtagsSrcs android.Paths |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 283 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 284 | // installed file for binary dependency |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 285 | installFile android.Path |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 286 | |
| 287 | // list of .java files and srcjars that was passed to javac |
| 288 | compiledJavaSrcs android.Paths |
| 289 | compiledSrcJars android.Paths |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 290 | |
| 291 | // list of extra progurad flag files |
| 292 | extraProguardFlagFiles android.Paths |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 293 | |
| 294 | // list of SDK lib names that this java moudule is exporting |
| 295 | exportedSdkLibs []string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 298 | func (j *Module) Srcs() android.Paths { |
| 299 | return android.Paths{j.implementationJarFile} |
| 300 | } |
| 301 | |
| 302 | var _ android.SourceFileProducer = (*Module)(nil) |
| 303 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 304 | type Dependency interface { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 305 | HeaderJars() android.Paths |
| 306 | ImplementationJars() android.Paths |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 307 | AidlIncludeDirs() android.Paths |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 308 | ExportedSdkLibs() []string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 311 | type SdkLibraryDependency interface { |
| 312 | HeaderJars(linkType linkType) android.Paths |
| 313 | } |
| 314 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 315 | type SrcDependency interface { |
| 316 | CompiledSrcs() android.Paths |
| 317 | CompiledSrcJars() android.Paths |
| 318 | } |
| 319 | |
| 320 | func (j *Module) CompiledSrcs() android.Paths { |
| 321 | return j.compiledJavaSrcs |
| 322 | } |
| 323 | |
| 324 | func (j *Module) CompiledSrcJars() android.Paths { |
| 325 | return j.compiledSrcJars |
| 326 | } |
| 327 | |
| 328 | var _ SrcDependency = (*Module)(nil) |
| 329 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 330 | func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { |
| 331 | android.InitAndroidArchModule(module, hod, android.MultilibCommon) |
| 332 | android.InitDefaultableModule(module) |
| 333 | } |
| 334 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 335 | type dependencyTag struct { |
| 336 | blueprint.BaseDependencyTag |
| 337 | name string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 340 | var ( |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 341 | staticLibTag = dependencyTag{name: "staticlib"} |
| 342 | libTag = dependencyTag{name: "javalib"} |
Colin Cross | 6a77c98 | 2018-06-19 22:43:34 -0700 | [diff] [blame] | 343 | annoTag = dependencyTag{name: "annotation processor"} |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 344 | bootClasspathTag = dependencyTag{name: "bootclasspath"} |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 345 | systemModulesTag = dependencyTag{name: "system modules"} |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 346 | frameworkResTag = dependencyTag{name: "framework-res"} |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 347 | frameworkApkTag = dependencyTag{name: "framework-apk"} |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 348 | kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"} |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 349 | proguardRaiseTag = dependencyTag{name: "proguard-raise"} |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 350 | ) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 351 | |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 352 | type sdkDep struct { |
Colin Cross | 47ff252 | 2017-10-02 14:22:08 -0700 | [diff] [blame] | 353 | useModule, useFiles, useDefaultLibs, invalidVersion bool |
| 354 | |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 355 | modules []string |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 356 | systemModules string |
| 357 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 358 | frameworkResModule string |
| 359 | |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 360 | jars android.Paths |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 361 | aidl android.Path |
| 362 | } |
| 363 | |
Colin Cross | 3144dfc | 2018-01-03 15:06:47 -0800 | [diff] [blame] | 364 | func (j *Module) shouldInstrument(ctx android.BaseContext) bool { |
| 365 | return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") |
| 366 | } |
| 367 | |
| 368 | func (j *Module) shouldInstrumentStatic(ctx android.BaseContext) bool { |
| 369 | return j.shouldInstrument(ctx) && |
| 370 | (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") || |
| 371 | ctx.Config().UnbundledBuild()) |
| 372 | } |
| 373 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 374 | func (j *Module) sdkVersion() string { |
| 375 | return String(j.deviceProperties.Sdk_version) |
| 376 | } |
| 377 | |
| 378 | func (j *Module) minSdkVersion() string { |
| 379 | if j.deviceProperties.Min_sdk_version != nil { |
| 380 | return *j.deviceProperties.Min_sdk_version |
| 381 | } |
| 382 | return j.sdkVersion() |
| 383 | } |
| 384 | |
| 385 | type sdkContext interface { |
| 386 | // sdkVersion eturns the sdk_version property of the current module, or an empty string if it is not set. |
| 387 | sdkVersion() string |
| 388 | // minSdkVersion returns the min_sdk_version property of the current module, or sdkVersion() if it is not set. |
| 389 | minSdkVersion() string |
| 390 | } |
| 391 | |
| 392 | func sdkVersionOrDefault(ctx android.BaseContext, v string) string { |
| 393 | switch v { |
| 394 | case "", "current", "system_current", "test_current", "core_current": |
| 395 | return ctx.Config().DefaultAppTargetSdk() |
| 396 | default: |
| 397 | return v |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | // Returns a sdk version as a number. For modules targeting an unreleased SDK (meaning it does not yet have a number) |
| 402 | // it returns android.FutureApiLevel (10000). |
| 403 | func sdkVersionToNumber(ctx android.BaseContext, v string) (int, error) { |
| 404 | switch v { |
| 405 | case "", "current", "test_current", "system_current", "core_current": |
| 406 | return ctx.Config().DefaultAppTargetSdkInt(), nil |
| 407 | default: |
| 408 | n := android.GetNumericSdkVersion(v) |
| 409 | if i, err := strconv.Atoi(n); err != nil { |
| 410 | return -1, fmt.Errorf("invalid sdk version %q", n) |
| 411 | } else { |
| 412 | return i, nil |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | func sdkVersionToNumberAsString(ctx android.BaseContext, v string) (string, error) { |
| 418 | n, err := sdkVersionToNumber(ctx, v) |
| 419 | if err != nil { |
| 420 | return "", err |
| 421 | } |
| 422 | return strconv.Itoa(n), nil |
| 423 | } |
| 424 | |
| 425 | func decodeSdkDep(ctx android.BaseContext, sdkContext sdkContext) sdkDep { |
| 426 | v := sdkContext.sdkVersion() |
| 427 | i, err := sdkVersionToNumber(ctx, v) |
| 428 | if err != nil { |
| 429 | ctx.PropertyErrorf("sdk_version", "%s", err) |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 430 | return sdkDep{} |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Jiyong Park | 1a5d7b1 | 2018-01-15 15:05:10 +0900 | [diff] [blame] | 433 | // Ensures that the specificed system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor apks) |
| 434 | // or PRODUCT_SYSTEMSDK_VERSIONS (for other apks or when BOARD_SYSTEMSDK_VERSIONS is not set) |
| 435 | if strings.HasPrefix(v, "system_") && i != android.FutureApiLevel { |
| 436 | allowed_versions := ctx.DeviceConfig().PlatformSystemSdkVersions() |
| 437 | if ctx.DeviceSpecific() || ctx.SocSpecific() { |
| 438 | if len(ctx.DeviceConfig().SystemSdkVersions()) > 0 { |
| 439 | allowed_versions = ctx.DeviceConfig().SystemSdkVersions() |
| 440 | } |
| 441 | } |
| 442 | version := strings.TrimPrefix(v, "system_") |
| 443 | if len(allowed_versions) > 0 && !android.InList(version, allowed_versions) { |
| 444 | ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q", |
| 445 | v, allowed_versions) |
| 446 | } |
| 447 | } |
| 448 | |
Anton Hansson | f66efeb | 2018-04-11 13:57:30 +0100 | [diff] [blame] | 449 | toPrebuilt := func(sdk string) sdkDep { |
| 450 | var api, v string |
| 451 | if strings.Contains(sdk, "_") { |
| 452 | t := strings.Split(sdk, "_") |
| 453 | api = t[0] |
| 454 | v = t[1] |
| 455 | } else { |
| 456 | api = "public" |
| 457 | v = sdk |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 458 | } |
Anton Hansson | f66efeb | 2018-04-11 13:57:30 +0100 | [diff] [blame] | 459 | dir := filepath.Join("prebuilts", "sdk", v, api) |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 460 | jar := filepath.Join(dir, "android.jar") |
Anton Hansson | f66efeb | 2018-04-11 13:57:30 +0100 | [diff] [blame] | 461 | // There's no aidl for other SDKs yet. |
| 462 | // TODO(77525052): Add aidl files for other SDKs too. |
| 463 | public_dir := filepath.Join("prebuilts", "sdk", v, "public") |
| 464 | aidl := filepath.Join(public_dir, "framework.aidl") |
Colin Cross | 32f3898 | 2018-02-22 11:47:25 -0800 | [diff] [blame] | 465 | jarPath := android.ExistentPathForSource(ctx, jar) |
| 466 | aidlPath := android.ExistentPathForSource(ctx, aidl) |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 467 | lambdaStubsPath := android.PathForSource(ctx, config.SdkLambdaStubsPath) |
Colin Cross | 47ff252 | 2017-10-02 14:22:08 -0700 | [diff] [blame] | 468 | |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 469 | if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() { |
Colin Cross | 47ff252 | 2017-10-02 14:22:08 -0700 | [diff] [blame] | 470 | return sdkDep{ |
| 471 | invalidVersion: true, |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 472 | modules: []string{fmt.Sprintf("sdk_%s_%s_android", api, v)}, |
Colin Cross | 47ff252 | 2017-10-02 14:22:08 -0700 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 476 | if !jarPath.Valid() { |
| 477 | ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar) |
| 478 | return sdkDep{} |
| 479 | } |
Colin Cross | 47ff252 | 2017-10-02 14:22:08 -0700 | [diff] [blame] | 480 | |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 481 | if !aidlPath.Valid() { |
| 482 | ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl) |
| 483 | return sdkDep{} |
| 484 | } |
Colin Cross | 47ff252 | 2017-10-02 14:22:08 -0700 | [diff] [blame] | 485 | |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 486 | return sdkDep{ |
| 487 | useFiles: true, |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 488 | jars: android.Paths{jarPath.Path(), lambdaStubsPath}, |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 489 | aidl: aidlPath.Path(), |
| 490 | } |
| 491 | } |
| 492 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 493 | toModule := func(m, r string) sdkDep { |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 494 | ret := sdkDep{ |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 495 | useModule: true, |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 496 | modules: []string{m, config.DefaultLambdaStubsLibrary}, |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 497 | systemModules: m + "_system_modules", |
| 498 | frameworkResModule: r, |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 499 | } |
| 500 | if m == "core.current.stubs" { |
| 501 | ret.systemModules = "core-system-modules" |
| 502 | } |
| 503 | return ret |
| 504 | } |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 505 | |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 506 | if ctx.Config().UnbundledBuild() && v != "" { |
Anton Hansson | f66efeb | 2018-04-11 13:57:30 +0100 | [diff] [blame] | 507 | return toPrebuilt(v) |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | switch v { |
| 511 | case "": |
| 512 | return sdkDep{ |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 513 | useDefaultLibs: true, |
| 514 | frameworkResModule: "framework-res", |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 515 | } |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 516 | case "current": |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 517 | return toModule("android_stubs_current", "framework-res") |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 518 | case "system_current": |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 519 | return toModule("android_system_stubs_current", "framework-res") |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 520 | case "test_current": |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 521 | return toModule("android_test_stubs_current", "framework-res") |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 522 | case "core_current": |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 523 | return toModule("core.current.stubs", "") |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 524 | default: |
Anton Hansson | f66efeb | 2018-04-11 13:57:30 +0100 | [diff] [blame] | 525 | return toPrebuilt(v) |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 529 | func (j *Module) deps(ctx android.BottomUpMutatorContext) { |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 530 | if ctx.Device() { |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 531 | if !Bool(j.properties.No_standard_libs) { |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 532 | sdkDep := decodeSdkDep(ctx, sdkContext(j)) |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 533 | if sdkDep.useDefaultLibs { |
Colin Cross | cb2c929 | 2017-09-23 19:57:16 -0700 | [diff] [blame] | 534 | ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...) |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 535 | if ctx.Config().TargetOpenJDK9() { |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 536 | ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules) |
| 537 | } |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 538 | if !Bool(j.properties.No_framework_libs) { |
Colin Cross | fa5eb23 | 2017-10-01 20:33:03 -0700 | [diff] [blame] | 539 | ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...) |
| 540 | } |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 541 | } else if sdkDep.useModule { |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 542 | if ctx.Config().TargetOpenJDK9() { |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 543 | ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules) |
| 544 | } |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 545 | ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...) |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 546 | if Bool(j.deviceProperties.Optimize.Enabled) { |
| 547 | ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultBootclasspathLibraries...) |
| 548 | ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultLibraries...) |
| 549 | } |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 550 | } |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 551 | } else if j.deviceProperties.System_modules == nil { |
| 552 | ctx.PropertyErrorf("no_standard_libs", |
| 553 | "system_modules is required to be set when no_standard_libs is true, did you mean no_framework_libs?") |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 554 | } else if *j.deviceProperties.System_modules != "none" && ctx.Config().TargetOpenJDK9() { |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 555 | ctx.AddDependency(ctx.Module(), systemModulesTag, *j.deviceProperties.System_modules) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 556 | } |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 557 | if ctx.ModuleName() == "framework" { |
| 558 | ctx.AddDependency(ctx.Module(), frameworkResTag, "framework-res") |
| 559 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 560 | if ctx.ModuleName() == "android_stubs_current" || |
| 561 | ctx.ModuleName() == "android_system_stubs_current" || |
Nan Zhang | 16c0a31 | 2018-06-13 17:42:48 -0700 | [diff] [blame] | 562 | ctx.ModuleName() == "android_test_stubs_current" || |
| 563 | ctx.ModuleName() == "metalava_android_stubs_current" || |
| 564 | ctx.ModuleName() == "metalava_android_system_stubs_current" || |
| 565 | ctx.ModuleName() == "metalava_android_test_stubs_current" { |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 566 | ctx.AddDependency(ctx.Module(), frameworkApkTag, "framework-res") |
| 567 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 568 | } |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 569 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 570 | ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...) |
| 571 | ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...) |
Mathew Inwood | 878c662 | 2018-07-02 16:34:51 +0100 | [diff] [blame] | 572 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 573 | {"arch", ctx.Config().BuildOsCommonVariant}, |
| 574 | }, annoTag, j.properties.Annotation_processors...) |
Colin Cross | 7f9036c | 2017-08-30 13:27:57 -0700 | [diff] [blame] | 575 | android.ExtractSourcesDeps(ctx, j.properties.Srcs) |
Nan Zhang | 27e284d | 2018-02-09 21:03:53 +0000 | [diff] [blame] | 576 | android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs) |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 577 | android.ExtractSourcesDeps(ctx, j.properties.Java_resources) |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 578 | android.ExtractSourceDeps(ctx, j.properties.Manifest) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 579 | |
| 580 | if j.hasSrcExt(".proto") { |
| 581 | protoDeps(ctx, &j.protoProperties) |
| 582 | } |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 583 | |
| 584 | if j.hasSrcExt(".kt") { |
| 585 | // TODO(ccross): move this to a mutator pass that can tell if generated sources contain |
| 586 | // Kotlin files |
| 587 | ctx.AddDependency(ctx.Module(), kotlinStdlibTag, "kotlin-stdlib") |
| 588 | } |
Colin Cross | 3144dfc | 2018-01-03 15:06:47 -0800 | [diff] [blame] | 589 | |
| 590 | if j.shouldInstrumentStatic(ctx) { |
| 591 | ctx.AddDependency(ctx.Module(), staticLibTag, "jacocoagent") |
| 592 | } |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | func hasSrcExt(srcs []string, ext string) bool { |
| 596 | for _, src := range srcs { |
| 597 | if filepath.Ext(src) == ext { |
| 598 | return true |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | return false |
| 603 | } |
| 604 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 605 | func shardPaths(paths android.Paths, shardSize int) []android.Paths { |
| 606 | ret := make([]android.Paths, 0, (len(paths)+shardSize-1)/shardSize) |
| 607 | for len(paths) > shardSize { |
| 608 | ret = append(ret, paths[0:shardSize]) |
| 609 | paths = paths[shardSize:] |
| 610 | } |
| 611 | if len(paths) > 0 { |
| 612 | ret = append(ret, paths) |
| 613 | } |
| 614 | return ret |
| 615 | } |
| 616 | |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 617 | func (j *Module) hasSrcExt(ext string) bool { |
| 618 | return hasSrcExt(j.properties.Srcs, ext) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 621 | func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 622 | aidlIncludeDirs android.Paths) []string { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 623 | |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 624 | aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs) |
| 625 | aidlIncludes = append(aidlIncludes, |
| 626 | android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...) |
| 627 | aidlIncludes = append(aidlIncludes, |
| 628 | android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 629 | |
| 630 | var flags []string |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 631 | if aidlPreprocess.Valid() { |
| 632 | flags = append(flags, "-p"+aidlPreprocess.String()) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 633 | } else { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 634 | flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I")) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 637 | flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I")) |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 638 | flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I")) |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 639 | flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String()) |
Colin Cross | 32f3898 | 2018-02-22 11:47:25 -0800 | [diff] [blame] | 640 | if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() { |
Colin Cross | d48633a | 2017-07-13 14:41:17 -0700 | [diff] [blame] | 641 | flags = append(flags, "-I"+src.String()) |
| 642 | } |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 643 | |
Martijn Coenen | eab1564 | 2018-03-09 09:29:59 +0100 | [diff] [blame] | 644 | if Bool(j.deviceProperties.Aidl.Generate_traces) { |
| 645 | flags = append(flags, "-t") |
| 646 | } |
| 647 | |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 648 | return flags |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 651 | type deps struct { |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 652 | classpath classpath |
| 653 | bootClasspath classpath |
Colin Cross | 6a77c98 | 2018-06-19 22:43:34 -0700 | [diff] [blame] | 654 | processorPath classpath |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 655 | staticJars android.Paths |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 656 | staticHeaderJars android.Paths |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 657 | staticJarResources android.Paths |
| 658 | aidlIncludeDirs android.Paths |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 659 | srcs android.Paths |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 660 | srcJars android.Paths |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 661 | systemModules android.Path |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 662 | aidlPreprocess android.OptionalPath |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 663 | kotlinStdlib android.Paths |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 664 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 665 | |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 666 | func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) { |
| 667 | for _, f := range dep.Srcs() { |
| 668 | if f.Ext() != ".jar" { |
| 669 | ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency", |
| 670 | ctx.OtherModuleName(dep.(blueprint.Module))) |
| 671 | } |
| 672 | } |
| 673 | } |
| 674 | |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 675 | type linkType int |
| 676 | |
| 677 | const ( |
| 678 | javaCore linkType = iota |
| 679 | javaSdk |
| 680 | javaSystem |
| 681 | javaPlatform |
| 682 | ) |
| 683 | |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 684 | func getLinkType(m *Module, name string) linkType { |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 685 | ver := m.sdkVersion() |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 686 | noStdLibs := Bool(m.properties.No_standard_libs) |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 687 | switch { |
Nan Zhang | 16c0a31 | 2018-06-13 17:42:48 -0700 | [diff] [blame] | 688 | case name == "core.current.stubs" || ver == "core_current" || noStdLibs || name == "stub-annotations": |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 689 | return javaCore |
Nan Zhang | 16c0a31 | 2018-06-13 17:42:48 -0700 | [diff] [blame] | 690 | case name == "android_system_stubs_current" || strings.HasPrefix(ver, "system_") || name == "metalava_android_system_stubs_current": |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 691 | return javaSystem |
Nan Zhang | 16c0a31 | 2018-06-13 17:42:48 -0700 | [diff] [blame] | 692 | case name == "android_test_stubs_current" || strings.HasPrefix(ver, "test_") || name == "metalava_android_test_stubs_current": |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 693 | return javaPlatform |
Nan Zhang | 16c0a31 | 2018-06-13 17:42:48 -0700 | [diff] [blame] | 694 | case name == "android_stubs_current" || ver == "current" || name == "metalava_android_stubs_current": |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 695 | return javaSdk |
| 696 | case ver == "": |
| 697 | return javaPlatform |
| 698 | default: |
| 699 | if _, err := strconv.Atoi(ver); err != nil { |
| 700 | panic(fmt.Errorf("expected sdk_version to be a number, got %q", ver)) |
| 701 | } |
| 702 | return javaSdk |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 706 | func checkLinkType(ctx android.ModuleContext, from *Module, to *Library, tag dependencyTag) { |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 707 | if ctx.Host() { |
| 708 | return |
| 709 | } |
| 710 | |
| 711 | myLinkType := getLinkType(from, ctx.ModuleName()) |
| 712 | otherLinkType := getLinkType(&to.Module, ctx.OtherModuleName(to)) |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 713 | commonMessage := "Adjust sdk_version: property of the source or target module so that target module is built with the same or smaller API set than the source." |
| 714 | |
| 715 | switch myLinkType { |
| 716 | case javaCore: |
| 717 | if otherLinkType != javaCore { |
| 718 | ctx.ModuleErrorf("compiles against core Java API, but dependency %q is compiling against non-core Java APIs."+commonMessage, |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 719 | ctx.OtherModuleName(to)) |
| 720 | } |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 721 | break |
| 722 | case javaSdk: |
| 723 | if otherLinkType != javaCore && otherLinkType != javaSdk { |
| 724 | ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage, |
| 725 | ctx.OtherModuleName(to)) |
| 726 | } |
| 727 | break |
| 728 | case javaSystem: |
| 729 | if otherLinkType == javaPlatform { |
| 730 | ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage, |
| 731 | ctx.OtherModuleName(to)) |
| 732 | } |
| 733 | break |
| 734 | case javaPlatform: |
| 735 | // no restriction on link-type |
| 736 | break |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 740 | func (j *Module) collectDeps(ctx android.ModuleContext) deps { |
| 741 | var deps deps |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 742 | |
Colin Cross | 300f038 | 2018-03-06 13:11:51 -0800 | [diff] [blame] | 743 | if ctx.Device() { |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 744 | sdkDep := decodeSdkDep(ctx, sdkContext(j)) |
Colin Cross | 300f038 | 2018-03-06 13:11:51 -0800 | [diff] [blame] | 745 | if sdkDep.invalidVersion { |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 746 | ctx.AddMissingDependencies(sdkDep.modules) |
Colin Cross | 300f038 | 2018-03-06 13:11:51 -0800 | [diff] [blame] | 747 | } else if sdkDep.useFiles { |
| 748 | // sdkDep.jar is actually equivalent to turbine header.jar. |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 749 | deps.classpath = append(deps.classpath, sdkDep.jars...) |
Colin Cross | 300f038 | 2018-03-06 13:11:51 -0800 | [diff] [blame] | 750 | deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl) |
| 751 | } |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 754 | ctx.VisitDirectDeps(func(module android.Module) { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 755 | otherName := ctx.OtherModuleName(module) |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 756 | tag := ctx.OtherModuleDependencyTag(module) |
| 757 | |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 758 | if to, ok := module.(*Library); ok { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 759 | switch tag { |
| 760 | case bootClasspathTag, libTag, staticLibTag: |
| 761 | checkLinkType(ctx, j, to, tag.(dependencyTag)) |
| 762 | } |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 763 | } |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 764 | switch dep := module.(type) { |
| 765 | case Dependency: |
| 766 | switch tag { |
| 767 | case bootClasspathTag: |
| 768 | deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...) |
| 769 | case libTag: |
| 770 | deps.classpath = append(deps.classpath, dep.HeaderJars()...) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 771 | // sdk lib names from dependencies are re-exported |
| 772 | j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...) |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 773 | case staticLibTag: |
| 774 | deps.classpath = append(deps.classpath, dep.HeaderJars()...) |
| 775 | deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...) |
| 776 | deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 777 | // sdk lib names from dependencies are re-exported |
| 778 | j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...) |
Colin Cross | 6a77c98 | 2018-06-19 22:43:34 -0700 | [diff] [blame] | 779 | case annoTag: |
| 780 | deps.processorPath = append(deps.processorPath, dep.ImplementationJars()...) |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 781 | case frameworkResTag: |
| 782 | if ctx.ModuleName() == "framework" { |
| 783 | // framework.jar has a one-off dependency on the R.java and Manifest.java files |
| 784 | // generated by framework-res.apk |
| 785 | deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar) |
| 786 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 787 | case frameworkApkTag: |
| 788 | if ctx.ModuleName() == "android_stubs_current" || |
| 789 | ctx.ModuleName() == "android_system_stubs_current" || |
Nan Zhang | 16c0a31 | 2018-06-13 17:42:48 -0700 | [diff] [blame] | 790 | ctx.ModuleName() == "android_test_stubs_current" || |
| 791 | ctx.ModuleName() == "metalava_android_stubs_current" || |
| 792 | ctx.ModuleName() == "metalava_android_system_stubs_current" || |
| 793 | ctx.ModuleName() == "metalava_android_test_stubs_current" { |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 794 | // framework stubs.jar need to depend on framework-res.apk, in order to pull the |
| 795 | // resource files out of there for aapt. |
| 796 | // |
| 797 | // Normally the package rule runs aapt, which includes the resource, |
| 798 | // but we're not running that in our package rule so just copy in the |
| 799 | // resource files here. |
| 800 | deps.staticJarResources = append(deps.staticJarResources, dep.(*AndroidApp).exportPackage) |
| 801 | } |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 802 | case kotlinStdlibTag: |
| 803 | deps.kotlinStdlib = dep.HeaderJars() |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 807 | case SdkLibraryDependency: |
| 808 | switch tag { |
| 809 | case libTag: |
| 810 | deps.classpath = append(deps.classpath, dep.HeaderJars(getLinkType(j, ctx.ModuleName()))...) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 811 | // names of sdk libs that are directly depended are exported |
| 812 | j.exportedSdkLibs = append(j.exportedSdkLibs, otherName) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 813 | default: |
| 814 | ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName) |
| 815 | } |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 816 | case android.SourceFileProducer: |
| 817 | switch tag { |
| 818 | case libTag: |
| 819 | checkProducesJars(ctx, dep) |
| 820 | deps.classpath = append(deps.classpath, dep.Srcs()...) |
| 821 | case staticLibTag: |
| 822 | checkProducesJars(ctx, dep) |
| 823 | deps.classpath = append(deps.classpath, dep.Srcs()...) |
| 824 | deps.staticJars = append(deps.staticJars, dep.Srcs()...) |
| 825 | deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...) |
| 826 | case android.DefaultsDepTag, android.SourceDepTag: |
| 827 | // Nothing to do |
| 828 | default: |
| 829 | ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName) |
| 830 | } |
| 831 | default: |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 832 | switch tag { |
| 833 | case android.DefaultsDepTag, android.SourceDepTag: |
Dan Willemsen | d6ba0d5 | 2017-09-13 15:46:47 -0700 | [diff] [blame] | 834 | // Nothing to do |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 835 | case systemModulesTag: |
| 836 | if deps.systemModules != nil { |
| 837 | panic("Found two system module dependencies") |
| 838 | } |
| 839 | sm := module.(*SystemModules) |
| 840 | if sm.outputFile == nil { |
| 841 | panic("Missing directory for system module dependency") |
| 842 | } |
| 843 | deps.systemModules = sm.outputFile |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 844 | default: |
| 845 | ctx.ModuleErrorf("depends on non-java module %q", otherName) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 846 | } |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 847 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 848 | }) |
| 849 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 850 | j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs) |
| 851 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 852 | return deps |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 855 | func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) string { |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 856 | var ret string |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 857 | sdk, err := sdkVersionToNumber(ctx, sdkContext.sdkVersion()) |
| 858 | if err != nil { |
| 859 | ctx.PropertyErrorf("sdk_version", "%s", err) |
| 860 | } |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 861 | if javaVersion != "" { |
| 862 | ret = javaVersion |
| 863 | } else if ctx.Device() && sdk <= 23 { |
| 864 | ret = "1.7" |
| 865 | } else if ctx.Device() && sdk <= 26 || !ctx.Config().TargetOpenJDK9() { |
| 866 | ret = "1.8" |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 867 | } else if ctx.Device() && sdkContext.sdkVersion() != "" && sdk == android.FutureApiLevel { |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 868 | // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current" |
| 869 | ret = "1.8" |
| 870 | } else { |
| 871 | ret = "1.9" |
| 872 | } |
| 873 | |
| 874 | return ret |
| 875 | } |
| 876 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 877 | func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 878 | |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 879 | var flags javaBuilderFlags |
| 880 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 881 | // javac flags. |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 882 | javacFlags := j.properties.Javacflags |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 883 | if ctx.Config().TargetOpenJDK9() { |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 884 | javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 885 | } |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 886 | if ctx.Config().MinimizeJavaDebugInfo() { |
Colin Cross | 126a25c | 2017-10-31 13:55:34 -0700 | [diff] [blame] | 887 | // Override the -g flag passed globally to remove local variable debug info to reduce |
| 888 | // disk and memory usage. |
| 889 | javacFlags = append(javacFlags, "-g:source,lines") |
| 890 | } |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 891 | if len(javacFlags) > 0 { |
| 892 | // optimization. |
| 893 | ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " ")) |
| 894 | flags.javacFlags = "$javacFlags" |
Colin Cross | 4f26bc0 | 2017-09-06 12:52:16 -0700 | [diff] [blame] | 895 | } |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 896 | |
Colin Cross | 6654810 | 2018-06-19 22:47:35 -0700 | [diff] [blame] | 897 | if ctx.Config().RunErrorProne() { |
| 898 | if config.ErrorProneClasspath == nil { |
| 899 | ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?") |
| 900 | } |
| 901 | |
| 902 | errorProneFlags := []string{ |
| 903 | "-Xplugin:ErrorProne", |
| 904 | "${config.ErrorProneChecks}", |
| 905 | } |
| 906 | errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...) |
| 907 | |
| 908 | flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " + |
| 909 | "'" + strings.Join(errorProneFlags, " ") + "'" |
| 910 | flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath)) |
Andreas Gampe | f3e5b55 | 2018-01-22 21:27:21 -0800 | [diff] [blame] | 911 | } |
| 912 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 913 | // javaVersion flag. |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 914 | flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j)) |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 915 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 916 | // classpath |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 917 | flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...) |
| 918 | flags.classpath = append(flags.classpath, deps.classpath...) |
Colin Cross | 6a77c98 | 2018-06-19 22:43:34 -0700 | [diff] [blame] | 919 | flags.processorPath = append(flags.processorPath, deps.processorPath...) |
Colin Cross | 7fdd2b7 | 2018-01-02 18:14:25 -0800 | [diff] [blame] | 920 | |
| 921 | if len(flags.bootClasspath) == 0 && ctx.Host() && !ctx.Config().TargetOpenJDK9() && |
| 922 | !Bool(j.properties.No_standard_libs) && |
| 923 | inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) { |
| 924 | // Give host-side tools a version of OpenJDK's standard libraries |
| 925 | // close to what they're targeting. As of Dec 2017, AOSP is only |
| 926 | // bundling OpenJDK 8 and 9, so nothing < 8 is available. |
| 927 | // |
| 928 | // When building with OpenJDK 8, the following should have no |
| 929 | // effect since those jars would be available by default. |
| 930 | // |
| 931 | // When building with OpenJDK 9 but targeting a version < 1.8, |
| 932 | // putting them on the bootclasspath means that: |
| 933 | // a) code can't (accidentally) refer to OpenJDK 9 specific APIs |
| 934 | // b) references to existing APIs are not reinterpreted in an |
| 935 | // OpenJDK 9-specific way, eg. calls to subclasses of |
| 936 | // java.nio.Buffer as in http://b/70862583 |
| 937 | java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME") |
| 938 | flags.bootClasspath = append(flags.bootClasspath, |
| 939 | android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"), |
| 940 | android.PathForSource(ctx, java8Home, "jre/lib/rt.jar")) |
Nan Zhang | 5f8cb42 | 2018-02-06 10:34:32 -0800 | [diff] [blame] | 941 | if Bool(j.properties.Use_tools_jar) { |
| 942 | flags.bootClasspath = append(flags.bootClasspath, |
| 943 | android.PathForSource(ctx, java8Home, "lib/tools.jar")) |
| 944 | } |
Colin Cross | 7fdd2b7 | 2018-01-02 18:14:25 -0800 | [diff] [blame] | 945 | } |
| 946 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 947 | // systemModules |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 948 | if deps.systemModules != nil { |
| 949 | flags.systemModules = append(flags.systemModules, deps.systemModules) |
| 950 | } |
| 951 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 952 | // aidl flags. |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 953 | aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs) |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 954 | if len(aidlFlags) > 0 { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 955 | // optimization. |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 956 | ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " ")) |
| 957 | flags.aidlFlags = "$aidlFlags" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 958 | } |
| 959 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 960 | return flags |
| 961 | } |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 962 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 963 | func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path) { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 964 | |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 965 | j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 966 | |
| 967 | deps := j.collectDeps(ctx) |
| 968 | flags := j.collectBuilderFlags(ctx, deps) |
| 969 | |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 970 | if ctx.Config().TargetOpenJDK9() { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 971 | j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...) |
| 972 | } |
| 973 | srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 974 | if hasSrcExt(srcFiles.Strings(), ".proto") { |
Colin Cross | 0f2ee15 | 2017-12-14 15:22:43 -0800 | [diff] [blame] | 975 | flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 976 | } |
| 977 | |
Colin Cross | af05017 | 2017-11-15 23:01:59 -0800 | [diff] [blame] | 978 | srcFiles = j.genSources(ctx, srcFiles, flags) |
| 979 | |
| 980 | srcJars := srcFiles.FilterByExt(".srcjar") |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 981 | srcJars = append(srcJars, deps.srcJars...) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 982 | srcJars = append(srcJars, extraSrcJars...) |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 983 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 984 | var jars android.Paths |
| 985 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 986 | jarName := ctx.ModuleName() + ".jar" |
| 987 | |
Przemyslaw Szczepaniak | 4b5fe9d | 2018-02-13 14:32:54 +0000 | [diff] [blame] | 988 | javaSrcFiles := srcFiles.FilterByExt(".java") |
| 989 | var uniqueSrcFiles android.Paths |
| 990 | set := make(map[string]bool) |
| 991 | for _, v := range javaSrcFiles { |
| 992 | if _, found := set[v.String()]; !found { |
| 993 | set[v.String()] = true |
| 994 | uniqueSrcFiles = append(uniqueSrcFiles, v) |
| 995 | } |
| 996 | } |
| 997 | |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 998 | var stripFiles []string |
| 999 | |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 1000 | if srcFiles.HasExt(".kt") { |
| 1001 | // If there are kotlin files, compile them first but pass all the kotlin and java files |
| 1002 | // kotlinc will use the java files to resolve types referenced by the kotlin files, but |
| 1003 | // won't emit any classes for them. |
| 1004 | |
| 1005 | flags.kotlincFlags = "-no-stdlib" |
Przemyslaw Szczepaniak | 66c0c40 | 2018-03-08 13:21:55 +0000 | [diff] [blame] | 1006 | |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 1007 | if ctx.Device() { |
| 1008 | flags.kotlincFlags += " -no-jdk" |
| 1009 | } |
| 1010 | |
Przemyslaw Szczepaniak | 4b5fe9d | 2018-02-13 14:32:54 +0000 | [diff] [blame] | 1011 | var kotlinSrcFiles android.Paths |
| 1012 | kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...) |
| 1013 | kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...) |
| 1014 | |
Przemyslaw Szczepaniak | e3d26bf | 2018-03-05 16:06:42 +0000 | [diff] [blame] | 1015 | flags.kotlincClasspath = append(flags.kotlincClasspath, deps.bootClasspath...) |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 1016 | flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...) |
| 1017 | flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...) |
| 1018 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 1019 | kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName) |
Przemyslaw Szczepaniak | 4b5fe9d | 2018-02-13 14:32:54 +0000 | [diff] [blame] | 1020 | TransformKotlinToClasses(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags) |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 1021 | if ctx.Failed() { |
| 1022 | return |
| 1023 | } |
| 1024 | |
| 1025 | // Make javac rule depend on the kotlinc rule |
Colin Cross | 49da275 | 2018-06-05 17:22:57 -0700 | [diff] [blame] | 1026 | flags.classpath = append(flags.classpath, deps.kotlinStdlib...) |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 1027 | flags.classpath = append(flags.classpath, kotlinJar) |
Przemyslaw Szczepaniak | 66c0c40 | 2018-03-08 13:21:55 +0000 | [diff] [blame] | 1028 | |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 1029 | // Jar kotlin classes into the final jar after javac |
| 1030 | jars = append(jars, kotlinJar) |
Przemyslaw Szczepaniak | 66c0c40 | 2018-03-08 13:21:55 +0000 | [diff] [blame] | 1031 | |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1032 | if Bool(j.properties.Renamed_kotlin_stdlib) { |
| 1033 | // Remove any kotlin-reflect related files |
| 1034 | // TODO(pszczepaniak): Support kotlin-reflect |
Colin Cross | 4c03f68 | 2018-07-15 08:16:31 -0700 | [diff] [blame^] | 1035 | stripFiles = append(stripFiles, |
| 1036 | "**/*.kotlin_module", |
| 1037 | "**/*.kotlin_builtin") |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1038 | } else { |
| 1039 | // Only add kotlin-stdlib if not using (on-device) renamed stdlib |
| 1040 | // (it's expected to be on device bootclasspath) |
Przemyslaw Szczepaniak | 66c0c40 | 2018-03-08 13:21:55 +0000 | [diff] [blame] | 1041 | jars = append(jars, deps.kotlinStdlib...) |
| 1042 | } |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 1045 | // Store the list of .java files that was passed to javac |
| 1046 | j.compiledJavaSrcs = uniqueSrcFiles |
| 1047 | j.compiledSrcJars = srcJars |
| 1048 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1049 | enable_sharding := false |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 1050 | if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") { |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1051 | if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 { |
| 1052 | enable_sharding = true |
| 1053 | if len(j.properties.Annotation_processors) != 0 || |
| 1054 | len(j.properties.Annotation_processor_classes) != 0 { |
| 1055 | ctx.PropertyErrorf("javac_shard_size", |
| 1056 | "%q cannot be set when annotation processors are enabled.", |
| 1057 | j.properties.Javac_shard_size) |
| 1058 | } |
| 1059 | } |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 1060 | j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName) |
| 1061 | if ctx.Failed() { |
| 1062 | return |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1063 | } |
| 1064 | } |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 1065 | if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 { |
Colin Cross | d689143 | 2017-09-27 17:39:56 -0700 | [diff] [blame] | 1066 | var extraJarDeps android.Paths |
Colin Cross | 6654810 | 2018-06-19 22:47:35 -0700 | [diff] [blame] | 1067 | if ctx.Config().RunErrorProne() { |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 1068 | // If error-prone is enabled, add an additional rule to compile the java files into |
| 1069 | // 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] | 1070 | // a rebuild when error-prone is turned off). |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 1071 | // TODO(ccross): Once we always compile with javac9 we may be able to conditionally |
| 1072 | // enable error-prone without affecting the output class files. |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 1073 | errorprone := android.PathForModuleOut(ctx, "errorprone", jarName) |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1074 | RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags) |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 1075 | extraJarDeps = append(extraJarDeps, errorprone) |
| 1076 | } |
| 1077 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1078 | if enable_sharding { |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1079 | flags.classpath = append(flags.classpath, j.headerJarFile) |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1080 | shardSize := int(*(j.properties.Javac_shard_size)) |
| 1081 | var shardSrcs []android.Paths |
| 1082 | if len(uniqueSrcFiles) > 0 { |
| 1083 | shardSrcs = shardPaths(uniqueSrcFiles, shardSize) |
| 1084 | for idx, shardSrc := range shardSrcs { |
| 1085 | classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx)) |
| 1086 | TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps) |
| 1087 | jars = append(jars, classes) |
| 1088 | } |
| 1089 | } |
| 1090 | if len(srcJars) > 0 { |
| 1091 | classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs))) |
| 1092 | TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps) |
| 1093 | jars = append(jars, classes) |
| 1094 | } |
| 1095 | } else { |
| 1096 | classes := android.PathForModuleOut(ctx, "javac", jarName) |
| 1097 | TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps) |
| 1098 | jars = append(jars, classes) |
| 1099 | } |
Colin Cross | d689143 | 2017-09-27 17:39:56 -0700 | [diff] [blame] | 1100 | if ctx.Failed() { |
| 1101 | return |
| 1102 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 1105 | dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs) |
| 1106 | fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources) |
| 1107 | |
| 1108 | var resArgs []string |
| 1109 | var resDeps android.Paths |
| 1110 | |
| 1111 | resArgs = append(resArgs, dirArgs...) |
| 1112 | resDeps = append(resDeps, dirDeps...) |
| 1113 | |
| 1114 | resArgs = append(resArgs, fileArgs...) |
| 1115 | resDeps = append(resDeps, fileDeps...) |
| 1116 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1117 | if Bool(j.properties.Include_srcs) { |
Colin Cross | 2372923 | 2017-10-03 13:14:07 -0700 | [diff] [blame] | 1118 | srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs) |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 1119 | resArgs = append(resArgs, srcArgs...) |
| 1120 | resDeps = append(resDeps, srcDeps...) |
| 1121 | } |
Colin Cross | 40a3671 | 2017-09-27 17:41:35 -0700 | [diff] [blame] | 1122 | |
| 1123 | if len(resArgs) > 0 { |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 1124 | resourceJar := android.PathForModuleOut(ctx, "res", jarName) |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1125 | TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps) |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 1126 | if ctx.Failed() { |
| 1127 | return |
| 1128 | } |
Colin Cross | 2097830 | 2015-04-10 17:05:07 -0700 | [diff] [blame] | 1129 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1130 | jars = append(jars, resourceJar) |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 1133 | // 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] | 1134 | jars = append(jars, deps.staticJars...) |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 1135 | jars = append(jars, deps.staticJarResources...) |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1136 | |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 1137 | var manifest android.OptionalPath |
| 1138 | if j.properties.Manifest != nil { |
| 1139 | manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest")) |
| 1140 | } |
Colin Cross | 635acc9 | 2017-09-12 22:50:46 -0700 | [diff] [blame] | 1141 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1142 | // Combine the classes built from sources, any manifests, and any static libraries into |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1143 | // classes.jar. If there is only one input jar this step will be skipped. |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1144 | var outputFile android.Path |
| 1145 | |
| 1146 | if len(jars) == 1 && !manifest.Valid() { |
| 1147 | // Optimization: skip the combine step if there is nothing to do |
Colin Cross | 7b60cdd | 2017-12-21 13:52:58 -0800 | [diff] [blame] | 1148 | // TODO(ccross): this leaves any module-info.class files, but those should only come from |
| 1149 | // prebuilt dependencies until we support modules in the platform build, so there shouldn't be |
| 1150 | // any if len(jars) == 1. |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1151 | outputFile = jars[0] |
| 1152 | } else { |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 1153 | combinedJar := android.PathForModuleOut(ctx, "combined", jarName) |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1154 | TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest, |
| 1155 | false, stripFiles, nil) |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1156 | outputFile = combinedJar |
| 1157 | } |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1158 | |
Przemyslaw Szczepaniak | 66c0c40 | 2018-03-08 13:21:55 +0000 | [diff] [blame] | 1159 | // Use renamed kotlin standard library? |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1160 | if srcFiles.HasExt(".kt") && Bool(j.properties.Renamed_kotlin_stdlib) { |
Przemyslaw Szczepaniak | 66c0c40 | 2018-03-08 13:21:55 +0000 | [diff] [blame] | 1161 | jarjarFile := android.PathForModuleOut(ctx, "kotlin-renamed", jarName) |
| 1162 | TransformJarJar(ctx, jarjarFile, outputFile, |
| 1163 | android.PathForSource(ctx, "external/kotlinc/jarjar-rules.txt")) |
| 1164 | outputFile = jarjarFile |
| 1165 | if ctx.Failed() { |
| 1166 | return |
| 1167 | } |
| 1168 | } |
| 1169 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1170 | if j.properties.Jarjar_rules != nil { |
| 1171 | jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules) |
Colin Cross | 8649b26 | 2017-09-27 18:03:17 -0700 | [diff] [blame] | 1172 | // Transform classes.jar into classes-jarjar.jar |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 1173 | jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName) |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1174 | TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules) |
| 1175 | outputFile = jarjarFile |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1176 | if ctx.Failed() { |
| 1177 | return |
| 1178 | } |
| 1179 | } |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1180 | j.implementationJarFile = outputFile |
| 1181 | if j.headerJarFile == nil { |
| 1182 | j.headerJarFile = j.implementationJarFile |
| 1183 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1184 | |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 1185 | if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") { |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 1186 | if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) { |
| 1187 | j.properties.Instrument = true |
| 1188 | } |
| 1189 | } |
| 1190 | |
Colin Cross | 3144dfc | 2018-01-03 15:06:47 -0800 | [diff] [blame] | 1191 | if j.shouldInstrument(ctx) { |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 1192 | outputFile = j.instrument(ctx, flags, outputFile, jarName) |
| 1193 | } |
| 1194 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1195 | if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) { |
David Brazdil | 17ef563 | 2018-06-27 10:27:45 +0100 | [diff] [blame] | 1196 | var dexOutputFile android.Path |
| 1197 | dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1198 | if ctx.Failed() { |
| 1199 | return |
| 1200 | } |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1201 | if Bool(j.properties.Installable) { |
David Brazdil | 17ef563 | 2018-06-27 10:27:45 +0100 | [diff] [blame] | 1202 | outputFile = dexOutputFile |
| 1203 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1204 | } |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 1205 | ctx.CheckbuildFile(outputFile) |
| 1206 | j.outputFile = outputFile |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1207 | } |
| 1208 | |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 1209 | func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths, |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1210 | deps deps, flags javaBuilderFlags, jarName string) android.Path { |
| 1211 | |
| 1212 | var jars android.Paths |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 1213 | if len(srcFiles) > 0 || len(srcJars) > 0 { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1214 | // Compile java sources into turbine.jar. |
| 1215 | turbineJar := android.PathForModuleOut(ctx, "turbine", jarName) |
| 1216 | TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags) |
| 1217 | if ctx.Failed() { |
| 1218 | return nil |
| 1219 | } |
| 1220 | jars = append(jars, turbineJar) |
| 1221 | } |
| 1222 | |
| 1223 | // Combine any static header libraries into classes-header.jar. If there is only |
| 1224 | // one input jar this step will be skipped. |
| 1225 | var headerJar android.Path |
| 1226 | jars = append(jars, deps.staticHeaderJars...) |
| 1227 | |
Colin Cross | 5c6ecc1 | 2017-10-23 18:12:27 -0700 | [diff] [blame] | 1228 | // we cannot skip the combine step for now if there is only one jar |
| 1229 | // since we have to strip META-INF/TRANSITIVE dir from turbine.jar |
| 1230 | combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName) |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1231 | TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, |
| 1232 | false, nil, []string{"META-INF"}) |
Colin Cross | 5c6ecc1 | 2017-10-23 18:12:27 -0700 | [diff] [blame] | 1233 | headerJar = combinedJar |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1234 | |
| 1235 | if j.properties.Jarjar_rules != nil { |
| 1236 | jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules) |
| 1237 | // Transform classes.jar into classes-jarjar.jar |
| 1238 | jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName) |
| 1239 | TransformJarJar(ctx, jarjarFile, headerJar, jarjar_rules) |
| 1240 | headerJar = jarjarFile |
| 1241 | if ctx.Failed() { |
| 1242 | return nil |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | return headerJar |
| 1247 | } |
| 1248 | |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 1249 | func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags, |
| 1250 | classesJar android.Path, jarName string) android.Path { |
| 1251 | |
Colin Cross | 7a3139e | 2017-12-19 13:57:50 -0800 | [diff] [blame] | 1252 | specs := j.jacocoModuleToZipCommand(ctx) |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 1253 | |
Colin Cross | 84c3882 | 2018-01-03 15:59:46 -0800 | [diff] [blame] | 1254 | jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName) |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 1255 | instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName) |
| 1256 | |
| 1257 | jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs) |
| 1258 | |
| 1259 | j.jacocoReportClassesFile = jacocoReportClassesFile |
| 1260 | |
| 1261 | return instrumentedJar |
| 1262 | } |
| 1263 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1264 | var _ Dependency = (*Library)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1265 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1266 | func (j *Module) HeaderJars() android.Paths { |
| 1267 | return android.Paths{j.headerJarFile} |
| 1268 | } |
| 1269 | |
| 1270 | func (j *Module) ImplementationJars() android.Paths { |
| 1271 | return android.Paths{j.implementationJarFile} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1274 | func (j *Module) AidlIncludeDirs() android.Paths { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 1275 | return j.exportAidlIncludeDirs |
| 1276 | } |
| 1277 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1278 | func (j *Module) ExportedSdkLibs() []string { |
| 1279 | return j.exportedSdkLibs |
| 1280 | } |
| 1281 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1282 | var _ logtagsProducer = (*Module)(nil) |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 1283 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1284 | func (j *Module) logtags() android.Paths { |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 1285 | return j.logtagsSrcs |
| 1286 | } |
| 1287 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1288 | // |
| 1289 | // Java libraries (.jar file) |
| 1290 | // |
| 1291 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1292 | type Library struct { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1293 | Module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1294 | } |
| 1295 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1296 | func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1297 | j.compile(ctx) |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 1298 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1299 | if Bool(j.properties.Installable) || ctx.Host() { |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 1300 | j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), |
| 1301 | ctx.ModuleName()+".jar", j.outputFile) |
| 1302 | } |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 1303 | } |
| 1304 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1305 | func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1306 | j.deps(ctx) |
| 1307 | } |
| 1308 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1309 | func LibraryFactory() android.Module { |
| 1310 | module := &Library{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1311 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1312 | module.AddProperties( |
| 1313 | &module.Module.properties, |
| 1314 | &module.Module.deviceProperties, |
| 1315 | &module.Module.protoProperties) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1316 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1317 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 1318 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1319 | } |
| 1320 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1321 | func LibraryHostFactory() android.Module { |
| 1322 | module := &Library{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1323 | |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 1324 | module.AddProperties( |
| 1325 | &module.Module.properties, |
| 1326 | &module.Module.protoProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1327 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1328 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 1329 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 1330 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1331 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | // |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1335 | // Java Junit Tests |
| 1336 | // |
| 1337 | |
| 1338 | type testProperties struct { |
| 1339 | // If true, add a static dependency on the platform junit library. Defaults to true. |
| 1340 | Junit *bool |
| 1341 | |
| 1342 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 1343 | // installed into. |
| 1344 | Test_suites []string `android:"arch_variant"` |
| 1345 | } |
| 1346 | |
| 1347 | type Test struct { |
| 1348 | Library |
| 1349 | |
| 1350 | testProperties testProperties |
| 1351 | } |
| 1352 | |
| 1353 | func (j *Test) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1354 | j.deps(ctx) |
Colin Cross | 38b40df | 2018-04-10 16:14:46 -0700 | [diff] [blame] | 1355 | if BoolDefault(j.testProperties.Junit, true) { |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1356 | ctx.AddDependency(ctx.Module(), staticLibTag, "junit") |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | func TestFactory() android.Module { |
| 1361 | module := &Test{} |
| 1362 | |
| 1363 | module.AddProperties( |
| 1364 | &module.Module.properties, |
| 1365 | &module.Module.deviceProperties, |
| 1366 | &module.Module.protoProperties, |
| 1367 | &module.testProperties) |
| 1368 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1369 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 1370 | |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1371 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 1372 | android.InitDefaultableModule(module) |
| 1373 | return module |
| 1374 | } |
| 1375 | |
| 1376 | func TestHostFactory() android.Module { |
| 1377 | module := &Test{} |
| 1378 | |
| 1379 | module.AddProperties( |
| 1380 | &module.Module.properties, |
| 1381 | &module.Module.protoProperties, |
| 1382 | &module.testProperties) |
| 1383 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1384 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 1385 | |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1386 | InitJavaModule(module, android.HostSupported) |
| 1387 | android.InitDefaultableModule(module) |
| 1388 | return module |
| 1389 | } |
| 1390 | |
| 1391 | // |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1392 | // Java Binaries (.jar file plus wrapper script) |
| 1393 | // |
| 1394 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1395 | type binaryProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1396 | // installable script to execute the resulting jar |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 1397 | Wrapper *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1400 | type Binary struct { |
| 1401 | Library |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1402 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1403 | binaryProperties binaryProperties |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 1404 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1405 | isWrapperVariant bool |
| 1406 | |
Colin Cross | c331599 | 2017-12-08 19:12:36 -0800 | [diff] [blame] | 1407 | wrapperFile android.Path |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 1408 | binaryFile android.OutputPath |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1409 | } |
| 1410 | |
Alex Light | 2423717 | 2017-10-26 09:46:21 -0700 | [diff] [blame] | 1411 | func (j *Binary) HostToolPath() android.OptionalPath { |
| 1412 | return android.OptionalPathForPath(j.binaryFile) |
| 1413 | } |
| 1414 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1415 | func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1416 | if ctx.Arch().ArchType == android.Common { |
| 1417 | // Compile the jar |
| 1418 | j.Library.GenerateAndroidBuildActions(ctx) |
Nan Zhang | 3c807db | 2017-11-03 14:53:31 -0700 | [diff] [blame] | 1419 | } else { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1420 | // Handle the binary wrapper |
| 1421 | j.isWrapperVariant = true |
| 1422 | |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 1423 | if j.binaryProperties.Wrapper != nil { |
| 1424 | j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1425 | } else { |
| 1426 | j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh") |
| 1427 | } |
| 1428 | |
| 1429 | // Depend on the installed jar so that the wrapper doesn't get executed by |
| 1430 | // another build rule before the jar has been installed. |
| 1431 | jarFile := ctx.PrimaryModule().(*Binary).installFile |
| 1432 | |
| 1433 | j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"), |
| 1434 | ctx.ModuleName(), j.wrapperFile, jarFile) |
Nan Zhang | 3c807db | 2017-11-03 14:53:31 -0700 | [diff] [blame] | 1435 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1438 | func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1439 | if ctx.Arch().ArchType == android.Common { |
| 1440 | j.deps(ctx) |
Colin Cross | c331599 | 2017-12-08 19:12:36 -0800 | [diff] [blame] | 1441 | } else { |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 1442 | android.ExtractSourceDeps(ctx, j.binaryProperties.Wrapper) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1443 | } |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1446 | func BinaryFactory() android.Module { |
| 1447 | module := &Binary{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1448 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1449 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 1450 | &module.Module.properties, |
| 1451 | &module.Module.deviceProperties, |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 1452 | &module.Module.protoProperties, |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 1453 | &module.binaryProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1454 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1455 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 1456 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1457 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst) |
| 1458 | android.InitDefaultableModule(module) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1459 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1462 | func BinaryHostFactory() android.Module { |
| 1463 | module := &Binary{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1464 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1465 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 1466 | &module.Module.properties, |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 1467 | &module.Module.protoProperties, |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 1468 | &module.binaryProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1469 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1470 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 1471 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1472 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst) |
| 1473 | android.InitDefaultableModule(module) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1474 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | // |
| 1478 | // Java prebuilts |
| 1479 | // |
| 1480 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1481 | type ImportProperties struct { |
| 1482 | Jars []string |
Colin Cross | 461bd1a | 2017-10-20 13:59:18 -0700 | [diff] [blame] | 1483 | |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 1484 | Sdk_version *string |
Colin Cross | 535e2cf | 2017-10-20 17:57:49 -0700 | [diff] [blame] | 1485 | |
| 1486 | Installable *bool |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1487 | |
| 1488 | // List of shared java libs that this module has dependencies to |
| 1489 | Libs []string |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1490 | |
| 1491 | // List of files to remove from the jar file(s) |
| 1492 | Exclude_files []string |
| 1493 | |
| 1494 | // List of directories to remove from the jar file(s) |
| 1495 | Exclude_dirs []string |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | type Import struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1499 | android.ModuleBase |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 1500 | prebuilt android.Prebuilt |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1501 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1502 | properties ImportProperties |
| 1503 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1504 | combinedClasspathFile android.Path |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1505 | exportedSdkLibs []string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 1508 | func (j *Import) sdkVersion() string { |
| 1509 | return String(j.properties.Sdk_version) |
| 1510 | } |
| 1511 | |
| 1512 | func (j *Import) minSdkVersion() string { |
| 1513 | return j.sdkVersion() |
| 1514 | } |
| 1515 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1516 | func (j *Import) Prebuilt() *android.Prebuilt { |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 1517 | return &j.prebuilt |
| 1518 | } |
| 1519 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1520 | func (j *Import) PrebuiltSrcs() []string { |
| 1521 | return j.properties.Jars |
| 1522 | } |
| 1523 | |
| 1524 | func (j *Import) Name() string { |
Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 1525 | return j.prebuilt.Name(j.ModuleBase.Name()) |
| 1526 | } |
| 1527 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1528 | func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1529 | android.ExtractSourcesDeps(ctx, j.properties.Jars) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1530 | ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...) |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 1531 | } |
| 1532 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1533 | func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1534 | jars := ctx.ExpandSources(j.properties.Jars, nil) |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 1535 | |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1536 | outputFile := android.PathForModuleOut(ctx, "classes.jar") |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1537 | TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{}, |
| 1538 | false, j.properties.Exclude_files, j.properties.Exclude_dirs) |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1539 | j.combinedClasspathFile = outputFile |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1540 | |
| 1541 | ctx.VisitDirectDeps(func(module android.Module) { |
| 1542 | otherName := ctx.OtherModuleName(module) |
| 1543 | tag := ctx.OtherModuleDependencyTag(module) |
| 1544 | |
| 1545 | switch dep := module.(type) { |
| 1546 | case Dependency: |
| 1547 | switch tag { |
| 1548 | case libTag, staticLibTag: |
| 1549 | // sdk lib names from dependencies are re-exported |
| 1550 | j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...) |
| 1551 | } |
| 1552 | case SdkLibraryDependency: |
| 1553 | switch tag { |
| 1554 | case libTag: |
| 1555 | // names of sdk libs that are directly depended are exported |
| 1556 | j.exportedSdkLibs = append(j.exportedSdkLibs, otherName) |
| 1557 | } |
| 1558 | } |
| 1559 | }) |
| 1560 | |
| 1561 | j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1562 | } |
| 1563 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1564 | var _ Dependency = (*Import)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1565 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1566 | func (j *Import) HeaderJars() android.Paths { |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1567 | return android.Paths{j.combinedClasspathFile} |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | func (j *Import) ImplementationJars() android.Paths { |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1571 | return android.Paths{j.combinedClasspathFile} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1572 | } |
| 1573 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1574 | func (j *Import) AidlIncludeDirs() android.Paths { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 1575 | return nil |
| 1576 | } |
| 1577 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1578 | func (j *Import) ExportedSdkLibs() []string { |
| 1579 | return j.exportedSdkLibs |
| 1580 | } |
| 1581 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1582 | var _ android.PrebuiltInterface = (*Import)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1583 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1584 | func ImportFactory() android.Module { |
| 1585 | module := &Import{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1586 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1587 | module.AddProperties(&module.properties) |
| 1588 | |
| 1589 | android.InitPrebuiltModule(module, &module.properties.Jars) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1590 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) |
| 1591 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1594 | func ImportFactoryHost() android.Module { |
| 1595 | module := &Import{} |
| 1596 | |
| 1597 | module.AddProperties(&module.properties) |
| 1598 | |
| 1599 | android.InitPrebuiltModule(module, &module.properties.Jars) |
| 1600 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon) |
| 1601 | return module |
| 1602 | } |
| 1603 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 1604 | // |
| 1605 | // Defaults |
| 1606 | // |
| 1607 | type Defaults struct { |
| 1608 | android.ModuleBase |
| 1609 | android.DefaultsModuleBase |
| 1610 | } |
| 1611 | |
| 1612 | func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1613 | } |
| 1614 | |
| 1615 | func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1616 | } |
| 1617 | |
| 1618 | func defaultsFactory() android.Module { |
| 1619 | return DefaultsFactory() |
| 1620 | } |
| 1621 | |
| 1622 | func DefaultsFactory(props ...interface{}) android.Module { |
| 1623 | module := &Defaults{} |
| 1624 | |
| 1625 | module.AddProperties(props...) |
| 1626 | module.AddProperties( |
| 1627 | &CompilerProperties{}, |
| 1628 | &CompilerDeviceProperties{}, |
Dan Willemsen | 6424d17 | 2018-03-08 13:27:59 -0800 | [diff] [blame] | 1629 | &android.ProtoProperties{}, |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 1630 | ) |
| 1631 | |
| 1632 | android.InitDefaultsModule(module) |
| 1633 | |
| 1634 | return module |
| 1635 | } |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 1636 | |
| 1637 | var Bool = proptools.Bool |
Colin Cross | 38b40df | 2018-04-10 16:14:46 -0700 | [diff] [blame] | 1638 | var BoolDefault = proptools.BoolDefault |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 1639 | var String = proptools.String |
Colin Cross | 0d0ba59 | 2018-02-20 13:33:42 -0800 | [diff] [blame] | 1640 | var inList = android.InList |