From c5c24ade6335455ea006499ee7ae449d89e56514 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 20 Nov 2015 15:35:00 -0800 Subject: Add arch features Allow architecture toolchains to register "features" supported by the current variant, and then apply properties from the selected features. Equivalent to the ARCH_*_HAS_* variables in the combo makefiles. Change-Id: Ib6823be1c1a52da677d081db9f24336a072eaf39 --- common/arch.go | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'common/arch.go') diff --git a/common/arch.go b/common/arch.go index 21f638ab..3669e801 100644 --- a/common/arch.go +++ b/common/arch.go @@ -208,12 +208,34 @@ type archProperties struct { } } +var archFeatureMap = map[ArchType]map[string][]string{} + +func RegisterArchFeatures(arch ArchType, variant string, features ...string) { + field := proptools.FieldNameForProperty(variant) + if variant != "" { + if !reflect.ValueOf(archProperties{}.Arch).FieldByName(field).IsValid() { + panic(fmt.Errorf("Invalid variant %q for arch %q", variant, arch)) + } + } + for _, feature := range features { + field := proptools.FieldNameForProperty(feature) + if !reflect.ValueOf(archProperties{}.Arch).FieldByName(field).IsValid() { + panic(fmt.Errorf("Invalid feature %q for arch %q variant %q", feature, arch, variant)) + } + } + if archFeatureMap[arch] == nil { + archFeatureMap[arch] = make(map[string][]string) + } + archFeatureMap[arch][variant] = features +} + // An Arch indicates a single CPU architecture. type Arch struct { - ArchType ArchType - ArchVariant string - CpuVariant string - Abi []string + ArchType ArchType + ArchVariant string + CpuVariant string + Abi []string + ArchFeatures []string } func (a Arch) String() string { @@ -516,6 +538,18 @@ func (a *AndroidModuleBase) setArchProperties(ctx AndroidBottomUpMutatorContext) a.appendProperties(ctx, genProps, archProps.Arch, field, prefix) } + // Handle arch-feature-specific properties in the form: + // arch: { + // feature: { + // key: value, + // }, + // }, + for _, feature := range arch.ArchFeatures { + field := proptools.FieldNameForProperty(feature) + prefix := "arch." + feature + a.appendProperties(ctx, genProps, archProps.Arch, field, prefix) + } + // Handle multilib-specific properties in the form: // multilib: { // lib32: { @@ -729,6 +763,10 @@ func decodeArch(arch string, archVariant, cpuVariant *string, abi *[]string) (Ar } } + if featureMap, ok := archFeatureMap[archType]; ok { + a.ArchFeatures = featureMap[stringPtr(archVariant)] + } + return a, nil } -- cgit v1.2.3