Use ContainsProperty to support default values

Instead of setting a string property to magic default value and then
checking for it later, call ctx.ContainsProperty to determine if it
was set.  Use the same method on the clang bool property, which
couldn't be set to a magic value.

blueprint's ModuleContext.ContainsProperty only works on a single
property, not on all arch variant properties -
ModuleContext.ContainsProperty("clang") will return false if
clang was not set but arch.arm.clang was set - so track which
properties were extended inside extendProperties, and override
ModuleContext.ContainsProperty in AndroidModuleContext to also
check the extended properties.

Change-Id: I03cbe71dc69344972e23d6c794da9be05e720c45
This commit is contained in:
Colin Cross
2015-03-26 16:14:04 -07:00
parent c940435029
commit 28d76590f1
3 changed files with 38 additions and 27 deletions

View File

@@ -401,8 +401,7 @@ func (c *ccBase) collectFlags(ctx common.AndroidModuleContext, toolchain Toolcha
// TODO: debug // TODO: debug
flags.CFlags = append(flags.CFlags, c.properties.Release.Cflags...) flags.CFlags = append(flags.CFlags, c.properties.Release.Cflags...)
if ctx.Host() { if ctx.Host() && !ctx.ContainsProperty("clang") {
// TODO: allow per-module clang disable for host
flags.Clang = true flags.Clang = true
} }
@@ -684,19 +683,15 @@ type ccLinked struct {
func newCCDynamic(dynamic *ccLinked, module CCModuleType, hod common.HostOrDeviceSupported, func newCCDynamic(dynamic *ccLinked, module CCModuleType, hod common.HostOrDeviceSupported,
multilib common.Multilib, props ...interface{}) (blueprint.Module, []interface{}) { multilib common.Multilib, props ...interface{}) (blueprint.Module, []interface{}) {
dynamic.properties.System_shared_libs = []string{defaultSystemSharedLibraries}
props = append(props, &dynamic.dynamicProperties) props = append(props, &dynamic.dynamicProperties)
return newCCBase(&dynamic.ccBase, module, hod, multilib, props...) return newCCBase(&dynamic.ccBase, module, hod, multilib, props...)
} }
const defaultSystemSharedLibraries = "__default__"
func (c *ccLinked) systemSharedLibs(ctx common.AndroidBaseContext) []string { func (c *ccLinked) systemSharedLibs(ctx common.AndroidBaseContext) []string {
if len(c.properties.System_shared_libs) == 1 && if ctx.ContainsProperty("system_shared_libs") {
c.properties.System_shared_libs[0] == defaultSystemSharedLibraries { return c.properties.System_shared_libs
} else {
if ctx.Host() { if ctx.Host() {
return []string{} return []string{}
} else if c.properties.Sdk_version != "" { } else if c.properties.Sdk_version != "" {
@@ -714,7 +709,6 @@ func (c *ccLinked) systemSharedLibs(ctx common.AndroidBaseContext) []string {
return []string{"libc", "libm"} return []string{"libc", "libm"}
} }
} }
return c.properties.System_shared_libs
} }
func (c *ccLinked) stl(ctx common.AndroidBaseContext) string { func (c *ccLinked) stl(ctx common.AndroidBaseContext) string {

View File

@@ -355,7 +355,7 @@ func (a *AndroidModuleBase) setArchProperties(ctx blueprint.EarlyMutatorContext,
// }, // },
// }, // },
t := arch.ArchType t := arch.ArchType
extendProperties(ctx, "arch", t.Name, generalPropsValue, a.extendProperties(ctx, "arch", t.Name, generalPropsValue,
reflect.ValueOf(a.archProperties[i].Arch).FieldByName(t.Field).Elem().Elem()) reflect.ValueOf(a.archProperties[i].Arch).FieldByName(t.Field).Elem().Elem())
// Handle multilib-specific properties in the form: // Handle multilib-specific properties in the form:
@@ -364,7 +364,7 @@ func (a *AndroidModuleBase) setArchProperties(ctx blueprint.EarlyMutatorContext,
// key: value, // key: value,
// }, // },
// }, // },
extendProperties(ctx, "multilib", t.Multilib, generalPropsValue, a.extendProperties(ctx, "multilib", t.Multilib, generalPropsValue,
reflect.ValueOf(a.archProperties[i].Multilib).FieldByName(t.MultilibField).Elem().Elem()) reflect.ValueOf(a.archProperties[i].Multilib).FieldByName(t.MultilibField).Elem().Elem())
// Handle host-or-device-specific properties in the form: // Handle host-or-device-specific properties in the form:
@@ -374,7 +374,7 @@ func (a *AndroidModuleBase) setArchProperties(ctx blueprint.EarlyMutatorContext,
// }, // },
// }, // },
hod := arch.HostOrDevice hod := arch.HostOrDevice
extendProperties(ctx, "target", hod.FieldLower(), generalPropsValue, a.extendProperties(ctx, "target", hod.FieldLower(), generalPropsValue,
reflect.ValueOf(a.archProperties[i].Target).FieldByName(hod.Field()).Elem().Elem()) reflect.ValueOf(a.archProperties[i].Target).FieldByName(hod.Field()).Elem().Elem())
// Handle host target properties in the form: // Handle host target properties in the form:
@@ -398,11 +398,11 @@ func (a *AndroidModuleBase) setArchProperties(ctx blueprint.EarlyMutatorContext,
if hod.Host() { if hod.Host() {
for _, v := range osList { for _, v := range osList {
if v.goos == runtime.GOOS { if v.goos == runtime.GOOS {
extendProperties(ctx, "target", v.goos, generalPropsValue, a.extendProperties(ctx, "target", v.goos, generalPropsValue,
reflect.ValueOf(a.archProperties[i].Target).FieldByName(v.field).Elem().Elem()) reflect.ValueOf(a.archProperties[i].Target).FieldByName(v.field).Elem().Elem())
} }
} }
extendProperties(ctx, "target", "not_windows", generalPropsValue, a.extendProperties(ctx, "target", "not_windows", generalPropsValue,
reflect.ValueOf(a.archProperties[i].Target).FieldByName("Not_windows").Elem().Elem()) reflect.ValueOf(a.archProperties[i].Target).FieldByName("Not_windows").Elem().Elem())
} }
@@ -421,10 +421,10 @@ func (a *AndroidModuleBase) setArchProperties(ctx blueprint.EarlyMutatorContext,
// debuggerd that need to know when they are a 32-bit process running on a 64-bit device // debuggerd that need to know when they are a 32-bit process running on a 64-bit device
if hod.Device() { if hod.Device() {
if true /* && target_is_64_bit */ { if true /* && target_is_64_bit */ {
extendProperties(ctx, "target", "android64", generalPropsValue, a.extendProperties(ctx, "target", "android64", generalPropsValue,
reflect.ValueOf(a.archProperties[i].Target).FieldByName("Android64").Elem().Elem()) reflect.ValueOf(a.archProperties[i].Target).FieldByName("Android64").Elem().Elem())
} else { } else {
extendProperties(ctx, "target", "android32", generalPropsValue, a.extendProperties(ctx, "target", "android32", generalPropsValue,
reflect.ValueOf(a.archProperties[i].Target).FieldByName("Android32").Elem().Elem()) reflect.ValueOf(a.archProperties[i].Target).FieldByName("Android32").Elem().Elem())
} }
} }
@@ -450,12 +450,12 @@ func forEachInterface(v reflect.Value, f func(reflect.Value)) {
} }
// TODO: move this to proptools // TODO: move this to proptools
func extendProperties(ctx blueprint.EarlyMutatorContext, variationType, variationName string, func (a *AndroidModuleBase) extendProperties(ctx blueprint.EarlyMutatorContext, variationType, variationName string,
dstValue, srcValue reflect.Value) { dstValue, srcValue reflect.Value) {
extendPropertiesRecursive(ctx, variationType, variationName, dstValue, srcValue, "") a.extendPropertiesRecursive(ctx, variationType, variationName, dstValue, srcValue, "")
} }
func extendPropertiesRecursive(ctx blueprint.EarlyMutatorContext, variationType, variationName string, func (a *AndroidModuleBase) extendPropertiesRecursive(ctx blueprint.EarlyMutatorContext, variationType, variationName string,
dstValue, srcValue reflect.Value, recursePrefix string) { dstValue, srcValue reflect.Value, recursePrefix string) {
typ := dstValue.Type() typ := dstValue.Type()
@@ -497,6 +497,11 @@ func extendPropertiesRecursive(ctx blueprint.EarlyMutatorContext, variationType,
continue continue
} }
if !ctx.ContainsProperty(propertyName) {
continue
}
a.extendedProperties[localPropertyName] = struct{}{}
switch srcFieldValue.Kind() { switch srcFieldValue.Kind() {
case reflect.Bool: case reflect.Bool:
// Replace the original value. // Replace the original value.
@@ -508,7 +513,7 @@ func extendPropertiesRecursive(ctx blueprint.EarlyMutatorContext, variationType,
case reflect.Struct: case reflect.Struct:
// Recursively extend the struct's fields. // Recursively extend the struct's fields.
newRecursePrefix := fmt.Sprintf("%s%s.", recursePrefix, strings.ToLower(field.Name)) newRecursePrefix := fmt.Sprintf("%s%s.", recursePrefix, strings.ToLower(field.Name))
extendPropertiesRecursive(ctx, variationType, variationName, a.extendPropertiesRecursive(ctx, variationType, variationName,
dstFieldValue, srcFieldValue, dstFieldValue, srcFieldValue,
newRecursePrefix) newRecursePrefix)
case reflect.Slice: case reflect.Slice:
@@ -528,7 +533,7 @@ func extendPropertiesRecursive(ctx blueprint.EarlyMutatorContext, variationType,
} }
if !dstFieldValue.IsNil() { if !dstFieldValue.IsNil() {
newRecursePrefix := fmt.Sprintf("%s.%s", recursePrefix, field.Name) newRecursePrefix := fmt.Sprintf("%s.%s", recursePrefix, field.Name)
extendPropertiesRecursive(ctx, variationType, variationName, a.extendPropertiesRecursive(ctx, variationType, variationName,
dstFieldValue.Elem(), srcFieldValue.Elem(), dstFieldValue.Elem(), srcFieldValue.Elem(),
newRecursePrefix) newRecursePrefix)
} }

View File

@@ -113,6 +113,7 @@ func InitAndroidModule(m AndroidModule,
base := m.base() base := m.base()
base.module = m base.module = m
base.extendedProperties = make(map[string]struct{})
propertyStructs = append(propertyStructs, &base.commonProperties) propertyStructs = append(propertyStructs, &base.commonProperties)
@@ -186,6 +187,7 @@ type AndroidModuleBase struct {
hostAndDeviceProperties hostAndDeviceProperties hostAndDeviceProperties hostAndDeviceProperties
generalProperties []interface{} generalProperties []interface{}
archProperties []*archProperties archProperties []*archProperties
extendedProperties map[string]struct{}
noAddressSanitizer bool noAddressSanitizer bool
installFiles []string installFiles []string
@@ -313,8 +315,9 @@ func (a *AndroidModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) {
androidBaseContextImpl: androidBaseContextImpl{ androidBaseContextImpl: androidBaseContextImpl{
arch: a.commonProperties.CompileArch, arch: a.commonProperties.CompileArch,
}, },
installDeps: a.computeInstallDeps(ctx), installDeps: a.computeInstallDeps(ctx),
installFiles: a.installFiles, installFiles: a.installFiles,
extendedProperties: a.extendedProperties,
} }
if a.commonProperties.Disabled { if a.commonProperties.Disabled {
@@ -343,9 +346,10 @@ type androidBaseContextImpl struct {
type androidModuleContext struct { type androidModuleContext struct {
blueprint.ModuleContext blueprint.ModuleContext
androidBaseContextImpl androidBaseContextImpl
installDeps []string installDeps []string
installFiles []string installFiles []string
checkbuildFiles []string checkbuildFiles []string
extendedProperties map[string]struct{}
} }
func (a *androidModuleContext) Build(pctx *blueprint.PackageContext, params blueprint.BuildParams) { func (a *androidModuleContext) Build(pctx *blueprint.PackageContext, params blueprint.BuildParams) {
@@ -353,6 +357,14 @@ func (a *androidModuleContext) Build(pctx *blueprint.PackageContext, params blue
a.ModuleContext.Build(pctx, params) a.ModuleContext.Build(pctx, params)
} }
func (a *androidModuleContext) ContainsProperty(property string) bool {
if a.ModuleContext.ContainsProperty(property) {
return true
}
_, ok := a.extendedProperties[property]
return ok
}
func (a *androidBaseContextImpl) Arch() Arch { func (a *androidBaseContextImpl) Arch() Arch {
return a.arch return a.arch
} }