androidmk: Support version_script

This only translates the common case using $(LOCAL_PATH). If it doesn't
match here, Soong will throw an error with a suggested fix.

Change-Id: If64c8fca008a1a414fc12389e6b1bb40af0df899
This commit is contained in:
Dan Willemsen 2016-06-03 13:54:46 -07:00
parent 0c236aba6e
commit 58f9bb1160
3 changed files with 67 additions and 1 deletions

View File

@ -42,7 +42,6 @@ var standardProperties = map[string]struct {
"LOCAL_CFLAGS": {"cflags", bpparser.List},
"LOCAL_CONLYFLAGS": {"conlyflags", bpparser.List},
"LOCAL_CPPFLAGS": {"cppflags", bpparser.List},
"LOCAL_LDFLAGS": {"ldflags", bpparser.List},
"LOCAL_REQUIRED_MODULES": {"required", bpparser.List},
"LOCAL_MODULE_TAGS": {"tags", bpparser.List},
"LOCAL_LDLIBS": {"host_ldlibs", bpparser.List},
@ -83,6 +82,7 @@ var rewriteProperties = map[string]struct {
"LOCAL_MODULE_HOST_OS": {hostOs},
"LOCAL_SRC_FILES": {srcFiles},
"LOCAL_SANITIZE": {sanitize},
"LOCAL_LDFLAGS": {ldflags},
}
type listSplitFunc func(bpparser.Value) (string, *bpparser.Value, error)
@ -422,6 +422,56 @@ func sanitize(file *bpFile, prefix string, mkvalue *mkparser.MakeString, appendV
return err
}
func ldflags(file *bpFile, prefix string, mkvalue *mkparser.MakeString, appendVariable bool) error {
val, err := makeVariableToBlueprint(file, mkvalue, bpparser.List)
if err != nil {
return err
}
lists, err := splitBpList(val, func(value bpparser.Value) (string, *bpparser.Value, error) {
// Anything other than "-Wl,--version_script," + LOCAL_PATH + "<path>" matches ldflags
if value.Variable != "" || value.Expression == nil {
return "ldflags", &value, nil
}
exp := value.Expression.Args[0]
if exp.Variable != "" || exp.Expression == nil || exp.Expression.Args[0].StringValue != "-Wl,--version-script," {
return "ldflags", &value, nil
}
if exp.Expression.Args[1].Variable != "LOCAL_PATH" {
file.errorf(mkvalue, "Unrecognized version-script")
return "ldflags", &value, nil
}
value.Expression.Args[1].StringValue = strings.TrimPrefix(value.Expression.Args[1].StringValue, "/")
return "version", &value.Expression.Args[1], nil
})
if err != nil {
return err
}
if ldflags, ok := lists["ldflags"]; ok && !emptyList(ldflags) {
err = setVariable(file, appendVariable, prefix, "ldflags", ldflags, true)
if err != nil {
return err
}
}
if version_script, ok := lists["version"]; ok && !emptyList(version_script) {
if len(version_script.ListValue) > 1 {
file.errorf(mkvalue, "multiple version scripts found?")
}
err = setVariable(file, false, prefix, "version_script", &version_script.ListValue[0], true)
if err != nil {
return err
}
}
return nil
}
var deleteProperties = map[string]struct{}{
"LOCAL_CPP_EXTENSION": struct{}{},
}

View File

@ -329,6 +329,20 @@ cc_library_shared {
recover: ["shift-exponent"],
},
}
`,
},
{
desc: "version_script in LOCAL_LDFLAGS",
in: `
include $(CLEAR_VARS)
LOCAL_LDFLAGS := -Wl,--link-opt -Wl,--version-script,$(LOCAL_PATH)/exported32.map
include $(BUILD_SHARED_LIBRARY)
`,
expected: `
cc_library_shared {
ldflags: ["-Wl,--link-opt"],
version_script: "exported32.map",
}
`,
},
}

View File

@ -69,6 +69,8 @@ func CheckBadLinkerFlags(ctx ModuleContext, prop string, flags []string) {
}
} else if strings.HasPrefix(flag, "-L") {
ctx.PropertyErrorf(prop, "Bad flag: `%s` is not allowed", flag)
} else if strings.HasPrefix(flag, "-Wl,--version-script") {
ctx.PropertyErrorf(prop, "Bad flag: `%s`, use version_script instead", flag)
} else if strings.Contains(flag, " ") {
ctx.PropertyErrorf(prop, "Bad flag: `%s` is not an allowed multi-word flag. Should it be split into multiple flags?", flag)
}