Merge "androidmk: make class+suffix into generic prefix" into master-soong

This commit is contained in:
Colin Cross 2015-05-13 00:50:09 +00:00 committed by Gerrit Code Review
commit 7d42bdad16
2 changed files with 123 additions and 143 deletions

View file

@ -74,7 +74,7 @@ var standardProperties = map[string]struct {
} }
var rewriteProperties = map[string]struct { var rewriteProperties = map[string]struct {
f func(file *bpFile, value *mkparser.MakeString, append bool, class, suffix string) error f func(file *bpFile, prefix string, value *mkparser.MakeString, append bool) error
}{ }{
"LOCAL_C_INCLUDES": {localIncludeDirs}, "LOCAL_C_INCLUDES": {localIncludeDirs},
"LOCAL_EXPORT_C_INCLUDE_DIRS": {exportIncludeDirs}, "LOCAL_EXPORT_C_INCLUDE_DIRS": {exportIncludeDirs},
@ -191,8 +191,7 @@ func splitLocalGlobal(file *bpFile, val *bpparser.Value) (local, global *bpparse
return local, global, nil return local, global, nil
} }
func localIncludeDirs(file *bpFile, value *mkparser.MakeString, appendVariable bool, func localIncludeDirs(file *bpFile, prefix string, value *mkparser.MakeString, appendVariable bool) error {
class, suffix string) error {
val, err := makeVariableToBlueprint(file, value, bpparser.List) val, err := makeVariableToBlueprint(file, value, bpparser.List)
if err != nil { if err != nil {
return err return err
@ -204,14 +203,14 @@ func localIncludeDirs(file *bpFile, value *mkparser.MakeString, appendVariable b
} }
if len(global.ListValue) > 0 || global.Expression != nil || global.Variable != "" { if len(global.ListValue) > 0 || global.Expression != nil || global.Variable != "" {
err = setVariable(file, appendVariable, "include_dirs", global, true, class, suffix) err = setVariable(file, appendVariable, prefix, "include_dirs", global, true)
if err != nil { if err != nil {
return err return err
} }
} }
if len(local.ListValue) > 0 || local.Expression != nil || local.Variable != "" { if len(local.ListValue) > 0 || local.Expression != nil || local.Variable != "" {
err = setVariable(file, appendVariable, "local_include_dirs", local, true, class, suffix) err = setVariable(file, appendVariable, prefix, "local_include_dirs", local, true)
if err != nil { if err != nil {
return err return err
} }
@ -220,9 +219,7 @@ func localIncludeDirs(file *bpFile, value *mkparser.MakeString, appendVariable b
return nil return nil
} }
func exportIncludeDirs(file *bpFile, value *mkparser.MakeString, appendVariable bool, func exportIncludeDirs(file *bpFile, prefix string, value *mkparser.MakeString, appendVariable bool) error {
class, suffix string) error {
val, err := makeVariableToBlueprint(file, value, bpparser.List) val, err := makeVariableToBlueprint(file, value, bpparser.List)
if err != nil { if err != nil {
return err return err
@ -234,7 +231,7 @@ func exportIncludeDirs(file *bpFile, value *mkparser.MakeString, appendVariable
} }
if len(local.ListValue) > 0 || local.Expression != nil || local.Variable != "" { if len(local.ListValue) > 0 || local.Expression != nil || local.Variable != "" {
err = setVariable(file, appendVariable, "export_include_dirs", local, true, class, suffix) err = setVariable(file, appendVariable, prefix, "export_include_dirs", local, true)
if err != nil { if err != nil {
return err return err
} }
@ -244,7 +241,7 @@ func exportIncludeDirs(file *bpFile, value *mkparser.MakeString, appendVariable
// Add any paths that could not be converted to local relative paths to export_include_dirs // Add any paths that could not be converted to local relative paths to export_include_dirs
// anyways, they will cause an error if they don't exist and can be fixed manually. // anyways, they will cause an error if they don't exist and can be fixed manually.
if len(global.ListValue) > 0 || global.Expression != nil || global.Variable != "" { if len(global.ListValue) > 0 || global.Expression != nil || global.Variable != "" {
err = setVariable(file, appendVariable, "export_include_dirs", global, true, class, suffix) err = setVariable(file, appendVariable, prefix, "export_include_dirs", global, true)
if err != nil { if err != nil {
return err return err
} }
@ -253,7 +250,7 @@ func exportIncludeDirs(file *bpFile, value *mkparser.MakeString, appendVariable
return nil return nil
} }
func stem(file *bpFile, value *mkparser.MakeString, appendVariable bool, class, suffix string) error { func stem(file *bpFile, prefix string, value *mkparser.MakeString, appendVariable bool) error {
val, err := makeVariableToBlueprint(file, value, bpparser.String) val, err := makeVariableToBlueprint(file, value, bpparser.String)
if err != nil { if err != nil {
return err return err
@ -266,47 +263,58 @@ func stem(file *bpFile, value *mkparser.MakeString, appendVariable bool, class,
val = &val.Expression.Args[1] val = &val.Expression.Args[1]
} }
return setVariable(file, appendVariable, varName, val, true, class, suffix) return setVariable(file, appendVariable, prefix, varName, val, true)
} }
var deleteProperties = map[string]struct{}{ var deleteProperties = map[string]struct{}{
"LOCAL_CPP_EXTENSION": struct{}{}, "LOCAL_CPP_EXTENSION": struct{}{},
} }
var propertySuffixes = []struct { var propertyPrefixes = map[string]string{
suffix string "arm": "arch.arm",
class string "arm64": "arm.arm64",
}{ "mips": "arch.mips",
{"arm", "arch"}, "mips64": "arch.mips64",
{"arm64", "arch"}, "x86": "arch.x86",
{"mips", "arch"}, "x86_64": "arch.x86_64",
{"mips64", "arch"}, "32": "multilib.lib32",
{"x86", "arch"}, "64": "multilib.lib64",
{"x86_64", "arch"},
{"32", "multilib"},
{"64", "multilib"},
} }
var propertySuffixTranslations = map[string]string{ var conditionalTranslations = map[string]map[bool]string{
"32": "lib32", "($(HOST_OS),darwin)": {
"64": "lib64", true: "target.darwin",
} false: "target.not_darwin"},
"($(HOST_OS), darwin)": {
var conditionalTranslations = map[string]struct { true: "target.darwin",
class string false: "target.not_darwin"},
suffix string "($(HOST_OS),windows)": {
}{ true: "target.windows",
"($(HOST_OS),darwin)": {"target", "darwin"}, false: "target.not_windows"},
"($(HOST_OS), darwin)": {"target", "darwin"}, "($(HOST_OS), windows)": {
"($(HOST_OS),windows)": {"target", "windows"}, true: "target.windows",
"($(HOST_OS), windows)": {"target", "windows"}, false: "target.not_windows"},
"($(HOST_OS),linux)": {"target", "linux"}, "($(HOST_OS),linux)": {
"($(HOST_OS), linux)": {"target", "linux"}, true: "target.linux",
"($(BUILD_OS),darwin)": {"target", "darwin"}, false: "target.not_linux"},
"($(BUILD_OS), darwin)": {"target", "darwin"}, "($(HOST_OS), linux)": {
"($(BUILD_OS),linux)": {"target", "linux"}, true: "target.linux",
"($(BUILD_OS), linux)": {"target", "linux"}, false: "target.not_linux"},
"USE_MINGW": {"target", "windows"}, "($(BUILD_OS),darwin)": {
true: "target.darwin",
false: "target.not_darwin"},
"($(BUILD_OS), darwin)": {
true: "target.darwin",
false: "target.not_darwin"},
"($(BUILD_OS),linux)": {
true: "target.linux",
false: "target.not_linux"},
"($(BUILD_OS), linux)": {
true: "target.linux",
false: "target.not_linux"},
"USE_MINGW": {
true: "target.windows",
false: "target.not_windows"},
} }
func mydir(args []string) string { func mydir(args []string) string {

View file

@ -188,34 +188,23 @@ func handleAssignment(file *bpFile, assignment mkparser.Assignment, c *condition
} }
name := assignment.Name.Value(nil) name := assignment.Name.Value(nil)
suffix := "" prefix := ""
class := ""
if strings.HasPrefix(name, "LOCAL_") { if strings.HasPrefix(name, "LOCAL_") {
for _, v := range propertySuffixes { for k, v := range propertyPrefixes {
s, c := v.suffix, v.class if strings.HasSuffix(name, "_"+k) {
if strings.HasSuffix(name, "_"+s) { name = strings.TrimSuffix(name, "_"+k)
name = strings.TrimSuffix(name, "_"+s) prefix = v
suffix = s
if s, ok := propertySuffixTranslations[s]; ok {
suffix = s
}
class = c
break break
} }
} }
if c != nil { if c != nil {
if class != "" { if prefix != "" {
file.errorf(assignment, "suffix assignment inside conditional, skipping conditional") file.errorf(assignment, "prefix assignment inside conditional, skipping conditional")
} else {
if v, ok := conditionalTranslations[c.cond]; ok {
class = v.class
suffix = v.suffix
if !c.eq {
suffix = "not_" + suffix
}
} else { } else {
var ok bool
if prefix, ok = conditionalTranslations[c.cond][c.eq]; !ok {
panic("unknown conditional") panic("unknown conditional")
} }
} }
@ -237,10 +226,10 @@ func handleAssignment(file *bpFile, assignment mkparser.Assignment, c *condition
var val *bpparser.Value var val *bpparser.Value
val, err = makeVariableToBlueprint(file, assignment.Value, prop.ValueType) val, err = makeVariableToBlueprint(file, assignment.Value, prop.ValueType)
if err == nil { if err == nil {
err = setVariable(file, appendVariable, prop.string, val, true, class, suffix) err = setVariable(file, appendVariable, prefix, prop.string, val, true)
} }
} else if prop, ok := rewriteProperties[name]; ok { } else if prop, ok := rewriteProperties[name]; ok {
err = prop.f(file, assignment.Value, appendVariable, class, suffix) err = prop.f(file, prefix, assignment.Value, appendVariable)
} else if _, ok := deleteProperties[name]; ok { } else if _, ok := deleteProperties[name]; ok {
return return
} else { } else {
@ -261,7 +250,7 @@ func handleAssignment(file *bpFile, assignment mkparser.Assignment, c *condition
default: default:
var val *bpparser.Value var val *bpparser.Value
val, err = makeVariableToBlueprint(file, assignment.Value, bpparser.List) val, err = makeVariableToBlueprint(file, assignment.Value, bpparser.List)
err = setVariable(file, appendVariable, name, val, false, class, suffix) err = setVariable(file, appendVariable, prefix, name, val, false)
} }
} }
if err != nil { if err != nil {
@ -274,39 +263,39 @@ func handleModuleConditionals(file *bpFile, directive mkparser.Directive, c *con
return return
} }
if v, ok := conditionalTranslations[c.cond]; ok { if _, ok := conditionalTranslations[c.cond]; !ok {
class := v.class panic("unknown conditional " + c.cond)
suffix := v.suffix
disabledSuffix := v.suffix
if !c.eq {
suffix = "not_" + suffix
} else {
disabledSuffix = "not_" + disabledSuffix
} }
prefix := conditionalTranslations[c.cond][c.eq]
disabledPrefix := conditionalTranslations[c.cond][!c.eq]
names := strings.Split(prefix, ".")
if len(names) != 2 {
panic("expected class.type")
}
class := names[0]
typ := names[1]
classProp := file.localAssignments[class]
// Hoist all properties inside the condtional up to the top level // Hoist all properties inside the condtional up to the top level
file.module.Properties = file.localAssignments[class+"___"+suffix].Value.MapValue file.module.Properties = file.localAssignments[prefix].Value.MapValue
file.module.Properties = append(file.module.Properties, file.localAssignments[class]) file.module.Properties = append(file.module.Properties, classProp)
file.localAssignments[class+"___"+suffix].Value.MapValue = nil file.localAssignments[prefix].Value.MapValue = nil
for i := range file.localAssignments[class].Value.MapValue { for i := range classProp.Value.MapValue {
if file.localAssignments[class].Value.MapValue[i].Name.Name == suffix { if classProp.Value.MapValue[i].Name.Name == typ {
file.localAssignments[class].Value.MapValue = classProp.Value.MapValue = append(classProp.Value.MapValue[:i], classProp.Value.MapValue[i+1:]...)
append(file.localAssignments[class].Value.MapValue[:i],
file.localAssignments[class].Value.MapValue[i+1:]...)
} }
} }
// Create a fake assignment with enabled = false // Create a fake assignment with enabled = false
val, err := makeVariableToBlueprint(file, mkparser.SimpleMakeString("true", file.pos), bpparser.Bool) val, err := makeVariableToBlueprint(file, mkparser.SimpleMakeString("true", file.pos), bpparser.Bool)
if err == nil { if err == nil {
err = setVariable(file, false, "disabled", val, true, class, disabledSuffix) err = setVariable(file, false, disabledPrefix, "disabled", val, true)
} }
if err != nil { if err != nil {
file.errorf(directive, err.Error()) file.errorf(directive, err.Error())
} }
} else {
panic("unknown conditional")
}
} }
func makeModule(file *bpFile, t string) { func makeModule(file *bpFile, t string) {
@ -347,19 +336,17 @@ func makeVariableToBlueprint(file *bpFile, val *mkparser.MakeString,
return exp, nil return exp, nil
} }
func setVariable(file *bpFile, plusequals bool, name string, value *bpparser.Value, local bool, func setVariable(file *bpFile, plusequals bool, prefix, name string, value *bpparser.Value, local bool) error {
class string, suffix string) error {
if prefix != "" {
name = prefix + "." + name
}
pos := file.pos pos := file.pos
var oldValue *bpparser.Value var oldValue *bpparser.Value
if local { if local {
var oldProp *bpparser.Property oldProp := file.localAssignments[name]
if class != "" {
oldProp = file.localAssignments[name+"___"+class+"___"+suffix]
} else {
oldProp = file.localAssignments[name]
}
if oldProp != nil { if oldProp != nil {
oldValue = &oldProp.Value oldValue = &oldProp.Value
} }
@ -375,50 +362,35 @@ func setVariable(file *bpFile, plusequals bool, name string, value *bpparser.Val
} }
val.Expression.Pos = pos val.Expression.Pos = pos
*oldValue = *val *oldValue = *val
} else if class == "" { } else {
names := strings.Split(name, ".")
container := &file.module.Properties
for i, n := range names[:len(names)-1] {
fqn := strings.Join(names[0:i+1], ".")
prop := file.localAssignments[fqn]
if prop == nil {
prop = &bpparser.Property{
Name: bpparser.Ident{Name: n, Pos: pos},
Pos: pos,
Value: bpparser.Value{
Type: bpparser.Map,
MapValue: []*bpparser.Property{},
},
}
file.localAssignments[fqn] = prop
*container = append(*container, prop)
}
container = &prop.Value.MapValue
}
prop := &bpparser.Property{ prop := &bpparser.Property{
Name: bpparser.Ident{Name: name, Pos: pos}, Name: bpparser.Ident{Name: names[len(names)-1], Pos: pos},
Pos: pos, Pos: pos,
Value: *value, Value: *value,
} }
file.localAssignments[name] = prop file.localAssignments[name] = prop
file.module.Properties = append(file.module.Properties, prop) *container = append(*container, prop)
} else {
classProp := file.localAssignments[class]
if classProp == nil {
classProp = &bpparser.Property{
Name: bpparser.Ident{Name: class, Pos: pos},
Pos: pos,
Value: bpparser.Value{
Type: bpparser.Map,
MapValue: []*bpparser.Property{},
},
}
file.localAssignments[class] = classProp
file.module.Properties = append(file.module.Properties, classProp)
}
suffixProp := file.localAssignments[class+"___"+suffix]
if suffixProp == nil {
suffixProp = &bpparser.Property{
Name: bpparser.Ident{Name: suffix, Pos: pos},
Pos: pos,
Value: bpparser.Value{
Type: bpparser.Map,
MapValue: []*bpparser.Property{},
},
}
file.localAssignments[class+"___"+suffix] = suffixProp
classProp.Value.MapValue = append(classProp.Value.MapValue, suffixProp)
}
prop := &bpparser.Property{
Name: bpparser.Ident{Name: name, Pos: pos},
Pos: pos,
Value: *value,
}
file.localAssignments[class+"___"+suffix+"___"+name] = prop
suffixProp.Value.MapValue = append(suffixProp.Value.MapValue, prop)
} }
} else { } else {
if oldValue != nil && plusequals { if oldValue != nil && plusequals {