diff options
author | Fabien Sanglard <sanglardf@google.com> | 2017-02-06 09:49:58 -0800 |
---|---|---|
committer | Fabien Sanglard <sanglardf@google.com> | 2017-02-07 09:43:02 -0800 |
commit | 5cb35194c2a6d0e6417776c6dd41597185f74e02 (patch) | |
tree | e35fd043ad35f4a035d1ba92302b82c1ff244633 /cc | |
parent | d61f1f455917ed6affe9361c0f89ddfcbfa50d02 (diff) | |
download | build_soong-5cb35194c2a6d0e6417776c6dd41597185f74e02.tar.gz build_soong-5cb35194c2a6d0e6417776c6dd41597185f74e02.tar.bz2 build_soong-5cb35194c2a6d0e6417776c6dd41597185f74e02.zip |
Fix CMakeList generator CFlag bug
Properly process CFlags featuring quotes and double quotes.
Test: on libui and libgui
Change-Id: I8581cef9ccc595b6e05d77bee7bea82f2efd219b
Diffstat (limited to 'cc')
-rw-r--r-- | cc/cmakelists.go | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/cc/cmakelists.go b/cc/cmakelists.go index f8273cf1..1c47ec98 100644 --- a/cc/cmakelists.go +++ b/cc/cmakelists.go @@ -290,7 +290,9 @@ func parseCompilerParameters(params []string, ctx blueprint.SingletonContext, f } i = i + 1 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: if i < len(params)-1 { compilerParameters.sysroot = params[i+1] @@ -303,6 +305,43 @@ func parseCompilerParameters(params []string, ctx blueprint.SingletonContext, f 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) { concatenateMaps(c1.headerSearchPath, c2.headerSearchPath) concatenateMaps(c1.systemHeaderSearchPath, c2.systemHeaderSearchPath) |