feat(plugin/project): support gen compile_commands.json for specific target#6572
feat(plugin/project): support gen compile_commands.json for specific target#6572waruqi merged 1 commit intoxmake-io:devfrom
Conversation
| for name, target in pairs(project.targets()) do | ||
| if not target:is_phony() then | ||
| _add_target(jsonfile, target) | ||
| if selected_target == nil or name == selected_target then |
There was a problem hiding this comment.
指定 target ,应该直接从 project.target("xxx") 取,而不是走遍历,太慢
| , " - xmake project -k vsxmake -a \"x86,x64\"" } | ||
| , {'t', "target", "kv" , nil , "Set specific target for compile_commands." | ||
| , " e.g. " | ||
| , " - xmake project -k compile_commands -t \"custom\"" } |
There was a problem hiding this comment.
尽可能把参数做成通用的,而不是仅仅针对 compile_commands。 像 cmakelists/vs 这些 generator 都可以指定 target 。
| local project_targets | ||
| local selected_target = option.get("target") | ||
| if selected_target then | ||
| project_targets = { project.target(selected_target) } |
There was a problem hiding this comment.
不用 {} 去 wrap,pairs 在外面的 sandbox 里面,可以直接遍历的。或者用 table.wrap(target)
另外,可以弄成 function 封装下
function _get_targets()
end
There was a problem hiding this comment.
-- get project targets
function _get_targets()
local project_targets
local selected_target = option.get("target")
if selected_target then
project_targets = table.wrap(project.target(selected_target))
-- project_targets = project.target(selected_target)
-- project_targets = { project.target(selected_target) }
else
project_targets = project.targets()
end
return project_targets
end
试了下3种写法, 只有直接加{}的能用. 另外的都是提示. error: attempt to index a function value (local 'target')
There was a problem hiding this comment.
_get_targets 如果要做成 project模块共用的函数要放什么地方比较好? 每个文件放一份, 改一次要改一堆地方...
There was a problem hiding this comment.
放这里,https://github.com/xmake-io/xmake/tree/dev/xmake/plugins/project/utils
有个 utils 目录,参考这个的导入方式
| project_targets = { project.target(selected_target) } | ||
| else | ||
| project_targets = project.targets() | ||
| end |
| _g.firstline = true | ||
|
|
||
| for _, target in pairs(project.targets()) do | ||
| local project_targets = target_cmds.get_project_targets() |
There was a problem hiding this comment.
不是,我的意思的参考这个,在同位置加个模块,而不是用这个。。比如 加个
target_utils.get_targets()
There was a problem hiding this comment.
更新了, 加了target_utils.lua文件
| import("private.action.require.install", {alias = "install_requires"}) | ||
| import("actions.config.configfiles", {alias = "generate_configfiles", rootdir = os.programdir()}) | ||
| import("vstudio.impl.vsutils", {rootdir = path.join(os.programdir(), "plugins", "project")}) | ||
| import("plugins.project.utils.target_utils", {rootdir = os.programdir()}) |
There was a problem hiding this comment.
This causes a naming conflict with the previous target_utils import.
add option to generate compile_commands for specific target, for #6140