diff options
| author | ruki <[email protected]> | 2017-07-12 18:34:01 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-07-12 18:34:01 +0800 |
| commit | b72d2cd32d1919170eb621dd6c0074c975eb67e1 (patch) | |
| tree | d34c3d1fbae58091301403fd9dc450bdad78647e | |
| parent | 693619f971581f9b7bc66fcdb1ef65d01aa002e5 (diff) | |
modify compflags and add compargv
| -rw-r--r-- | xmake/core/base/os.lua | 12 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 9 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/compiler.lua | 24 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/linker.lua | 9 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 1 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 33 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 15 | ||||
| -rw-r--r-- | xmake/modules/core/tools/ar.lua | 12 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 42 | ||||
| -rw-r--r-- | xmake/plugins/project/makefile/makefile.lua | 20 |
10 files changed, 117 insertions, 60 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index aeab699c4..acce3d2e9 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -159,6 +159,15 @@ end -- make string from arguments list function os.args(argv) + -- init key + local key = tostring(argv) + + -- init cache + os._ARGS = os._ARGS or {} + if os._ARGS[key] then + return os._ARGS[key] + end + -- make it local args = nil for _, arg in ipairs(argv) do @@ -181,6 +190,9 @@ function os.args(argv) end end + -- cache it + os._ARGS[key] = args or "" + -- ok? return args or "" end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 4b72d5c2e..6ca800f7f 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -135,15 +135,16 @@ end -- make linking command for this target function target:linkcmd(objectfiles) - - -- make command return self:linker():linkcmd(objectfiles or self:objectfiles(), self:targetfile(), {target = self}) end +-- make linking arguments for this target +function target:linkargv(objectfiles) + return self:linker():linkargv(objectfiles or self:objectfiles(), self:targetfile(), {target = self}) +end + -- make link flags for the given target function target:linkflags() - - -- make flags return self:linker():linkflags({target = self}) end diff --git a/xmake/core/sandbox/modules/import/core/tool/compiler.lua b/xmake/core/sandbox/modules/import/core/tool/compiler.lua index 3aa7c0577..12cb8cf24 100644 --- a/xmake/core/sandbox/modules/import/core/tool/compiler.lua +++ b/xmake/core/sandbox/modules/import/core/tool/compiler.lua @@ -49,6 +49,11 @@ end -- make command for compiling source file function sandbox_core_tool_compiler.compcmd(sourcefiles, objectfile, opt) + return os.args(table.join(sandbox_core_tool_compiler.compargv(sourcefiles, objectfile, opt))) +end + +-- make arguments list for compiling source file +function sandbox_core_tool_compiler.compargv(sourcefiles, objectfile, opt) -- init options opt = opt or {} @@ -65,8 +70,8 @@ function sandbox_core_tool_compiler.compcmd(sourcefiles, objectfile, opt) raise(errors) end - -- make command - return instance:compcmd(sourcefiles, objectfile, opt) + -- make arguments list + return instance:compargv(sourcefiles, objectfile, opt) end -- compile source files @@ -100,7 +105,7 @@ end -- @param opt the argument options (contain all the compiler attributes of target), -- .e.g {target = ..., targetkind = "static", cxflags = "", defines = "", includedirs = "", ...} -- --- @return flags string, flags list +-- @return the flags list -- function sandbox_core_tool_compiler.compflags(sourcefiles, opt) @@ -122,6 +127,11 @@ end -- make command for building source file function sandbox_core_tool_compiler.buildcmd(sourcefiles, targetfile, opt) + return os.args(table.join(sandbox_core_tool_compiler.buildargv(sourcefiles, targetfile, opt))) +end + +-- make arguments list for building source file +function sandbox_core_tool_compiler.buildargv(sourcefiles, targetfile, opt) -- get source kind if only one source file local sourcekind = opt.sourcekind @@ -135,8 +145,8 @@ function sandbox_core_tool_compiler.buildcmd(sourcefiles, targetfile, opt) raise(errors) end - -- make command - return instance:buildcmd(sourcefiles, targetfile, opt) + -- make arguments list + return instance:buildargv(sourcefiles, targetfile, opt) end -- build source files @@ -182,7 +192,7 @@ function sandbox_core_tool_compiler.features(sourcekind, opt) if sandbox_core_tool_compiler._features then -- get flags - local _, flags = instance:compflags(opt) + local flags = instance:compflags(opt) -- get features local ok, results_or_errors = sandbox.load(sandbox_core_tool_compiler._features, instance:name(), {flags = flags, program = instance:program()}) @@ -244,7 +254,7 @@ function sandbox_core_tool_compiler.has_features(features, opt) end -- get flags - local _, flags = instance:compflags(opt) + local flags = instance:compflags(opt) -- has features? local ok, results_or_errors = sandbox.load(sandbox_core_tool_compiler._has_features, instance:name(), features, {flags = flags, program = instance:program()}) diff --git a/xmake/core/sandbox/modules/import/core/tool/linker.lua b/xmake/core/sandbox/modules/import/core/tool/linker.lua index f25b1f779..33ded2ce2 100644 --- a/xmake/core/sandbox/modules/import/core/tool/linker.lua +++ b/xmake/core/sandbox/modules/import/core/tool/linker.lua @@ -32,6 +32,11 @@ local raise = require("sandbox/modules/raise") -- make command for linking target file function sandbox_core_tool_linker.linkcmd(targetkind, sourcekinds, objectfiles, targetfile, opt) + return os.args(table.join(sandbox_core_tool_linker.linkargv(targetkind, sourcekinds, objectfiles, targetfile, opt))) +end + +-- make arguments list for linking target file +function sandbox_core_tool_linker.linkargv(targetkind, sourcekinds, objectfiles, targetfile, opt) -- get the linker instance local instance, errors = linker.load(targetkind, sourcekinds) @@ -39,8 +44,8 @@ function sandbox_core_tool_linker.linkcmd(targetkind, sourcekinds, objectfiles, raise(errors) end - -- make command - return instance:linkcmd(objectfiles, targetfile, opt) + -- make arguments list + return instance:linkargv(objectfiles, targetfile, opt) end -- make link flags for the given target diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index 7f53818e4..b4fcacc6c 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -39,6 +39,7 @@ sandbox_os.arch = os.arch sandbox_os.exit = os.exit sandbox_os.date = os.date sandbox_os.time = os.time +sandbox_os.args = os.args sandbox_os.argv = os.argv sandbox_os.argw = os.argw sandbox_os.mtime = os.mtime diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index c477f8d8a..3aad4c642 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -133,7 +133,7 @@ function compiler:build(sourcefiles, targetfile, opt) -- make flags local flags = self:compflags(opt) if opt.target then - flags = flags .. " " .. (opt.target:linkflags()) + flags = table.join(flags, opt.target:linkflags()) end -- get target kind @@ -146,8 +146,8 @@ function compiler:build(sourcefiles, targetfile, opt) return sandbox.load(self:_tool().build, self:_tool(), sourcefiles, targetkind or "binary", targetfile, flags) end --- get the build command (compile and link) -function compiler:buildcmd(sourcefiles, targetfile, opt) +-- get the build arguments list (compile and link) +function compiler:buildargv(sourcefiles, targetfile, opt) -- init options opt = opt or {} @@ -155,7 +155,7 @@ function compiler:buildcmd(sourcefiles, targetfile, opt) -- make flags local flags = self:compflags(opt) if opt.target then - flags = flags .. " " .. (opt.target:linkflags()) + flags = table.join(flags, opt.target:linkflags()) end -- get target kind @@ -165,7 +165,12 @@ function compiler:buildcmd(sourcefiles, targetfile, opt) end -- get it - return self:_tool():buildcmd(sourcefiles, targetkind or "binary", targetfile, flags) + return self:_tool():buildargv(sourcefiles, targetkind or "binary", targetfile, flags) +end + +-- get the build command +function compiler:buildcmd(sourcefiles, targetfile, opt) + return os.args(table.join(self:buildargv(sourcefiles, targetfile, opt))) end -- compile the source files @@ -175,12 +180,17 @@ function compiler:compile(sourcefiles, objectfile, opt) opt = opt or {} -- compile it - return sandbox.load(self:_tool().compile, self:_tool(), sourcefiles, objectfile, opt.incdepfiles, (self:compflags(opt))) + return sandbox.load(self:_tool().compile, self:_tool(), sourcefiles, objectfile, opt.incdepfiles, self:compflags(opt)) +end + +-- get the compile arguments list +function compiler:compargv(sourcefiles, objectfile, opt) + return self:_tool():compargv(sourcefiles, objectfile, self:compflags(opt)) end -- get the compile command function compiler:compcmd(sourcefiles, objectfile, opt) - return self:_tool():compcmd(sourcefiles, objectfile, (self:compflags(opt))) + return os.args(table.join(self:compargv(sourcefiles, objectfile, opt))) end -- get the compling flags @@ -209,7 +219,7 @@ function compiler:compflags(opt) self._FLAGS = self._FLAGS or {} local flags_cached = self._FLAGS[key] if flags_cached then - return flags_cached[1], flags_cached[2] + return flags_cached end end @@ -244,16 +254,13 @@ function compiler:compflags(opt) -- add flags from the compiler self:_addflags_from_compiler(flags, targetkind) - -- make flags string - local flags_str = os.args(flags) - -- save flags if key then - self._FLAGS[key] = {flags_str, flags} + self._FLAGS[key] = flags end -- get it - return flags_str, flags + return flags end -- return module diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index c313c045b..9e83e3e3a 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -179,12 +179,17 @@ end -- link the target file function linker:link(objectfiles, targetfile, opt) - return sandbox.load(self:_tool().link, self:_tool(), table.concat(table.wrap(objectfiles), " "), self:_targetkind(), targetfile, (self:linkflags(opt))) + return sandbox.load(self:_tool().link, self:_tool(), table.wrap(objectfiles), self:_targetkind(), targetfile, self:linkflags(opt)) +end + +-- get the link arguments list +function linker:linkargv(objectfiles, targetfile, opt) + return self:_tool():linkargv(table.wrap(objectfiles), self:_targetkind(), targetfile, self:linkflags(opt)) end -- get the link command function linker:linkcmd(objectfiles, targetfile, opt) - return self:_tool():linkcmd(table.concat(table.wrap(objectfiles), " "), self:_targetkind(), targetfile, (self:linkflags(opt))) + return os.args(table.join(self:linkargv(objectfiles, targetfile, opt))) end -- get the link flags @@ -211,7 +216,7 @@ function linker:linkflags(opt) self._FLAGS = self._FLAGS or {} local flags_cached = self._FLAGS[key] if flags_cached then - return flags_cached[1], flags_cached[2] + return flags_cached end end @@ -256,11 +261,11 @@ function linker:linkflags(opt) -- save flags if key then - self._FLAGS[key] = {flags_str, flags} + self._FLAGS[key] = flags end -- get it - return flags_str, flags + return flags end -- return module diff --git a/xmake/modules/core/tools/ar.lua b/xmake/modules/core/tools/ar.lua index bce088fc3..bfbc8a577 100644 --- a/xmake/modules/core/tools/ar.lua +++ b/xmake/modules/core/tools/ar.lua @@ -49,14 +49,14 @@ function strip(self, level) return maps[level] end --- make the link command -function linkcmd(self, objectfiles, targetkind, targetfile, flags) +-- make the link arguments list +function linkargv(self, objectfiles, targetkind, targetfile, flags) -- check assert(targetkind == "static") -- make it - return format("%s %s %s %s", self:program(), flags, targetfile, objectfiles) + return self:program(), table.join(flags or {}, targetfile, objectfiles) end -- link the library file @@ -69,7 +69,7 @@ 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 -- extract the static library to object directory @@ -85,11 +85,11 @@ function extract(self, libraryfile, objectdir) local olddir = os.cd(objectdir) -- extract it - os.run("%s -x %s", self:program(), libraryfile) + os.runv(self:program(), {"-x", libraryfile}) -- check repeat object name local repeats = {} - local objectfiles = os.iorun("%s -t %s", self:program(), libraryfile) + local objectfiles = os.iorunv(self:program(), {"-t", libraryfile}) for _, objectfile in ipairs(objectfiles:split('\n')) do if repeats[objectfile] then raise("object name(%s) conflicts in library: %s", objectfile, libraryfile) diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 62d41abc3..3d510fb39 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -243,9 +243,9 @@ function nf_framework(self, framework) return {"-framework", framework} 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 @@ -255,11 +255,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 complie command -function _compcmd1(self, sourcefile, objectfile, flags) +-- make the complie arguments list +function _compargv1(self, sourcefile, objectfile, flags) -- get ccache local ccache = nil @@ -267,14 +267,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 or {}, "-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 @@ -287,7 +297,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 @@ -317,7 +327,7 @@ function _compile1(self, sourcefile, objectfile, incdepfile, flags) local tmpfile = os.tmpfile() -- generate it - os.run("%s -c -MM %s -o %s %s", self:program(), flags or "", tmpfile, sourcefile) + os.runv(self:program(), table.join("-c", "-MM", flags or {}, "-o", tmpfile, sourcefile)) -- translate it local results = {} @@ -338,14 +348,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/plugins/project/makefile/makefile.lua b/xmake/plugins/project/makefile/makefile.lua index e09b4edc1..09b6d2e0f 100644 --- a/xmake/plugins/project/makefile/makefile.lua +++ b/xmake/plugins/project/makefile/makefile.lua @@ -103,7 +103,7 @@ function _make_object(makefile, target, sourcefile, objectfile) local program = platform.tool(sourcekind) -- get complier flags - local compflags = compiler.compflags(sourcefile, {target = target, sourcekind = sourcekind}) + local compflags = os.args(compiler.compflags(sourcefile, {target = target, sourcekind = sourcekind})) -- make command local command = compiler.compcmd(sourcefile, objectfile, {target = target}) @@ -115,7 +115,10 @@ function _make_object(makefile, target, sourcefile, objectfile) end -- replace program to $(XX) - p, e = command:find(program, 1, true) + p, e = command:find("\"" .. program .. "\"", 1, true) + if not p then + p, e = command:find(program, 1, true) + end if p then command = format("%s$(%s)%s", command:sub(1, p - 1), sourcekind:upper(), command:sub(e + 1)) end @@ -164,7 +167,7 @@ function _make_single_object(makefile, target, sourcekind, sourcebatch) local program = platform.tool(sourcekind) -- get complier flags - local compflags = compiler.compflags(sourcefiles, {target = target, sourcekind = sourcekind}) + local compflags = os.args(compiler.compflags(sourcefiles, {target = target, sourcekind = sourcekind})) -- make command local command = compiler.compcmd(sourcefiles, objectfiles, {target = target, sourcekind = sourcekind}) @@ -257,13 +260,16 @@ function _make_target(makefile, target) local command = target:linkcmd() -- replace linkflags to $(XX) - local p, e = command:find(target:linkflags(), 1, true) + local p, e = command:find(os.args(target:linkflags()), 1, true) if p then command = format("%s$(%s_%s)%s", command:sub(1, p - 1), target:name(), (linkerkind:upper():gsub('%-', '_')), command:sub(e + 1)) end -- replace program to $(XX) - p, e = command:find(program, 1, true) + p, e = command:find("\"" .. program .. "\"", 1, true) + if not p then + p, e = command:find(program, 1, true) + end if p then command = format("%s$(%s)%s", command:sub(1, p - 1), (linkerkind:upper():gsub('%-', '_')), command:sub(e + 1)) end @@ -346,9 +352,9 @@ function _make_all(makefile) for targetname, target in pairs(project.targets()) do if not target:isphony() then for sourcekind, sourcebatch in pairs(target:sourcebatches()) do - makefile:print("%s_%s=%s", targetname, sourcekind:upper(), compiler.compflags(sourcebatch.sourcefiles, {target = target, sourcekind = sourcekind})) + makefile:print("%s_%s=%s", targetname, sourcekind:upper(), os.args(compiler.compflags(sourcebatch.sourcefiles, {target = target, sourcekind = sourcekind}))) end - makefile:print("%s_%s=%s", targetname, target:linker():kind():upper(), target:linkflags()) + makefile:print("%s_%s=%s", targetname, target:linker():kind():upper(), os.args(target:linkflags())) end end makefile:print("") |
