532bde121b
This change stops using deprecated functionality and migrates this repository's custom Soong code to support current practices to manage path property related dependencies. i.e. when a property includes something that looks like ":module". ExtractSourcesDeps has been deprecated in favor of tagging properties with `android:"path"` which will cause the pathDepsMutator to add the dependencies automatically. android.SourceDepTag has been deprecated as the underlying type needs to be changed and this will no longer work for its current uses. * ctx.GetDirectDepWithTag(moduleName, android.SourceDepTag) will not work to retrieve a reference to the module dependency added for path properties. GetModuleFromPathDep(ctx, moduleName, "") must be used instead. * depTag == android.SourceDepTag can no longer be used to check to see if depTag was used to add a module dependency for a module reference in a path property without any output tag. IsSourceDepTagWithOutputTag(depTag, "") must be used instead. Bug: 193228441 Test: m nothing Change-Id: I307039612f0f2a541ac7dbfddd052ef78c290f60
187 lines
5.5 KiB
Go
187 lines
5.5 KiB
Go
// Copyright (C) 2018 The Android Open Source Project
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package selinux
|
|
|
|
// This file contains "se_cil_compat_map" module type used to build and install
|
|
// sepolicy backwards compatibility mapping files.
|
|
|
|
import (
|
|
"android/soong/android"
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/google/blueprint"
|
|
"github.com/google/blueprint/proptools"
|
|
)
|
|
|
|
var (
|
|
combine_maps = pctx.HostBinToolVariable("combine_maps", "combine_maps")
|
|
combineMapsCmd = "${combine_maps} -t ${topHalf} -b ${bottomHalf} -o $out"
|
|
combineMapsRule = pctx.StaticRule(
|
|
"combineMapsRule",
|
|
blueprint.RuleParams{
|
|
Command: combineMapsCmd,
|
|
CommandDeps: []string{"${combine_maps}"},
|
|
},
|
|
"topHalf",
|
|
"bottomHalf",
|
|
)
|
|
|
|
String = proptools.String
|
|
TopHalfDepTag = dependencyTag{name: "top"}
|
|
)
|
|
|
|
func init() {
|
|
android.RegisterModuleType("se_cil_compat_map", cilCompatMapFactory)
|
|
pctx.Import("android/soong/android")
|
|
}
|
|
|
|
func cilCompatMapFactory() android.Module {
|
|
c := &cilCompatMap{}
|
|
c.AddProperties(&c.properties)
|
|
android.InitAndroidArchModule(c, android.DeviceSupported, android.MultilibCommon)
|
|
return c
|
|
}
|
|
|
|
type cilCompatMapProperties struct {
|
|
// se_cil_compat_map module representing a compatibility mapping file for
|
|
// platform versions (x->y). Bottom half represents a mapping (y->z).
|
|
// Together the halves are used to generate a (x->z) mapping.
|
|
Top_half *string
|
|
// list of source (.cil) files used to build an the bottom half of sepolicy
|
|
// compatibility mapping file. bottom_half may reference the outputs of
|
|
// other modules that produce source files like genrule or filegroup using
|
|
// the syntax ":module". srcs has to be non-empty.
|
|
Bottom_half []string `android:"path"`
|
|
// name of the output
|
|
Stem *string
|
|
}
|
|
|
|
type cilCompatMap struct {
|
|
android.ModuleBase
|
|
properties cilCompatMapProperties
|
|
// (.intermediate) module output path as installation source.
|
|
installSource android.Path
|
|
installPath android.InstallPath
|
|
}
|
|
|
|
type CilCompatMapGenerator interface {
|
|
GeneratedMapFile() android.Path
|
|
}
|
|
|
|
func expandTopHalf(ctx android.ModuleContext) android.OptionalPath {
|
|
var topHalf android.OptionalPath
|
|
ctx.VisitDirectDeps(func(dep android.Module) {
|
|
depTag := ctx.OtherModuleDependencyTag(dep)
|
|
switch depTag {
|
|
case TopHalfDepTag:
|
|
topHalf = android.OptionalPathForPath(dep.(CilCompatMapGenerator).GeneratedMapFile())
|
|
}
|
|
})
|
|
return topHalf
|
|
}
|
|
|
|
func expandSeSources(ctx android.ModuleContext, srcFiles []string) android.Paths {
|
|
expandedSrcFiles := make(android.Paths, 0, len(srcFiles))
|
|
for _, s := range srcFiles {
|
|
if m := android.SrcIsModule(s); m != "" {
|
|
module := android.GetModuleFromPathDep(ctx, m, "")
|
|
if module == nil {
|
|
// Error will have been handled by ExtractSourcesDeps
|
|
continue
|
|
}
|
|
if fg, ok := module.(*fileGroup); ok {
|
|
if ctx.ProductSpecific() {
|
|
expandedSrcFiles = append(expandedSrcFiles, fg.ProductPrivateSrcs()...)
|
|
} else if ctx.SystemExtSpecific() {
|
|
expandedSrcFiles = append(expandedSrcFiles, fg.SystemExtPrivateSrcs()...)
|
|
} else {
|
|
expandedSrcFiles = append(expandedSrcFiles, fg.SystemPrivateSrcs()...)
|
|
}
|
|
} else {
|
|
ctx.ModuleErrorf("srcs dependency %q is not an selinux filegroup", m)
|
|
}
|
|
} else {
|
|
p := android.PathForModuleSrc(ctx, s)
|
|
expandedSrcFiles = append(expandedSrcFiles, p)
|
|
}
|
|
}
|
|
return expandedSrcFiles
|
|
}
|
|
|
|
func (c *cilCompatMap) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
c.installPath = android.PathForModuleInstall(ctx, "etc", "selinux", "mapping")
|
|
|
|
srcFiles := expandSeSources(ctx, c.properties.Bottom_half)
|
|
|
|
for _, src := range srcFiles {
|
|
if src.Ext() != ".cil" {
|
|
ctx.PropertyErrorf("bottom_half", "%s has to be a .cil file.", src.String())
|
|
}
|
|
}
|
|
|
|
bottomHalf := android.PathForModuleGen(ctx, "bottom_half")
|
|
ctx.Build(pctx, android.BuildParams{
|
|
Rule: android.Cat,
|
|
Output: bottomHalf,
|
|
Inputs: srcFiles,
|
|
})
|
|
|
|
topHalf := expandTopHalf(ctx)
|
|
if topHalf.Valid() {
|
|
out := android.PathForModuleGen(ctx, c.Name())
|
|
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
|
Rule: combineMapsRule,
|
|
Output: out,
|
|
Implicits: []android.Path{
|
|
topHalf.Path(),
|
|
bottomHalf,
|
|
},
|
|
Args: map[string]string{
|
|
"topHalf": topHalf.String(),
|
|
"bottomHalf": bottomHalf.String(),
|
|
},
|
|
})
|
|
c.installSource = out
|
|
} else {
|
|
c.installSource = bottomHalf
|
|
}
|
|
}
|
|
|
|
func (c *cilCompatMap) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|
if c.properties.Top_half != nil {
|
|
ctx.AddDependency(c, TopHalfDepTag, String(c.properties.Top_half))
|
|
}
|
|
}
|
|
|
|
func (c *cilCompatMap) AndroidMk() android.AndroidMkData {
|
|
ret := android.AndroidMkData{
|
|
OutputFile: android.OptionalPathForPath(c.installSource),
|
|
Class: "ETC",
|
|
}
|
|
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
|
|
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", c.installPath.ToMakePath().String())
|
|
if c.properties.Stem != nil {
|
|
fmt.Fprintln(w, "LOCAL_INSTALLED_MODULE_STEM :=", String(c.properties.Stem))
|
|
}
|
|
})
|
|
return ret
|
|
}
|
|
|
|
var _ CilCompatMapGenerator = (*cilCompatMap)(nil)
|
|
|
|
func (c *cilCompatMap) GeneratedMapFile() android.Path {
|
|
return c.installSource
|
|
}
|