From 58f9bb1160074f06e2cea66f78dfdf4d42834c59 Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Fri, 3 Jun 2016 13:54:46 -0700 Subject: [PATCH] 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 --- androidmk/cmd/androidmk/android.go | 52 +++++++++++++++++++++++++++++- androidmk/cmd/androidmk/test.go | 14 ++++++++ cc/check.go | 2 ++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go index eb89f19f3..d4802744a 100644 --- a/androidmk/cmd/androidmk/android.go +++ b/androidmk/cmd/androidmk/android.go @@ -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 + "" 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{}{}, } diff --git a/androidmk/cmd/androidmk/test.go b/androidmk/cmd/androidmk/test.go index 579578e50..b3ce5d028 100644 --- a/androidmk/cmd/androidmk/test.go +++ b/androidmk/cmd/androidmk/test.go @@ -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", +} `, }, } diff --git a/cc/check.go b/cc/check.go index e6a803612..38a64a07b 100644 --- a/cc/check.go +++ b/cc/check.go @@ -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) }