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

Commit 2f265950 authored by Liz Kammer's avatar Liz Kammer Committed by Gerrit Code Review
Browse files

Merge changes I4a5ea40c,I40ab16e3

* changes:
  Handle excludes_{shared,static}_libs
  Extract function to handle configurable excludes
parents d5c00287 47535c51
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -100,6 +100,22 @@ func BazelLabelForModuleDeps(ctx BazelConversionPathContext, modules []string) b
	return labels
}

// BazelLabelForModuleDeps expects two lists: modules (containing modules to include in the list),
// and excludes (modules to exclude from the list). Both of these should contain references to other
// modules, ("<module>" or ":<module>"). It returns a Bazel-compatible label list which corresponds
// to dependencies on the module within the given ctx, and the excluded dependencies.
func BazelLabelForModuleDepsExcludes(ctx BazelConversionPathContext, modules, excludes []string) bazel.LabelList {
	moduleLabels := BazelLabelForModuleDeps(ctx, RemoveListFromList(modules, excludes))
	if len(excludes) == 0 {
		return moduleLabels
	}
	excludeLabels := BazelLabelForModuleDeps(ctx, excludes)
	return bazel.LabelList{
		Includes: moduleLabels.Includes,
		Excludes: excludeLabels.Includes,
	}
}

func BazelLabelForModuleSrcSingle(ctx BazelConversionPathContext, path string) bazel.Label {
	return BazelLabelForModuleSrcExcludes(ctx, []string{path}, []string(nil)).Includes[0]
}
+11 −6
Original line number Diff line number Diff line
@@ -458,12 +458,13 @@ type ProductConfigContext interface {
// with the appropriate ProductConfigVariable.
type ProductConfigProperty struct {
	ProductConfigVariable string
	FullConfig            string
	Property              interface{}
}

// ProductConfigProperties is a map of property name to a slice of ProductConfigProperty such that
// all it all product variable-specific versions of a property are easily accessed together
type ProductConfigProperties map[string][]ProductConfigProperty
type ProductConfigProperties map[string]map[string]ProductConfigProperty

// ProductVariableProperties returns a ProductConfigProperties containing only the properties which
// have been set for the module in the given context.
@@ -512,11 +513,15 @@ func productVariableValues(variableProps interface{}, suffix string, productConf

			// e.g. Asflags, Cflags, Enabled, etc.
			propertyName := variableValue.Type().Field(j).Name
			(*productConfigProperties)[propertyName] = append((*productConfigProperties)[propertyName],
				ProductConfigProperty{
					ProductConfigVariable: productVariableName + suffix,
			if (*productConfigProperties)[propertyName] == nil {
				(*productConfigProperties)[propertyName] = make(map[string]ProductConfigProperty)
			}
			config := productVariableName + suffix
			(*productConfigProperties)[propertyName][config] = ProductConfigProperty{
				ProductConfigVariable: productVariableName,
				FullConfig:            config,
				Property:              property.Interface(),
				})
			}
		}
	}
}
+5 −5
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ const (
	// This is consistently named "conditions_default" to mirror the Soong
	// config variable default key in an Android.bp file, although there's no
	// integration with Soong config variables (yet).
	ConditionsDefault = "conditions_default"
	conditionsDefault = "conditions_default"

	ConditionsDefaultSelectKey = "//conditions:default"

@@ -76,7 +76,7 @@ var (
		archArm64:         "//build/bazel/platforms/arch:arm64",
		archX86:           "//build/bazel/platforms/arch:x86",
		archX86_64:        "//build/bazel/platforms/arch:x86_64",
		ConditionsDefault: ConditionsDefaultSelectKey, // The default condition of as arch select map.
		conditionsDefault: ConditionsDefaultSelectKey, // The default condition of as arch select map.
	}

	// A map of target operating systems to the Bazel label of the
@@ -88,7 +88,7 @@ var (
		osLinux:           "//build/bazel/platforms/os:linux",
		osLinuxBionic:     "//build/bazel/platforms/os:linux_bionic",
		osWindows:         "//build/bazel/platforms/os:windows",
		ConditionsDefault: ConditionsDefaultSelectKey, // The default condition of an os select map.
		conditionsDefault: ConditionsDefaultSelectKey, // The default condition of an os select map.
	}

	platformOsArchMap = map[string]string{
@@ -105,7 +105,7 @@ var (
		osArchLinuxBionicX86_64: "//build/bazel/platforms/os_arch:linux_bionic_x86_64",
		osArchWindowsX86:        "//build/bazel/platforms/os_arch:windows_x86",
		osArchWindowsX86_64:     "//build/bazel/platforms/os_arch:windows_x86_64",
		ConditionsDefault:       ConditionsDefaultSelectKey, // The default condition of an os select map.
		conditionsDefault:       ConditionsDefaultSelectKey, // The default condition of an os select map.
	}
)

@@ -168,7 +168,7 @@ func (ct configurationType) SelectKey(config string) string {
	case osArch:
		return platformOsArchMap[config]
	case productVariables:
		if config == ConditionsDefault {
		if config == conditionsDefault {
			return ConditionsDefaultSelectKey
		}
		return fmt.Sprintf("%s:%s", productVariableBazelPackage, strings.ToLower(config))
+40 −0
Original line number Diff line number Diff line
@@ -68,6 +68,13 @@ func (ll *LabelList) IsNil() bool {
	return ll.Includes == nil && ll.Excludes == nil
}

func (ll *LabelList) deepCopy() LabelList {
	return LabelList{
		Includes: ll.Includes[:],
		Excludes: ll.Excludes[:],
	}
}

// uniqueParentDirectories returns a list of the unique parent directories for
// all files in ll.Includes.
func (ll *LabelList) uniqueParentDirectories() []string {
@@ -469,6 +476,39 @@ func (lla LabelListAttribute) HasConfigurableValues() bool {
	return len(lla.ConfigurableValues) > 0
}

// ResolveExcludes handles excludes across the various axes, ensuring that items are removed from
// the base value and included in default values as appropriate.
func (lla *LabelListAttribute) ResolveExcludes() {
	for axis, configToLabels := range lla.ConfigurableValues {
		baseLabels := lla.Value.deepCopy()
		for config, val := range configToLabels {
			// Exclude config-specific excludes from base value
			lla.Value = SubtractBazelLabelList(lla.Value, LabelList{Includes: val.Excludes})

			// add base values to config specific to add labels excluded by others in this axis
			// then remove all config-specific excludes
			allLabels := baseLabels.deepCopy()
			allLabels.Append(val)
			lla.ConfigurableValues[axis][config] = SubtractBazelLabelList(allLabels, LabelList{Includes: val.Excludes})
		}

		// After going through all configs, delete the duplicates in the config
		// values that are already in the base Value.
		for config, val := range configToLabels {
			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][conditionsDefault] = SubtractBazelLabelList(baseLabels, lla.Value)

		// if everything ends up without includes, just delete the axis
		if !lla.ConfigurableValues[axis].HasConfigurableValues() {
			delete(lla.ConfigurableValues, axis)
		}
	}
}

// StringListAttribute corresponds to the string_list Bazel attribute type with
// support for additional metadata, like configurations.
type StringListAttribute struct {
+88 −0
Original line number Diff line number Diff line
@@ -205,3 +205,91 @@ func TestUniqueSortedBazelLabelList(t *testing.T) {
		}
	}
}

func makeLabels(labels ...string) []Label {
	var ret []Label
	for _, l := range labels {
		ret = append(ret, Label{Label: l})
	}
	return ret
}

func makeLabelList(includes, excludes []string) LabelList {
	return LabelList{
		Includes: makeLabels(includes...),
		Excludes: makeLabels(excludes...),
	}
}

func TestResolveExcludes(t *testing.T) {
	attr := LabelListAttribute{
		Value: makeLabelList(
			[]string{
				"all_include",
				"arm_exclude",
				"android_exclude",
			},
			[]string{"all_exclude"},
		),
		ConfigurableValues: configurableLabelLists{
			ArchConfigurationAxis: labelListSelectValues{
				"arm": makeLabelList([]string{}, []string{"arm_exclude"}),
				"x86": makeLabelList([]string{"x86_include"}, []string{}),
			},
			OsConfigurationAxis: labelListSelectValues{
				"android": makeLabelList([]string{}, []string{"android_exclude"}),
				"linux":   makeLabelList([]string{"linux_include"}, []string{}),
			},
			OsArchConfigurationAxis: labelListSelectValues{
				"linux_x86": makeLabelList([]string{"linux_x86_include"}, []string{}),
			},
			ProductVariableConfigurationAxis("a"): labelListSelectValues{
				"a": makeLabelList([]string{}, []string{"not_in_value"}),
			},
		},
	}

	attr.ResolveExcludes()

	expectedBaseIncludes := []Label{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{
			"arm":                nilLabels,
			"x86":                makeLabels("arm_exclude", "x86_include"),
			"conditions_default": makeLabels("arm_exclude"),
		},
		OsConfigurationAxis: map[string][]Label{
			"android":            nilLabels,
			"linux":              makeLabels("android_exclude", "linux_include"),
			"conditions_default": makeLabels("android_exclude"),
		},
		OsArchConfigurationAxis: map[string][]Label{
			"linux_x86":          makeLabels("linux_x86_include"),
			"conditions_default": nilLabels,
		},
	}
	for _, axis := range attr.SortedConfigurationAxes() {
		if _, ok := expectedConfiguredIncludes[axis]; !ok {
			t.Errorf("Found unexpected axis %s", axis)
			continue
		}
		expectedForAxis := expectedConfiguredIncludes[axis]
		gotForAxis := attr.ConfigurableValues[axis]
		if len(expectedForAxis) != len(gotForAxis) {
			t.Errorf("Expected %d configs for %s, got %d: %s", len(expectedForAxis), axis, len(gotForAxis), gotForAxis)
		}
		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)
				}
			} else {
				t.Errorf("Got unexpected config %q for %s", config, axis)
			}
		}
	}
}
Loading