diff options
| author | ruki <[email protected]> | 2018-05-19 00:46:16 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-05-18 22:37:36 +0800 |
| commit | 90008609b8044bd4f600c9cc11e792b1eb4c03e5 (patch) | |
| tree | 0cac18a49ce69826331f38822d32c53001fb43e8 | |
| parent | 344d26e6176003b72e8af45ff9202b2f7d11d3dc (diff) | |
improve command arguments
| -rw-r--r-- | xmake/actions/clean/main.lua | 3 | ||||
| -rw-r--r-- | xmake/core/base/os.lua | 28 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/io.lua | 4 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 26 | ||||
| -rw-r--r-- | xmake/modules/core/tools/ar.lua | 15 | ||||
| -rw-r--r-- | xmake/modules/core/tools/link.lua | 15 |
6 files changed, 29 insertions, 62 deletions
diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua index 0f9517666..f2b42806b 100644 --- a/xmake/actions/clean/main.lua +++ b/xmake/actions/clean/main.lua @@ -71,9 +71,6 @@ function _on_clean_target(target) -- remove the target file _remove(target:targetfile()) - -- remove the target arguments file if exists - _remove(target:targetfile() .. ".arg") - -- remove the target dependent file if exists _remove(target:dependfile()) diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 71a6119f6..e5377820f 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -501,8 +501,8 @@ function os.tmpdir() end -- generate the temporary file path -function os.tmpfile() - return path.join(os.tmpdir(), "_" .. (hash.uuid():gsub("-", ""))) +function os.tmpfile(key) + return path.join(os.tmpdir(), "_" .. (hash.uuid(key):gsub("-", ""))) end -- run command @@ -583,8 +583,19 @@ function os.execv(program, argv, opt) wildcards = true end - -- init arguments - local args = wildcards and os.argw(argv) or argv + -- translate arguments for wildcards + argv = wildcards and os.argw(argv) or argv + + -- too long arguments for windows? + local argsfile = nil + if os.host() == "windows" then + local args = os.args(argv) + if #args > 256 then + argsfile = os.tmpfile(args) .. ".args.txt" + io.writefile(argsfile, args) + argv = {"@" .. argsfile} + end + end -- is not executable program file? local filename = program @@ -594,13 +605,13 @@ function os.execv(program, argv, opt) local splitinfo = program:split("%s") filename = splitinfo[1] if #splitinfo > 1 then - args = table.join(table.slice(splitinfo, 2), args) + argv = table.join(table.slice(splitinfo, 2), argv) end end -- open command local ok = -1 - local proc = process.openv(filename, args, opt.stdout, opt.stderr) + local proc = process.openv(filename, argv, opt.stdout, opt.stderr) if proc ~= nil then -- wait process @@ -635,6 +646,11 @@ function os.execv(program, argv, opt) process.close(proc) end + -- remove arguments file + if argsfile and os.isfile(argsfile) then + os.rm(argsfile) + end + -- ok? return ok end diff --git a/xmake/core/sandbox/modules/io.lua b/xmake/core/sandbox/modules/io.lua index a1e8ce443..5840f0712 100644 --- a/xmake/core/sandbox/modules/io.lua +++ b/xmake/core/sandbox/modules/io.lua @@ -179,15 +179,11 @@ end -- print line to file function sandbox_io.print(filepath, ...) - - -- print it sandbox_io.writefile(filepath, vformat(...) .. "\n") end -- print data to file function sandbox_io.printf(filepath, ...) - - -- print it sandbox_io.writefile(filepath, vformat(...)) end diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index 16e5878d4..e029588d5 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -204,35 +204,17 @@ end -- get the current directory function sandbox_os.curdir() - - -- get it - local curdir = os.curdir() - assert(curdir) - - -- ok - return curdir + return assert(os.curdir()) end -- get the temporary directory function sandbox_os.tmpdir() - - -- get it - local tmpdir = os.tmpdir() - assert(tmpdir) - - -- ok - return tmpdir + return assert(os.tmpdir()) end -- get the temporary file -function sandbox_os.tmpfile() - - -- get it - local tmpfile = os.tmpfile() - assert(tmpfile) - - -- ok - return tmpfile +function sandbox_os.tmpfile(key) + return assert(os.tmpfile(key)) end -- get the script directory diff --git a/xmake/modules/core/tools/ar.lua b/xmake/modules/core/tools/ar.lua index 935ca925f..de70ddc46 100644 --- a/xmake/modules/core/tools/ar.lua +++ b/xmake/modules/core/tools/ar.lua @@ -55,19 +55,8 @@ function linkargv(self, objectfiles, targetkind, targetfile, flags) -- check assert(targetkind == "static") - -- make arguments list - local argv = table.join(flags, targetfile, objectfiles) - - -- too long? - local args = os.args(argv) - if #args > 4096 and os.host() == "windows" then - local argfile = targetfile .. ".arg" - io.printf(argfile, args) - argv = {"@" .. argfile} - end - - -- ok? - return self:program(), argv + -- make it + return self:program(), table.join(flags, targetfile, objectfiles) end -- link the library file diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua index 620c2468d..f9cde52ec 100644 --- a/xmake/modules/core/tools/link.lua +++ b/xmake/modules/core/tools/link.lua @@ -90,20 +90,7 @@ end -- make the link arguments list function linkargv(self, objectfiles, targetkind, targetfile, flags) - - -- make arguments list - local argv = table.join(flags, "-out:" .. targetfile, objectfiles) - - -- too long? - local args = os.args(argv) - if #args > 4096 then - local argfile = targetfile .. ".arg" - io.printf(argfile, args) - argv = {"@" .. argfile} - end - - -- ok? - return self:program(), argv + return self:program(), table.join(flags, "-out:" .. targetfile, objectfiles) end -- link the target file |
