Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a9e9f539 authored by Cole Faust's avatar Cole Faust Committed by Gerrit Code Review
Browse files

Merge "Add new properties to aid in removing the 1-variant fallback" into main

parents 25ebc502 65cb40a9
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -41,6 +41,14 @@ type fileGroupProperties struct {

	Exclude_srcs proptools.Configurable[[]string] `android:"path"`

	// Sources the will be included in the filegroup, but any module dependencies will be added
	// using the device os and the device's first architecture's variant.
	Device_first_srcs proptools.Configurable[[]string] `android:"path_device_first"`

	// Sources the will be included in the filegroup, but any module dependencies will be added
	// using the device os and the common architecture's variant.
	Device_common_srcs proptools.Configurable[[]string] `android:"path_device_common"`

	// The base path to the files.  May be used by other modules to determine which portion
	// of the path to use.  For example, when a filegroup is used as data in a cc_test rule,
	// the base path is stripped off the path and the remaining path is used as the
@@ -90,11 +98,13 @@ func (fg *fileGroup) JSONActions() []blueprint.JSONAction {
}

func (fg *fileGroup) GenerateAndroidBuildActions(ctx ModuleContext) {
	fg.srcs = PathsForModuleSrcExcludes(ctx, fg.properties.Srcs.GetOrDefault(ctx, nil), fg.properties.Exclude_srcs.GetOrDefault(ctx, nil))
	srcs := PathsForModuleSrcExcludes(ctx, fg.properties.Srcs.GetOrDefault(ctx, nil), fg.properties.Exclude_srcs.GetOrDefault(ctx, nil))
	srcs = append(srcs, PathsForModuleSrc(ctx, fg.properties.Device_first_srcs.GetOrDefault(ctx, nil))...)
	srcs = append(srcs, PathsForModuleSrc(ctx, fg.properties.Device_common_srcs.GetOrDefault(ctx, nil))...)
	if fg.properties.Path != nil {
		fg.srcs = PathsWithModuleSrcSubDir(ctx, fg.srcs, String(fg.properties.Path))
		srcs = PathsWithModuleSrcSubDir(ctx, srcs, String(fg.properties.Path))
	}
	SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: fg.srcs.Strings()})
	SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: srcs.Strings()})

	var aconfigDeclarations []string
	var intermediateCacheOutputPaths Paths
@@ -108,6 +118,8 @@ func (fg *fileGroup) GenerateAndroidBuildActions(ctx ModuleContext) {
			maps.Copy(modeInfos, dep.ModeInfos)
		}
	})

	fg.srcs = srcs
	SetProvider(ctx, CodegenInfoProvider, CodegenInfo{
		AconfigDeclarations:          aconfigDeclarations,
		IntermediateCacheOutputPaths: intermediateCacheOutputPaths,
+56 −12
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ import (
	"fmt"
	"reflect"

	"github.com/google/blueprint"
	"github.com/google/blueprint/proptools"
)

@@ -38,20 +39,32 @@ func pathDepsMutator(ctx BottomUpMutatorContext) {
		// 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 @@ func addPathDepsForProps(ctx BottomUpMutatorContext, props []interface{}) {
			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 @@ func pathPropertiesForPropertyStruct(ctx BottomUpMutatorContext, ps interface{})
	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 @@ func isSliceOfStruct(v reflect.Value) bool {

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)
}
+1 −1
Original line number Diff line number Diff line
@@ -11342,7 +11342,7 @@ func TestAconfifDeclarationsValidation(t *testing.T) {
		}
		filegroup {
			name: "qux-filegroup",
			srcs: [
			device_common_srcs: [
				":qux-lib{.generated_srcjars}",
			],
		}
+1 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ func TestLibbpfProgDataDependency(t *testing.T) {

		cc_test {
			name: "vts_test_binary_bpf_module",
			compile_multilib: "first",
			srcs: ["BpfTest.cpp"],
			data: [":bpf.o"],
			gtest: false,
+9 −3
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ type Deps struct {

	GeneratedSources            []string
	GeneratedHeaders            []string
	DeviceFirstGeneratedHeaders []string
	GeneratedDeps               []string

	ReexportGeneratedHeaders []string
@@ -2609,6 +2610,11 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
		actx.AddDependency(c, depTag, gen)
	}

	for _, gen := range deps.DeviceFirstGeneratedHeaders {
		depTag := genHeaderDepTag
		actx.AddVariationDependencies(ctx.Config().AndroidFirstDeviceTarget.Variations(), depTag, gen)
	}

	crtVariations := GetCrtVariations(ctx, c)
	actx.AddVariationDependencies(crtVariations, objDepTag, deps.ObjFiles...)
	for _, crt := range deps.CrtBegin {
Loading