Add new properties to aid in removing the 1-variant fallback
These new properties are essentially methods to specify "outgoing
transitions" in blueprint files. There are lots of host tests
that want to include apps built for device in their data, so they
need a property that adds dependencies based on the device variants
instead of copying the same host variants.
After this cl is submitted, I'll do an LSC to update all the usages
that are relying on the 1-variant fallback to use these properties
instead.
Bug: 372091092
Test: m nothing --no-skip-soong-tests
Change-Id: I45b8fb024da120ad61606e3a21de86e4392be2a4
diff --git a/android/path_properties.go b/android/path_properties.go
index d80a8ed..8ada133 100644
--- a/android/path_properties.go
+++ b/android/path_properties.go
@@ -18,6 +18,7 @@
"fmt"
"reflect"
+ "github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
@@ -38,20 +39,32 @@
// squashed into the real modules.
return
}
+ if !ctx.Module().Enabled(ctx) {
+ return
+ }
props := ctx.Module().base().GetProperties()
addPathDepsForProps(ctx, props)
}
func addPathDepsForProps(ctx BottomUpMutatorContext, props []interface{}) {
// Iterate through each property struct of the module extracting the contents of all properties
- // tagged with `android:"path"`.
+ // tagged with `android:"path"` or one of the variant-specifying tags.
var pathProperties []string
+ var pathDeviceFirstProperties []string
+ var pathDeviceCommonProperties []string
+ var pathCommonOsProperties []string
for _, ps := range props {
- pathProperties = append(pathProperties, pathPropertiesForPropertyStruct(ctx, ps)...)
+ pathProperties = append(pathProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path")...)
+ pathDeviceFirstProperties = append(pathDeviceFirstProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path_device_first")...)
+ pathDeviceCommonProperties = append(pathDeviceCommonProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path_device_common")...)
+ pathCommonOsProperties = append(pathCommonOsProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path_common_os")...)
}
// Remove duplicates to avoid multiple dependencies.
pathProperties = FirstUniqueStrings(pathProperties)
+ pathDeviceFirstProperties = FirstUniqueStrings(pathDeviceFirstProperties)
+ pathDeviceCommonProperties = FirstUniqueStrings(pathDeviceCommonProperties)
+ pathCommonOsProperties = FirstUniqueStrings(pathCommonOsProperties)
// Add dependencies to anything that is a module reference.
for _, s := range pathProperties {
@@ -59,12 +72,35 @@
ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(m, t), m)
}
}
+ // For properties tagged "path_device_first", use the first arch device variant when adding
+ // dependencies. This allows host modules to have some properties that add dependencies on
+ // device modules.
+ for _, s := range pathDeviceFirstProperties {
+ if m, t := SrcIsModuleWithTag(s); m != "" {
+ ctx.AddVariationDependencies(ctx.Config().AndroidFirstDeviceTarget.Variations(), sourceOrOutputDepTag(m, t), m)
+ }
+ }
+ // properties tagged "path_device_common" get the device common variant
+ for _, s := range pathDeviceCommonProperties {
+ if m, t := SrcIsModuleWithTag(s); m != "" {
+ ctx.AddVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), sourceOrOutputDepTag(m, t), m)
+ }
+ }
+ // properties tagged "path_device_common" get the device common variant
+ for _, s := range pathCommonOsProperties {
+ if m, t := SrcIsModuleWithTag(s); m != "" {
+ ctx.AddVariationDependencies([]blueprint.Variation{
+ {Mutator: "os", Variation: "common_os"},
+ {Mutator: "arch", Variation: ""},
+ }, sourceOrOutputDepTag(m, t), m)
+ }
+ }
}
-// pathPropertiesForPropertyStruct uses the indexes of properties that are tagged with
-// android:"path" to extract all their values from a property struct, returning them as a single
+// taggedPropertiesForPropertyStruct uses the indexes of properties that are tagged with
+// android:"tagValue" to extract all their values from a property struct, returning them as a single
// slice of strings.
-func pathPropertiesForPropertyStruct(ctx BottomUpMutatorContext, ps interface{}) []string {
+func taggedPropertiesForPropertyStruct(ctx BottomUpMutatorContext, ps interface{}, tagValue string) []string {
v := reflect.ValueOf(ps)
if v.Kind() != reflect.Ptr || v.Elem().Kind() != reflect.Struct {
panic(fmt.Errorf("type %s is not a pointer to a struct", v.Type()))
@@ -79,7 +115,7 @@
v = v.Elem()
// Get or create the list of indexes of properties that are tagged with `android:"path"`.
- pathPropertyIndexes := pathPropertyIndexesForPropertyStruct(ps)
+ pathPropertyIndexes := taggedPropertyIndexesForPropertyStruct(ps, tagValue)
var ret []string
@@ -172,12 +208,20 @@
var pathPropertyIndexesCache OncePer
-// pathPropertyIndexesForPropertyStruct returns a list of all of the indexes of properties in
-// property struct type that are tagged with `android:"path"`. Each index is a []int suitable for
-// passing to reflect.Value.FieldByIndex. The value is cached in a global cache by type.
-func pathPropertyIndexesForPropertyStruct(ps interface{}) [][]int {
- key := NewCustomOnceKey(reflect.TypeOf(ps))
+// taggedPropertyIndexesForPropertyStruct returns a list of all of the indexes of properties in
+// property struct type that are tagged with `android:"tagValue"`. Each index is a []int suitable
+// for passing to reflect.Value.FieldByIndex. The value is cached in a global cache by type and
+// tagValue.
+func taggedPropertyIndexesForPropertyStruct(ps interface{}, tagValue string) [][]int {
+ type pathPropertyIndexesOnceKey struct {
+ propStructType reflect.Type
+ tagValue string
+ }
+ key := NewCustomOnceKey(pathPropertyIndexesOnceKey{
+ propStructType: reflect.TypeOf(ps),
+ tagValue: tagValue,
+ })
return pathPropertyIndexesCache.Once(key, func() interface{} {
- return proptools.PropertyIndexesWithTag(ps, "android", "path")
+ return proptools.PropertyIndexesWithTag(ps, "android", tagValue)
}).([][]int)
}