From 0bd88d0b4e782df6aa99475307a4cfab6d617d14 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Mon, 25 May 2020 12:20:51 +0100 Subject: [PATCH] Correct link type for module stubs Module stubs compile against module_current, so any module depending on them had to compile against module_current (or broader) too. Treat them as the API surface the stubs are for. Bug: 157010342 Test: m Change-Id: I49b9082dc1b5afe6c22e94126e574dd8061f0f39 --- java/java.go | 4 ++++ java/sdk_library.go | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/java/java.go b/java/java.go index 726d4869b..0c5ef5db8 100644 --- a/java/java.go +++ b/java/java.go @@ -843,6 +843,10 @@ func (m *Module) getLinkType(name string) (ret linkType, stubs bool) { return javaSystem, true } + if stub, linkType := moduleStubLinkType(name); stub { + return linkType, true + } + ver := m.sdkVersion() switch ver.kind { case sdkCore: diff --git a/java/sdk_library.go b/java/sdk_library.go index 61bb106d8..94f38f558 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -1224,6 +1224,24 @@ func (s *frameworkModulesNamingScheme) apiModuleName(scope *apiScope, baseName s var _ sdkLibraryComponentNamingScheme = (*frameworkModulesNamingScheme)(nil) +func moduleStubLinkType(name string) (stub bool, ret linkType) { + // This suffix-based approach is fragile and could potentially mis-trigger. + // TODO(b/155164730): Clean this up when modules no longer reference sdk_lib stubs directly. + if strings.HasSuffix(name, ".stubs.public") || strings.HasSuffix(name, "-stubs-publicapi") { + return true, javaSdk + } + if strings.HasSuffix(name, ".stubs.system") || strings.HasSuffix(name, "-stubs-systemapi") { + return true, javaSystem + } + if strings.HasSuffix(name, ".stubs.module_lib") || strings.HasSuffix(name, "-stubs-module_libs_api") { + return true, javaModule + } + if strings.HasSuffix(name, ".stubs.test") { + return true, javaSystem + } + return false, javaPlatform +} + // java_sdk_library is a special Java library that provides optional platform APIs to apps. // In practice, it can be viewed as a combination of several modules: 1) stubs library that clients // are linked against to, 2) droiddoc module that internally generates API stubs source files,