diff options
| author | ruki <[email protected]> | 2025-09-04 22:57:52 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-09-04 22:30:35 +0800 |
| commit | 4d11d90ba502bcd82a72c2ea66b1115897d81c52 (patch) | |
| tree | 7475b62c335f4c4028a0e7f36e5f4073b61151fd | |
| parent | 15c0177361f6a6b488ab6937d088f4a0a711a086 (diff) | |
improve bin2c
| -rw-r--r-- | xmake/modules/private/utils/batchcmds.lua | 23 | ||||
| -rw-r--r-- | xmake/modules/utils/run_script.lua | 10 | ||||
| -rw-r--r-- | xmake/rules/utils/bin2c/xmake.lua | 4 |
3 files changed, 34 insertions, 3 deletions
diff --git a/xmake/modules/private/utils/batchcmds.lua b/xmake/modules/private/utils/batchcmds.lua index 944507397..544c94c2e 100644 --- a/xmake/modules/private/utils/batchcmds.lua +++ b/xmake/modules/private/utils/batchcmds.lua @@ -28,6 +28,7 @@ import("core.theme.theme") import("core.tool.linker") import("core.tool.compiler") import("core.language.language") +import("utils.run_script") import("utils.progress", {alias = "progress_utils"}) import("utils.binary.rpath", {alias = "rpath_utils"}) @@ -121,6 +122,22 @@ function _runcmd_vexecv(cmd, opt) end end +-- run command: lua +function _runcmd_lua(cmd, opt) + if cmd.script then + if opt.dryrun then + print(os.args(table.join("xmake", "lua", cmd.script, cmd.argv))) + else + vprint(os.args(table.join("xmake", "lua", cmd.script, cmd.argv))) + local runopt = table.clone(cmd.opt) or {} + runopt.arguments = cmd.argv + -- it will run in a separate native thread, which will not block other coroutine jobs + runopt.thread = true + run_script(cmd.script, runopt) + end + end +end + -- run command: os.mkdir function _runcmd_mkdir(cmd, opt) local dir = cmd.dir @@ -214,6 +231,7 @@ function _runcmd(cmd, opt) vrunv = _runcmd_vrunv, execv = _runcmd_execv, vexecv = _runcmd_vexecv, + lua = _runcmd_lua, mkdir = _runcmd_mkdir, rmdir = _runcmd_rmdir, cd = _runcmd_cd, @@ -271,6 +289,11 @@ function batchcmds:vexecv(program, argv, opt) table.insert(self:cmds(), {kind = "vexecv", program = program, argv = argv, opt = opt}) end +-- add command: run lua script file, command or module +function batchcmds:lua(script, argv, opt) + table.insert(self:cmds(), {kind = "lua", script = script, argv = argv, opt = opt}) +end + -- add command: compiler.compile function batchcmds:compile(sourcefiles, objectfile, opt) diff --git a/xmake/modules/utils/run_script.lua b/xmake/modules/utils/run_script.lua index 709580f1b..0394ccb6e 100644 --- a/xmake/modules/utils/run_script.lua +++ b/xmake/modules/utils/run_script.lua @@ -170,11 +170,19 @@ function main(script, opt) local curdir = opt.curdir or os.workingdir() local oldir = os.cd(curdir) if opt.thread then + local argv + for _, arg in ipairs(opt.arguments) do + argv = argv or {} + if path.instance_of(arg) then + arg = tostring(arg) + end + table.insert(argv, arg) + end local thread_opt = { curdir = curdir, command = opt.command, deserialize = opt.deserialize, - arguments = opt.arguments, + arguments = argv, verbose = opt.verbose, diagnosis = opt.diagnosis } diff --git a/xmake/rules/utils/bin2c/xmake.lua b/xmake/rules/utils/bin2c/xmake.lua index 9bed0f658..5373d2093 100644 --- a/xmake/rules/utils/bin2c/xmake.lua +++ b/xmake/rules/utils/bin2c/xmake.lua @@ -38,7 +38,7 @@ rule("utils.bin2c") -- add commands batchcmds:show_progress(opt.progress, "${color.build.object}generating.bin2c %s", sourcefile_bin) batchcmds:mkdir(headerdir) - local argv = {"lua", "private.utils.bin2c", "-i", path(sourcefile_bin), "-o", path(headerfile)} + local argv = {"-i", path(sourcefile_bin), "-o", path(headerfile)} local linewidth = target:extraconf("rules", "utils.bin2c", "linewidth") if linewidth then table.insert(argv, "-w") @@ -48,7 +48,7 @@ rule("utils.bin2c") if nozeroend then table.insert(argv, "--nozeroend") end - batchcmds:vrunv(os.programfile(), argv, {envs = {XMAKE_SKIP_HISTORY = "y"}}) + batchcmds:lua("private.utils.bin2c", argv) -- add deps batchcmds:add_depfiles(sourcefile_bin) |
