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