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