summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-02-20 00:46:00 +0800
committerruki <[email protected]>2021-02-20 00:46:00 +0800
commit9dec8733c04c91f1dd145b5ff4455db6e940e140 (patch)
tree64900ce3f660d043dad3a8bb3d5642c40f481da9
parent514905243e16f94e472390a7d211e7bca70ddb71 (diff)
improve compile_commands
-rw-r--r--xmake/plugins/project/clang/compile_commands.lua19
1 files changed, 17 insertions, 2 deletions
diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua
index 7a4a5e8d5..48cd0ed96 100644
--- a/xmake/plugins/project/clang/compile_commands.lua
+++ b/xmake/plugins/project/clang/compile_commands.lua
@@ -22,6 +22,7 @@
import("core.tool.compiler")
import("core.project.rule")
import("core.project.project")
+import("core.language.language")
-- escape path
function _escape_path(p)
@@ -50,6 +51,20 @@ end
-- make command
function _make_arguments(jsonfile, arguments, sourcefile)
+ -- attempt to get source file from arguments
+ if not sourcefile then
+ for _, arg in ipairs(arguments) do
+ local sourcekind = try {function () return language.sourcekind_of(path.filename(arg)) end}
+ if sourcekind and os.isfile(arg) then
+ sourcefile = arg
+ break
+ end
+ end
+ if not sourcefile then
+ return
+ end
+ end
+
-- translate some unsupported arguments
arguments = _translate_arguments(arguments)
@@ -84,7 +99,7 @@ function _make_commands_for_objectrules(jsonfile, target, sourcebatch, suffix)
if script then
local cmds = script(target, sourcebatch)
for _, cmd in ipairs(cmds) do
- _make_arguments(jsonfile, cmd, "")
+ _make_arguments(jsonfile, cmd)
end
end
@@ -97,7 +112,7 @@ function _make_commands_for_objectrules(jsonfile, target, sourcebatch, suffix)
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
local cmds = script(target, sourcefile)
for _, cmd in ipairs(cmds) do
- _make_arguments(jsonfile, cmd, sourcefile)
+ _make_arguments(jsonfile, cmd)
end
end
end