From a62aa2399031a01620775a06dbae53af0cff5a25 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Thu, 28 May 2020 23:46:55 +0900 Subject: [PATCH] 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. Bug: 157638999 Test: m Change-Id: Iaf5023020b5440f1ffd4f5414b5a7864655fc22a --- apex/apex.go | 15 +++++++++++++-- apex/apex_test.go | 3 ++- java/java.go | 4 ++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 866c0f118..a91dc29bc 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1144,6 +1144,7 @@ func (class apexFileClass) NameInMake() string { // apexFile represents a file in an APEX bundle type apexFile struct { builtFile android.Path + stem string moduleName string installDir string class apexFileClass @@ -1192,7 +1193,11 @@ func (af *apexFile) apexRelativePath(path string) string { // Path() returns path of this apex file relative to the APEX root func (af *apexFile) Path() string { - return af.apexRelativePath(af.builtFile.Base()) + stem := af.builtFile.Base() + if af.stem != "" { + stem = af.stem + } + return af.apexRelativePath(stem) } // SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root @@ -1639,11 +1644,17 @@ func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) ap return af } -func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib java.Dependency, module android.Module) apexFile { +type javaDependency interface { + java.Dependency + Stem() string +} + +func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaDependency, module android.Module) apexFile { dirInApex := "javalib" fileToCopy := lib.DexJar() af := newApexFile(ctx, fileToCopy, module.Name(), dirInApex, javaSharedLib, module) af.jacocoReportClassesFile = lib.JacocoReportClassesFile() + af.stem = lib.Stem() + ".jar" return af } diff --git a/apex/apex_test.go b/apex/apex_test.go index 9633f2713..dee7ff246 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -414,6 +414,7 @@ func TestBasicApex(t *testing.T) { java_library { name: "myjar", srcs: ["foo/bar/MyClass.java"], + stem: "myjar_stem", sdk_version: "none", system_modules: "none", static_libs: ["myotherjar"], @@ -468,7 +469,7 @@ func TestBasicApex(t *testing.T) { // Ensure that both direct and indirect deps are copied into apex ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") - ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar") + ensureContains(t, copyCmds, "image.apex/javalib/myjar_stem.jar") // .. but not for java libs ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar") diff --git a/java/java.go b/java/java.go index 466132e1e..032aee610 100644 --- a/java/java.go +++ b/java/java.go @@ -1878,7 +1878,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 @@ -2728,7 +2728,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 {