Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 62ac8a07 authored by Liz Kammer's avatar Liz Kammer Committed by Gerrit Code Review
Browse files

Merge "Handle restricting to device only builds"

parents a1675a53 dfeb1203
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -204,6 +204,7 @@ var (
		"system/libziparchive":                               Bp2BuildDefaultTrueRecursively,
		"system/logging/liblog":                              Bp2BuildDefaultTrueRecursively,
		"system/media/audio":                                 Bp2BuildDefaultTrueRecursively,
		"system/memory/libion":                               Bp2BuildDefaultTrueRecursively,
		"system/memory/libmemunreachable":                    Bp2BuildDefaultTrueRecursively,
		"system/sepolicy/apex":                               Bp2BuildDefaultTrueRecursively,
		"system/timezone/apex":                               Bp2BuildDefaultTrueRecursively,
@@ -263,21 +264,23 @@ var (

	Bp2buildModuleAlwaysConvertList = []string{
		// cc mainline modules
		"libnativeloader-headers",
		"libgui_bufferqueue_sources",
		"code_coverage.policy",
		"code_coverage.policy.other",
		"codec2_soft_exports",
		"com.android.media.swcodec-ld.config.txt",
		"libcodec2_headers",
		"libcodec2_internal",
		"com.android.media.swcodec-mediaswcodec.rc",
		"flatbuffer_headers",
		"gemmlowp_headers",
		"gl_headers",
		"libbluetooth-types-header",
		"libaudioclient_aidl_conversion_util",
		"libaudioutils_fixedfft",
		"libbluetooth-types-header",
		"libcodec2_headers",
		"libcodec2_internal",
		"libdmabufheap",
		"libgui_bufferqueue_sources",
		"libnativeloader-headers",
		"libsync",

		//external/avb
		"avbtool",
+75 −17
Original line number Diff line number Diff line
@@ -1181,33 +1181,89 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator
	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)
				}
			}
		}
	}

	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 !neitherHostNorDevice {
					if archProps.Enabled != nil {
						if axis != bazel.OsConfigurationAxis || osSupport[config] {
							enabledProperty.SetSelectValue(axis, config, archProps.Enabled)
						}
					}
				}
			}
		}
	}

	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 +1280,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 +1287,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{}
+5 −0
Original line number Diff line number Diff line
@@ -409,6 +409,11 @@ func (ba BoolAttribute) HasConfigurableValues() bool {
	return false
}

// SetValue sets value for the no config axis
func (ba *BoolAttribute) SetValue(value *bool) {
	ba.SetSelectValue(NoConfigAxis, "", value)
}

// SetSelectValue sets value for the given axis/config.
func (ba *BoolAttribute) SetSelectValue(axis ConfigurationAxis, config string, value *bool) {
	axis.validateConfig(config)
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ android_app_certificate {
}
`,
		expectedBazelTargets: []string{
			makeBazelTarget("android_app_certificate", "com.android.apogee.cert", attrNameToString{
			makeBazelTargetNoRestrictions("android_app_certificate", "com.android.apogee.cert", attrNameToString{
				"certificate": `"chamber_of_secrets_dir"`,
			}),
		}})
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ apex_key {
        private_key: "com.android.apogee.pem",
}
`,
		expectedBazelTargets: []string{makeBazelTarget("apex_key", "com.android.apogee.key", attrNameToString{
		expectedBazelTargets: []string{makeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", attrNameToString{
			"private_key": `"com.android.apogee.pem"`,
			"public_key":  `"com.android.apogee.avbpubkey"`,
		}),
Loading