summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-09-02 22:52:54 +0800
committerruki <[email protected]>2019-09-02 11:17:27 +0800
commited6d5a86251d32c2b73dd0ca382b68aeeddcfee1 (patch)
tree49254ef95e202687616432695a0d990fe48aff9b
parent7f3180689e0acb358fd3b44717580983f247d49e (diff)
improve to pass progress info to build target
-rw-r--r--xmake/actions/build/build.lua49
-rw-r--r--xmake/actions/build/kinds/binary.lua11
-rw-r--r--xmake/actions/build/kinds/object.lua9
-rw-r--r--xmake/actions/build/kinds/shared.lua11
-rw-r--r--xmake/actions/build/kinds/static.lua11
-rw-r--r--xmake/languages/rust/xmake.lua3
-rw-r--r--xmake/rules/rust/build/target.lua78
-rw-r--r--xmake/rules/rust/xmake.lua4
8 files changed, 47 insertions, 129 deletions
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua
index 84b5dfa5e..60a17bccb 100644
--- a/xmake/actions/build/build.lua
+++ b/xmake/actions/build/build.lua
@@ -33,40 +33,41 @@ function _clean_target(target)
end
-- do build the given target
-function _do_build_target(target)
+function _do_build_target(target, opt)
-- build target
if not target:isphony() then
- import("kinds." .. target:targetkind()).build(target, _g)
+ import("kinds." .. target:targetkind()).build(target, opt)
end
end
-- on build the given target
-function _on_build_target(target)
-
- -- has been disabled?
- if target:get("enabled") == false then
- return
- end
+function _on_build_target(target, opt)
-- build target with rules
local done = false
for _, r in ipairs(target:orderules()) do
local on_build = r:script("build")
if on_build then
- on_build(target, {origin = _do_build_target})
+ on_build(target, opt)
done = true
end
end
if done then return end
-- do build
- _do_build_target(target)
+ _do_build_target(target, opt)
end
-- build the given target
function _build_target(target)
+ -- has been disabled?
+ if target:get("enabled") == false then
+ _g.targetindex = _g.targetindex + 1
+ return
+ end
+
-- enter the environments of the target packages
local oldenvs = {}
for name, values in pairs(target:pkgenvs()) do
@@ -74,19 +75,16 @@ function _build_target(target)
os.addenv(name, unpack(values))
end
+ -- compute the progress range
+ local progress = {}
+ progress.start = (_g.targetindex * 100) / _g.targetcount
+ progress.stop = ((_g.targetindex + 1) * 100) / _g.targetcount
+
-- the target scripts
local scripts =
{
function (target)
- -- has been disabled?
- if target:get("enabled") == false then
- return
- end
-
- -- get progress
- local progress = _g.targetindex * 100 / _g.targetcount
-
-- do before build for target
local before_build = target:script("build_before")
if before_build then
@@ -101,16 +99,15 @@ function _build_target(target)
end
end
end
- , target:script("build", _on_build_target)
, function (target)
- -- has been disabled?
- if target:get("enabled") == false then
- return
+ -- do build
+ local on_build = target:script("build", _on_build_target)
+ if on_build then
+ on_build(target, {origin = _do_build_target, progress = progress})
end
-
- -- get progress
- local progress = (_g.targetindex + 1) * 100 / _g.targetcount
+ end
+ , function (target)
-- do after build for target
local after_build = target:script("build_after")
@@ -137,7 +134,7 @@ function _build_target(target)
for i = 1, 3 do
local script = scripts[i]
if script ~= nil then
- script(target, {origin = (i == 2 and _do_build_target or nil)})
+ script(target)
end
end
diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua
index 7a7683d02..0d242108b 100644
--- a/xmake/actions/build/kinds/binary.lua
+++ b/xmake/actions/build/kinds/binary.lua
@@ -71,7 +71,7 @@ function _do_link_target(target, opt)
local verbose = option.get("verbose")
-- trace progress into
- cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", opt.progress)
+ cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", opt.progress.stop)
if verbose then
cprint("${dim color.build.target}linking.$(mode) %s", path.filename(targetfile))
else
@@ -150,14 +150,11 @@ function _link_target(target, opt)
end
-- build binary target
-function build(target, buildinfo)
+function build(target, opt)
-- build objects
- object.build(target, buildinfo)
-
- -- get progress
- local progress = (buildinfo.targetindex + 1) * 100 / buildinfo.targetcount
+ object.build(target, opt)
-- link target
- _link_target(target, {progress = progress})
+ _link_target(target, opt)
end
diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua
index 70d4dabc6..8cf9bba99 100644
--- a/xmake/actions/build/kinds/object.lua
+++ b/xmake/actions/build/kinds/object.lua
@@ -145,14 +145,9 @@ function build_sourcefiles(target, sourcebatches, opt)
end
-- build objects for the given target
-function build(target, buildinfo)
-
- -- compute the progress range
- local progress = {}
- progress.start = (buildinfo.targetindex * 100) / buildinfo.targetcount
- progress.stop = ((buildinfo.targetindex + 1) * 100) / buildinfo.targetcount
+function build(target, opt)
-- build source files
- build_sourcefiles(target, target:sourcebatches(), {progress = progress})
+ build_sourcefiles(target, target:sourcebatches(), opt)
end
diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua
index 5a5846a58..f6a8d6161 100644
--- a/xmake/actions/build/kinds/shared.lua
+++ b/xmake/actions/build/kinds/shared.lua
@@ -84,7 +84,7 @@ function _do_link_target(target, opt)
local verbose = option.get("verbose")
-- trace progress info
- cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", opt.progress)
+ cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", opt.progress.stop)
if verbose then
cprint("${dim color.build.target}linking.$(mode) %s", path.filename(targetfile))
else
@@ -163,14 +163,11 @@ function _link_target(target, opt)
end
-- build shared target
-function build(target, buildinfo)
+function build(target, opt)
-- build objects
- object.build(target, buildinfo)
-
- -- get progress
- local progress = (buildinfo.targetindex + 1) * 100 / buildinfo.targetcount
+ object.build(target, opt)
-- link target
- _link_target(target, {progress = progress})
+ _link_target(target, opt)
end
diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua
index 1e4f30825..c9a6987dd 100644
--- a/xmake/actions/build/kinds/static.lua
+++ b/xmake/actions/build/kinds/static.lua
@@ -80,7 +80,7 @@ function _do_link_target(target, opt)
local verbose = option.get("verbose")
-- trace progress info
- cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", opt.progress)
+ cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", opt.progress.stop)
if verbose then
cprint("${dim color.build.target}archiving.$(mode) %s", path.filename(targetfile))
else
@@ -159,14 +159,11 @@ function _link_target(target, opt)
end
-- build static target
-function build(target, buildinfo)
+function build(target, opt)
-- build objects
- object.build(target, buildinfo)
-
- -- get progress
- local progress = (buildinfo.targetindex + 1) * 100 / buildinfo.targetcount
+ object.build(target, opt)
-- link target
- _link_target(target, {progress = progress})
+ _link_target(target, opt)
end
diff --git a/xmake/languages/rust/xmake.lua b/xmake/languages/rust/xmake.lua
index 977f815df..d5a386d09 100644
--- a/xmake/languages/rust/xmake.lua
+++ b/xmake/languages/rust/xmake.lua
@@ -39,6 +39,9 @@ language("rust")
-- set mixing kinds
set_mixingkinds("rc")
+ -- add rules
+ add_rules("rust")
+
-- on load
on_load("load")
diff --git a/xmake/rules/rust/build/target.lua b/xmake/rules/rust/build/target.lua
index d10220a5e..2acff260e 100644
--- a/xmake/rules/rust/build/target.lua
+++ b/xmake/rules/rust/build/target.lua
@@ -26,79 +26,11 @@ import("core.tool.compiler")
import("core.project.depend")
-- build the source files
-function main(target, sourcebatch, opt)
-
- -- is verbose?
- local verbose = option.get("verbose")
-
- -- get progress range
- local progress = assert(opt.progress, "no progress!")
-
- -- get source files and kind
- local sourcefiles = sourcebatch.sourcefiles
- local sourcekind = sourcebatch.sourcekind
-
- -- get object file
- local objectfile = target:objectfile(path.join(path.directory(sourcefiles[1]), "__go__"))
-
- -- get depend file
- local dependfile = target:dependfile(objectfile)
-
- -- remove the object files in sourcebatch
- local objectfiles_set = hashset.from(sourcebatch.objectfiles)
- for idx, file in irpairs(target:objectfiles()) do
- if objectfiles_set:has(file) then
- table.remove(target:objectfiles(), idx)
- end
- end
-
- -- add object file
- table.insert(target:objectfiles(), objectfile)
-
- -- load compiler
- local compinst = compiler.load(sourcekind, {target = target})
-
- -- get compile flags
- local compflags = compinst:compflags({target = target})
-
- -- load dependent info
- local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
-
- -- need build this object?
- local depvalues = {compinst:program(), compflags}
- if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then
- return
- end
-
- -- trace progress info
- for index, sourcefile in ipairs(sourcefiles) do
-
- -- calculate progress
- local progress_now = progress.start + ((index - 1) * (progress.stop - progress.start)) / #sourcefiles
-
- -- trace progress info
- cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", progress_now)
- if verbose then
- cprint("${dim color.build.object}compiling.$(mode) %s", sourcefile)
- else
- cprint("${color.build.object}compiling.$(mode) %s", sourcefile)
- end
- end
-
- -- trace verbose info
- if verbose then
- print(compinst:compcmd(sourcefiles, objectfile, {compflags = compflags}))
- end
-
- -- flush io buffer to update progress info
- io.flush()
+function build_sourcefiles(target, sourcebatch, opt)
+end
- -- compile it
- dependinfo.files = {}
- assert(compinst:compile(sourcefiles, objectfile, {dependinfo = dependinfo, compflags = compflags}))
+-- build target
+function main(target, opt)
- -- update files and values to the dependent file
- dependinfo.values = depvalues
- table.join2(dependinfo.files, sourcefiles)
- depend.save(dependinfo, dependfile)
+ print(opt)
end
diff --git a/xmake/rules/rust/xmake.lua b/xmake/rules/rust/xmake.lua
index 9b6de4b8f..3d88f2c96 100644
--- a/xmake/rules/rust/xmake.lua
+++ b/xmake/rules/rust/xmake.lua
@@ -21,8 +21,8 @@
-- define rule: rust.build
rule("rust.build")
set_extensions(".rs")
- on_build_files(function (target, sourcebatch, opt)
- import("build.target")(target, sourcebatch, opt)
+ on_build(function (target, opt)
+ import("build.target")(target, opt)
end)
-- define rule: cpp