diff options
Diffstat (limited to 'android/module.go')
-rw-r--r-- | android/module.go | 131 |
1 files changed, 108 insertions, 23 deletions
diff --git a/android/module.go b/android/module.go index ab68e24f1..292508199 100644 --- a/android/module.go +++ b/android/module.go @@ -1177,37 +1177,103 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator data := &attrs.Data - required := depsToLabelList(props.Required) archVariantProps := mod.GetArchVariantProperties(ctx, &commonProperties{}) var enabledProperty bazel.BoolAttribute - if props.Enabled != nil { - enabledProperty.Value = props.Enabled + + onlyAndroid := false + neitherHostNorDevice := false + + osSupport := map[string]bool{} + + // if the target is enabled and supports arch variance, determine the defaults based on the module + // type's host or device property and host_supported/device_supported properties + if mod.commonProperties.ArchSpecific { + moduleSupportsDevice := mod.DeviceSupported() + moduleSupportsHost := mod.HostSupported() + if moduleSupportsHost && !moduleSupportsDevice { + // for host only, we specify as unsupported on android rather than listing all host osSupport + // TODO(b/220874839): consider replacing this with a constraint that covers all host osSupport + // instead + enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, Android.Name, proptools.BoolPtr(false)) + } else if moduleSupportsDevice && !moduleSupportsHost { + enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, Android.Name, proptools.BoolPtr(true)) + // specify as a positive to ensure any target-specific enabled can be resolved + // also save that a target is only android, as if there is only the positive restriction on + // android, it'll be dropped, so we may need to add it back later + onlyAndroid = true + } else if !moduleSupportsHost && !moduleSupportsDevice { + neitherHostNorDevice = true + } + + for _, os := range OsTypeList() { + if os.Class == Host { + osSupport[os.Name] = moduleSupportsHost + } else if os.Class == Device { + osSupport[os.Name] = moduleSupportsDevice + } + } } + if neitherHostNorDevice { + // we can't build this, disable + enabledProperty.Value = proptools.BoolPtr(false) + } else if props.Enabled != nil { + enabledProperty.SetValue(props.Enabled) + if !*props.Enabled { + for os, enabled := range osSupport { + if val := enabledProperty.SelectValue(bazel.OsConfigurationAxis, os); enabled && val != nil && *val { + // if this should be disabled by default, clear out any enabling we've done + enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, os, nil) + } + } + } + } + + required := depsToLabelList(props.Required) for axis, configToProps := range archVariantProps { for config, _props := range configToProps { if archProps, ok := _props.(*commonProperties); ok { - required.SetSelectValue(axis, config, depsToLabelList(archProps.Required).Value) - if archProps.Enabled != nil { - enabledProperty.SetSelectValue(axis, config, archProps.Enabled) + // TODO(b/234748998) Remove this requiredFiltered workaround when aapt2 converts successfully + requiredFiltered := archProps.Required + if name == "apexer" { + requiredFiltered = make([]string, 0, len(archProps.Required)) + for _, req := range archProps.Required { + if req != "aapt2" && req != "apexer" { + requiredFiltered = append(requiredFiltered, req) + } + } + } + required.SetSelectValue(axis, config, depsToLabelList(requiredFiltered).Value) + if !neitherHostNorDevice { + if archProps.Enabled != nil { + if axis != bazel.OsConfigurationAxis || osSupport[config] { + enabledProperty.SetSelectValue(axis, config, archProps.Enabled) + } + } } } } } - if enabledPropertyOverrides.Value != nil { - enabledProperty.Value = enabledPropertyOverrides.Value - } - for _, axis := range enabledPropertyOverrides.SortedConfigurationAxes() { - configToBools := enabledPropertyOverrides.ConfigurableValues[axis] - for cfg, val := range configToBools { - enabledProperty.SetSelectValue(axis, cfg, &val) + if !neitherHostNorDevice { + if enabledPropertyOverrides.Value != nil { + enabledProperty.Value = enabledPropertyOverrides.Value + } + for _, axis := range enabledPropertyOverrides.SortedConfigurationAxes() { + configToBools := enabledPropertyOverrides.ConfigurableValues[axis] + for cfg, val := range configToBools { + if axis != bazel.OsConfigurationAxis || osSupport[cfg] { + enabledProperty.SetSelectValue(axis, cfg, &val) + } + } } } productConfigEnabledLabels := []bazel.Label{} - if !proptools.BoolDefault(enabledProperty.Value, true) { + // TODO(b/234497586): Soong config variables and product variables have different overriding behavior, we + // should handle it correctly + if !proptools.BoolDefault(enabledProperty.Value, true) && !neitherHostNorDevice { // If the module is not enabled by default, then we can check if a // product variable enables it productConfigEnabledLabels = productVariableConfigEnableLabels(ctx) @@ -1224,11 +1290,6 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator productConfigEnabledLabels, nil, }) - moduleSupportsDevice := mod.commonProperties.HostOrDeviceSupported&deviceSupported == deviceSupported - if mod.commonProperties.HostOrDeviceSupported != NeitherHostNorDeviceSupported && !moduleSupportsDevice { - enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, Android.Name, proptools.BoolPtr(false)) - } - platformEnabledAttribute, err := enabledProperty.ToLabelListAttribute( bazel.LabelList{[]bazel.Label{bazel.Label{Label: "@platforms//:incompatible"}}, nil}, bazel.LabelList{[]bazel.Label{}, nil}) @@ -1236,6 +1297,13 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator ctx.ModuleErrorf("Error processing platform enabled attribute: %s", err) } + // if android is the only arch/os enabled, then add a restriction to only be compatible with android + if platformEnabledAttribute.IsNil() && onlyAndroid { + l := bazel.LabelAttribute{} + l.SetValue(bazel.Label{Label: bazel.OsConfigurationAxis.SelectKey(Android.Name)}) + platformEnabledAttribute.Add(&l) + } + data.Append(required) constraints := constraintAttributes{} @@ -2275,7 +2343,11 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) return } - m.module.GenerateAndroidBuildActions(ctx) + if mixedBuildMod, handled := m.isHandledByBazel(ctx); handled { + mixedBuildMod.ProcessBazelQueryResponse(ctx) + } else { + m.module.GenerateAndroidBuildActions(ctx) + } if ctx.Failed() { return } @@ -2331,6 +2403,18 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) m.variables = ctx.variables } +func (m *ModuleBase) isHandledByBazel(ctx ModuleContext) (MixedBuildBuildable, bool) { + if !ctx.Config().BazelContext.BazelEnabled() { + return nil, false + } + if mixedBuildMod, ok := m.module.(MixedBuildBuildable); ok { + if mixedBuildMod.IsMixedBuildSupported(ctx) && MixedBuildsEnabled(ctx) { + return mixedBuildMod, true + } + } + return nil, false +} + // Check the supplied dist structure to make sure that it is valid. // // property - the base property, e.g. dist or dists[1], which is combined with the @@ -2446,7 +2530,7 @@ type baseModuleContext struct { bazelConversionMode bool } -func (b *baseModuleContext) BazelConversionMode() bool { +func (b *baseModuleContext) isBazelConversionMode() bool { return b.bazelConversionMode } func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string { @@ -2835,7 +2919,7 @@ func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, bluepri } func (b *baseModuleContext) ModuleFromName(name string) (blueprint.Module, bool) { - if !b.BazelConversionMode() { + if !b.isBazelConversionMode() { panic("cannot call ModuleFromName if not in bazel conversion mode") } if moduleName, _ := SrcIsModuleWithTag(name); moduleName != "" { @@ -3208,8 +3292,9 @@ func (m *moduleContext) installFile(installPath InstallPath, name string, srcPat extraCmds := "" if extraZip != nil { - extraCmds += fmt.Sprintf(" && unzip -qDD -d '%s' '%s'", + extraCmds += fmt.Sprintf(" && ( unzip -qDD -d '%s' '%s' 2>&1 | grep -v \"zipfile is empty\"; exit $${PIPESTATUS[0]} )", extraZip.dir.String(), extraZip.zip.String()) + extraCmds += " || ( code=$$?; if [ $$code -ne 0 -a $$code -ne 1 ]; then exit $$code; fi )" implicitDeps = append(implicitDeps, extraZip.zip) } |