Use OutputFilesProvider on certain module types

The module types below no longer implement OutputFileProducer, but
use OutputFilesProvider for output files inter-module-communication.

se_policy_conf
se_policy_cil
se_policy_binary
se_compat_cil
se_versioned_policy

Test: CI
Bug: 339477385
Change-Id: I87d1845162f91065acd7d2f6c27fd7583cc8b5e0
diff --git a/build/soong/compat_cil.go b/build/soong/compat_cil.go
index baad413..3b9d5e2 100644
--- a/build/soong/compat_cil.go
+++ b/build/soong/compat_cil.go
@@ -92,6 +92,10 @@
 	c.installPath = android.PathForModuleInstall(ctx, "etc", "selinux", "mapping")
 	c.installSource = android.OptionalPathForPath(out)
 	ctx.InstallFile(c.installPath, c.stem(), out)
+
+	if c.installSource.Valid() {
+		ctx.SetOutputFiles(android.Paths{c.installSource.Path()}, "")
+	}
 }
 
 func (c *compatCil) AndroidMkEntries() []android.AndroidMkEntries {
@@ -110,21 +114,6 @@
 	}}
 }
 
-func (c *compatCil) OutputFiles(tag string) (android.Paths, error) {
-	switch tag {
-	case "":
-		if c.installSource.Valid() {
-			return android.Paths{c.installSource.Path()}, nil
-		} else {
-			return nil, nil
-		}
-	default:
-		return nil, fmt.Errorf("unsupported module reference tag %q", tag)
-	}
-}
-
-var _ android.OutputFileProducer = (*compatCil)(nil)
-
 // se_compat_test checks if compat files ({ver}.cil, {ver}.compat.cil) files are compatible with
 // current policy.
 func compatTestFactory() android.SingletonModule {
@@ -239,15 +228,7 @@
 func (f *compatTestModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
 	var inputs android.Paths
 	ctx.VisitDirectDepsWithTag(compatTestDepTag, func(child android.Module) {
-		o, ok := child.(android.OutputFileProducer)
-		if !ok {
-			panic(fmt.Errorf("Module %q should be an OutputFileProducer but it isn't", ctx.OtherModuleName(child)))
-		}
-
-		outputs, err := o.OutputFiles("")
-		if err != nil {
-			panic(fmt.Errorf("Module %q error while producing output: %v", ctx.OtherModuleName(child), err))
-		}
+		outputs := android.OutputFilesForModule(ctx, child, "")
 		if len(outputs) != 1 {
 			panic(fmt.Errorf("Module %q should produce exactly one output, but did %q", ctx.OtherModuleName(child), outputs.Strings()))
 		}
diff --git a/build/soong/policy.go b/build/soong/policy.go
index be9d34e..7b2122c 100644
--- a/build/soong/policy.go
+++ b/build/soong/policy.go
@@ -15,7 +15,6 @@
 package selinux
 
 import (
-	"fmt"
 	"os"
 	"sort"
 	"strconv"
@@ -294,6 +293,8 @@
 	c.installSource = c.transformPolicyToConf(ctx)
 	c.installPath = android.PathForModuleInstall(ctx, "etc")
 	ctx.InstallFile(c.installPath, c.stem(), c.installSource)
+
+	ctx.SetOutputFiles(android.Paths{c.installSource}, "")
 }
 
 func (c *policyConf) AndroidMkEntries() []android.AndroidMkEntries {
@@ -310,15 +311,6 @@
 	}}
 }
 
-func (c *policyConf) OutputFiles(tag string) (android.Paths, error) {
-	if tag == "" {
-		return android.Paths{c.installSource}, nil
-	}
-	return nil, fmt.Errorf("Unknown tag %q", tag)
-}
-
-var _ android.OutputFileProducer = (*policyConf)(nil)
-
 type policyCilProperties struct {
 	// Name of the output. Default is {module_name}
 	Stem *string
@@ -457,6 +449,8 @@
 	}
 	c.installSource = cil
 	ctx.InstallFile(c.installPath, c.stem(), c.installSource)
+
+	ctx.SetOutputFiles(android.Paths{c.installSource}, "")
 }
 
 func (c *policyCil) AndroidMkEntries() []android.AndroidMkEntries {
@@ -473,15 +467,6 @@
 	}}
 }
 
-func (c *policyCil) OutputFiles(tag string) (android.Paths, error) {
-	if tag == "" {
-		return android.Paths{c.installSource}, nil
-	}
-	return nil, fmt.Errorf("Unknown tag %q", tag)
-}
-
-var _ android.OutputFileProducer = (*policyCil)(nil)
-
 type policyBinaryProperties struct {
 	// Name of the output. Default is {module_name}
 	Stem *string
@@ -604,6 +589,8 @@
 	}
 	c.installSource = out
 	ctx.InstallFile(c.installPath, c.stem(), c.installSource)
+
+	ctx.SetOutputFiles(android.Paths{c.installSource}, "")
 }
 
 func (c *policyBinary) AndroidMkEntries() []android.AndroidMkEntries {
@@ -619,12 +606,3 @@
 		},
 	}}
 }
-
-func (c *policyBinary) OutputFiles(tag string) (android.Paths, error) {
-	if tag == "" {
-		return android.Paths{c.installSource}, nil
-	}
-	return nil, fmt.Errorf("Unknown tag %q", tag)
-}
-
-var _ android.OutputFileProducer = (*policyBinary)(nil)
diff --git a/build/soong/sepolicy_neverallow.go b/build/soong/sepolicy_neverallow.go
index d46c6b4..78cbc84 100644
--- a/build/soong/sepolicy_neverallow.go
+++ b/build/soong/sepolicy_neverallow.go
@@ -125,15 +125,7 @@
 			return
 		}
 
-		o, ok := child.(android.OutputFileProducer)
-		if !ok {
-			panic(fmt.Errorf("Module %q isn't an OutputFileProducer", ctx.OtherModuleName(child)))
-		}
-
-		outputs, err := o.OutputFiles("")
-		if err != nil {
-			panic(fmt.Errorf("Module %q error while producing output: %v", ctx.OtherModuleName(child), err))
-		}
+		outputs := android.OutputFilesForModule(ctx, child, "")
 
 		switch ctx.OtherModuleDependencyTag(child) {
 		case checkpolicyTag:
diff --git a/build/soong/versioned_policy.go b/build/soong/versioned_policy.go
index be396e3..9c8b9cd 100644
--- a/build/soong/versioned_policy.go
+++ b/build/soong/versioned_policy.go
@@ -15,7 +15,6 @@
 package selinux
 
 import (
-	"fmt"
 	"os"
 	"strconv"
 
@@ -163,6 +162,8 @@
 		m.installPath = m.installPath.Join(ctx, subdir)
 	}
 	ctx.InstallFile(m.installPath, m.installSource.Base(), m.installSource)
+
+	ctx.SetOutputFiles(android.Paths{m.installSource}, "")
 }
 
 func (m *versionedPolicy) AndroidMkEntries() []android.AndroidMkEntries {
@@ -178,12 +179,3 @@
 		},
 	}}
 }
-
-func (m *versionedPolicy) OutputFiles(tag string) (android.Paths, error) {
-	if tag == "" {
-		return android.Paths{m.installSource}, nil
-	}
-	return nil, fmt.Errorf("Unknown tag %q", tag)
-}
-
-var _ android.OutputFileProducer = (*policyConf)(nil)