Add new stub_only_static_libs attr for sdk_library
Allow java_sdk_libraries to include libraries statically into their stubs. The immediate use-case of this is to embed libcore notice files into their stubs. Also extend the java_sdk_library tests for impl/stub-only-libs, plus some not assert utils. Bug: 173186484 Bug: 184839599 Test: soong tests Change-Id: I1ebf2f35c048eab5cec5125482a0304fe660f188
This commit is contained in:
parent
b21166e236
commit
dae54cd84f
|
@ -126,13 +126,44 @@ func AssertStringDoesNotContain(t *testing.T, message string, s string, unexpect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AssertStringContainsEquals checks if the string contains or does not contain the substring, given
|
||||||
|
// the value of the expected bool. If the expectation does not hold it reports an error prefixed with
|
||||||
|
// the supplied message and including a reason for why it failed.
|
||||||
|
func AssertStringContainsEquals(t *testing.T, message string, s string, substring string, expected bool) {
|
||||||
|
if expected {
|
||||||
|
AssertStringDoesContain(t, message, s, substring)
|
||||||
|
} else {
|
||||||
|
AssertStringDoesNotContain(t, message, s, substring)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// AssertStringListContains checks if the list of strings contains the expected string. If it does
|
// AssertStringListContains checks if the list of strings contains the expected string. If it does
|
||||||
// not then it reports an error prefixed with the supplied message and including a reason for why it
|
// not then it reports an error prefixed with the supplied message and including a reason for why it
|
||||||
// failed.
|
// failed.
|
||||||
func AssertStringListContains(t *testing.T, message string, list []string, expected string) {
|
func AssertStringListContains(t *testing.T, message string, list []string, s string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if !InList(expected, list) {
|
if !InList(s, list) {
|
||||||
t.Errorf("%s: could not find %q within %q", message, expected, list)
|
t.Errorf("%s: could not find %q within %q", message, s, list)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssertStringListDoesNotContain checks if the list of strings contains the expected string. If it does
|
||||||
|
// then it reports an error prefixed with the supplied message and including a reason for why it failed.
|
||||||
|
func AssertStringListDoesNotContain(t *testing.T, message string, list []string, s string) {
|
||||||
|
t.Helper()
|
||||||
|
if InList(s, list) {
|
||||||
|
t.Errorf("%s: unexpectedly found %q within %q", message, s, list)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssertStringContainsEquals checks if the string contains or does not contain the substring, given
|
||||||
|
// the value of the expected bool. If the expectation does not hold it reports an error prefixed with
|
||||||
|
// the supplied message and including a reason for why it failed.
|
||||||
|
func AssertStringListContainsEquals(t *testing.T, message string, list []string, s string, expected bool) {
|
||||||
|
if expected {
|
||||||
|
AssertStringListContains(t, message, list, s)
|
||||||
|
} else {
|
||||||
|
AssertStringListDoesNotContain(t, message, list, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1647,31 +1647,51 @@ func TestJavaSdkLibrary_StubOrImplOnlyLibs(t *testing.T) {
|
||||||
java_sdk_library {
|
java_sdk_library {
|
||||||
name: "sdklib",
|
name: "sdklib",
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
impl_only_libs: ["foo"],
|
libs: ["lib"],
|
||||||
stub_only_libs: ["bar"],
|
static_libs: ["static-lib"],
|
||||||
|
impl_only_libs: ["impl-only-lib"],
|
||||||
|
stub_only_libs: ["stub-only-lib"],
|
||||||
|
stub_only_static_libs: ["stub-only-static-lib"],
|
||||||
}
|
}
|
||||||
java_library {
|
java_defaults {
|
||||||
name: "foo",
|
name: "defaults",
|
||||||
srcs: ["a.java"],
|
|
||||||
sdk_version: "current",
|
|
||||||
}
|
|
||||||
java_library {
|
|
||||||
name: "bar",
|
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
sdk_version: "current",
|
sdk_version: "current",
|
||||||
}
|
}
|
||||||
|
java_library { name: "lib", defaults: ["defaults"] }
|
||||||
|
java_library { name: "static-lib", defaults: ["defaults"] }
|
||||||
|
java_library { name: "impl-only-lib", defaults: ["defaults"] }
|
||||||
|
java_library { name: "stub-only-lib", defaults: ["defaults"] }
|
||||||
|
java_library { name: "stub-only-static-lib", defaults: ["defaults"] }
|
||||||
`)
|
`)
|
||||||
|
var expectations = []struct {
|
||||||
for _, implName := range []string{"sdklib", "sdklib.impl"} {
|
lib string
|
||||||
implJavacCp := result.ModuleForTests(implName, "android_common").Rule("javac").Args["classpath"]
|
on_impl_classpath bool
|
||||||
if !strings.Contains(implJavacCp, "/foo.jar") || strings.Contains(implJavacCp, "/bar.jar") {
|
on_stub_classpath bool
|
||||||
t.Errorf("%v javac classpath %v does not contain foo and not bar", implName, implJavacCp)
|
in_impl_combined bool
|
||||||
}
|
in_stub_combined bool
|
||||||
|
}{
|
||||||
|
{lib: "lib", on_impl_classpath: true},
|
||||||
|
{lib: "static-lib", in_impl_combined: true},
|
||||||
|
{lib: "impl-only-lib", on_impl_classpath: true},
|
||||||
|
{lib: "stub-only-lib", on_stub_classpath: true},
|
||||||
|
{lib: "stub-only-static-lib", in_stub_combined: true},
|
||||||
}
|
}
|
||||||
stubName := apiScopePublic.stubsLibraryModuleName("sdklib")
|
verify := func(sdklib, dep string, cp, combined bool) {
|
||||||
stubsJavacCp := result.ModuleForTests(stubName, "android_common").Rule("javac").Args["classpath"]
|
sdklibCp := result.ModuleForTests(sdklib, "android_common").Rule("javac").Args["classpath"]
|
||||||
if strings.Contains(stubsJavacCp, "/foo.jar") || !strings.Contains(stubsJavacCp, "/bar.jar") {
|
expected := cp || combined // Every combined jar is also on the classpath.
|
||||||
t.Errorf("stubs javac classpath %v does not contain bar and not foo", stubsJavacCp)
|
android.AssertStringContainsEquals(t, "bad classpath for "+sdklib, sdklibCp, "/"+dep+".jar", expected)
|
||||||
|
|
||||||
|
combineJarInputs := result.ModuleForTests(sdklib, "android_common").Rule("combineJar").Inputs.Strings()
|
||||||
|
depPath := filepath.Join("out", "soong", ".intermediates", dep, "android_common", "turbine-combined", dep+".jar")
|
||||||
|
android.AssertStringListContainsEquals(t, "bad combined inputs for "+sdklib, combineJarInputs, depPath, combined)
|
||||||
|
}
|
||||||
|
for _, expectation := range expectations {
|
||||||
|
verify("sdklib", expectation.lib, expectation.on_impl_classpath, expectation.in_impl_combined)
|
||||||
|
verify("sdklib.impl", expectation.lib, expectation.on_impl_classpath, expectation.in_impl_combined)
|
||||||
|
|
||||||
|
stubName := apiScopePublic.stubsLibraryModuleName("sdklib")
|
||||||
|
verify(stubName, expectation.lib, expectation.on_stub_classpath, expectation.in_stub_combined)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -399,6 +399,9 @@ type sdkLibraryProperties struct {
|
||||||
// List of Java libraries that will be in the classpath when building stubs
|
// List of Java libraries that will be in the classpath when building stubs
|
||||||
Stub_only_libs []string `android:"arch_variant"`
|
Stub_only_libs []string `android:"arch_variant"`
|
||||||
|
|
||||||
|
// List of Java libraries that will included in stub libraries
|
||||||
|
Stub_only_static_libs []string `android:"arch_variant"`
|
||||||
|
|
||||||
// list of package names that will be documented and publicized as API.
|
// list of package names that will be documented and publicized as API.
|
||||||
// This allows the API to be restricted to a subset of the source files provided.
|
// This allows the API to be restricted to a subset of the source files provided.
|
||||||
// If this is unspecified then all the source files will be treated as being part
|
// If this is unspecified then all the source files will be treated as being part
|
||||||
|
@ -1275,6 +1278,7 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext
|
||||||
System_modules *string
|
System_modules *string
|
||||||
Patch_module *string
|
Patch_module *string
|
||||||
Libs []string
|
Libs []string
|
||||||
|
Static_libs []string
|
||||||
Compile_dex *bool
|
Compile_dex *bool
|
||||||
Java_version *string
|
Java_version *string
|
||||||
Openjdk9 struct {
|
Openjdk9 struct {
|
||||||
|
@ -1299,6 +1303,7 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext
|
||||||
props.Patch_module = module.properties.Patch_module
|
props.Patch_module = module.properties.Patch_module
|
||||||
props.Installable = proptools.BoolPtr(false)
|
props.Installable = proptools.BoolPtr(false)
|
||||||
props.Libs = module.sdkLibraryProperties.Stub_only_libs
|
props.Libs = module.sdkLibraryProperties.Stub_only_libs
|
||||||
|
props.Static_libs = module.sdkLibraryProperties.Stub_only_static_libs
|
||||||
// The stub-annotations library contains special versions of the annotations
|
// The stub-annotations library contains special versions of the annotations
|
||||||
// with CLASS retention policy, so that they're kept.
|
// with CLASS retention policy, so that they're kept.
|
||||||
if proptools.Bool(module.sdkLibraryProperties.Annotations_enabled) {
|
if proptools.Bool(module.sdkLibraryProperties.Annotations_enabled) {
|
||||||
|
|
Loading…
Reference in New Issue