Loading android/test_asserts.go +34 −3 Original line number Diff line number Diff line Loading @@ -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 // not then it reports an error prefixed with the supplied message and including a reason for why it // 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() if !InList(s, 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(expected, list) { t.Errorf("%s: could not find %q within %q", message, expected, list) 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) } } Loading java/java_test.go +40 −20 Original line number Diff line number Diff line Loading @@ -1647,31 +1647,51 @@ func TestJavaSdkLibrary_StubOrImplOnlyLibs(t *testing.T) { java_sdk_library { name: "sdklib", srcs: ["a.java"], impl_only_libs: ["foo"], stub_only_libs: ["bar"], libs: ["lib"], 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 { name: "foo", srcs: ["a.java"], sdk_version: "current", } java_library { name: "bar", java_defaults { name: "defaults", srcs: ["a.java"], 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"] } `) for _, implName := range []string{"sdklib", "sdklib.impl"} { implJavacCp := result.ModuleForTests(implName, "android_common").Rule("javac").Args["classpath"] if !strings.Contains(implJavacCp, "/foo.jar") || strings.Contains(implJavacCp, "/bar.jar") { t.Errorf("%v javac classpath %v does not contain foo and not bar", implName, implJavacCp) var expectations = []struct { lib string on_impl_classpath bool on_stub_classpath bool 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}, } verify := func(sdklib, dep string, cp, combined bool) { sdklibCp := result.ModuleForTests(sdklib, "android_common").Rule("javac").Args["classpath"] expected := cp || combined // Every combined jar is also on the classpath. 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") stubsJavacCp := result.ModuleForTests(stubName, "android_common").Rule("javac").Args["classpath"] if strings.Contains(stubsJavacCp, "/foo.jar") || !strings.Contains(stubsJavacCp, "/bar.jar") { t.Errorf("stubs javac classpath %v does not contain bar and not foo", stubsJavacCp) verify(stubName, expectation.lib, expectation.on_stub_classpath, expectation.in_stub_combined) } } Loading java/sdk_library.go +5 −0 Original line number Diff line number Diff line Loading @@ -399,6 +399,9 @@ type sdkLibraryProperties struct { // List of Java libraries that will be in the classpath when building stubs 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. // 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 Loading Loading @@ -1275,6 +1278,7 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext System_modules *string Patch_module *string Libs []string Static_libs []string Compile_dex *bool Java_version *string Openjdk9 struct { Loading @@ -1299,6 +1303,7 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext props.Patch_module = module.properties.Patch_module props.Installable = proptools.BoolPtr(false) 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 // with CLASS retention policy, so that they're kept. if proptools.Bool(module.sdkLibraryProperties.Annotations_enabled) { Loading Loading
android/test_asserts.go +34 −3 Original line number Diff line number Diff line Loading @@ -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 // not then it reports an error prefixed with the supplied message and including a reason for why it // 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() if !InList(s, 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(expected, list) { t.Errorf("%s: could not find %q within %q", message, expected, list) 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) } } Loading
java/java_test.go +40 −20 Original line number Diff line number Diff line Loading @@ -1647,31 +1647,51 @@ func TestJavaSdkLibrary_StubOrImplOnlyLibs(t *testing.T) { java_sdk_library { name: "sdklib", srcs: ["a.java"], impl_only_libs: ["foo"], stub_only_libs: ["bar"], libs: ["lib"], 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 { name: "foo", srcs: ["a.java"], sdk_version: "current", } java_library { name: "bar", java_defaults { name: "defaults", srcs: ["a.java"], 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"] } `) for _, implName := range []string{"sdklib", "sdklib.impl"} { implJavacCp := result.ModuleForTests(implName, "android_common").Rule("javac").Args["classpath"] if !strings.Contains(implJavacCp, "/foo.jar") || strings.Contains(implJavacCp, "/bar.jar") { t.Errorf("%v javac classpath %v does not contain foo and not bar", implName, implJavacCp) var expectations = []struct { lib string on_impl_classpath bool on_stub_classpath bool 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}, } verify := func(sdklib, dep string, cp, combined bool) { sdklibCp := result.ModuleForTests(sdklib, "android_common").Rule("javac").Args["classpath"] expected := cp || combined // Every combined jar is also on the classpath. 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") stubsJavacCp := result.ModuleForTests(stubName, "android_common").Rule("javac").Args["classpath"] if strings.Contains(stubsJavacCp, "/foo.jar") || !strings.Contains(stubsJavacCp, "/bar.jar") { t.Errorf("stubs javac classpath %v does not contain bar and not foo", stubsJavacCp) verify(stubName, expectation.lib, expectation.on_stub_classpath, expectation.in_stub_combined) } } Loading
java/sdk_library.go +5 −0 Original line number Diff line number Diff line Loading @@ -399,6 +399,9 @@ type sdkLibraryProperties struct { // List of Java libraries that will be in the classpath when building stubs 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. // 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 Loading Loading @@ -1275,6 +1278,7 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext System_modules *string Patch_module *string Libs []string Static_libs []string Compile_dex *bool Java_version *string Openjdk9 struct { Loading @@ -1299,6 +1303,7 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext props.Patch_module = module.properties.Patch_module props.Installable = proptools.BoolPtr(false) 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 // with CLASS retention policy, so that they're kept. if proptools.Bool(module.sdkLibraryProperties.Annotations_enabled) { Loading