From aa55f745051c31e48c0002699e17d0ef88eb2100 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 6 Oct 2020 17:20:13 +0100 Subject: [PATCH] Allow access to the class jar for java_import using {.jar} tag Layoutlib requires access to the jar file (containing .class) files for a number of libraries including "core-libart". It does that using the {.jar} output tag, e.g. "core-libart{.jar}". This change makes sure that works when "core-libart" is provided as a java_import instead of a java_library. Bug: 142938164 Test: m nothing Change-Id: I605019d680c28e4a33f0ca14279d63fa62b9774b --- java/java.go | 11 +++++++++++ java/java_test.go | 26 +++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/java/java.go b/java/java.go index 1d7eaa771..b5108bf3e 100644 --- a/java/java.go +++ b/java/java.go @@ -2699,6 +2699,17 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { } } +func (j *Import) OutputFiles(tag string) (android.Paths, error) { + switch tag { + case ".jar": + return android.Paths{j.combinedClasspathFile}, nil + default: + return nil, fmt.Errorf("unsupported module reference tag %q", tag) + } +} + +var _ android.OutputFileProducer = (*Import)(nil) + var _ Dependency = (*Import)(nil) func (j *Import) HeaderJars() android.Paths { diff --git a/java/java_test.go b/java/java_test.go index f16639aa8..a43e2a8c9 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1412,7 +1412,31 @@ func TestJavaLibrary(t *testing.T) { name: "core", sdk_version: "none", system_modules: "none", - }`), + } + + filegroup { + name: "core-jar", + srcs: [":core{.jar}"], + } +`), + }) + ctx := testContext() + run(t, ctx, config) +} + +func TestJavaImport(t *testing.T) { + config := testConfig(nil, "", map[string][]byte{ + "libcore/Android.bp": []byte(` + java_import { + name: "core", + sdk_version: "none", + } + + filegroup { + name: "core-jar", + srcs: [":core{.jar}"], + } +`), }) ctx := testContext() run(t, ctx, config)