| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1 | // Copyright 2021 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 | import ( | 
|  | 18 | "fmt" | 
|  | 19 | "path/filepath" | 
|  | 20 | "strconv" | 
|  | 21 | "strings" | 
|  | 22 |  | 
| Chris Parsons | 39a1697 | 2023-06-08 14:28:51 +0000 | [diff] [blame] | 23 | "android/soong/ui/metrics/bp2build_metrics_proto" | 
| Jihoon Kang | 1bfb6f2 | 2023-07-01 00:13:47 +0000 | [diff] [blame] | 24 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 25 | "github.com/google/blueprint/pathtools" | 
|  | 26 | "github.com/google/blueprint/proptools" | 
|  | 27 |  | 
|  | 28 | "android/soong/android" | 
|  | 29 | "android/soong/dexpreopt" | 
|  | 30 | "android/soong/java/config" | 
|  | 31 | ) | 
|  | 32 |  | 
|  | 33 | // This file contains the definition and the implementation of the base module that most | 
|  | 34 | // source-based Java module structs embed. | 
|  | 35 |  | 
|  | 36 | // TODO: | 
|  | 37 | // Autogenerated files: | 
|  | 38 | //  Renderscript | 
|  | 39 | // Post-jar passes: | 
|  | 40 | //  Proguard | 
|  | 41 | // Rmtypedefs | 
|  | 42 | // DroidDoc | 
|  | 43 | // Findbugs | 
|  | 44 |  | 
|  | 45 | // Properties that are common to most Java modules, i.e. whether it's a host or device module. | 
|  | 46 | type CommonProperties struct { | 
|  | 47 | // list of source files used to compile the Java module.  May be .java, .kt, .logtags, .proto, | 
|  | 48 | // or .aidl files. | 
|  | 49 | Srcs []string `android:"path,arch_variant"` | 
|  | 50 |  | 
|  | 51 | // list Kotlin of source files containing Kotlin code that should be treated as common code in | 
|  | 52 | // a codebase that supports Kotlin multiplatform.  See | 
|  | 53 | // https://kotlinlang.org/docs/reference/multiplatform.html.  May be only be .kt files. | 
|  | 54 | Common_srcs []string `android:"path,arch_variant"` | 
|  | 55 |  | 
|  | 56 | // list of source files that should not be used to build the Java module. | 
|  | 57 | // This is most useful in the arch/multilib variants to remove non-common files | 
|  | 58 | Exclude_srcs []string `android:"path,arch_variant"` | 
|  | 59 |  | 
|  | 60 | // list of directories containing Java resources | 
|  | 61 | Java_resource_dirs []string `android:"arch_variant"` | 
|  | 62 |  | 
|  | 63 | // list of directories that should be excluded from java_resource_dirs | 
|  | 64 | Exclude_java_resource_dirs []string `android:"arch_variant"` | 
|  | 65 |  | 
|  | 66 | // list of files to use as Java resources | 
|  | 67 | Java_resources []string `android:"path,arch_variant"` | 
|  | 68 |  | 
|  | 69 | // list of files that should be excluded from java_resources and java_resource_dirs | 
|  | 70 | Exclude_java_resources []string `android:"path,arch_variant"` | 
|  | 71 |  | 
|  | 72 | // list of module-specific flags that will be used for javac compiles | 
|  | 73 | Javacflags []string `android:"arch_variant"` | 
|  | 74 |  | 
|  | 75 | // list of module-specific flags that will be used for kotlinc compiles | 
|  | 76 | Kotlincflags []string `android:"arch_variant"` | 
|  | 77 |  | 
|  | 78 | // list of java libraries that will be in the classpath | 
|  | 79 | Libs []string `android:"arch_variant"` | 
|  | 80 |  | 
|  | 81 | // list of java libraries that will be compiled into the resulting jar | 
|  | 82 | Static_libs []string `android:"arch_variant"` | 
|  | 83 |  | 
| Jihoon Kang | 381c2fa | 2023-06-01 22:17:32 +0000 | [diff] [blame] | 84 | // list of java libraries that should not be used to build this module | 
|  | 85 | Exclude_static_libs []string `android:"arch_variant"` | 
|  | 86 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 87 | // manifest file to be included in resulting jar | 
|  | 88 | Manifest *string `android:"path"` | 
|  | 89 |  | 
|  | 90 | // if not blank, run jarjar using the specified rules file | 
|  | 91 | Jarjar_rules *string `android:"path,arch_variant"` | 
|  | 92 |  | 
|  | 93 | // If not blank, set the java version passed to javac as -source and -target | 
|  | 94 | Java_version *string | 
|  | 95 |  | 
|  | 96 | // If set to true, allow this module to be dexed and installed on devices.  Has no | 
|  | 97 | // effect on host modules, which are always considered installable. | 
|  | 98 | Installable *bool | 
|  | 99 |  | 
|  | 100 | // If set to true, include sources used to compile the module in to the final jar | 
|  | 101 | Include_srcs *bool | 
|  | 102 |  | 
|  | 103 | // If not empty, classes are restricted to the specified packages and their sub-packages. | 
|  | 104 | // This restriction is checked after applying jarjar rules and including static libs. | 
|  | 105 | Permitted_packages []string | 
|  | 106 |  | 
|  | 107 | // List of modules to use as annotation processors | 
|  | 108 | Plugins []string | 
|  | 109 |  | 
|  | 110 | // List of modules to export to libraries that directly depend on this library as annotation | 
|  | 111 | // processors.  Note that if the plugins set generates_api: true this will disable the turbine | 
|  | 112 | // optimization on modules that depend on this module, which will reduce parallelism and cause | 
|  | 113 | // more recompilation. | 
|  | 114 | Exported_plugins []string | 
|  | 115 |  | 
|  | 116 | // The number of Java source entries each Javac instance can process | 
|  | 117 | Javac_shard_size *int64 | 
|  | 118 |  | 
|  | 119 | // Add host jdk tools.jar to bootclasspath | 
|  | 120 | Use_tools_jar *bool | 
|  | 121 |  | 
|  | 122 | Openjdk9 struct { | 
|  | 123 | // List of source files that should only be used when passing -source 1.9 or higher | 
|  | 124 | Srcs []string `android:"path"` | 
|  | 125 |  | 
|  | 126 | // List of javac flags that should only be used when passing -source 1.9 or higher | 
|  | 127 | Javacflags []string | 
|  | 128 | } | 
|  | 129 |  | 
|  | 130 | // When compiling language level 9+ .java code in packages that are part of | 
|  | 131 | // a system module, patch_module names the module that your sources and | 
|  | 132 | // dependencies should be patched into. The Android runtime currently | 
|  | 133 | // doesn't implement the JEP 261 module system so this option is only | 
|  | 134 | // supported at compile time. It should only be needed to compile tests in | 
|  | 135 | // packages that exist in libcore and which are inconvenient to move | 
|  | 136 | // elsewhere. | 
| Liz Kammer | 0a470a3 | 2023-10-05 17:02:00 -0400 | [diff] [blame] | 137 | Patch_module *string | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 138 |  | 
|  | 139 | Jacoco struct { | 
|  | 140 | // List of classes to include for instrumentation with jacoco to collect coverage | 
|  | 141 | // information at runtime when building with coverage enabled.  If unset defaults to all | 
|  | 142 | // classes. | 
|  | 143 | // Supports '*' as the last character of an entry in the list as a wildcard match. | 
|  | 144 | // If preceded by '.' it matches all classes in the package and subpackages, otherwise | 
|  | 145 | // it matches classes in the package that have the class name as a prefix. | 
|  | 146 | Include_filter []string | 
|  | 147 |  | 
|  | 148 | // List of classes to exclude from instrumentation with jacoco to collect coverage | 
|  | 149 | // information at runtime when building with coverage enabled.  Overrides classes selected | 
|  | 150 | // by the include_filter property. | 
|  | 151 | // Supports '*' as the last character of an entry in the list as a wildcard match. | 
|  | 152 | // If preceded by '.' it matches all classes in the package and subpackages, otherwise | 
|  | 153 | // it matches classes in the package that have the class name as a prefix. | 
|  | 154 | Exclude_filter []string | 
|  | 155 | } | 
|  | 156 |  | 
|  | 157 | Errorprone struct { | 
|  | 158 | // List of javac flags that should only be used when running errorprone. | 
|  | 159 | Javacflags []string | 
|  | 160 |  | 
|  | 161 | // List of java_plugin modules that provide extra errorprone checks. | 
|  | 162 | Extra_check_modules []string | 
| Cole Faust | 75fffb1 | 2021-06-13 15:23:16 -0700 | [diff] [blame] | 163 |  | 
| Cole Faust | 2b1536e | 2021-06-18 12:25:54 -0700 | [diff] [blame] | 164 | // This property can be in 3 states. When set to true, errorprone will | 
|  | 165 | // be run during the regular build. When set to false, errorprone will | 
|  | 166 | // never be run. When unset, errorprone will be run when the RUN_ERROR_PRONE | 
|  | 167 | // environment variable is true. Setting this to false will improve build | 
|  | 168 | // performance more than adding -XepDisableAllChecks in javacflags. | 
| Cole Faust | 75fffb1 | 2021-06-13 15:23:16 -0700 | [diff] [blame] | 169 | Enabled *bool | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 170 | } | 
|  | 171 |  | 
|  | 172 | Proto struct { | 
|  | 173 | // List of extra options that will be passed to the proto generator. | 
|  | 174 | Output_params []string | 
|  | 175 | } | 
|  | 176 |  | 
| Sam Delmerico | c759372 | 2022-08-31 15:57:52 -0400 | [diff] [blame] | 177 | // If true, then jacocoagent is automatically added as a libs dependency so that | 
|  | 178 | // r8 will not strip instrumentation classes out of dexed libraries. | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 179 | Instrument bool `blueprint:"mutated"` | 
| Paul Duffin | 0038a8d | 2022-05-03 00:28:40 +0000 | [diff] [blame] | 180 | // If true, then the module supports statically including the jacocoagent | 
|  | 181 | // into the library. | 
|  | 182 | Supports_static_instrumentation bool `blueprint:"mutated"` | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 183 |  | 
|  | 184 | // List of files to include in the META-INF/services folder of the resulting jar. | 
|  | 185 | Services []string `android:"path,arch_variant"` | 
|  | 186 |  | 
|  | 187 | // If true, package the kotlin stdlib into the jar.  Defaults to true. | 
|  | 188 | Static_kotlin_stdlib *bool `android:"arch_variant"` | 
|  | 189 |  | 
|  | 190 | // A list of java_library instances that provide additional hiddenapi annotations for the library. | 
|  | 191 | Hiddenapi_additional_annotations []string | 
| Joe Onorato | 175073c | 2023-06-01 14:42:59 -0700 | [diff] [blame] | 192 |  | 
|  | 193 | // Additional srcJars tacked in by GeneratedJavaLibraryModule | 
|  | 194 | Generated_srcjars []android.Path `android:"mutated"` | 
| Mark White | a15790a | 2023-08-22 21:28:11 +0000 | [diff] [blame] | 195 |  | 
|  | 196 | // If true, then only the headers are built and not the implementation jar. | 
| Liz Kammer | 6077263 | 2023-10-05 17:18:44 -0400 | [diff] [blame] | 197 | Headers_only *bool | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 198 | } | 
|  | 199 |  | 
|  | 200 | // Properties that are specific to device modules. Host module factories should not add these when | 
|  | 201 | // constructing a new module. | 
|  | 202 | type DeviceProperties struct { | 
| Trevor Radcliffe | 347e5e4 | 2021-11-05 19:30:24 +0000 | [diff] [blame] | 203 | // If not blank, set to the version of the sdk to compile against. | 
| Spandan Das | 1ccf574 | 2022-10-14 16:51:23 +0000 | [diff] [blame] | 204 | // Defaults to an empty string, which compiles the module against the private platform APIs. | 
| Trevor Radcliffe | 347e5e4 | 2021-11-05 19:30:24 +0000 | [diff] [blame] | 205 | // Values are of one of the following forms: | 
| Vinh Tran | a9c8f7d | 2022-04-14 20:18:47 +0000 | [diff] [blame] | 206 | // 1) numerical API level, "current", "none", or "core_platform" | 
|  | 207 | // 2) An SDK kind with an API level: "<sdk kind>_<API level>" | 
|  | 208 | // See build/soong/android/sdk_version.go for the complete and up to date list of SDK kinds. | 
|  | 209 | // If the SDK kind is empty, it will be set to public. | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 210 | Sdk_version *string | 
|  | 211 |  | 
|  | 212 | // if not blank, set the minimum version of the sdk that the compiled artifacts will run against. | 
| Trevor Radcliffe | 347e5e4 | 2021-11-05 19:30:24 +0000 | [diff] [blame] | 213 | // Defaults to sdk_version if not set. See sdk_version for possible values. | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 214 | Min_sdk_version *string | 
|  | 215 |  | 
| satayev | 0a420e7 | 2021-11-29 17:25:52 +0000 | [diff] [blame] | 216 | // if not blank, set the maximum version of the sdk that the compiled artifacts will run against. | 
|  | 217 | // Defaults to empty string "". See sdk_version for possible values. | 
|  | 218 | Max_sdk_version *string | 
|  | 219 |  | 
| William Loh | 5a082f9 | 2022-05-17 20:21:50 +0000 | [diff] [blame] | 220 | // if not blank, set the maxSdkVersion properties of permission and uses-permission tags. | 
|  | 221 | // Defaults to empty string "". See sdk_version for possible values. | 
|  | 222 | Replace_max_sdk_version_placeholder *string | 
|  | 223 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 224 | // if not blank, set the targetSdkVersion in the AndroidManifest.xml. | 
| Trevor Radcliffe | 347e5e4 | 2021-11-05 19:30:24 +0000 | [diff] [blame] | 225 | // Defaults to sdk_version if not set. See sdk_version for possible values. | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 226 | Target_sdk_version *string | 
|  | 227 |  | 
|  | 228 | // Whether to compile against the platform APIs instead of an SDK. | 
|  | 229 | // If true, then sdk_version must be empty. The value of this field | 
| Vinh Tran | d91939e | 2022-04-18 19:27:17 +0000 | [diff] [blame] | 230 | // is ignored when module's type isn't android_app, android_test, or android_test_helper_app. | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 231 | Platform_apis *bool | 
|  | 232 |  | 
|  | 233 | Aidl struct { | 
|  | 234 | // Top level directories to pass to aidl tool | 
|  | 235 | Include_dirs []string | 
|  | 236 |  | 
|  | 237 | // Directories rooted at the Android.bp file to pass to aidl tool | 
|  | 238 | Local_include_dirs []string | 
|  | 239 |  | 
|  | 240 | // directories that should be added as include directories for any aidl sources of modules | 
|  | 241 | // that depend on this module, as well as to aidl for this module. | 
|  | 242 | Export_include_dirs []string | 
|  | 243 |  | 
|  | 244 | // whether to generate traces (for systrace) for this interface | 
|  | 245 | Generate_traces *bool | 
|  | 246 |  | 
|  | 247 | // whether to generate Binder#GetTransaction name method. | 
|  | 248 | Generate_get_transaction_name *bool | 
|  | 249 |  | 
| Thiébaud Weksteen | de8417c | 2022-02-10 15:41:46 +1100 | [diff] [blame] | 250 | // whether all interfaces should be annotated with required permissions. | 
|  | 251 | Enforce_permissions *bool | 
|  | 252 |  | 
|  | 253 | // allowlist for interfaces that (temporarily) do not require annotation for permissions. | 
|  | 254 | Enforce_permissions_exceptions []string `android:"path"` | 
|  | 255 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 256 | // list of flags that will be passed to the AIDL compiler | 
|  | 257 | Flags []string | 
|  | 258 | } | 
|  | 259 |  | 
|  | 260 | // If true, export a copy of the module as a -hostdex module for host testing. | 
|  | 261 | Hostdex *bool | 
|  | 262 |  | 
|  | 263 | Target struct { | 
|  | 264 | Hostdex struct { | 
|  | 265 | // Additional required dependencies to add to -hostdex modules. | 
|  | 266 | Required []string | 
|  | 267 | } | 
|  | 268 | } | 
|  | 269 |  | 
|  | 270 | // When targeting 1.9 and above, override the modules to use with --system, | 
|  | 271 | // otherwise provides defaults libraries to add to the bootclasspath. | 
|  | 272 | System_modules *string | 
|  | 273 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 274 | IsSDKLibrary bool `blueprint:"mutated"` | 
|  | 275 |  | 
|  | 276 | // If true, generate the signature file of APK Signing Scheme V4, along side the signed APK file. | 
|  | 277 | // Defaults to false. | 
|  | 278 | V4_signature *bool | 
|  | 279 |  | 
|  | 280 | // Only for libraries created by a sysprop_library module, SyspropPublicStub is the name of the | 
|  | 281 | // public stubs library. | 
|  | 282 | SyspropPublicStub string `blueprint:"mutated"` | 
| Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 283 |  | 
|  | 284 | HiddenAPIPackageProperties | 
|  | 285 | HiddenAPIFlagFileProperties | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 286 | } | 
|  | 287 |  | 
| Jooyung Han | 01d80d8 | 2022-01-08 12:16:32 +0900 | [diff] [blame] | 288 | // Device properties that can be overridden by overriding module (e.g. override_android_app) | 
|  | 289 | type OverridableDeviceProperties struct { | 
|  | 290 | // set the name of the output. If not set, `name` is used. | 
|  | 291 | // To override a module with this property set, overriding module might need to set this as well. | 
|  | 292 | // Otherwise, both the overridden and the overriding modules will have the same output name, which | 
|  | 293 | // can cause the duplicate output error. | 
|  | 294 | Stem *string | 
|  | 295 | } | 
|  | 296 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 297 | // Functionality common to Module and Import | 
|  | 298 | // | 
|  | 299 | // It is embedded in Module so its functionality can be used by methods in Module | 
|  | 300 | // but it is currently only initialized by Import and Library. | 
|  | 301 | type embeddableInModuleAndImport struct { | 
|  | 302 |  | 
|  | 303 | // Functionality related to this being used as a component of a java_sdk_library. | 
|  | 304 | EmbeddableSdkLibraryComponent | 
|  | 305 | } | 
|  | 306 |  | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 307 | func (e *embeddableInModuleAndImport) initModuleAndImport(module android.Module) { | 
|  | 308 | e.initSdkLibraryComponent(module) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 309 | } | 
|  | 310 |  | 
|  | 311 | // Module/Import's DepIsInSameApex(...) delegates to this method. | 
|  | 312 | // | 
|  | 313 | // This cannot implement DepIsInSameApex(...) directly as that leads to ambiguity with | 
|  | 314 | // the one provided by ApexModuleBase. | 
|  | 315 | func (e *embeddableInModuleAndImport) depIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { | 
|  | 316 | // dependencies other than the static linkage are all considered crossing APEX boundary | 
|  | 317 | if staticLibTag == ctx.OtherModuleDependencyTag(dep) { | 
|  | 318 | return true | 
|  | 319 | } | 
|  | 320 | return false | 
|  | 321 | } | 
|  | 322 |  | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 323 | // OptionalDexJarPath can be either unset, hold a valid path to a dex jar file, | 
|  | 324 | // or an invalid path describing the reason it is invalid. | 
|  | 325 | // | 
|  | 326 | // It is unset if a dex jar isn't applicable, i.e. no build rule has been | 
|  | 327 | // requested to create one. | 
|  | 328 | // | 
|  | 329 | // If a dex jar has been requested to be built then it is set, and it may be | 
|  | 330 | // either a valid android.Path, or invalid with a reason message. The latter | 
|  | 331 | // happens if the source that should produce the dex file isn't able to. | 
|  | 332 | // | 
|  | 333 | // E.g. it is invalid with a reason message if there is a prebuilt APEX that | 
|  | 334 | // could produce the dex jar through a deapexer module, but the APEX isn't | 
|  | 335 | // installable so doing so wouldn't be safe. | 
|  | 336 | type OptionalDexJarPath struct { | 
|  | 337 | isSet bool | 
|  | 338 | path  android.OptionalPath | 
|  | 339 | } | 
|  | 340 |  | 
|  | 341 | // IsSet returns true if a path has been set, either invalid or valid. | 
|  | 342 | func (o OptionalDexJarPath) IsSet() bool { | 
|  | 343 | return o.isSet | 
|  | 344 | } | 
|  | 345 |  | 
|  | 346 | // Valid returns true if there is a path that is valid. | 
|  | 347 | func (o OptionalDexJarPath) Valid() bool { | 
|  | 348 | return o.isSet && o.path.Valid() | 
|  | 349 | } | 
|  | 350 |  | 
|  | 351 | // Path returns the valid path, or panics if it's either not set or is invalid. | 
|  | 352 | func (o OptionalDexJarPath) Path() android.Path { | 
|  | 353 | if !o.isSet { | 
|  | 354 | panic("path isn't set") | 
|  | 355 | } | 
|  | 356 | return o.path.Path() | 
|  | 357 | } | 
|  | 358 |  | 
|  | 359 | // PathOrNil returns the path if it's set and valid, or else nil. | 
|  | 360 | func (o OptionalDexJarPath) PathOrNil() android.Path { | 
|  | 361 | if o.Valid() { | 
|  | 362 | return o.Path() | 
|  | 363 | } | 
|  | 364 | return nil | 
|  | 365 | } | 
|  | 366 |  | 
|  | 367 | // InvalidReason returns the reason for an invalid path, which is never "". It | 
|  | 368 | // returns "" for an unset or valid path. | 
|  | 369 | func (o OptionalDexJarPath) InvalidReason() string { | 
|  | 370 | if !o.isSet { | 
|  | 371 | return "" | 
|  | 372 | } | 
|  | 373 | return o.path.InvalidReason() | 
|  | 374 | } | 
|  | 375 |  | 
|  | 376 | func (o OptionalDexJarPath) String() string { | 
|  | 377 | if !o.isSet { | 
|  | 378 | return "<unset>" | 
|  | 379 | } | 
|  | 380 | return o.path.String() | 
|  | 381 | } | 
|  | 382 |  | 
|  | 383 | // makeUnsetDexJarPath returns an unset OptionalDexJarPath. | 
|  | 384 | func makeUnsetDexJarPath() OptionalDexJarPath { | 
|  | 385 | return OptionalDexJarPath{isSet: false} | 
|  | 386 | } | 
|  | 387 |  | 
|  | 388 | // makeDexJarPathFromOptionalPath returns an OptionalDexJarPath that is set with | 
|  | 389 | // the given OptionalPath, which may be valid or invalid. | 
|  | 390 | func makeDexJarPathFromOptionalPath(path android.OptionalPath) OptionalDexJarPath { | 
|  | 391 | return OptionalDexJarPath{isSet: true, path: path} | 
|  | 392 | } | 
|  | 393 |  | 
|  | 394 | // makeDexJarPathFromPath returns an OptionalDexJarPath that is set with the | 
|  | 395 | // valid given path. It returns an unset OptionalDexJarPath if the given path is | 
|  | 396 | // nil. | 
|  | 397 | func makeDexJarPathFromPath(path android.Path) OptionalDexJarPath { | 
|  | 398 | if path == nil { | 
|  | 399 | return makeUnsetDexJarPath() | 
|  | 400 | } | 
|  | 401 | return makeDexJarPathFromOptionalPath(android.OptionalPathForPath(path)) | 
|  | 402 | } | 
|  | 403 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 404 | // Module contains the properties and members used by all java module types | 
|  | 405 | type Module struct { | 
|  | 406 | android.ModuleBase | 
|  | 407 | android.DefaultableModuleBase | 
|  | 408 | android.ApexModuleBase | 
| Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 409 | android.BazelModuleBase | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 410 |  | 
|  | 411 | // Functionality common to Module and Import. | 
|  | 412 | embeddableInModuleAndImport | 
|  | 413 |  | 
|  | 414 | properties       CommonProperties | 
|  | 415 | protoProperties  android.ProtoProperties | 
|  | 416 | deviceProperties DeviceProperties | 
|  | 417 |  | 
| Jooyung Han | 01d80d8 | 2022-01-08 12:16:32 +0900 | [diff] [blame] | 418 | overridableDeviceProperties OverridableDeviceProperties | 
|  | 419 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 420 | // jar file containing header classes including static library dependencies, suitable for | 
|  | 421 | // inserting into the bootclasspath/classpath of another compile | 
|  | 422 | headerJarFile android.Path | 
|  | 423 |  | 
|  | 424 | // jar file containing implementation classes including static library dependencies but no | 
|  | 425 | // resources | 
|  | 426 | implementationJarFile android.Path | 
|  | 427 |  | 
|  | 428 | // jar file containing only resources including from static library dependencies | 
|  | 429 | resourceJar android.Path | 
|  | 430 |  | 
|  | 431 | // args and dependencies to package source files into a srcjar | 
|  | 432 | srcJarArgs []string | 
|  | 433 | srcJarDeps android.Paths | 
|  | 434 |  | 
| Anton Hansson | 0e73f9e | 2023-09-20 13:39:57 +0000 | [diff] [blame] | 435 | // the source files of this module and all its static dependencies | 
|  | 436 | transitiveSrcFiles *android.DepSet[android.Path] | 
|  | 437 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 438 | // jar file containing implementation classes and resources including static library | 
|  | 439 | // dependencies | 
|  | 440 | implementationAndResourcesJar android.Path | 
|  | 441 |  | 
|  | 442 | // output file containing classes.dex and resources | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 443 | dexJarFile OptionalDexJarPath | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 444 |  | 
|  | 445 | // output file containing uninstrumented classes that will be instrumented by jacoco | 
|  | 446 | jacocoReportClassesFile android.Path | 
|  | 447 |  | 
|  | 448 | // output file of the module, which may be a classes jar or a dex jar | 
|  | 449 | outputFile       android.Path | 
|  | 450 | extraOutputFiles android.Paths | 
|  | 451 |  | 
| Thiébaud Weksteen | de8417c | 2022-02-10 15:41:46 +1100 | [diff] [blame] | 452 | exportAidlIncludeDirs     android.Paths | 
|  | 453 | ignoredAidlPermissionList android.Paths | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 454 |  | 
|  | 455 | logtagsSrcs android.Paths | 
|  | 456 |  | 
|  | 457 | // installed file for binary dependency | 
|  | 458 | installFile android.Path | 
|  | 459 |  | 
| Colin Cross | 3108ce1 | 2021-11-10 14:38:50 -0800 | [diff] [blame] | 460 | // installed file for hostdex copy | 
|  | 461 | hostdexInstallFile android.InstallPath | 
|  | 462 |  | 
| Chaohui Wang | dcbe33c | 2022-10-11 11:13:30 +0800 | [diff] [blame] | 463 | // list of unique .java and .kt source files | 
|  | 464 | uniqueSrcFiles android.Paths | 
|  | 465 |  | 
|  | 466 | // list of srcjars that was passed to javac | 
|  | 467 | compiledSrcJars android.Paths | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 468 |  | 
|  | 469 | // manifest file to use instead of properties.Manifest | 
|  | 470 | overrideManifest android.OptionalPath | 
|  | 471 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 472 | // list of plugins that this java module is exporting | 
|  | 473 | exportedPluginJars android.Paths | 
|  | 474 |  | 
|  | 475 | // list of plugins that this java module is exporting | 
|  | 476 | exportedPluginClasses []string | 
|  | 477 |  | 
|  | 478 | // if true, the exported plugins generate API and require disabling turbine. | 
|  | 479 | exportedDisableTurbine bool | 
|  | 480 |  | 
|  | 481 | // list of source files, collected from srcFiles with unique java and all kt files, | 
|  | 482 | // will be used by android.IDEInfo struct | 
|  | 483 | expandIDEInfoCompiledSrcs []string | 
|  | 484 |  | 
|  | 485 | // expanded Jarjar_rules | 
|  | 486 | expandJarjarRules android.Path | 
|  | 487 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 488 | // Extra files generated by the module type to be added as java resources. | 
|  | 489 | extraResources android.Paths | 
|  | 490 |  | 
|  | 491 | hiddenAPI | 
|  | 492 | dexer | 
|  | 493 | dexpreopter | 
|  | 494 | usesLibrary | 
|  | 495 | linter | 
|  | 496 |  | 
|  | 497 | // list of the xref extraction files | 
|  | 498 | kytheFiles android.Paths | 
|  | 499 |  | 
|  | 500 | // Collect the module directory for IDE info in java/jdeps.go. | 
|  | 501 | modulePaths []string | 
|  | 502 |  | 
|  | 503 | hideApexVariantFromMake bool | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 504 |  | 
|  | 505 | sdkVersion    android.SdkSpec | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 506 | minSdkVersion android.ApiLevel | 
| Spandan Das | a26eda7 | 2023-03-02 00:56:06 +0000 | [diff] [blame] | 507 | maxSdkVersion android.ApiLevel | 
| Romain Jobredeaux | 3ec36ad4 | 2021-10-29 13:08:48 -0400 | [diff] [blame] | 508 |  | 
|  | 509 | sourceExtensions []string | 
| Vadim Spivak | 3c496f0 | 2023-06-08 06:14:59 +0000 | [diff] [blame] | 510 |  | 
|  | 511 | annoSrcJars android.Paths | 
| Jihoon Kang | 1bfb6f2 | 2023-07-01 00:13:47 +0000 | [diff] [blame] | 512 |  | 
|  | 513 | // output file name based on Stem property. | 
|  | 514 | // This should be set in every ModuleWithStem's GenerateAndroidBuildActions | 
|  | 515 | // or the module should override Stem(). | 
|  | 516 | stem string | 
| Joe Onorato | 6fe59eb | 2023-07-16 13:20:33 -0700 | [diff] [blame] | 517 |  | 
|  | 518 | // Aconfig "cache files" that went directly into this module.  Transitive ones are | 
|  | 519 | // tracked via JavaInfo.TransitiveAconfigFiles | 
|  | 520 | // TODO: Extract to something standalone to propagate tags via GeneratedJavaLibraryModule | 
|  | 521 | aconfigIntermediates android.Paths | 
|  | 522 |  | 
|  | 523 | // Aconfig files for all transitive deps.  Also exposed via JavaInfo | 
|  | 524 | transitiveAconfigFiles *android.DepSet[android.Path] | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 525 | } | 
|  | 526 |  | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 527 | func (j *Module) CheckStableSdkVersion(ctx android.BaseModuleContext) error { | 
|  | 528 | sdkVersion := j.SdkVersion(ctx) | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 529 | if sdkVersion.Stable() { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 530 | return nil | 
|  | 531 | } | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 532 | if sdkVersion.Kind == android.SdkCorePlatform { | 
| Paul Duffin | 1ea7c9f | 2021-03-15 09:39:13 +0000 | [diff] [blame] | 533 | if useLegacyCorePlatformApi(ctx, j.BaseModuleName()) { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 534 | return fmt.Errorf("non stable SDK %v - uses legacy core platform", sdkVersion) | 
|  | 535 | } else { | 
|  | 536 | // Treat stable core platform as stable. | 
|  | 537 | return nil | 
|  | 538 | } | 
|  | 539 | } else { | 
|  | 540 | return fmt.Errorf("non stable SDK %v", sdkVersion) | 
|  | 541 | } | 
|  | 542 | } | 
|  | 543 |  | 
|  | 544 | // checkSdkVersions enforces restrictions around SDK dependencies. | 
|  | 545 | func (j *Module) checkSdkVersions(ctx android.ModuleContext) { | 
|  | 546 | if j.RequiresStableAPIs(ctx) { | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 547 | if sc, ok := ctx.Module().(android.SdkContext); ok { | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 548 | if !sc.SdkVersion(ctx).Specified() { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 549 | ctx.PropertyErrorf("sdk_version", | 
|  | 550 | "sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).") | 
|  | 551 | } | 
|  | 552 | } | 
|  | 553 | } | 
|  | 554 |  | 
|  | 555 | // Make sure this module doesn't statically link to modules with lower-ranked SDK link type. | 
|  | 556 | // See rank() for details. | 
|  | 557 | ctx.VisitDirectDeps(func(module android.Module) { | 
|  | 558 | tag := ctx.OtherModuleDependencyTag(module) | 
|  | 559 | switch module.(type) { | 
|  | 560 | // TODO(satayev): cover other types as well, e.g. imports | 
|  | 561 | case *Library, *AndroidLibrary: | 
|  | 562 | switch tag { | 
| Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame] | 563 | case bootClasspathTag, sdkLibTag, libTag, staticLibTag, java9LibTag: | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 564 | j.checkSdkLinkType(ctx, module.(moduleWithSdkDep), tag.(dependencyTag)) | 
|  | 565 | } | 
|  | 566 | } | 
|  | 567 | }) | 
|  | 568 | } | 
|  | 569 |  | 
|  | 570 | func (j *Module) checkPlatformAPI(ctx android.ModuleContext) { | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 571 | if sc, ok := ctx.Module().(android.SdkContext); ok { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 572 | usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis) | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 573 | sdkVersionSpecified := sc.SdkVersion(ctx).Specified() | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 574 | if usePlatformAPI && sdkVersionSpecified { | 
| Spandan Das | 6099934 | 2021-11-16 04:15:33 +0000 | [diff] [blame] | 575 | ctx.PropertyErrorf("platform_apis", "This module has conflicting settings. sdk_version is not empty, which means this module cannot use platform APIs. However platform_apis is set to true.") | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 576 | } else if !usePlatformAPI && !sdkVersionSpecified { | 
| Spandan Das | 6099934 | 2021-11-16 04:15:33 +0000 | [diff] [blame] | 577 | ctx.PropertyErrorf("platform_apis", "This module has conflicting settings. sdk_version is empty, which means that this module is build against platform APIs. However platform_apis is not set to true") | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 578 | } | 
|  | 579 |  | 
|  | 580 | } | 
|  | 581 | } | 
|  | 582 |  | 
| Mark White | a15790a | 2023-08-22 21:28:11 +0000 | [diff] [blame] | 583 | func (j *Module) checkHeadersOnly(ctx android.ModuleContext) { | 
|  | 584 | if _, ok := ctx.Module().(android.SdkContext); ok { | 
| Liz Kammer | 6077263 | 2023-10-05 17:18:44 -0400 | [diff] [blame] | 585 | headersOnly := proptools.Bool(j.properties.Headers_only) | 
| Mark White | a15790a | 2023-08-22 21:28:11 +0000 | [diff] [blame] | 586 | installable := proptools.Bool(j.properties.Installable) | 
|  | 587 |  | 
|  | 588 | if headersOnly && installable { | 
|  | 589 | ctx.PropertyErrorf("headers_only", "This module has conflicting settings. headers_only is true which, which means this module doesn't generate an implementation jar. However installable is set to true.") | 
|  | 590 | } | 
|  | 591 | } | 
|  | 592 | } | 
|  | 593 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 594 | func (j *Module) addHostProperties() { | 
|  | 595 | j.AddProperties( | 
|  | 596 | &j.properties, | 
|  | 597 | &j.protoProperties, | 
|  | 598 | &j.usesLibraryProperties, | 
|  | 599 | ) | 
|  | 600 | } | 
|  | 601 |  | 
|  | 602 | func (j *Module) addHostAndDeviceProperties() { | 
|  | 603 | j.addHostProperties() | 
|  | 604 | j.AddProperties( | 
|  | 605 | &j.deviceProperties, | 
| Jooyung Han | 01d80d8 | 2022-01-08 12:16:32 +0900 | [diff] [blame] | 606 | &j.overridableDeviceProperties, | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 607 | &j.dexer.dexProperties, | 
|  | 608 | &j.dexpreoptProperties, | 
|  | 609 | &j.linter.properties, | 
|  | 610 | ) | 
|  | 611 | } | 
|  | 612 |  | 
| Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 613 | // provideHiddenAPIPropertyInfo populates a HiddenAPIPropertyInfo from hidden API properties and | 
|  | 614 | // makes it available through the hiddenAPIPropertyInfoProvider. | 
|  | 615 | func (j *Module) provideHiddenAPIPropertyInfo(ctx android.ModuleContext) { | 
|  | 616 | hiddenAPIInfo := newHiddenAPIPropertyInfo() | 
|  | 617 |  | 
|  | 618 | // Populate with flag file paths from the properties. | 
|  | 619 | hiddenAPIInfo.extractFlagFilesFromProperties(ctx, &j.deviceProperties.HiddenAPIFlagFileProperties) | 
|  | 620 |  | 
|  | 621 | // Populate with package rules from the properties. | 
|  | 622 | hiddenAPIInfo.extractPackageRulesFromProperties(&j.deviceProperties.HiddenAPIPackageProperties) | 
|  | 623 |  | 
|  | 624 | ctx.SetProvider(hiddenAPIPropertyInfoProvider, hiddenAPIInfo) | 
|  | 625 | } | 
|  | 626 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 627 | func (j *Module) OutputFiles(tag string) (android.Paths, error) { | 
|  | 628 | switch tag { | 
|  | 629 | case "": | 
|  | 630 | return append(android.Paths{j.outputFile}, j.extraOutputFiles...), nil | 
|  | 631 | case android.DefaultDistTag: | 
|  | 632 | return android.Paths{j.outputFile}, nil | 
|  | 633 | case ".jar": | 
|  | 634 | return android.Paths{j.implementationAndResourcesJar}, nil | 
| Colin Cross | ab50dea | 2022-10-14 11:45:44 -0700 | [diff] [blame] | 635 | case ".hjar": | 
|  | 636 | return android.Paths{j.headerJarFile}, nil | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 637 | case ".proguard_map": | 
|  | 638 | if j.dexer.proguardDictionary.Valid() { | 
|  | 639 | return android.Paths{j.dexer.proguardDictionary.Path()}, nil | 
|  | 640 | } | 
|  | 641 | return nil, fmt.Errorf("%q was requested, but no output file was found.", tag) | 
| Joe Onorato | ffac9be | 2023-08-19 19:48:34 -0700 | [diff] [blame] | 642 | case ".generated_srcjars": | 
|  | 643 | return j.properties.Generated_srcjars, nil | 
| Thiébaud Weksteen | d054436 | 2023-09-29 10:26:43 +1000 | [diff] [blame] | 644 | case ".lint": | 
|  | 645 | if j.linter.outputs.xml != nil { | 
|  | 646 | return android.Paths{j.linter.outputs.xml}, nil | 
|  | 647 | } | 
|  | 648 | return nil, fmt.Errorf("%q was requested, but no output file was found.", tag) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 649 | default: | 
|  | 650 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) | 
|  | 651 | } | 
|  | 652 | } | 
|  | 653 |  | 
|  | 654 | var _ android.OutputFileProducer = (*Module)(nil) | 
|  | 655 |  | 
|  | 656 | func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { | 
|  | 657 | initJavaModule(module, hod, false) | 
|  | 658 | } | 
|  | 659 |  | 
|  | 660 | func InitJavaModuleMultiTargets(module android.DefaultableModule, hod android.HostOrDeviceSupported) { | 
|  | 661 | initJavaModule(module, hod, true) | 
|  | 662 | } | 
|  | 663 |  | 
|  | 664 | func initJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported, multiTargets bool) { | 
|  | 665 | multilib := android.MultilibCommon | 
|  | 666 | if multiTargets { | 
|  | 667 | android.InitAndroidMultiTargetsArchModule(module, hod, multilib) | 
|  | 668 | } else { | 
|  | 669 | android.InitAndroidArchModule(module, hod, multilib) | 
|  | 670 | } | 
|  | 671 | android.InitDefaultableModule(module) | 
|  | 672 | } | 
|  | 673 |  | 
|  | 674 | func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool { | 
|  | 675 | return j.properties.Instrument && | 
|  | 676 | ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") && | 
|  | 677 | ctx.DeviceConfig().JavaCoverageEnabledForPath(ctx.ModuleDir()) | 
|  | 678 | } | 
|  | 679 |  | 
|  | 680 | func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool { | 
| Paul Duffin | 0038a8d | 2022-05-03 00:28:40 +0000 | [diff] [blame] | 681 | return j.properties.Supports_static_instrumentation && | 
|  | 682 | j.shouldInstrument(ctx) && | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 683 | (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") || | 
|  | 684 | ctx.Config().UnbundledBuild()) | 
|  | 685 | } | 
|  | 686 |  | 
|  | 687 | func (j *Module) shouldInstrumentInApex(ctx android.BaseModuleContext) bool { | 
|  | 688 | // Force enable the instrumentation for java code that is built for APEXes ... | 
|  | 689 | // except for the jacocoagent itself (because instrumenting jacocoagent using jacocoagent | 
|  | 690 | // doesn't make sense) or framework libraries (e.g. libraries found in the InstrumentFrameworkModules list) unless EMMA_INSTRUMENT_FRAMEWORK is true. | 
|  | 691 | apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) | 
|  | 692 | isJacocoAgent := ctx.ModuleName() == "jacocoagent" | 
|  | 693 | if j.DirectlyInAnyApex() && !isJacocoAgent && !apexInfo.IsForPlatform() { | 
|  | 694 | if !inList(ctx.ModuleName(), config.InstrumentFrameworkModules) { | 
|  | 695 | return true | 
|  | 696 | } else if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") { | 
|  | 697 | return true | 
|  | 698 | } | 
|  | 699 | } | 
|  | 700 | return false | 
|  | 701 | } | 
|  | 702 |  | 
| Sam Delmerico | 1e3f78f | 2022-09-07 12:07:07 -0400 | [diff] [blame] | 703 | func (j *Module) setInstrument(value bool) { | 
|  | 704 | j.properties.Instrument = value | 
|  | 705 | } | 
|  | 706 |  | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 707 | func (j *Module) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { | 
|  | 708 | return android.SdkSpecFrom(ctx, String(j.deviceProperties.Sdk_version)) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 709 | } | 
|  | 710 |  | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 711 | func (j *Module) SystemModules() string { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 712 | return proptools.String(j.deviceProperties.System_modules) | 
|  | 713 | } | 
|  | 714 |  | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 715 | func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 716 | if j.deviceProperties.Min_sdk_version != nil { | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 717 | return android.ApiLevelFrom(ctx, *j.deviceProperties.Min_sdk_version) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 718 | } | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 719 | return j.SdkVersion(ctx).ApiLevel | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 720 | } | 
|  | 721 |  | 
| Yu Liu | f2b9401 | 2023-09-19 15:09:10 -0700 | [diff] [blame] | 722 | func (j *Module) GetDeviceProperties() *DeviceProperties { | 
|  | 723 | return &j.deviceProperties | 
|  | 724 | } | 
|  | 725 |  | 
| Spandan Das | a26eda7 | 2023-03-02 00:56:06 +0000 | [diff] [blame] | 726 | func (j *Module) MaxSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { | 
|  | 727 | if j.deviceProperties.Max_sdk_version != nil { | 
|  | 728 | return android.ApiLevelFrom(ctx, *j.deviceProperties.Max_sdk_version) | 
|  | 729 | } | 
|  | 730 | // Default is PrivateApiLevel | 
|  | 731 | return android.SdkSpecPrivate.ApiLevel | 
| satayev | 0a420e7 | 2021-11-29 17:25:52 +0000 | [diff] [blame] | 732 | } | 
|  | 733 |  | 
| Spandan Das | a26eda7 | 2023-03-02 00:56:06 +0000 | [diff] [blame] | 734 | func (j *Module) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.ApiLevel { | 
|  | 735 | if j.deviceProperties.Replace_max_sdk_version_placeholder != nil { | 
|  | 736 | return android.ApiLevelFrom(ctx, *j.deviceProperties.Replace_max_sdk_version_placeholder) | 
|  | 737 | } | 
|  | 738 | // Default is PrivateApiLevel | 
|  | 739 | return android.SdkSpecPrivate.ApiLevel | 
| William Loh | 5a082f9 | 2022-05-17 20:21:50 +0000 | [diff] [blame] | 740 | } | 
|  | 741 |  | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 742 | func (j *Module) MinSdkVersionString() string { | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 743 | return j.minSdkVersion.String() | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 744 | } | 
|  | 745 |  | 
| Spandan Das | ca70fc4 | 2023-03-01 23:38:49 +0000 | [diff] [blame] | 746 | func (j *Module) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 747 | if j.deviceProperties.Target_sdk_version != nil { | 
| Spandan Das | ca70fc4 | 2023-03-01 23:38:49 +0000 | [diff] [blame] | 748 | return android.ApiLevelFrom(ctx, *j.deviceProperties.Target_sdk_version) | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 749 | } | 
| Spandan Das | ca70fc4 | 2023-03-01 23:38:49 +0000 | [diff] [blame] | 750 | return j.SdkVersion(ctx).ApiLevel | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 751 | } | 
|  | 752 |  | 
|  | 753 | func (j *Module) AvailableFor(what string) bool { | 
|  | 754 | if what == android.AvailableToPlatform && Bool(j.deviceProperties.Hostdex) { | 
|  | 755 | // Exception: for hostdex: true libraries, the platform variant is created | 
|  | 756 | // even if it's not marked as available to platform. In that case, the platform | 
|  | 757 | // variant is used only for the hostdex and not installed to the device. | 
|  | 758 | return true | 
|  | 759 | } | 
|  | 760 | return j.ApexModuleBase.AvailableFor(what) | 
|  | 761 | } | 
|  | 762 |  | 
|  | 763 | func (j *Module) deps(ctx android.BottomUpMutatorContext) { | 
|  | 764 | if ctx.Device() { | 
|  | 765 | j.linter.deps(ctx) | 
|  | 766 |  | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 767 | sdkDeps(ctx, android.SdkContext(j), j.dexer) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 768 |  | 
|  | 769 | if j.deviceProperties.SyspropPublicStub != "" { | 
|  | 770 | // This is a sysprop implementation library that has a corresponding sysprop public | 
|  | 771 | // stubs library, and a dependency on it so that dependencies on the implementation can | 
|  | 772 | // be forwarded to the public stubs library when necessary. | 
|  | 773 | ctx.AddVariationDependencies(nil, syspropPublicStubDepTag, j.deviceProperties.SyspropPublicStub) | 
|  | 774 | } | 
|  | 775 | } | 
|  | 776 |  | 
|  | 777 | libDeps := ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) | 
| Jihoon Kang | 381c2fa | 2023-06-01 22:17:32 +0000 | [diff] [blame] | 778 |  | 
|  | 779 | j.properties.Static_libs = android.RemoveListFromList(j.properties.Static_libs, j.properties.Exclude_static_libs) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 780 | ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...) | 
|  | 781 |  | 
|  | 782 | // Add dependency on libraries that provide additional hidden api annotations. | 
|  | 783 | ctx.AddVariationDependencies(nil, hiddenApiAnnotationsTag, j.properties.Hiddenapi_additional_annotations...) | 
|  | 784 |  | 
|  | 785 | if ctx.DeviceConfig().VndkVersion() != "" && ctx.Config().EnforceInterPartitionJavaSdkLibrary() { | 
|  | 786 | // Require java_sdk_library at inter-partition java dependency to ensure stable | 
|  | 787 | // interface between partitions. If inter-partition java_library dependency is detected, | 
|  | 788 | // raise build error because java_library doesn't have a stable interface. | 
|  | 789 | // | 
|  | 790 | // Inputs: | 
|  | 791 | //    PRODUCT_ENFORCE_INTER_PARTITION_JAVA_SDK_LIBRARY | 
|  | 792 | //      if true, enable enforcement | 
|  | 793 | //    PRODUCT_INTER_PARTITION_JAVA_LIBRARY_ALLOWLIST | 
|  | 794 | //      exception list of java_library names to allow inter-partition dependency | 
|  | 795 | for idx := range j.properties.Libs { | 
|  | 796 | if libDeps[idx] == nil { | 
|  | 797 | continue | 
|  | 798 | } | 
|  | 799 |  | 
|  | 800 | if javaDep, ok := libDeps[idx].(javaSdkLibraryEnforceContext); ok { | 
|  | 801 | // java_sdk_library is always allowed at inter-partition dependency. | 
|  | 802 | // So, skip check. | 
|  | 803 | if _, ok := javaDep.(*SdkLibrary); ok { | 
|  | 804 | continue | 
|  | 805 | } | 
|  | 806 |  | 
|  | 807 | j.checkPartitionsForJavaDependency(ctx, "libs", javaDep) | 
|  | 808 | } | 
|  | 809 | } | 
|  | 810 | } | 
|  | 811 |  | 
|  | 812 | // For library dependencies that are component libraries (like stubs), add the implementation | 
|  | 813 | // as a dependency (dexpreopt needs to be against the implementation library, not stubs). | 
|  | 814 | for _, dep := range libDeps { | 
|  | 815 | if dep != nil { | 
|  | 816 | if component, ok := dep.(SdkLibraryComponentDependency); ok { | 
|  | 817 | if lib := component.OptionalSdkLibraryImplementation(); lib != nil { | 
| Ulya Trafimovich | fc0f6e3 | 2021-08-12 16:16:11 +0100 | [diff] [blame] | 818 | // Add library as optional if it's one of the optional compatibility libs. | 
| Ulya Trafimovich | f5d91bb | 2022-05-04 12:00:02 +0100 | [diff] [blame] | 819 | tag := usesLibReqTag | 
|  | 820 | if android.InList(*lib, dexpreopt.OptionalCompatUsesLibs) { | 
|  | 821 | tag = usesLibOptTag | 
|  | 822 | } | 
| Ulya Trafimovich | fc0f6e3 | 2021-08-12 16:16:11 +0100 | [diff] [blame] | 823 | ctx.AddVariationDependencies(nil, tag, *lib) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 824 | } | 
|  | 825 | } | 
|  | 826 | } | 
|  | 827 | } | 
|  | 828 |  | 
|  | 829 | ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...) | 
|  | 830 | ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), errorpronePluginTag, j.properties.Errorprone.Extra_check_modules...) | 
|  | 831 | ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...) | 
|  | 832 |  | 
|  | 833 | android.ProtoDeps(ctx, &j.protoProperties) | 
|  | 834 | if j.hasSrcExt(".proto") { | 
|  | 835 | protoDeps(ctx, &j.protoProperties) | 
|  | 836 | } | 
|  | 837 |  | 
|  | 838 | if j.hasSrcExt(".kt") { | 
|  | 839 | // TODO(ccross): move this to a mutator pass that can tell if generated sources contain | 
|  | 840 | // Kotlin files | 
|  | 841 | ctx.AddVariationDependencies(nil, kotlinStdlibTag, | 
|  | 842 | "kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8") | 
| Colin Cross | 0635447 | 2022-05-03 14:20:24 -0700 | [diff] [blame] | 843 | ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations") | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 844 | } | 
|  | 845 |  | 
|  | 846 | // Framework libraries need special handling in static coverage builds: they should not have | 
|  | 847 | // static dependency on jacoco, otherwise there would be multiple conflicting definitions of | 
|  | 848 | // the same jacoco classes coming from different bootclasspath jars. | 
|  | 849 | if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) { | 
|  | 850 | if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") { | 
|  | 851 | j.properties.Instrument = true | 
|  | 852 | } | 
|  | 853 | } else if j.shouldInstrumentStatic(ctx) { | 
|  | 854 | ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent") | 
|  | 855 | } | 
| Colin Cross | a1ff7c6 | 2021-09-17 14:11:52 -0700 | [diff] [blame] | 856 |  | 
|  | 857 | if j.useCompose() { | 
|  | 858 | ctx.AddVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), kotlinPluginTag, | 
|  | 859 | "androidx.compose.compiler_compiler-hosted") | 
|  | 860 | } | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 861 | } | 
|  | 862 |  | 
|  | 863 | func hasSrcExt(srcs []string, ext string) bool { | 
|  | 864 | for _, src := range srcs { | 
|  | 865 | if filepath.Ext(src) == ext { | 
|  | 866 | return true | 
|  | 867 | } | 
|  | 868 | } | 
|  | 869 |  | 
|  | 870 | return false | 
|  | 871 | } | 
|  | 872 |  | 
|  | 873 | func (j *Module) hasSrcExt(ext string) bool { | 
|  | 874 | return hasSrcExt(j.properties.Srcs, ext) | 
|  | 875 | } | 
|  | 876 |  | 
| Thiébaud Weksteen | de8417c | 2022-02-10 15:41:46 +1100 | [diff] [blame] | 877 | func (j *Module) individualAidlFlags(ctx android.ModuleContext, aidlFile android.Path) string { | 
|  | 878 | var flags string | 
|  | 879 |  | 
|  | 880 | if Bool(j.deviceProperties.Aidl.Enforce_permissions) { | 
|  | 881 | if !android.InList(aidlFile.String(), j.ignoredAidlPermissionList.Strings()) { | 
|  | 882 | flags = "-Wmissing-permission-annotation -Werror" | 
|  | 883 | } | 
|  | 884 | } | 
|  | 885 | return flags | 
|  | 886 | } | 
|  | 887 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 888 | func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, | 
| Sam Delmerico | 2351eac | 2022-05-24 17:10:02 +0000 | [diff] [blame] | 889 | aidlIncludeDirs android.Paths, aidlSrcs android.Paths) (string, android.Paths) { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 890 |  | 
|  | 891 | aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs) | 
|  | 892 | aidlIncludes = append(aidlIncludes, | 
|  | 893 | android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...) | 
|  | 894 | aidlIncludes = append(aidlIncludes, | 
|  | 895 | android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...) | 
|  | 896 |  | 
|  | 897 | var flags []string | 
|  | 898 | var deps android.Paths | 
| Sam Delmerico | 2351eac | 2022-05-24 17:10:02 +0000 | [diff] [blame] | 899 | var includeDirs android.Paths | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 900 |  | 
|  | 901 | flags = append(flags, j.deviceProperties.Aidl.Flags...) | 
|  | 902 |  | 
|  | 903 | if aidlPreprocess.Valid() { | 
|  | 904 | flags = append(flags, "-p"+aidlPreprocess.String()) | 
|  | 905 | deps = append(deps, aidlPreprocess.Path()) | 
|  | 906 | } else if len(aidlIncludeDirs) > 0 { | 
| Sam Delmerico | 2351eac | 2022-05-24 17:10:02 +0000 | [diff] [blame] | 907 | includeDirs = append(includeDirs, aidlIncludeDirs...) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 908 | } | 
|  | 909 |  | 
|  | 910 | if len(j.exportAidlIncludeDirs) > 0 { | 
| Sam Delmerico | 2351eac | 2022-05-24 17:10:02 +0000 | [diff] [blame] | 911 | includeDirs = append(includeDirs, j.exportAidlIncludeDirs...) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 912 | } | 
|  | 913 |  | 
|  | 914 | if len(aidlIncludes) > 0 { | 
| Sam Delmerico | 2351eac | 2022-05-24 17:10:02 +0000 | [diff] [blame] | 915 | includeDirs = append(includeDirs, aidlIncludes...) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 916 | } | 
|  | 917 |  | 
| Sam Delmerico | 2351eac | 2022-05-24 17:10:02 +0000 | [diff] [blame] | 918 | includeDirs = append(includeDirs, android.PathForModuleSrc(ctx)) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 919 | if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() { | 
| Sam Delmerico | 2351eac | 2022-05-24 17:10:02 +0000 | [diff] [blame] | 920 | includeDirs = append(includeDirs, src.Path()) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 921 | } | 
| Sam Delmerico | 2351eac | 2022-05-24 17:10:02 +0000 | [diff] [blame] | 922 | flags = append(flags, android.JoinWithPrefix(includeDirs.Strings(), "-I")) | 
|  | 923 | // add flags for dirs containing AIDL srcs that haven't been specified yet | 
|  | 924 | flags = append(flags, genAidlIncludeFlags(ctx, aidlSrcs, includeDirs)) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 925 |  | 
| Zim | 8774ae1 | 2022-08-17 11:46:34 +0100 | [diff] [blame] | 926 | sdkVersion := (j.SdkVersion(ctx)).Kind | 
| Parth Sane | 000cbe0 | 2022-11-22 13:01:22 +0000 | [diff] [blame] | 927 | defaultTrace := ((sdkVersion == android.SdkSystemServer) || (sdkVersion == android.SdkCore) || (sdkVersion == android.SdkCorePlatform) || (sdkVersion == android.SdkModule) || (sdkVersion == android.SdkSystem)) | 
| Zim | 8774ae1 | 2022-08-17 11:46:34 +0100 | [diff] [blame] | 928 | if proptools.BoolDefault(j.deviceProperties.Aidl.Generate_traces, defaultTrace) { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 929 | flags = append(flags, "-t") | 
|  | 930 | } | 
|  | 931 |  | 
|  | 932 | if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) { | 
|  | 933 | flags = append(flags, "--transaction_names") | 
|  | 934 | } | 
|  | 935 |  | 
| Thiébaud Weksteen | de8417c | 2022-02-10 15:41:46 +1100 | [diff] [blame] | 936 | if Bool(j.deviceProperties.Aidl.Enforce_permissions) { | 
|  | 937 | exceptions := j.deviceProperties.Aidl.Enforce_permissions_exceptions | 
|  | 938 | j.ignoredAidlPermissionList = android.PathsForModuleSrcExcludes(ctx, exceptions, nil) | 
|  | 939 | } | 
|  | 940 |  | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 941 | aidlMinSdkVersion := j.MinSdkVersion(ctx).String() | 
| Jooyung Han | 07f70c0 | 2021-11-06 07:08:45 +0900 | [diff] [blame] | 942 | flags = append(flags, "--min_sdk_version="+aidlMinSdkVersion) | 
|  | 943 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 944 | return strings.Join(flags, " "), deps | 
|  | 945 | } | 
|  | 946 |  | 
|  | 947 | func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags { | 
|  | 948 |  | 
|  | 949 | var flags javaBuilderFlags | 
|  | 950 |  | 
|  | 951 | // javaVersion flag. | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 952 | flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), android.SdkContext(j)) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 953 |  | 
| Cole Faust | 2b1536e | 2021-06-18 12:25:54 -0700 | [diff] [blame] | 954 | epEnabled := j.properties.Errorprone.Enabled | 
|  | 955 | if (ctx.Config().RunErrorProne() && epEnabled == nil) || Bool(epEnabled) { | 
| Paul Duffin | 7413558 | 2022-10-06 11:01:59 +0100 | [diff] [blame] | 956 | if config.ErrorProneClasspath == nil && !ctx.Config().RunningInsideUnitTest() { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 957 | ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?") | 
|  | 958 | } | 
|  | 959 |  | 
|  | 960 | errorProneFlags := []string{ | 
|  | 961 | "-Xplugin:ErrorProne", | 
|  | 962 | "${config.ErrorProneChecks}", | 
|  | 963 | } | 
|  | 964 | errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...) | 
|  | 965 |  | 
| Colin Cross | 8bf6cad | 2022-02-28 13:07:03 -0800 | [diff] [blame] | 966 | flags.errorProneExtraJavacFlags = "${config.ErrorProneHeapFlags} ${config.ErrorProneFlags} " + | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 967 | "'" + strings.Join(errorProneFlags, " ") + "'" | 
|  | 968 | flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath)) | 
|  | 969 | } | 
|  | 970 |  | 
|  | 971 | // classpath | 
|  | 972 | flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...) | 
|  | 973 | flags.classpath = append(flags.classpath, deps.classpath...) | 
| Colin Cross | 9bb9bfb | 2022-03-17 11:12:32 -0700 | [diff] [blame] | 974 | flags.dexClasspath = append(flags.dexClasspath, deps.dexClasspath...) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 975 | flags.java9Classpath = append(flags.java9Classpath, deps.java9Classpath...) | 
|  | 976 | flags.processorPath = append(flags.processorPath, deps.processorPath...) | 
|  | 977 | flags.errorProneProcessorPath = append(flags.errorProneProcessorPath, deps.errorProneProcessorPath...) | 
|  | 978 |  | 
|  | 979 | flags.processors = append(flags.processors, deps.processorClasses...) | 
|  | 980 | flags.processors = android.FirstUniqueStrings(flags.processors) | 
|  | 981 |  | 
|  | 982 | if len(flags.bootClasspath) == 0 && ctx.Host() && !flags.javaVersion.usesJavaModules() && | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 983 | decodeSdkDep(ctx, android.SdkContext(j)).hasStandardLibs() { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 984 | // Give host-side tools a version of OpenJDK's standard libraries | 
|  | 985 | // close to what they're targeting. As of Dec 2017, AOSP is only | 
|  | 986 | // bundling OpenJDK 8 and 9, so nothing < 8 is available. | 
|  | 987 | // | 
|  | 988 | // When building with OpenJDK 8, the following should have no | 
|  | 989 | // effect since those jars would be available by default. | 
|  | 990 | // | 
|  | 991 | // When building with OpenJDK 9 but targeting a version < 1.8, | 
|  | 992 | // putting them on the bootclasspath means that: | 
|  | 993 | // a) code can't (accidentally) refer to OpenJDK 9 specific APIs | 
|  | 994 | // b) references to existing APIs are not reinterpreted in an | 
|  | 995 | //    OpenJDK 9-specific way, eg. calls to subclasses of | 
|  | 996 | //    java.nio.Buffer as in http://b/70862583 | 
|  | 997 | java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME") | 
|  | 998 | flags.bootClasspath = append(flags.bootClasspath, | 
|  | 999 | android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"), | 
|  | 1000 | android.PathForSource(ctx, java8Home, "jre/lib/rt.jar")) | 
|  | 1001 | if Bool(j.properties.Use_tools_jar) { | 
|  | 1002 | flags.bootClasspath = append(flags.bootClasspath, | 
|  | 1003 | android.PathForSource(ctx, java8Home, "lib/tools.jar")) | 
|  | 1004 | } | 
|  | 1005 | } | 
|  | 1006 |  | 
|  | 1007 | // systemModules | 
|  | 1008 | flags.systemModules = deps.systemModules | 
|  | 1009 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1010 | return flags | 
|  | 1011 | } | 
|  | 1012 |  | 
|  | 1013 | func (j *Module) collectJavacFlags( | 
|  | 1014 | ctx android.ModuleContext, flags javaBuilderFlags, srcFiles android.Paths) javaBuilderFlags { | 
|  | 1015 | // javac flags. | 
|  | 1016 | javacFlags := j.properties.Javacflags | 
|  | 1017 |  | 
|  | 1018 | if ctx.Config().MinimizeJavaDebugInfo() && !ctx.Host() { | 
|  | 1019 | // For non-host binaries, override the -g flag passed globally to remove | 
|  | 1020 | // local variable debug info to reduce disk and memory usage. | 
|  | 1021 | javacFlags = append(javacFlags, "-g:source,lines") | 
|  | 1022 | } | 
|  | 1023 | javacFlags = append(javacFlags, "-Xlint:-dep-ann") | 
|  | 1024 |  | 
|  | 1025 | if flags.javaVersion.usesJavaModules() { | 
|  | 1026 | javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...) | 
| Liz Kammer | 9f52f6b | 2023-10-06 16:47:00 -0400 | [diff] [blame] | 1027 | } else if len(j.properties.Openjdk9.Javacflags) > 0 { | 
|  | 1028 | // java version defaults higher than openjdk 9, these conditionals should no longer be necessary | 
|  | 1029 | ctx.PropertyErrorf("openjdk9.javacflags", "JDK version defaults to higher than 9") | 
|  | 1030 | } | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1031 |  | 
| Liz Kammer | 9f52f6b | 2023-10-06 16:47:00 -0400 | [diff] [blame] | 1032 | if flags.javaVersion.usesJavaModules() { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1033 | if j.properties.Patch_module != nil { | 
|  | 1034 | // Manually specify build directory in case it is not under the repo root. | 
|  | 1035 | // (javac doesn't seem to expand into symbolic links when searching for patch-module targets, so | 
|  | 1036 | // just adding a symlink under the root doesn't help.) | 
| Lukacs T. Berki | 9f6c24a | 2021-08-26 15:07:24 +0200 | [diff] [blame] | 1037 | patchPaths := []string{".", ctx.Config().SoongOutDir()} | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1038 |  | 
|  | 1039 | // b/150878007 | 
|  | 1040 | // | 
|  | 1041 | // Workaround to support *Bazel-executed* JDK9 javac in Bazel's | 
|  | 1042 | // execution root for --patch-module. If this javac command line is | 
|  | 1043 | // invoked within Bazel's execution root working directory, the top | 
|  | 1044 | // level directories (e.g. libcore/, tools/, frameworks/) are all | 
|  | 1045 | // symlinks. JDK9 javac does not traverse into symlinks, which causes | 
|  | 1046 | // --patch-module to fail source file lookups when invoked in the | 
|  | 1047 | // execution root. | 
|  | 1048 | // | 
|  | 1049 | // Short of patching javac or enumerating *all* directories as possible | 
|  | 1050 | // input dirs, manually add the top level dir of the source files to be | 
|  | 1051 | // compiled. | 
|  | 1052 | topLevelDirs := map[string]bool{} | 
|  | 1053 | for _, srcFilePath := range srcFiles { | 
|  | 1054 | srcFileParts := strings.Split(srcFilePath.String(), "/") | 
|  | 1055 | // Ignore source files that are already in the top level directory | 
|  | 1056 | // as well as generated files in the out directory. The out | 
|  | 1057 | // directory may be an absolute path, which means srcFileParts[0] is the | 
|  | 1058 | // empty string, so check that as well. Note that "out" in Bazel's execution | 
|  | 1059 | // root is *not* a symlink, which doesn't cause problems for --patch-modules | 
|  | 1060 | // anyway, so it's fine to not apply this workaround for generated | 
|  | 1061 | // source files. | 
|  | 1062 | if len(srcFileParts) > 1 && | 
|  | 1063 | srcFileParts[0] != "" && | 
|  | 1064 | srcFileParts[0] != "out" { | 
|  | 1065 | topLevelDirs[srcFileParts[0]] = true | 
|  | 1066 | } | 
|  | 1067 | } | 
| Cole Faust | 18994c7 | 2023-02-28 16:02:16 -0800 | [diff] [blame] | 1068 | patchPaths = append(patchPaths, android.SortedKeys(topLevelDirs)...) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1069 |  | 
|  | 1070 | classPath := flags.classpath.FormJavaClassPath("") | 
|  | 1071 | if classPath != "" { | 
|  | 1072 | patchPaths = append(patchPaths, classPath) | 
|  | 1073 | } | 
|  | 1074 | javacFlags = append( | 
|  | 1075 | javacFlags, | 
|  | 1076 | "--patch-module="+String(j.properties.Patch_module)+"="+strings.Join(patchPaths, ":")) | 
|  | 1077 | } | 
|  | 1078 | } | 
|  | 1079 |  | 
|  | 1080 | if len(javacFlags) > 0 { | 
|  | 1081 | // optimization. | 
|  | 1082 | ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " ")) | 
|  | 1083 | flags.javacFlags = "$javacFlags" | 
|  | 1084 | } | 
|  | 1085 |  | 
|  | 1086 | return flags | 
|  | 1087 | } | 
|  | 1088 |  | 
| Romain Jobredeaux | 3ec36ad4 | 2021-10-29 13:08:48 -0400 | [diff] [blame] | 1089 | func (j *Module) AddJSONData(d *map[string]interface{}) { | 
|  | 1090 | (&j.ModuleBase).AddJSONData(d) | 
|  | 1091 | (*d)["Java"] = map[string]interface{}{ | 
|  | 1092 | "SourceExtensions": j.sourceExtensions, | 
|  | 1093 | } | 
|  | 1094 |  | 
|  | 1095 | } | 
|  | 1096 |  | 
| usta | 0391ca4 | 2023-09-19 15:51:59 -0400 | [diff] [blame] | 1097 | func (j *Module) addGeneratedSrcJars(path android.Path) { | 
|  | 1098 | j.properties.Generated_srcjars = append(j.properties.Generated_srcjars, path) | 
| Joe Onorato | 175073c | 2023-06-01 14:42:59 -0700 | [diff] [blame] | 1099 | } | 
|  | 1100 |  | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1101 | func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspathJars, extraCombinedJars android.Paths) { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1102 | j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs) | 
|  | 1103 |  | 
|  | 1104 | deps := j.collectDeps(ctx) | 
|  | 1105 | flags := j.collectBuilderFlags(ctx, deps) | 
|  | 1106 |  | 
|  | 1107 | if flags.javaVersion.usesJavaModules() { | 
|  | 1108 | j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...) | 
| Liz Kammer | 9f52f6b | 2023-10-06 16:47:00 -0400 | [diff] [blame] | 1109 | } else if len(j.properties.Openjdk9.Javacflags) > 0 { | 
|  | 1110 | // java version defaults higher than openjdk 9, these conditionals should no longer be necessary | 
|  | 1111 | ctx.PropertyErrorf("openjdk9.srcs", "JDK version defaults to higher than 9") | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1112 | } | 
| Sorin Basca | 9347ae3 | 2021-12-20 11:51:24 +0000 | [diff] [blame] | 1113 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1114 | srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs) | 
| Romain Jobredeaux | 3ec36ad4 | 2021-10-29 13:08:48 -0400 | [diff] [blame] | 1115 | j.sourceExtensions = []string{} | 
|  | 1116 | for _, ext := range []string{".kt", ".proto", ".aidl", ".java", ".logtags"} { | 
|  | 1117 | if hasSrcExt(srcFiles.Strings(), ext) { | 
|  | 1118 | j.sourceExtensions = append(j.sourceExtensions, ext) | 
|  | 1119 | } | 
|  | 1120 | } | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1121 | if hasSrcExt(srcFiles.Strings(), ".proto") { | 
|  | 1122 | flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags) | 
|  | 1123 | } | 
|  | 1124 |  | 
|  | 1125 | kotlinCommonSrcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Common_srcs, nil) | 
|  | 1126 | if len(kotlinCommonSrcFiles.FilterOutByExt(".kt")) > 0 { | 
|  | 1127 | ctx.PropertyErrorf("common_srcs", "common_srcs must be .kt files") | 
|  | 1128 | } | 
|  | 1129 |  | 
| Sam Delmerico | 2351eac | 2022-05-24 17:10:02 +0000 | [diff] [blame] | 1130 | aidlSrcs := srcFiles.FilterByExt(".aidl") | 
|  | 1131 | flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs, aidlSrcs) | 
|  | 1132 |  | 
| Thiébaud Weksteen | 5c26f81 | 2022-05-05 14:49:02 +1000 | [diff] [blame] | 1133 | nonGeneratedSrcJars := srcFiles.FilterByExt(".srcjar") | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1134 | srcFiles = j.genSources(ctx, srcFiles, flags) | 
|  | 1135 |  | 
|  | 1136 | // Collect javac flags only after computing the full set of srcFiles to | 
|  | 1137 | // ensure that the --patch-module lookup paths are complete. | 
|  | 1138 | flags = j.collectJavacFlags(ctx, flags, srcFiles) | 
|  | 1139 |  | 
|  | 1140 | srcJars := srcFiles.FilterByExt(".srcjar") | 
|  | 1141 | srcJars = append(srcJars, deps.srcJars...) | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1142 | srcJars = append(srcJars, extraSrcJars...) | 
| Joe Onorato | 175073c | 2023-06-01 14:42:59 -0700 | [diff] [blame] | 1143 | srcJars = append(srcJars, j.properties.Generated_srcjars...) | 
| Colin Cross | b0ef30a | 2021-06-29 10:42:00 -0700 | [diff] [blame] | 1144 | srcFiles = srcFiles.FilterOutByExt(".srcjar") | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1145 |  | 
|  | 1146 | if j.properties.Jarjar_rules != nil { | 
|  | 1147 | j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules) | 
|  | 1148 | } | 
|  | 1149 |  | 
| Jihoon Kang | 1bfb6f2 | 2023-07-01 00:13:47 +0000 | [diff] [blame] | 1150 | jarName := j.Stem() + ".jar" | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1151 |  | 
| Chaohui Wang | dcbe33c | 2022-10-11 11:13:30 +0800 | [diff] [blame] | 1152 | var uniqueJavaFiles android.Paths | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1153 | set := make(map[string]bool) | 
| Chaohui Wang | dcbe33c | 2022-10-11 11:13:30 +0800 | [diff] [blame] | 1154 | for _, v := range srcFiles.FilterByExt(".java") { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1155 | if _, found := set[v.String()]; !found { | 
|  | 1156 | set[v.String()] = true | 
| Chaohui Wang | dcbe33c | 2022-10-11 11:13:30 +0800 | [diff] [blame] | 1157 | uniqueJavaFiles = append(uniqueJavaFiles, v) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1158 | } | 
|  | 1159 | } | 
| Chaohui Wang | dcbe33c | 2022-10-11 11:13:30 +0800 | [diff] [blame] | 1160 | var uniqueKtFiles android.Paths | 
|  | 1161 | for _, v := range srcFiles.FilterByExt(".kt") { | 
|  | 1162 | if _, found := set[v.String()]; !found { | 
|  | 1163 | set[v.String()] = true | 
|  | 1164 | uniqueKtFiles = append(uniqueKtFiles, v) | 
|  | 1165 | } | 
|  | 1166 | } | 
|  | 1167 |  | 
|  | 1168 | var uniqueSrcFiles android.Paths | 
|  | 1169 | uniqueSrcFiles = append(uniqueSrcFiles, uniqueJavaFiles...) | 
|  | 1170 | uniqueSrcFiles = append(uniqueSrcFiles, uniqueKtFiles...) | 
|  | 1171 | j.uniqueSrcFiles = uniqueSrcFiles | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1172 |  | 
| Colin Cross | b5db401 | 2022-03-28 17:12:39 -0700 | [diff] [blame] | 1173 | // We don't currently run annotation processors in turbine, which means we can't use turbine | 
|  | 1174 | // generated header jars when an annotation processor that generates API is enabled.  One | 
|  | 1175 | // exception (handled further below) is when kotlin sources are enabled, in which case turbine | 
|  | 1176 | //  is used to run all of the annotation processors. | 
|  | 1177 | disableTurbine := deps.disableTurbine | 
|  | 1178 |  | 
| Chaohui Wang | dcbe33c | 2022-10-11 11:13:30 +0800 | [diff] [blame] | 1179 | // Collect .java and .kt files for AIDEGen | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1180 | j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, uniqueSrcFiles.Strings()...) | 
|  | 1181 |  | 
|  | 1182 | var kotlinJars android.Paths | 
| Colin Cross | 220a9a1 | 2022-03-28 17:08:01 -0700 | [diff] [blame] | 1183 | var kotlinHeaderJars android.Paths | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1184 |  | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1185 | // Prepend extraClasspathJars to classpath so that the resource processor R.jar comes before | 
|  | 1186 | // any dependencies so that it can override any non-final R classes from dependencies with the | 
|  | 1187 | // final R classes from the app. | 
|  | 1188 | flags.classpath = append(android.CopyOf(extraClasspathJars), flags.classpath...) | 
|  | 1189 |  | 
| Mark White | a15790a | 2023-08-22 21:28:11 +0000 | [diff] [blame] | 1190 | // If compiling headers then compile them and skip the rest | 
| Liz Kammer | 6077263 | 2023-10-05 17:18:44 -0400 | [diff] [blame] | 1191 | if proptools.Bool(j.properties.Headers_only) { | 
| Mark White | a15790a | 2023-08-22 21:28:11 +0000 | [diff] [blame] | 1192 | if srcFiles.HasExt(".kt") { | 
|  | 1193 | ctx.ModuleErrorf("Compiling headers_only with .kt not supported") | 
|  | 1194 | } | 
|  | 1195 | if ctx.Config().IsEnvFalse("TURBINE_ENABLED") || disableTurbine { | 
|  | 1196 | ctx.ModuleErrorf("headers_only is enabled but Turbine is disabled.") | 
|  | 1197 | } | 
|  | 1198 |  | 
|  | 1199 | _, j.headerJarFile = | 
|  | 1200 | j.compileJavaHeader(ctx, uniqueJavaFiles, srcJars, deps, flags, jarName, | 
|  | 1201 | extraCombinedJars) | 
|  | 1202 | if ctx.Failed() { | 
|  | 1203 | return | 
|  | 1204 | } | 
|  | 1205 |  | 
|  | 1206 | ctx.SetProvider(JavaInfoProvider, JavaInfo{ | 
|  | 1207 | HeaderJars:                     android.PathsIfNonNil(j.headerJarFile), | 
|  | 1208 | TransitiveLibsHeaderJars:       j.transitiveLibsHeaderJars, | 
|  | 1209 | TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars, | 
|  | 1210 | AidlIncludeDirs:                j.exportAidlIncludeDirs, | 
|  | 1211 | ExportedPlugins:                j.exportedPluginJars, | 
|  | 1212 | ExportedPluginClasses:          j.exportedPluginClasses, | 
|  | 1213 | ExportedPluginDisableTurbine:   j.exportedDisableTurbine, | 
|  | 1214 | }) | 
|  | 1215 |  | 
|  | 1216 | j.outputFile = j.headerJarFile | 
|  | 1217 | return | 
|  | 1218 | } | 
|  | 1219 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1220 | if srcFiles.HasExt(".kt") { | 
| Colin Cross | b5db401 | 2022-03-28 17:12:39 -0700 | [diff] [blame] | 1221 | // When using kotlin sources turbine is used to generate annotation processor sources, | 
|  | 1222 | // including for annotation processors that generate API, so we can use turbine for | 
|  | 1223 | // java sources too. | 
|  | 1224 | disableTurbine = false | 
|  | 1225 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1226 | // user defined kotlin flags. | 
|  | 1227 | kotlincFlags := j.properties.Kotlincflags | 
|  | 1228 | CheckKotlincFlags(ctx, kotlincFlags) | 
|  | 1229 |  | 
| Aurimas Liutikas | 24a987f | 2021-05-17 17:47:10 +0000 | [diff] [blame] | 1230 | // Workaround for KT-46512 | 
|  | 1231 | kotlincFlags = append(kotlincFlags, "-Xsam-conversions=class") | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1232 |  | 
|  | 1233 | // If there are kotlin files, compile them first but pass all the kotlin and java files | 
|  | 1234 | // kotlinc will use the java files to resolve types referenced by the kotlin files, but | 
|  | 1235 | // won't emit any classes for them. | 
|  | 1236 | kotlincFlags = append(kotlincFlags, "-no-stdlib") | 
|  | 1237 | if ctx.Device() { | 
|  | 1238 | kotlincFlags = append(kotlincFlags, "-no-jdk") | 
|  | 1239 | } | 
| Colin Cross | a1ff7c6 | 2021-09-17 14:11:52 -0700 | [diff] [blame] | 1240 |  | 
|  | 1241 | for _, plugin := range deps.kotlinPlugins { | 
|  | 1242 | kotlincFlags = append(kotlincFlags, "-Xplugin="+plugin.String()) | 
|  | 1243 | } | 
|  | 1244 | flags.kotlincDeps = append(flags.kotlincDeps, deps.kotlinPlugins...) | 
|  | 1245 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1246 | if len(kotlincFlags) > 0 { | 
|  | 1247 | // optimization. | 
|  | 1248 | ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " ")) | 
|  | 1249 | flags.kotlincFlags += "$kotlincFlags" | 
|  | 1250 | } | 
|  | 1251 |  | 
| Chaohui Wang | dcbe33c | 2022-10-11 11:13:30 +0800 | [diff] [blame] | 1252 | // Collect common .kt files for AIDEGen | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1253 | j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, kotlinCommonSrcFiles.Strings()...) | 
|  | 1254 |  | 
|  | 1255 | flags.classpath = append(flags.classpath, deps.kotlinStdlib...) | 
|  | 1256 | flags.classpath = append(flags.classpath, deps.kotlinAnnotations...) | 
|  | 1257 |  | 
|  | 1258 | flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...) | 
|  | 1259 | flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...) | 
|  | 1260 |  | 
| Isaac Chiou | a23d994 | 2022-04-06 06:14:38 +0000 | [diff] [blame] | 1261 | if len(flags.processorPath) > 0 { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1262 | // Use kapt for annotation processing | 
| Isaac Chiou | a23d994 | 2022-04-06 06:14:38 +0000 | [diff] [blame] | 1263 | kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar") | 
|  | 1264 | kaptResJar := android.PathForModuleOut(ctx, "kapt", "kapt-res.jar") | 
| Chaohui Wang | dcbe33c | 2022-10-11 11:13:30 +0800 | [diff] [blame] | 1265 | kotlinKapt(ctx, kaptSrcJar, kaptResJar, uniqueSrcFiles, kotlinCommonSrcFiles, srcJars, flags) | 
| Isaac Chiou | a23d994 | 2022-04-06 06:14:38 +0000 | [diff] [blame] | 1266 | srcJars = append(srcJars, kaptSrcJar) | 
|  | 1267 | kotlinJars = append(kotlinJars, kaptResJar) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1268 | // Disable annotation processing in javac, it's already been handled by kapt | 
|  | 1269 | flags.processorPath = nil | 
|  | 1270 | flags.processors = nil | 
|  | 1271 | } | 
|  | 1272 |  | 
|  | 1273 | kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName) | 
| Colin Cross | 220a9a1 | 2022-03-28 17:08:01 -0700 | [diff] [blame] | 1274 | kotlinHeaderJar := android.PathForModuleOut(ctx, "kotlin_headers", jarName) | 
| Chaohui Wang | dcbe33c | 2022-10-11 11:13:30 +0800 | [diff] [blame] | 1275 | kotlinCompile(ctx, kotlinJar, kotlinHeaderJar, uniqueSrcFiles, kotlinCommonSrcFiles, srcJars, flags) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1276 | if ctx.Failed() { | 
|  | 1277 | return | 
|  | 1278 | } | 
|  | 1279 |  | 
| Isaac Chiou | a23d994 | 2022-04-06 06:14:38 +0000 | [diff] [blame] | 1280 | // Make javac rule depend on the kotlinc rule | 
|  | 1281 | flags.classpath = append(classpath{kotlinHeaderJar}, flags.classpath...) | 
|  | 1282 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1283 | kotlinJars = append(kotlinJars, kotlinJar) | 
| Colin Cross | 220a9a1 | 2022-03-28 17:08:01 -0700 | [diff] [blame] | 1284 | kotlinHeaderJars = append(kotlinHeaderJars, kotlinHeaderJar) | 
|  | 1285 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1286 | // Jar kotlin classes into the final jar after javac | 
|  | 1287 | if BoolDefault(j.properties.Static_kotlin_stdlib, true) { | 
|  | 1288 | kotlinJars = append(kotlinJars, deps.kotlinStdlib...) | 
| Colin Cross | 0635447 | 2022-05-03 14:20:24 -0700 | [diff] [blame] | 1289 | kotlinJars = append(kotlinJars, deps.kotlinAnnotations...) | 
| Colin Cross | 220a9a1 | 2022-03-28 17:08:01 -0700 | [diff] [blame] | 1290 | kotlinHeaderJars = append(kotlinHeaderJars, deps.kotlinStdlib...) | 
| Colin Cross | 0635447 | 2022-05-03 14:20:24 -0700 | [diff] [blame] | 1291 | kotlinHeaderJars = append(kotlinHeaderJars, deps.kotlinAnnotations...) | 
| Colin Cross | 9bb9bfb | 2022-03-17 11:12:32 -0700 | [diff] [blame] | 1292 | } else { | 
|  | 1293 | flags.dexClasspath = append(flags.dexClasspath, deps.kotlinStdlib...) | 
| Colin Cross | 0635447 | 2022-05-03 14:20:24 -0700 | [diff] [blame] | 1294 | flags.dexClasspath = append(flags.dexClasspath, deps.kotlinAnnotations...) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1295 | } | 
|  | 1296 | } | 
|  | 1297 |  | 
|  | 1298 | jars := append(android.Paths(nil), kotlinJars...) | 
|  | 1299 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1300 | j.compiledSrcJars = srcJars | 
|  | 1301 |  | 
|  | 1302 | enableSharding := false | 
| Colin Cross | 3d56ed5 | 2021-11-18 22:23:12 -0800 | [diff] [blame] | 1303 | var headerJarFileWithoutDepsOrJarjar android.Path | 
| Colin Cross | b5db401 | 2022-03-28 17:12:39 -0700 | [diff] [blame] | 1304 | if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !disableTurbine { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1305 | if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 { | 
|  | 1306 | enableSharding = true | 
|  | 1307 | // Formerly, there was a check here that prevented annotation processors | 
|  | 1308 | // from being used when sharding was enabled, as some annotation processors | 
|  | 1309 | // do not function correctly in sharded environments. It was removed to | 
|  | 1310 | // allow for the use of annotation processors that do function correctly | 
|  | 1311 | // with sharding enabled. See: b/77284273. | 
|  | 1312 | } | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1313 | extraJars := append(android.CopyOf(extraCombinedJars), kotlinHeaderJars...) | 
| Colin Cross | 3d56ed5 | 2021-11-18 22:23:12 -0800 | [diff] [blame] | 1314 | headerJarFileWithoutDepsOrJarjar, j.headerJarFile = | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1315 | j.compileJavaHeader(ctx, uniqueJavaFiles, srcJars, deps, flags, jarName, extraJars) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1316 | if ctx.Failed() { | 
|  | 1317 | return | 
|  | 1318 | } | 
|  | 1319 | } | 
| Chaohui Wang | dcbe33c | 2022-10-11 11:13:30 +0800 | [diff] [blame] | 1320 | if len(uniqueJavaFiles) > 0 || len(srcJars) > 0 { | 
| Cole Faust | 2d516df | 2022-08-24 11:22:52 -0700 | [diff] [blame] | 1321 | hasErrorproneableFiles := false | 
|  | 1322 | for _, ext := range j.sourceExtensions { | 
|  | 1323 | if ext != ".proto" && ext != ".aidl" { | 
|  | 1324 | // Skip running errorprone on pure proto or pure aidl modules. Some modules take a long time to | 
|  | 1325 | // compile, and it's not useful to have warnings on these generated sources. | 
|  | 1326 | hasErrorproneableFiles = true | 
|  | 1327 | break | 
|  | 1328 | } | 
|  | 1329 | } | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1330 | var extraJarDeps android.Paths | 
| Cole Faust | 75fffb1 | 2021-06-13 15:23:16 -0700 | [diff] [blame] | 1331 | if Bool(j.properties.Errorprone.Enabled) { | 
|  | 1332 | // If error-prone is enabled, enable errorprone flags on the regular | 
|  | 1333 | // build. | 
|  | 1334 | flags = enableErrorproneFlags(flags) | 
| Cole Faust | 2d516df | 2022-08-24 11:22:52 -0700 | [diff] [blame] | 1335 | } else if hasErrorproneableFiles && ctx.Config().RunErrorProne() && j.properties.Errorprone.Enabled == nil { | 
| Cole Faust | 75fffb1 | 2021-06-13 15:23:16 -0700 | [diff] [blame] | 1336 | // Otherwise, if the RUN_ERROR_PRONE environment variable is set, create | 
|  | 1337 | // a new jar file just for compiling with the errorprone compiler to. | 
|  | 1338 | // This is because we don't want to cause the java files to get completely | 
|  | 1339 | // rebuilt every time the state of the RUN_ERROR_PRONE variable changes. | 
|  | 1340 | // We also don't want to run this if errorprone is enabled by default for | 
|  | 1341 | // this module, or else we could have duplicated errorprone messages. | 
|  | 1342 | errorproneFlags := enableErrorproneFlags(flags) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1343 | errorprone := android.PathForModuleOut(ctx, "errorprone", jarName) | 
| Vadim Spivak | 3c496f0 | 2023-06-08 06:14:59 +0000 | [diff] [blame] | 1344 | errorproneAnnoSrcJar := android.PathForModuleOut(ctx, "errorprone", "anno.srcjar") | 
| Cole Faust | 75fffb1 | 2021-06-13 15:23:16 -0700 | [diff] [blame] | 1345 |  | 
| Vadim Spivak | 3c496f0 | 2023-06-08 06:14:59 +0000 | [diff] [blame] | 1346 | transformJavaToClasses(ctx, errorprone, -1, uniqueJavaFiles, srcJars, errorproneAnnoSrcJar, errorproneFlags, nil, | 
| Cole Faust | 75fffb1 | 2021-06-13 15:23:16 -0700 | [diff] [blame] | 1347 | "errorprone", "errorprone") | 
|  | 1348 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1349 | extraJarDeps = append(extraJarDeps, errorprone) | 
|  | 1350 | } | 
|  | 1351 |  | 
|  | 1352 | if enableSharding { | 
| Colin Cross | 3d56ed5 | 2021-11-18 22:23:12 -0800 | [diff] [blame] | 1353 | if headerJarFileWithoutDepsOrJarjar != nil { | 
|  | 1354 | flags.classpath = append(classpath{headerJarFileWithoutDepsOrJarjar}, flags.classpath...) | 
|  | 1355 | } | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1356 | shardSize := int(*(j.properties.Javac_shard_size)) | 
|  | 1357 | var shardSrcs []android.Paths | 
| Chaohui Wang | dcbe33c | 2022-10-11 11:13:30 +0800 | [diff] [blame] | 1358 | if len(uniqueJavaFiles) > 0 { | 
|  | 1359 | shardSrcs = android.ShardPaths(uniqueJavaFiles, shardSize) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1360 | for idx, shardSrc := range shardSrcs { | 
|  | 1361 | classes := j.compileJavaClasses(ctx, jarName, idx, shardSrc, | 
|  | 1362 | nil, flags, extraJarDeps) | 
|  | 1363 | jars = append(jars, classes) | 
|  | 1364 | } | 
|  | 1365 | } | 
| Colin Cross | a052ddb | 2023-09-25 21:46:58 -0700 | [diff] [blame] | 1366 | // Assume approximately 5 sources per srcjar. | 
|  | 1367 | // For framework-minus-apex in AOSP at the time this was written, there are 266 srcjars, with a mean | 
|  | 1368 | // of 5.8 sources per srcjar, but a median of 1, a standard deviation of 10, and a max of 48 source files. | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1369 | if len(srcJars) > 0 { | 
| Colin Cross | a052ddb | 2023-09-25 21:46:58 -0700 | [diff] [blame] | 1370 | startIdx := len(shardSrcs) | 
|  | 1371 | shardSrcJarsList := android.ShardPaths(srcJars, shardSize/5) | 
|  | 1372 | for idx, shardSrcJars := range shardSrcJarsList { | 
|  | 1373 | classes := j.compileJavaClasses(ctx, jarName, startIdx+idx, | 
|  | 1374 | nil, shardSrcJars, flags, extraJarDeps) | 
|  | 1375 | jars = append(jars, classes) | 
|  | 1376 | } | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1377 | } | 
|  | 1378 | } else { | 
| Chaohui Wang | dcbe33c | 2022-10-11 11:13:30 +0800 | [diff] [blame] | 1379 | classes := j.compileJavaClasses(ctx, jarName, -1, uniqueJavaFiles, srcJars, flags, extraJarDeps) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1380 | jars = append(jars, classes) | 
|  | 1381 | } | 
|  | 1382 | if ctx.Failed() { | 
|  | 1383 | return | 
|  | 1384 | } | 
|  | 1385 | } | 
|  | 1386 |  | 
|  | 1387 | j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles | 
|  | 1388 |  | 
|  | 1389 | var includeSrcJar android.WritablePath | 
|  | 1390 | if Bool(j.properties.Include_srcs) { | 
|  | 1391 | includeSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+".srcjar") | 
|  | 1392 | TransformResourcesToJar(ctx, includeSrcJar, j.srcJarArgs, j.srcJarDeps) | 
|  | 1393 | } | 
|  | 1394 |  | 
|  | 1395 | dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, | 
|  | 1396 | j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources) | 
|  | 1397 | fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources) | 
|  | 1398 | extraArgs, extraDeps := resourcePathsToJarArgs(j.extraResources), j.extraResources | 
|  | 1399 |  | 
|  | 1400 | var resArgs []string | 
|  | 1401 | var resDeps android.Paths | 
|  | 1402 |  | 
|  | 1403 | resArgs = append(resArgs, dirArgs...) | 
|  | 1404 | resDeps = append(resDeps, dirDeps...) | 
|  | 1405 |  | 
|  | 1406 | resArgs = append(resArgs, fileArgs...) | 
|  | 1407 | resDeps = append(resDeps, fileDeps...) | 
|  | 1408 |  | 
|  | 1409 | resArgs = append(resArgs, extraArgs...) | 
|  | 1410 | resDeps = append(resDeps, extraDeps...) | 
|  | 1411 |  | 
|  | 1412 | if len(resArgs) > 0 { | 
|  | 1413 | resourceJar := android.PathForModuleOut(ctx, "res", jarName) | 
|  | 1414 | TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps) | 
|  | 1415 | j.resourceJar = resourceJar | 
|  | 1416 | if ctx.Failed() { | 
|  | 1417 | return | 
|  | 1418 | } | 
|  | 1419 | } | 
|  | 1420 |  | 
|  | 1421 | var resourceJars android.Paths | 
|  | 1422 | if j.resourceJar != nil { | 
|  | 1423 | resourceJars = append(resourceJars, j.resourceJar) | 
|  | 1424 | } | 
|  | 1425 | if Bool(j.properties.Include_srcs) { | 
|  | 1426 | resourceJars = append(resourceJars, includeSrcJar) | 
|  | 1427 | } | 
|  | 1428 | resourceJars = append(resourceJars, deps.staticResourceJars...) | 
|  | 1429 |  | 
|  | 1430 | if len(resourceJars) > 1 { | 
|  | 1431 | combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName) | 
|  | 1432 | TransformJarsToJar(ctx, combinedJar, "for resources", resourceJars, android.OptionalPath{}, | 
|  | 1433 | false, nil, nil) | 
|  | 1434 | j.resourceJar = combinedJar | 
|  | 1435 | } else if len(resourceJars) == 1 { | 
|  | 1436 | j.resourceJar = resourceJars[0] | 
|  | 1437 | } | 
|  | 1438 |  | 
|  | 1439 | if len(deps.staticJars) > 0 { | 
|  | 1440 | jars = append(jars, deps.staticJars...) | 
|  | 1441 | } | 
|  | 1442 |  | 
|  | 1443 | manifest := j.overrideManifest | 
|  | 1444 | if !manifest.Valid() && j.properties.Manifest != nil { | 
|  | 1445 | manifest = android.OptionalPathForPath(android.PathForModuleSrc(ctx, *j.properties.Manifest)) | 
|  | 1446 | } | 
|  | 1447 |  | 
|  | 1448 | services := android.PathsForModuleSrc(ctx, j.properties.Services) | 
|  | 1449 | if len(services) > 0 { | 
|  | 1450 | servicesJar := android.PathForModuleOut(ctx, "services", jarName) | 
|  | 1451 | var zipargs []string | 
|  | 1452 | for _, file := range services { | 
|  | 1453 | serviceFile := file.String() | 
|  | 1454 | zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile) | 
|  | 1455 | } | 
|  | 1456 | rule := zip | 
|  | 1457 | args := map[string]string{ | 
|  | 1458 | "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "), | 
|  | 1459 | } | 
|  | 1460 | if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_ZIP") { | 
|  | 1461 | rule = zipRE | 
|  | 1462 | args["implicits"] = strings.Join(services.Strings(), ",") | 
|  | 1463 | } | 
|  | 1464 | ctx.Build(pctx, android.BuildParams{ | 
|  | 1465 | Rule:      rule, | 
|  | 1466 | Output:    servicesJar, | 
|  | 1467 | Implicits: services, | 
|  | 1468 | Args:      args, | 
|  | 1469 | }) | 
|  | 1470 | jars = append(jars, servicesJar) | 
|  | 1471 | } | 
|  | 1472 |  | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1473 | jars = append(android.CopyOf(extraCombinedJars), jars...) | 
|  | 1474 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1475 | // Combine the classes built from sources, any manifests, and any static libraries into | 
|  | 1476 | // classes.jar. If there is only one input jar this step will be skipped. | 
|  | 1477 | var outputFile android.OutputPath | 
|  | 1478 |  | 
|  | 1479 | if len(jars) == 1 && !manifest.Valid() { | 
|  | 1480 | // Optimization: skip the combine step as there is nothing to do | 
|  | 1481 | // TODO(ccross): this leaves any module-info.class files, but those should only come from | 
|  | 1482 | // prebuilt dependencies until we support modules in the platform build, so there shouldn't be | 
|  | 1483 | // any if len(jars) == 1. | 
|  | 1484 |  | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 1485 | // moduleStubLinkType determines if the module is the TopLevelStubLibrary generated | 
|  | 1486 | // from sdk_library. The TopLevelStubLibrary contains only one static lib, | 
|  | 1487 | // either with .from-source or .from-text suffix. | 
|  | 1488 | // outputFile should be agnostic to the build configuration, | 
|  | 1489 | // thus "combine" the single static lib in order to prevent the static lib from being exposed | 
|  | 1490 | // to the copy rules. | 
|  | 1491 | stub, _ := moduleStubLinkType(ctx.ModuleName()) | 
|  | 1492 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1493 | // Transform the single path to the jar into an OutputPath as that is required by the following | 
|  | 1494 | // code. | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 1495 | if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok && !stub { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1496 | // The path contains an embedded OutputPath so reuse that. | 
|  | 1497 | outputFile = moduleOutPath.OutputPath | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 1498 | } else if outputPath, ok := jars[0].(android.OutputPath); ok && !stub { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1499 | // The path is an OutputPath so reuse it directly. | 
|  | 1500 | outputFile = outputPath | 
|  | 1501 | } else { | 
|  | 1502 | // The file is not in the out directory so create an OutputPath into which it can be copied | 
|  | 1503 | // and which the following code can use to refer to it. | 
|  | 1504 | combinedJar := android.PathForModuleOut(ctx, "combined", jarName) | 
|  | 1505 | ctx.Build(pctx, android.BuildParams{ | 
|  | 1506 | Rule:   android.Cp, | 
|  | 1507 | Input:  jars[0], | 
|  | 1508 | Output: combinedJar, | 
|  | 1509 | }) | 
|  | 1510 | outputFile = combinedJar.OutputPath | 
|  | 1511 | } | 
|  | 1512 | } else { | 
|  | 1513 | combinedJar := android.PathForModuleOut(ctx, "combined", jarName) | 
|  | 1514 | TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest, | 
|  | 1515 | false, nil, nil) | 
|  | 1516 | outputFile = combinedJar.OutputPath | 
|  | 1517 | } | 
|  | 1518 |  | 
|  | 1519 | // jarjar implementation jar if necessary | 
|  | 1520 | if j.expandJarjarRules != nil { | 
|  | 1521 | // Transform classes.jar into classes-jarjar.jar | 
|  | 1522 | jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName).OutputPath | 
|  | 1523 | TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules) | 
|  | 1524 | outputFile = jarjarFile | 
|  | 1525 |  | 
|  | 1526 | // jarjar resource jar if necessary | 
|  | 1527 | if j.resourceJar != nil { | 
|  | 1528 | resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName) | 
|  | 1529 | TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules) | 
|  | 1530 | j.resourceJar = resourceJarJarFile | 
|  | 1531 | } | 
|  | 1532 |  | 
|  | 1533 | if ctx.Failed() { | 
|  | 1534 | return | 
|  | 1535 | } | 
|  | 1536 | } | 
|  | 1537 |  | 
|  | 1538 | // Check package restrictions if necessary. | 
|  | 1539 | if len(j.properties.Permitted_packages) > 0 { | 
| Paul Duffin | 08a18bf | 2021-10-01 13:19:58 +0100 | [diff] [blame] | 1540 | // Time stamp file created by the package check rule. | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1541 | pkgckFile := android.PathForModuleOut(ctx, "package-check.stamp") | 
| Paul Duffin | 08a18bf | 2021-10-01 13:19:58 +0100 | [diff] [blame] | 1542 |  | 
|  | 1543 | // Create a rule to copy the output jar to another path and add a validate dependency that | 
|  | 1544 | // will check that the jar only contains the permitted packages. The new location will become | 
|  | 1545 | // the output file of this module. | 
|  | 1546 | inputFile := outputFile | 
|  | 1547 | outputFile = android.PathForModuleOut(ctx, "package-check", jarName).OutputPath | 
|  | 1548 | ctx.Build(pctx, android.BuildParams{ | 
|  | 1549 | Rule:   android.Cp, | 
|  | 1550 | Input:  inputFile, | 
|  | 1551 | Output: outputFile, | 
|  | 1552 | // Make sure that any dependency on the output file will cause ninja to run the package check | 
|  | 1553 | // rule. | 
|  | 1554 | Validation: pkgckFile, | 
|  | 1555 | }) | 
|  | 1556 |  | 
|  | 1557 | // Check packages and create a timestamp file when complete. | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1558 | CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1559 |  | 
|  | 1560 | if ctx.Failed() { | 
|  | 1561 | return | 
|  | 1562 | } | 
|  | 1563 | } | 
|  | 1564 |  | 
|  | 1565 | j.implementationJarFile = outputFile | 
|  | 1566 | if j.headerJarFile == nil { | 
| Colin Cross | f06d8dc | 2023-07-18 22:11:07 -0700 | [diff] [blame] | 1567 | // If this module couldn't generate a header jar (for example due to api generating annotation processors) | 
|  | 1568 | // then use the implementation jar.  Run it through zip2zip first to remove any files in META-INF/services | 
|  | 1569 | // so that javac on modules that depend on this module don't pick up annotation processors (which may be | 
|  | 1570 | // missing their implementations) from META-INF/services/javax.annotation.processing.Processor. | 
|  | 1571 | headerJarFile := android.PathForModuleOut(ctx, "javac-header", jarName) | 
|  | 1572 | convertImplementationJarToHeaderJar(ctx, j.implementationJarFile, headerJarFile) | 
|  | 1573 | j.headerJarFile = headerJarFile | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1574 | } | 
|  | 1575 |  | 
| Yuntao Xu | 5b009ae | 2021-05-13 12:42:24 -0700 | [diff] [blame] | 1576 | // enforce syntax check to jacoco filters for any build (http://b/183622051) | 
|  | 1577 | specs := j.jacocoModuleToZipCommand(ctx) | 
|  | 1578 | if ctx.Failed() { | 
|  | 1579 | return | 
|  | 1580 | } | 
|  | 1581 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1582 | if j.shouldInstrument(ctx) { | 
| Yuntao Xu | 5b009ae | 2021-05-13 12:42:24 -0700 | [diff] [blame] | 1583 | outputFile = j.instrument(ctx, flags, outputFile, jarName, specs) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1584 | } | 
|  | 1585 |  | 
|  | 1586 | // merge implementation jar with resources if necessary | 
|  | 1587 | implementationAndResourcesJar := outputFile | 
|  | 1588 | if j.resourceJar != nil { | 
|  | 1589 | jars := android.Paths{j.resourceJar, implementationAndResourcesJar} | 
|  | 1590 | combinedJar := android.PathForModuleOut(ctx, "withres", jarName).OutputPath | 
|  | 1591 | TransformJarsToJar(ctx, combinedJar, "for resources", jars, manifest, | 
|  | 1592 | false, nil, nil) | 
|  | 1593 | implementationAndResourcesJar = combinedJar | 
|  | 1594 | } | 
|  | 1595 |  | 
|  | 1596 | j.implementationAndResourcesJar = implementationAndResourcesJar | 
|  | 1597 |  | 
|  | 1598 | // Enable dex compilation for the APEX variants, unless it is disabled explicitly | 
| Paul Duffin | e7b1f5b | 2022-06-29 10:15:52 +0000 | [diff] [blame] | 1599 | compileDex := j.dexProperties.Compile_dex | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1600 | apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) | 
|  | 1601 | if j.DirectlyInAnyApex() && !apexInfo.IsForPlatform() { | 
| Paul Duffin | e7b1f5b | 2022-06-29 10:15:52 +0000 | [diff] [blame] | 1602 | if compileDex == nil { | 
|  | 1603 | compileDex = proptools.BoolPtr(true) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1604 | } | 
|  | 1605 | if j.deviceProperties.Hostdex == nil { | 
|  | 1606 | j.deviceProperties.Hostdex = proptools.BoolPtr(true) | 
|  | 1607 | } | 
|  | 1608 | } | 
|  | 1609 |  | 
| Paul Duffin | e7b1f5b | 2022-06-29 10:15:52 +0000 | [diff] [blame] | 1610 | if ctx.Device() && (Bool(j.properties.Installable) || Bool(compileDex)) { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1611 | if j.hasCode(ctx) { | 
|  | 1612 | if j.shouldInstrumentStatic(ctx) { | 
|  | 1613 | j.dexer.extraProguardFlagFiles = append(j.dexer.extraProguardFlagFiles, | 
|  | 1614 | android.PathForSource(ctx, "build/make/core/proguard.jacoco.flags")) | 
|  | 1615 | } | 
|  | 1616 | // Dex compilation | 
|  | 1617 | var dexOutputFile android.OutputPath | 
| Spandan Das | c404cc7 | 2023-02-23 18:05:05 +0000 | [diff] [blame] | 1618 | params := &compileDexParams{ | 
|  | 1619 | flags:         flags, | 
|  | 1620 | sdkVersion:    j.SdkVersion(ctx), | 
|  | 1621 | minSdkVersion: j.MinSdkVersion(ctx), | 
|  | 1622 | classesJar:    implementationAndResourcesJar, | 
|  | 1623 | jarName:       jarName, | 
|  | 1624 | } | 
|  | 1625 | dexOutputFile = j.dexer.compileDex(ctx, params) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1626 | if ctx.Failed() { | 
|  | 1627 | return | 
|  | 1628 | } | 
|  | 1629 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1630 | // merge dex jar with resources if necessary | 
|  | 1631 | if j.resourceJar != nil { | 
|  | 1632 | jars := android.Paths{dexOutputFile, j.resourceJar} | 
|  | 1633 | combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName).OutputPath | 
|  | 1634 | TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{}, | 
|  | 1635 | false, nil, nil) | 
|  | 1636 | if *j.dexProperties.Uncompress_dex { | 
|  | 1637 | combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName).OutputPath | 
| Cole Faust | 51d7bfd | 2023-09-07 05:31:32 +0000 | [diff] [blame] | 1638 | TransformZipAlign(ctx, combinedAlignedJar, combinedJar, nil) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1639 | dexOutputFile = combinedAlignedJar | 
|  | 1640 | } else { | 
|  | 1641 | dexOutputFile = combinedJar | 
|  | 1642 | } | 
|  | 1643 | } | 
|  | 1644 |  | 
| Paul Duffin | 4de9450 | 2021-05-16 05:21:16 +0100 | [diff] [blame] | 1645 | // Initialize the hiddenapi structure. | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1646 |  | 
|  | 1647 | j.initHiddenAPI(ctx, makeDexJarPathFromPath(dexOutputFile), j.implementationJarFile, j.dexProperties.Uncompress_dex) | 
| Paul Duffin | 4de9450 | 2021-05-16 05:21:16 +0100 | [diff] [blame] | 1648 |  | 
|  | 1649 | // Encode hidden API flags in dex file, if needed. | 
|  | 1650 | dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile) | 
|  | 1651 |  | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1652 | j.dexJarFile = makeDexJarPathFromPath(dexOutputFile) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1653 |  | 
|  | 1654 | // Dexpreopting | 
|  | 1655 | j.dexpreopt(ctx, dexOutputFile) | 
|  | 1656 |  | 
|  | 1657 | outputFile = dexOutputFile | 
|  | 1658 | } else { | 
|  | 1659 | // There is no code to compile into a dex jar, make sure the resources are propagated | 
|  | 1660 | // to the APK if this is an app. | 
|  | 1661 | outputFile = implementationAndResourcesJar | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1662 | j.dexJarFile = makeDexJarPathFromPath(j.resourceJar) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1663 | } | 
|  | 1664 |  | 
|  | 1665 | if ctx.Failed() { | 
|  | 1666 | return | 
|  | 1667 | } | 
|  | 1668 | } else { | 
|  | 1669 | outputFile = implementationAndResourcesJar | 
|  | 1670 | } | 
|  | 1671 |  | 
|  | 1672 | if ctx.Device() { | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 1673 | lintSDKVersion := func(apiLevel android.ApiLevel) int { | 
|  | 1674 | if !apiLevel.IsPreview() { | 
|  | 1675 | return apiLevel.FinalInt() | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1676 | } else { | 
| Cole Faust | e5bf3fb | 2022-07-01 19:39:14 +0000 | [diff] [blame] | 1677 | // When running metalava, we pass --version-codename. When that value | 
|  | 1678 | // is not REL, metalava will add 1 to the --current-version argument. | 
|  | 1679 | // On old branches, PLATFORM_SDK_VERSION is the latest version (for that | 
|  | 1680 | // branch) and the codename is REL, except potentially on the most | 
|  | 1681 | // recent non-master branch. On that branch, it goes through two other | 
|  | 1682 | // phases before it gets to the phase previously described: | 
|  | 1683 | //  - PLATFORM_SDK_VERSION has not been updated yet, and the codename | 
|  | 1684 | //    is not rel. This happens for most of the internal branch's life | 
|  | 1685 | //    while the branch has been cut but is still under active development. | 
|  | 1686 | //  - PLATFORM_SDK_VERSION has been set, but the codename is still not | 
|  | 1687 | //    REL. This happens briefly during the release process. During this | 
|  | 1688 | //    state the code to add --current-version is commented out, and then | 
|  | 1689 | //    that commenting out is reverted after the codename is set to REL. | 
|  | 1690 | // On the master branch, the PLATFORM_SDK_VERSION always represents a | 
|  | 1691 | // prior version and the codename is always non-REL. | 
|  | 1692 | // | 
|  | 1693 | // We need to add one here to match metalava adding 1. Technically | 
|  | 1694 | // this means that in the state described in the second bullet point | 
|  | 1695 | // above, this number is 1 higher than it should be. | 
|  | 1696 | return ctx.Config().PlatformSdkVersion().FinalInt() + 1 | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1697 | } | 
|  | 1698 | } | 
|  | 1699 |  | 
|  | 1700 | j.linter.name = ctx.ModuleName() | 
| Thiébaud Weksteen | 5c26f81 | 2022-05-05 14:49:02 +1000 | [diff] [blame] | 1701 | j.linter.srcs = append(srcFiles, nonGeneratedSrcJars...) | 
|  | 1702 | j.linter.srcJars, _ = android.FilterPathList(srcJars, nonGeneratedSrcJars) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1703 | j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...) | 
|  | 1704 | j.linter.classes = j.implementationJarFile | 
| Spandan Das | ba7e532 | 2022-04-22 17:28:25 +0000 | [diff] [blame] | 1705 | j.linter.minSdkVersion = lintSDKVersion(j.MinSdkVersion(ctx)) | 
| Spandan Das | ca70fc4 | 2023-03-01 23:38:49 +0000 | [diff] [blame] | 1706 | j.linter.targetSdkVersion = lintSDKVersion(j.TargetSdkVersion(ctx)) | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 1707 | j.linter.compileSdkVersion = lintSDKVersion(j.SdkVersion(ctx).ApiLevel) | 
| Pedro Loureiro | 18233a2 | 2021-06-08 18:11:21 +0000 | [diff] [blame] | 1708 | j.linter.compileSdkKind = j.SdkVersion(ctx).Kind | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1709 | j.linter.javaLanguageLevel = flags.javaVersion.String() | 
|  | 1710 | j.linter.kotlinLanguageLevel = "1.3" | 
|  | 1711 | if !apexInfo.IsForPlatform() && ctx.Config().UnbundledBuildApps() { | 
|  | 1712 | j.linter.buildModuleReportZip = true | 
|  | 1713 | } | 
|  | 1714 | j.linter.lint(ctx) | 
|  | 1715 | } | 
|  | 1716 |  | 
| Anton Hansson | 0e73f9e | 2023-09-20 13:39:57 +0000 | [diff] [blame] | 1717 | j.collectTransitiveSrcFiles(ctx, srcFiles) | 
|  | 1718 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1719 | ctx.CheckbuildFile(outputFile) | 
|  | 1720 |  | 
| Joe Onorato | 6fe59eb | 2023-07-16 13:20:33 -0700 | [diff] [blame] | 1721 | j.collectTransitiveAconfigFiles(ctx) | 
|  | 1722 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1723 | ctx.SetProvider(JavaInfoProvider, JavaInfo{ | 
|  | 1724 | HeaderJars:                     android.PathsIfNonNil(j.headerJarFile), | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 1725 | TransitiveLibsHeaderJars:       j.transitiveLibsHeaderJars, | 
|  | 1726 | TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars, | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1727 | ImplementationAndResourcesJars: android.PathsIfNonNil(j.implementationAndResourcesJar), | 
|  | 1728 | ImplementationJars:             android.PathsIfNonNil(j.implementationJarFile), | 
|  | 1729 | ResourceJars:                   android.PathsIfNonNil(j.resourceJar), | 
|  | 1730 | AidlIncludeDirs:                j.exportAidlIncludeDirs, | 
|  | 1731 | SrcJarArgs:                     j.srcJarArgs, | 
|  | 1732 | SrcJarDeps:                     j.srcJarDeps, | 
| Anton Hansson | 0e73f9e | 2023-09-20 13:39:57 +0000 | [diff] [blame] | 1733 | TransitiveSrcFiles:             j.transitiveSrcFiles, | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1734 | ExportedPlugins:                j.exportedPluginJars, | 
|  | 1735 | ExportedPluginClasses:          j.exportedPluginClasses, | 
|  | 1736 | ExportedPluginDisableTurbine:   j.exportedDisableTurbine, | 
|  | 1737 | JacocoReportClassesFile:        j.jacocoReportClassesFile, | 
| Joe Onorato | 6fe59eb | 2023-07-16 13:20:33 -0700 | [diff] [blame] | 1738 | TransitiveAconfigFiles:         j.transitiveAconfigFiles, | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1739 | }) | 
|  | 1740 |  | 
|  | 1741 | // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource | 
|  | 1742 | j.outputFile = outputFile.WithoutRel() | 
|  | 1743 | } | 
|  | 1744 |  | 
| Colin Cross | a1ff7c6 | 2021-09-17 14:11:52 -0700 | [diff] [blame] | 1745 | func (j *Module) useCompose() bool { | 
|  | 1746 | return android.InList("androidx.compose.runtime_runtime", j.properties.Static_libs) | 
|  | 1747 | } | 
|  | 1748 |  | 
| Sam Delmerico | 95d7094 | 2023-08-02 18:00:35 -0400 | [diff] [blame] | 1749 | func (j *Module) collectProguardSpecInfo(ctx android.ModuleContext) ProguardSpecInfo { | 
|  | 1750 | transitiveUnconditionalExportedFlags := []*android.DepSet[android.Path]{} | 
|  | 1751 | transitiveProguardFlags := []*android.DepSet[android.Path]{} | 
|  | 1752 |  | 
|  | 1753 | ctx.VisitDirectDeps(func(m android.Module) { | 
|  | 1754 | depProguardInfo := ctx.OtherModuleProvider(m, ProguardSpecInfoProvider).(ProguardSpecInfo) | 
|  | 1755 | depTag := ctx.OtherModuleDependencyTag(m) | 
|  | 1756 |  | 
|  | 1757 | if depProguardInfo.UnconditionallyExportedProguardFlags != nil { | 
|  | 1758 | transitiveUnconditionalExportedFlags = append(transitiveUnconditionalExportedFlags, depProguardInfo.UnconditionallyExportedProguardFlags) | 
|  | 1759 | transitiveProguardFlags = append(transitiveProguardFlags, depProguardInfo.UnconditionallyExportedProguardFlags) | 
|  | 1760 | } | 
|  | 1761 |  | 
|  | 1762 | if depTag == staticLibTag && depProguardInfo.ProguardFlagsFiles != nil { | 
|  | 1763 | transitiveProguardFlags = append(transitiveProguardFlags, depProguardInfo.ProguardFlagsFiles) | 
|  | 1764 | } | 
|  | 1765 | }) | 
|  | 1766 |  | 
|  | 1767 | directUnconditionalExportedFlags := android.Paths{} | 
|  | 1768 | proguardFlagsForThisModule := android.PathsForModuleSrc(ctx, j.dexProperties.Optimize.Proguard_flags_files) | 
|  | 1769 | exportUnconditionally := proptools.Bool(j.dexProperties.Optimize.Export_proguard_flags_files) | 
|  | 1770 | if exportUnconditionally { | 
|  | 1771 | // if we explicitly export, then our unconditional exports are the same as our transitive flags | 
|  | 1772 | transitiveUnconditionalExportedFlags = transitiveProguardFlags | 
|  | 1773 | directUnconditionalExportedFlags = proguardFlagsForThisModule | 
|  | 1774 | } | 
|  | 1775 |  | 
|  | 1776 | return ProguardSpecInfo{ | 
|  | 1777 | Export_proguard_flags_files: exportUnconditionally, | 
|  | 1778 | ProguardFlagsFiles: android.NewDepSet[android.Path]( | 
|  | 1779 | android.POSTORDER, | 
|  | 1780 | proguardFlagsForThisModule, | 
|  | 1781 | transitiveProguardFlags, | 
|  | 1782 | ), | 
|  | 1783 | UnconditionallyExportedProguardFlags: android.NewDepSet[android.Path]( | 
|  | 1784 | android.POSTORDER, | 
|  | 1785 | directUnconditionalExportedFlags, | 
|  | 1786 | transitiveUnconditionalExportedFlags, | 
|  | 1787 | ), | 
|  | 1788 | } | 
|  | 1789 |  | 
|  | 1790 | } | 
|  | 1791 |  | 
| Cole Faust | 75fffb1 | 2021-06-13 15:23:16 -0700 | [diff] [blame] | 1792 | // Returns a copy of the supplied flags, but with all the errorprone-related | 
|  | 1793 | // fields copied to the regular build's fields. | 
|  | 1794 | func enableErrorproneFlags(flags javaBuilderFlags) javaBuilderFlags { | 
|  | 1795 | flags.processorPath = append(flags.errorProneProcessorPath, flags.processorPath...) | 
|  | 1796 |  | 
|  | 1797 | if len(flags.errorProneExtraJavacFlags) > 0 { | 
|  | 1798 | if len(flags.javacFlags) > 0 { | 
|  | 1799 | flags.javacFlags += " " + flags.errorProneExtraJavacFlags | 
|  | 1800 | } else { | 
|  | 1801 | flags.javacFlags = flags.errorProneExtraJavacFlags | 
|  | 1802 | } | 
|  | 1803 | } | 
|  | 1804 | return flags | 
|  | 1805 | } | 
|  | 1806 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1807 | func (j *Module) compileJavaClasses(ctx android.ModuleContext, jarName string, idx int, | 
|  | 1808 | srcFiles, srcJars android.Paths, flags javaBuilderFlags, extraJarDeps android.Paths) android.WritablePath { | 
|  | 1809 |  | 
|  | 1810 | kzipName := pathtools.ReplaceExtension(jarName, "kzip") | 
| Vadim Spivak | 3c496f0 | 2023-06-08 06:14:59 +0000 | [diff] [blame] | 1811 | annoSrcJar := android.PathForModuleOut(ctx, "javac", "anno.srcjar") | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1812 | if idx >= 0 { | 
|  | 1813 | kzipName = strings.TrimSuffix(jarName, filepath.Ext(jarName)) + strconv.Itoa(idx) + ".kzip" | 
| Vadim Spivak | 3c496f0 | 2023-06-08 06:14:59 +0000 | [diff] [blame] | 1814 | annoSrcJar = android.PathForModuleOut(ctx, "javac", "anno-"+strconv.Itoa(idx)+".srcjar") | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1815 | jarName += strconv.Itoa(idx) | 
|  | 1816 | } | 
|  | 1817 |  | 
|  | 1818 | classes := android.PathForModuleOut(ctx, "javac", jarName).OutputPath | 
| Vadim Spivak | 3c496f0 | 2023-06-08 06:14:59 +0000 | [diff] [blame] | 1819 | TransformJavaToClasses(ctx, classes, idx, srcFiles, srcJars, annoSrcJar, flags, extraJarDeps) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1820 |  | 
|  | 1821 | if ctx.Config().EmitXrefRules() { | 
|  | 1822 | extractionFile := android.PathForModuleOut(ctx, kzipName) | 
|  | 1823 | emitXrefRule(ctx, extractionFile, idx, srcFiles, srcJars, flags, extraJarDeps) | 
|  | 1824 | j.kytheFiles = append(j.kytheFiles, extractionFile) | 
|  | 1825 | } | 
|  | 1826 |  | 
| Vadim Spivak | 3c496f0 | 2023-06-08 06:14:59 +0000 | [diff] [blame] | 1827 | if len(flags.processorPath) > 0 { | 
|  | 1828 | j.annoSrcJars = append(j.annoSrcJars, annoSrcJar) | 
|  | 1829 | } | 
|  | 1830 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1831 | return classes | 
|  | 1832 | } | 
|  | 1833 |  | 
|  | 1834 | // Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user, | 
|  | 1835 | // since some of these flags may be used internally. | 
|  | 1836 | func CheckKotlincFlags(ctx android.ModuleContext, flags []string) { | 
|  | 1837 | for _, flag := range flags { | 
|  | 1838 | flag = strings.TrimSpace(flag) | 
|  | 1839 |  | 
|  | 1840 | if !strings.HasPrefix(flag, "-") { | 
|  | 1841 | ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag) | 
|  | 1842 | } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") { | 
|  | 1843 | ctx.PropertyErrorf("kotlincflags", | 
|  | 1844 | "Bad flag: `%s`, only use internal compiler for consistency.", flag) | 
|  | 1845 | } else if inList(flag, config.KotlincIllegalFlags) { | 
|  | 1846 | ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag) | 
|  | 1847 | } else if flag == "-include-runtime" { | 
|  | 1848 | ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag) | 
|  | 1849 | } else { | 
|  | 1850 | args := strings.Split(flag, " ") | 
|  | 1851 | if args[0] == "-kotlin-home" { | 
|  | 1852 | ctx.PropertyErrorf("kotlincflags", | 
|  | 1853 | "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag) | 
|  | 1854 | } | 
|  | 1855 | } | 
|  | 1856 | } | 
|  | 1857 | } | 
|  | 1858 |  | 
|  | 1859 | func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths, | 
|  | 1860 | deps deps, flags javaBuilderFlags, jarName string, | 
| Colin Cross | 3d56ed5 | 2021-11-18 22:23:12 -0800 | [diff] [blame] | 1861 | extraJars android.Paths) (headerJar, jarjarAndDepsHeaderJar android.Path) { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1862 |  | 
|  | 1863 | var jars android.Paths | 
|  | 1864 | if len(srcFiles) > 0 || len(srcJars) > 0 { | 
|  | 1865 | // Compile java sources into turbine.jar. | 
|  | 1866 | turbineJar := android.PathForModuleOut(ctx, "turbine", jarName) | 
|  | 1867 | TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags) | 
|  | 1868 | if ctx.Failed() { | 
|  | 1869 | return nil, nil | 
|  | 1870 | } | 
|  | 1871 | jars = append(jars, turbineJar) | 
| Colin Cross | 3d56ed5 | 2021-11-18 22:23:12 -0800 | [diff] [blame] | 1872 | headerJar = turbineJar | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1873 | } | 
|  | 1874 |  | 
|  | 1875 | jars = append(jars, extraJars...) | 
|  | 1876 |  | 
|  | 1877 | // Combine any static header libraries into classes-header.jar. If there is only | 
|  | 1878 | // one input jar this step will be skipped. | 
|  | 1879 | jars = append(jars, deps.staticHeaderJars...) | 
|  | 1880 |  | 
|  | 1881 | // we cannot skip the combine step for now if there is only one jar | 
|  | 1882 | // since we have to strip META-INF/TRANSITIVE dir from turbine.jar | 
|  | 1883 | combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName) | 
|  | 1884 | TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, | 
|  | 1885 | false, nil, []string{"META-INF/TRANSITIVE"}) | 
| Colin Cross | 3d56ed5 | 2021-11-18 22:23:12 -0800 | [diff] [blame] | 1886 | jarjarAndDepsHeaderJar = combinedJar | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1887 |  | 
|  | 1888 | if j.expandJarjarRules != nil { | 
|  | 1889 | // Transform classes.jar into classes-jarjar.jar | 
|  | 1890 | jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName) | 
| Colin Cross | 3d56ed5 | 2021-11-18 22:23:12 -0800 | [diff] [blame] | 1891 | TransformJarJar(ctx, jarjarFile, jarjarAndDepsHeaderJar, j.expandJarjarRules) | 
|  | 1892 | jarjarAndDepsHeaderJar = jarjarFile | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1893 | if ctx.Failed() { | 
|  | 1894 | return nil, nil | 
|  | 1895 | } | 
|  | 1896 | } | 
|  | 1897 |  | 
| Colin Cross | 3d56ed5 | 2021-11-18 22:23:12 -0800 | [diff] [blame] | 1898 | return headerJar, jarjarAndDepsHeaderJar | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1899 | } | 
|  | 1900 |  | 
|  | 1901 | func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags, | 
| Yuntao Xu | 5b009ae | 2021-05-13 12:42:24 -0700 | [diff] [blame] | 1902 | classesJar android.Path, jarName string, specs string) android.OutputPath { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1903 |  | 
|  | 1904 | jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName) | 
|  | 1905 | instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName).OutputPath | 
|  | 1906 |  | 
|  | 1907 | jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs) | 
|  | 1908 |  | 
|  | 1909 | j.jacocoReportClassesFile = jacocoReportClassesFile | 
|  | 1910 |  | 
|  | 1911 | return instrumentedJar | 
|  | 1912 | } | 
|  | 1913 |  | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 1914 | type providesTransitiveHeaderJars struct { | 
|  | 1915 | // set of header jars for all transitive libs deps | 
| Colin Cross | c85750b | 2022-04-21 12:50:51 -0700 | [diff] [blame] | 1916 | transitiveLibsHeaderJars *android.DepSet[android.Path] | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 1917 | // set of header jars for all transitive static libs deps | 
| Colin Cross | c85750b | 2022-04-21 12:50:51 -0700 | [diff] [blame] | 1918 | transitiveStaticLibsHeaderJars *android.DepSet[android.Path] | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 1919 | } | 
|  | 1920 |  | 
| Colin Cross | c85750b | 2022-04-21 12:50:51 -0700 | [diff] [blame] | 1921 | func (j *providesTransitiveHeaderJars) TransitiveLibsHeaderJars() *android.DepSet[android.Path] { | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 1922 | return j.transitiveLibsHeaderJars | 
|  | 1923 | } | 
|  | 1924 |  | 
| Colin Cross | c85750b | 2022-04-21 12:50:51 -0700 | [diff] [blame] | 1925 | func (j *providesTransitiveHeaderJars) TransitiveStaticLibsHeaderJars() *android.DepSet[android.Path] { | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 1926 | return j.transitiveStaticLibsHeaderJars | 
|  | 1927 | } | 
|  | 1928 |  | 
|  | 1929 | func (j *providesTransitiveHeaderJars) collectTransitiveHeaderJars(ctx android.ModuleContext) { | 
|  | 1930 | directLibs := android.Paths{} | 
|  | 1931 | directStaticLibs := android.Paths{} | 
| Colin Cross | c85750b | 2022-04-21 12:50:51 -0700 | [diff] [blame] | 1932 | transitiveLibs := []*android.DepSet[android.Path]{} | 
|  | 1933 | transitiveStaticLibs := []*android.DepSet[android.Path]{} | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 1934 | ctx.VisitDirectDeps(func(module android.Module) { | 
|  | 1935 | // don't add deps of the prebuilt version of the same library | 
|  | 1936 | if ctx.ModuleName() == android.RemoveOptionalPrebuiltPrefix(module.Name()) { | 
|  | 1937 | return | 
|  | 1938 | } | 
|  | 1939 |  | 
|  | 1940 | dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo) | 
|  | 1941 | if dep.TransitiveLibsHeaderJars != nil { | 
|  | 1942 | transitiveLibs = append(transitiveLibs, dep.TransitiveLibsHeaderJars) | 
|  | 1943 | } | 
|  | 1944 | if dep.TransitiveStaticLibsHeaderJars != nil { | 
|  | 1945 | transitiveStaticLibs = append(transitiveStaticLibs, dep.TransitiveStaticLibsHeaderJars) | 
|  | 1946 | } | 
|  | 1947 |  | 
|  | 1948 | tag := ctx.OtherModuleDependencyTag(module) | 
|  | 1949 | _, isUsesLibDep := tag.(usesLibraryDependencyTag) | 
|  | 1950 | if tag == libTag || tag == r8LibraryJarTag || isUsesLibDep { | 
|  | 1951 | directLibs = append(directLibs, dep.HeaderJars...) | 
|  | 1952 | } else if tag == staticLibTag { | 
|  | 1953 | directStaticLibs = append(directStaticLibs, dep.HeaderJars...) | 
|  | 1954 | } | 
|  | 1955 | }) | 
|  | 1956 | j.transitiveLibsHeaderJars = android.NewDepSet(android.POSTORDER, directLibs, transitiveLibs) | 
|  | 1957 | j.transitiveStaticLibsHeaderJars = android.NewDepSet(android.POSTORDER, directStaticLibs, transitiveStaticLibs) | 
|  | 1958 | } | 
|  | 1959 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1960 | func (j *Module) HeaderJars() android.Paths { | 
|  | 1961 | if j.headerJarFile == nil { | 
|  | 1962 | return nil | 
|  | 1963 | } | 
|  | 1964 | return android.Paths{j.headerJarFile} | 
|  | 1965 | } | 
|  | 1966 |  | 
|  | 1967 | func (j *Module) ImplementationJars() android.Paths { | 
|  | 1968 | if j.implementationJarFile == nil { | 
|  | 1969 | return nil | 
|  | 1970 | } | 
|  | 1971 | return android.Paths{j.implementationJarFile} | 
|  | 1972 | } | 
|  | 1973 |  | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1974 | func (j *Module) DexJarBuildPath() OptionalDexJarPath { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 1975 | return j.dexJarFile | 
|  | 1976 | } | 
|  | 1977 |  | 
|  | 1978 | func (j *Module) DexJarInstallPath() android.Path { | 
|  | 1979 | return j.installFile | 
|  | 1980 | } | 
|  | 1981 |  | 
|  | 1982 | func (j *Module) ImplementationAndResourcesJars() android.Paths { | 
|  | 1983 | if j.implementationAndResourcesJar == nil { | 
|  | 1984 | return nil | 
|  | 1985 | } | 
|  | 1986 | return android.Paths{j.implementationAndResourcesJar} | 
|  | 1987 | } | 
|  | 1988 |  | 
|  | 1989 | func (j *Module) AidlIncludeDirs() android.Paths { | 
|  | 1990 | // exportAidlIncludeDirs is type android.Paths already | 
|  | 1991 | return j.exportAidlIncludeDirs | 
|  | 1992 | } | 
|  | 1993 |  | 
|  | 1994 | func (j *Module) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { | 
|  | 1995 | return j.classLoaderContexts | 
|  | 1996 | } | 
|  | 1997 |  | 
|  | 1998 | // Collect information for opening IDE project files in java/jdeps.go. | 
|  | 1999 | func (j *Module) IDEInfo(dpInfo *android.IdeInfo) { | 
|  | 2000 | dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...) | 
|  | 2001 | dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...) | 
|  | 2002 | dpInfo.SrcJars = append(dpInfo.SrcJars, j.compiledSrcJars.Strings()...) | 
|  | 2003 | dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...) | 
|  | 2004 | if j.expandJarjarRules != nil { | 
|  | 2005 | dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String()) | 
|  | 2006 | } | 
|  | 2007 | dpInfo.Paths = append(dpInfo.Paths, j.modulePaths...) | 
| Yike | f628202 | 2022-04-13 20:41:01 +0800 | [diff] [blame] | 2008 | dpInfo.Static_libs = append(dpInfo.Static_libs, j.properties.Static_libs...) | 
|  | 2009 | dpInfo.Libs = append(dpInfo.Libs, j.properties.Libs...) | 
| Vadim Spivak | 3c496f0 | 2023-06-08 06:14:59 +0000 | [diff] [blame] | 2010 | dpInfo.SrcJars = append(dpInfo.SrcJars, j.annoSrcJars.Strings()...) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2011 | } | 
|  | 2012 |  | 
|  | 2013 | func (j *Module) CompilerDeps() []string { | 
|  | 2014 | jdeps := []string{} | 
|  | 2015 | jdeps = append(jdeps, j.properties.Libs...) | 
|  | 2016 | jdeps = append(jdeps, j.properties.Static_libs...) | 
|  | 2017 | return jdeps | 
|  | 2018 | } | 
|  | 2019 |  | 
|  | 2020 | func (j *Module) hasCode(ctx android.ModuleContext) bool { | 
|  | 2021 | srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs) | 
|  | 2022 | return len(srcFiles) > 0 || len(ctx.GetDirectDepsWithTag(staticLibTag)) > 0 | 
|  | 2023 | } | 
|  | 2024 |  | 
|  | 2025 | // Implements android.ApexModule | 
|  | 2026 | func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { | 
|  | 2027 | return j.depIsInSameApex(ctx, dep) | 
|  | 2028 | } | 
|  | 2029 |  | 
|  | 2030 | // Implements android.ApexModule | 
| satayev | 758968a | 2021-12-06 11:42:40 +0000 | [diff] [blame] | 2031 | func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { | 
| Spandan Das | 7fa982c | 2023-02-24 18:38:56 +0000 | [diff] [blame] | 2032 | sdkVersionSpec := j.SdkVersion(ctx) | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 2033 | minSdkVersion := j.MinSdkVersion(ctx) | 
|  | 2034 | if !minSdkVersion.Specified() { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2035 | return fmt.Errorf("min_sdk_version is not specified") | 
|  | 2036 | } | 
| Spandan Das | 7fa982c | 2023-02-24 18:38:56 +0000 | [diff] [blame] | 2037 | // If the module is compiling against core (via sdk_version), skip comparison check. | 
|  | 2038 | if sdkVersionSpec.Kind == android.SdkCore { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2039 | return nil | 
|  | 2040 | } | 
| Spandan Das | 7fa982c | 2023-02-24 18:38:56 +0000 | [diff] [blame] | 2041 | if minSdkVersion.GreaterThan(sdkVersion) { | 
|  | 2042 | return fmt.Errorf("newer SDK(%v)", minSdkVersion) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2043 | } | 
|  | 2044 | return nil | 
|  | 2045 | } | 
|  | 2046 |  | 
|  | 2047 | func (j *Module) Stem() string { | 
| Jihoon Kang | 1bfb6f2 | 2023-07-01 00:13:47 +0000 | [diff] [blame] | 2048 | if j.stem == "" { | 
|  | 2049 | panic("Stem() called before stem property was set") | 
|  | 2050 | } | 
|  | 2051 | return j.stem | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2052 | } | 
|  | 2053 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2054 | func (j *Module) JacocoReportClassesFile() android.Path { | 
|  | 2055 | return j.jacocoReportClassesFile | 
|  | 2056 | } | 
|  | 2057 |  | 
| Anton Hansson | 0e73f9e | 2023-09-20 13:39:57 +0000 | [diff] [blame] | 2058 | func (j *Module) collectTransitiveSrcFiles(ctx android.ModuleContext, mine android.Paths) { | 
|  | 2059 | var fromDeps []*android.DepSet[android.Path] | 
|  | 2060 | ctx.VisitDirectDeps(func(module android.Module) { | 
|  | 2061 | tag := ctx.OtherModuleDependencyTag(module) | 
|  | 2062 | if tag == staticLibTag { | 
|  | 2063 | depInfo := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo) | 
|  | 2064 | if depInfo.TransitiveSrcFiles != nil { | 
|  | 2065 | fromDeps = append(fromDeps, depInfo.TransitiveSrcFiles) | 
|  | 2066 | } | 
|  | 2067 | } | 
|  | 2068 | }) | 
|  | 2069 |  | 
|  | 2070 | j.transitiveSrcFiles = android.NewDepSet(android.POSTORDER, mine, fromDeps) | 
|  | 2071 | } | 
|  | 2072 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2073 | func (j *Module) IsInstallable() bool { | 
|  | 2074 | return Bool(j.properties.Installable) | 
|  | 2075 | } | 
|  | 2076 |  | 
| Joe Onorato | 6fe59eb | 2023-07-16 13:20:33 -0700 | [diff] [blame] | 2077 | func (j *Module) collectTransitiveAconfigFiles(ctx android.ModuleContext) { | 
|  | 2078 | // Aconfig files from this module | 
|  | 2079 | mine := j.aconfigIntermediates | 
|  | 2080 |  | 
|  | 2081 | // Aconfig files from transitive dependencies | 
|  | 2082 | fromDeps := []*android.DepSet[android.Path]{} | 
|  | 2083 | ctx.VisitDirectDeps(func(module android.Module) { | 
|  | 2084 | dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo) | 
|  | 2085 | if dep.TransitiveAconfigFiles != nil { | 
|  | 2086 | fromDeps = append(fromDeps, dep.TransitiveAconfigFiles) | 
|  | 2087 | } | 
|  | 2088 | }) | 
|  | 2089 |  | 
|  | 2090 | // DepSet containing aconfig files myself and from dependencies | 
|  | 2091 | j.transitiveAconfigFiles = android.NewDepSet(android.POSTORDER, mine, fromDeps) | 
|  | 2092 | } | 
|  | 2093 |  | 
|  | 2094 | func (j *Module) AddAconfigIntermediate(path android.Path) { | 
|  | 2095 | j.aconfigIntermediates = append(j.aconfigIntermediates, path) | 
|  | 2096 | } | 
|  | 2097 |  | 
|  | 2098 | func (j *Module) getTransitiveAconfigFiles() *android.DepSet[android.Path] { | 
|  | 2099 | if j.transitiveAconfigFiles == nil { | 
|  | 2100 | panic(fmt.Errorf("java.Moduile: getTransitiveAconfigFiles called before collectTransitiveAconfigFiles module=%s", j.Name())) | 
|  | 2101 | } | 
|  | 2102 | return j.transitiveAconfigFiles | 
|  | 2103 | } | 
|  | 2104 |  | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2105 | type sdkLinkType int | 
|  | 2106 |  | 
|  | 2107 | const ( | 
|  | 2108 | // TODO(jiyong) rename these for better readability. Make the allowed | 
|  | 2109 | // and disallowed link types explicit | 
|  | 2110 | // order is important here. See rank() | 
|  | 2111 | javaCore sdkLinkType = iota | 
|  | 2112 | javaSdk | 
|  | 2113 | javaSystem | 
|  | 2114 | javaModule | 
|  | 2115 | javaSystemServer | 
|  | 2116 | javaPlatform | 
|  | 2117 | ) | 
|  | 2118 |  | 
|  | 2119 | func (lt sdkLinkType) String() string { | 
|  | 2120 | switch lt { | 
|  | 2121 | case javaCore: | 
|  | 2122 | return "core Java API" | 
|  | 2123 | case javaSdk: | 
|  | 2124 | return "Android API" | 
|  | 2125 | case javaSystem: | 
|  | 2126 | return "system API" | 
|  | 2127 | case javaModule: | 
|  | 2128 | return "module API" | 
|  | 2129 | case javaSystemServer: | 
|  | 2130 | return "system server API" | 
|  | 2131 | case javaPlatform: | 
|  | 2132 | return "private API" | 
|  | 2133 | default: | 
|  | 2134 | panic(fmt.Errorf("unrecognized linktype: %d", lt)) | 
|  | 2135 | } | 
|  | 2136 | } | 
|  | 2137 |  | 
|  | 2138 | // rank determines the total order among sdkLinkType. An SDK link type of rank A can link to | 
|  | 2139 | // another SDK link type of rank B only when B <= A. For example, a module linking to Android SDK | 
|  | 2140 | // can't statically depend on modules that use Platform API. | 
|  | 2141 | func (lt sdkLinkType) rank() int { | 
|  | 2142 | return int(lt) | 
|  | 2143 | } | 
|  | 2144 |  | 
|  | 2145 | type moduleWithSdkDep interface { | 
|  | 2146 | android.Module | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 2147 | getSdkLinkType(ctx android.BaseModuleContext, name string) (ret sdkLinkType, stubs bool) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2148 | } | 
|  | 2149 |  | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 2150 | func (m *Module) getSdkLinkType(ctx android.BaseModuleContext, name string) (ret sdkLinkType, stubs bool) { | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2151 | switch name { | 
| Jihoon Kang | 91c8395 | 2023-05-30 19:12:28 +0000 | [diff] [blame] | 2152 | case android.SdkCore.DefaultJavaLibraryName(), | 
|  | 2153 | "legacy.core.platform.api.stubs", | 
|  | 2154 | "stable.core.platform.api.stubs", | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2155 | "stub-annotations", "private-stub-annotations-jar", | 
| Jihoon Kang | 91c8395 | 2023-05-30 19:12:28 +0000 | [diff] [blame] | 2156 | "core-lambda-stubs", | 
| Jihoon Kang | b507831 | 2023-03-29 23:25:49 +0000 | [diff] [blame] | 2157 | "core-generated-annotation-stubs": | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2158 | return javaCore, true | 
| Jihoon Kang | 91c8395 | 2023-05-30 19:12:28 +0000 | [diff] [blame] | 2159 | case android.SdkPublic.DefaultJavaLibraryName(): | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2160 | return javaSdk, true | 
| Jihoon Kang | 91c8395 | 2023-05-30 19:12:28 +0000 | [diff] [blame] | 2161 | case android.SdkSystem.DefaultJavaLibraryName(): | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2162 | return javaSystem, true | 
| Jihoon Kang | 91c8395 | 2023-05-30 19:12:28 +0000 | [diff] [blame] | 2163 | case android.SdkModule.DefaultJavaLibraryName(): | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2164 | return javaModule, true | 
| Jihoon Kang | 91c8395 | 2023-05-30 19:12:28 +0000 | [diff] [blame] | 2165 | case android.SdkSystemServer.DefaultJavaLibraryName(): | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2166 | return javaSystemServer, true | 
| Jihoon Kang | 91c8395 | 2023-05-30 19:12:28 +0000 | [diff] [blame] | 2167 | case android.SdkTest.DefaultJavaLibraryName(): | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2168 | return javaSystem, true | 
|  | 2169 | } | 
|  | 2170 |  | 
|  | 2171 | if stub, linkType := moduleStubLinkType(name); stub { | 
|  | 2172 | return linkType, true | 
|  | 2173 | } | 
|  | 2174 |  | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 2175 | ver := m.SdkVersion(ctx) | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2176 | switch ver.Kind { | 
|  | 2177 | case android.SdkCore: | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2178 | return javaCore, false | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2179 | case android.SdkSystem: | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2180 | return javaSystem, false | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2181 | case android.SdkPublic: | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2182 | return javaSdk, false | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2183 | case android.SdkModule: | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2184 | return javaModule, false | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2185 | case android.SdkSystemServer: | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2186 | return javaSystemServer, false | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2187 | case android.SdkPrivate, android.SdkNone, android.SdkCorePlatform, android.SdkTest: | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2188 | return javaPlatform, false | 
|  | 2189 | } | 
|  | 2190 |  | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2191 | if !ver.Valid() { | 
|  | 2192 | panic(fmt.Errorf("sdk_version is invalid. got %q", ver.Raw)) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2193 | } | 
|  | 2194 | return javaSdk, false | 
|  | 2195 | } | 
|  | 2196 |  | 
|  | 2197 | // checkSdkLinkType make sures the given dependency doesn't have a lower SDK link type rank than | 
|  | 2198 | // this module's. See the comment on rank() for details and an example. | 
|  | 2199 | func (j *Module) checkSdkLinkType( | 
|  | 2200 | ctx android.ModuleContext, dep moduleWithSdkDep, tag dependencyTag) { | 
|  | 2201 | if ctx.Host() { | 
|  | 2202 | return | 
|  | 2203 | } | 
|  | 2204 |  | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 2205 | myLinkType, stubs := j.getSdkLinkType(ctx, ctx.ModuleName()) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2206 | if stubs { | 
|  | 2207 | return | 
|  | 2208 | } | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 2209 | depLinkType, _ := dep.getSdkLinkType(ctx, ctx.OtherModuleName(dep)) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2210 |  | 
|  | 2211 | if myLinkType.rank() < depLinkType.rank() { | 
|  | 2212 | ctx.ModuleErrorf("compiles against %v, but dependency %q is compiling against %v. "+ | 
|  | 2213 | "In order to fix this, consider adjusting sdk_version: OR platform_apis: "+ | 
|  | 2214 | "property of the source or target module so that target module is built "+ | 
|  | 2215 | "with the same or smaller API set when compared to the source.", | 
|  | 2216 | myLinkType, ctx.OtherModuleName(dep), depLinkType) | 
|  | 2217 | } | 
|  | 2218 | } | 
|  | 2219 |  | 
|  | 2220 | func (j *Module) collectDeps(ctx android.ModuleContext) deps { | 
|  | 2221 | var deps deps | 
|  | 2222 |  | 
|  | 2223 | if ctx.Device() { | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2224 | sdkDep := decodeSdkDep(ctx, android.SdkContext(j)) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2225 | if sdkDep.invalidVersion { | 
|  | 2226 | ctx.AddMissingDependencies(sdkDep.bootclasspath) | 
|  | 2227 | ctx.AddMissingDependencies(sdkDep.java9Classpath) | 
|  | 2228 | } else if sdkDep.useFiles { | 
|  | 2229 | // sdkDep.jar is actually equivalent to turbine header.jar. | 
|  | 2230 | deps.classpath = append(deps.classpath, sdkDep.jars...) | 
| Colin Cross | 9bb9bfb | 2022-03-17 11:12:32 -0700 | [diff] [blame] | 2231 | deps.dexClasspath = append(deps.dexClasspath, sdkDep.jars...) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2232 | deps.aidlPreprocess = sdkDep.aidl | 
|  | 2233 | } else { | 
|  | 2234 | deps.aidlPreprocess = sdkDep.aidl | 
|  | 2235 | } | 
|  | 2236 | } | 
|  | 2237 |  | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 2238 | sdkLinkType, _ := j.getSdkLinkType(ctx, ctx.ModuleName()) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2239 |  | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 2240 | j.collectTransitiveHeaderJars(ctx) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2241 | ctx.VisitDirectDeps(func(module android.Module) { | 
|  | 2242 | otherName := ctx.OtherModuleName(module) | 
|  | 2243 | tag := ctx.OtherModuleDependencyTag(module) | 
|  | 2244 |  | 
|  | 2245 | if IsJniDepTag(tag) { | 
|  | 2246 | // Handled by AndroidApp.collectAppDeps | 
|  | 2247 | return | 
|  | 2248 | } | 
|  | 2249 | if tag == certificateTag { | 
|  | 2250 | // Handled by AndroidApp.collectAppDeps | 
|  | 2251 | return | 
|  | 2252 | } | 
|  | 2253 |  | 
|  | 2254 | if dep, ok := module.(SdkLibraryDependency); ok { | 
|  | 2255 | switch tag { | 
| Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame] | 2256 | case sdkLibTag, libTag: | 
| Colin Cross | 9bb9bfb | 2022-03-17 11:12:32 -0700 | [diff] [blame] | 2257 | depHeaderJars := dep.SdkHeaderJars(ctx, j.SdkVersion(ctx)) | 
|  | 2258 | deps.classpath = append(deps.classpath, depHeaderJars...) | 
|  | 2259 | deps.dexClasspath = append(deps.dexClasspath, depHeaderJars...) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2260 | case staticLibTag: | 
|  | 2261 | ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName) | 
|  | 2262 | } | 
|  | 2263 | } else if ctx.OtherModuleHasProvider(module, JavaInfoProvider) { | 
|  | 2264 | dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo) | 
|  | 2265 | if sdkLinkType != javaPlatform && | 
|  | 2266 | ctx.OtherModuleHasProvider(module, SyspropPublicStubInfoProvider) { | 
|  | 2267 | // dep is a sysprop implementation library, but this module is not linking against | 
|  | 2268 | // the platform, so it gets the sysprop public stubs library instead.  Replace | 
|  | 2269 | // dep with the JavaInfo from the SyspropPublicStubInfoProvider. | 
|  | 2270 | syspropDep := ctx.OtherModuleProvider(module, SyspropPublicStubInfoProvider).(SyspropPublicStubInfo) | 
|  | 2271 | dep = syspropDep.JavaInfo | 
|  | 2272 | } | 
|  | 2273 | switch tag { | 
|  | 2274 | case bootClasspathTag: | 
|  | 2275 | deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars...) | 
| Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame] | 2276 | case sdkLibTag, libTag, instrumentationForTag: | 
| Sam Delmerico | 0d1c4a0 | 2022-04-26 18:34:55 +0000 | [diff] [blame] | 2277 | if _, ok := module.(*Plugin); ok { | 
|  | 2278 | ctx.ModuleErrorf("a java_plugin (%s) cannot be used as a libs dependency", otherName) | 
|  | 2279 | } | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2280 | deps.classpath = append(deps.classpath, dep.HeaderJars...) | 
| Colin Cross | 9bb9bfb | 2022-03-17 11:12:32 -0700 | [diff] [blame] | 2281 | deps.dexClasspath = append(deps.dexClasspath, dep.HeaderJars...) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2282 | deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs...) | 
|  | 2283 | addPlugins(&deps, dep.ExportedPlugins, dep.ExportedPluginClasses...) | 
|  | 2284 | deps.disableTurbine = deps.disableTurbine || dep.ExportedPluginDisableTurbine | 
|  | 2285 | case java9LibTag: | 
|  | 2286 | deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars...) | 
|  | 2287 | case staticLibTag: | 
| Sam Delmerico | 0d1c4a0 | 2022-04-26 18:34:55 +0000 | [diff] [blame] | 2288 | if _, ok := module.(*Plugin); ok { | 
|  | 2289 | ctx.ModuleErrorf("a java_plugin (%s) cannot be used as a static_libs dependency", otherName) | 
|  | 2290 | } | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2291 | deps.classpath = append(deps.classpath, dep.HeaderJars...) | 
|  | 2292 | deps.staticJars = append(deps.staticJars, dep.ImplementationJars...) | 
|  | 2293 | deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars...) | 
|  | 2294 | deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars...) | 
|  | 2295 | deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs...) | 
|  | 2296 | addPlugins(&deps, dep.ExportedPlugins, dep.ExportedPluginClasses...) | 
|  | 2297 | // Turbine doesn't run annotation processors, so any module that uses an | 
|  | 2298 | // annotation processor that generates API is incompatible with the turbine | 
|  | 2299 | // optimization. | 
|  | 2300 | deps.disableTurbine = deps.disableTurbine || dep.ExportedPluginDisableTurbine | 
|  | 2301 | case pluginTag: | 
|  | 2302 | if plugin, ok := module.(*Plugin); ok { | 
|  | 2303 | if plugin.pluginProperties.Processor_class != nil { | 
|  | 2304 | addPlugins(&deps, dep.ImplementationAndResourcesJars, *plugin.pluginProperties.Processor_class) | 
|  | 2305 | } else { | 
|  | 2306 | addPlugins(&deps, dep.ImplementationAndResourcesJars) | 
|  | 2307 | } | 
|  | 2308 | // Turbine doesn't run annotation processors, so any module that uses an | 
|  | 2309 | // annotation processor that generates API is incompatible with the turbine | 
|  | 2310 | // optimization. | 
|  | 2311 | deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api) | 
|  | 2312 | } else { | 
|  | 2313 | ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName) | 
|  | 2314 | } | 
|  | 2315 | case errorpronePluginTag: | 
|  | 2316 | if _, ok := module.(*Plugin); ok { | 
|  | 2317 | deps.errorProneProcessorPath = append(deps.errorProneProcessorPath, dep.ImplementationAndResourcesJars...) | 
|  | 2318 | } else { | 
|  | 2319 | ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName) | 
|  | 2320 | } | 
|  | 2321 | case exportedPluginTag: | 
|  | 2322 | if plugin, ok := module.(*Plugin); ok { | 
|  | 2323 | j.exportedPluginJars = append(j.exportedPluginJars, dep.ImplementationAndResourcesJars...) | 
|  | 2324 | if plugin.pluginProperties.Processor_class != nil { | 
|  | 2325 | j.exportedPluginClasses = append(j.exportedPluginClasses, *plugin.pluginProperties.Processor_class) | 
|  | 2326 | } | 
|  | 2327 | // Turbine doesn't run annotation processors, so any module that uses an | 
|  | 2328 | // annotation processor that generates API is incompatible with the turbine | 
|  | 2329 | // optimization. | 
|  | 2330 | j.exportedDisableTurbine = Bool(plugin.pluginProperties.Generates_api) | 
|  | 2331 | } else { | 
|  | 2332 | ctx.PropertyErrorf("exported_plugins", "%q is not a java_plugin module", otherName) | 
|  | 2333 | } | 
|  | 2334 | case kotlinStdlibTag: | 
|  | 2335 | deps.kotlinStdlib = append(deps.kotlinStdlib, dep.HeaderJars...) | 
|  | 2336 | case kotlinAnnotationsTag: | 
|  | 2337 | deps.kotlinAnnotations = dep.HeaderJars | 
| Colin Cross | a1ff7c6 | 2021-09-17 14:11:52 -0700 | [diff] [blame] | 2338 | case kotlinPluginTag: | 
|  | 2339 | deps.kotlinPlugins = append(deps.kotlinPlugins, dep.ImplementationAndResourcesJars...) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2340 | case syspropPublicStubDepTag: | 
|  | 2341 | // This is a sysprop implementation library, forward the JavaInfoProvider from | 
|  | 2342 | // the corresponding sysprop public stub library as SyspropPublicStubInfoProvider. | 
|  | 2343 | ctx.SetProvider(SyspropPublicStubInfoProvider, SyspropPublicStubInfo{ | 
|  | 2344 | JavaInfo: dep, | 
|  | 2345 | }) | 
|  | 2346 | } | 
|  | 2347 | } else if dep, ok := module.(android.SourceFileProducer); ok { | 
|  | 2348 | switch tag { | 
| Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame] | 2349 | case sdkLibTag, libTag: | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2350 | checkProducesJars(ctx, dep) | 
|  | 2351 | deps.classpath = append(deps.classpath, dep.Srcs()...) | 
| Colin Cross | 9bb9bfb | 2022-03-17 11:12:32 -0700 | [diff] [blame] | 2352 | deps.dexClasspath = append(deps.classpath, dep.Srcs()...) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2353 | case staticLibTag: | 
|  | 2354 | checkProducesJars(ctx, dep) | 
|  | 2355 | deps.classpath = append(deps.classpath, dep.Srcs()...) | 
|  | 2356 | deps.staticJars = append(deps.staticJars, dep.Srcs()...) | 
|  | 2357 | deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...) | 
|  | 2358 | } | 
|  | 2359 | } else { | 
|  | 2360 | switch tag { | 
|  | 2361 | case bootClasspathTag: | 
|  | 2362 | // If a system modules dependency has been added to the bootclasspath | 
|  | 2363 | // then add its libs to the bootclasspath. | 
|  | 2364 | sm := module.(SystemModulesProvider) | 
|  | 2365 | deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...) | 
|  | 2366 |  | 
|  | 2367 | case systemModulesTag: | 
|  | 2368 | if deps.systemModules != nil { | 
|  | 2369 | panic("Found two system module dependencies") | 
|  | 2370 | } | 
|  | 2371 | sm := module.(SystemModulesProvider) | 
|  | 2372 | outputDir, outputDeps := sm.OutputDirAndDeps() | 
|  | 2373 | deps.systemModules = &systemModules{outputDir, outputDeps} | 
| Paul Duffin | 53a70a4 | 2022-01-11 14:35:55 +0000 | [diff] [blame] | 2374 |  | 
|  | 2375 | case instrumentationForTag: | 
|  | 2376 | ctx.PropertyErrorf("instrumentation_for", "dependency %q of type %q does not provide JavaInfo so is unsuitable for use with this property", ctx.OtherModuleName(module), ctx.OtherModuleType(module)) | 
| Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 2377 | } | 
|  | 2378 | } | 
|  | 2379 |  | 
|  | 2380 | addCLCFromDep(ctx, module, j.classLoaderContexts) | 
|  | 2381 | }) | 
|  | 2382 |  | 
|  | 2383 | return deps | 
|  | 2384 | } | 
|  | 2385 |  | 
|  | 2386 | func addPlugins(deps *deps, pluginJars android.Paths, pluginClasses ...string) { | 
|  | 2387 | deps.processorPath = append(deps.processorPath, pluginJars...) | 
|  | 2388 | deps.processorClasses = append(deps.processorClasses, pluginClasses...) | 
|  | 2389 | } | 
|  | 2390 |  | 
|  | 2391 | // TODO(b/132357300) Generalize SdkLibrarComponentDependency to non-SDK libraries and merge with | 
|  | 2392 | // this interface. | 
|  | 2393 | type ProvidesUsesLib interface { | 
|  | 2394 | ProvidesUsesLib() *string | 
|  | 2395 | } | 
|  | 2396 |  | 
|  | 2397 | func (j *Module) ProvidesUsesLib() *string { | 
|  | 2398 | return j.usesLibraryProperties.Provides_uses_lib | 
|  | 2399 | } | 
| satayev | 1c564cc | 2021-05-25 19:50:30 +0100 | [diff] [blame] | 2400 |  | 
|  | 2401 | type ModuleWithStem interface { | 
|  | 2402 | Stem() string | 
|  | 2403 | } | 
|  | 2404 |  | 
|  | 2405 | var _ ModuleWithStem = (*Module)(nil) | 
| Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 2406 |  | 
| Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 2407 | func (j *Module) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { | 
| Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 2408 | switch ctx.ModuleType() { | 
| Zi Wang | 3096e68 | 2023-06-27 15:44:10 -0700 | [diff] [blame] | 2409 | case "java_library", "java_library_host", "java_library_static", "tradefed_java_library_host": | 
| Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 2410 | if lib, ok := ctx.Module().(*Library); ok { | 
|  | 2411 | javaLibraryBp2Build(ctx, lib) | 
|  | 2412 | } | 
|  | 2413 | case "java_binary_host": | 
|  | 2414 | if binary, ok := ctx.Module().(*Binary); ok { | 
|  | 2415 | javaBinaryHostBp2Build(ctx, binary) | 
|  | 2416 | } | 
| Zi Wang | 65b3672 | 2023-05-23 15:18:33 -0700 | [diff] [blame] | 2417 | case "java_test_host": | 
|  | 2418 | if testHost, ok := ctx.Module().(*TestHost); ok { | 
|  | 2419 | javaTestHostBp2Build(ctx, testHost) | 
|  | 2420 | } | 
| Chris Parsons | 39a1697 | 2023-06-08 14:28:51 +0000 | [diff] [blame] | 2421 | default: | 
|  | 2422 | ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "") | 
| Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 2423 | } | 
| Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 2424 | } |