diff options
Diffstat (limited to 'bazel/properties.go')
| -rw-r--r-- | bazel/properties.go | 74 |
1 files changed, 64 insertions, 10 deletions
diff --git a/bazel/properties.go b/bazel/properties.go index b370bbfb2..76be0581b 100644 --- a/bazel/properties.go +++ b/bazel/properties.go @@ -107,6 +107,14 @@ func (ll *LabelList) uniqueParentDirectories() []string { return dirs } +// Add inserts the label Label at the end of the LabelList. +func (ll *LabelList) Add(label *Label) { + if label == nil { + return + } + ll.Includes = append(ll.Includes, *label) +} + // Append appends the fields of other labelList to the corresponding fields of ll. func (ll *LabelList) Append(other LabelList) { if len(ll.Includes) > 0 || len(other.Includes) > 0 { @@ -366,9 +374,23 @@ func (ba *BoolAttribute) SortedConfigurationAxes() []ConfigurationAxis { // labelListSelectValues supports config-specific label_list typed Bazel attribute values. type labelListSelectValues map[string]LabelList -func (ll labelListSelectValues) appendSelects(other labelListSelectValues) { +func (ll labelListSelectValues) addSelects(label labelSelectValues) { + for k, v := range label { + if label == nil { + continue + } + l := ll[k] + (&l).Add(v) + ll[k] = l + } +} + +func (ll labelListSelectValues) appendSelects(other labelListSelectValues, forceSpecifyEmptyList bool) { for k, v := range other { l := ll[k] + if forceSpecifyEmptyList && l.IsNil() && !v.IsNil() { + l.Includes = []Label{} + } (&l).Append(v) ll[k] = l } @@ -424,17 +446,22 @@ func (cll configurableLabelLists) setValueForAxis(axis ConfigurationAxis, config cll[axis][config] = list } -func (cll configurableLabelLists) Append(other configurableLabelLists) { +func (cll configurableLabelLists) Append(other configurableLabelLists, forceSpecifyEmptyList bool) { for axis, otherSelects := range other { selects := cll[axis] if selects == nil { selects = make(labelListSelectValues, len(otherSelects)) } - selects.appendSelects(otherSelects) + selects.appendSelects(otherSelects, forceSpecifyEmptyList) cll[axis] = selects } } +func (lla *LabelListAttribute) Clone() *LabelListAttribute { + result := &LabelListAttribute{ForceSpecifyEmptyList: lla.ForceSpecifyEmptyList} + return result.Append(*lla) +} + // MakeLabelListAttribute initializes a LabelListAttribute with the non-arch specific value. func MakeLabelListAttribute(value LabelList) LabelListAttribute { return LabelListAttribute{ @@ -488,16 +515,37 @@ func (lla *LabelListAttribute) SortedConfigurationAxes() []ConfigurationAxis { } // Append all values, including os and arch specific ones, from another -// LabelListAttribute to this LabelListAttribute. -func (lla *LabelListAttribute) Append(other LabelListAttribute) { - if lla.ForceSpecifyEmptyList && !other.Value.IsNil() { +// LabelListAttribute to this LabelListAttribute. Returns this LabelListAttribute. +func (lla *LabelListAttribute) Append(other LabelListAttribute) *LabelListAttribute { + forceSpecifyEmptyList := lla.ForceSpecifyEmptyList || other.ForceSpecifyEmptyList + if forceSpecifyEmptyList && lla.Value.IsNil() && !other.Value.IsNil() { lla.Value.Includes = []Label{} } lla.Value.Append(other.Value) if lla.ConfigurableValues == nil { lla.ConfigurableValues = make(configurableLabelLists) } - lla.ConfigurableValues.Append(other.ConfigurableValues) + lla.ConfigurableValues.Append(other.ConfigurableValues, forceSpecifyEmptyList) + return lla +} + +// Add inserts the labels for each axis of LabelAttribute at the end of corresponding axis's +// LabelList within the LabelListAttribute +func (lla *LabelListAttribute) Add(label *LabelAttribute) { + if label == nil { + return + } + + lla.Value.Add(label.Value) + if lla.ConfigurableValues == nil && label.ConfigurableValues != nil { + lla.ConfigurableValues = make(configurableLabelLists) + } + for axis, _ := range label.ConfigurableValues { + if _, exists := lla.ConfigurableValues[axis]; !exists { + lla.ConfigurableValues[axis] = make(labelListSelectValues) + } + lla.ConfigurableValues[axis].addSelects(label.ConfigurableValues[axis]) + } } // HasConfigurableValues returns true if the attribute contains axis-specific label list values. @@ -566,7 +614,7 @@ type OtherModuleContext interface { // LabelMapper is a function that takes a OtherModuleContext and returns a (potentially changed) // label and whether it was changed. -type LabelMapper func(OtherModuleContext, string) (string, bool) +type LabelMapper func(OtherModuleContext, Label) (string, bool) // LabelPartition contains descriptions of a partition for labels type LabelPartition struct { @@ -588,7 +636,7 @@ type LabelPartitions map[string]LabelPartition // not. func (lf LabelPartition) filter(ctx OtherModuleContext, label Label) *Label { if lf.LabelMapper != nil { - if newLabel, changed := lf.LabelMapper(ctx, label.Label); changed { + if newLabel, changed := lf.LabelMapper(ctx, label); changed { return &Label{newLabel, label.OriginalModuleName} } } @@ -757,12 +805,18 @@ func (sla StringListAttribute) HasConfigurableValues() bool { // Append appends all values, including os and arch specific ones, from another // StringListAttribute to this StringListAttribute -func (sla *StringListAttribute) Append(other StringListAttribute) { +func (sla *StringListAttribute) Append(other StringListAttribute) *StringListAttribute { sla.Value = append(sla.Value, other.Value...) if sla.ConfigurableValues == nil { sla.ConfigurableValues = make(configurableStringLists) } sla.ConfigurableValues.Append(other.ConfigurableValues) + return sla +} + +func (sla *StringListAttribute) Clone() *StringListAttribute { + result := &StringListAttribute{} + return result.Append(*sla) } // SetSelectValue set a value for a bazel select for the given axis, config and value. |