From 0c236aba6e8b45ac0fde3c7db627f366e3caeaee Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Fri, 3 Jun 2016 12:54:51 -0700 Subject: [PATCH] androidmk: Update LOCAL_SANITIZE* support Change-Id: Ib3d5473869f69e9e3a74ebb403653e5918ad240a --- androidmk/cmd/androidmk/android.go | 60 +++++++++++++++++++++++++++- androidmk/cmd/androidmk/test.go | 64 ++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 2 deletions(-) diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go index d26808b62..eb89f19f3 100644 --- a/androidmk/cmd/androidmk/android.go +++ b/androidmk/cmd/androidmk/android.go @@ -48,8 +48,7 @@ var standardProperties = map[string]struct { "LOCAL_LDLIBS": {"host_ldlibs", bpparser.List}, "LOCAL_CLANG_CFLAGS": {"clang_cflags", bpparser.List}, "LOCAL_YACCFLAGS": {"yaccflags", bpparser.List}, - "LOCAL_SANITIZE": {"sanitize", bpparser.List}, - "LOCAL_SANITIZE_RECOVER": {"sanitize_recover", bpparser.List}, + "LOCAL_SANITIZE_RECOVER": {"sanitize.recover", bpparser.List}, "LOCAL_LOGTAGS_FILES": {"logtags", bpparser.List}, "LOCAL_JAVA_RESOURCE_DIRS": {"java_resource_dirs", bpparser.List}, @@ -83,6 +82,7 @@ var rewriteProperties = map[string]struct { "LOCAL_MODULE_STEM": {stem}, "LOCAL_MODULE_HOST_OS": {hostOs}, "LOCAL_SRC_FILES": {srcFiles}, + "LOCAL_SANITIZE": {sanitize}, } type listSplitFunc func(bpparser.Value) (string, *bpparser.Value, error) @@ -366,6 +366,62 @@ func srcFiles(file *bpFile, prefix string, value *mkparser.MakeString, appendVar return nil } +func sanitize(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) { + if value.Variable != "" { + return "vars", &value, nil + } + + if value.Expression != nil { + file.errorf(mkvalue, "unknown sanitize expression") + return "unknown", &value, nil + } + + switch value.StringValue { + case "never", "address", "coverage", "integer", "thread", "undefined": + bpTrue := bpparser.Value{ + Type: bpparser.Bool, + BoolValue: true, + } + return value.StringValue, &bpTrue, nil + default: + file.errorf(mkvalue, "unknown sanitize argument: %s", value.StringValue) + return "unknown", &value, nil + } + }) + if err != nil { + return err + } + + for k, v := range lists { + if emptyList(v) { + continue + } + + switch k { + case "never", "address", "coverage", "integer", "thread", "undefined": + err = setVariable(file, false, prefix, "sanitize."+k, &lists[k].ListValue[0], true) + case "unknown": + // Nothing, we already added the error above + case "vars": + fallthrough + default: + err = setVariable(file, true, prefix, "sanitize", v, true) + } + + if err != nil { + return err + } + } + + return err +} + var deleteProperties = map[string]struct{}{ "LOCAL_CPP_EXTENSION": struct{}{}, } diff --git a/androidmk/cmd/androidmk/test.go b/androidmk/cmd/androidmk/test.go index 965da2bf5..579578e50 100644 --- a/androidmk/cmd/androidmk/test.go +++ b/androidmk/cmd/androidmk/test.go @@ -265,6 +265,70 @@ cc_library_shared { }, }, } +`, + }, + { + desc: "LOCAL_SANITIZE := never", + in: ` +include $(CLEAR_VARS) +LOCAL_SANITIZE := never +include $(BUILD_SHARED_LIBRARY) +`, + expected: ` +cc_library_shared { + sanitize: { + never: true, + }, +} +`, + }, + { + desc: "LOCAL_SANITIZE unknown parameter", + in: ` +include $(CLEAR_VARS) +LOCAL_SANITIZE := integer asdf +LOCAL_SANITIZE_RECOVER := qwert +include $(BUILD_SHARED_LIBRARY) +`, + expected: ` +cc_library_shared { + // ANDROIDMK TRANSLATION ERROR: unknown sanitize argument: asdf + // integer asdf + sanitize: { + integer: true, + recover: ["qwert"], + }, +} +`, + }, + { + desc: "LOCAL_SANITIZE using variable", + in: ` +sanitize_var := never +include $(CLEAR_VARS) +LOCAL_SANITIZE := $(sanitize_var) +include $(BUILD_SHARED_LIBRARY) +`, + expected: ` +sanitize_var = ["never"] +cc_library_shared { + sanitize: sanitize_var, +} +`, + }, + { + desc: "LOCAL_SANITIZE_RECOVER", + in: ` +include $(CLEAR_VARS) +LOCAL_SANITIZE_RECOVER := shift-exponent +include $(BUILD_SHARED_LIBRARY) +`, + expected: ` +cc_library_shared { + sanitize: { + recover: ["shift-exponent"], + }, +} `, }, }