xmake 自定义 task 没有办法转发参数么? #7287
Answered
by
githubnotebooks
githubnotebooks
asked this question in
Q&A
-
task("mybuild", function()
set_category("action")
set_menu({
usage = "xmake mybuild",
description = "mybuild ...",
options = {
{ nil, "args", "vs", nil, "..." },
},
})
on_run(function()
import("core.base.option")
local args = option.get("args") or ""
print(args)
local args_str = table.concat(args, " ")
print(args_str)
os.exec("xmake build " .. args_str)
end)
end)在上述代码中,我想要将参数转发给 xmake build,如果是普通的构建目标,这是没问题的,但如果带有 -v,那么就不行了。 xmake mybuild -v t1 # 这里只将 t1 转发给 xmake build
xmake mybuild t1 -v # 这里虽然将 t1 和 -v 都转发过去,但 xmake build t1 -v 是非法的,报错,必须是 xmake build -v t1 的形式如果不能转发参数,那么当我的 task 内部调用 xmake build 的时候,我是不是得找到源代码,然后把 build 的 option 都拷贝到 mybuild 中? task("build")
set_category("main")
on_run("main")
set_menu {
usage = "xmake [task] [options] [target]"
, description = "Build targets if no given tasks."
, shortname = 'b'
, options =
{
{nil, "version", "k", nil , "Print the version number and exit." }
, {'b', "build", "k", nil , "Build target. This is default building mode and optional." }
, {'r', "rebuild", "k", nil , "Rebuild the target." }
, {'a', "all", "k", nil , "Build all targets." }
, {nil, "shallow", "k", nil , "Only re-build the given targets without dependencies." }
, {'g', "group", "kv", nil , "Build all targets of the given group. It support path pattern matching.",
"e.g.",
" xmake -g test",
" xmake -g test_*",
" xmake --group=benchmark/*" }
, {nil, "dry-run", "k", nil , "Dry run to build target." }
, {}
, {'j', "jobs", "kv", tostring(os.default_njob()),
"Set the number of parallel compilation jobs." }
, {nil, "linkjobs", "kv", nil, "Set the number of parallel link jobs." }
, {'w', "warning", "k", false , "Enable the warnings output. (deprecated)" }
, {nil, "linkonly", "k", false , "Only link targets if object files have been compiled." }
, {nil, "files", "kv", nil , "Build the given source files.",
"e.g. ",
" - xmake --files=src/main.c",
" - xmake --files='src/*.c' [target]",
" - xmake --files='src/**.c|excluded_file.c'",
" - xmake --files='src/main.c" .. path.envsep() .. "src/test.c'" }
, {}
, {nil, "target", "v", nil , "The target name. It will build all default targets if this parameter is not specified."
, values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) end }
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
githubnotebooks
Feb 2, 2026
Replies: 1 comment 1 reply
-
|
参考下 watch 的实现 xmake/xmake/plugins/watch/xmake.lua Line 47 in d7bdbc9 xmake/xmake/plugins/watch/main.lua Line 73 in d7bdbc9 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
哦我知道了,需要通过
--派发参数,必须是:此时 vs 类型的多值参数才能接收到
{ "-v", "arg1", "arg2"}这三个参数而不会把-v丢掉。