summaryrefslogtreecommitdiff
path: root/java/java_test.go
diff options
context:
space:
mode:
authorPaul Duffin <paulduffin@google.com>2020-05-20 11:52:25 +0100
committerPaul Duffin <paulduffin@google.com>2020-05-20 18:00:45 +0100
commit803a9565cd3d85ba22fb00f870b8fffabc3ab30d (patch)
tree656b554ec43bc1be840854428e1af1aca7096856 /java/java_test.go
parentb05d4295de0883cb1e31c04971a6c5dbea719ed1 (diff)
java_sdk_library: Add redirection to module-lib stubs
Previously, when using sdk_version: "module_current" any direct reference to an sdk library would use the public not module-lib stubs. This change corrects that. Prior to the addition of the module-lib api scope almost all java_sdk_library instances supported all the scopes to which a request for jars could be redirected, i.e. public, system and test. The exceptions to that are a few special instances that were used with sdk_version: "none" and so were either caught by the java_sdk_library special cases or dropped through to public. The addition of module-lib, plus the flexible control over which scopes are generated means that is no longer true. It is possible for a java_sdk_library to be requested for a scope it does not have which would have resulted in an empty set of paths being returned leading to confusing compilation errors. To avoid that this change also adds support for using the inheritance hierarchy defined by the apiScope.extends field to fall back to the closest available surface. Test: m nothing Bug: 155164730 Change-Id: I6aab75a772433ee0a36b6f1758a4aec4be2f9a49
Diffstat (limited to 'java/java_test.go')
-rw-r--r--java/java_test.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/java/java_test.go b/java/java_test.go
index f61f4bb20..af2c3626a 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -1261,6 +1261,45 @@ func TestJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) {
`)
}
+func TestJavaSdkLibrary_MissingScope(t *testing.T) {
+ testJavaError(t, `requires api scope module-lib from foo but it only has \[\] available`, `
+ java_sdk_library {
+ name: "foo",
+ srcs: ["a.java"],
+ public: {
+ enabled: false,
+ },
+ }
+
+ java_library {
+ name: "baz",
+ srcs: ["a.java"],
+ libs: ["foo"],
+ sdk_version: "module_current",
+ }
+ `)
+}
+
+func TestJavaSdkLibrary_FallbackScope(t *testing.T) {
+ testJava(t, `
+ java_sdk_library {
+ name: "foo",
+ srcs: ["a.java"],
+ system: {
+ enabled: true,
+ },
+ }
+
+ java_library {
+ name: "baz",
+ srcs: ["a.java"],
+ libs: ["foo"],
+ // foo does not have module-lib scope so it should fallback to system
+ sdk_version: "module_current",
+ }
+ `)
+}
+
var compilerFlagsTestCases = []struct {
in string
out bool