Commit graph

19 commits

Author SHA1 Message Date
Cole Faust
a52b058ccc Refactor selects
In order to do less cloning, refactor selects so that all the
soong-visibile structs are immutable to soong and can be reused.

Additionally, refactor how the inner linked list of selects is managed,
so that the append/prepend/replace logic is simpler.

Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Iba5d27405decc1b0596590c3e0555daeb044bf9e
2024-04-29 13:23:30 -07:00
Cole Faust
4560bb086e Allow extending configurable propeties with non-configurable properties
Sometimes modules add arch-variant properties in load hooks, to disable
modules by default on certain platforms for example. When changing the
property to a Configurable property, these load hooks would also need
to be changed in order to have a matching type for
ExtendMatchingProperties.

Since this can be kindof a pain to address everywhere, for now,
special case the extension functions to promote non-configurable
properties to configurable ones. We can remove this later when
everything switches to configurable properties.

Bug: 323382414
Test: go tests
Change-Id: Iac96587dbd60ccdd6aa667dd69a71ad252abe589
2024-04-25 15:31:00 -07:00
Cole Faust
185cb44bef Export ConfigurableCase and add constructors
Some soong code sets arch-variant properties in order to control a
module's default behavior. I'll make this continue to work, but long
term the arch-variant properties should be replaced with selects,
so expose an API for creating select statements in soong code.

Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: I6c65d6e112b6f826f1027777b6fdf36915d34b1d
2024-04-23 13:55:59 -07:00
Cole Faust
3311debbb3 Support multi-variable selects and typed selects
This adds support for selecting on multiple variables at once, so that
you can do AND/OR combindations of them. For example:

select((
    arch(),
    os(),
), {
    ("arm64", "linux"): ["libfoo64"],
    (default, "linux"): ["libfoo"],
    (default, "windows"): ["libfoowindows"],
    (default, default): ["libbar"],
})

It also allows for select conditions to be boolean-typed. You can
write literal true and false without quotes to select on them. Currently
we don't have any boolean-typed variables though, so a fake one was
added for testing.

Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ibe586e7b21865b8734027848cc421594cbd1d8cc
2024-04-12 16:33:01 -07:00
Cole Faust
021cc8f5b8 Add support for unset select branches
Currently, with the arch/os mutator, you can override a property
using the default value for just a few arch types, for example:

cc_defaults {
    name: "my_defaults",
    target: {
        windows: {
            enabled: true,
        }
    }
}

cc_binary {
    name: "foo",
    enabled: false,
    defaults: ["my_defaults"],
}

You could make a select statment that acts like the above if it were
all in one module, but currently with select statements you can't make
a defaults module that can be generically applied to any other module
and have the same behavior as the above.

After this cl, the defaults module could look like:

cc_defaults {
    name: "my_defaults",
    enabled: select(variant("arch"), {
        "windows": true,
        _: unset,
    }),
}

Which would have the same behavior. Unset may also be useful for
setting the property under some configurations, but wanting to leave
the implementation-specific default value in others.

Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: I3ea3277ea8b9a0ac5e613b4378945388b9df036a
2024-04-02 16:35:33 -07:00
Cole Faust
6437d4e737 Select statements
Select statements are a new blueprint feature inspired by bazel's select
statements. They are essentially alternative syntax for soong config
variables that require less boilerplate. In addition, they support
making decisions based on a module's variant, which will eliminate
the need for manual property struct manipulation, such as the arch
mutator's arch: and target: properties.

In order to support decisions based on the variant, select statements
cannot be evaluated as soon as they're parsed. Instead, they must be
stored in the property struct unevaluated. This means that individual
properties need to change their type from say, string, to
Configurable[string]. Currently, only configurable strings, bools, and
string slices are supported, but more types can be added later.
The module implementation must call my_property.Evaluate(ctx) in order
to get the final, resolved value of the select statement.

Bug: 323382414
Test: go tests
Change-Id: I62f8721d7f0ac3d1df4a06d7eaa260a5aa7fcba3
2024-03-06 15:00:39 -08:00
Colin Cross
c4fc4b447f Optimize (Extend|Append|Prepend)[Matching]Properties
The property squashing functions were performing 19% of all allocations
and allocating 3.43 GB, most of which was used to track the name of the
property, but the name of the property is only used to print errors.
Keep the elements of the name in a preallocated slice instead, and only
compute the name when an error occurs.

Calling reflect.Value.Interface() was also expensive, and only passed
to filter and order functions, none of which use the values.  Modify
the signature of the filter and order functions to remove the interfaces
and the property name.

Test: extend_test.go
Change-Id: I517f89daf251bb43f7cfefa6f1e83951c0e271b7
2024-02-02 15:57:26 -08:00
Colin Cross
1c3530ab58 Support AppendMatchingProperties on an embedded anonymous struct
Recurse into embedded anonymous structs and the BlueprintEmbed
workaround structs when looking for properties in
extendPropertiesRecursive.

Test: proptools/extend_test.go
Change-Id: I975651a64e5173747403629a09263562761f1495
2021-06-28 17:08:52 -07:00
Liz Kammer
c1ccfee2bd Add support for maps as properties
This support enables specifying properties of the type "map" within a
Soong module, but explicitly does not allow them to be used within a bp
file.

This means that rather than specifying each arch/os/target within a
struct to support arch-variant properties/attributes, we can use a map.
This allows us to simplify the implementation of LabelAttribute,
StringListAttribute, and LabelListAttribute as the number of select
statements supported becoming large and hard results in a lot of
duplication.

Test: go test blueprint tests
Test: m nothing
Change-Id: I88cc5952a6bdb60a2344fa0737216f016086cea5
2021-05-26 09:54:22 -04:00
Sasha Smundak
29fdcad56c Implement list of maps
Allow property value to be a list of maps, e.g.
my_module {
  my_list: [
    { name: "foo", value: 42, something: true, },
    { name: "bar", value: 34, something: false, },
  ],
}

Test: internal
Change-Id: I2fc37d692aac39f23c9aa7bda2859ab49f3bc672
2020-03-02 17:26:20 -08:00
Jiyong Park
10f27f8139 Slice properties can be replaced
override_* in Soong requires a module to override certain properties of
other module. In that case, values of a slice property (e.g. []string)
should be replaced by the same property value in the overriding module.
However, since proptools only supports Append and Prepend orders where
the original values are kept for slice properties, the behavior
couldn't be implemented. To support the use case, Replace order is
introduced, in which case slice property values are completely replaced.
For other types of properties, the Replace order behaves exactly the
same as the Append order.

Bug: 144338929
Test: m

Change-Id: Iae9feda035177fe6a22e6e8319c0fdaa9e08e85e
2019-11-19 10:45:58 +09:00
Nan Zhang
f586544ab7 Support parsing int64 in Blueprint file.
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
2017-11-02 22:10:47 -07:00
Colin Cross
bf2adbfee2 Relax type requirements when extending properties
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
2016-08-22 15:35:17 -07:00
Colin Cross
c3d731258a Support nil pointers to structs in properties
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
2016-08-05 17:19:36 -07:00
Colin Cross
75c4701ed2 Support ExtendProperties that can append or prepend
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
2016-05-05 16:23:19 -07:00
Dan Willemsen
4c00085f2d AppendProperties: Replace *strings instead of appending
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.
2016-01-05 14:16:04 -08:00
Colin Cross
9d1469d559 Support embedded anonymous property structs
Allow property structs to contain anonymous embedded structs and
interfaces.  Properties in an anonymous embedded struct or interface are
treated as if they were properties in the embedding struct.
2015-11-20 17:26:52 -08:00
Colin Cross
8011768729 Add property support for pointers to bools and strings
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.
2015-11-02 13:59:12 -08:00
Colin Cross
0bc7e077eb Add helpers for extending properties to proptools
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.
2015-10-31 20:09:58 -07:00