Merge changes Ib9972bcd,I87d18451 into main

* changes:
  Use OutputFilesProvider on certain module types
  Use OutputFilesProvider on certain module types
This commit is contained in:
Zi Wang 2024-06-10 16:33:43 +00:00 committed by Gerrit Code Review
commit f5f05c1f9f
9 changed files with 31 additions and 128 deletions

View file

@ -15,10 +15,8 @@
package selinux
import (
"fmt"
"path"
"path/filepath"
"strings"
"android/soong/android"
)
@ -76,16 +74,6 @@ func (b *buildFiles) DepsMutator(ctx android.BottomUpMutatorContext) {
// 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 @@ func (b *buildFiles) GenerateAndroidBuildActions(ctx android.ModuleContext) {
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)
}
}

View file

@ -19,7 +19,6 @@ package selinux
import (
"android/soong/android"
"fmt"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@ -149,6 +148,10 @@ func (c *cilCompatMap) GenerateAndroidBuildActions(ctx android.ModuleContext) {
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 @@ func (c *cilCompatMap) AndroidMkEntries() []android.AndroidMkEntries {
}
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)
}

View file

@ -92,6 +92,10 @@ func (c *compatCil) GenerateAndroidBuildActions(ctx android.ModuleContext) {
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) AndroidMkEntries() []android.AndroidMkEntries {
}}
}
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) GenerateSingletonBuildActions(ctx android.SingletonCo
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()))
}

View file

@ -15,7 +15,6 @@
package selinux
import (
"fmt"
"os"
"sort"
"strconv"
@ -294,6 +293,8 @@ func (c *policyConf) GenerateAndroidBuildActions(ctx android.ModuleContext) {
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) AndroidMkEntries() []android.AndroidMkEntries {
}}
}
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 @@ func (c *policyCil) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}
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) AndroidMkEntries() []android.AndroidMkEntries {
}}
}
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 @@ func (c *policyBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}
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) AndroidMkEntries() []android.AndroidMkEntries {
},
}}
}
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)

View file

@ -153,6 +153,8 @@ func (m *selinuxContextsModule) GenerateAndroidBuildActions(ctx android.ModuleCo
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 @@ func vndServiceFactory() android.Module {
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"`

View file

@ -94,17 +94,7 @@ func (f *freezeTestModule) outputFileOfDep(ctx android.ModuleContext, depTag dep
}
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

View file

@ -125,15 +125,7 @@ func (n *neverallowTestModule) GenerateAndroidBuildActions(ctx android.ModuleCon
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:

View file

@ -15,8 +15,6 @@
package selinux
import (
"fmt"
"github.com/google/blueprint/proptools"
"android/soong/android"
@ -89,6 +87,8 @@ func (v *sepolicyVers) GenerateAndroidBuildActions(ctx android.ModuleContext) {
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) AndroidMkEntries() []android.AndroidMkEntries {
},
}}
}
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)

View file

@ -15,7 +15,6 @@
package selinux
import (
"fmt"
"os"
"strconv"
@ -163,6 +162,8 @@ func (m *versionedPolicy) GenerateAndroidBuildActions(ctx android.ModuleContext)
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) AndroidMkEntries() []android.AndroidMkEntries {
},
}}
}
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)