diff options
| author | ruki <[email protected]> | 2017-02-14 10:53:05 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-02-14 10:53:13 +0800 |
| commit | 7f135386a31972e4f4e486ae5854115b2e1af5a2 (patch) | |
| tree | 6a8b9329f3209c7cc72cb7aaac0a581480eb1f93 | |
| parent | 5e23aa6f9344b21dee98ad3fad9182808d690485 (diff) | |
select feature for compiler
| -rwxr-xr-x | xmake/actions/build/kinds/object.lua | 73 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 15 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/compiler.lua | 16 | ||||
| -rw-r--r-- | xmake/core/tool/builder.lua | 10 | ||||
| -rwxr-xr-x | xmake/tools/cl.lua | 9 | ||||
| -rwxr-xr-x | xmake/tools/gcc.lua | 10 | ||||
| -rwxr-xr-x | xmake/tools/go.lua | 34 | ||||
| -rwxr-xr-x | xmake/tools/ml.lua | 9 | ||||
| -rw-r--r-- | xmake/tools/swiftc.lua | 9 |
9 files changed, 135 insertions, 50 deletions
diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua index e9cf4c40b..fdcf6f00e 100755 --- a/xmake/actions/build/kinds/object.lua +++ b/xmake/actions/build/kinds/object.lua @@ -79,9 +79,9 @@ end function _build_object(target, buildinfo, index, sourcebatch) -- get the object and source with the given index - local sourcefile = sourcebatch[index][1] - local objectfile = sourcebatch[index][2] - local incdepfile = sourcebatch[index][3] + local sourcefile = sourcebatch.sourcefiles[index] + local objectfile = sourcebatch.objectfiles[index] + local incdepfile = sourcebatch.incdepfiles[index] -- get the source file type local filetype = path.extension(sourcefile):lower() @@ -161,19 +161,16 @@ function _build_object(target, buildinfo, index, sourcebatch) print(compiler.compcmd(sourcefile, objectfile, target)) end - -- complie it and enable multitasking + -- complie it compiler.compile(sourcefile, objectfile, incdepfile, target) end --- build objects from the given source batch -function _build_objects(target, buildinfo, sourcekind, sourcebatch) - - -- get the max job count - local jobs = tonumber(option.get("jobs") or "4") +-- build each objects from the given source batch +function _build_objects_foreach(target, buildinfo, sourcekind, sourcebatch, jobs) -- make objects local index = 1 - local total = #sourcebatch + local total = #sourcebatch.sourcefiles local tasks = {} local procs = {} repeat @@ -263,7 +260,45 @@ function _build_objects(target, buildinfo, sourcekind, sourcebatch) until #tasks == 0 -- update object index - _g.sourceindex = _g.sourceindex + #sourcebatch + _g.sourceindex = _g.sourceindex + #sourcebatch.sourcefiles +end + +-- build multiple objects at the same time from the given source batch +function _build_objects_multiple(target, buildinfo, sourcekind, sourcebatch, jobs) + + -- is verbose? + local verbose = option.get("verbose") + + -- get source and object files + local sourcefiles = sourcebatch.sourcefiles + local objectfiles = sourcebatch.objectfiles + local incdepfiles = sourcebatch.incdepfiles + + -- trace percent info + for index, sourcefile in ipairs(sourcefiles) do + + -- calculate percent + local percent = ((buildinfo.targetindex + (_g.sourceindex + index - 1) / _g.sourcecount) * 100 / buildinfo.targetcount) + + -- trace percent info + cprintf("${green}[%02d%%]:${clear} ", percent) + if verbose then + cprint("${dim}%scompiling.$(mode) %s", ifelse(config.get("ccache"), "ccache ", ""), sourcefile) + else + print("%scompiling.$(mode) %s", ifelse(config.get("ccache"), "ccache ", ""), sourcefile) + end + end + + -- trace verbose info + if verbose then + print(compiler.compcmd(sourcefiles, "xxx.o", target, sourcekind)) + end + + -- complie them + compiler.compile(sourcefiles, "xxx.o", incdepfiles, target, sourcekind) + + -- update object index + _g.sourceindex = _g.sourceindex + #sourcebatch.sourcefiles end -- build objects for the given target @@ -273,11 +308,23 @@ function build(target, buildinfo) _g.sourceindex = 0 _g.sourcecount = target:sourcecount() + -- get the max job count + local jobs = tonumber(option.get("jobs") or "4") + -- build source batches for sourcekind, sourcebatch in pairs(target:sourcebatches()) do - -- build objects - _build_objects(target, buildinfo, sourcekind, sourcebatch) + -- support to compile multiple objects at the same time? + if compiler.feature(sourcekind, "compile:multifiles") then + + -- build multiple objects + _build_objects_multiple(target, buildinfo, sourcekind, sourcebatch, jobs) + + else + + -- build each objects + _build_objects_foreach(target, buildinfo, sourcekind, sourcebatch, jobs) + end end end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 03d3cc33d..3c205993b 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -473,9 +473,18 @@ function target:sourcebatches() -- get source kind local sourcekind = language.sourcekind_of(sourcefile) - -- add source and object file to this batch - sourcebatches[sourcekind] = sourcebatches[sourcekind] or {} - table.insert(sourcebatches[sourcekind], {sourcefile, objectfiles[index], incdepfiles[index]}) + -- make this batch + local sourcebatch = sourcebatches[sourcekind] or {sourcefiles = {}, objectfiles = {}, incdepfiles = {}} + sourcebatches[sourcekind] = sourcebatch + + -- add source file to this batch + table.insert(sourcebatch.sourcefiles, sourcefile) + + -- add object file to this batch + table.insert(sourcebatch.objectfiles, objectfiles[index]) + + -- add incdep file to this batch + table.insert(sourcebatch.incdepfiles, incdepfiles[index]) end -- cache it diff --git a/xmake/core/sandbox/modules/import/core/tool/compiler.lua b/xmake/core/sandbox/modules/import/core/tool/compiler.lua index a3ae9d69b..3cf003be3 100644 --- a/xmake/core/sandbox/modules/import/core/tool/compiler.lua +++ b/xmake/core/sandbox/modules/import/core/tool/compiler.lua @@ -32,8 +32,21 @@ local compiler = require("tool/compiler") local raise = require("sandbox/modules/raise") local assert = require("sandbox/modules/assert") +-- get the feature of compiler +function sandbox_core_tool_compiler.feature(sourcekind, name) + + -- get the compiler instance + local instance, errors = compiler.load(sourcekind) + if not instance then + raise(errors) + end + + -- get feature + return instance:feature(name) +end + -- make command for compiling source file -function sandbox_core_tool_compiler.compcmd(sourcefile, objectfile, target, sourcekind) +function sandbox_core_tool_compiler.compcmd(sourcefiles, objectfile, target, sourcekind) -- get source kind if only one source file if not sourcekind and type(sourcefiles) == "string" then @@ -71,7 +84,6 @@ function sandbox_core_tool_compiler.compile(sourcefiles, objectfile, incdepfiles end end --- TODO modify: compflags(sourcekind, target) -- make compiling flags for the given target function sandbox_core_tool_compiler.compflags(sourcefiles, target, sourcekind) diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index fe0af6af9..0cee9be22 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -225,6 +225,16 @@ function builder:get(name) return self:_tool().get(name) end +-- get feature of the tool +function builder:feature(name) + + -- get it + local features = self:_tool().get("features") + if features then + return features[name] + end +end + -- check the given flags function builder:check(flags) diff --git a/xmake/tools/cl.lua b/xmake/tools/cl.lua index 12016b421..1143bf8da 100755 --- a/xmake/tools/cl.lua +++ b/xmake/tools/cl.lua @@ -79,6 +79,11 @@ function init(shellname) , ["-fsanitize=address"] = "" } + -- init features + _g.features = + { + ["compile:multifiles"] = false + } end -- get the property @@ -289,7 +294,7 @@ end function compcmd(sourcefiles, objectfile, flags) -- only support single source file now - assert(type(sourcefiles) == "string", "not support") + assert(type(sourcefiles) ~= "table", "'compile:multifiles' not support!") -- for only single source file return _compcmd1(sourcefiles, objectfile, flags) @@ -299,7 +304,7 @@ end function compile(sourcefiles, objectfile, incdepfiles, flags) -- only support single source file now - assert(type(sourcefiles) == "string", "not support") + assert(type(sourcefiles) ~= "table", "'compile:multifiles' not support!") -- for only single source file _compile1(sourcefiles, objectfile, incdepfiles, flags) diff --git a/xmake/tools/gcc.lua b/xmake/tools/gcc.lua index 0f555245d..0f8d5fbfa 100755 --- a/xmake/tools/gcc.lua +++ b/xmake/tools/gcc.lua @@ -65,6 +65,12 @@ function init(shellname, kind) , ["-S"] = "-S" } + + -- init features + _g.features = + { + ["compile:multifiles"] = false + } end -- get the property @@ -351,7 +357,7 @@ end function compcmd(sourcefiles, objectfile, flags) -- only support single source file now - assert(type(sourcefiles) == "string", "not support") + assert(type(sourcefiles) ~= "table", "'compile:multifiles' not support!") -- for only single source file return _compcmd1(sourcefiles, objectfile, flags) @@ -361,7 +367,7 @@ end function compile(sourcefiles, objectfile, incdepfiles, flags) -- only support single source file now - assert(type(sourcefiles) == "string", "not support") + assert(type(sourcefiles) ~= "table", "'compile:multifiles' not support!") -- for only single source file _compile1(sourcefiles, objectfile, incdepfiles, flags) diff --git a/xmake/tools/go.lua b/xmake/tools/go.lua index 1703862b1..03997d889 100755 --- a/xmake/tools/go.lua +++ b/xmake/tools/go.lua @@ -39,6 +39,12 @@ function init(shellname, kind) -- init arflags _g.arflags = { "grcP" } + + -- init features + _g.features = + { + ["compile:multifiles"] = true + } end -- get the property @@ -107,40 +113,20 @@ function archive(objectfiles, targetfile, flags) end -- make the complie command -function _compcmd1(sourcefile, objectfile, flags) +function compcmd(sourcefiles, objectfile, flags) -- make it - return format("%s tool compile %s -o %s %s", _g.shellname, flags, objectfile, sourcefile) + return format("%s tool compile %s -o %s %s", _g.shellname, flags, objectfile, table.concat(table.wrap(sourcefiles), " ")) end -- complie the source file -function _compile1(sourcefile, objectfile, incdepfile, flags) +function compile(sourcefiles, objectfile, incdepfiles, flags) -- ensure the object directory os.mkdir(path.directory(objectfile)) -- compile it - os.run(_compcmd1(sourcefile, objectfile, flags)) -end - --- make the complie command -function compcmd(sourcefiles, objectfile, flags) - - -- only support single source file now - assert(type(sourcefiles) == "string", "not support") - - -- for only single source file - return _compcmd1(sourcefiles, objectfile, flags) -end - --- complie the source file -function compile(sourcefiles, objectfile, incdepfiles, flags) - - -- only support single source file now - assert(type(sourcefiles) == "string", "not support") - - -- for only single source file - _compile1(sourcefiles, objectfile, incdepfiles, flags) + os.run(compcmd(sourcefiles, objectfile, flags)) end -- check the given flags diff --git a/xmake/tools/ml.lua b/xmake/tools/ml.lua index 9a5f6ae7e..f866ba629 100755 --- a/xmake/tools/ml.lua +++ b/xmake/tools/ml.lua @@ -55,6 +55,11 @@ function init(shellname) , ["-fsanitize=address"] = "" } + -- init features + _g.features = + { + ["compile:multifiles"] = false + } end -- get the property @@ -123,7 +128,7 @@ end function compcmd(sourcefiles, objectfile, flags) -- only support single source file now - assert(type(sourcefiles) == "string", "not support") + assert(type(sourcefiles) ~= "table", "'compile:multifiles' not support!") -- for only single source file return _compcmd1(sourcefiles, objectfile, flags) @@ -133,7 +138,7 @@ end function compile(sourcefiles, objectfile, incdepfiles, flags) -- only support single source file now - assert(type(sourcefiles) == "string", "not support") + assert(type(sourcefiles) ~= "table", "'compile:multifiles' not support!") -- for only single source file _compile1(sourcefiles, objectfile, incdepfiles, flags) diff --git a/xmake/tools/swiftc.lua b/xmake/tools/swiftc.lua index f5dec36aa..54441f34d 100644 --- a/xmake/tools/swiftc.lua +++ b/xmake/tools/swiftc.lua @@ -59,6 +59,11 @@ function init(shellname) , ["-fsanitize=address"] = "" } + -- init features + _g.features = + { + ["compile:multifiles"] = false + } end -- get the property @@ -205,7 +210,7 @@ end function compcmd(sourcefiles, objectfile, flags) -- only support single source file now - assert(type(sourcefiles) == "string", "not support") + assert(type(sourcefiles) ~= "table", "'compile:multifiles' not support!") -- for only single source file return _compcmd1(sourcefiles, objectfile, flags) @@ -215,7 +220,7 @@ end function compile(sourcefiles, objectfile, incdepfiles, flags) -- only support single source file now - assert(type(sourcefiles) == "string", "not support") + assert(type(sourcefiles) ~= "table", "'compile:multifiles' not support!") -- for only single source file _compile1(sourcefiles, objectfile, incdepfiles, flags) |
