From f5a6628b27ab67cba0aa5fd153973cc5d704a366 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 21 Feb 2020 08:16:41 -0800 Subject: Use header jar without jarjar for sharded classpath Sharding uses the header jar of all of the classes of the module with the sources of a subset, but was incorrectly used the jarjar version of the header jar, which may have renamed some of the classes. Fixes: 149969343 Test: m framework-minus-apex Change-Id: I568c939f8030d3ddc1e7fa8796cffcac4d6172e8 --- java/java.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 462dba809..c89784a03 100644 --- a/java/java.go +++ b/java/java.go @@ -1323,6 +1323,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { j.compiledSrcJars = srcJars enable_sharding := false + var headerJarFileWithoutJarjar android.Path if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine { if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 { enable_sharding = true @@ -1332,7 +1333,8 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { // allow for the use of annotation processors that do function correctly // with sharding enabled. See: b/77284273. } - j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars) + headerJarFileWithoutJarjar, j.headerJarFile = + j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars) if ctx.Failed() { return } @@ -1351,7 +1353,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { } if enable_sharding { - flags.classpath = append(flags.classpath, j.headerJarFile) + flags.classpath = append(flags.classpath, headerJarFileWithoutJarjar) shardSize := int(*(j.properties.Javac_shard_size)) var shardSrcs []android.Paths if len(uniqueSrcFiles) > 0 { @@ -1642,7 +1644,8 @@ func CheckKotlincFlags(ctx android.ModuleContext, flags []string) { } func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths, - deps deps, flags javaBuilderFlags, jarName string, extraJars android.Paths) android.Path { + deps deps, flags javaBuilderFlags, jarName string, + extraJars android.Paths) (headerJar, jarjarHeaderJar android.Path) { var jars android.Paths if len(srcFiles) > 0 || len(srcJars) > 0 { @@ -1650,7 +1653,7 @@ func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars turbineJar := android.PathForModuleOut(ctx, "turbine", jarName) TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags) if ctx.Failed() { - return nil + return nil, nil } jars = append(jars, turbineJar) } @@ -1659,7 +1662,6 @@ func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars // Combine any static header libraries into classes-header.jar. If there is only // one input jar this step will be skipped. - var headerJar android.Path jars = append(jars, deps.staticHeaderJars...) // we cannot skip the combine step for now if there is only one jar @@ -1668,18 +1670,19 @@ func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, false, nil, []string{"META-INF/TRANSITIVE"}) headerJar = combinedJar + jarjarHeaderJar = combinedJar if j.expandJarjarRules != nil { // Transform classes.jar into classes-jarjar.jar jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName) TransformJarJar(ctx, jarjarFile, headerJar, j.expandJarjarRules) - headerJar = jarjarFile + jarjarHeaderJar = jarjarFile if ctx.Failed() { - return nil + return nil, nil } } - return headerJar + return headerJar, jarjarHeaderJar } func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags, -- cgit v1.2.3 From 81aaa0c1bd99e38f61611d574712a761e3ef8508 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Tue, 18 Feb 2020 12:50:44 +0000 Subject: Reland "Turn on the instrumentation by default for the java code in APEXes" This reverts commit c021ea0b3543d4ff64b16414c0276b96dc5b2c4b. Exempt-From-Owner-Approval: cherry-pick from aosp Bug: 149353192 Merged-In: I2b1c0736202de26c5ea88c0ab14574bd7207a5fb Test: N/A (this is a clean revert) forward fix will be followed (cherry picked from commit 00cae1cc88773a5238809130841b6a6b7eb63614) Change-Id: I2b1c0736202de26c5ea88c0ab14574bd7207a5fb --- java/java.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index c89784a03..1273eff9c 100644 --- a/java/java.go +++ b/java/java.go @@ -1521,6 +1521,11 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { j.headerJarFile = j.implementationJarFile } + // Force enable the instrumentation for java code that is built for APEXes + if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !j.IsForPlatform() { + j.properties.Instrument = true + } + if j.shouldInstrument(ctx) { outputFile = j.instrument(ctx, flags, outputFile, jarName) } -- cgit v1.2.3 From 2882660422bbbe7ecc5d0ead431b383f6d5e7fcd Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Fri, 21 Feb 2020 16:04:53 +0900 Subject: Expect added members for instrumented modules hiddenapi expects that all members in a class to have corresponding hidden API flags. However, this can't be satisfied when the java module having the class is instrumented; JaCoCo added a few number of synthetic members. In this case, give 'no-force-assign-all' option to the hidden api tool so that it doesn't complain about the synthetic methods. Also, disabling instrumenting jacocoagent itself, because it doesn't make sense. Exempt-From-Owner-Approval: PS3 fixes a typo in a comment. PS2 got ORV. Bug: 149353192 Test: SKIP_ABI_CHECKS=true EMMA_INSTRUMENT=true EMMA_INSTRUMENT_FRAMEWORK=true SKIP_BOOT_JARS_CHECK=true m out/soong/.intermediates/external/apache-xml/apache-xml/android_common_com.android.art.debug/hiddenapi/unaligned/unaligned.jar Merged-In: Ibaf383c439945ab664e885af319548b56e2c8cb6 (cherry picked from commit 93e57a0b862beabdd11b8dac342167ea7f7c7b76) Change-Id: Ibaf383c439945ab664e885af319548b56e2c8cb6 --- java/java.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 1273eff9c..8d58a9023 100644 --- a/java/java.go +++ b/java/java.go @@ -1521,8 +1521,11 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { j.headerJarFile = j.implementationJarFile } - // Force enable the instrumentation for java code that is built for APEXes - if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !j.IsForPlatform() { + // Force enable the instrumentation for java code that is built for APEXes ... + // except for the jacocoagent itself (because instrumenting jacocoagent using jacocoagent + // doesn't make sense) + isJacocoAgent := ctx.ModuleName() == "jacocoagent" + if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !isJacocoAgent && !j.IsForPlatform() { j.properties.Instrument = true } -- cgit v1.2.3 From b8fa86ad6f8186258b89572bef0468fc873eb30d Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Tue, 10 Mar 2020 06:23:13 +0900 Subject: Fix apex_available Checking apex_available was missing some corner cases. For example, the deps of share deps of cc_library modules are missed while those from cc_library_shared are correctly tracked. This was due to.. * calling DepIsInSameApex in WalkDeps: both work fine separately, but when they are used together, it fails to work. It's due to how WalkDeps works. (We might fix this bug too risky since it is used very widely) * incorrect receiver for DepIsInSameApex in apex_deps mutator: receiver is supposed to be parent, but child was used before. Interestingly lots of deps are within the same group of module types(cc to cc, java to java), it has worked. (note that receiver's DepIsInSameApex implementation can be different). This change fixes them by.. * walkPayloadDeps is now relying on ApexVariation, which is calculated correctly by TopDown apex_deps mutator. * use correct receiver for DepIsInSameApex in apex_deps mutator, which requires for java.SdkLibrary to override the method and for java.Library/Import to use passed dep instead of receiver to check its membership of sdk. Exempt-From-Owner-Approval: cherry-pick from aosp/master Bug: 151071238 Test: build/boot Merged-In: I0569ef4bb8e79635e4d97a89f421a8d8b7d26456 (cherry picked from commit 5e9013be2202effb500a0aa14d95f5fef70cc75e) Change-Id: I0569ef4bb8e79635e4d97a89f421a8d8b7d26456 --- java/java.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 8d58a9023..23dc0b5c5 100644 --- a/java/java.go +++ b/java/java.go @@ -1790,11 +1790,16 @@ func (j *Module) hasCode(ctx android.ModuleContext) bool { } func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { - depTag := ctx.OtherModuleDependencyTag(dep) // Dependencies other than the static linkage are all considered crossing APEX boundary + if staticLibTag == ctx.OtherModuleDependencyTag(dep) { + return true + } // Also, a dependency to an sdk member is also considered as such. This is required because // sdk members should be mutated into APEXes. Refer to sdk.sdkDepsReplaceMutator. - return depTag == staticLibTag || j.IsInAnySdk() + if sa, ok := dep.(android.SdkAware); ok && sa.IsInAnySdk() { + return true + } + return false } func (j *Module) Stem() string { @@ -2495,11 +2500,16 @@ func (j *Import) SrcJarArgs() ([]string, android.Paths) { } func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { - depTag := ctx.OtherModuleDependencyTag(dep) // dependencies other than the static linkage are all considered crossing APEX boundary + if staticLibTag == ctx.OtherModuleDependencyTag(dep) { + return true + } // Also, a dependency to an sdk member is also considered as such. This is required because // sdk members should be mutated into APEXes. Refer to sdk.sdkDepsReplaceMutator. - return depTag == staticLibTag || j.IsInAnySdk() + if sa, ok := dep.(android.SdkAware); ok && sa.IsInAnySdk() { + return true + } + return false } // Add compile time check for interface implementation -- cgit v1.2.3 From bbd78556daf4a7e015f2e3ddfe9539909e9ebf40 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Thu, 19 Mar 2020 15:23:38 +0000 Subject: Make system_server stubs consistent with other stubs Include the module_api stubs in system_server one instead of putting both of these jars on the classpath. Also rename it to be in line with the other stubs. Bug: 149293194 Test: m Change-Id: Iead5af4152a49cd59a4fd7afc0312c2f0c872c1e --- java/java.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 23dc0b5c5..c73efa4da 100644 --- a/java/java.go +++ b/java/java.go @@ -841,7 +841,7 @@ func (m *Module) getLinkType(name string) (ret linkType, stubs bool) { return javaModule, true case ver.kind == sdkModule: return javaModule, false - case name == "services-stubs": + case name == "android_system_server_stubs_current": return javaSystemServer, true case ver.kind == sdkSystemServer: return javaSystemServer, false -- cgit v1.2.3 From a4a83b0ef9b9769681ad285290fdbbf043eff3d5 Mon Sep 17 00:00:00 2001 From: Ulya Trafimovich Date: Wed, 11 Mar 2020 11:59:34 +0000 Subject: Simplify the construction of class loader contexts for system server jars. This reworks CL https://r.android.com/1180134 as follows: 1) Do not reorder the list of system server jars passed from Make to Soong via the product variable PRODUCT_SYSTEM_SERVER_JARS. This means that for some products the order of jars on the system server classpath may be non-optimal: a jar X that depends on Y may be dexpreopted before Y, so that all references to the classes and methods from Y wil be unresolved. Unfortunately for such products, fixing the order is not a simple matter of rearranging their PRODUCT_SYSTEM_SERVER_JARS, because the conflicts may arise when the product-specific variable gets merged with the common variable. 2) As a consequence of 1), do not add artificial dependencies between system server jars: this is now impossible, as it would create circular dependencies for those products that have non-optimal order of jars. 3) Copy dex files for system server jars to a predefined build location. This is necessary because at the time when Soong generates class loader context for k-th jar, it needs to know the paths to jars 1 .. (k-1), and it might have not processed those jars yet (so Soong can't query the paths from the modules). This approach is similar to the way Soong handles bootclasspath jars. 4) Do not exclude from dexpreopting system server jars that are not Soong modules (those that are Make modules). The previous CL excluded them because Make modules do not have ModuleContext. But it turns out that ModuleContext is not necessary, as all the information is passed via the dexpreopt config. Test: aosp_walleye-userdebug boots and there are no messages in the logcat regarding class loader context mismatch: $ adb logcat | grep 'mismatch' # empty Test: Class loader contexts in the oat files for system server jars match expectations: $ oatdump --oat-file=out/target/product/walleye/system/framework/oat/arm64/com.android.location.provider.odex 2>/dev/null | grep '^classpath' classpath = PCL[] $ oatdump --oat-file=out/target/product/walleye/system/framework/oat/arm64/services.odex 2>/dev/null | grep '^classpath' classpath = PCL[/system/framework/com.android.location.provider.jar*1989208671] $ oatdump --oat-file=out/target/product/walleye/system/framework/oat/arm64/ethernet-service.odex 2>/dev/null | grep '^classpath' classpath = PCL[/system/framework/com.android.location.provider.jar*1989208671:/system/framework/services.jar*4040443083:/system/framework/services.jar!classes2.dex*2210087472] Test: The phone boots and logcat has no scary messages related to class loader contexts: $ lunch aosp_walleye-userdebug && m $ adb reboot bootloader && fastboot flashall -w && adb wait-for-device $ adb root $ adb shell stop $ adb logcat -c $ adb shell setprop dalvik.vm.extra-opts -verbose:oat $ adb shell start $ adb logcat | egrep -io 'system_server: .*load.*/system/framework.*' system_server: Loading /system/framework/oat/arm64/com.android.location.provider.odex with executable: 0 system_server: Successfully loaded /system/framework/oat/arm64/com.android.location.provider.odex with executable: 0 system_server: Loading /system/framework/oat/arm64/services.odex with executable: 0 system_server: Successfully loaded /system/framework/oat/arm64/services.odex with executable: 0 system_server: Loading /system/framework/oat/arm64/ethernet-service.odex with executable: 0 system_server: Successfully loaded /system/framework/oat/arm64/ethernet-service.odex with executable: 0 system_server: Loading /system/framework/oat/arm64/wifi-service.odex with executable: 0 system_server: Successfully loaded /system/framework/oat/arm64/wifi-service.odex with executable: 0 system_server: Loading /system/framework/oat/arm64/com.android.location.provider.odex with executable: 1 system_server: Successfully loaded /system/framework/oat/arm64/com.android.location.provider.odex with executable: 1 system_server: Loading /system/framework/oat/arm64/services.odex with executable: 1 system_server: Successfully loaded /system/framework/oat/arm64/services.odex with executable: 1 system_server: Loading /system/framework/oat/arm64/ethernet-service.odex with executable: 1 system_server: Successfully loaded /system/framework/oat/arm64/ethernet-service.odex with executable: 1 system_server: Loading /system/framework/oat/arm64/wifi-service.odex with executable: 1 system_server: Successfully loaded /system/framework/oat/arm64/wifi-service.odex with executable: 1 system_server: Loading /system/framework/oat/arm64/com.android.location.provider.odex with executable: 1 system_server: Successfully loaded /system/framework/oat/arm64/com.android.location.provider.odex with executable: 1 Bug: 141785760 Bug: 140451054 Bug: 148944771 Bug: 147017252 Change-Id: I33c4087f8bfacd0ecb89877aa150b75360d06710 --- java/java.go | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 23dc0b5c5..27e4d6156 100644 --- a/java/java.go +++ b/java/java.go @@ -23,14 +23,12 @@ import ( "path/filepath" "strconv" "strings" - "sync" "github.com/google/blueprint" "github.com/google/blueprint/pathtools" "github.com/google/blueprint/proptools" "android/soong/android" - "android/soong/dexpreopt" "android/soong/java/config" "android/soong/tradefed" ) @@ -54,8 +52,6 @@ func init() { PropertyName: "java_tests", }, }) - - android.PostDepsMutators(RegisterPostDepsMutators) } func RegisterJavaBuildComponents(ctx android.RegistrationContext) { @@ -84,44 +80,6 @@ func RegisterJavaBuildComponents(ctx android.RegistrationContext) { ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory) } -func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) { - ctx.BottomUp("ordered_system_server_jars", systemServerJarsDepsMutator) -} - -var ( - dexpreoptedSystemServerJarsKey = android.NewOnceKey("dexpreoptedSystemServerJars") - dexpreoptedSystemServerJarsLock sync.Mutex -) - -func DexpreoptedSystemServerJars(config android.Config) *[]string { - return config.Once(dexpreoptedSystemServerJarsKey, func() interface{} { - return &[]string{} - }).(*[]string) -} - -// A PostDepsMutator pass that enforces total order on non-updatable system server jars. A total -// order is neededed because such jars must be dexpreopted together (each jar on the list must have -// all preceding jars in its class loader context). The total order must be compatible with the -// partial order imposed by genuine dependencies between system server jars (which is not always -// respected by the PRODUCT_SYSTEM_SERVER_JARS variable). -// -// An earlier mutator pass creates genuine dependencies, and this pass traverses the jars in that -// order (which is partial and non-deterministic). This pass adds additional dependencies between -// jars, making the order total and deterministic. It also constructs a global ordered list. -func systemServerJarsDepsMutator(ctx android.BottomUpMutatorContext) { - jars := dexpreopt.NonUpdatableSystemServerJars(ctx, dexpreopt.GetGlobalConfig(ctx)) - name := ctx.ModuleName() - if android.InList(name, jars) { - dexpreoptedSystemServerJarsLock.Lock() - defer dexpreoptedSystemServerJarsLock.Unlock() - jars := DexpreoptedSystemServerJars(ctx.Config()) - for _, dep := range *jars { - ctx.AddDependency(ctx.Module(), dexpreopt.SystemServerDepTag, dep) - } - *jars = append(*jars, name) - } -} - func (j *Module) checkSdkVersion(ctx android.ModuleContext) { if j.SocSpecific() || j.DeviceSpecific() || (j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) { @@ -705,11 +663,6 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { } else if j.shouldInstrumentStatic(ctx) { ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent") } - - // services depend on com.android.location.provider, but dependency in not registered in a Blueprint file - if ctx.ModuleName() == "services" { - ctx.AddDependency(ctx.Module(), dexpreopt.SystemServerForcedDepTag, "com.android.location.provider") - } } func hasSrcExt(srcs []string, ext string) bool { -- cgit v1.2.3 From 688de9af5d4089f58a8f98ad8594595bd7ff3688 Mon Sep 17 00:00:00 2001 From: Songchun Fan Date: Tue, 24 Mar 2020 20:32:24 -0700 Subject: [soong] new field in Android.bp to request APK signing V4 If "v4_signature: true" is set, the v4 signature file, named [outputApkFile].idsig will be generated along side the outputApkFile. Test: m nothing Test: atest PackageManagerShellCommandIncrementalTest BUG: 149354175 Change-Id: Ie84725a15406f96f65042ea9909460e4eb34d57f --- java/java.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 46adedcd1..dc0b27244 100644 --- a/java/java.go +++ b/java/java.go @@ -319,6 +319,10 @@ type CompilerDeviceProperties struct { UncompressDex bool `blueprint:"mutated"` IsSDKLibrary bool `blueprint:"mutated"` + + // If true, generate the signature file of APK Signing Scheme V4, along side the signed APK file. + // Defaults to false. + V4_signature *bool } func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool { -- cgit v1.2.3 From 37ca4a1e0dfab898a8abc61c6f62b2d7fc1119e3 Mon Sep 17 00:00:00 2001 From: Jaewoong Jung Date: Thu, 26 Mar 2020 14:01:48 -0700 Subject: Add code coverage support to android_app JNI libs. This is a cherry-pick change. Test: Built mainline module coverage data Bug: 152117890 Change-Id: I47bf3e5d6e78c4518729bdb52616e248156d3cec Merged-In: I47bf3e5d6e78c4518729bdb52616e248156d3cec --- java/java.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index dc0b27244..55ad8b019 100644 --- a/java/java.go +++ b/java/java.go @@ -538,9 +538,10 @@ func (s sdkDep) hasFrameworkLibs() bool { } type jniLib struct { - name string - path android.Path - target android.Target + name string + path android.Path + target android.Target + coverageFile android.OptionalPath } func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool { -- cgit v1.2.3 From 1e65f94a4b2cc7dea1896937c2068b87c899c465 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Fri, 27 Mar 2020 19:39:48 +0000 Subject: Add a Tag field to dist to dist a tagged output Make java_library support this mode of output, to allow callers to dist the classes.jar file rather than the dexed jar file. Bug: 152618077 Test: followup CL Change-Id: I5ba6949833a0fbb95376142aec5096ff5f084c00 --- java/java.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index dc0b27244..edf83cfe1 100644 --- a/java/java.go +++ b/java/java.go @@ -419,6 +419,8 @@ type Module struct { // list of the xref extraction files kytheFiles android.Paths + + distFile android.Path } func (j *Module) OutputFiles(tag string) (android.Paths, error) { @@ -1775,9 +1777,18 @@ func (j *Module) IsInstallable() bool { // Java libraries (.jar file) // +type LibraryProperties struct { + Dist struct { + // The tag of the output of this module that should be output. + Tag *string `android:"arch_variant"` + } `android:"arch_variant"` +} + type Library struct { Module + libraryProperties LibraryProperties + InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths) } @@ -1821,6 +1832,15 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".jar", j.outputFile, extraInstallDeps...) } + + // Verify Dist.Tag is set to a supported output + if j.libraryProperties.Dist.Tag != nil { + distFiles, err := j.OutputFiles(*j.libraryProperties.Dist.Tag) + if err != nil { + ctx.PropertyErrorf("dist.tag", "%s", err.Error()) + } + j.distFile = distFiles[0] + } } func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) { @@ -1945,7 +1965,8 @@ func LibraryFactory() android.Module { &module.Module.properties, &module.Module.deviceProperties, &module.Module.dexpreoptProperties, - &module.Module.protoProperties) + &module.Module.protoProperties, + &module.libraryProperties) android.InitApexModule(module) android.InitSdkAwareModule(module) -- cgit v1.2.3 From e5ac15a1b74094e38e65db7b3dee29e422e15b2b Mon Sep 17 00:00:00 2001 From: Artur Satayev Date: Wed, 8 Apr 2020 19:09:30 +0100 Subject: Check updatable APKs compile against managed SDKs. As a follow up, this property will be set to APKs participating in mainline program. Bug: 153333044 Test: m Change-Id: I6ea2f3c1d26992259e4e9e6a6d8cecf091d39c43 Merged-In: I6ea2f3c1d26992259e4e9e6a6d8cecf091d39c43 (cherry picked from commit 2db1c3f1c432740f734917e04b2b847066c8d508) Exempt-From-Owner-Approval: clean cherry-pick --- java/java.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index d67ff874d..79568131d 100644 --- a/java/java.go +++ b/java/java.go @@ -80,7 +80,7 @@ func RegisterJavaBuildComponents(ctx android.RegistrationContext) { ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory) } -func (j *Module) checkSdkVersion(ctx android.ModuleContext) { +func (j *Module) checkSdkVersions(ctx android.ModuleContext) { if j.SocSpecific() || j.DeviceSpecific() || (j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) { if sc, ok := ctx.Module().(sdkContext); ok { @@ -90,6 +90,18 @@ func (j *Module) checkSdkVersion(ctx android.ModuleContext) { } } } + + ctx.VisitDirectDeps(func(module android.Module) { + tag := ctx.OtherModuleDependencyTag(module) + switch module.(type) { + // TODO(satayev): cover other types as well, e.g. imports + case *Library, *AndroidLibrary: + switch tag { + case bootClasspathTag, libTag, staticLibTag, java9LibTag: + checkLinkType(ctx, j, module.(linkTypeContext), tag.(dependencyTag)) + } + } + }) } func (j *Module) checkPlatformAPI(ctx android.ModuleContext) { @@ -892,15 +904,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { // Handled by AndroidApp.collectAppDeps return } - switch module.(type) { - case *Library, *AndroidLibrary: - if to, ok := module.(linkTypeContext); ok { - switch tag { - case bootClasspathTag, libTag, staticLibTag: - checkLinkType(ctx, j, to, tag.(dependencyTag)) - } - } - } + switch dep := module.(type) { case SdkLibraryDependency: switch tag { @@ -1817,7 +1821,7 @@ func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bo } func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { - j.checkSdkVersion(ctx) + j.checkSdkVersions(ctx) j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar") j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter) -- cgit v1.2.3 From 2b9e3d39d9548e7e333bd0d56c42a88239483706 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 28 Feb 2020 14:39:53 +0000 Subject: Simplify java library sdk member code Adds the accessor function for retrieving the impl/header jars to the librarySdkMemberType structure instead of passing it into its buildSnapshot() method. That enabled: * The removal of the [header/impl]LibrarySdkMemberType structs. * The removal of their implementations of BuildSnapshot. * Replacing buildSnapshot() with BuildSnapshot() This will make subsequent refactoring of the SdkMemberType interface a little simpler. Bug: 153306490 Test: m nothing Bug: 150451422 Merged-In: I1f96986bb497cf9d9df9916e40065f66b35a4704 Change-Id: I1f96986bb497cf9d9df9916e40065f66b35a4704 --- java/java.go | 64 ++++++++++++++++++++++-------------------------------------- 1 file changed, 23 insertions(+), 41 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 79568131d..e4b51c00c 100644 --- a/java/java.go +++ b/java/java.go @@ -39,11 +39,17 @@ func init() { // Register sdk member types. android.RegisterSdkMemberType(javaHeaderLibsSdkMemberType) - android.RegisterSdkMemberType(&implLibrarySdkMemberType{ - librarySdkMemberType{ - android.SdkMemberTypeBase{ - PropertyName: "java_libs", - }, + android.RegisterSdkMemberType(&librarySdkMemberType{ + android.SdkMemberTypeBase{ + PropertyName: "java_libs", + }, + func(j *Library) android.Path { + implementationJars := j.ImplementationJars() + if len(implementationJars) != 1 { + panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name())) + } + + return implementationJars[0] }, }) @@ -1870,6 +1876,10 @@ func sdkSnapshotFilePathForMember(member android.SdkMember, suffix string) strin type librarySdkMemberType struct { android.SdkMemberTypeBase + + // Function to retrieve the appropriate output jar (implementation or header) from + // the library. + jarToExportGetter func(j *Library) android.Path } func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { @@ -1881,11 +1891,7 @@ func (mt *librarySdkMemberType) IsInstance(module android.Module) bool { return ok } -func (mt *librarySdkMemberType) buildSnapshot( - sdkModuleContext android.ModuleContext, - builder android.SnapshotBuilder, - member android.SdkMember, - jarToExportGetter func(j *Library) android.Path) { +func (mt *librarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) { variants := member.Variants() if len(variants) != 1 { @@ -1897,7 +1903,7 @@ func (mt *librarySdkMemberType) buildSnapshot( variant := variants[0] j := variant.(*Library) - exportedJar := jarToExportGetter(j) + exportedJar := mt.jarToExportGetter(j) snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member) builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) @@ -1913,43 +1919,19 @@ func (mt *librarySdkMemberType) buildSnapshot( module.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) } -var javaHeaderLibsSdkMemberType android.SdkMemberType = &headerLibrarySdkMemberType{ - librarySdkMemberType{ - android.SdkMemberTypeBase{ - PropertyName: "java_header_libs", - SupportsSdk: true, - }, +var javaHeaderLibsSdkMemberType android.SdkMemberType = &librarySdkMemberType{ + android.SdkMemberTypeBase{ + PropertyName: "java_header_libs", + SupportsSdk: true, }, -} - -type headerLibrarySdkMemberType struct { - librarySdkMemberType -} - -func (mt *headerLibrarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) { - mt.librarySdkMemberType.buildSnapshot(sdkModuleContext, builder, member, func(j *Library) android.Path { + func(j *Library) android.Path { headerJars := j.HeaderJars() if len(headerJars) != 1 { panic(fmt.Errorf("there must be only one header jar from %q", j.Name())) } return headerJars[0] - }) -} - -type implLibrarySdkMemberType struct { - librarySdkMemberType -} - -func (mt *implLibrarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) { - mt.librarySdkMemberType.buildSnapshot(sdkModuleContext, builder, member, func(j *Library) android.Path { - implementationJars := j.ImplementationJars() - if len(implementationJars) != 1 { - panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name())) - } - - return implementationJars[0] - }) + }, } // java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well. -- cgit v1.2.3 From d76209b690540d1a5f626ad329db09874375d89a Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Mon, 2 Mar 2020 11:33:02 +0000 Subject: Refactor java_library/java_test snapshot processing Adds support for handling the common arch to the sdk module type snapshot generation code and then refactors the java_library and java_test snapshot processing to take advantage of that. Bug: 150451422 Bug: 153306490 Test: m nothing Merged-In: If746f375f1c4288ab6b67c7d216593b70258b043 Change-Id: If746f375f1c4288ab6b67c7d216593b70258b043 --- java/java.go | 113 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 70 insertions(+), 43 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index e4b51c00c..fbb195510 100644 --- a/java/java.go +++ b/java/java.go @@ -1866,12 +1866,12 @@ const ( ) // path to the jar file of a java library. Relative to / -func sdkSnapshotFilePathForJar(member android.SdkMember) string { - return sdkSnapshotFilePathForMember(member, jarFileSuffix) +func sdkSnapshotFilePathForJar(name string) string { + return sdkSnapshotFilePathForMember(name, jarFileSuffix) } -func sdkSnapshotFilePathForMember(member android.SdkMember, suffix string) string { - return filepath.Join(javaDir, member.Name()+suffix) +func sdkSnapshotFilePathForMember(name string, suffix string) string { + return filepath.Join(javaDir, name+suffix) } type librarySdkMemberType struct { @@ -1891,32 +1891,46 @@ func (mt *librarySdkMemberType) IsInstance(module android.Module) bool { return ok } -func (mt *librarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) { +func (mt *librarySdkMemberType) AddPrebuiltModule(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) android.BpModule { + return builder.AddPrebuiltModule(member, "java_import") +} - variants := member.Variants() - if len(variants) != 1 { - sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name()) - for _, variant := range variants { - sdkModuleContext.ModuleErrorf(" %q", variant) - } - } - variant := variants[0] +func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { + return &librarySdkMemberProperties{memberType: mt} +} + +type librarySdkMemberProperties struct { + android.SdkMemberPropertiesBase + + memberType *librarySdkMemberType + + library *Library + jarToExport android.Path +} + +func (p *librarySdkMemberProperties) PopulateFromVariant(variant android.SdkAware) { j := variant.(*Library) - exportedJar := mt.jarToExportGetter(j) - snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member) - builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) + p.library = j + p.jarToExport = p.memberType.jarToExportGetter(j) +} + +func (p *librarySdkMemberProperties) AddToPropertySet(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, propertySet android.BpPropertySet) { + if p.jarToExport != nil { + exportedJar := p.jarToExport + snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.library.Name()) + builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) - for _, dir := range j.AidlIncludeDirs() { - // TODO(jiyong): copy parcelable declarations only - aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil) - for _, file := range aidlFiles { - builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file)) + for _, dir := range p.library.AidlIncludeDirs() { + // TODO(jiyong): copy parcelable declarations only + aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil) + for _, file := range aidlFiles { + builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file)) + } } - } - module := builder.AddPrebuiltModule(member, "java_import") - module.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) + propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) + } } var javaHeaderLibsSdkMemberType android.SdkMemberType = &librarySdkMemberType{ @@ -2082,31 +2096,44 @@ func (mt *testSdkMemberType) IsInstance(module android.Module) bool { return ok } -func (mt *testSdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) { - variants := member.Variants() - if len(variants) != 1 { - sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name()) - for _, variant := range variants { - sdkModuleContext.ModuleErrorf(" %q", variant) - } - } - variant := variants[0] - j := variant.(*Test) +func (mt *testSdkMemberType) AddPrebuiltModule(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) android.BpModule { + return builder.AddPrebuiltModule(member, "java_test_import") +} + +func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { + return &testSdkMemberProperties{} +} + +type testSdkMemberProperties struct { + android.SdkMemberPropertiesBase - implementationJars := j.ImplementationJars() + test *Test + jarToExport android.Path +} + +func (p *testSdkMemberProperties) PopulateFromVariant(variant android.SdkAware) { + test := variant.(*Test) + + implementationJars := test.ImplementationJars() if len(implementationJars) != 1 { - panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name())) + panic(fmt.Errorf("there must be only one implementation jar from %q", test.Name())) } - snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member) - builder.CopyToSnapshot(implementationJars[0], snapshotRelativeJavaLibPath) + p.test = test + p.jarToExport = implementationJars[0] +} + +func (p *testSdkMemberProperties) AddToPropertySet(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, propertySet android.BpPropertySet) { + if p.jarToExport != nil { + snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.test.Name()) + builder.CopyToSnapshot(p.jarToExport, snapshotRelativeJavaLibPath) - snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(member, testConfigSuffix) - builder.CopyToSnapshot(j.testConfig, snapshotRelativeTestConfigPath) + snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(p.test.Name(), testConfigSuffix) + builder.CopyToSnapshot(p.test.testConfig, snapshotRelativeTestConfigPath) - module := builder.AddPrebuiltModule(member, "java_test_import") - module.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) - module.AddProperty("test_config", snapshotRelativeTestConfigPath) + propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) + propertySet.AddProperty("test_config", snapshotRelativeTestConfigPath) + } } // java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and -- cgit v1.2.3 From 9b358d7a587ce04d1e9a23d893fa2cac161ecffb Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Mon, 2 Mar 2020 10:16:35 +0000 Subject: Add support for multiple os types Updates the member snapshot creation code to support multiple os types. It basically sorts the variants by os type, then applies the code to optimize the arch properties and then it optimizes the properties that are common across architectures and extracts any properties that are common across os types. The java and cc member types needed to be modified to make the location of the generated files within the snapshot os type dependent when there is more than one os type. That was done by adding an OsPrefix() method to the SdkMemberPropertiesBase which returns the os prefix to use when there is > 1 os type and otherwise returns an empty string. Added three tests, one for cc shared libraries, one for cc binary and one for java header libraries. Bug: 150451422 Bug: 153306490 Test: m nothing Merged-In: I08f5fbdd7852b06c9a9a2f1cfdc364338a3d5bac Change-Id: I08f5fbdd7852b06c9a9a2f1cfdc364338a3d5bac --- java/java.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index fbb195510..e3fa69d26 100644 --- a/java/java.go +++ b/java/java.go @@ -1866,12 +1866,12 @@ const ( ) // path to the jar file of a java library. Relative to / -func sdkSnapshotFilePathForJar(name string) string { - return sdkSnapshotFilePathForMember(name, jarFileSuffix) +func sdkSnapshotFilePathForJar(osPrefix, name string) string { + return sdkSnapshotFilePathForMember(osPrefix, name, jarFileSuffix) } -func sdkSnapshotFilePathForMember(name string, suffix string) string { - return filepath.Join(javaDir, name+suffix) +func sdkSnapshotFilePathForMember(osPrefix, name string, suffix string) string { + return filepath.Join(javaDir, osPrefix, name+suffix) } type librarySdkMemberType struct { @@ -1918,7 +1918,7 @@ func (p *librarySdkMemberProperties) PopulateFromVariant(variant android.SdkAwar func (p *librarySdkMemberProperties) AddToPropertySet(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, propertySet android.BpPropertySet) { if p.jarToExport != nil { exportedJar := p.jarToExport - snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.library.Name()) + snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), p.library.Name()) builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) for _, dir := range p.library.AidlIncludeDirs() { @@ -2125,10 +2125,10 @@ func (p *testSdkMemberProperties) PopulateFromVariant(variant android.SdkAware) func (p *testSdkMemberProperties) AddToPropertySet(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, propertySet android.BpPropertySet) { if p.jarToExport != nil { - snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.test.Name()) + snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), p.test.Name()) builder.CopyToSnapshot(p.jarToExport, snapshotRelativeJavaLibPath) - snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(p.test.Name(), testConfigSuffix) + snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(p.OsPrefix(), p.test.Name(), testConfigSuffix) builder.CopyToSnapshot(p.test.testConfig, snapshotRelativeTestConfigPath) propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) @@ -2336,7 +2336,7 @@ func BinaryHostFactory() android.Module { // type ImportProperties struct { - Jars []string `android:"path"` + Jars []string `android:"path,arch_variant"` Sdk_version *string -- cgit v1.2.3 From 17ab883cb03878acf0429fa858ec4d5739c7a093 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 19 Mar 2020 16:11:18 +0000 Subject: Make new module creation API more flexible Previously passing additional information to the implementations of AddPrebuiltModule() or the SdkMemberProperties interface would have required making changes to the API. This change added an SdkMemberContext object into which additional information can easily be added without requiring changes to existing implementations. The BuildSnapshot() method was not modified because it is deprecated and will be removed in a follow up change. It also switches the API from passing variants as android.SdkAware to android.Module. That is for a couple of reasons: 1) SdkAware is designed for managing the relationship between the module and the SDK, not for generating the output snapshot. As such there is nothing in SdkAware that is needed for generating the output snapshot. 2) Accepting android.Module instead makes it easier to use the underlying code for generating the snapshot module as well as the individual member modules. This is in preparation for a number of improvements and bug fixes in both the snapshot creation code and implementations to address found while trying to built the platform against ART prebuilts. Bug: 151937654 Bug: 153306490 Test: m nothing Merged-In: Iac10f1200c0f283aa35402167eec8f9aeb65a38e Change-Id: Iac10f1200c0f283aa35402167eec8f9aeb65a38e --- java/java.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index e3fa69d26..416cbe5a4 100644 --- a/java/java.go +++ b/java/java.go @@ -1891,8 +1891,8 @@ func (mt *librarySdkMemberType) IsInstance(module android.Module) bool { return ok } -func (mt *librarySdkMemberType) AddPrebuiltModule(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) android.BpModule { - return builder.AddPrebuiltModule(member, "java_import") +func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { + return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_import") } func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { @@ -1908,15 +1908,18 @@ type librarySdkMemberProperties struct { jarToExport android.Path } -func (p *librarySdkMemberProperties) PopulateFromVariant(variant android.SdkAware) { +func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { j := variant.(*Library) p.library = j p.jarToExport = p.memberType.jarToExportGetter(j) } -func (p *librarySdkMemberProperties) AddToPropertySet(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, propertySet android.BpPropertySet) { +func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { if p.jarToExport != nil { + sdkModuleContext := ctx.SdkModuleContext() + builder := ctx.SnapshotBuilder() + exportedJar := p.jarToExport snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), p.library.Name()) builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) @@ -2096,8 +2099,8 @@ func (mt *testSdkMemberType) IsInstance(module android.Module) bool { return ok } -func (mt *testSdkMemberType) AddPrebuiltModule(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) android.BpModule { - return builder.AddPrebuiltModule(member, "java_test_import") +func (mt *testSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { + return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_test_import") } func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { @@ -2111,7 +2114,7 @@ type testSdkMemberProperties struct { jarToExport android.Path } -func (p *testSdkMemberProperties) PopulateFromVariant(variant android.SdkAware) { +func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { test := variant.(*Test) implementationJars := test.ImplementationJars() @@ -2123,8 +2126,10 @@ func (p *testSdkMemberProperties) PopulateFromVariant(variant android.SdkAware) p.jarToExport = implementationJars[0] } -func (p *testSdkMemberProperties) AddToPropertySet(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, propertySet android.BpPropertySet) { +func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { if p.jarToExport != nil { + builder := ctx.SnapshotBuilder() + snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), p.test.Name()) builder.CopyToSnapshot(p.jarToExport, snapshotRelativeJavaLibPath) -- cgit v1.2.3 From c9103930a41317898fb495424ac3b2f9c12d36ff Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 17 Mar 2020 21:04:24 +0000 Subject: Improve consistency of handling java snapshot properties Previously, java snapshot properties (java_library and java_test) relied on the properties not being optimized when there was a single os type and instead being added directly to the common os type properties. However, that means that the behavior is inconsistent for other member types depending on whether there was one os type or not. This change updates the java sdk member handling to support optimization. This involved: 1) Adding AidlIncludeDirs field to librarySdkMemberProperties to specify the aidl include dirs instead of extracting that from the library field. 2) Renaming jarToExport to JarToExport (in both library/testSdkMemberProperties)to allow it to be optimized. 3) Adding MemberType() and Name() methods to SdkMemberPropertiesContext to avoid having to store the former in the properties struct and retrieve the latter from the library/test fields. 4) Removing the now unused library/test fields from the properties structures. 5) Separating the processing of the jar/test config in AddToPropertySet(...) as they may be optimized separately. 6) Ditto for the jar/aidl include dirs. 7) While doing this work I noticed that although the contents of the aidl include dirs are copied into the snapshot the java_import does not make use of them. Raised bug 151933053 and added TODO to track that work. Bug: 142935992 Bug: 153306490 Test: m nothing Merged-In: Iba9799e111ca5672b2133568163d8c49837ba9cd Change-Id: Iba9799e111ca5672b2133568163d8c49837ba9cd --- java/java.go | 57 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 416cbe5a4..20e01f2af 100644 --- a/java/java.go +++ b/java/java.go @@ -1896,35 +1896,38 @@ func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, } func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { - return &librarySdkMemberProperties{memberType: mt} + return &librarySdkMemberProperties{} } type librarySdkMemberProperties struct { android.SdkMemberPropertiesBase - memberType *librarySdkMemberType - - library *Library - jarToExport android.Path + JarToExport android.Path + AidlIncludeDirs android.Paths } func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { j := variant.(*Library) - p.library = j - p.jarToExport = p.memberType.jarToExportGetter(j) + p.JarToExport = ctx.MemberType().(*librarySdkMemberType).jarToExportGetter(j) + p.AidlIncludeDirs = j.AidlIncludeDirs() } func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { - if p.jarToExport != nil { - sdkModuleContext := ctx.SdkModuleContext() - builder := ctx.SnapshotBuilder() + builder := ctx.SnapshotBuilder() - exportedJar := p.jarToExport - snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), p.library.Name()) + exportedJar := p.JarToExport + if exportedJar != nil { + snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name()) builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) - for _, dir := range p.library.AidlIncludeDirs() { + propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) + } + + aidlIncludeDirs := p.AidlIncludeDirs + if len(aidlIncludeDirs) != 0 { + sdkModuleContext := ctx.SdkModuleContext() + for _, dir := range aidlIncludeDirs { // TODO(jiyong): copy parcelable declarations only aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil) for _, file := range aidlFiles { @@ -1932,7 +1935,7 @@ func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberConte } } - propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) + // TODO(b/151933053) - add aidl include dirs property } } @@ -2110,8 +2113,8 @@ func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberPr type testSdkMemberProperties struct { android.SdkMemberPropertiesBase - test *Test - jarToExport android.Path + JarToExport android.Path + TestConfig android.Path } func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { @@ -2122,21 +2125,25 @@ func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberConte panic(fmt.Errorf("there must be only one implementation jar from %q", test.Name())) } - p.test = test - p.jarToExport = implementationJars[0] + p.JarToExport = implementationJars[0] + p.TestConfig = test.testConfig } func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { - if p.jarToExport != nil { - builder := ctx.SnapshotBuilder() - - snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), p.test.Name()) - builder.CopyToSnapshot(p.jarToExport, snapshotRelativeJavaLibPath) + builder := ctx.SnapshotBuilder() - snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(p.OsPrefix(), p.test.Name(), testConfigSuffix) - builder.CopyToSnapshot(p.test.testConfig, snapshotRelativeTestConfigPath) + exportedJar := p.JarToExport + if exportedJar != nil { + snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name()) + builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) + } + + testConfig := p.TestConfig + if testConfig != nil { + snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(p.OsPrefix(), ctx.Name(), testConfigSuffix) + builder.CopyToSnapshot(testConfig, snapshotRelativeTestConfigPath) propertySet.AddProperty("test_config", snapshotRelativeTestConfigPath) } } -- cgit v1.2.3 From b20ad0a7d4c8aa6d88124bacc45555113fa02f70 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 31 Mar 2020 15:23:40 +0100 Subject: Stop requiring apex_available on java_library members of sdks Previously, adding java_library to an sdk required that the names of any APEXes that transitively compiled against it were added to its apex_available property. This change removes that requirement. Also corrects the dependency path in the TestApexAvailable_IndirectDep error which previously passed through "shared from static" static dependency tags even though those are explicitly NOT followed when checking apex_available settings. Bug: 152878661 Bug: 153306490 Test: m droid Merged-In: I995ed38956c1bc210b09494812de012fed9f9232 Change-Id: I995ed38956c1bc210b09494812de012fed9f9232 --- java/java.go | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 20e01f2af..57ed29d14 100644 --- a/java/java.go +++ b/java/java.go @@ -1764,11 +1764,6 @@ func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu if staticLibTag == ctx.OtherModuleDependencyTag(dep) { return true } - // Also, a dependency to an sdk member is also considered as such. This is required because - // sdk members should be mutated into APEXes. Refer to sdk.sdkDepsReplaceMutator. - if sa, ok := dep.(android.SdkAware); ok && sa.IsInAnySdk() { - return true - } return false } @@ -2508,11 +2503,6 @@ func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu if staticLibTag == ctx.OtherModuleDependencyTag(dep) { return true } - // Also, a dependency to an sdk member is also considered as such. This is required because - // sdk members should be mutated into APEXes. Refer to sdk.sdkDepsReplaceMutator. - if sa, ok := dep.(android.SdkAware); ok && sa.IsInAnySdk() { - return true - } return false } -- cgit v1.2.3 From d99540b254789c47862d0d7cf8e45e44e7b81115 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 22 Apr 2020 11:44:34 -0700 Subject: Repeat kapt processor argument for multiple processors kapt claims to support a comma separated list of annotation processors, but it errors if multiple annotation processors are given. Surrounding the the list with {} does not error, but it also doesn't even warn if the second element in the list is garbage, so it may not be running the second processor. Repeat the processor argument for each annotation processor class instead. Bug: 154736649 Test: TestKapt Test: m checkbuild Change-Id: I4c7c161dbf867d7fba1aaf16fd5e502647e3f682 Merged-In: I4c7c161dbf867d7fba1aaf16fd5e502647e3f682 (cherry picked from commit 5a11686e64d7c6665589458a94f183d0823dc833) --- java/java.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 57ed29d14..1c2e22a51 100644 --- a/java/java.go +++ b/java/java.go @@ -1134,7 +1134,8 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB flags.java9Classpath = append(flags.java9Classpath, deps.java9Classpath...) flags.processorPath = append(flags.processorPath, deps.processorPath...) - flags.processor = strings.Join(deps.processorClasses, ",") + flags.processors = append(flags.processors, deps.processorClasses...) + flags.processors = android.FirstUniqueStrings(flags.processors) if len(flags.bootClasspath) == 0 && ctx.Host() && !flags.javaVersion.usesJavaModules() && decodeSdkDep(ctx, sdkContext(j)).hasStandardLibs() { @@ -1269,7 +1270,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { srcJars = append(srcJars, kaptSrcJar) // Disable annotation processing in javac, it's already been handled by kapt flags.processorPath = nil - flags.processor = "" + flags.processors = nil } kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName) -- cgit v1.2.3 From 062ed7eaa11123cca7dcd608df5148718b7e4fca Mon Sep 17 00:00:00 2001 From: Jaewoong Jung Date: Sun, 26 Apr 2020 15:10:51 -0700 Subject: Add defaults support to runtime_resource_overlay. Bug: 154956723 Test: app_test.go Change-Id: Ida29035ef45ec188c95a07a8bccaaa77eea486d7 --- java/java.go | 1 + 1 file changed, 1 insertion(+) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 1c2e22a51..5d7780720 100644 --- a/java/java.go +++ b/java/java.go @@ -2745,6 +2745,7 @@ func DefaultsFactory() android.Module { &sdkLibraryProperties{}, &DexImportProperties{}, &android.ApexProperties{}, + &RuntimeResourceOverlayProperties{}, ) android.InitDefaultsModule(module) -- cgit v1.2.3 From 2eedf623ff3fe9f104d4fd07754c3b15b712d0e1 Mon Sep 17 00:00:00 2001 From: Artur Satayev Date: Wed, 15 Apr 2020 17:29:42 +0100 Subject: Ensure APEX's Java deps use stable SDKs. Test: m Bug: 153333044 Change-Id: Ib1acf3073e96fe23c92d292ec0b1a91e2cd408db Merged-In: Ib1acf3073e96fe23c92d292ec0b1a91e2cd408db Exempt-From-Owner-Approval: cp from aosp (cherry picked from commit 8cf899afcc69643f63350bc9f9f92677bb8feabd) --- java/java.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 5d7780720..6589721f8 100644 --- a/java/java.go +++ b/java/java.go @@ -86,6 +86,14 @@ func RegisterJavaBuildComponents(ctx android.RegistrationContext) { ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory) } +func (j *Module) CheckStableSdkVersion() error { + sdkVersion := j.sdkVersion() + if sdkVersion.stable() { + return nil + } + return fmt.Errorf("non stable SDK %v", sdkVersion) +} + func (j *Module) checkSdkVersions(ctx android.ModuleContext) { if j.SocSpecific() || j.DeviceSpecific() || (j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) { -- cgit v1.2.3 From 388d39ba9a13db914a26d70a92e6074216842b43 Mon Sep 17 00:00:00 2001 From: Artur Satayev Date: Mon, 27 Apr 2020 18:53:18 +0100 Subject: Introduce min_sdk_version to deps info. Bug: 149622332 Test: m Change-Id: Ie6568cb8a82d5cca9a3dc91b5a068abf4b0632dc Merged-In: Ie6568cb8a82d5cca9a3dc91b5a068abf4b0632dc Exempt-From-Owner-Approval: cp from aosp (cherry picked from commit 480e25b74f9e7101ff3083bd4517f15ac0a6a1b9) --- java/java.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 6589721f8..549519792 100644 --- a/java/java.go +++ b/java/java.go @@ -604,6 +604,10 @@ func (j *Module) targetSdkVersion() sdkSpec { return j.sdkVersion() } +func (j *Module) MinSdkVersion() string { + return j.minSdkVersion().version.String() +} + func (j *Module) AvailableFor(what string) bool { if what == android.AvailableToPlatform && Bool(j.deviceProperties.Hostdex) { // Exception: for hostdex: true libraries, the platform variant is created @@ -2395,6 +2399,10 @@ func (j *Import) minSdkVersion() sdkSpec { return j.sdkVersion() } +func (j *Import) MinSdkVersion() string { + return j.minSdkVersion().version.String() +} + func (j *Import) Prebuilt() *android.Prebuilt { return &j.prebuilt } -- cgit v1.2.3 From 08385bf9ac57ca1f94c5be3fc1379556243a1768 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 6 May 2020 10:23:19 +0100 Subject: Retry: Detect invalid arch specific properties in snapshot Previously, the snapshot code did not know whether a specific property could be arch specific or not and assumed that they all were which meant that it could generate snapshots containing arch specific values for properties that are not arch specific and so would fail when unpacked. This change requires arch specific fields in SdkMemberProperties to be tagged as such using `android:"arch_variant"` (just as in module input property structures). Any property without that must have properties that are common across all variants. Bug: 155628860 Test: m nothing Merged-In: I3df60f0b53ba02ec2c55a80c7da058eac5909d26 Change-Id: I3df60f0b53ba02ec2c55a80c7da058eac5909d26 (cherry picked from commit 864e1b45dbf90e0b79b767be385e5f57f3dbdd25) --- java/java.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 549519792..1dba1c078 100644 --- a/java/java.go +++ b/java/java.go @@ -1910,7 +1910,7 @@ func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMembe type librarySdkMemberProperties struct { android.SdkMemberPropertiesBase - JarToExport android.Path + JarToExport android.Path `android:"arch_variant"` AidlIncludeDirs android.Paths } -- cgit v1.2.3 From 1a724e666fef89d0797df279546b55d47db35ae8 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 8 May 2020 13:44:43 +0100 Subject: java_sdk_library: Delegate component module to naming scheme Adds a naming scheme abstraction to which the java_sdk_library/import will delegate the task of creating the names of their component modules. The naming scheme can be selected in a module definition but for now the only supported option is "default". Test: m nothing Bug: 155480189 Merged-In: I708657661188ea4a14a4dd8c6bc4b46237bbe5e0 Change-Id: I708657661188ea4a14a4dd8c6bc4b46237bbe5e0 (cherry picked from commit 1b1e8069ec08a9f54cf0f8aa4ed95cab2781b3db) --- java/java.go | 1 + 1 file changed, 1 insertion(+) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 1dba1c078..38cde2afe 100644 --- a/java/java.go +++ b/java/java.go @@ -2759,6 +2759,7 @@ func DefaultsFactory() android.Module { &ImportProperties{}, &AARImportProperties{}, &sdkLibraryProperties{}, + &commonToSdkLibraryAndImportProperties{}, &DexImportProperties{}, &android.ApexProperties{}, &RuntimeResourceOverlayProperties{}, -- cgit v1.2.3 From db22475ecb59f5228083ad9ba7f4d1ba2606083b Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 14 May 2020 18:05:32 -0700 Subject: Use system modules for prebuilt SDKs >=30 Prebuilt SDKs >=30 now contain core-for-system-modules.jar, convert them to system modules and use them when compiling against the SDK to allow using javac -source 1.9 -target 1.9. Bug: 117069453 Test: TestClasspath Change-Id: Iebadad5980b952ed91c3ffd56cff1ce1827d3247 --- java/java.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 549519792..517924847 100644 --- a/java/java.go +++ b/java/java.go @@ -629,13 +629,15 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { } } else if sdkDep.useModule { ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...) - ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules) ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...) if j.deviceProperties.EffectiveOptimizeEnabled() && sdkDep.hasStandardLibs() { ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...) ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...) } } + if sdkDep.systemModules != "" { + ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules) + } if ctx.ModuleName() == "android_stubs_current" || ctx.ModuleName() == "android_system_stubs_current" || @@ -1038,19 +1040,10 @@ func addPlugins(deps *deps, pluginJars android.Paths, pluginClasses ...string) { } func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) javaVersion { - sdk, err := sdkContext.sdkVersion().effectiveVersion(ctx) - if err != nil { - ctx.PropertyErrorf("sdk_version", "%s", err) - } if javaVersion != "" { return normalizeJavaVersion(ctx, javaVersion) - } else if ctx.Device() && sdk <= 23 { - return JAVA_VERSION_7 - } else if ctx.Device() && sdk <= 29 { - return JAVA_VERSION_8 - } else if ctx.Device() && ctx.Config().UnbundledBuildUsePrebuiltSdks() { - // TODO(b/142896162): once we have prebuilt system modules we can use 1.9 for unbundled builds - return JAVA_VERSION_8 + } else if ctx.Device() { + return sdkContext.sdkVersion().defaultJavaLanguageVersion(ctx) } else { return JAVA_VERSION_9 } -- cgit v1.2.3 From eb03296b57a414b5c327ae6b4057f279f6903439 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 13 May 2020 11:05:02 -0700 Subject: Don't use SDK variant for vendor JNI libraries Vendor JNI libraries already have stable APIs enforced by the VNDK, they shouldn't use SDK variants. Bug: 156225490 Test: TestJNISDK Change-Id: I21ba67e8e9fb05016caf5888129adc1a939545c2 Merged-In: I21ba67e8e9fb05016caf5888129adc1a939545c2 (cherry picked from commit c2d24050c5e3a09b7bc5236d15f24afa2405911f) --- java/java.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 38cde2afe..066e09afb 100644 --- a/java/java.go +++ b/java/java.go @@ -95,8 +95,7 @@ func (j *Module) CheckStableSdkVersion() error { } func (j *Module) checkSdkVersions(ctx android.ModuleContext) { - if j.SocSpecific() || j.DeviceSpecific() || - (j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) { + if j.RequiresStableAPIs(ctx) { if sc, ok := ctx.Module().(sdkContext); ok { if !sc.sdkVersion().specified() { ctx.PropertyErrorf("sdk_version", -- cgit v1.2.3 From ba60625021fc6bf429c00b37dfd79b6082861ab7 Mon Sep 17 00:00:00 2001 From: easoncylee Date: Thu, 30 Apr 2020 14:57:06 +0800 Subject: Add test_mainline_modules to the auto-gen test config(AndroidJUnitTest only). To support parameterized mainline modules in Test Mapping, we plan to add a new parameter called test_mainline_modules in build system to auto-generate the test config based on the parameter. For detailed information: go/test-mapping-mainline-gcl (search for auto-generated pattern) Bug: 155238134 Test: add "test_mainline_modules: [some.apk]" to TetheringTests, and build the modules, confirm the parameterized option is added in the test config. Change-Id: I41ba8749ce46da62db402a8b8a555d4874e1cfc0 Merged-In: I41ba8749ce46da62db402a8b8a555d4874e1cfc0 --- java/java.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index a5d69e304..6141a40b0 100644 --- a/java/java.go +++ b/java/java.go @@ -2029,6 +2029,10 @@ type testProperties struct { // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true // explicitly. Auto_gen_config *bool + + // Add parameterized mainline modules to auto generated test config. The options will be + // handled by TradeFed to do downloading and installing the specified modules on the device. + Test_mainline_modules []string } type testHelperLibraryProperties struct { -- cgit v1.2.3 From c8f2f186d1603f992bedbaa1f878bb03dc7c512b Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Sun, 17 May 2020 08:34:50 +0100 Subject: Extract common behavior between Module and Import Although the duplication being eliminated here is minimal follow up changes will add more functionality that is common to Module and Import. Test: m nothing Bug: 156723295 Merged-In: I1733405526764272beba63470a9bc8a958d41024 Change-Id: I1733405526764272beba63470a9bc8a958d41024 (cherry picked from commit 0d3c2e136b24272a51feed84eec947b7f42cf057) --- java/java.go | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index a5d69e304..da9bd3dfe 100644 --- a/java/java.go +++ b/java/java.go @@ -354,6 +354,22 @@ func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool { return BoolDefault(me.Optimize.Enabled, me.Optimize.EnabledByDefault) } +// Functionality common to Module and Import +type embeddableInModuleAndImport struct { +} + +// Module/Import's DepIsInSameApex(...) delegates to this method. +// +// This cannot implement DepIsInSameApex(...) directly as that leads to ambiguity with +// the one provided by ApexModuleBase. +func (e *embeddableInModuleAndImport) depIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { + // dependencies other than the static linkage are all considered crossing APEX boundary + if staticLibTag == ctx.OtherModuleDependencyTag(dep) { + return true + } + return false +} + // Module contains the properties and members used by all java module types type Module struct { android.ModuleBase @@ -361,6 +377,9 @@ type Module struct { android.ApexModuleBase android.SdkBase + // Functionality common to Module and Import. + embeddableInModuleAndImport + properties CompilerProperties protoProperties android.ProtoProperties deviceProperties CompilerDeviceProperties @@ -1765,11 +1784,7 @@ func (j *Module) hasCode(ctx android.ModuleContext) bool { } func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { - // Dependencies other than the static linkage are all considered crossing APEX boundary - if staticLibTag == ctx.OtherModuleDependencyTag(dep) { - return true - } - return false + return j.depIsInSameApex(ctx, dep) } func (j *Module) Stem() string { @@ -2377,6 +2392,9 @@ type Import struct { prebuilt android.Prebuilt android.SdkBase + // Functionality common to Module and Import. + embeddableInModuleAndImport + properties ImportProperties combinedClasspathFile android.Path @@ -2508,11 +2526,7 @@ func (j *Import) SrcJarArgs() ([]string, android.Paths) { } func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { - // dependencies other than the static linkage are all considered crossing APEX boundary - if staticLibTag == ctx.OtherModuleDependencyTag(dep) { - return true - } - return false + return j.depIsInSameApex(ctx, dep) } // Add compile time check for interface implementation -- cgit v1.2.3 From 442a47552193e2893dbbc1b67a9a1bbd08903314 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 15 May 2020 10:20:31 +0100 Subject: Improve tracking of exported sdk libraries The build tracks the java_sdk_library/_import modules that are referenced by libraries so that it can ensure that any Android app that includes code that depends on one of those modules has the appropriate entry in their manifest. Unfortunately, there were a couple of issues with that: 1) It only tracks direct references to the java_sdk_library module itself, e.g. android.test.mock. Direct references to the stubs module, e.g. android.test.mock.stubs were not tracked. Making it possible for Android apps to reference libraries which would not be available at runtime. 2) The logic for determining whether something was a java_sdk_library was repeated in a number of places making it difficult to allow java_sdk_library/_import instances to determine whether they should be treated as an Android shared library. 3) It tracks (and could use) even those java_sdk_library instances which do not represent a shared library, e.g. the ones that set api_only: true. While this change will simplifty fixing that the actual issue will be fixed in a follow up change. Changes: * Added EmbeddableSdkLibraryComponent and embedded it into java_sdk_library/_import, java_library and java_import. It provides the common code to minimize duplication. It contains an SdkLibraryToImplicitlyTrack field that if set will cause any references to the containing module to add the SdkLibraryParent to the list of implicit sdk libraries being tracked. * Changed code that assumed that anything that implemented SdkLibraryDependency required tracking to use the OptionalImplicitSdkLibrary() method to get the optional name of the sdk library to track. That will allow a follow up change to return nil from that method to exclude an sdk library from being tracked. * Moved SdkLibraryDependency from java.go to sdk_library.go as that is a better place for it to be. * Changed the stubs java_library/java_import creation code to initialize the SdkLibraryToImplicitlyTrack field with the name of the creating module. * Initialized the SdkLibraryToImplicitlyTrack field in the java_sdk_library/_import so that direct references to them will be tracked too. * Added tests to verify that direct access to the .stubs child of both java_sdk_library and java_sdk_library_import are tracked properly. Test: atest CtsProviderTestCases - which relies on android.test.mock being implicitly tracked to verify that I had not broken anything. Used aapt2 dump badging to read the manifest. m nothing - to run the new tests which failed before fixing the code. Bug: 156723295 Merged-In: Ia99def91e9b74d2ed0a777de04b476c00ea0393d Change-Id: Ia99def91e9b74d2ed0a777de04b476c00ea0393d (cherry picked from commit 859fe961b015259368e9994969b569eb34f54ddc) --- java/java.go | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index da9bd3dfe..00b11f77a 100644 --- a/java/java.go +++ b/java/java.go @@ -355,7 +355,17 @@ func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool { } // Functionality common to Module and Import +// +// It is embedded in Module so its functionality can be used by methods in Module +// but it is currently only initialized by Import and Library. type embeddableInModuleAndImport struct { + + // Functionality related to this being used as a component of a java_sdk_library. + EmbeddableSdkLibraryComponent +} + +func (e *embeddableInModuleAndImport) initModuleAndImport(moduleBase *android.ModuleBase) { + e.initSdkLibraryComponent(moduleBase) } // Module/Import's DepIsInSameApex(...) delegates to this method. @@ -496,11 +506,6 @@ type Dependency interface { JacocoReportClassesFile() android.Path } -type SdkLibraryDependency interface { - SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths - SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths -} - type xref interface { XrefJavaFiles() android.Paths } @@ -930,6 +935,12 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { } } + // If this is a component library (stubs, etc.) for a java_sdk_library then + // add the name of that java_sdk_library to the exported sdk libs to make sure + // that, if necessary, a element for that java_sdk_library is + // added to the Android manifest. + j.exportedSdkLibs = append(j.exportedSdkLibs, j.OptionalImplicitSdkLibrary()...) + ctx.VisitDirectDeps(func(module android.Module) { otherName := ctx.OtherModuleName(module) tag := ctx.OtherModuleDependencyTag(module) @@ -949,7 +960,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { case libTag: deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...) // names of sdk libs that are directly depended are exported - j.exportedSdkLibs = append(j.exportedSdkLibs, otherName) + j.exportedSdkLibs = append(j.exportedSdkLibs, dep.OptionalImplicitSdkLibrary()...) case staticLibTag: ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName) } @@ -1990,6 +2001,8 @@ func LibraryFactory() android.Module { &module.Module.protoProperties, &module.libraryProperties) + module.initModuleAndImport(&module.ModuleBase) + android.InitApexModule(module) android.InitSdkAwareModule(module) InitJavaModule(module, android.HostAndDeviceSupported) @@ -2451,6 +2464,12 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { } j.combinedClasspathFile = outputFile + // If this is a component library (impl, stubs, etc.) for a java_sdk_library then + // add the name of that java_sdk_library to the exported sdk libs to make sure + // that, if necessary, a element for that java_sdk_library is + // added to the Android manifest. + j.exportedSdkLibs = append(j.exportedSdkLibs, j.OptionalImplicitSdkLibrary()...) + ctx.VisitDirectDeps(func(module android.Module) { otherName := ctx.OtherModuleName(module) tag := ctx.OtherModuleDependencyTag(module) @@ -2567,6 +2586,8 @@ func ImportFactory() android.Module { module.AddProperties(&module.properties) + module.initModuleAndImport(&module.ModuleBase) + android.InitPrebuiltModule(module, &module.properties.Jars) android.InitApexModule(module) android.InitSdkAwareModule(module) -- cgit v1.2.3 From 98c71228f1f81cba80f17a73df6e7ace57e83a30 Mon Sep 17 00:00:00 2001 From: David Srbecky Date: Wed, 20 May 2020 22:20:28 +0100 Subject: Allow the user to explicitly set the java Uncompress_dex property. ART tests need to explicitly control the compression. Bug: 157239179 Test: "atest ArtGtestsTarget" with http://go/aog/1302773 Change-Id: I4490aa0a61fa71f830feb6a46dffd8d20fccfc66 --- java/java.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index da9bd3dfe..26b785c9e 100644 --- a/java/java.go +++ b/java/java.go @@ -342,8 +342,13 @@ type CompilerDeviceProperties struct { // set the name of the output Stem *string - UncompressDex bool `blueprint:"mutated"` - IsSDKLibrary bool `blueprint:"mutated"` + // Keep the data uncompressed. We always need uncompressed dex for execution, + // so this might actually save space by avoiding storing the same data twice. + // This defaults to reasonable value based on module and should not be set. + // It exists only to support ART tests. + Uncompress_dex *bool + + IsSDKLibrary bool `blueprint:"mutated"` // If true, generate the signature file of APK Signing Scheme V4, along side the signed APK file. // Defaults to false. @@ -1560,7 +1565,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { // Hidden API CSV generation and dex encoding dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile, - j.deviceProperties.UncompressDex) + proptools.Bool(j.deviceProperties.Uncompress_dex)) // merge dex jar with resources if necessary if j.resourceJar != nil { @@ -1568,7 +1573,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName) TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{}, false, nil, nil) - if j.deviceProperties.UncompressDex { + if *j.deviceProperties.Uncompress_dex { combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName) TransformZipAlign(ctx, combinedAlignedJar, combinedJar) dexOutputFile = combinedAlignedJar @@ -1845,8 +1850,11 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.checkSdkVersions(ctx) j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar") j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary - j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter) - j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex + if j.deviceProperties.Uncompress_dex == nil { + // If the value was not force-set by the user, use reasonable default based on the module. + j.deviceProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter)) + } + j.dexpreopter.uncompressedDex = *j.deviceProperties.Uncompress_dex j.compile(ctx, nil) exclusivelyForApex := android.InAnyApex(ctx.ModuleName()) && !j.IsForPlatform() -- cgit v1.2.3 From ed0314270d226d5a8769439a607f79b8c974f793 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Mon, 25 May 2020 01:55:59 +0000 Subject: Revert "Improve tracking of exported sdk libraries" Revert submission 11569833 Reason for revert: Broke presubmit: b/157231582 Reverted Changes: Ia99def91e:Improve tracking of exported sdk libraries If91b4d106:java_sdk_library: Do not expose stubs implementati... Id6d76e56c:java_sdk_library: Access outputs using tags Change-Id: I3a07d412e795df512c430e4d2ed221f4d17e904a --- java/java.go | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 00b11f77a..da9bd3dfe 100644 --- a/java/java.go +++ b/java/java.go @@ -355,17 +355,7 @@ func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool { } // Functionality common to Module and Import -// -// It is embedded in Module so its functionality can be used by methods in Module -// but it is currently only initialized by Import and Library. type embeddableInModuleAndImport struct { - - // Functionality related to this being used as a component of a java_sdk_library. - EmbeddableSdkLibraryComponent -} - -func (e *embeddableInModuleAndImport) initModuleAndImport(moduleBase *android.ModuleBase) { - e.initSdkLibraryComponent(moduleBase) } // Module/Import's DepIsInSameApex(...) delegates to this method. @@ -506,6 +496,11 @@ type Dependency interface { JacocoReportClassesFile() android.Path } +type SdkLibraryDependency interface { + SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths + SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths +} + type xref interface { XrefJavaFiles() android.Paths } @@ -935,12 +930,6 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { } } - // If this is a component library (stubs, etc.) for a java_sdk_library then - // add the name of that java_sdk_library to the exported sdk libs to make sure - // that, if necessary, a element for that java_sdk_library is - // added to the Android manifest. - j.exportedSdkLibs = append(j.exportedSdkLibs, j.OptionalImplicitSdkLibrary()...) - ctx.VisitDirectDeps(func(module android.Module) { otherName := ctx.OtherModuleName(module) tag := ctx.OtherModuleDependencyTag(module) @@ -960,7 +949,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { case libTag: deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...) // names of sdk libs that are directly depended are exported - j.exportedSdkLibs = append(j.exportedSdkLibs, dep.OptionalImplicitSdkLibrary()...) + j.exportedSdkLibs = append(j.exportedSdkLibs, otherName) case staticLibTag: ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName) } @@ -2001,8 +1990,6 @@ func LibraryFactory() android.Module { &module.Module.protoProperties, &module.libraryProperties) - module.initModuleAndImport(&module.ModuleBase) - android.InitApexModule(module) android.InitSdkAwareModule(module) InitJavaModule(module, android.HostAndDeviceSupported) @@ -2464,12 +2451,6 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { } j.combinedClasspathFile = outputFile - // If this is a component library (impl, stubs, etc.) for a java_sdk_library then - // add the name of that java_sdk_library to the exported sdk libs to make sure - // that, if necessary, a element for that java_sdk_library is - // added to the Android manifest. - j.exportedSdkLibs = append(j.exportedSdkLibs, j.OptionalImplicitSdkLibrary()...) - ctx.VisitDirectDeps(func(module android.Module) { otherName := ctx.OtherModuleName(module) tag := ctx.OtherModuleDependencyTag(module) @@ -2586,8 +2567,6 @@ func ImportFactory() android.Module { module.AddProperties(&module.properties) - module.initModuleAndImport(&module.ModuleBase) - android.InitPrebuiltModule(module, &module.properties.Jars) android.InitApexModule(module) android.InitSdkAwareModule(module) -- cgit v1.2.3 From 64e61997569dde18f70abac001942ee677bccab0 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 15 May 2020 10:20:31 +0100 Subject: Retry: "Improve tracking of exported sdk libraries" The build tracks the java_sdk_library/_import modules that are referenced by libraries so that it can ensure that any Android app that includes code that depends on one of those modules has the appropriate entry in their manifest. Unfortunately, there were a couple of issues with that: 1) It only tracks direct references to the java_sdk_library module itself, e.g. android.test.mock. Direct references to the stubs module, e.g. android.test.mock.stubs were not tracked. Making it possible for Android apps to reference libraries which would not be available at runtime. 2) The logic for determining whether something was a java_sdk_library was repeated in a number of places making it difficult to allow java_sdk_library/_import instances to determine whether they should be treated as an Android shared library. 3) It tracks (and could use) even those java_sdk_library instances which do not represent a shared library, e.g. the ones that set api_only: true. While this change will simplifty fixing that the actual issue will be fixed in a follow up change. Changes: * Added EmbeddableSdkLibraryComponent and embedded it into java_sdk_library/_import, java_library and java_import. It provides the common code to minimize duplication. It contains an SdkLibraryToImplicitlyTrack field that if set will cause any references to the containing module to add the SdkLibraryParent to the list of implicit sdk libraries being tracked. * Changed code that assumed that anything that implemented SdkLibraryDependency required tracking to use the OptionalImplicitSdkLibrary() method to get the optional name of the sdk library to track. That will allow a follow up change to return nil from that method to exclude an sdk library from being tracked. * Moved SdkLibraryDependency from java.go to sdk_library.go as that is a better place for it to be. * Changed the stubs java_library/java_import creation code to initialize the SdkLibraryToImplicitlyTrack field with the name of the creating module. * Initialized the SdkLibraryToImplicitlyTrack field in the java_sdk_library/_import so that direct references to them will be tracked too. * Added tests to verify that direct access to the .stubs child of both java_sdk_library and java_sdk_library_import are tracked properly. Test: atest CtsProviderTestCases - which relies on android.test.mock being implicitly tracked to verify that I had not broken anything. Used aapt2 dump badging to read the manifest. m nothing - to run the new tests which failed before fixing the code. Bug: 156723295 (cherry picked from commit 859fe961b015259368e9994969b569eb34f54ddc) Change-Id: I760a9ac72856e3a07a497ce40db70c7e70106837 --- java/java.go | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index da9bd3dfe..00b11f77a 100644 --- a/java/java.go +++ b/java/java.go @@ -355,7 +355,17 @@ func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool { } // Functionality common to Module and Import +// +// It is embedded in Module so its functionality can be used by methods in Module +// but it is currently only initialized by Import and Library. type embeddableInModuleAndImport struct { + + // Functionality related to this being used as a component of a java_sdk_library. + EmbeddableSdkLibraryComponent +} + +func (e *embeddableInModuleAndImport) initModuleAndImport(moduleBase *android.ModuleBase) { + e.initSdkLibraryComponent(moduleBase) } // Module/Import's DepIsInSameApex(...) delegates to this method. @@ -496,11 +506,6 @@ type Dependency interface { JacocoReportClassesFile() android.Path } -type SdkLibraryDependency interface { - SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths - SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths -} - type xref interface { XrefJavaFiles() android.Paths } @@ -930,6 +935,12 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { } } + // If this is a component library (stubs, etc.) for a java_sdk_library then + // add the name of that java_sdk_library to the exported sdk libs to make sure + // that, if necessary, a element for that java_sdk_library is + // added to the Android manifest. + j.exportedSdkLibs = append(j.exportedSdkLibs, j.OptionalImplicitSdkLibrary()...) + ctx.VisitDirectDeps(func(module android.Module) { otherName := ctx.OtherModuleName(module) tag := ctx.OtherModuleDependencyTag(module) @@ -949,7 +960,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { case libTag: deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...) // names of sdk libs that are directly depended are exported - j.exportedSdkLibs = append(j.exportedSdkLibs, otherName) + j.exportedSdkLibs = append(j.exportedSdkLibs, dep.OptionalImplicitSdkLibrary()...) case staticLibTag: ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName) } @@ -1990,6 +2001,8 @@ func LibraryFactory() android.Module { &module.Module.protoProperties, &module.libraryProperties) + module.initModuleAndImport(&module.ModuleBase) + android.InitApexModule(module) android.InitSdkAwareModule(module) InitJavaModule(module, android.HostAndDeviceSupported) @@ -2451,6 +2464,12 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { } j.combinedClasspathFile = outputFile + // If this is a component library (impl, stubs, etc.) for a java_sdk_library then + // add the name of that java_sdk_library to the exported sdk libs to make sure + // that, if necessary, a element for that java_sdk_library is + // added to the Android manifest. + j.exportedSdkLibs = append(j.exportedSdkLibs, j.OptionalImplicitSdkLibrary()...) + ctx.VisitDirectDeps(func(module android.Module) { otherName := ctx.OtherModuleName(module) tag := ctx.OtherModuleDependencyTag(module) @@ -2567,6 +2586,8 @@ func ImportFactory() android.Module { module.AddProperties(&module.properties) + module.initModuleAndImport(&module.ModuleBase) + android.InitPrebuiltModule(module, &module.properties.Jars) android.InitApexModule(module) android.InitSdkAwareModule(module) -- cgit v1.2.3 From ac103461a47e86665ec78df6e5d9792d7464a57b Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Tue, 19 May 2020 12:06:48 +0100 Subject: Improve the structure of the link check method Match by name first, then by kind. Bug: 157010342 Test: m Change-Id: Ic337a073c3bd14ac03b1d899aeb612247a708495 --- java/java.go | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index da9bd3dfe..726d4869b 100644 --- a/java/java.go +++ b/java/java.go @@ -827,41 +827,42 @@ type linkTypeContext interface { } func (m *Module) getLinkType(name string) (ret linkType, stubs bool) { - ver := m.sdkVersion() - switch { - case name == "core.current.stubs" || name == "core.platform.api.stubs" || - name == "stub-annotations" || name == "private-stub-annotations-jar" || - name == "core-lambda-stubs" || name == "core-generated-annotation-stubs": + switch name { + case "core.current.stubs", "core.platform.api.stubs", "stub-annotations", + "private-stub-annotations-jar", "core-lambda-stubs", "core-generated-annotation-stubs": return javaCore, true - case ver.kind == sdkCore: - return javaCore, false - case name == "android_system_stubs_current": + case "android_stubs_current": + return javaSdk, true + case "android_system_stubs_current": return javaSystem, true - case ver.kind == sdkSystem: - return javaSystem, false - case name == "android_test_stubs_current": + case "android_module_lib_stubs_current": + return javaModule, true + case "android_system_server_stubs_current": + return javaSystemServer, true + case "android_test_stubs_current": return javaSystem, true - case ver.kind == sdkTest: - return javaPlatform, false - case name == "android_stubs_current": - return javaSdk, true - case ver.kind == sdkPublic: + } + + ver := m.sdkVersion() + switch ver.kind { + case sdkCore: + return javaCore, false + case sdkSystem: + return javaSystem, false + case sdkPublic: return javaSdk, false - case name == "android_module_lib_stubs_current": - return javaModule, true - case ver.kind == sdkModule: + case sdkModule: return javaModule, false - case name == "android_system_server_stubs_current": - return javaSystemServer, true - case ver.kind == sdkSystemServer: + case sdkSystemServer: return javaSystemServer, false - case ver.kind == sdkPrivate || ver.kind == sdkNone || ver.kind == sdkCorePlatform: + case sdkPrivate, sdkNone, sdkCorePlatform, sdkTest: return javaPlatform, false - case !ver.valid(): + } + + if !ver.valid() { panic(fmt.Errorf("sdk_version is invalid. got %q", ver.raw)) - default: - return javaSdk, false } + return javaSdk, false } func checkLinkType(ctx android.ModuleContext, from *Module, to linkTypeContext, tag dependencyTag) { -- cgit v1.2.3 From 0bd88d0b4e782df6aa99475307a4cfab6d617d14 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Mon, 25 May 2020 12:20:51 +0100 Subject: Correct link type for module stubs Module stubs compile against module_current, so any module depending on them had to compile against module_current (or broader) too. Treat them as the API surface the stubs are for. Bug: 157010342 Test: m Change-Id: I49b9082dc1b5afe6c22e94126e574dd8061f0f39 --- java/java.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 726d4869b..0c5ef5db8 100644 --- a/java/java.go +++ b/java/java.go @@ -843,6 +843,10 @@ func (m *Module) getLinkType(name string) (ret linkType, stubs bool) { return javaSystem, true } + if stub, linkType := moduleStubLinkType(name); stub { + return linkType, true + } + ver := m.sdkVersion() switch ver.kind { case sdkCore: -- cgit v1.2.3 From ed50ca8dd8806e957a42751ebac83ebe57805ab8 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Thu, 28 May 2020 23:46:55 +0900 Subject: apex respects stem of java_library modules apex now respects stem of java_library modules. As a follow-up we need to suppor the same for other types of modules. Exempt-From-Owner-Approval: cherry-pick from AOSP Bug: 157638999 Test: m Merged-In: Iaf5023020b5440f1ffd4f5414b5a7864655fc22a (cherry picked from commit a62aa2399031a01620775a06dbae53af0cff5a25) Change-Id: Iaf5023020b5440f1ffd4f5414b5a7864655fc22a --- java/java.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 81f98c0d5..c30dc4e50 100644 --- a/java/java.go +++ b/java/java.go @@ -1880,7 +1880,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { extraInstallDeps = j.InstallMixin(ctx, j.outputFile) } j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), - ctx.ModuleName()+".jar", j.outputFile, extraInstallDeps...) + j.Stem()+".jar", j.outputFile, extraInstallDeps...) } // Verify Dist.Tag is set to a supported output @@ -2721,7 +2721,7 @@ func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.maybeStrippedDexJarFile = dexOutputFile ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), - ctx.ModuleName()+".jar", dexOutputFile) + j.Stem()+".jar", dexOutputFile) } func (j *DexImport) DexJar() android.Path { -- cgit v1.2.3 From a105cf99d0efb05f186cf07b1e34cb3f79694664 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 29 May 2020 11:24:51 +0100 Subject: Collect permitted packages from java_sdk_library instances Switching an updatable boot jar from java_library to java_sdk_library changed the contents of the updatable-bcp-packages.txt due to the code requiring the module to be *Library. This change updates that to allow it to be any module that implements the PermittedPackagesForUpdatableBootJars interface which is *Library and anything that embeds that like *SdkLibrary. Bug: 155164730 Test: m droid and check the contents of system/etc/updatable-bcp-packages.txt Change-Id: I464af74628da311734f102f77ec8158daec5b32d --- java/java.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index c30dc4e50..e01d10999 100644 --- a/java/java.go +++ b/java/java.go @@ -1839,6 +1839,17 @@ type Library struct { InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths) } +// Provides access to the list of permitted packages from updatable boot jars. +type PermittedPackagesForUpdatableBootJars interface { + PermittedPackagesForUpdatableBootJars() []string +} + +var _ PermittedPackagesForUpdatableBootJars = (*Library)(nil) + +func (j *Library) PermittedPackagesForUpdatableBootJars() []string { + return j.properties.Permitted_packages +} + func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool { // Store uncompressed (and aligned) any dex files from jars in APEXes. if am, ok := ctx.Module().(android.ApexModule); ok && !am.IsForPlatform() { -- cgit v1.2.3 From c05da0a90e29184df74c50a49a7905277a56aa3e Mon Sep 17 00:00:00 2001 From: Kousik Kumar Date: Wed, 20 May 2020 11:27:16 -0700 Subject: Add support for remote-execution / caching of jar/zip actions Test: Ran a build with `RBE_JAR="true" RBE_JAR_EXEC_STRATEGY="remote" RBE_ZIP="true" RBE_ZIP_EXEC_STRATEGY="remote" ... use_rbe m` and that succeeded. Bug: b/156765207 Change-Id: Ia17b532fbb282be414adf879914870082dd0841b Merged-In: Ia17b532fbb282be414adf879914870082dd0841b --- java/java.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index e01d10999..2623d2c10 100644 --- a/java/java.go +++ b/java/java.go @@ -1462,13 +1462,19 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { serviceFile := file.String() zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile) } + rule := zip + args := map[string]string{ + "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "), + } + if ctx.Config().IsEnvTrue("RBE_ZIP") { + rule = zipRE + args["implicits"] = strings.Join(services.Strings(), ",") + } ctx.Build(pctx, android.BuildParams{ - Rule: zip, + Rule: rule, Output: servicesJar, Implicits: services, - Args: map[string]string{ - "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "), - }, + Args: args, }) jars = append(jars, servicesJar) } -- cgit v1.2.3 From aa7359ab0c97cc198699607cc17f4df6b3977997 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 2 Jun 2020 09:52:17 +0100 Subject: Always run package check Previously, the package check was only run when building checkbuild or the phony target created for a specific module. It would not run when building a module that depended upon a library with the permitted_packages property. That was because the package check was only run when the package-check.stamp file was built and that was only added to the phony and checkbuild targets. Instead of touching a separate package-check.stamp file to indicate that the check has been performed this change copies the input jar file to the package check to a separate ../package-check/ file which is then treated as the output of the library and is the input for any dex processing. So, any modules that depend on this library will transitively depend on the output file produced by the package check command and so will ensure that the package check is always run. Test: Removed "android.net" from the permitted_packages for "framework-tethering", build "framework-tethering" which triggered and failed the package check and "com.android.tethering" which did not. Made this change. Built "com.android.tethering" which triggered and then failed the package check. Removed change to "framework-tethering" Bug: 157649935 Merged-In: Ib01aa09e13f80282218049270eb7a58ec5f9f605 Change-Id: Ib01aa09e13f80282218049270eb7a58ec5f9f605 (cherry picked from commit 91206d9ed1a1e3cb81d1ace021580c4be8362f1f) --- java/java.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 2623d2c10..1a5e86f3d 100644 --- a/java/java.go +++ b/java/java.go @@ -467,9 +467,6 @@ type Module struct { // expanded Jarjar_rules expandJarjarRules android.Path - // list of additional targets for checkbuild - additionalCheckedModules android.Paths - // Extra files generated by the module type to be added as java resources. extraResources android.Paths @@ -1527,10 +1524,10 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { // Check package restrictions if necessary. if len(j.properties.Permitted_packages) > 0 { - // Check packages and copy to package-checked file. - pkgckFile := android.PathForModuleOut(ctx, "package-check.stamp") - CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages) - j.additionalCheckedModules = append(j.additionalCheckedModules, pkgckFile) + // Check packages and copy input to package-checked file. + // Use the file copied after a successful package check as the output file for this + // module so that any dependencies on this module will trigger the package check. + outputFile = CheckJarPackages(ctx, outputFile, j.properties.Permitted_packages) if ctx.Failed() { return -- cgit v1.2.3 From 8383972ec0a4c2cc5129c4b92cfb8dbe79766987 Mon Sep 17 00:00:00 2001 From: Tej Singh Date: Wed, 3 Jun 2020 18:45:54 +0000 Subject: Revert "Always run package check" This reverts commit aa7359ab0c97cc198699607cc17f4df6b3977997. Reason for revert: package-check.sh doesn't work on mac Change-Id: Ia3dcee612c1f6b4121e1351c8710638ae41bc88a Merged-In: I50af71d54d5f1f8b516bfcf1efbcf6217e89c83a --- java/java.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 1a5e86f3d..2623d2c10 100644 --- a/java/java.go +++ b/java/java.go @@ -467,6 +467,9 @@ type Module struct { // expanded Jarjar_rules expandJarjarRules android.Path + // list of additional targets for checkbuild + additionalCheckedModules android.Paths + // Extra files generated by the module type to be added as java resources. extraResources android.Paths @@ -1524,10 +1527,10 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { // Check package restrictions if necessary. if len(j.properties.Permitted_packages) > 0 { - // Check packages and copy input to package-checked file. - // Use the file copied after a successful package check as the output file for this - // module so that any dependencies on this module will trigger the package check. - outputFile = CheckJarPackages(ctx, outputFile, j.properties.Permitted_packages) + // Check packages and copy to package-checked file. + pkgckFile := android.PathForModuleOut(ctx, "package-check.stamp") + CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages) + j.additionalCheckedModules = append(j.additionalCheckedModules, pkgckFile) if ctx.Failed() { return -- cgit v1.2.3 From 2cd081cf06c552a562aabae25b7cc17f8242d22f Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Mon, 1 Jun 2020 21:39:15 +0900 Subject: dex_import can be added to apex Bug:157886942 Test: m Change-Id: Ida6f7bb784efe74cc1fa0e8d370eaee803f08b0f Merged-In: Ida6f7bb784efe74cc1fa0e8d370eaee803f08b0f --- java/java.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 2623d2c10..f2f47b7d0 100644 --- a/java/java.go +++ b/java/java.go @@ -2684,6 +2684,10 @@ func (j *DexImport) Stem() string { return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name()) } +func (a *DexImport) JacocoReportClassesFile() android.Path { + return nil +} + func (j *DexImport) IsInstallable() bool { return true } -- cgit v1.2.3 From afd3d11a795b9f331637d3587a94142f20e8c55d Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Mon, 8 Jun 2020 19:24:09 +0900 Subject: dex_import that isn't available for platform isn't installed This change fixes a bug that dex_import module is always installed to the platform even when the module is not available to the platform. Bug: 158284983 Test: OUT_DIR=/tmp/ndk build/soong/scripts/build-ndk-prebuilts.sh Change-Id: I85570506e700be59ee63e4f1d7902a40e36df39c --- java/java.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index f2f47b7d0..b0865040e 100644 --- a/java/java.go +++ b/java/java.go @@ -2741,8 +2741,10 @@ func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.maybeStrippedDexJarFile = dexOutputFile - ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), - j.Stem()+".jar", dexOutputFile) + if j.IsForPlatform() { + ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), + j.Stem()+".jar", dexOutputFile) + } } func (j *DexImport) DexJar() android.Path { -- cgit v1.2.3 From 9855207d0e8b496327255c6bc3a4d36d8449775e Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 4 Jun 2020 13:25:17 -0700 Subject: Define Soong phony rules in Make To support dist-for-goals in Soong, we need to define all phony rules in Make so that dist-for-goals can insert additional dependencies on them. Collect all the phony rules in phonySingleton and write them out as Make rules when Soong is embedded in Make, or as blueprint.Phony rules when Soong is run standalone. Bug: 153485543 Test: m checkbuild Change-Id: I68201eff30744b0f487fc4f11f033767b53a627d Merged-In: I68201eff30744b0f487fc4f11f033767b53a627d (cherry picked from commit c3d87d31129405975f9a889e3c1c96cdcbe275a4) --- java/java.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index b0865040e..f563a3878 100644 --- a/java/java.go +++ b/java/java.go @@ -2852,11 +2852,7 @@ func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonC }) // TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets if len(xrefTargets) > 0 { - ctx.Build(pctx, android.BuildParams{ - Rule: blueprint.Phony, - Output: android.PathForPhony(ctx, "xref_java"), - Inputs: xrefTargets, - }) + ctx.Phony("xref_java", xrefTargets...) } } -- cgit v1.2.3 From 1c14b4ecf632f0b90b66b086df03f8eb4c6a33b0 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 15 Jun 2020 16:09:53 -0700 Subject: Consolidate adding common java properties Use a method to add the properties that are present on all java modules. Bug: 153485543 Test: m checkbuild Change-Id: I7803b15eb0de810c8ab8d4b9acf2511935a26fb6 Merged-In: I7803b15eb0de810c8ab8d4b9acf2511935a26fb6 (cherry picked from commit ce6734e666086814df721b681158dc90f7bcf6dd) --- java/java.go | 63 +++++++++++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 35 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index f563a3878..c80eef97f 100644 --- a/java/java.go +++ b/java/java.go @@ -482,6 +482,21 @@ type Module struct { distFile android.Path } +func (j *Module) addHostProperties() { + j.AddProperties( + &j.properties, + &j.protoProperties, + ) +} + +func (j *Module) addHostAndDeviceProperties() { + j.addHostProperties() + j.AddProperties( + &j.deviceProperties, + &j.dexpreoptProperties, + ) +} + func (j *Module) OutputFiles(tag string) (android.Paths, error) { switch tag { case "": @@ -2024,12 +2039,8 @@ var javaHeaderLibsSdkMemberType android.SdkMemberType = &librarySdkMemberType{ func LibraryFactory() android.Module { module := &Library{} - module.AddProperties( - &module.Module.properties, - &module.Module.deviceProperties, - &module.Module.dexpreoptProperties, - &module.Module.protoProperties, - &module.libraryProperties) + module.addHostAndDeviceProperties() + module.AddProperties(&module.libraryProperties) module.initModuleAndImport(&module.ModuleBase) @@ -2051,9 +2062,7 @@ func LibraryStaticFactory() android.Module { func LibraryHostFactory() android.Module { module := &Library{} - module.AddProperties( - &module.Module.properties, - &module.Module.protoProperties) + module.addHostProperties() module.Module.properties.Installable = proptools.BoolPtr(true) @@ -2221,12 +2230,8 @@ func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, func TestFactory() android.Module { module := &Test{} - module.AddProperties( - &module.Module.properties, - &module.Module.deviceProperties, - &module.Module.dexpreoptProperties, - &module.Module.protoProperties, - &module.testProperties) + module.addHostAndDeviceProperties() + module.AddProperties(&module.testProperties) module.Module.properties.Installable = proptools.BoolPtr(true) module.Module.dexpreopter.isTest = true @@ -2239,12 +2244,8 @@ func TestFactory() android.Module { func TestHelperLibraryFactory() android.Module { module := &TestHelperLibrary{} - module.AddProperties( - &module.Module.properties, - &module.Module.deviceProperties, - &module.Module.dexpreoptProperties, - &module.Module.protoProperties, - &module.testHelperLibraryProperties) + module.addHostAndDeviceProperties() + module.AddProperties(&module.testHelperLibraryProperties) module.Module.properties.Installable = proptools.BoolPtr(true) module.Module.dexpreopter.isTest = true @@ -2285,10 +2286,8 @@ func JavaTestImportFactory() android.Module { func TestHostFactory() android.Module { module := &Test{} - module.AddProperties( - &module.Module.properties, - &module.Module.protoProperties, - &module.testProperties) + module.addHostProperties() + module.AddProperties(&module.testProperties) module.Module.properties.Installable = proptools.BoolPtr(true) @@ -2372,12 +2371,8 @@ func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) { func BinaryFactory() android.Module { module := &Binary{} - module.AddProperties( - &module.Module.properties, - &module.Module.deviceProperties, - &module.Module.dexpreoptProperties, - &module.Module.protoProperties, - &module.binaryProperties) + module.addHostAndDeviceProperties() + module.AddProperties(&module.binaryProperties) module.Module.properties.Installable = proptools.BoolPtr(true) @@ -2393,10 +2388,8 @@ func BinaryFactory() android.Module { func BinaryHostFactory() android.Module { module := &Binary{} - module.AddProperties( - &module.Module.properties, - &module.Module.protoProperties, - &module.binaryProperties) + module.addHostProperties() + module.AddProperties(&module.binaryProperties) module.Module.properties.Installable = proptools.BoolPtr(true) -- cgit v1.2.3 From 1e28e3c61593571db5ecea328d134ee50501104d Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 2 Jun 2020 20:09:13 -0700 Subject: Add support for running Android lint on java and android modules. Add a rule that runs Android lint on each java and android module and produces reports in xml, html and text formats. Bug: 153485543 Test: m out/soong/.intermediates/packages/apps/Settings/Settings-core/android_common/lint-report.html Change-Id: I5a530975b73ba767fef45b257d4f9ec901a19fcb Merged-In: I5a530975b73ba767fef45b257d4f9ec901a19fcb (cherry picked from commit 014489c1e6cbd2801970b88d5b608dc5c45b403c) --- java/java.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index c80eef97f..0c0c659e9 100644 --- a/java/java.go +++ b/java/java.go @@ -475,6 +475,7 @@ type Module struct { hiddenAPI dexpreopter + linter // list of the xref extraction files kytheFiles android.Paths @@ -494,6 +495,7 @@ func (j *Module) addHostAndDeviceProperties() { j.AddProperties( &j.deviceProperties, &j.dexpreoptProperties, + &j.linter.properties, ) } @@ -1635,6 +1637,28 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { outputFile = implementationAndResourcesJar } + if ctx.Device() { + lintSDKVersionString := func(sdkSpec sdkSpec) string { + if v := sdkSpec.version; v.isNumbered() { + return v.String() + } else { + return ctx.Config().DefaultAppTargetSdk() + } + } + + j.linter.name = ctx.ModuleName() + j.linter.srcs = srcFiles + j.linter.srcJars = srcJars + j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...) + j.linter.classes = j.implementationJarFile + j.linter.minSdkVersion = lintSDKVersionString(j.minSdkVersion()) + j.linter.targetSdkVersion = lintSDKVersionString(j.targetSdkVersion()) + j.linter.compileSdkVersion = lintSDKVersionString(j.sdkVersion()) + j.linter.javaLanguageLevel = flags.javaVersion.String() + j.linter.kotlinLanguageLevel = "1.3" + j.linter.lint(ctx) + } + ctx.CheckbuildFile(outputFile) // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource @@ -2235,6 +2259,7 @@ func TestFactory() android.Module { module.Module.properties.Installable = proptools.BoolPtr(true) module.Module.dexpreopter.isTest = true + module.Module.linter.test = true InitJavaModule(module, android.HostAndDeviceSupported) return module @@ -2249,6 +2274,7 @@ func TestHelperLibraryFactory() android.Module { module.Module.properties.Installable = proptools.BoolPtr(true) module.Module.dexpreopter.isTest = true + module.Module.linter.test = true InitJavaModule(module, android.HostAndDeviceSupported) return module @@ -2823,6 +2849,7 @@ func DefaultsFactory() android.Module { &DexImportProperties{}, &android.ApexProperties{}, &RuntimeResourceOverlayProperties{}, + &LintProperties{}, ) android.InitDefaultsModule(module) -- cgit v1.2.3 From 3791b45f670062d8d01c87b1debb7c36cbed9e70 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 18 Jun 2020 15:46:32 -0700 Subject: Fix annotation processors in kotlin modules that generate resources The kapt rule was only keeping the generated sources, and not the generated classes directory. The generated classes directory will contain resources generated by the annotation processor and needs to be added to the final jar. Test: m ApiFinder Bug: 153485543 Change-Id: I89197d0afcb1eee011c01aa400f9977e66f43768 Merged-In: I89197d0afcb1eee011c01aa400f9977e66f43768 (cherry picked from commit 9ca38d22a49127901dadb14ffa093e29a2942f2d) --- java/java.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 0c0c659e9..e8d434424 100644 --- a/java/java.go +++ b/java/java.go @@ -1327,8 +1327,10 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { if len(flags.processorPath) > 0 { // Use kapt for annotation processing kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar") - kotlinKapt(ctx, kaptSrcJar, kotlinSrcFiles, srcJars, flags) + kaptResJar := android.PathForModuleOut(ctx, "kapt", "kapt-res.jar") + kotlinKapt(ctx, kaptSrcJar, kaptResJar, kotlinSrcFiles, srcJars, flags) srcJars = append(srcJars, kaptSrcJar) + kotlinJars = append(kotlinJars, kaptResJar) // Disable annotation processing in javac, it's already been handled by kapt flags.processorPath = nil flags.processors = nil -- cgit v1.2.3 From aaf58061a09be3723d8bc644240394391a8d2e0d Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 18 Jun 2020 15:52:01 -0700 Subject: Allow kotlin modules to skip packaging the kotlin stdlib Host tools like lint may package their own version of the kotlin stdlib, and any jars loaded by them shouldn't contain the platform version. Add a static_kotlin_stdlib property that defaults to true to allow building the module without staticalling including the kotlin stdlib. Bug: 153485543 Test: m ApiFinder Change-Id: I7da78ef493806ce4ab0050e4ee9e8d330b0509c8 Merged-In: I7da78ef493806ce4ab0050e4ee9e8d330b0509c8 (cherry picked from commit 0b67a8bd0fc87c7c584d165abfeeb9314ce22f18) --- java/java.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index e8d434424..1d4d45972 100644 --- a/java/java.go +++ b/java/java.go @@ -253,6 +253,9 @@ type CompilerProperties struct { // List of files to include in the META-INF/services folder of the resulting jar. Services []string `android:"path,arch_variant"` + + // If true, package the kotlin stdlib into the jar. Defaults to true. + Static_kotlin_stdlib *bool `android:"arch_variant"` } type CompilerDeviceProperties struct { @@ -1345,9 +1348,11 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { // Make javac rule depend on the kotlinc rule flags.classpath = append(flags.classpath, kotlinJar) - // Jar kotlin classes into the final jar after javac kotlinJars = append(kotlinJars, kotlinJar) - kotlinJars = append(kotlinJars, deps.kotlinStdlib...) + // Jar kotlin classes into the final jar after javac + if BoolDefault(j.properties.Static_kotlin_stdlib, true) { + kotlinJars = append(kotlinJars, deps.kotlinStdlib...) + } } jars := append(android.Paths(nil), kotlinJars...) -- cgit v1.2.3 From 205a504053505699fbf19bb38ec07f8674a8fb1b Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 18 Jun 2020 15:56:48 -0700 Subject: Support adding extra lint checks Add a lint.extra_check_modules property to list modules to use as plugins to Lint. Bug: 153485543 Test: m checkbuild Change-Id: I25c7799438cfec43163e757637c65b8657488d36 Merged-In: I25c7799438cfec43163e757637c65b8657488d36 (cherry picked from commit 92e4b46af561503506b54f9e4c925615bd03a069) --- java/java.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 1d4d45972..9e196f43d 100644 --- a/java/java.go +++ b/java/java.go @@ -574,6 +574,7 @@ var ( certificateTag = dependencyTag{name: "certificate"} instrumentationForTag = dependencyTag{name: "instrumentation_for"} usesLibTag = dependencyTag{name: "uses-library"} + extraLintCheckTag = dependencyTag{name: "extra-lint-check"} ) func IsLibDepTag(depTag blueprint.DependencyTag) bool { @@ -668,6 +669,8 @@ func (j *Module) AvailableFor(what string) bool { func (j *Module) deps(ctx android.BottomUpMutatorContext) { if ctx.Device() { + j.linter.deps(ctx) + sdkDep := decodeSdkDep(ctx, sdkContext(j)) if sdkDep.useDefaultLibs { ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...) -- cgit v1.2.3 From 9ee66da850cbc0be76e556f57af37781e5631662 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 17 Jun 2020 16:59:43 +0100 Subject: Fix check-boot-jars when a boot jar is provided by prebuilt Previously, when a boot jar was provided by a java_sdk_library_import module the check-boot-jars check failed because the file it depended on was not available. In an incremental build the build failed due to the file in the out directory not having a rule to generate it. That was because the module was named prebuilt_. instead of .. This was fixed by simply removing prebuilt_ prefix from the name if it was present. After fixing that the check-boot-jars still did not work properly because it was expecting a jar file containing .class files but instead was given a jar file containing .dex files which meant the check did not work properly. This was fixed by defining a new ApexDependency interface for use by the apex/apex.go code to use instead of java.Dependency for generating the androidmk entries. The *SdkLibraryImport type then implemented those, by delegating to the implementation library. Bug: 158304459 Bug: 159112414 Test: m check-boot-jars m checkbuild manual inspection of the .jar file used by check-boot-jars to ensure it contained .class files and not .dex files. Change-Id: I545c5c9072dd472337d2f9b4dfdf08f53c981662 Merged-In: I545c5c9072dd472337d2f9b4dfdf08f53c981662 --- java/java.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 9e196f43d..90e9b1f6f 100644 --- a/java/java.go +++ b/java/java.go @@ -517,11 +517,16 @@ func (j *Module) OutputFiles(tag string) (android.Paths, error) { var _ android.OutputFileProducer = (*Module)(nil) -type Dependency interface { +// Methods that need to be implemented for a module that is added to apex java_libs property. +type ApexDependency interface { HeaderJars() android.Paths + ImplementationAndResourcesJars() android.Paths +} + +type Dependency interface { + ApexDependency ImplementationJars() android.Paths ResourceJars() android.Paths - ImplementationAndResourcesJars() android.Paths DexJar() android.Path AidlIncludeDirs() android.Paths ExportedSdkLibs() []string -- cgit v1.2.3 From c4422106a7cf4731e27d664646bc0d57ad3f37fa Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 24 Jun 2020 16:22:38 +0100 Subject: Apply hiddenapi encoding to java_sdk_library .impl Adds a ConfigurationName property, and ConfigurationName() method that allows a library to separate its name (e.g. framework-tethering.impl) from the name used in the build configuration, e.g. ctx.Config().BootJars(). Updates hiddenapi processing to use ConfigurationName() instead of ctx.ModuleName(). Changes java_sdk_library to set the ConfigurationName property of the implementation library to the name of the module instead of .impl so that it will match the name in the boot jars list. Bug: 159683330 Test: m framework-tethering dexdump ${PRODUCT_OUT}/apex/com.android.tethering/javalib/framework-tethering.jar | grep hiddenapi | wc -l Verify that there are >0 hiddenapi entries. Add java_sdk_library_import prefer=true for framework-tethering and repeat the above to verify that there are 0 hiddenapi entries. Apply this change, repeat above and verify that there are the same # of entries as before. Remove the prebuilt for framework-tethering Repeat the above and verify that there is no change to the # of entries Change-Id: I6c3016c35d0fcb1b95d4f9b37a307a69878f8e0a --- java/java.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 90e9b1f6f..5632ff586 100644 --- a/java/java.go +++ b/java/java.go @@ -342,6 +342,12 @@ type CompilerDeviceProperties struct { // otherwise provides defaults libraries to add to the bootclasspath. System_modules *string + // The name of the module as used in build configuration. + // + // Allows a library to separate its actual name from the name used in + // build configuration, e.g.ctx.Config().BootJars(). + ConfigurationName *string `blueprint:"mutated"` + // set the name of the output Stem *string @@ -1617,8 +1623,11 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { return } + configurationName := j.ConfigurationName() + primary := configurationName == ctx.ModuleName() + // Hidden API CSV generation and dex encoding - dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile, + dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, configurationName, primary, dexOutputFile, j.implementationJarFile, proptools.Bool(j.deviceProperties.Uncompress_dex)) // merge dex jar with resources if necessary @@ -1872,6 +1881,10 @@ func (j *Module) Stem() string { return proptools.StringDefault(j.deviceProperties.Stem, j.Name()) } +func (j *Module) ConfigurationName() string { + return proptools.StringDefault(j.deviceProperties.ConfigurationName, j.BaseModuleName()) +} + func (j *Module) JacocoReportClassesFile() android.Path { return j.jacocoReportClassesFile } -- cgit v1.2.3