From 1d0eb7a9d0a0fbff8db6eb9f3e872a5bc8ef6da6 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 3 Nov 2021 14:08:20 -0700 Subject: [PATCH] Fix ctx.InstallFile calls for java modules Call ctx.InstallFile on the primary install file last so that the primary install file can depend on the extra install files, and so that the primary install file can be inferred from the last installed file. Add missing ctx.InstallFile calls for the dexpreopt and hostdex outputs. Fix the install subdirectory for modules installing to the testcases directory. Bug: 204136549 Test: m checkbuild Change-Id: I7edd7647be27439d3ca0ecc589ca5e89d4ba8474 --- android/paths.go | 6 ++++++ java/app.go | 6 ++++-- java/dexpreopt.go | 32 ++++++++++++++++++-------------- java/java.go | 31 +++++++++++++++++++++++++++---- 4 files changed, 55 insertions(+), 20 deletions(-) diff --git a/android/paths.go b/android/paths.go index 82c8a2471..5285ee869 100644 --- a/android/paths.go +++ b/android/paths.go @@ -1661,6 +1661,12 @@ func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string return makePathForInstall(ctx, os, arch, partition, ctx.Debug(), pathComponents...) } +// PathForHostDexInstall returns an InstallPath representing the install path for the +// module appended with paths... +func PathForHostDexInstall(ctx ModuleInstallPathContext, pathComponents ...string) InstallPath { + return makePathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "", ctx.Debug(), pathComponents...) +} + // PathForModuleInPartitionInstall is similar to PathForModuleInstall but partition is provided by the caller func PathForModuleInPartitionInstall(ctx ModuleInstallPathContext, partition string, pathComponents ...string) InstallPath { os, arch := osAndArch(ctx) diff --git a/java/app.go b/java/app.go index 6554d6693..7c195fc3f 100755 --- a/java/app.go +++ b/java/app.go @@ -721,10 +721,12 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { // Install the app package. if (Bool(a.Module.properties.Installable) || ctx.Host()) && apexInfo.IsForPlatform() { - ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile) + var extraInstalledPaths android.Paths for _, extra := range a.extraOutputFiles { - ctx.InstallFile(a.installDir, extra.Base(), extra) + installed := ctx.InstallFile(a.installDir, extra.Base(), extra) + extraInstalledPaths = append(extraInstalledPaths, installed) } + ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile, extraInstalledPaths...) } a.buildAppDependencyInfo(ctx) diff --git a/java/dexpreopt.go b/java/dexpreopt.go index e9dc982c7..8ab5a4549 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -335,17 +335,19 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr dexpreoptRule.Build("dexpreopt", "dexpreopt") - if global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) { - // 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. Preopting of boot classpath jars in the ART APEX are handled in - // java/dexpreopt_bootjars.go, and other APEX jars are not preopted. - 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), "/") - installBase := filepath.Base(install.To) - arch := filepath.Base(installDir) - installPath := android.PathForModuleInPartitionInstall(ctx, "", installDir) + 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), "/") + installBase := filepath.Base(install.To) + arch := filepath.Base(installDir) + installPath := android.PathForModuleInPartitionInstall(ctx, "", installDir) + + if global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) { + // 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. + // Preopting of boot classpath jars in the ART APEX are handled in + // java/dexpreopt_bootjars.go, and other APEX jars are not preopted. // The installs will be handled by Make as sub-modules of the java library. d.builtInstalledForApex = append(d.builtInstalledForApex, dexpreopterInstall{ name: arch + "-" + installBase, @@ -354,10 +356,12 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr installDirOnDevice: installPath, installFileOnDevice: installBase, }) + } else { + ctx.InstallFile(installPath, installBase, install.From) } - } else { - // The installs will be handled by Make as LOCAL_SOONG_BUILT_INSTALLED of the java library - // module. + } + + if !global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) { d.builtInstalled = dexpreoptRule.Installs().String() } } diff --git a/java/java.go b/java/java.go index 854097b0a..a538fbed9 100644 --- a/java/java.go +++ b/java/java.go @@ -567,8 +567,22 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { if j.InstallMixin != nil { extraInstallDeps = j.InstallMixin(ctx, j.outputFile) } - j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), - j.Stem()+".jar", j.outputFile, extraInstallDeps...) + hostDexNeeded := Bool(j.deviceProperties.Hostdex) && !ctx.Host() + if hostDexNeeded { + ctx.InstallFile(android.PathForHostDexInstall(ctx, "framework"), + j.Stem()+"-hostdex.jar", j.outputFile) + } + var installDir android.InstallPath + if ctx.InstallInTestcases() { + var archDir string + if !ctx.Host() { + archDir = ctx.DeviceConfig().DeviceArch() + } + installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir) + } else { + installDir = android.PathForModuleInstall(ctx, "framework") + } + j.installFile = ctx.InstallFile(installDir, j.Stem()+".jar", j.outputFile, extraInstallDeps...) } } @@ -1376,8 +1390,17 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { }) if Bool(j.properties.Installable) { - ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), - jarName, outputFile) + var installDir android.InstallPath + if ctx.InstallInTestcases() { + var archDir string + if !ctx.Host() { + archDir = ctx.DeviceConfig().DeviceArch() + } + installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir) + } else { + installDir = android.PathForModuleInstall(ctx, "framework") + } + ctx.InstallFile(installDir, jarName, outputFile) } j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs)