xref: /aosp_15_r20/build/soong/android/configurable_properties.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1package android
2
3import "github.com/google/blueprint/proptools"
4
5// CreateSelectOsToBool is a utility function that makes it easy to create a
6// Configurable property value that maps from os to a bool. Use an empty string
7// to indicate a "default" case.
8func CreateSelectOsToBool(cases map[string]*bool) proptools.Configurable[bool] {
9	var resultCases []proptools.ConfigurableCase[bool]
10	for pattern, value := range cases {
11		if pattern == "" {
12			resultCases = append(resultCases, proptools.NewConfigurableCase(
13				[]proptools.ConfigurablePattern{proptools.NewDefaultConfigurablePattern()},
14				value,
15			))
16		} else {
17			resultCases = append(resultCases, proptools.NewConfigurableCase(
18				[]proptools.ConfigurablePattern{proptools.NewStringConfigurablePattern(pattern)},
19				value,
20			))
21		}
22	}
23
24	return proptools.NewConfigurable(
25		[]proptools.ConfigurableCondition{proptools.NewConfigurableCondition("os", nil)},
26		resultCases,
27	)
28}
29
30func NewSimpleConfigurable[T proptools.ConfigurableElements](value T) proptools.Configurable[T] {
31	return proptools.NewConfigurable(nil, []proptools.ConfigurableCase[T]{
32		proptools.NewConfigurableCase(nil, &value),
33	})
34}
35