From ac103461a47e86665ec78df6e5d9792d7464a57b Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Tue, 19 May 2020 12:06:48 +0100 Subject: [PATCH] Improve the structure of the link check method Match by name first, then by kind. Bug: 157010342 Test: m Change-Id: Ic337a073c3bd14ac03b1d899aeb612247a708495 --- java/java.go | 61 ++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/java/java.go b/java/java.go index da9bd3dfe..726d4869b 100644 --- a/java/java.go +++ b/java/java.go @@ -827,41 +827,42 @@ type linkTypeContext interface { } func (m *Module) getLinkType(name string) (ret linkType, stubs bool) { - ver := m.sdkVersion() - switch { - case name == "core.current.stubs" || name == "core.platform.api.stubs" || - name == "stub-annotations" || name == "private-stub-annotations-jar" || - name == "core-lambda-stubs" || name == "core-generated-annotation-stubs": + switch name { + case "core.current.stubs", "core.platform.api.stubs", "stub-annotations", + "private-stub-annotations-jar", "core-lambda-stubs", "core-generated-annotation-stubs": return javaCore, true - case ver.kind == sdkCore: - return javaCore, false - case name == "android_system_stubs_current": - return javaSystem, true - case ver.kind == sdkSystem: - return javaSystem, false - case name == "android_test_stubs_current": - return javaSystem, true - case ver.kind == sdkTest: - return javaPlatform, false - case name == "android_stubs_current": + case "android_stubs_current": return javaSdk, true - case ver.kind == sdkPublic: - return javaSdk, false - case name == "android_module_lib_stubs_current": + case "android_system_stubs_current": + return javaSystem, true + case "android_module_lib_stubs_current": return javaModule, true - case ver.kind == sdkModule: - return javaModule, false - case name == "android_system_server_stubs_current": + case "android_system_server_stubs_current": return javaSystemServer, true - case ver.kind == sdkSystemServer: - return javaSystemServer, false - case ver.kind == sdkPrivate || ver.kind == sdkNone || ver.kind == sdkCorePlatform: - return javaPlatform, false - case !ver.valid(): - panic(fmt.Errorf("sdk_version is invalid. got %q", ver.raw)) - default: - return javaSdk, false + case "android_test_stubs_current": + return javaSystem, true } + + ver := m.sdkVersion() + switch ver.kind { + case sdkCore: + return javaCore, false + case sdkSystem: + return javaSystem, false + case sdkPublic: + return javaSdk, false + case sdkModule: + return javaModule, false + case sdkSystemServer: + return javaSystemServer, false + case sdkPrivate, sdkNone, sdkCorePlatform, sdkTest: + return javaPlatform, false + } + + if !ver.valid() { + panic(fmt.Errorf("sdk_version is invalid. got %q", ver.raw)) + } + return javaSdk, false } func checkLinkType(ctx android.ModuleContext, from *Module, to linkTypeContext, tag dependencyTag) {