diff options
| author | 2024-04-05 00:36:44 +0000 | |
|---|---|---|
| committer | 2024-05-03 20:51:11 +0000 | |
| commit | d831af426762a24794f3420ba00eb1b388cea221 (patch) | |
| tree | 2341b9c8943ce73ab7af0c0dbba1c286be1c1190 /java/java.go | |
| parent | 2ddb22ce99d56fdaf0ce65726d68c068b3dc3247 (diff) | |
Remove compilation actions from java sdk library
This change modifies the build actions of java_sdk_library module type
so that it does not perform any compilation actions (i.e. does not
create the top level java_sdk_library jar file). Instead, it delegates
the build actions the top level jar file was performing to the
dynamically created ".impl"-suffixed java library module. The build
actions that are delegated to the impl library module include hiddenapi
processing, dexing, and dexpreopt.
Test: m nothing --no-skip-soong-tests
Bug: 332785297
Change-Id: I7534f9eaacf6d9f72fbf8d540b1e26af84106c20
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/java/java.go b/java/java.go index 2834c5f0c..82c646958 100644 --- a/java/java.go +++ b/java/java.go @@ -670,6 +670,10 @@ type Library struct { var _ android.ApexModule = (*Library)(nil) +func (j *Library) CheckDepsMinSdkVersion(ctx android.ModuleContext) { + CheckMinSdkVersion(ctx, j) +} + // Provides access to the list of permitted packages from apex boot jars. type PermittedPackagesForUpdatableBootJars interface { PermittedPackagesForUpdatableBootJars() []string @@ -898,6 +902,12 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.minSdkVersion = j.MinSdkVersion(ctx) j.maxSdkVersion = j.MaxSdkVersion(ctx) + // Check min_sdk_version of the transitive dependencies if this module is created from + // java_sdk_library. + if j.deviceProperties.Min_sdk_version != nil && j.SdkLibraryName() != nil { + j.CheckDepsMinSdkVersion(ctx) + } + // SdkLibrary.GenerateAndroidBuildActions(ctx) sets the stubsLinkType to Unknown. // If the stubsLinkType has already been set to Unknown, the stubsLinkType should // not be overridden. @@ -928,8 +938,12 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.checkSdkVersions(ctx) j.checkHeadersOnly(ctx) if ctx.Device() { + libName := j.Name() + if j.SdkLibraryName() != nil && strings.HasSuffix(libName, ".impl") { + libName = proptools.String(j.SdkLibraryName()) + } j.dexpreopter.installPath = j.dexpreopter.getInstallPath( - ctx, j.Name(), android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) + ctx, libName, android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary setUncompressDex(ctx, &j.dexpreopter, &j.dexer) j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex @@ -940,8 +954,24 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { } j.compile(ctx, nil, nil, nil) - exclusivelyForApex := !apexInfo.IsForPlatform() - if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex { + // If this module is an impl library created from java_sdk_library, + // install the files under the java_sdk_library module outdir instead of this module outdir. + if j.SdkLibraryName() != nil && strings.HasSuffix(j.Name(), ".impl") { + j.setInstallRules(ctx, proptools.String(j.SdkLibraryName())) + } else { + j.setInstallRules(ctx, ctx.ModuleName()) + } + + android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{ + TestOnly: Bool(j.sourceProperties.Test_only), + TopLevelTarget: j.sourceProperties.Top_level_test_target, + }) +} + +func (j *Library) setInstallRules(ctx android.ModuleContext, installModuleName string) { + apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) + + if (Bool(j.properties.Installable) || ctx.Host()) && apexInfo.IsForPlatform() { var extraInstallDeps android.InstallPaths if j.InstallMixin != nil { extraInstallDeps = j.InstallMixin(ctx, j.outputFile) @@ -958,22 +988,23 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { if !ctx.Host() { archDir = ctx.DeviceConfig().DeviceArch() } - installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir) + installDir = android.PathForModuleInstall(ctx, installModuleName, archDir) } else { installDir = android.PathForModuleInstall(ctx, "framework") } j.installFile = ctx.InstallFile(installDir, j.Stem()+".jar", j.outputFile, extraInstallDeps...) } - - android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{ - TestOnly: Bool(j.sourceProperties.Test_only), - TopLevelTarget: j.sourceProperties.Top_level_test_target, - }) } func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) { j.usesLibrary.deps(ctx, false) j.deps(ctx) + + if j.SdkLibraryName() != nil && strings.HasSuffix(j.Name(), ".impl") { + if dexpreopt.IsDex2oatNeeded(ctx) { + dexpreopt.RegisterToolDeps(ctx) + } + } } const ( |