summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-05-27 00:50:35 +0800
committerruki <[email protected]>2020-05-26 23:03:31 +0800
commit7690eaf09fd10101d67c10f8fdbf3fc0f02992fe (patch)
treeb7efd5d07e96ae89790fff71b26bc491b31aa8e7
parent8711cc579bc5519f400e25d09cee8d79f0e454bf (diff)
add winos.cmdargv
-rw-r--r--xmake/core/base/winos.lua30
-rw-r--r--xmake/core/sandbox/modules/winos.lua1
-rw-r--r--xmake/modules/core/tools/link.lua14
3 files changed, 30 insertions, 15 deletions
diff --git a/xmake/core/base/winos.lua b/xmake/core/base/winos.lua
index 22ffb5040..5841f5a6c 100644
--- a/xmake/core/base/winos.lua
+++ b/xmake/core/base/winos.lua
@@ -25,7 +25,6 @@ local winos = winos or {}
local os = require("base/os")
local semver = require("base/semver")
-
winos._ansi_cp = winos._ansi_cp or winos.ansi_cp
winos._oem_cp = winos._oem_cp or winos.oem_cp
@@ -148,10 +147,35 @@ function winos.version()
-- save to cache
winos._VERSION = winver or false
-
- -- done
return winver
end
+-- get command arguments on windows to solve 8192 character command line length limit
+function winos.cmdargv(argv, key)
+
+ -- too long arguments?
+ local argn = 0
+ for _, arg in ipairs(argv) do
+ argn = argn + #arg
+ if argn > 1024 then
+ break
+ end
+ end
+ if argn > 1024 then
+ local argsfile = os.tmpfile(key or table.concat(argv, '')) .. ".args.txt"
+ local f = io.open(argsfile, 'w')
+ if f then
+ -- we need 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
+ for _, arg in ipairs(argv) do
+ f:write(os.args(arg, {escape = true}) .. "\n")
+ end
+ f:close()
+ end
+ argv = {"@" .. argsfile}
+ end
+ return argv
+end
+
-- return module: winos
return winos
diff --git a/xmake/core/sandbox/modules/winos.lua b/xmake/core/sandbox/modules/winos.lua
index 6c4c372aa..fc480dfc3 100644
--- a/xmake/core/sandbox/modules/winos.lua
+++ b/xmake/core/sandbox/modules/winos.lua
@@ -33,6 +33,7 @@ sandbox_winos.console_cp = winos.console_cp
sandbox_winos.console_output_cp = winos.console_output_cp
sandbox_winos.registry_query = winos.registry_query
sandbox_winos.logical_drives = winos.logical_drives
+sandbox_winos.cmdargv = winos.cmdargv
-- get windows system version
function sandbox_winos.version()
diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua
index ccf679c20..3bcbb238d 100644
--- a/xmake/modules/core/tools/link.lua
+++ b/xmake/modules/core/tools/link.lua
@@ -92,19 +92,9 @@ end
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
-
- -- init arguments
- local argv = table.join(flags, "-out:" .. os.args(targetfile), objectfiles)
-
- -- too long arguments for windows?
opt = opt or {}
- local args = os.args(argv, {escape = true})
- if #args > 1024 and not opt.rawargs then
- local argsfile = os.tmpfile(args) .. ".args.txt"
- io.writefile(argsfile, args)
- argv = {"@" .. argsfile}
- end
- return self:program(), argv
+ local argv = table.join(flags, "-out:" .. targetfile, objectfiles)
+ return self:program(), opt.rawargs and argv or winos.cmdargv(argv)
end
-- link the target file