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:
14
cc/cc.go
14
cc/cc.go
@@ -401,8 +401,7 @@ func (c *ccBase) collectFlags(ctx common.AndroidModuleContext, toolchain Toolcha
|
||||
// TODO: debug
|
||||
flags.CFlags = append(flags.CFlags, c.properties.Release.Cflags...)
|
||||
|
||||
if ctx.Host() {
|
||||
// TODO: allow per-module clang disable for host
|
||||
if ctx.Host() && !ctx.ContainsProperty("clang") {
|
||||
flags.Clang = true
|
||||
}
|
||||
|
||||
@@ -684,19 +683,15 @@ type ccLinked struct {
|
||||
func newCCDynamic(dynamic *ccLinked, module CCModuleType, hod common.HostOrDeviceSupported,
|
||||
multilib common.Multilib, props ...interface{}) (blueprint.Module, []interface{}) {
|
||||
|
||||
dynamic.properties.System_shared_libs = []string{defaultSystemSharedLibraries}
|
||||
|
||||
props = append(props, &dynamic.dynamicProperties)
|
||||
|
||||
return newCCBase(&dynamic.ccBase, module, hod, multilib, props...)
|
||||
}
|
||||
|
||||
const defaultSystemSharedLibraries = "__default__"
|
||||
|
||||
func (c *ccLinked) systemSharedLibs(ctx common.AndroidBaseContext) []string {
|
||||
if len(c.properties.System_shared_libs) == 1 &&
|
||||
c.properties.System_shared_libs[0] == defaultSystemSharedLibraries {
|
||||
|
||||
if ctx.ContainsProperty("system_shared_libs") {
|
||||
return c.properties.System_shared_libs
|
||||
} else {
|
||||
if ctx.Host() {
|
||||
return []string{}
|
||||
} else if c.properties.Sdk_version != "" {
|
||||
@@ -714,7 +709,6 @@ func (c *ccLinked) systemSharedLibs(ctx common.AndroidBaseContext) []string {
|
||||
return []string{"libc", "libm"}
|
||||
}
|
||||
}
|
||||
return c.properties.System_shared_libs
|
||||
}
|
||||
|
||||
func (c *ccLinked) stl(ctx common.AndroidBaseContext) string {
|
||||
|
@@ -355,7 +355,7 @@ func (a *AndroidModuleBase) setArchProperties(ctx blueprint.EarlyMutatorContext,
|
||||
// },
|
||||
// },
|
||||
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())
|
||||
|
||||
// Handle multilib-specific properties in the form:
|
||||
@@ -364,7 +364,7 @@ func (a *AndroidModuleBase) setArchProperties(ctx blueprint.EarlyMutatorContext,
|
||||
// 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())
|
||||
|
||||
// Handle host-or-device-specific properties in the form:
|
||||
@@ -374,7 +374,7 @@ func (a *AndroidModuleBase) setArchProperties(ctx blueprint.EarlyMutatorContext,
|
||||
// },
|
||||
// },
|
||||
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())
|
||||
|
||||
// Handle host target properties in the form:
|
||||
@@ -398,11 +398,11 @@ func (a *AndroidModuleBase) setArchProperties(ctx blueprint.EarlyMutatorContext,
|
||||
if hod.Host() {
|
||||
for _, v := range osList {
|
||||
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())
|
||||
}
|
||||
}
|
||||
extendProperties(ctx, "target", "not_windows", generalPropsValue,
|
||||
a.extendProperties(ctx, "target", "not_windows", generalPropsValue,
|
||||
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
|
||||
if hod.Device() {
|
||||
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())
|
||||
} else {
|
||||
extendProperties(ctx, "target", "android32", generalPropsValue,
|
||||
a.extendProperties(ctx, "target", "android32", generalPropsValue,
|
||||
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
|
||||
func extendProperties(ctx blueprint.EarlyMutatorContext, variationType, variationName string,
|
||||
func (a *AndroidModuleBase) extendProperties(ctx blueprint.EarlyMutatorContext, variationType, variationName string,
|
||||
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) {
|
||||
|
||||
typ := dstValue.Type()
|
||||
@@ -497,6 +497,11 @@ func extendPropertiesRecursive(ctx blueprint.EarlyMutatorContext, variationType,
|
||||
continue
|
||||
}
|
||||
|
||||
if !ctx.ContainsProperty(propertyName) {
|
||||
continue
|
||||
}
|
||||
a.extendedProperties[localPropertyName] = struct{}{}
|
||||
|
||||
switch srcFieldValue.Kind() {
|
||||
case reflect.Bool:
|
||||
// Replace the original value.
|
||||
@@ -508,7 +513,7 @@ func extendPropertiesRecursive(ctx blueprint.EarlyMutatorContext, variationType,
|
||||
case reflect.Struct:
|
||||
// Recursively extend the struct's fields.
|
||||
newRecursePrefix := fmt.Sprintf("%s%s.", recursePrefix, strings.ToLower(field.Name))
|
||||
extendPropertiesRecursive(ctx, variationType, variationName,
|
||||
a.extendPropertiesRecursive(ctx, variationType, variationName,
|
||||
dstFieldValue, srcFieldValue,
|
||||
newRecursePrefix)
|
||||
case reflect.Slice:
|
||||
@@ -528,7 +533,7 @@ func extendPropertiesRecursive(ctx blueprint.EarlyMutatorContext, variationType,
|
||||
}
|
||||
if !dstFieldValue.IsNil() {
|
||||
newRecursePrefix := fmt.Sprintf("%s.%s", recursePrefix, field.Name)
|
||||
extendPropertiesRecursive(ctx, variationType, variationName,
|
||||
a.extendPropertiesRecursive(ctx, variationType, variationName,
|
||||
dstFieldValue.Elem(), srcFieldValue.Elem(),
|
||||
newRecursePrefix)
|
||||
}
|
||||
|
@@ -113,6 +113,7 @@ func InitAndroidModule(m AndroidModule,
|
||||
|
||||
base := m.base()
|
||||
base.module = m
|
||||
base.extendedProperties = make(map[string]struct{})
|
||||
|
||||
propertyStructs = append(propertyStructs, &base.commonProperties)
|
||||
|
||||
@@ -186,6 +187,7 @@ type AndroidModuleBase struct {
|
||||
hostAndDeviceProperties hostAndDeviceProperties
|
||||
generalProperties []interface{}
|
||||
archProperties []*archProperties
|
||||
extendedProperties map[string]struct{}
|
||||
|
||||
noAddressSanitizer bool
|
||||
installFiles []string
|
||||
@@ -313,8 +315,9 @@ func (a *AndroidModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) {
|
||||
androidBaseContextImpl: androidBaseContextImpl{
|
||||
arch: a.commonProperties.CompileArch,
|
||||
},
|
||||
installDeps: a.computeInstallDeps(ctx),
|
||||
installFiles: a.installFiles,
|
||||
installDeps: a.computeInstallDeps(ctx),
|
||||
installFiles: a.installFiles,
|
||||
extendedProperties: a.extendedProperties,
|
||||
}
|
||||
|
||||
if a.commonProperties.Disabled {
|
||||
@@ -343,9 +346,10 @@ type androidBaseContextImpl struct {
|
||||
type androidModuleContext struct {
|
||||
blueprint.ModuleContext
|
||||
androidBaseContextImpl
|
||||
installDeps []string
|
||||
installFiles []string
|
||||
checkbuildFiles []string
|
||||
installDeps []string
|
||||
installFiles []string
|
||||
checkbuildFiles []string
|
||||
extendedProperties map[string]struct{}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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 {
|
||||
return a.arch
|
||||
}
|
||||
|
Reference in New Issue
Block a user