diff options
| author | ruki <[email protected]> | 2017-07-13 09:51:24 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-07-13 09:51:41 +0800 |
| commit | b9e5a411e38224db1f71a39cad57cc54dc13fee6 (patch) | |
| tree | 916f94e87922de4b7ec2168245e3c1fd8763a8e6 | |
| parent | b72d2cd32d1919170eb621dd6c0074c975eb67e1 (diff) | |
modify all cmd to argv for core.tools
| -rw-r--r-- | xmake/core/tool/linker.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/core/tools/ar.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 67 | ||||
| -rw-r--r-- | xmake/modules/core/tools/dmd.lua | 16 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/core/tools/go.lua | 18 | ||||
| -rw-r--r-- | xmake/modules/core/tools/lib.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/core/tools/link.lua | 23 | ||||
| -rw-r--r-- | xmake/modules/core/tools/ml.lua | 14 | ||||
| -rw-r--r-- | xmake/modules/core/tools/rc.lua | 14 | ||||
| -rw-r--r-- | xmake/modules/core/tools/rustc.lua | 16 | ||||
| -rw-r--r-- | xmake/modules/core/tools/swiftc.lua | 40 |
12 files changed, 112 insertions, 107 deletions
diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index 9e83e3e3a..b63e64d73 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -256,9 +256,6 @@ function linker:linkflags(opt) -- add flags from the linker self:_addflags_from_linker(flags) - -- make flags string - local flags_str = os.args(flags) - -- save flags if key then self._FLAGS[key] = flags diff --git a/xmake/modules/core/tools/ar.lua b/xmake/modules/core/tools/ar.lua index bfbc8a577..b1a8fbf92 100644 --- a/xmake/modules/core/tools/ar.lua +++ b/xmake/modules/core/tools/ar.lua @@ -56,7 +56,7 @@ function linkargv(self, objectfiles, targetkind, targetfile, flags) assert(targetkind == "static") -- make it - return self:program(), table.join(flags or {}, targetfile, objectfiles) + return self:program(), table.join(flags, targetfile, objectfiles) end -- link the library file diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index a28e08589..0fa1ab65d 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -39,7 +39,7 @@ function init(self) , ["-O1"] = "" , ["-Os"] = "-O1" , ["-O3"] = "-Ox" - , ["-Ofast"] = "-Ox -fp:fast" + , ["-Ofast"] = {"-Ox", "-fp:fast"} , ["-fomit-frame-pointer"] = "-Oy" -- symbols @@ -87,8 +87,6 @@ end -- get the property function get(self, name) - - -- get it return _g[name] end @@ -96,12 +94,12 @@ end function nf_symbol(self, level, target) -- debug? generate *.pdb file - local flags = "" + local flags = nil if level == "debug" then if target and target.symbolfile then - flags = "-ZI -Fd" .. target:symbolfile() - if self:has_flags("-ZI -FS -Fd" .. os.tmpfile() .. ".pdb") then - flags = "-FS " .. flags + flags = {"-ZI", "-Fd" .. target:symbolfile()} + if self:has_flags({"-ZI", "-FS", "-Fd" .. os.tmpfile() .. ".pdb"}) then + table.insert(flags, 1, "-FS") end else flags = "-ZI" @@ -118,15 +116,15 @@ function nf_warning(self, level) -- the maps local maps = { - none = "-W0" - , less = "-W1" - , more = "-W3" - , all = "-W3" -- = "-Wall" will enable too more warnings - , error = "-WX" + none = "-W0" + , less = "-W1" + , more = "-W3" + , all = "-W3" -- = "-Wall" will enable too more warnings + , error = "-WX" } -- make it - return maps[level] or "" + return maps[level] end -- make the optimize flag @@ -136,31 +134,30 @@ function nf_optimize(self, level) local maps = { none = "-Od" - , fast = "" , faster = "-Ox" - , fastest = "-Ox -fp:fast" + , fastest = {"-Ox", "-fp:fast"} , smallest = "-O1" - , aggressive = "-Ox -fp:fast" + , aggressive = {"-Ox", "-fp:fast"} } -- make it - return maps[level] or "" + return maps[level] end -- make the vector extension flag function nf_vectorext(self, extension) -- the maps - local maps = + local maps = { - sse = "-arch:SSE" - , sse2 = "-arch:SSE2" - , avx = "-arch:AVX" - , avx2 = "-arch:AVX2" + sse = "-arch:SSE" + , sse2 = "-arch:SSE2" + , avx = "-arch:AVX" + , avx2 = "-arch:AVX2" } -- make it - return maps[extension] or "" + return maps[extension] end -- make the language flag @@ -170,10 +167,10 @@ function nf_language(self, stdname) local cmaps = { -- stdc - c99 = "-TP" -- compile as c++ files because msvc only support c89 - , gnu99 = "-TP" - , c11 = "-TP" - , gnu11 = "-TP" + c99 = "-TP" -- compile as c++ files because msvc only support c89 + , gnu99 = "-TP" + , c11 = "-TP" + , gnu11 = "-TP" } -- select maps @@ -183,7 +180,7 @@ function nf_language(self, stdname) end -- make it - return maps[stdname] or "" + return maps[stdname] end -- make the define flag @@ -201,9 +198,9 @@ function nf_includedir(self, dir) return "-I" .. dir end --- make the complie command -function _compcmd1(self, sourcefile, objectfile, flags) - return format("%s -c %s -Fo%s %s", self:program(), flags, objectfile, sourcefile) +-- make the complie arguments list +function _compargv1(self, sourcefile, objectfile, flags) + return self:program(), table.join("-c", flags, "-Fo" .. objectfile, sourcefile) end -- complie the source file @@ -221,7 +218,7 @@ function _compile1(self, sourcefile, objectfile, incdepfile, flags) local outdata = try { function () - return os.iorun(_compcmd1(self, sourcefile, objectfile, flags)) + return os.iorunv(_compargv1(self, sourcefile, objectfile, flags)) end, catch @@ -270,14 +267,14 @@ function _compile1(self, sourcefile, objectfile, incdepfile, flags) end end --- make the complie command -function compcmd(self, sourcefiles, objectfile, flags) +-- make the complie arguments list +function compargv(self, sourcefiles, objectfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'object:sources' not support!") -- for only single source file - return _compcmd1(self, sourcefiles, objectfile, flags) + return _compargv1(self, sourcefiles, objectfile, flags) end -- complie the source file diff --git a/xmake/modules/core/tools/dmd.lua b/xmake/modules/core/tools/dmd.lua index 30c0ce394..03855e4f3 100644 --- a/xmake/modules/core/tools/dmd.lua +++ b/xmake/modules/core/tools/dmd.lua @@ -150,9 +150,9 @@ function nf_rpathdir(self, dir) end end --- make the link command -function linkcmd(self, objectfiles, targetkind, targetfile, flags) - return format("%s %s -of%s %s", self:program(), flags, targetfile, objectfiles) +-- make the link arguments list +function linkargv(self, objectfiles, targetkind, targetfile, flags) + return self:program(), table.join(flags, "-of" .. targetfile, objectfiles) end -- link the target file @@ -162,12 +162,12 @@ function link(self, objectfiles, targetkind, targetfile, flags) os.mkdir(path.directory(targetfile)) -- link it - os.run(linkcmd(self, objectfiles, targetkind, targetfile, flags)) + os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags)) end --- make the complie command -function compcmd(self, sourcefiles, objectfile, flags) - return format("%s -c %s -of%s %s", self:program(), flags, objectfile, table.concat(table.wrap(sourcefiles), " ")) +-- make the complie arguments list +function compargv(self, sourcefiles, objectfile, flags) + return self:program(), table.join("-c", flags, "-of" .. objectfile, sourcefiles) end -- complie the source file @@ -177,6 +177,6 @@ function compile(self, sourcefiles, objectfile, incdepfile, flags) os.mkdir(path.directory(objectfile)) -- compile it - os.run(compcmd(self, sourcefiles, objectfile, flags)) + os.runv(compargv(self, sourcefiles, objectfile, flags)) end diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 3d510fb39..e952f8eb8 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -268,7 +268,7 @@ function _compargv1(self, sourcefile, objectfile, flags) end -- make argv - local argv = table.join("-c", flags or {}, "-o", objectfile, sourcefile) + local argv = table.join("-c", flags, "-o", objectfile, sourcefile) -- uses cache? local program = self:program() diff --git a/xmake/modules/core/tools/go.lua b/xmake/modules/core/tools/go.lua index 46b434e58..cb597652f 100644 --- a/xmake/modules/core/tools/go.lua +++ b/xmake/modules/core/tools/go.lua @@ -104,14 +104,14 @@ function nf_linkdir(self, dir) return {"-L", dir} end --- make the link command -function linkcmd(self, objectfiles, targetkind, targetfile, flags) +-- make the link arguments list +function linkargv(self, objectfiles, targetkind, targetfile, flags) -- make it if targetkind == "static" then - return format("%s tool pack %s %s %s", self:program(), flags, targetfile, objectfiles) + return self:program(), table.join("tool", "pack", flags, targetfile, objectfiles) else - return format("%s tool link %s -o %s %s", self:program(), flags, targetfile, objectfiles) + return self:program(), table.join("tool", "link", flags, "-o", targetfile, objectfiles) end end @@ -122,12 +122,12 @@ function link(self, objectfiles, targetkind, targetfile, flags) os.mkdir(path.directory(targetfile)) -- link it - os.run(linkcmd(self, objectfiles, targetkind, targetfile, flags)) + os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags)) end --- make the complie command -function compcmd(self, sourcefiles, objectfile, flags) - return format("%s tool compile %s -o %s %s", self:program(), flags, objectfile, table.concat(table.wrap(sourcefiles), " ")) +-- make the complie arguments list +function compargv(self, sourcefiles, objectfile, flags) + return self:program(), table.join("tool", "compile", flags, "-o", objectfile, sourcefiles) end -- complie the source file @@ -137,6 +137,6 @@ function compile(self, sourcefiles, objectfile, incdepfile, flags) os.mkdir(path.directory(objectfile)) -- compile it - os.run(compcmd(self, sourcefiles, objectfile, flags)) + os.runv(compargv(self, sourcefiles, objectfile, flags)) end diff --git a/xmake/modules/core/tools/lib.lua b/xmake/modules/core/tools/lib.lua index b7d18b024..0b1541b04 100644 --- a/xmake/modules/core/tools/lib.lua +++ b/xmake/modules/core/tools/lib.lua @@ -34,7 +34,7 @@ function extract(self, libraryfile, objectdir) os.mkdir(objectdir) -- list object files - local objectfiles = os.iorun("%s -nologo -list %s", self:program(), libraryfile) + local objectfiles = os.iorunv(self:program(), {"-nologo", "-list", libraryfile}) -- extrace all object files for _, objectfile in ipairs(objectfiles:split('\n')) do @@ -56,7 +56,7 @@ function extract(self, libraryfile, objectdir) end -- extract it - os.run("%s -nologo -extract:%s -out:%s %s", self:program(), objectfile, outputfile, libraryfile) + os.runv(self:program(), {"-nologo", "-extract:" .. objectfile, "-out:" .. outputfile, libraryfile}) end end end diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua index f41a093d4..a193d2609 100644 --- a/xmake/modules/core/tools/link.lua +++ b/xmake/modules/core/tools/link.lua @@ -70,11 +70,11 @@ end function nf_symbol(self, level, target) -- debug? generate *.pdb file - local flags = "" + local flags = nil local targetkind = target:get("kind") if level == "debug" and (targetkind == "binary" or targetkind == "shared") then if target and target.symbolfile then - flags = "-debug -pdb:" .. target:symbolfile() + flags = {"-debug", "-pdb:" .. target:symbolfile()} else flags = "-debug" end @@ -94,21 +94,22 @@ function nf_linkdir(self, dir) return "-libpath:" .. dir end --- make the link command -function linkcmd(self, objectfiles, targetkind, targetfile, flags) +-- make the link arguments list +function linkargv(self, objectfiles, targetkind, targetfile, flags) - -- make it - local cmd = format("%s %s -out:%s %s", self:program(), flags, targetfile, objectfiles) + -- make arguments list + local argv = table.join(flags, "-out:" .. targetfile, objectfiles) -- too long? - if #cmd > 4096 then + local args = os.args(argv) + if #args > 4096 then local argfile = targetfile .. ".arg" - io.printf(argfile, "%s -out:%s %s", flags, targetfile, objectfiles) - cmd = format("%s @%s", self:program(), argfile) + io.printf(argfile, args) + argv = {"@" .. argfile} end -- ok? - return cmd + return self:program(), argv end -- link the target file @@ -118,6 +119,6 @@ function link(self, objectfiles, targetkind, targetfile, flags) os.mkdir(path.directory(targetfile)) -- link it - os.run(linkcmd(self, objectfiles, targetkind, targetfile, flags)) + os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags)) end diff --git a/xmake/modules/core/tools/ml.lua b/xmake/modules/core/tools/ml.lua index 27343320e..207580dbc 100644 --- a/xmake/modules/core/tools/ml.lua +++ b/xmake/modules/core/tools/ml.lua @@ -96,9 +96,9 @@ function nf_includedir(self, dir) return "-I" .. dir end --- make the complie command -function _compcmd1(self, sourcefile, objectfile, flags) - return format("%s -c %s -Fo%s %s", self:program(), flags, objectfile, sourcefile) +-- make the complie arguments list +function _compargv1(self, sourcefile, objectfile, flags) + return self:program(), table.join("-c", flags, "-Fo" .. objectfile, sourcefile) end -- complie the source file @@ -108,17 +108,17 @@ function _compile1(self, sourcefile, objectfile, incdepfile, flags) os.mkdir(path.directory(objectfile)) -- compile it - os.run(_compcmd1(self, sourcefile, objectfile, flags)) + os.runv(_compargv1(self, sourcefile, objectfile, flags)) end --- make the complie command -function compcmd(self, sourcefiles, objectfile, flags) +-- make the complie arguments list +function compargv(self, sourcefiles, objectfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'object:sources' not support!") -- for only single source file - return _compcmd1(self, sourcefiles, objectfile, flags) + return _compargv1(self, sourcefiles, objectfile, flags) end -- complie the source file diff --git a/xmake/modules/core/tools/rc.lua b/xmake/modules/core/tools/rc.lua index 75a679ddd..4f39181bf 100644 --- a/xmake/modules/core/tools/rc.lua +++ b/xmake/modules/core/tools/rc.lua @@ -56,9 +56,9 @@ function nf_includedir(self, dir) return "-I" .. dir end --- make the complie command -function _compcmd1(self, sourcefile, objectfile, flags) - return format("%s %s -Fo%s %s", self:program(), flags, objectfile, sourcefile) +-- make the complie arguments list +function _compargv1(self, sourcefile, objectfile, flags) + return self:program(), table.join(flags, "-Fo" .. objectfile, sourcefile) end -- complie the source file @@ -71,7 +71,7 @@ function _compile1(self, sourcefile, objectfile, incdepfile, flags) try { function () - local outdata, errdata = os.iorun(_compcmd1(self, sourcefile, objectfile, flags)) + local outdata, errdata = os.iorunv(_compargv1(self, sourcefile, objectfile, flags)) return (outdata or "") .. (errdata or "") end, catch @@ -95,14 +95,14 @@ function _compile1(self, sourcefile, objectfile, incdepfile, flags) } end --- make the complie command -function compcmd(self, sourcefiles, objectfile, flags) +-- make the complie arguments list +function compargv(self, sourcefiles, objectfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'object:sources' not support!") -- for only single source file - return _compcmd1(self, sourcefiles, objectfile, flags) + return _compargv1(self, sourcefiles, objectfile, flags) end -- complie the source file diff --git a/xmake/modules/core/tools/rustc.lua b/xmake/modules/core/tools/rustc.lua index 635d94e9c..f82dcf006 100644 --- a/xmake/modules/core/tools/rustc.lua +++ b/xmake/modules/core/tools/rustc.lua @@ -94,9 +94,9 @@ function nf_linkdir(self, dir) return {"-L", dir} end --- make the build command -function buildcmd(self, sourcefiles, targetkind, targetfile, flags) - return format("%s %s -o %s %s", self:program(), flags, targetfile, table.concat(sourcefiles, " ")) +-- make the build arguments list +function buildargv(self, sourcefiles, targetkind, targetfile, flags) + return self:program(), table.join(flags, "-o", targetfile, sourcefiles) end -- build the target file @@ -106,12 +106,12 @@ function build(self, sourcefiles, targetkind, targetfile, flags) os.mkdir(path.directory(targetfile)) -- build it - os.run(buildcmd(self, sourcefiles, targetkind, targetfile, flags)) + os.runv(buildargv(self, sourcefiles, targetkind, targetfile, flags)) end --- make the complie command -function compcmd(self, sourcefiles, objectfile, flags) - return format("%s --emit obj %s -o %s %s", self:program(), flags, objectfile, table.concat(table.wrap(sourcefiles), " ")) +-- make the complie arguments list +function compargv(self, sourcefiles, objectfile, flags) + return self:program(), table.join("--emit", "obj", flags, "-o", objectfile, sourcefiles) end -- complie the source file @@ -121,6 +121,6 @@ function compile(self, sourcefiles, objectfile, incdepfile, flags) os.mkdir(path.directory(objectfile)) -- compile it - os.run(compcmd(self, sourcefiles, objectfile, flags)) + os.runv(compargv(self, sourcefiles, objectfile, flags)) end diff --git a/xmake/modules/core/tools/swiftc.lua b/xmake/modules/core/tools/swiftc.lua index b7641128c..cfe97a0c3 100644 --- a/xmake/modules/core/tools/swiftc.lua +++ b/xmake/modules/core/tools/swiftc.lua @@ -180,9 +180,9 @@ function nf_linkdir(self, dir) return "-L" .. dir end --- make the link command -function linkcmd(self, objectfiles, targetkind, targetfile, flags) - return format("%s -o %s %s %s", self:program(), targetfile, objectfiles, flags) +-- make the link arguments list +function linkargv(self, objectfiles, targetkind, targetfile, flags) + return self:program(), table.join("-o", targetfile, objectfiles, flags) end -- link the target file @@ -192,11 +192,11 @@ function link(self, objectfiles, targetkind, targetfile, flags) os.mkdir(path.directory(targetfile)) -- link it - os.run(linkcmd(self, objectfiles, targetkind, targetfile, flags)) + os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags)) end --- make the compile command -function _compcmd1(self, sourcefile, objectfile, flags) +-- make the compile arguments list +function _compargv1(self, sourcefile, objectfile, flags) -- get ccache local ccache = nil @@ -204,14 +204,24 @@ function _compcmd1(self, sourcefile, objectfile, flags) ccache = find_ccache() end - -- make it - local command = format("%s -c %s -o %s %s", self:program(), flags, objectfile, sourcefile) + -- make argv + local argv = table.join("-c", flags, "-o", objectfile, sourcefile) + + -- uses cache? + local program = self:program() if ccache then - command = ccache:append(command, " ") + + -- parse the filename and arguments, .e.g "xcrun -sdk macosx clang" + if not os.isexec(program) then + argv = table.join(program:split("%s"), argv) + else + table.insert(argv, 1, program) + end + return ccache, argv end - -- ok - return command + -- no cache + return program, argv end -- complie the source file @@ -221,17 +231,17 @@ function _compile1(self, sourcefile, objectfile, incdepfile, flags) os.mkdir(path.directory(objectfile)) -- compile it - os.run(_compcmd1(self, sourcefile, objectfile, flags)) + os.runv(_compargv1(self, sourcefile, objectfile, flags)) end --- make the complie command -function compcmd(self, sourcefiles, objectfile, flags) +-- make the complie arguments list +function compargv(self, sourcefiles, objectfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'object:sources' not support!") -- for only single source file - return _compcmd1(self, sourcefiles, objectfile, flags) + return _compargv1(self, sourcefiles, objectfile, flags) end -- complie the source file |
