From a41a6963b4a8636a6b5de9b0d4aa746c9a6e99ac Mon Sep 17 00:00:00 2001 From: Bill Peckham Date: Mon, 11 Jan 2021 10:58:54 -0800 Subject: [PATCH] Enable an apex to include a java_import. With the addition of the compile_dex property to the java_import module it becomes possible to include a java_import module in an apex. This change allows the dependency and adds a test. Bug: 177228901 Test: m nothing Test: new TestApexWithJavaImport Change-Id: I9336dade1857109e2fd21f7d57e1dc4abc4a402c --- apex/apex.go | 3 ++- apex/apex_test.go | 28 ++++++++++++++++++++++++++++ java/java.go | 4 ++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/apex/apex.go b/apex/apex.go index 376811af2..6538032ec 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1428,6 +1428,7 @@ type javaModule interface { } var _ javaModule = (*java.Library)(nil) +var _ javaModule = (*java.Import)(nil) var _ javaModule = (*java.SdkLibrary)(nil) var _ javaModule = (*java.DexImport)(nil) var _ javaModule = (*java.SdkLibraryImport)(nil) @@ -1629,7 +1630,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { } case javaLibTag: switch child.(type) { - case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport: + case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import: af := apexFileForJavaModule(ctx, child.(javaModule)) if !af.ok() { ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName) diff --git a/apex/apex_test.go b/apex/apex_test.go index 58739b0d6..3c7e0194b 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -4515,6 +4515,34 @@ func TestErrorsIfDepsAreNotEnabled(t *testing.T) { `) } +func TestApexWithJavaImport(t *testing.T) { + ctx, _ := testApex(t, ` + apex { + name: "myapex", + key: "myapex.key", + java_libs: ["myjavaimport"], + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + + java_import { + name: "myjavaimport", + apex_available: ["myapex"], + jars: ["my.jar"], + compile_dex: true, + } + `) + + module := ctx.ModuleForTests("myapex", "android_common_myapex_image") + apexRule := module.Rule("apexRule") + copyCmds := apexRule.Args["copy_commands"] + ensureContains(t, copyCmds, "image.apex/javalib/myjavaimport.jar") +} + func TestApexWithApps(t *testing.T) { ctx, _ := testApex(t, ` apex { diff --git a/java/java.go b/java/java.go index 3c6146b76..59ec94d5b 100644 --- a/java/java.go +++ b/java/java.go @@ -2831,6 +2831,10 @@ func (a *Import) JacocoReportClassesFile() android.Path { return nil } +func (j *Import) LintDepSets() LintDepSets { + return LintDepSets{} +} + func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)