Merge changes I8f4eaed1,I358a62d3

* changes:
  Dexpreopt standalone system server jars from prebuilts.
  Dexpreopt standalone system server jars.
This commit is contained in:
Jiakai Zhang
2021-12-20 19:52:37 +00:00
committed by Gerrit Code Review
9 changed files with 157 additions and 38 deletions

View File

@@ -182,7 +182,14 @@ func (j *TestHelperLibrary) AndroidMkEntries() []android.AndroidMkEntries {
}
func (prebuilt *Import) AndroidMkEntries() []android.AndroidMkEntries {
if prebuilt.hideApexVariantFromMake || !prebuilt.ContainingSdk().Unversioned() {
if prebuilt.hideApexVariantFromMake {
// For a library imported from a prebuilt APEX, we don't need a Make module for itself, as we
// don't need to install it. However, we need to add its dexpreopt outputs as sub-modules, if it
// is preopted.
dexpreoptEntries := prebuilt.dexpreopter.AndroidMkEntriesForApex()
return append(dexpreoptEntries, android.AndroidMkEntries{Disabled: true})
}
if !prebuilt.ContainingSdk().Unversioned() {
return []android.AndroidMkEntries{android.AndroidMkEntries{
Disabled: true,
}}

View File

@@ -115,6 +115,11 @@ func isApexVariant(ctx android.BaseModuleContext) bool {
return !apexInfo.IsForPlatform()
}
func forPrebuiltApex(ctx android.BaseModuleContext) bool {
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
return apexInfo.ForPrebuiltApex
}
func moduleName(ctx android.BaseModuleContext) string {
// Remove the "prebuilt_" prefix if the module is from a prebuilt because the prefix is not
// expected by dexpreopter.
@@ -134,7 +139,9 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool {
return true
}
if !ctx.Module().(DexpreopterInterface).IsInstallable() {
// If the module is from a prebuilt APEX, it shouldn't be installable, but it can still be
// dexpreopted.
if !ctx.Module().(DexpreopterInterface).IsInstallable() && !forPrebuiltApex(ctx) {
return true
}
@@ -152,15 +159,16 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool {
return true
}
isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx))
if isApexVariant(ctx) {
// Don't preopt APEX variant module unless the module is an APEX system server jar and we are
// building the entire system image.
if !global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) || ctx.Config().UnbundledBuild() {
if !isApexSystemServerJar || ctx.Config().UnbundledBuild() {
return true
}
} else {
// Don't preopt the platform variant of an APEX system server jar to avoid conflicts.
if global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) {
if isApexSystemServerJar {
return true
}
}
@@ -191,8 +199,8 @@ func (d *dexpreopter) odexOnSystemOther(ctx android.ModuleContext, installPath a
func (d *dexpreopter) getInstallPath(
ctx android.ModuleContext, defaultInstallPath android.InstallPath) android.InstallPath {
global := dexpreopt.GetGlobalConfig(ctx)
if global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) {
dexLocation := dexpreopt.GetSystemServerDexLocation(global, moduleName(ctx))
if global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx)) {
dexLocation := dexpreopt.GetSystemServerDexLocation(ctx, global, moduleName(ctx))
return android.PathForModuleInPartitionInstall(ctx, "", strings.TrimPrefix(dexLocation, "/"))
}
if !d.dexpreoptDisabled(ctx) && isApexVariant(ctx) &&
@@ -229,8 +237,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr
return
}
isSystemServerJar := global.SystemServerJars.ContainsJar(moduleName(ctx)) ||
global.ApexSystemServerJars.ContainsJar(moduleName(ctx))
isSystemServerJar := global.AllSystemServerJars(ctx).ContainsJar(moduleName(ctx))
bootImage := defaultBootImageConfig(ctx)
if global.UseArtImage {
@@ -336,6 +343,8 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr
dexpreoptRule.Build("dexpreopt", "dexpreopt")
isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx))
for _, install := range dexpreoptRule.Installs() {
// Remove the "/" prefix because the path should be relative to $ANDROID_PRODUCT_OUT.
installDir := strings.TrimPrefix(filepath.Dir(install.To), "/")
@@ -343,7 +352,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr
arch := filepath.Base(installDir)
installPath := android.PathForModuleInPartitionInstall(ctx, "", installDir)
if global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) {
if isApexSystemServerJar {
// APEX variants of java libraries are hidden from Make, so their dexpreopt
// outputs need special handling. Currently, for APEX variants of java
// libraries, only those in the system server classpath are handled here.
@@ -362,7 +371,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr
}
}
if !global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) {
if !isApexSystemServerJar {
d.builtInstalled = dexpreoptRule.Installs().String()
}
}

View File

@@ -72,9 +72,10 @@ func (m *dexpreoptSystemserverCheck) GenerateAndroidBuildActions(ctx android.Mod
return
}
systemServerJars := dexpreopt.AllSystemServerJars(ctx, global)
// TODO(b/203198541): Check all system server jars.
systemServerJars := global.AllSystemServerClasspathJars(ctx)
for _, jar := range systemServerJars.CopyOfJars() {
dexLocation := dexpreopt.GetSystemServerDexLocation(global, jar)
dexLocation := dexpreopt.GetSystemServerDexLocation(ctx, global, jar)
odexLocation := dexpreopt.ToOdexPath(dexLocation, targets[0].Arch.ArchType)
odexPath := getInstallPath(ctx, odexLocation)
vdexPath := getInstallPath(ctx, pathtools.ReplaceExtension(odexLocation, "vdex"))

View File

@@ -60,7 +60,7 @@ func (p *platformSystemServerClasspathModule) GenerateAndroidBuildActions(ctx an
classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, p.classpathType)
standaloneConfiguredJars := p.standaloneConfiguredJars(ctx)
standaloneClasspathJars := configuredJarListToClasspathJars(ctx, standaloneConfiguredJars, STANDALONE_SYSTEMSERVER_JARS)
configuredJars = configuredJars.AppendList(standaloneConfiguredJars)
configuredJars = configuredJars.AppendList(&standaloneConfiguredJars)
classpathJars = append(classpathJars, standaloneClasspathJars...)
p.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
}
@@ -122,7 +122,7 @@ func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.Mo
classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, s.classpathType)
standaloneConfiguredJars := s.standaloneConfiguredJars(ctx)
standaloneClasspathJars := configuredJarListToClasspathJars(ctx, standaloneConfiguredJars, STANDALONE_SYSTEMSERVER_JARS)
configuredJars = configuredJars.AppendList(standaloneConfiguredJars)
configuredJars = configuredJars.AppendList(&standaloneConfiguredJars)
classpathJars = append(classpathJars, standaloneClasspathJars...)
s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)