Merge "Add AppendSimpleValue" into main am: 28c638257d
am: ece5b2fba8
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/3132817 Change-Id: Ib0a0bcd927fa8966d568a768494a7b5f2340c75f Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
6d13ab0b7f
1 changed files with 37 additions and 6 deletions
|
@ -296,7 +296,7 @@ func NewConfigurableCase[T ConfigurableElements](patterns []ConfigurablePattern,
|
||||||
patterns = slices.Clone(patterns)
|
patterns = slices.Clone(patterns)
|
||||||
return ConfigurableCase[T]{
|
return ConfigurableCase[T]{
|
||||||
patterns: patterns,
|
patterns: patterns,
|
||||||
value: copyConfiguredValue(value),
|
value: copyConfiguredValuePtr(value),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,6 +408,22 @@ func NewConfigurable[T ConfigurableElements](conditions []ConfigurableCondition,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Configurable[T]) AppendSimpleValue(value T) {
|
||||||
|
value = copyConfiguredValue(value)
|
||||||
|
// This may be a property that was never initialized from a bp file
|
||||||
|
if c.inner == nil {
|
||||||
|
c.inner = &configurableInner[T]{
|
||||||
|
single: singleConfigurable[T]{
|
||||||
|
cases: []ConfigurableCase[T]{{
|
||||||
|
value: &value,
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.inner.appendSimpleValue(value)
|
||||||
|
}
|
||||||
|
|
||||||
// Get returns the final value for the configurable property.
|
// Get returns the final value for the configurable property.
|
||||||
// A configurable property may be unset, in which case Get will return nil.
|
// A configurable property may be unset, in which case Get will return nil.
|
||||||
func (c *Configurable[T]) Get(evaluator ConfigurableEvaluator) ConfigurableOptional[T] {
|
func (c *Configurable[T]) Get(evaluator ConfigurableEvaluator) ConfigurableOptional[T] {
|
||||||
|
@ -420,7 +436,7 @@ func (c *Configurable[T]) GetOrDefault(evaluator ConfigurableEvaluator, defaultV
|
||||||
result := c.inner.evaluate(c.propertyName, evaluator)
|
result := c.inner.evaluate(c.propertyName, evaluator)
|
||||||
if result != nil {
|
if result != nil {
|
||||||
// Copy the result so that it can't be changed from soong
|
// Copy the result so that it can't be changed from soong
|
||||||
return copyAndDereferenceConfiguredValue(result)
|
return copyConfiguredValue(*result)
|
||||||
}
|
}
|
||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
|
@ -628,6 +644,21 @@ func (c *configurableInner[T]) setAppend(append *configurableInner[T], replace b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *configurableInner[T]) appendSimpleValue(value T) {
|
||||||
|
if c.next == nil {
|
||||||
|
c.replace = false
|
||||||
|
c.next = &configurableInner[T]{
|
||||||
|
single: singleConfigurable[T]{
|
||||||
|
cases: []ConfigurableCase[T]{{
|
||||||
|
value: &value,
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c.next.appendSimpleValue(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c Configurable[T]) printfInto(value string) error {
|
func (c Configurable[T]) printfInto(value string) error {
|
||||||
return c.inner.printfInto(value)
|
return c.inner.printfInto(value)
|
||||||
}
|
}
|
||||||
|
@ -754,7 +785,7 @@ func (c Configurable[T]) configuredType() reflect.Type {
|
||||||
return reflect.TypeOf((*T)(nil)).Elem()
|
return reflect.TypeOf((*T)(nil)).Elem()
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyConfiguredValue[T ConfigurableElements](t *T) *T {
|
func copyConfiguredValuePtr[T ConfigurableElements](t *T) *T {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -781,12 +812,12 @@ func configuredValuePtrToOptional[T ConfigurableElements](t *T) ConfigurableOpti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyAndDereferenceConfiguredValue[T ConfigurableElements](t *T) T {
|
func copyConfiguredValue[T ConfigurableElements](t T) T {
|
||||||
switch t2 := any(*t).(type) {
|
switch t2 := any(t).(type) {
|
||||||
case []string:
|
case []string:
|
||||||
return any(slices.Clone(t2)).(T)
|
return any(slices.Clone(t2)).(T)
|
||||||
default:
|
default:
|
||||||
return *t
|
return t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue