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

Commit 94f8a60f authored by Christopher Parsons's avatar Christopher Parsons Committed by Gerrit Code Review
Browse files

Merge "Fix nondeterminism in bp2build"

parents e136efdc 7b3289b4
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -343,8 +343,8 @@ type ConfigurationAxis struct {
}

func (ca *ConfigurationAxis) less(other ConfigurationAxis) bool {
	if ca.configurationType < other.configurationType {
		return true
	}
	if ca.configurationType == other.configurationType {
		return ca.subType < other.subType
	}
	return ca.configurationType < other.configurationType
}
+15 −35
Original line number Diff line number Diff line
@@ -73,6 +73,16 @@ func MakeLabelList(labels []Label) LabelList {
	}
}

func SortedConfigurationAxes[T any](m map[ConfigurationAxis]T) []ConfigurationAxis {
	keys := make([]ConfigurationAxis, 0, len(m))
	for k := range m {
		keys = append(keys, k)
	}

	sort.Slice(keys, func(i, j int) bool { return keys[i].less(keys[j]) })
	return keys
}

// MakeLabelListFromTargetNames creates a LabelList from unqualified target names
// This is a utiltity function for bp2build converters of Soong modules that have 1:many generated targets
func MakeLabelListFromTargetNames(targetNames []string) LabelList {
@@ -412,13 +422,7 @@ func (la *LabelAttribute) SelectValue(axis ConfigurationAxis, config string) *La

// SortedConfigurationAxes returns all the used ConfigurationAxis in sorted order.
func (la *LabelAttribute) SortedConfigurationAxes() []ConfigurationAxis {
	keys := make([]ConfigurationAxis, 0, len(la.ConfigurableValues))
	for k := range la.ConfigurableValues {
		keys = append(keys, k)
	}

	sort.Slice(keys, func(i, j int) bool { return keys[i].less(keys[j]) })
	return keys
	return SortedConfigurationAxes(la.ConfigurableValues)
}

// MakeLabelAttribute turns a string into a LabelAttribute
@@ -608,13 +612,7 @@ func (ba BoolAttribute) SelectValue(axis ConfigurationAxis, config string) *bool

// SortedConfigurationAxes returns all the used ConfigurationAxis in sorted order.
func (ba *BoolAttribute) SortedConfigurationAxes() []ConfigurationAxis {
	keys := make([]ConfigurationAxis, 0, len(ba.ConfigurableValues))
	for k := range ba.ConfigurableValues {
		keys = append(keys, k)
	}

	sort.Slice(keys, func(i, j int) bool { return keys[i].less(keys[j]) })
	return keys
	return SortedConfigurationAxes(ba.ConfigurableValues)
}

// labelListSelectValues supports config-specific label_list typed Bazel attribute values.
@@ -761,13 +759,7 @@ func (lla *LabelListAttribute) SelectValue(axis ConfigurationAxis, config string

// SortedConfigurationAxes returns all the used ConfigurationAxis in sorted order.
func (lla *LabelListAttribute) SortedConfigurationAxes() []ConfigurationAxis {
	keys := make([]ConfigurationAxis, 0, len(lla.ConfigurableValues))
	for k := range lla.ConfigurableValues {
		keys = append(keys, k)
	}

	sort.Slice(keys, func(i, j int) bool { return keys[i].less(keys[j]) })
	return keys
	return SortedConfigurationAxes(lla.ConfigurableValues)
}

// Append all values, including os and arch specific ones, from another
@@ -1145,13 +1137,7 @@ func (sa *StringAttribute) SelectValue(axis ConfigurationAxis, config string) *s

// SortedConfigurationAxes returns all the used ConfigurationAxis in sorted order.
func (sa *StringAttribute) SortedConfigurationAxes() []ConfigurationAxis {
	keys := make([]ConfigurationAxis, 0, len(sa.ConfigurableValues))
	for k := range sa.ConfigurableValues {
		keys = append(keys, k)
	}

	sort.Slice(keys, func(i, j int) bool { return keys[i].less(keys[j]) })
	return keys
	return SortedConfigurationAxes(sa.ConfigurableValues)
}

// Collapse reduces the configurable axes of the string attribute to a single axis.
@@ -1353,13 +1339,7 @@ func (sla *StringListAttribute) SelectValue(axis ConfigurationAxis, config strin

// SortedConfigurationAxes returns all the used ConfigurationAxis in sorted order.
func (sla *StringListAttribute) SortedConfigurationAxes() []ConfigurationAxis {
	keys := make([]ConfigurationAxis, 0, len(sla.ConfigurableValues))
	for k := range sla.ConfigurableValues {
		keys = append(keys, k)
	}

	sort.Slice(keys, func(i, j int) bool { return keys[i].less(keys[j]) })
	return keys
	return SortedConfigurationAxes(sla.ConfigurableValues)
}

// DeduplicateAxesFromBase ensures no duplication of items between the no-configuration value and
+6 −0
Original line number Diff line number Diff line
@@ -160,6 +160,12 @@ var (
// select statements.
func prettyPrintAttribute(v bazel.Attribute, indent int) (string, error) {
	var value reflect.Value
	// configurableAttrs is the list of individual select statements to be
	// concatenated together. These select statements should be along different
	// axes. For example, one element may be
	// `select({"//color:red": "one", "//color:green": "two"})`, and the second
	// element may be `select({"//animal:cat": "three", "//animal:dog": "four"}).
	// These selects should be sorted by axis identifier.
	var configurableAttrs []selects
	var prepend bool
	var defaultSelectValue *string
+7 −1
Original line number Diff line number Diff line
@@ -702,7 +702,13 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
	compilerAttrs := compilerAttributes{}
	linkerAttrs := linkerAttributes{}

	for axis, configs := range axisToConfigs {
	// Iterate through these axes in a deterministic order. This is required
	// because processing certain dependencies may result in concatenating
	// elements along other axes. (For example, processing NoConfig may result
	// in elements being added to InApex). This is thus the only way to ensure
	// that the order of entries in each list is in a predictable order.
	for _, axis := range bazel.SortedConfigurationAxes(axisToConfigs) {
		configs := axisToConfigs[axis]
		for cfg := range configs {
			var allHdrs []string
			if baseCompilerProps, ok := archVariantCompilerProps[axis][cfg].(*BaseCompilerProperties); ok {