Use OutputFilesProvider on certain module types

se_build_files, se_cil_compat_map and sepolicy_vers will be using
OutputFilesProvider for output files inter-module-communication.

Test: CI
Bug: 339477385
Change-Id: Ib9972bcdea4850508cb9070903af53973bff9f66
diff --git a/build/soong/build_files.go b/build/soong/build_files.go
index a15c65c..9f9ea63 100644
--- a/build/soong/build_files.go
+++ b/build/soong/build_files.go
@@ -15,10 +15,8 @@
 package selinux
 
 import (
-	"fmt"
 	"path"
 	"path/filepath"
-	"strings"
 
 	"android/soong/android"
 )
@@ -76,16 +74,6 @@
 	// do nothing
 }
 
-func (b *buildFiles) OutputFiles(tag string) (android.Paths, error) {
-	if paths, ok := b.srcs[tag]; ok {
-		return paths, nil
-	}
-
-	return nil, fmt.Errorf("unknown tag %q. Supported tags are: %q", tag, strings.Join(android.SortedKeys(b.srcs), " "))
-}
-
-var _ android.OutputFileProducer = (*buildFiles)(nil)
-
 type sepolicyDir struct {
 	tag   string
 	paths []string
@@ -120,4 +108,12 @@
 		b.srcs[".product_public_"+ver] = b.findSrcsInDirs(ctx, filepath.Join(ctx.DeviceConfig().ProductSepolicyPrebuiltApiDir(), "prebuilts", "api", ver, "public"))
 		b.srcs[".product_private_"+ver] = b.findSrcsInDirs(ctx, filepath.Join(ctx.DeviceConfig().ProductSepolicyPrebuiltApiDir(), "prebuilts", "api", ver, "private"))
 	}
+
+	b.setOutputFiles(ctx)
+}
+
+func (b *buildFiles) setOutputFiles(ctx android.ModuleContext) {
+	for tag, files := range b.srcs {
+		ctx.SetOutputFiles(files, tag)
+	}
 }
diff --git a/build/soong/cil_compat_map.go b/build/soong/cil_compat_map.go
index dd883cc..f834f5d 100644
--- a/build/soong/cil_compat_map.go
+++ b/build/soong/cil_compat_map.go
@@ -19,7 +19,6 @@
 
 import (
 	"android/soong/android"
-	"fmt"
 
 	"github.com/google/blueprint"
 	"github.com/google/blueprint/proptools"
@@ -149,6 +148,10 @@
 		c.installSource = android.OptionalPathForPath(bottomHalf)
 	}
 	ctx.InstallFile(c.installPath, c.stem(), c.installSource.Path())
+
+	if c.installSource.Valid() {
+		ctx.SetOutputFiles(android.Paths{c.installSource.Path()}, "")
+	}
 }
 
 func (c *cilCompatMap) DepsMutator(ctx android.BottomUpMutatorContext) {
@@ -176,19 +179,7 @@
 }
 
 var _ CilCompatMapGenerator = (*cilCompatMap)(nil)
-var _ android.OutputFileProducer = (*cilCompatMap)(nil)
 
 func (c *cilCompatMap) GeneratedMapFile() android.OptionalPath {
 	return c.installSource
 }
-
-func (c *cilCompatMap) OutputFiles(tag string) (android.Paths, error) {
-	if tag == "" {
-		if c.installSource.Valid() {
-			return android.Paths{c.installSource.Path()}, nil
-		} else {
-			return nil, nil
-		}
-	}
-	return nil, fmt.Errorf("Unknown tag %q", tag)
-}
diff --git a/build/soong/selinux_contexts.go b/build/soong/selinux_contexts.go
index 1282b90..d0bbc28 100644
--- a/build/soong/selinux_contexts.go
+++ b/build/soong/selinux_contexts.go
@@ -153,6 +153,8 @@
 
 	m.outputPath = m.build(ctx, android.PathsForModuleSrc(ctx, m.properties.Srcs))
 	ctx.InstallFile(m.installPath, m.stem(), m.outputPath)
+
+	ctx.SetOutputFiles([]android.Path{m.outputPath}, "")
 }
 
 func newModule() *selinuxContextsModule {
@@ -541,16 +543,6 @@
 	return m
 }
 
-var _ android.OutputFileProducer = (*selinuxContextsModule)(nil)
-
-// Implements android.OutputFileProducer
-func (m *selinuxContextsModule) OutputFiles(tag string) (android.Paths, error) {
-	if tag == "" {
-		return []android.Path{m.outputPath}, nil
-	}
-	return nil, fmt.Errorf("unsupported module reference tag %q", tag)
-}
-
 type contextsTestProperties struct {
 	// Contexts files to be tested.
 	Srcs []string `android:"path"`
diff --git a/build/soong/sepolicy_freeze.go b/build/soong/sepolicy_freeze.go
index e1e8956..d6f4f3c 100644
--- a/build/soong/sepolicy_freeze.go
+++ b/build/soong/sepolicy_freeze.go
@@ -94,17 +94,7 @@
 	}
 
 	dep := deps[0]
-	outputFileProducer, ok := dep.(android.OutputFileProducer)
-	if !ok {
-		ctx.ModuleErrorf("module %q is not an output file producer", dep.String())
-		return nil
-	}
-
-	output, err := outputFileProducer.OutputFiles("")
-	if err != nil {
-		ctx.ModuleErrorf("module %q failed to produce output: %w", dep.String(), err)
-		return nil
-	}
+	output := android.OutputFilesForModule(ctx, dep, "")
 	if len(output) != 1 {
 		ctx.ModuleErrorf("module %q produced %d outputs; expected only one output", dep.String(), len(output))
 		return nil
diff --git a/build/soong/sepolicy_vers.go b/build/soong/sepolicy_vers.go
index ca40173..894a3ef 100644
--- a/build/soong/sepolicy_vers.go
+++ b/build/soong/sepolicy_vers.go
@@ -15,8 +15,6 @@
 package selinux
 
 import (
-	"fmt"
-
 	"github.com/google/blueprint/proptools"
 
 	"android/soong/android"
@@ -89,6 +87,8 @@
 	v.installPath = android.PathForModuleInstall(ctx, "etc", "selinux")
 	v.installSource = out
 	ctx.InstallFile(v.installPath, v.stem(), v.installSource)
+
+	ctx.SetOutputFiles(android.Paths{v.installSource}, "")
 }
 
 func (v *sepolicyVers) AndroidMkEntries() []android.AndroidMkEntries {
@@ -103,12 +103,3 @@
 		},
 	}}
 }
-
-func (v *sepolicyVers) OutputFiles(tag string) (android.Paths, error) {
-	if tag == "" {
-		return android.Paths{v.installSource}, nil
-	}
-	return nil, fmt.Errorf("Unknown tag %q", tag)
-}
-
-var _ android.OutputFileProducer = (*sepolicyVers)(nil)