diff options
| author | ruki <[email protected]> | 2017-02-13 22:42:59 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-02-13 22:42:59 +0800 |
| commit | f7eaf51c4cad7d94989e130de2172df2cbc74193 (patch) | |
| tree | 71436cd40bc3766d13165969025fc95bd7bb24f2 | |
| parent | a2b7b07658824d024f8d54bc73f4687c34179e49 (diff) | |
add source batches for building
| -rw-r--r-- | docs/README.md | 2 | ||||
| -rw-r--r-- | docs/manual.md | 2 | ||||
| -rw-r--r-- | docs/plugins.md | 2 | ||||
| -rwxr-xr-x | xmake/actions/build/kinds/binary.lua | 8 | ||||
| -rwxr-xr-x | xmake/actions/build/kinds/object.lua | 41 | ||||
| -rwxr-xr-x | xmake/actions/build/kinds/shared.lua | 8 | ||||
| -rwxr-xr-x | xmake/actions/build/kinds/static.lua | 8 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 37 |
8 files changed, 79 insertions, 29 deletions
diff --git a/docs/README.md b/docs/README.md index 75b13c5d7..2836cfc08 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,5 +1,5 @@ --- -search: english +search: en --- # A make-like build utility based on Lua diff --git a/docs/manual.md b/docs/manual.md index 4386fdf74..bf6d73a4f 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -1,5 +1,5 @@ --- -search: english +search: en --- ## Condition diff --git a/docs/plugins.md b/docs/plugins.md index 9966f7b22..bbeb90f46 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -1,5 +1,5 @@ --- -search: english +search: en --- ## Plugin Development diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua index 254a98f62..f231fabca 100755 --- a/xmake/actions/build/kinds/binary.lua +++ b/xmake/actions/build/kinds/binary.lua @@ -28,10 +28,10 @@ import("core.tool.linker") import("object") -- build binary target -function build(target, g) +function build(target, buildinfo) - -- build all objects - object.buildall(target, g) + -- build objects + object.build(target, buildinfo) -- expand object files with *.o/obj local objectfiles = {} @@ -53,7 +53,7 @@ function build(target, g) local verbose = option.get("verbose") -- trace percent into - cprintf("${green}[%02d%%]:${clear} ", (g.targetindex + 1) * 100 / g.targetcount) + cprintf("${green}[%02d%%]:${clear} ", (buildinfo.targetindex + 1) * 100 / buildinfo.targetcount) if verbose then cprint("${dim magenta}linking.$(mode) %s", path.filename(targetfile)) else diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua index 431f12325..e9cf4c40b 100755 --- a/xmake/actions/build/kinds/object.lua +++ b/xmake/actions/build/kinds/object.lua @@ -76,23 +76,18 @@ function _build_from_static(target, sourcefile, objectfile, percent) end -- build object -function _build(target, g, index) - - -- the object and source files - local objectfiles = target:objectfiles() - local sourcefiles = target:sourcefiles() - local incdepfiles = target:incdepfiles() +function _build_object(target, buildinfo, index, sourcebatch) -- get the object and source with the given index - local sourcefile = sourcefiles[index] - local objectfile = objectfiles[index] - local incdepfile = incdepfiles[index] + local sourcefile = sourcebatch[index][1] + local objectfile = sourcebatch[index][2] + local incdepfile = sourcebatch[index][3] -- get the source file type local filetype = path.extension(sourcefile):lower() -- calculate percent - local percent = ((g.targetindex + (index - 1) / #objectfiles) * 100 / g.targetcount) + local percent = ((buildinfo.targetindex + (_g.sourceindex + index - 1) / _g.sourcecount) * 100 / buildinfo.targetcount) -- build the object for the *.o/obj source makefile if filetype == ".o" or filetype == ".obj" then @@ -170,15 +165,15 @@ function _build(target, g, index) compiler.compile(sourcefile, objectfile, incdepfile, target) end --- build objects for the given target -function buildall(target, g) +-- 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") -- make objects local index = 1 - local total = #target:objectfiles() + local total = #sourcebatch local tasks = {} local procs = {} repeat @@ -245,7 +240,7 @@ function buildall(target, g) os.cd(curdir) -- build object - _build(target, g, index) + _build_object(target, buildinfo, index, sourcebatch) end) @@ -266,5 +261,23 @@ function buildall(target, g) end until #tasks == 0 + + -- update object index + _g.sourceindex = _g.sourceindex + #sourcebatch +end + +-- build objects for the given target +function build(target, buildinfo) + + -- init source index and count + _g.sourceindex = 0 + _g.sourcecount = target:sourcecount() + + -- build source batches + for sourcekind, sourcebatch in pairs(target:sourcebatches()) do + + -- build objects + _build_objects(target, buildinfo, sourcekind, sourcebatch) + end end diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua index 42d52c9c2..718a685a8 100755 --- a/xmake/actions/build/kinds/shared.lua +++ b/xmake/actions/build/kinds/shared.lua @@ -28,10 +28,10 @@ import("core.tool.linker") import("object") -- build binary target -function build(target, g) +function build(target, buildinfo) - -- build all objects - object.buildall(target, g) + -- build objects + object.build(target, buildinfo) -- make headers local srcheaders, dstheaders = target:headerfiles() @@ -66,7 +66,7 @@ function build(target, g) local verbose = option.get("verbose") -- trace percent info - cprintf("${green}[%02d%%]:${clear} ", (g.targetindex + 1) * 100 / g.targetcount) + cprintf("${green}[%02d%%]:${clear} ", (buildinfo.targetindex + 1) * 100 / buildinfo.targetcount) if verbose then cprint("${dim magenta}linking.$(mode) %s", path.filename(targetfile)) else diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua index 006400405..4df049a47 100755 --- a/xmake/actions/build/kinds/static.lua +++ b/xmake/actions/build/kinds/static.lua @@ -28,10 +28,10 @@ import("core.tool.archiver") import("object") -- build binary target -function build(target, g) +function build(target, buildinfo) - -- build all objects - object.buildall(target, g) + -- build objects + object.build(target, buildinfo) -- make headers local srcheaders, dstheaders = target:headerfiles() @@ -66,7 +66,7 @@ function build(target, g) local verbose = option.get("verbose") -- trace percent info - cprintf("${green}[%02d%%]:${clear} ", (g.targetindex + 1) * 100 / g.targetcount) + cprintf("${green}[%02d%%]:${clear} ", (buildinfo.targetindex + 1) * 100 / buildinfo.targetcount) if verbose then cprint("${dim magenta}archiving.$(mode) %s", path.filename(targetfile)) else diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index ef66558e4..03d3cc33d 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -447,6 +447,43 @@ function target:sourcekinds() return sourcekinds end +-- get source count +function target:sourcecount() + return #self:sourcefiles() +end + +-- get source batches +function target:sourcebatches() + + -- cached? return it directly + if self._SOURCEBATCHES then + return self._SOURCEBATCHES + end + + -- the object and source files + local objectfiles = self:objectfiles() + local sourcefiles = self:sourcefiles() + local incdepfiles = self:incdepfiles() + assert(objectfiles and sourcefiles and incdepfiles) + + -- make source batches for each source kinds + local sourcebatches = {} + for index, sourcefile in ipairs(sourcefiles) do + + -- 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]}) + end + + -- cache it + self._SOURCEBATCHES = sourcebatches + + -- ok? + return sourcebatches +end -- return module return target |
