Move special next handling of hidden APIs to java_sdk_library

Previously, the logic to add the Metalava command line option
`--hide-annotation android.annotation.FlaggedApi` when
`SOONG_SDK_SNAPSHOT_HIDE_FLAGGED_APIS=true` was done in
`droidstubs.go`. It worked but it turns out that we need to pass more
options to Metalava in that situation because while we need to hide
most flagged APIs we need to release some flagged APIs whose features
are ready. They cannot have the `@FlaggedApi` annotation removed
because that would cause the APIs to be released in the next QPR which
is not what we want.

So, in addition to the above option we will need to pass additional
options to Metalava to tell it to keep some flagged APIs. Rather than
hard code that in the build, requiring build changes for every new
SDK extension release this change uses the argument expansion mechanism
in Metalava (treating `@<file>` as if the contents of `<file>` were
passed as command line options) to delegate that to
":sdkext-released-flagged-apis".

The easiest way to do that was to move the logic to `sdk_library.go`
as `droidstub` would do the work of tracking the file dependencies
correctly. It also reduces the affect modules to `java_sdk_library`
modules rather than all `droidstubs` modules.

Bug: 313398274
Test: UNBUNDLED_BUILD_SDKS_FROM_SOURCE=true vendor/google/build/mainline_modules_sdks.sh --build-release=next
Change-Id: Ib1cf22f8ef74abc135215537e9311936372eaac7
Merged-In: I4967376c0236bad729398af80fa59b48dbab5f21
This commit is contained in:
Paul Duffin
2023-11-28 16:16:50 +00:00
parent 8d6ba4367d
commit 640380699f
2 changed files with 19 additions and 10 deletions

View File

@@ -1682,6 +1682,24 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC
}
droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide "))
droidstubsFiles := append([]string{}, module.sdkLibraryProperties.Droiddoc_option_files...)
// If requested hide the flagged APIs from the output of metalava. This
// should be implemented in the module SDK snapshot code by depending on
// special metalava rules that hide the flagged APIs but that will take
// lots of work. In the meantime, this is a temporary workaround that
// can and will only be used when building module SDK snapshots. This
// delegates the decision as to what options are passed to metalava to
// the "sdkext-released-flagged-apis" module by using metalava's support
// for expanding an argument of the form "@<file>" to the list of
// arguments found in <file>.
if mctx.Config().GetenvWithDefault("SOONG_SDK_SNAPSHOT_HIDE_FLAGGED_APIS", "false") == "true" {
metalavaHideFlaggedApisSource := ":sdkext-released-flagged-apis"
droidstubsArgs = append(droidstubsArgs,
fmt.Sprintf("@$(location %s)", metalavaHideFlaggedApisSource))
droidstubsFiles = append(droidstubsFiles, metalavaHideFlaggedApisSource)
}
// Output Javadoc comments for public scope.
if apiScope == apiScopePublic {
props.Output_javadoc_comments = proptools.BoolPtr(true)
@@ -1689,7 +1707,7 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC
// Add in scope specific arguments.
droidstubsArgs = append(droidstubsArgs, scopeSpecificDroidstubsArgs...)
props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
props.Arg_files = droidstubsFiles
props.Args = proptools.StringPtr(strings.Join(droidstubsArgs, " "))
// List of APIs identified from the provided source files are created. They are later