aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duffin <paulduffin@google.com>2023-11-28 16:16:50 +0000
committerPaul Duffin <paulduffin@google.com>2023-11-28 16:26:06 +0000
commit640380699f0eab0c445a59a757bb670954d8f1ed (patch)
tree81e95e4af1e7bad7f94aac6c4e4ee6c00641e589
parent8d6ba4367d853f5d7227ab7ccc9b0512b1191417 (diff)
downloadsoong-640380699f0eab0c445a59a757bb670954d8f1ed.tar.gz
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
-rw-r--r--java/droidstubs.go9
-rw-r--r--java/sdk_library.go20
2 files changed, 19 insertions, 10 deletions
diff --git a/java/droidstubs.go b/java/droidstubs.go
index eaf388740..a9e20e03f 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -544,15 +544,6 @@ func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersi
// information.
cmd.FlagWithArg("--format-defaults ", "overloaded-method-order=source,add-additional-overrides=yes")
- // 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.
- if ctx.Config().GetenvWithDefault("SOONG_SDK_SNAPSHOT_HIDE_FLAGGED_APIS", "false") == "true" {
- cmd.Flag("--hide-annotation android.annotation.FlaggedApi")
- }
-
return cmd
}
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 76f050b73..853792d20 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -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