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 <uses-library>.

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 <uses-library> tag
4) disallowing linking to the runtime shared lib
5) HTML generation

Bug: 77575606
Test: m -j

Change-Id: I4a4ccf6e730e041703c63bb275d8860d0de96887
This commit is contained in:
Jiyong Park
2018-04-10 13:07:10 +09:00
parent 59bcf6e631
commit c678ad3f71
7 changed files with 620 additions and 0 deletions

View File

@@ -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")
}
}