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