diff options
| author | ruki <[email protected]> | 2017-07-19 15:27:58 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-07-19 15:27:58 +0800 |
| commit | 03509bb551e7b5491a8ed08f9fc7241d39beb215 (patch) | |
| tree | 9a4c478654f808ec9c02639874850f93af6719fe /xmake/plugins | |
| parent | 9b9f7b171ad00c963213e6a985652ea05af8ad93 (diff) | |
fix arguments escape for compile_commands
Diffstat (limited to 'xmake/plugins')
| -rw-r--r-- | xmake/plugins/project/clang/compile_commands.lua | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua index 446f51279..39640ae48 100644 --- a/xmake/plugins/project/clang/compile_commands.lua +++ b/xmake/plugins/project/clang/compile_commands.lua @@ -41,13 +41,19 @@ function _make_object(jsonfile, target, sourcefile, objectfile) -- get compile arguments local arguments = table.join(compiler.compargv(sourcefile, objectfile, {target = target, sourcekind = sourcekind})) + -- escape '"', '\' + local arguments_escape = {} + for _, arg in ipairs(arguments) do + table.insert(arguments_escape, (arg:gsub("[\"\\]", "\\%1"))) + end + -- make body jsonfile:printf( [[%s{ "directory": "%s", "arguments": ["%s"], "file": "%s" -}]], ifelse(_g.firstline, "", ",\n"), os.projectdir(), table.concat(arguments, "\", \""), sourcefile) +}]], ifelse(_g.firstline, "", ",\n"), os.projectdir(), table.concat(arguments_escape, "\", \""), sourcefile) -- clear first line marks _g.firstline = false |
