aboutsummaryrefslogtreecommitdiffstats
path: root/proptools/extend.go
Commit message (Collapse)AuthorAgeFilesLines
* Make off-the-shelf order funcs public.HEADstaging/lineage-17.0_merge-android-10.0.0_r9lineage-17.1Jaewoong Jung2019-12-111-6/+6
| | | | | | | These are useful outside the package too when calling proptools.ExtendMatchingProperties. Change-Id: I054eb105e0dd5287aff99b8be137a8b09d52492d
* Support parsing int64 in Blueprint file.Nan Zhang2017-11-021-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | Support int64 number instead of int to be more fixed to bit size so that the underlying arch won't affect overflow cases. Besides, refection: func (v Value) Int() int64 always cast to int64 no matter the input is int, int16, int32. Currently we always treat "-" as negative sign to bind to next value, and "+" as plus operator to add operands together. So we allow: a = 5 + -4 + 5 or a = -4 + 5 But we don't allow: a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise, a = 5 + +5 would exist which looks pretty weird. In the future, we may want fully support number calculator logic eg, "+"/"-" can be positive/negative sign or operator, and "(" and ")" will be considered to group expressions with a higher precedence. int & uint properties within struct keeps unchanged, which is only allowed when tagged with 'blueprint:mutated'. We only allow *int64 property instead of int64 property within struct since it does't make sense to do prepending or appending to int64. Change-Id: I565e046dbd268af3538aee148cd7300037e56523
* Replace unpack's replace semantics with appendColin Cross2017-08-011-62/+68
| | | | | | | | | | | | | | | | | Blueprint was using "replace" semantics when unpacking properties into property structs, meaning if a module factory pre-set property values they would be overwritten by whatever was in the Blueprint file. This is different than what would happen if the same property was updated using the Append*Properties functions in proptools, which would use "append" semantics, which append strings and lists, logically ORs booleans and replaces pointers to strings and booleans. Replace unpack's semantics with append semantics for consistency. Any previous users of pre-set properties can move to using a pointer to a string or boolean if they want the old behavior. Test: unpack_test.go Test: extend_test.go Change-Id: I02eebe80916e578938142f8e76889bd985223afc
* Relax type requirements when extending propertiesColin Cross2016-08-221-39/+52
| | | | | | | | | | | | Allow using ExtendMatchingProperties to extend pointer to a struct or an interface containing a pointer to a struct using a struct, and vice-versa. Also fixes a pre-existing bug where extending a nested structure could fail if there were multiple possible destnations and some of them did not have a matching nested property. Change-Id: I6e69d78eb6595ba7dd2603e3aa7dd8de3f292744
* Support nil pointers to structs in propertiesColin Cross2016-08-051-13/+40
| | | | | | | | | | | | Allow primary builders to reduce allocations of empty structures by allowing nil pointers to concrete struct types. Property readers will not recurse into nil pointers, property writers will replace the nil pointer with a pointer to the zero value of the pointer element type. Allows a >50% primary builder time improvement with a trivial change in Soong. Change-Id: If6ad674bf7bf2a694c335378a074643a97d3c50b
* Optimize proptoolsColin Cross2016-08-051-6/+14
| | | | | | | | | | | proptools cloning and extending are a significant portion of the run time for Soong. Optimize out calls to reflect.Type.Field(), which must allocate a []int to store the index, by caching all the fields of each type as it is seen, and by iterating over a slice of cached fields instead of calling Field(i) for each one. Also avoid calling reflect.Value.Interface() twice on the same Value. Change-Id: I4e13fc85f30d8614a5586283e928c0a6d7f24809
* Support ExtendProperties that can append or prependColin Cross2016-05-051-10/+95
| | | | | | | | ExtendProperties is the same as AppendProperties or PrependProperties, but takes a function that determines whether each property should be appended or prepended. Change-Id: I26e400d56d75a88bab9c27c382ee5321bc623ee5
* AppendProperties: Replace *strings instead of appendingDan Willemsen2016-01-051-14/+13
| | | | | | | This makes *string values act like *bool values -- instead of appending or prepending the contents of the string, the entire string is replaced. The use case here is for overriding filenames, where appending doesn't work.
* Add property support for pointers to bools and stringsColin Cross2015-11-021-12/+52
| | | | | | | | | | | | | | | | | | | The only append semantics for bool that result in a no-op when the zero value is appended is to OR the two values together, but that is rarely the desired semantics. Add support for *bool and *string as property types, where appending a nil pointer is a no-op. For *bool, appending a non-nil pointer replaces the destination with the value. For *string, appending a non-nil pointer appends the value. This also provides a more reliable replacement for ModuleContext.ContainsProperty, as the build logic can tell that the property was set, even if it was set by a mutator and not by the blueprints file, by testing against nil. []string already provides these semantics for lists. Setting a *bool or *string property from a blueprints file is the same syntax as setting a bool or a string property.
* Add helpers for extending properties to proptoolsColin Cross2015-10-311-0/+316
It is common for a mutator to append or prepend property structs together. Add helper functions to append or prepend properties in property structs. The append operation is defined as appending string and slices of strings normally, OR-ing bool values, and recursing into embedded structs, pointers to structs, and interfaces containing pointers to structs. Appending or prepending the zero value of a property will always be a no-op.