diff options
author | 2024-08-21 20:42:18 +0000 | |
---|---|---|
committer | 2024-08-22 22:05:03 +0000 | |
commit | fa3f0782f7b1f179435f19d37e7e348cff626695 (patch) | |
tree | c27f01eae78d8a0b6d719b6a85e1bc2cacf9c294 /java/sdk_library.go | |
parent | 5fdb54d4393505a38d25fa633ea11968ebbf1316 (diff) |
Remove suffix based stub matching logic
This change prevents non-stub modules with stub suffix from being
determined as the stub module, and instead makes the check more robust
by determining the condition based on the user-hidden
`Stub_contributing_api` property, which is only set for the stub
submodules generated by `java_sdk_library`.
Test: m nothing --no-skip-soong-tests
Bug: 361179822
Change-Id: I28a599c5b4fe1e8460e60580c0535aaf19e39ba3
Diffstat (limited to 'java/sdk_library.go')
-rw-r--r-- | java/sdk_library.go | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/java/sdk_library.go b/java/sdk_library.go index 4f95a997d..765e96391 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -1794,7 +1794,8 @@ type libraryProperties struct { Dir *string Tag *string } - Is_stubs_module *bool + Is_stubs_module *bool + Stub_contributing_api *string } func (module *SdkLibrary) stubsLibraryProps(mctx android.DefaultableHookContext, apiScope *apiScope) libraryProperties { @@ -1820,6 +1821,7 @@ func (module *SdkLibrary) stubsLibraryProps(mctx android.DefaultableHookContext, // interop with older developer tools that don't support 1.9. props.Java_version = proptools.StringPtr("1.8") props.Is_stubs_module = proptools.BoolPtr(true) + props.Stub_contributing_api = proptools.StringPtr(apiScope.kind.String()) return props } @@ -2087,6 +2089,8 @@ func (module *SdkLibrary) topLevelStubsLibraryProps(mctx android.DefaultableHook } props.Compile_dex = compileDex + props.Stub_contributing_api = proptools.StringPtr(apiScope.kind.String()) + if !Bool(module.sdkLibraryProperties.No_dist) && doDist { props.Dist.Targets = []string{"sdk", "win_sdk"} props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.distStem())) @@ -2423,36 +2427,25 @@ func (s *defaultNamingScheme) exportableSourceStubsLibraryModuleName(scope *apiS var _ sdkLibraryComponentNamingScheme = (*defaultNamingScheme)(nil) -func hasStubsLibrarySuffix(name string, apiScope *apiScope) bool { - return strings.HasSuffix(name, apiScope.stubsLibraryModuleNameSuffix()) || - strings.HasSuffix(name, apiScope.exportableStubsLibraryModuleNameSuffix()) -} - -func moduleStubLinkType(name string) (stub bool, ret sdkLinkType) { - name = strings.TrimSuffix(name, ".from-source") - - // 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 hasStubsLibrarySuffix(name, apiScopePublic) { - if name == "hwbinder.stubs" || name == "libcore_private.stubs" { - // Due to a previous bug, these modules were not considered stubs, so we retain that. - return false, javaPlatform - } +func moduleStubLinkType(j *Module) (stub bool, ret sdkLinkType) { + kind := android.ToSdkKind(proptools.String(j.properties.Stub_contributing_api)) + switch kind { + case android.SdkPublic: return true, javaSdk - } - if hasStubsLibrarySuffix(name, apiScopeSystem) { + case android.SdkSystem: return true, javaSystem - } - if hasStubsLibrarySuffix(name, apiScopeModuleLib) { + case android.SdkModule: return true, javaModule - } - if hasStubsLibrarySuffix(name, apiScopeTest) { + case android.SdkTest: return true, javaSystem - } - if hasStubsLibrarySuffix(name, apiScopeSystemServer) { + case android.SdkSystemServer: return true, javaSystemServer + // Default value for all modules other than java_sdk_library-generated stub submodules + case android.SdkInvalid: + return false, javaPlatform + default: + panic(fmt.Sprintf("stub_contributing_api set as an unsupported sdk kind %s", kind.String())) } - return false, javaPlatform } // java_sdk_library is a special Java library that provides optional platform APIs to apps. |