From f2ede7a13792af1fbe932f9bcdd6a5a057c8f17f Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Wed, 9 Sep 2020 18:48:40 -0700 Subject: [PATCH] Sanitize APEX module name properly. An APEX module name, unlike the APEX package name, can contain characters like '-', which are not allowed as C define strings. Sanitize it properly. Test: build GKI APEX Change-Id: I8257d43c55862da8fab7f1e342c2d14369d1211e --- cc/compiler.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cc/compiler.go b/cc/compiler.go index f504c38a2..c268dec2b 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -573,10 +573,12 @@ func (compiler *baseCompiler) uniqueApexVariations() bool { return compiler.useApexNameMacro() } +var invalidDefineCharRegex = regexp.MustCompile("[^a-zA-Z0-9_]") + // makeDefineString transforms a name of an APEX module into a value to be used as value for C define // For example, com.android.foo => COM_ANDROID_FOO func makeDefineString(name string) string { - return strings.ReplaceAll(strings.ToUpper(name), ".", "_") + return invalidDefineCharRegex.ReplaceAllString(strings.ToUpper(name), "_") } var gnuToCReplacer = strings.NewReplacer("gnu", "c")