Support dist_group property instead of owner for setting sdk dist subdirectory

Reusing the owner property is confusing, especially when the property is
required on every java_sdk_library module.  Create a new dist_group property
to use instead.

Bug: 186723288
Test: TestJavaSdkLibraryDist
Change-Id: I9e62c703a95d6b63cafa60bffb1b37ba85388593
This commit is contained in:
Colin Cross
2021-06-01 13:13:40 -07:00
parent 30c491b885
commit 986b69aa51
2 changed files with 32 additions and 4 deletions

View File

@@ -457,6 +457,11 @@ type sdkLibraryProperties struct {
// * API incompatibilities baseline filegroup -> <dist-stem>-incompatibilities.api.<scope>.latest // * API incompatibilities baseline filegroup -> <dist-stem>-incompatibilities.api.<scope>.latest
Dist_stem *string 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. // A compatibility mode that allows historical API-tracking files to not exist.
// Do not use. // Do not use.
Unsafe_ignore_missing_latest_api bool Unsafe_ignore_missing_latest_api bool
@@ -1198,12 +1203,10 @@ func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
// The dist path of the stub artifacts // The dist path of the stub artifacts
func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string { func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string {
if module.ModuleBase.Owner() != "" { if Bool(module.sdkLibraryProperties.Core_lib) {
return path.Join("apistubs", module.ModuleBase.Owner(), apiScope.name)
} else if Bool(module.sdkLibraryProperties.Core_lib) {
return path.Join("apistubs", "core", apiScope.name) return path.Join("apistubs", "core", apiScope.name)
} else { } 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()) 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 { func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string {
return ":" + module.distStem() + ".api." + apiScope.name + ".latest" return ":" + module.distStem() + ".api." + apiScope.name + ".latest"
} }

View File

@@ -851,6 +851,13 @@ func TestJavaSdkLibraryDist(t *testing.T) {
srcs: ["foo.java"], 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 { java_sdk_library {
name: "sdklib_owner_foo", name: "sdklib_owner_foo",
unsafe_ignore_missing_latest_api: true, unsafe_ignore_missing_latest_api: true,
@@ -884,6 +891,11 @@ func TestJavaSdkLibraryDist(t *testing.T) {
distDir: "apistubs/android/public", distDir: "apistubs/android/public",
distStem: "sdklib_no_owner.jar", distStem: "sdklib_no_owner.jar",
}, },
{
module: "sdklib_group_foo",
distDir: "apistubs/foo/public",
distStem: "sdklib_group_foo.jar",
},
{ {
module: "sdklib_owner_foo", module: "sdklib_owner_foo",
distDir: "apistubs/foo/public", distDir: "apistubs/foo/public",