From 9e6c24285695c2f0df26642605f54ade8d220e70 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Fri, 9 Aug 2019 20:39:45 +0900 Subject: [PATCH] java_import can be included in apex java_import can be included in apex via 'java_libs' property. Bug: 139175488 Test: m (apex_test.go updated) Change-Id: I3680a47cdac93b0cb2d41da8df3f8defa2bbe670 --- android/module.go | 1 + apex/apex.go | 28 ++++++++++++++++++++++++---- apex/apex_test.go | 13 ++++++++++++- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/android/module.go b/android/module.go index 138b9cd6a..2fc46c376 100644 --- a/android/module.go +++ b/android/module.go @@ -71,6 +71,7 @@ type BaseModuleContext interface { OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag OtherModuleExists(name string) bool + OtherModuleType(m blueprint.Module) string GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module diff --git a/apex/apex.go b/apex/apex.go index e4fad83e9..58f700bc3 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -740,6 +740,18 @@ func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, return } +func getCopyManifestForPrebuiltJavaLibrary(java *java.Import) (fileToCopy android.Path, dirInApex string) { + dirInApex = "javalib" + // The output is only one, but for some reason, ImplementationJars returns Paths, not Path + implJars := java.ImplementationJars() + if len(implJars) != 1 { + panic(fmt.Errorf("java.ImplementationJars() must return single Path, but got: %s", + strings.Join(implJars.Strings(), ", "))) + } + fileToCopy = implJars[0] + return +} + func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) { dirInApex = filepath.Join("etc", prebuilt.SubDir()) fileToCopy = prebuilt.OutputFile() @@ -833,16 +845,24 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { ctx.PropertyErrorf("binaries", "%q is neither cc_binary, (embedded) py_binary, (host) blueprint_go_binary, (host) bootstrap_go_binary, nor sh_binary", depName) } case javaLibTag: - if java, ok := child.(*java.Library); ok { - fileToCopy, dirInApex := getCopyManifestForJavaLibrary(java) + if javaLib, ok := child.(*java.Library); ok { + fileToCopy, dirInApex := getCopyManifestForJavaLibrary(javaLib) if fileToCopy == nil { ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName) } else { - filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, java, nil}) + filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil}) + } + return true + } else if javaLib, ok := child.(*java.Import); ok { + fileToCopy, dirInApex := getCopyManifestForPrebuiltJavaLibrary(javaLib) + if fileToCopy == nil { + ctx.PropertyErrorf("java_libs", "%q does not have a jar output", depName) + } else { + filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil}) } return true } else { - ctx.PropertyErrorf("java_libs", "%q is not a java_library module", depName) + ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child)) } case prebuiltTag: if prebuilt, ok := child.(*android.PrebuiltEtc); ok { diff --git a/apex/apex_test.go b/apex/apex_test.go index 38d2bf2f7..45c715f07 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -92,6 +92,7 @@ func testApexContext(t *testing.T, bp string) (*android.TestContext, android.Con ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(java.AndroidAppCertificateFactory)) ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory)) ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory)) + ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(java.ImportFactory)) ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel() @@ -208,6 +209,7 @@ func testApexContext(t *testing.T, bp string) (*android.TestContext, android.Con "myprebuilt": nil, "my_include": nil, "foo/bar/MyClass.java": nil, + "prebuilt.jar": nil, "vendor/foo/devkeys/test.x509.pem": nil, "vendor/foo/devkeys/test.pk8": nil, "testkey.x509.pem": nil, @@ -291,7 +293,7 @@ func TestBasicApex(t *testing.T) { binaries: ["foo",], } }, - java_libs: ["myjar"], + java_libs: ["myjar", "myprebuiltjar"], } apex { @@ -366,6 +368,12 @@ func TestBasicApex(t *testing.T) { system_modules: "none", compile_dex: true, } + + java_import { + name: "myprebuiltjar", + jars: ["prebuilt.jar"], + installable: true, + } `) apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") @@ -383,6 +391,7 @@ func TestBasicApex(t *testing.T) { // Ensure that apex variant is created for the direct dep ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex") ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex") + ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common_myapex") // Ensure that apex variant is created for the indirect dep ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex") @@ -392,6 +401,7 @@ func TestBasicApex(t *testing.T) { 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/myprebuiltjar.jar") // .. but not for java libs ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") @@ -400,6 +410,7 @@ func TestBasicApex(t *testing.T) { ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared") ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") + ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common") // Ensure that all symlinks are present. found_foo_link_64 := false