Merge "Clean up android/module.go"

This commit is contained in:
Treehugger Robot
2022-08-08 11:43:36 +00:00
committed by Gerrit Code Review

View File

@@ -35,10 +35,6 @@ import (
var ( var (
DeviceSharedLibrary = "shared_library" DeviceSharedLibrary = "shared_library"
DeviceStaticLibrary = "static_library" DeviceStaticLibrary = "static_library"
DeviceExecutable = "executable"
HostSharedLibrary = "host_shared_library"
HostStaticLibrary = "host_static_library"
HostExecutable = "host_executable"
) )
type BuildParams struct { type BuildParams struct {
@@ -980,8 +976,8 @@ func (t TaggedDistFiles) merge(other TaggedDistFiles) TaggedDistFiles {
} }
func MakeDefaultDistFiles(paths ...Path) TaggedDistFiles { func MakeDefaultDistFiles(paths ...Path) TaggedDistFiles {
for _, path := range paths { for _, p := range paths {
if path == nil { if p == nil {
panic("The path to a dist file cannot be nil.") panic("The path to a dist file cannot be nil.")
} }
} }
@@ -1005,7 +1001,6 @@ const (
MultilibFirst Multilib = "first" MultilibFirst Multilib = "first"
MultilibCommon Multilib = "common" MultilibCommon Multilib = "common"
MultilibCommonFirst Multilib = "common_first" MultilibCommonFirst Multilib = "common_first"
MultilibDefault Multilib = ""
) )
type HostOrDeviceSupported int type HostOrDeviceSupported int
@@ -1149,23 +1144,17 @@ func InitCommonOSAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupport
func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutatorContext, func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutatorContext,
enabledPropertyOverrides bazel.BoolAttribute) constraintAttributes { enabledPropertyOverrides bazel.BoolAttribute) constraintAttributes {
// Assert passed-in attributes include Name
name := attrs.Name
if len(name) == 0 {
ctx.ModuleErrorf("CommonAttributes in fillCommonBp2BuildModuleAttrs expects a `.Name`!")
}
mod := ctx.Module().base() mod := ctx.Module().base()
props := &mod.commonProperties // Assert passed-in attributes include Name
if len(attrs.Name) == 0 {
ctx.ModuleErrorf("CommonAttributes in fillCommonBp2BuildModuleAttrs expects a `.Name`!")
}
depsToLabelList := func(deps []string) bazel.LabelListAttribute { depsToLabelList := func(deps []string) bazel.LabelListAttribute {
return bazel.MakeLabelListAttribute(BazelLabelForModuleDeps(ctx, deps)) return bazel.MakeLabelListAttribute(BazelLabelForModuleDeps(ctx, deps))
} }
data := &attrs.Data
archVariantProps := mod.GetArchVariantProperties(ctx, &commonProperties{})
var enabledProperty bazel.BoolAttribute var enabledProperty bazel.BoolAttribute
onlyAndroid := false onlyAndroid := false
@@ -1193,11 +1182,11 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator
neitherHostNorDevice = true neitherHostNorDevice = true
} }
for _, os := range OsTypeList() { for _, osType := range OsTypeList() {
if os.Class == Host { if osType.Class == Host {
osSupport[os.Name] = moduleSupportsHost osSupport[osType.Name] = moduleSupportsHost
} else if os.Class == Device { } else if osType.Class == Device {
osSupport[os.Name] = moduleSupportsDevice osSupport[osType.Name] = moduleSupportsDevice
} }
} }
} }
@@ -1205,25 +1194,26 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator
if neitherHostNorDevice { if neitherHostNorDevice {
// we can't build this, disable // we can't build this, disable
enabledProperty.Value = proptools.BoolPtr(false) enabledProperty.Value = proptools.BoolPtr(false)
} else if props.Enabled != nil { } else if mod.commonProperties.Enabled != nil {
enabledProperty.SetValue(props.Enabled) enabledProperty.SetValue(mod.commonProperties.Enabled)
if !*props.Enabled { if !*mod.commonProperties.Enabled {
for os, enabled := range osSupport { for oss, enabled := range osSupport {
if val := enabledProperty.SelectValue(bazel.OsConfigurationAxis, os); enabled && val != nil && *val { if val := enabledProperty.SelectValue(bazel.OsConfigurationAxis, oss); enabled && val != nil && *val {
// if this should be disabled by default, clear out any enabling we've done // if this should be disabled by default, clear out any enabling we've done
enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, os, nil) enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, oss, nil)
} }
} }
} }
} }
required := depsToLabelList(props.Required) required := depsToLabelList(mod.commonProperties.Required)
archVariantProps := mod.GetArchVariantProperties(ctx, &commonProperties{})
for axis, configToProps := range archVariantProps { for axis, configToProps := range archVariantProps {
for config, _props := range configToProps { for config, _props := range configToProps {
if archProps, ok := _props.(*commonProperties); ok { if archProps, ok := _props.(*commonProperties); ok {
// TODO(b/234748998) Remove this requiredFiltered workaround when aapt2 converts successfully // TODO(b/234748998) Remove this requiredFiltered workaround when aapt2 converts successfully
requiredFiltered := archProps.Required requiredFiltered := archProps.Required
if name == "apexer" { if attrs.Name == "apexer" {
requiredFiltered = make([]string, 0, len(archProps.Required)) requiredFiltered = make([]string, 0, len(archProps.Required))
for _, req := range archProps.Required { for _, req := range archProps.Required {
if req != "aapt2" && req != "apexer" { if req != "aapt2" && req != "apexer" {
@@ -1278,7 +1268,7 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator
}) })
platformEnabledAttribute, err := enabledProperty.ToLabelListAttribute( platformEnabledAttribute, err := enabledProperty.ToLabelListAttribute(
bazel.LabelList{[]bazel.Label{bazel.Label{Label: "@platforms//:incompatible"}}, nil}, bazel.LabelList{[]bazel.Label{{Label: "@platforms//:incompatible"}}, nil},
bazel.LabelList{[]bazel.Label{}, nil}) bazel.LabelList{[]bazel.Label{}, nil})
if err != nil { if err != nil {
ctx.ModuleErrorf("Error processing platform enabled attribute: %s", err) ctx.ModuleErrorf("Error processing platform enabled attribute: %s", err)
@@ -1291,15 +1281,13 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator
platformEnabledAttribute.Add(&l) platformEnabledAttribute.Add(&l)
} }
data.Append(required) attrs.Data.Append(required)
constraints := constraintAttributes{}
moduleEnableConstraints := bazel.LabelListAttribute{} moduleEnableConstraints := bazel.LabelListAttribute{}
moduleEnableConstraints.Append(platformEnabledAttribute) moduleEnableConstraints.Append(platformEnabledAttribute)
moduleEnableConstraints.Append(productConfigEnabledAttribute) moduleEnableConstraints.Append(productConfigEnabledAttribute)
constraints.Target_compatible_with = moduleEnableConstraints
return constraints return constraintAttributes{Target_compatible_with: moduleEnableConstraints}
} }
// Check product variables for `enabled: true` flag override. // Check product variables for `enabled: true` flag override.
@@ -1642,7 +1630,7 @@ func (m *ModuleBase) BuildParamsForTests() []BuildParams {
// transformSourceToObj, and should only affects unit tests. // transformSourceToObj, and should only affects unit tests.
vars := m.VariablesForTests() vars := m.VariablesForTests()
buildParams := append([]BuildParams(nil), m.buildParams...) buildParams := append([]BuildParams(nil), m.buildParams...)
for i, _ := range buildParams { for i := range buildParams {
newArgs := make(map[string]string) newArgs := make(map[string]string)
for k, v := range buildParams[i].Args { for k, v := range buildParams[i].Args {
newArgs[k] = v newArgs[k] = v
@@ -2287,7 +2275,7 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
// Some common property checks for properties that will be used later in androidmk.go // Some common property checks for properties that will be used later in androidmk.go
checkDistProperties(ctx, "dist", &m.distProperties.Dist) checkDistProperties(ctx, "dist", &m.distProperties.Dist)
for i, _ := range m.distProperties.Dists { for i := range m.distProperties.Dists {
checkDistProperties(ctx, fmt.Sprintf("dists[%d]", i), &m.distProperties.Dists[i]) checkDistProperties(ctx, fmt.Sprintf("dists[%d]", i), &m.distProperties.Dists[i])
} }
@@ -3465,14 +3453,6 @@ func sourceOrOutputDepTag(moduleName, tag string) blueprint.DependencyTag {
return sourceOrOutputDependencyTag{moduleName: moduleName, tag: tag} return sourceOrOutputDependencyTag{moduleName: moduleName, tag: tag}
} }
// IsSourceDepTag returns true if the supplied blueprint.DependencyTag is one that was used to add
// dependencies by either ExtractSourceDeps, ExtractSourcesDeps or automatically for properties
// tagged with `android:"path"`.
func IsSourceDepTag(depTag blueprint.DependencyTag) bool {
_, ok := depTag.(sourceOrOutputDependencyTag)
return ok
}
// IsSourceDepTagWithOutputTag returns true if the supplied blueprint.DependencyTag is one that was // IsSourceDepTagWithOutputTag returns true if the supplied blueprint.DependencyTag is one that was
// used to add dependencies by either ExtractSourceDeps, ExtractSourcesDeps or automatically for // used to add dependencies by either ExtractSourceDeps, ExtractSourcesDeps or automatically for
// properties tagged with `android:"path"` AND it was added using a module reference of // properties tagged with `android:"path"` AND it was added using a module reference of
@@ -3599,14 +3579,14 @@ func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
// be tagged with `android:"path" to support automatic source module dependency resolution. // be tagged with `android:"path" to support automatic source module dependency resolution.
// //
// Deprecated: use PathForModuleSrc instead. // Deprecated: use PathForModuleSrc instead.
func (m *moduleContext) ExpandSource(srcFile, prop string) Path { func (m *moduleContext) ExpandSource(srcFile, _ string) Path {
return PathForModuleSrc(m, srcFile) return PathForModuleSrc(m, srcFile)
} }
// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if // Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module // the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
// dependency resolution. // dependency resolution.
func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath { func (m *moduleContext) ExpandOptionalSource(srcFile *string, _ string) OptionalPath {
if srcFile != nil { if srcFile != nil {
return OptionalPathForPath(PathForModuleSrc(m, *srcFile)) return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
} }