diff options
| author | ruki <[email protected]> | 2023-01-21 22:32:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-01-21 22:32:02 +0800 |
| commit | eb42f01b0cb0ad0db3af1f154905156c390cd433 (patch) | |
| tree | 589fb08cfc2c78d309f989da00ada141f5e5a014 | |
| parent | 88fdf3aa54af364d7bb7f01e82a7cc1046d30411 (diff) | |
improve compile_commands #3286
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | xmake/plugins/project/clang/compile_commands.lua | 40 |
2 files changed, 35 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a7b60e1f..84c945a0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ * [#3229](https://github.com/xmake-io/xmake/issues/3229): Fix find rc.exe for vs2015 * [#3271](https://github.com/xmake-io/xmake/issues/3271): Fix macro defines with spaces * [#3273](https://github.com/xmake-io/xmake/issues/3273): Fix nim link error +* [#3286](https://github.com/xmake-io/xmake/issues/3286): Fix compile_commands for clangd ## v2.7.5 @@ -1524,6 +1525,7 @@ * [#3229](https://github.com/xmake-io/xmake/issues/3229): 修复 vs2015 下找不到 rc.exe 问题 * [#3271](https://github.com/xmake-io/xmake/issues/3271): 修复支持带有空格的宏定义 * [#3273](https://github.com/xmake-io/xmake/issues/3273): 修复 nim 链接错误 +* [#3286](https://github.com/xmake-io/xmake/issues/3286): 修复 compile_commands 对 clangd 的支持 ## v2.7.5 diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua index f6cd3bac4..e82bfb4f7 100644 --- a/xmake/plugins/project/clang/compile_commands.lua +++ b/xmake/plugins/project/clang/compile_commands.lua @@ -42,13 +42,23 @@ function _sourcebatch_is_built(sourcebatch) end end +-- get LSP, clangd, ccls, ... +function _get_lsp() + local lsp = option.get("lsp") + if lsp == nil then + lsp = os.getenv("XMAKE_GENERATOR_COMPDB_LSP") + end + return lsp +end + -- translate external/system include flags, because some tools (vscode) do not support them yet. -- https://github.com/xmake-io/xmake/issues/1050 function _translate_arguments(arguments) local args = {} local cc = path.basename(arguments[1]):lower() local is_include = false - local lsp = option.get("lsp") + local lsp = _get_lsp() + local program_map = {} for idx, arg in ipairs(arguments) do -- convert path to string, maybe we need convert path, but not supported now. arg = tostring(arg) @@ -94,13 +104,28 @@ function _translate_arguments(arguments) is_include = true end if arg then - -- split "/usr/bin/xcrun -sdk macosx clang" - -- @see https://github.com/xmake-io/xmake/issues/3159 - if idx == 1 and not os.isfile(arg) and arg:find(" ", 1, true) then - table.join2(args, os.argv(arg)) - else - table.insert(args, arg) + -- improve to support for "/usr/bin/xcrun -sdk macosx clang" + -- @see + -- https://github.com/xmake-io/xmake/issues/3159 + -- https://github.com/xmake-io/xmake/issues/3286 + if idx == 1 and is_host("macosx") and arg:find("xcrun -sdk", 1, true) then + local cmd = program_map[arg] + if cmd == nil then + cmd = arg:gsub("xcrun %-sdk (%S+) (%S+)", function (plat, cc) + return "xcrun -sdk " .. plat .. " -f " .. cc + end) + local splitinfo = cmd:split("%s") + local binpath = try {function() return os.iorunv(splitinfo[1], table.slice(splitinfo, 2) or {}) end} + if binpath then + binpath = binpath:trim() + if #binpath > 0 then + arg = binpath + end + end + program_map[arg] = cmd + end end + table.insert(args, arg) end end return args @@ -257,6 +282,7 @@ function _make_target(jsonfile, target) local oldenvs = os.addenvs(target:pkgenvs()) -- we enable it for clangd, @see https://github.com/xmake-io/xmake/issues/2818 + local lsp = _get_lsp() if not lsp or lsp ~= "clangd" then target:set("pcheader", nil) target:set("pcxxheader", nil) |
