diff --git a/java/sdk_library.go b/java/sdk_library.go index 3f87727a7..aec113cdc 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -457,6 +457,11 @@ type sdkLibraryProperties struct { // * API incompatibilities baseline filegroup -> -incompatibilities.api..latest Dist_stem *string + // The subdirectory for the artifacts that are copied to the dist directory. If not specified + // then defaults to "android". Should be set to "android" for anything that should be published + // in the public Android SDK. + Dist_group *string + // A compatibility mode that allows historical API-tracking files to not exist. // Do not use. Unsafe_ignore_missing_latest_api bool @@ -1198,12 +1203,10 @@ func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { // The dist path of the stub artifacts func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string { - if module.ModuleBase.Owner() != "" { - return path.Join("apistubs", module.ModuleBase.Owner(), apiScope.name) - } else if Bool(module.sdkLibraryProperties.Core_lib) { + if Bool(module.sdkLibraryProperties.Core_lib) { return path.Join("apistubs", "core", apiScope.name) } else { - return path.Join("apistubs", "android", apiScope.name) + return path.Join("apistubs", module.distGroup(), apiScope.name) } } @@ -1228,6 +1231,19 @@ func (module *SdkLibrary) distStem() string { return proptools.StringDefault(module.sdkLibraryProperties.Dist_stem, module.BaseModuleName()) } +// distGroup returns the subdirectory of the dist path of the stub artifacts. +func (module *SdkLibrary) distGroup() string { + if group := proptools.String(module.sdkLibraryProperties.Dist_group); group != "" { + return group + } + // TODO(b/186723288): Remove this once everything uses dist_group. + if owner := module.ModuleBase.Owner(); owner != "" { + return owner + } + // TODO(b/186723288): Make this "unknown". + return "android" +} + func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string { return ":" + module.distStem() + ".api." + apiScope.name + ".latest" } diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go index 84b5a242a..0fe6e72ef 100644 --- a/java/sdk_library_test.go +++ b/java/sdk_library_test.go @@ -851,6 +851,13 @@ func TestJavaSdkLibraryDist(t *testing.T) { srcs: ["foo.java"], } + java_sdk_library { + name: "sdklib_group_foo", + unsafe_ignore_missing_latest_api: true, + srcs: ["foo.java"], + dist_group: "foo", + } + java_sdk_library { name: "sdklib_owner_foo", unsafe_ignore_missing_latest_api: true, @@ -884,6 +891,11 @@ func TestJavaSdkLibraryDist(t *testing.T) { distDir: "apistubs/android/public", distStem: "sdklib_no_owner.jar", }, + { + module: "sdklib_group_foo", + distDir: "apistubs/foo/public", + distStem: "sdklib_group_foo.jar", + }, { module: "sdklib_owner_foo", distDir: "apistubs/foo/public",