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

Commit 9af49a49 authored by Jingwen Chen's avatar Jingwen Chen
Browse files

Fix //conditions:default excludes computation for LabelListAttribute.

Previously, excludes computation for the default condition in label list
selects was clobbering pre-existing values. This CL fixes it by
performing a union of the new values with existing ones instead.

Test: properties_test.go
Bug: 198556411
Change-Id: Id11f4fb14e359201304afde0d8ba856851d41395
parent 55bc820d
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -534,9 +534,13 @@ func (lla *LabelListAttribute) ResolveExcludes() {
			lla.ConfigurableValues[axis][config] = SubtractBazelLabelList(val, lla.Value)
		}

		// Now that the Value list is finalized for this axis, compare it with the original
		// list, and put the difference into the default condition for the axis.
		lla.ConfigurableValues[axis][ConditionsDefaultConfigKey] = SubtractBazelLabelList(baseLabels, lla.Value)
		// Now that the Value list is finalized for this axis, compare it with
		// the original list, and union the difference with the default
		// condition for the axis.
		difference := SubtractBazelLabelList(baseLabels, lla.Value)
		existingDefaults := lla.ConfigurableValues[axis][ConditionsDefaultConfigKey]
		existingDefaults.Append(difference)
		lla.ConfigurableValues[axis][ConditionsDefaultConfigKey] = FirstUniqueBazelLabelList(existingDefaults)

		// if everything ends up without includes, just delete the axis
		if !lla.ConfigurableValues[axis].HasConfigurableValues() {
+29 −16
Original line number Diff line number Diff line
@@ -238,6 +238,7 @@ func TestResolveExcludes(t *testing.T) {
			ArchConfigurationAxis: labelListSelectValues{
				"arm":                      makeLabelList([]string{}, []string{"arm_exclude"}),
				"x86":                      makeLabelList([]string{"x86_include"}, []string{}),
				ConditionsDefaultConfigKey: makeLabelList([]string{"default_include"}, []string{}),
			},
			OsConfigurationAxis: labelListSelectValues{
				"android": makeLabelList([]string{}, []string{"android_exclude"}),
@@ -246,7 +247,13 @@ func TestResolveExcludes(t *testing.T) {
			OsArchConfigurationAxis: labelListSelectValues{
				"linux_x86": makeLabelList([]string{"linux_x86_include"}, []string{}),
			},
			ProductVariableConfigurationAxis("a"): labelListSelectValues{
			ProductVariableConfigurationAxis("product_with_defaults"): labelListSelectValues{
				"a":                        makeLabelList([]string{}, []string{"not_in_value"}),
				"b":                        makeLabelList([]string{"b_val"}, []string{}),
				"c":                        makeLabelList([]string{"c_val"}, []string{}),
				ConditionsDefaultConfigKey: makeLabelList([]string{"c_val", "default", "default2"}, []string{}),
			},
			ProductVariableConfigurationAxis("product_only_with_excludes"): labelListSelectValues{
				"a": makeLabelList([]string{}, []string{"not_in_value"}),
			},
		},
@@ -254,25 +261,31 @@ func TestResolveExcludes(t *testing.T) {

	attr.ResolveExcludes()

	expectedBaseIncludes := []Label{Label{Label: "all_include"}}
	expectedBaseIncludes := []Label{{Label: "all_include"}}
	if !reflect.DeepEqual(expectedBaseIncludes, attr.Value.Includes) {
		t.Errorf("Expected Value includes %q, got %q", attr.Value.Includes, expectedBaseIncludes)
	}
	var nilLabels []Label
	expectedConfiguredIncludes := map[ConfigurationAxis]map[string][]Label{
		ArchConfigurationAxis: map[string][]Label{
		ArchConfigurationAxis: {
			"arm":                      nilLabels,
			"x86":                      makeLabels("arm_exclude", "x86_include"),
			"conditions_default": makeLabels("arm_exclude"),
			ConditionsDefaultConfigKey: makeLabels("arm_exclude", "default_include"),
		},
		OsConfigurationAxis: map[string][]Label{
		OsConfigurationAxis: {
			"android":                  nilLabels,
			"linux":                    makeLabels("android_exclude", "linux_include"),
			"conditions_default": makeLabels("android_exclude"),
			ConditionsDefaultConfigKey: makeLabels("android_exclude"),
		},
		OsArchConfigurationAxis: map[string][]Label{
		OsArchConfigurationAxis: {
			"linux_x86":                makeLabels("linux_x86_include"),
			"conditions_default": nilLabels,
			ConditionsDefaultConfigKey: nilLabels,
		},
		ProductVariableConfigurationAxis("product_with_defaults"): {
			"a":                        nilLabels,
			"b":                        makeLabels("b_val"),
			"c":                        makeLabels("c_val"),
			ConditionsDefaultConfigKey: makeLabels("c_val", "default", "default2"),
		},
	}
	for _, axis := range attr.SortedConfigurationAxes() {
@@ -288,7 +301,7 @@ func TestResolveExcludes(t *testing.T) {
		for config, value := range gotForAxis {
			if expected, ok := expectedForAxis[config]; ok {
				if !reflect.DeepEqual(expected, value.Includes) {
					t.Errorf("For %s, expected: %#v, got %#v", axis, expected, value.Includes)
					t.Errorf("For %s,\nexpected: %#v\ngot %#v", axis, expected, value.Includes)
				}
			} else {
				t.Errorf("Got unexpected config %q for %s", config, axis)