aboutsummaryrefslogtreecommitdiffstats
path: root/androidmk
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2015-05-08 15:37:50 -0700
committerColin Cross <ccross@android.com>2015-05-12 11:38:37 -0700
commita93000350a17db52c8aadba4fe442ce834722559 (patch)
tree18898121f0a1aaffd67b71f9d0b902b6d67dbed9 /androidmk
parentf22982707d9d94b56263b0a98ddb9efbef762364 (diff)
downloadbuild_soong-a93000350a17db52c8aadba4fe442ce834722559.tar.gz
build_soong-a93000350a17db52c8aadba4fe442ce834722559.tar.bz2
build_soong-a93000350a17db52c8aadba4fe442ce834722559.zip
androidmk: strip LOCAL_PATH from export_include_dirs and local_include_dirs
Sort LOCAL_INCLUDE_DIRS values into local_include_dir include_dirs based on whether they are prefixed with $(LOCAL_PATH)/, and strip $(LOCAL_PATH)/ from export_include_dirs. Change-Id: I20f9f0f8385088660855c7ccf85b7933ff2dcd44
Diffstat (limited to 'androidmk')
-rw-r--r--androidmk/cmd/androidmk/android.go181
-rw-r--r--androidmk/cmd/androidmk/androidmk.go78
2 files changed, 227 insertions, 32 deletions
diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go
index f693f5de..69481cfb 100644
--- a/androidmk/cmd/androidmk/android.go
+++ b/androidmk/cmd/androidmk/android.go
@@ -38,8 +38,6 @@ var standardProperties = map[string]struct {
"LOCAL_STATIC_LIBRARIES": {"static_libs", bpparser.List},
"LOCAL_WHOLE_STATIC_LIBRARIES": {"whole_static_libs", bpparser.List},
"LOCAL_SYSTEM_SHARED_LIBRARIES": {"system_shared_libs", bpparser.List},
- "LOCAL_C_INCLUDES": {"include_dirs", bpparser.List},
- "LOCAL_EXPORT_C_INCLUDE_DIRS": {"export_include_dirs", bpparser.List},
"LOCAL_ASFLAGS": {"asflags", bpparser.List},
"LOCAL_CLANG_ASFLAGS": {"clang_asflags", bpparser.List},
"LOCAL_CFLAGS": {"cflags", bpparser.List},
@@ -76,6 +74,185 @@ var standardProperties = map[string]struct {
"LOCAL_EXPORT_PACKAGE_RESOURCES": {"export_package_resources", bpparser.Bool},
}
+var rewriteProperties = map[string]struct {
+ f func(file *bpFile, value *mkparser.MakeString, append bool, class, suffix string) error
+}{
+ "LOCAL_C_INCLUDES": {localIncludeDirs},
+ "LOCAL_EXPORT_C_INCLUDE_DIRS": {exportIncludeDirs},
+}
+
+func localAbsPath(value bpparser.Value) (*bpparser.Value, error) {
+ if value.Type != bpparser.String {
+ return nil, fmt.Errorf("isLocalAbsPath expected a string, got %d", value.Type)
+ }
+
+ if value.Expression == nil {
+ if value.Variable == "LOCAL_PATH" {
+ return &bpparser.Value{
+ Type: bpparser.String,
+ StringValue: ".",
+ }, nil
+ }
+ return nil, nil
+ }
+
+ if value.Expression.Operator != '+' {
+ return nil, nil
+ }
+
+ firstOperand := value.Expression.Args[0]
+ secondOperand := value.Expression.Args[1]
+ if firstOperand.Type != bpparser.String {
+ return nil, nil
+ }
+
+ if firstOperand.Expression != nil {
+ return nil, nil
+ }
+
+ if firstOperand.Variable != "LOCAL_PATH" {
+ return nil, nil
+ }
+
+ if secondOperand.Expression == nil && secondOperand.Variable == "" {
+ if strings.HasPrefix(secondOperand.StringValue, "/") {
+ secondOperand.StringValue = secondOperand.StringValue[1:]
+ }
+ }
+ return &secondOperand, nil
+}
+
+func emptyList(value *bpparser.Value) bool {
+ return value.Type == bpparser.List && value.Expression == nil && value.Variable == "" &&
+ len(value.ListValue) == 0
+}
+
+func splitLocalGlobal(file *bpFile, val *bpparser.Value) (local, global *bpparser.Value, err error) {
+ local = &bpparser.Value{
+ Type: bpparser.List,
+ }
+ global = &bpparser.Value{
+ Type: bpparser.List,
+ }
+
+ if val.Expression != nil {
+ localA, globalA, err := splitLocalGlobal(file, &val.Expression.Args[0])
+ if err != nil {
+ return nil, nil, err
+ }
+
+ localB, globalB, err := splitLocalGlobal(file, &val.Expression.Args[1])
+ if err != nil {
+ return nil, nil, err
+ }
+
+ if emptyList(localA) {
+ local = localB
+ } else if emptyList(localB) {
+ local = localA
+ } else {
+ localExpression := *val.Expression
+ local.Expression = &localExpression
+ local.Expression.Args = [2]bpparser.Value{*localA, *localB}
+ }
+
+ if emptyList(globalA) {
+ global = globalB
+ } else if emptyList(globalB) {
+ global = globalA
+ } else {
+ globalExpression := *val.Expression
+ global.Expression = &globalExpression
+ global.Expression.Args = [2]bpparser.Value{*globalA, *globalB}
+ }
+ } else if val.Variable != "" {
+ if val.Variable == "LOCAL_PATH" {
+ local.ListValue = append(local.ListValue, bpparser.Value{
+ Type: bpparser.String,
+ StringValue: ".",
+ })
+ } else {
+ global.Variable = val.Variable
+ }
+ } else {
+ for _, v := range val.ListValue {
+ localPath, err := localAbsPath(v)
+ if err != nil {
+ return nil, nil, err
+ }
+ if localPath != nil {
+ local.ListValue = append(local.ListValue, *localPath)
+ } else {
+ global.ListValue = append(global.ListValue, v)
+ }
+ }
+ }
+
+ return local, global, nil
+}
+
+func localIncludeDirs(file *bpFile, value *mkparser.MakeString, appendVariable bool,
+ class, suffix string) error {
+ val, err := makeVariableToBlueprint(file, value, bpparser.List)
+ if err != nil {
+ return err
+ }
+
+ local, global, err := splitLocalGlobal(file, val)
+ if err != nil {
+ return err
+ }
+
+ if len(global.ListValue) > 0 || global.Expression != nil || global.Variable != "" {
+ err = setVariable(file, appendVariable, "include_dirs", global, true, class, suffix)
+ if err != nil {
+ return err
+ }
+ }
+
+ if len(local.ListValue) > 0 || local.Expression != nil || local.Variable != "" {
+ err = setVariable(file, appendVariable, "local_include_dirs", local, true, class, suffix)
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+func exportIncludeDirs(file *bpFile, value *mkparser.MakeString, appendVariable bool,
+ class, suffix string) error {
+
+ val, err := makeVariableToBlueprint(file, value, bpparser.List)
+ if err != nil {
+ return err
+ }
+
+ local, global, err := splitLocalGlobal(file, val)
+ if err != nil {
+ return err
+ }
+
+ if len(local.ListValue) > 0 || local.Expression != nil || local.Variable != "" {
+ err = setVariable(file, appendVariable, "export_include_dirs", local, true, class, suffix)
+ if err != nil {
+ return err
+ }
+ appendVariable = true
+ }
+
+ // 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.
+ if len(global.ListValue) > 0 || global.Expression != nil || global.Variable != "" {
+ err = setVariable(file, appendVariable, "export_include_dirs", global, true, class, suffix)
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
var deleteProperties = map[string]struct{}{
"LOCAL_CPP_EXTENSION": struct{}{},
}
diff --git a/androidmk/cmd/androidmk/androidmk.go b/androidmk/cmd/androidmk/androidmk.go
index 294f32e1..b818230c 100644
--- a/androidmk/cmd/androidmk/androidmk.go
+++ b/androidmk/cmd/androidmk/androidmk.go
@@ -230,9 +230,17 @@ func handleAssignment(file *bpFile, assignment mkparser.Assignment, c *condition
}
}
+ appendVariable := assignment.Type == "+="
+
var err error
if prop, ok := standardProperties[name]; ok {
- err = setVariable(file, assignment.Value, assignment.Type == "+=", prop.string, prop.ValueType, true, class, suffix)
+ var val *bpparser.Value
+ val, err = makeVariableToBlueprint(file, assignment.Value, prop.ValueType)
+ if err == nil {
+ err = setVariable(file, appendVariable, prop.string, val, true, class, suffix)
+ }
+ } else if prop, ok := rewriteProperties[name]; ok {
+ err = prop.f(file, assignment.Value, appendVariable, class, suffix)
} else if _, ok := deleteProperties[name]; ok {
return
} else {
@@ -251,7 +259,9 @@ func handleAssignment(file *bpFile, assignment mkparser.Assignment, c *condition
file.errorf(assignment, "unsupported assignment to %s", name)
return
default:
- err = setVariable(file, assignment.Value, assignment.Type == "+=", name, bpparser.List, false, class, suffix)
+ var val *bpparser.Value
+ val, err = makeVariableToBlueprint(file, assignment.Value, bpparser.List)
+ err = setVariable(file, appendVariable, name, val, false, class, suffix)
}
}
if err != nil {
@@ -287,8 +297,10 @@ func handleModuleConditionals(file *bpFile, directive mkparser.Directive, c *con
}
// Create a fake assignment with enabled = false
- err := setVariable(file, mkparser.SimpleMakeString("true", file.pos), false,
- "disabled", bpparser.Bool, true, class, disabledSuffix)
+ val, err := makeVariableToBlueprint(file, mkparser.SimpleMakeString("true", file.pos), bpparser.Bool)
+ if err == nil {
+ err = setVariable(file, false, "disabled", val, true, class, disabledSuffix)
+ }
if err != nil {
file.errorf(directive, err.Error())
}
@@ -312,8 +324,31 @@ func resetModule(file *bpFile) {
file.localAssignments = make(map[string]*bpparser.Property)
}
-func setVariable(file *bpFile, val *mkparser.MakeString, plusequals bool, name string,
- typ bpparser.ValueType, local bool, class string, suffix string) error {
+func makeVariableToBlueprint(file *bpFile, val *mkparser.MakeString,
+ typ bpparser.ValueType) (*bpparser.Value, error) {
+
+ var exp *bpparser.Value
+ var err error
+ switch typ {
+ case bpparser.List:
+ exp, err = makeToListExpression(val, file.scope)
+ case bpparser.String:
+ exp, err = makeToStringExpression(val, file.scope)
+ case bpparser.Bool:
+ exp, err = makeToBoolExpression(val)
+ default:
+ panic("unknown type")
+ }
+
+ if err != nil {
+ return nil, err
+ }
+
+ return exp, nil
+}
+
+func setVariable(file *bpFile, plusequals bool, name string, value *bpparser.Value, local bool,
+ class string, suffix string) error {
pos := file.pos
@@ -332,26 +367,9 @@ func setVariable(file *bpFile, val *mkparser.MakeString, plusequals bool, name s
oldValue = file.globalAssignments[name]
}
- var exp *bpparser.Value
- var err error
- switch typ {
- case bpparser.List:
- exp, err = makeToListExpression(val, file.scope)
- case bpparser.String:
- exp, err = makeToStringExpression(val, file.scope)
- case bpparser.Bool:
- exp, err = makeToBoolExpression(val)
- default:
- panic("unknown type")
- }
-
- if err != nil {
- return err
- }
-
if local {
if oldValue != nil && plusequals {
- val, err := addValues(oldValue, exp)
+ val, err := addValues(oldValue, value)
if err != nil {
return fmt.Errorf("unsupported addition: %s", err.Error())
}
@@ -361,7 +379,7 @@ func setVariable(file *bpFile, val *mkparser.MakeString, plusequals bool, name s
prop := &bpparser.Property{
Name: bpparser.Ident{Name: name, Pos: pos},
Pos: pos,
- Value: *exp,
+ Value: *value,
}
file.localAssignments[name] = prop
file.module.Properties = append(file.module.Properties, prop)
@@ -397,7 +415,7 @@ func setVariable(file *bpFile, val *mkparser.MakeString, plusequals bool, name s
prop := &bpparser.Property{
Name: bpparser.Ident{Name: name, Pos: pos},
Pos: pos,
- Value: *exp,
+ Value: *value,
}
file.localAssignments[class+"___"+suffix+"___"+name] = prop
suffixProp.Value.MapValue = append(suffixProp.Value.MapValue, prop)
@@ -409,8 +427,8 @@ func setVariable(file *bpFile, val *mkparser.MakeString, plusequals bool, name s
Name: name,
Pos: pos,
},
- Value: *exp,
- OrigValue: *exp,
+ Value: *value,
+ OrigValue: *value,
Pos: pos,
Assigner: "+=",
}
@@ -421,8 +439,8 @@ func setVariable(file *bpFile, val *mkparser.MakeString, plusequals bool, name s
Name: name,
Pos: pos,
},
- Value: *exp,
- OrigValue: *exp,
+ Value: *value,
+ OrigValue: *value,
Pos: pos,
Assigner: "=",
}