local argv2 = {sourcefile, "--output="..path.absolute(outdir), "--root="..rootdir orpath.absolute(target:scriptdir()), "--"} -- hack: insert a placeholder to avoid the case where (#argv < limit) and (#argv + #argv2 > limit) if is_host("windows") then local argv2l = 0 for _, v inpairs(argv2) do argv2l = argv2l + #v end local _ = "-DFUCK_YOU_WINDOWS" .. string.rep("S", argv2l) table.insert(argv, #argv + 1, _) argv = winos.cmdargv(argv) end for k,v inpairs(argv2) do table.insert(argv, k, v) end
-- get command arguments on windows to solve 8192 character command line length limit functionwinos.cmdargv(argv, opt)
-- too long arguments? local limit = 4096 local argn = 0 for _, arginipairs(argv) do arg = tostring(arg) argn = argn + #arg if argn > limit then break end end if argn > limit then opt = opt or {} local argsfile = os.tmpfile(opt.tmpkey oros.args(argv)) .. ".args.txt" local f = io.open(argsfile, 'w', {encoding = "ansi"}) if f then -- we need to split args file to solve `fatal error LNK1170: line in command file contains 131071 or more characters` -- @see https://github.com/xmake-io/xmake/issues/812 local idx = 1 while idx <= #argv do arg = tostring(argv[idx]) arg1 = argv[idx + 1] if arg1 then arg1 = tostring(arg1) end -- we need to ensure `/name value` in same line, -- otherwise cl.exe will prompt that the corresponding parameter value cannot be found -- -- e.g. -- -- /sourceDependencies xxxx.json -- -Dxxx -- foo.obj -- if idx + 1 <= #argv andarg:find("^[-/]") andnot arg1:find("^[-/]") then f:write(os.args(arg, {escape = opt.escape}) .. " ") f:write(os.args(arg1, {escape = opt.escape}) .. "\n") idx = idx + 2 else f:write(os.args(arg, {escape = opt.escape}) .. "\n") idx = idx + 1 end end f:close() end argv = {"@" .. argsfile} end return argv end