Merge "Fix CMakeList generator CFlag bug"
am: 1d83bc7866
Change-Id: I68e9011ae41464d26fa8d228df64032b6f47236a
This commit is contained in:
@@ -290,7 +290,9 @@ func parseCompilerParameters(params []string, ctx blueprint.SingletonContext, f
|
|||||||
}
|
}
|
||||||
i = i + 1
|
i = i + 1
|
||||||
case flag:
|
case flag:
|
||||||
compilerParameters.flags = append(compilerParameters.flags, param)
|
c := cleanupParameter(param)
|
||||||
|
f.WriteString(fmt.Sprintf("# FLAG '%s' became %s\n", param, c))
|
||||||
|
compilerParameters.flags = append(compilerParameters.flags, c)
|
||||||
case systemRoot:
|
case systemRoot:
|
||||||
if i < len(params)-1 {
|
if i < len(params)-1 {
|
||||||
compilerParameters.sysroot = params[i+1]
|
compilerParameters.sysroot = params[i+1]
|
||||||
@@ -303,6 +305,43 @@ func parseCompilerParameters(params []string, ctx blueprint.SingletonContext, f
|
|||||||
return compilerParameters
|
return compilerParameters
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cleanupParameter(p string) string {
|
||||||
|
// In the blueprint, c flags can be passed as:
|
||||||
|
// cflags: [ "-DLOG_TAG=\"libEGL\"", ]
|
||||||
|
// which becomes:
|
||||||
|
// '-DLOG_TAG="libEGL"' in soong.
|
||||||
|
// In order to be injected in CMakelists.txt we need to:
|
||||||
|
// - Remove the wrapping ' character
|
||||||
|
// - Double escape all special \ and " characters.
|
||||||
|
// For a end result like:
|
||||||
|
// -DLOG_TAG=\\\"libEGL\\\"
|
||||||
|
if !strings.HasPrefix(p, "'") || !strings.HasSuffix(p, "'") || len(p) < 3 {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reverse wrapper quotes and escaping that may have happened in NinjaAndShellEscape
|
||||||
|
// TODO: It is ok to reverse here for now but if NinjaAndShellEscape becomes more complex,
|
||||||
|
// we should create a method NinjaAndShellUnescape in escape.go and use that instead.
|
||||||
|
p = p[1 : len(p)-1]
|
||||||
|
p = strings.Replace(p, `'\''`, `'`, -1)
|
||||||
|
p = strings.Replace(p, `$$`, `$`, -1)
|
||||||
|
|
||||||
|
p = doubleEscape(p)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func escape(s string) string {
|
||||||
|
s = strings.Replace(s, `\`, `\\`, -1)
|
||||||
|
s = strings.Replace(s, `"`, `\"`, -1)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func doubleEscape(s string) string {
|
||||||
|
s = escape(s)
|
||||||
|
s = escape(s)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
func concatenateParams(c1 *compilerParameters, c2 compilerParameters) {
|
func concatenateParams(c1 *compilerParameters, c2 compilerParameters) {
|
||||||
concatenateMaps(c1.headerSearchPath, c2.headerSearchPath)
|
concatenateMaps(c1.headerSearchPath, c2.headerSearchPath)
|
||||||
concatenateMaps(c1.systemHeaderSearchPath, c2.systemHeaderSearchPath)
|
concatenateMaps(c1.systemHeaderSearchPath, c2.systemHeaderSearchPath)
|
||||||
|
Reference in New Issue
Block a user