From c678ad3f7143291458d053bd7094301aff15d873 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Tue, 10 Apr 2018 13:07:10 +0900 Subject: Adding java_sdk_library java_sdk_library is to make a Java library that implements optional SDK APIs to apps. It is actually a wrapper for several modules: 1) stubs library that clients are linked against to, 2) droiddoc module that internally generates API stubs source files, 3) the real runtime shared library that implements the API, and 4) XML file for adding the runtime lib to the classpath at runtime if requested via . Note: this is only the initial CL for the feature. Followings are features currently missing and under development. 1) check for API consistency 2) install stubs libs as the dist artifacts 3) ensuring that apps have appropriate tag 4) disallowing linking to the runtime shared lib 5) HTML generation Bug: 77575606 Test: m -j Change-Id: I4a4ccf6e730e041703c63bb275d8860d0de96887 --- java/java_test.go | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'java/java_test.go') diff --git a/java/java_test.go b/java/java_test.go index d4f2be19e..de514e048 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -83,9 +83,13 @@ func testContext(config android.Config, bp string, ctx.RegisterModuleType("droiddoc", android.ModuleFactoryAdaptor(DroiddocFactory)) ctx.RegisterModuleType("droiddoc_host", android.ModuleFactoryAdaptor(DroiddocHostFactory)) ctx.RegisterModuleType("droiddoc_template", android.ModuleFactoryAdaptor(DroiddocTemplateFactory)) + ctx.RegisterModuleType("java_sdk_library", android.ModuleFactoryAdaptor(sdkLibraryFactory)) ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators) ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) + ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { + ctx.TopDown("java_sdk_library", sdkLibraryMutator).Parallel() + }) ctx.RegisterPreSingletonType("overlay", android.SingletonFactoryAdaptor(OverlaySingletonFactory)) ctx.Register() @@ -998,3 +1002,60 @@ func TestExcludeFileGroupInSrcs(t *testing.T) { t.Errorf(`foo inputs %v != ["java-fg/c.java"]`, javac.Inputs) } } + +func TestJavaSdkLibrary(t *testing.T) { + ctx := testJava(t, ` + droiddoc_template { + name: "droiddoc-templates-sdk", + path: ".", + } + java_library { + name: "conscrypt", + } + java_library { + name: "bouncycastle", + } + java_sdk_library { + name: "foo", + srcs: ["a.java", "b.java"], + api_packages: ["foo"], + } + java_sdk_library { + name: "bar", + srcs: ["a.java", "b.java"], + api_packages: ["bar"], + } + java_library { + name: "baz", + srcs: ["c.java"], + libs: ["foo", "bar"], + sdk_version: "system_current", + } + `) + + // check the existence of the internal modules + ctx.ModuleForTests("foo", "android_common") + ctx.ModuleForTests("foo"+sdkStubsLibrarySuffix, "android_common") + ctx.ModuleForTests("foo"+sdkStubsLibrarySuffix+sdkSystemApiSuffix, "android_common") + ctx.ModuleForTests("foo"+sdkDocsSuffix, "android_common") + ctx.ModuleForTests("foo"+sdkDocsSuffix+sdkSystemApiSuffix, "android_common") + ctx.ModuleForTests("foo"+sdkImplLibrarySuffix, "android_common") + ctx.ModuleForTests("foo"+sdkXmlFileSuffix, "") + + bazJavac := ctx.ModuleForTests("baz", "android_common").Rule("javac") + // tests if baz is actually linked to the stubs lib + if !strings.Contains(bazJavac.Args["classpath"], "foo.stubs.system.jar") { + t.Errorf("baz javac classpath %v does not contain %q", bazJavac.Args["classpath"], + "foo.stubs.system.jar") + } + // ... and not to the impl lib + if strings.Contains(bazJavac.Args["classpath"], "foo.impl.jar") { + t.Errorf("baz javac classpath %v should not contain %q", bazJavac.Args["classpath"], + "foo.impl.jar") + } + // test if baz is not linked to the system variant of foo + if strings.Contains(bazJavac.Args["classpath"], "foo.stubs.jar") { + t.Errorf("baz javac classpath %v should not contain %q", bazJavac.Args["classpath"], + "foo.stubs.jar") + } +} -- cgit v1.2.3-59-g8ed1b