summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-08-13 09:53:43 +0800
committerGitHub <[email protected]>2024-08-13 09:53:43 +0800
commitddb86e44c1e4849fee6e2a4d72dc8ee47350aaa0 (patch)
treeef828878e0f463d6639d98ced7edb67e8defbf51
parentaf3090adbb8e46ee8e3d62417e9a6dc9b06f068c (diff)
parent90846dd50abc804a82787e24a079eb15eac12908 (diff)
Merge pull request #5460 from 24bit-xjkp/dev
fix(plugin/project): Generate compile_commands for tests
-rw-r--r--xmake/actions/test/main.lua35
-rw-r--r--xmake/plugins/project/clang/compile_commands.lua9
2 files changed, 29 insertions, 15 deletions
diff --git a/xmake/actions/test/main.lua b/xmake/actions/test/main.lua
index f8314ce69..c1bb156dd 100644
--- a/xmake/actions/test/main.lua
+++ b/xmake/actions/test/main.lua
@@ -366,20 +366,8 @@ function _try_build_target(targetname)
return passed, errors
end
-function main()
-
- -- do action for remote?
- if remote_build_action.enabled() then
- return remote_build_action()
- end
-
- -- lock the whole project
- project.lock()
-
- -- load config first
- task.run("config", {}, {disable_dump = true})
-
- -- get tests
+-- get tests, export this for the `project` plugin
+function get_tests()
local tests = {}
local group_pattern = option.get("group")
if group_pattern then
@@ -440,6 +428,24 @@ function main()
end
end
end
+ return tests
+end
+
+function main()
+
+ -- do action for remote?
+ if remote_build_action.enabled() then
+ return remote_build_action()
+ end
+
+ -- lock the whole project
+ project.lock()
+
+ -- load config first
+ task.run("config", {}, {disable_dump = true})
+
+ -- get tests
+ local tests = get_tests()
local test_patterns = option.get("tests")
if test_patterns then
local tests_new = {}
@@ -488,4 +494,3 @@ function main()
-- unlock the whole project
project.unlock()
end
-
diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua
index 059173c45..fa32ea7ca 100644
--- a/xmake/plugins/project/clang/compile_commands.lua
+++ b/xmake/plugins/project/clang/compile_commands.lua
@@ -28,6 +28,7 @@ import("private.utils.batchcmds")
import("private.utils.executable_path")
import("private.utils.rule_groups")
import("plugins.project.utils.target_cmds", {rootdir = os.programdir()})
+import("actions.test.main", {rootdir = os.programdir(), alias = "test_action"})
-- escape path
function _escape_path(p)
@@ -288,11 +289,19 @@ end
function _add_targets(jsonfile)
jsonfile:print("[")
_g.firstline = true
+
for _, target in pairs(project.targets()) do
if not target:is_phony() then
_add_target(jsonfile, target)
end
end
+ -- https://github.com/xmake-io/xmake/issues/4750
+ for _, test in pairs(test_action.get_tests()) do
+ local target = test.target
+ if not target:is_phony() then
+ _add_target(jsonfile, target)
+ end
+ end
jsonfile:print("]")
end