From 39e68fff470e7737c8ae9d9fd46ace1c5f5c70a7 Mon Sep 17 00:00:00 2001 From: mrziwang Date: Mon, 1 Jul 2024 16:35:32 -0700 Subject: [PATCH] Use OutputFilesProvider on droidstubs In the context of incremental soong, the output files inter-module-communication will be through OutputFilesProvider. The OutputFileProducer interface will be deprecated. Test: CI Bug: 339477385 Change-Id: I8ea7463cfc3881d800255aa99147897eeba85b04 --- java/droiddoc_test.go | 6 +-- java/droidstubs.go | 100 +++++++++++++++++------------------------- 2 files changed, 41 insertions(+), 65 deletions(-) diff --git a/java/droiddoc_test.go b/java/droiddoc_test.go index 8d1f5917c..e5846407f 100644 --- a/java/droiddoc_test.go +++ b/java/droiddoc_test.go @@ -69,11 +69,7 @@ func TestDroiddoc(t *testing.T) { "bar-doc/a.java": nil, "bar-doc/b.java": nil, }) - barStubs := ctx.ModuleForTests("bar-stubs", "android_common") - barStubsOutputs, err := barStubs.Module().(*Droidstubs).OutputFiles("") - if err != nil { - t.Errorf("Unexpected error %q retrieving \"bar-stubs\" output file", err) - } + barStubsOutputs := ctx.ModuleForTests("bar-stubs", "android_common").OutputFiles(t, "") if len(barStubsOutputs) != 1 { t.Errorf("Expected one output from \"bar-stubs\" got %s", barStubsOutputs) } diff --git a/java/droidstubs.go b/java/droidstubs.go index 01571858c..a8e0a22e5 100644 --- a/java/droidstubs.go +++ b/java/droidstubs.go @@ -283,66 +283,6 @@ func DroidstubsHostFactory() android.Module { return module } -func getStubsTypeAndTag(tag string) (StubsType, string, error) { - if len(tag) == 0 { - return Everything, "", nil - } - if tag[0] != '.' { - return Unavailable, "", fmt.Errorf("tag must begin with \".\"") - } - - stubsType := Everything - // Check if the tag has a stubs type prefix (e.g. ".exportable") - for st := Everything; st <= Exportable; st++ { - if strings.HasPrefix(tag, "."+st.String()) { - stubsType = st - } - } - - return stubsType, strings.TrimPrefix(tag, "."+stubsType.String()), nil -} - -// Droidstubs' tag supports specifying with the stubs type. -// While supporting the pre-existing tags, it also supports tags with -// the stubs type prefix. Some examples are shown below: -// {.annotations.zip} - pre-existing behavior. Returns the path to the -// annotation zip. -// {.exportable} - Returns the path to the exportable stubs src jar. -// {.exportable.annotations.zip} - Returns the path to the exportable -// annotations zip file. -// {.runtime.api_versions.xml} - Runtime stubs does not generate api versions -// xml file. For unsupported combinations, the default everything output file -// is returned. -func (d *Droidstubs) OutputFiles(tag string) (android.Paths, error) { - stubsType, prefixRemovedTag, err := getStubsTypeAndTag(tag) - if err != nil { - return nil, err - } - switch prefixRemovedTag { - case "": - stubsSrcJar, err := d.StubsSrcJar(stubsType) - return android.Paths{stubsSrcJar}, err - case ".docs.zip": - docZip, err := d.DocZip(stubsType) - return android.Paths{docZip}, err - case ".api.txt", android.DefaultDistTag: - // This is the default dist path for dist properties that have no tag property. - apiFilePath, err := d.ApiFilePath(stubsType) - return android.Paths{apiFilePath}, err - case ".removed-api.txt": - removedApiFilePath, err := d.RemovedApiFilePath(stubsType) - return android.Paths{removedApiFilePath}, err - case ".annotations.zip": - annotationsZip, err := d.AnnotationsZip(stubsType) - return android.Paths{annotationsZip}, err - case ".api_versions.xml": - apiVersionsXmlFilePath, err := d.ApiVersionsXmlFilePath(stubsType) - return android.Paths{apiVersionsXmlFilePath}, err - default: - return nil, fmt.Errorf("unsupported module reference tag %q", tag) - } -} - func (d *Droidstubs) AnnotationsZip(stubsType StubsType) (ret android.Path, err error) { switch stubsType { case Everything: @@ -1363,6 +1303,46 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { rule.Build("nullabilityWarningsCheck", "nullability warnings check") } + + d.setOutputFiles(ctx) +} + +// This method sets the outputFiles property, which is used to set the +// OutputFilesProvider later. +// Droidstubs' tag supports specifying with the stubs type. +// While supporting the pre-existing tags, it also supports tags with +// the stubs type prefix. Some examples are shown below: +// {.annotations.zip} - pre-existing behavior. Returns the path to the +// annotation zip. +// {.exportable} - Returns the path to the exportable stubs src jar. +// {.exportable.annotations.zip} - Returns the path to the exportable +// annotations zip file. +// {.runtime.api_versions.xml} - Runtime stubs does not generate api versions +// xml file. For unsupported combinations, the default everything output file +// is returned. +func (d *Droidstubs) setOutputFiles(ctx android.ModuleContext) { + tagToOutputFileFunc := map[string]func(StubsType) (android.Path, error){ + "": d.StubsSrcJar, + ".docs.zip": d.DocZip, + ".api.txt": d.ApiFilePath, + android.DefaultDistTag: d.ApiFilePath, + ".removed-api.txt": d.RemovedApiFilePath, + ".annotations.zip": d.AnnotationsZip, + ".api_versions.xml": d.ApiVersionsXmlFilePath, + } + stubsTypeToPrefix := map[StubsType]string{ + Everything: "", + Exportable: ".exportable", + } + for _, tag := range android.SortedKeys(tagToOutputFileFunc) { + for _, stubType := range android.SortedKeys(stubsTypeToPrefix) { + tagWithPrefix := stubsTypeToPrefix[stubType] + tag + outputFile, err := tagToOutputFileFunc[tag](stubType) + if err == nil { + ctx.SetOutputFiles(android.Paths{outputFile}, tagWithPrefix) + } + } + } } func (d *Droidstubs) createApiContribution(ctx android.DefaultableHookContext) {