From 4eeaaaa589f2fff682bf56fa32489a5aedcb6463 Mon Sep 17 00:00:00 2001 From: 小鸡快跑 <2283572185@qq.com> Date: Mon, 12 Aug 2024 17:52:02 +0800 Subject: fix(plugin/project): Generate compile_commands for tests 1. Implement the get_tests_table as a function 2. Generate compile_commands for tests --- xmake/actions/test/main.lua | 35 ++++++++++++++---------- xmake/plugins/project/clang/compile_commands.lua | 9 ++++++ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/xmake/actions/test/main.lua b/xmake/actions/test/main.lua index f8314ce69..684660afc 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 table, export this for the `project` plugin +function get_tests_table() 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_table() 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..45ef1c4fe 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_table()) do + local target = test.target + if not target:is_phony() then + _add_target(jsonfile, target) + end + end jsonfile:print("]") end -- cgit v1.3.1 From 5d2ddd6a06df3e856d8e3c984728f301dbfa4f40 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 12 Aug 2024 22:37:34 +0800 Subject: Update main.lua --- xmake/actions/test/main.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/actions/test/main.lua b/xmake/actions/test/main.lua index 684660afc..93aed9c09 100644 --- a/xmake/actions/test/main.lua +++ b/xmake/actions/test/main.lua @@ -366,8 +366,8 @@ function _try_build_target(targetname) return passed, errors end --- get tests table, export this for the `project` plugin -function get_tests_table() +-- get tests, export this for the `project` plugin +function get_tests() local tests = {} local group_pattern = option.get("group") if group_pattern then -- cgit v1.3.1 From 1288ac7075a8589df677880d1befe3ebc83856a1 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 12 Aug 2024 22:37:53 +0800 Subject: Update compile_commands.lua --- xmake/plugins/project/clang/compile_commands.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua index 45ef1c4fe..fa32ea7ca 100644 --- a/xmake/plugins/project/clang/compile_commands.lua +++ b/xmake/plugins/project/clang/compile_commands.lua @@ -296,7 +296,7 @@ function _add_targets(jsonfile) end end -- https://github.com/xmake-io/xmake/issues/4750 - for _, test in pairs(test_action.get_tests_table()) do + for _, test in pairs(test_action.get_tests()) do local target = test.target if not target:is_phony() then _add_target(jsonfile, target) -- cgit v1.3.1 From 90846dd50abc804a82787e24a079eb15eac12908 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 12 Aug 2024 22:41:58 +0800 Subject: Update main.lua --- xmake/actions/test/main.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/actions/test/main.lua b/xmake/actions/test/main.lua index 93aed9c09..c1bb156dd 100644 --- a/xmake/actions/test/main.lua +++ b/xmake/actions/test/main.lua @@ -445,7 +445,7 @@ function main() task.run("config", {}, {disable_dump = true}) -- get tests - local tests = get_tests_table() + local tests = get_tests() local test_patterns = option.get("tests") if test_patterns then local tests_new = {} -- cgit v1.3.1