Use OutputFilesProvider on java modules
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: I3c9f0b766325dd490bc903dc65259c3953d34606
diff --git a/java/sdk_library.go b/java/sdk_library.go
index e6cb6c4..031bde3 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1086,57 +1086,26 @@
return regexp.MustCompile(fmt.Sprintf(`^\.(%s)\.(%s)$`, scopesRegexp, componentsRegexp))
}()
-// For OutputFileProducer interface
-//
-// .<scope>.<component name>, for all ComponentNames (for example: .public.removed-api.txt)
-func (c *commonToSdkLibraryAndImport) commonOutputFiles(tag string) (android.Paths, error) {
- if groups := tagSplitter.FindStringSubmatch(tag); groups != nil {
- scopeName := groups[1]
- component := groups[2]
-
- if scope, ok := scopeByName[scopeName]; ok {
- paths := c.findScopePaths(scope)
- if paths == nil {
- return nil, fmt.Errorf("%q does not provide api scope %s", c.module.RootLibraryName(), scopeName)
- }
-
- switch component {
- case stubsSourceComponentName:
- if paths.stubsSrcJar.Valid() {
- return android.Paths{paths.stubsSrcJar.Path()}, nil
- }
-
- case apiTxtComponentName:
- if paths.currentApiFilePath.Valid() {
- return android.Paths{paths.currentApiFilePath.Path()}, nil
- }
-
- case removedApiTxtComponentName:
- if paths.removedApiFilePath.Valid() {
- return android.Paths{paths.removedApiFilePath.Path()}, nil
- }
-
- case annotationsComponentName:
- if paths.annotationsZip.Valid() {
- return android.Paths{paths.annotationsZip.Path()}, nil
- }
- }
-
- return nil, fmt.Errorf("%s not available for api scope %s", component, scopeName)
- } else {
- return nil, fmt.Errorf("unknown scope %s in %s", scope, tag)
+func (module *commonToSdkLibraryAndImport) setOutputFiles(ctx android.ModuleContext) {
+ if module.doctagPaths != nil {
+ ctx.SetOutputFiles(module.doctagPaths, ".doctags")
+ }
+ for _, scopeName := range android.SortedKeys(scopeByName) {
+ paths := module.findScopePaths(scopeByName[scopeName])
+ if paths == nil {
+ continue
}
-
- } else {
- switch tag {
- case ".doctags":
- if c.doctagPaths != nil {
- return c.doctagPaths, nil
- } else {
- return nil, fmt.Errorf("no doctag_files specified on %s", c.module.RootLibraryName())
+ componentToOutput := map[string]android.OptionalPath{
+ stubsSourceComponentName: paths.stubsSrcJar,
+ apiTxtComponentName: paths.currentApiFilePath,
+ removedApiTxtComponentName: paths.removedApiFilePath,
+ annotationsComponentName: paths.annotationsZip,
+ }
+ for _, component := range android.SortedKeys(componentToOutput) {
+ if componentToOutput[component].Valid() {
+ ctx.SetOutputFiles(android.Paths{componentToOutput[component].Path()}, "."+scopeName+"."+component)
}
}
- return nil, nil
}
}
@@ -1579,20 +1548,6 @@
}
}
-func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) {
- paths, err := module.commonOutputFiles(tag)
- if paths != nil || err != nil {
- return paths, err
- }
- if module.requiresRuntimeImplementationLibrary() {
- return module.implLibraryModule.OutputFiles(tag)
- }
- if tag == "" {
- return nil, nil
- }
- return nil, fmt.Errorf("unsupported module reference tag %q", tag)
-}
-
func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if disableSourceApexVariant(ctx) {
// Prebuilts are active, do not create the installation rules for the source javalib.
@@ -1702,6 +1657,10 @@
}
}
android.SetProvider(ctx, android.AdditionalSdkInfoProvider, android.AdditionalSdkInfo{additionalSdkInfo})
+ module.setOutputFiles(ctx)
+ if module.requiresRuntimeImplementationLibrary() && module.implLibraryModule != nil {
+ setOutputFiles(ctx, module.implLibraryModule.Module)
+ }
}
func (module *SdkLibrary) BuiltInstalledForApex() []dexpreopterInstall {
@@ -2937,18 +2896,6 @@
var _ hiddenAPIModule = (*SdkLibraryImport)(nil)
-func (module *SdkLibraryImport) OutputFiles(tag string) (android.Paths, error) {
- paths, err := module.commonOutputFiles(tag)
- if paths != nil || err != nil {
- return paths, err
- }
- if module.implLibraryModule != nil {
- return module.implLibraryModule.OutputFiles(tag)
- } else {
- return nil, nil
- }
-}
-
func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
module.generateCommonBuildActions(ctx)
@@ -3031,6 +2978,11 @@
}
}
}
+
+ module.setOutputFiles(ctx)
+ if module.implLibraryModule != nil {
+ setOutputFiles(ctx, module.implLibraryModule.Module)
+ }
}
func (module *SdkLibraryImport) sdkJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec, headerJars bool) android.Paths {