summaryrefslogtreecommitdiff
path: root/java/java_test.go
diff options
context:
space:
mode:
authorJiyong Park <jiyong@google.com>2020-05-28 00:19:53 +0900
committerJiyong Park <jiyong@google.com>2020-05-28 18:07:06 +0900
commit932cdfeb062032b98e237a005a634446a23acd19 (patch)
tree8693a65cee7fcc8902614ae3af85496934950674 /java/java_test.go
parentbd371b653344535d3dec367d1706c5a06dd117b8 (diff)
Add default_to_stubs option to java_sdk_library
Previously, when a lib that doesn't have sdk_version property set depends on a java_sdk_library, the impl library was used for linking. This might be too permissive because the client lib might be using empty sdk_version because it needed some private APIs from the platform, but not from the java_sdk_library. This actually happend for some of the CTS tests. They don't set sdk_version, but were directly depending on android.test.[base|runner|mock].stubs libraries. If we switch the references to the stub libraries into the corresponding java_sdk_library modules (e.g. aandroid.test.[base|runner|mock]), then we would be allowing private APIs to the CTS tests, which is not good. To solve this problem, default_to_stub property is introduced. It when set to true prevents the impl lib from being used for linking. When a module that doesn't have sdk_version depends on it, the widest API surface that the java_sdk_library provides is linked instead. Bug: 157007292 Test: m Change-Id: Id2acc3cafb71d1e90d4fdc9c0c70a73983355e0f
Diffstat (limited to 'java/java_test.go')
-rw-r--r--java/java_test.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/java/java_test.go b/java/java_test.go
index 9266d295d..8ea34d975 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -1465,6 +1465,33 @@ func TestJavaSdkLibrary_FallbackScope(t *testing.T) {
`)
}
+func TestJavaSdkLibrary_DefaultToStubs(t *testing.T) {
+ ctx, _ := testJava(t, `
+ java_sdk_library {
+ name: "foo",
+ srcs: ["a.java"],
+ system: {
+ enabled: true,
+ },
+ default_to_stubs: true,
+ }
+
+ java_library {
+ name: "baz",
+ srcs: ["a.java"],
+ libs: ["foo"],
+ // does not have sdk_version set, should fallback to module,
+ // which will then fallback to system because the module scope
+ // is not enabled.
+ }
+ `)
+ // The baz library should depend on the system stubs jar.
+ bazLibrary := ctx.ModuleForTests("baz", "android_common").Rule("javac")
+ if expected, actual := `^-classpath .*:/[^:]*/turbine-combined/foo\.stubs.system\.jar$`, bazLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) {
+ t.Errorf("expected %q, found %#q", expected, actual)
+ }
+}
+
var compilerFlagsTestCases = []struct {
in string
out bool