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