Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f2ede7a1 authored by Yifan Hong's avatar Yifan Hong
Browse files

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
parent 4f35976c
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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")