diff options
| author | ruki <[email protected]> | 2025-12-28 12:30:19 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-12-29 00:09:38 +0800 |
| commit | 722f528c4352fe5584cdd04c9270a3348b0c8e82 (patch) | |
| tree | 9bf26bd25f0b570f8eee13431fbcae6a6834b2b8 | |
| parent | 399988ff7a79d7d9ee994c8911bf6e69588dd7c5 (diff) | |
prepare test targets in compile_commands
| -rw-r--r-- | xmake/plugins/project/clang/compile_commands.lua | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua index a017b4a32..4f01354fa 100644 --- a/xmake/plugins/project/clang/compile_commands.lua +++ b/xmake/plugins/project/clang/compile_commands.lua @@ -276,6 +276,23 @@ function _add_target(jsonfile, target) os.setenvs(oldenvs) end +-- get test targets +-- https://github.com/xmake-io/xmake/issues/4750 +function _get_test_targets() + local test_targets = _g.test_targets + if test_targets == nil then + test_targets = {} + for _, test in pairs(test_action.get_tests()) do + local target = test.target + if not target:is_phony() then + table.insert(test_targets, target) + end + end + _g.test_targets = test_targets + end + return test_targets +end + -- add targets function _add_targets(jsonfile) jsonfile:print("[") @@ -288,15 +305,19 @@ function _add_targets(jsonfile) 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 + for _, target in ipairs(_get_test_targets()) do + _add_target(jsonfile, target) end jsonfile:print("]") end +-- prepare targets +function _prepare_targets() + target_cmds.prepare_targets() + -- https://github.com/xmake-io/xmake/issues/7166 + target_cmds.prepare_targets(_get_test_targets()) +end + -- generate compilation databases for clang-based tools(compile_commands.json) -- -- references: @@ -308,7 +329,7 @@ function make(outputdir) local oldir = os.cd(os.projectdir()) local jsonfile = io.open(path.join(outputdir, "compile_commands.json"), "w") os.setenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR", "true") - target_cmds.prepare_targets() + _prepare_targets() _add_targets(jsonfile) jsonfile:close() os.setenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR", nil) |
