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