summaryrefslogtreecommitdiff
path: root/xmake/actions/build/build.lua
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/actions/build/build.lua')
-rw-r--r--xmake/actions/build/build.lua79
1 files changed, 35 insertions, 44 deletions
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua
index cfbd75880..865d7e24c 100644
--- a/xmake/actions/build/build.lua
+++ b/xmake/actions/build/build.lua
@@ -35,27 +35,18 @@ function _clean_target(target)
end
end
--- do build the given target
-function _do_build_target(target, opt)
-
- -- build target
- if not target:isphony() then
- import("kinds." .. target:targetkind()).build(target, opt)
- end
-end
-
--- add builtin build jobs
-function _add_buildjobs_builtin(buildjobs, rootjob, target)
+-- add builtin batch jobs
+function _add_batchjobs_builtin(batchjobs, rootjob, target)
-- uses the rules script?
local job
- for _, r in irpairs(target:orderules()) do -- reverse rules order for buildjobs:addjob()
+ for _, r in irpairs(target:orderules()) do -- reverse rules order for batchjobs:addjob()
local script = r:script("build")
if script then
- if r:extraconf("build", "batch") then -- TODO extraconf/rule
- job = assert(script(target, buildjobs, {rootjob = job or rootjob}), "rule(%s):on_build(): no returned job!", r:name())
+ if r:extraconf("build", "batch") then
+ job = assert(script(target, batchjobs, {rootjob = job or rootjob}), "rule(%s):on_build(): no returned job!", r:name())
else
- job = buildjobs:addjob(r:name() .. "/build", function (index, total)
+ job = batchjobs:addjob("rule/" .. r:name() .. "/build", function (index, total)
script(target, {progress = (index * 100) / total})
end, job or rootjob)
end
@@ -63,20 +54,20 @@ function _add_buildjobs_builtin(buildjobs, rootjob, target)
end
-- uses the builtin target script
- if not job then
- -- _do_build_target(target, opt)
+ if not job and not target:isphony() then
+ job = import("kinds." .. target:targetkind(), {anonymous = true})(batchjobs, rootjob, target)
end
- return job
+ return job or rootjob
end
--- add build jobs
-function _add_buildjobs(buildjobs, rootjob, target)
+-- add batch jobs
+function _add_batchjobs(batchjobs, rootjob, target)
local job
local script = target:script("build")
if not script then
- -- do builtin build jobs
- job = _add_buildjobs_builtin(buildjobs, rootjob, target)
+ -- do builtin batch jobs
+ job = _add_batchjobs_builtin(batchjobs, rootjob, target)
elseif target:extraconf("build", "batch") then
-- do custom batch script
-- e.g.
@@ -87,7 +78,7 @@ function _add_buildjobs(buildjobs, rootjob, target)
-- end, opt.rootjob)
-- end, {batch = true})
--
- job = assert(script(target, buildjobs, {rootjob = rootjob}), "target(%s):on_build(): no returned job!", target:name())
+ job = assert(script(target, batchjobs, {rootjob = rootjob}), "target(%s):on_build(): no returned job!", target:name())
else
-- do custom script directly
-- e.g.
@@ -97,15 +88,15 @@ function _add_buildjobs(buildjobs, rootjob, target)
-- print("build it")
-- end)
--
- job = buildjobs:addjob(target:name() .. "/build", function (index, total)
+ job = batchjobs:addjob(target:name() .. "/build", function (index, total)
script(target, {progress = (index * 100) / total})
end, rootjob)
end
return job
end
--- add build jobs for the given target
-function _add_buildjobs_for_target(buildjobs, rootjob, target)
+-- add batch jobs for the given target
+function _add_batchjobs_for_target(batchjobs, rootjob, target)
-- has been disabled?
if target:get("enabled") == false then
@@ -114,7 +105,7 @@ function _add_buildjobs_for_target(buildjobs, rootjob, target)
-- add after_build job for target
local oldenvs = {}
- local job_after_build = buildjobs:addjob(target:name() .. "/after_build", function (index, total)
+ local job_after_build = batchjobs:addjob(target:name() .. "/after_build", function (index, total)
-- do after_build
local progress = (index * 100) / total
@@ -135,11 +126,11 @@ function _add_buildjobs_for_target(buildjobs, rootjob, target)
end
end, rootjob)
- -- add build jobs for target, @note only on_build script support batch jobs
- local job_build = _add_buildjobs(buildjobs, job_after_build, target)
+ -- add batch jobs for target, @note only on_build script support batch jobs
+ local job_build = _add_batchjobs(batchjobs, job_after_build, target)
-- add before_build job for target
- local job_before_build = buildjobs:addjob(target:name() .. "/before_build", function (index, total)
+ local job_before_build = batchjobs:addjob(target:name() .. "/before_build", function (index, total)
-- enter the environments of the target packages
for name, values in pairs(target:pkgenvs()) do
@@ -168,19 +159,19 @@ function _add_buildjobs_for_target(buildjobs, rootjob, target)
return job_before_build
end
--- add build jobs for the given target and deps
-function _add_buildjobs_for_target_and_deps(buildjobs, rootjob, inserted, target)
+-- add batch jobs for the given target and deps
+function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, inserted, target)
if not inserted[target:name()] then
- rootjob = _add_buildjobs_for_target(buildjobs, rootjob, target)
+ rootjob = _add_batchjobs_for_target(batchjobs, rootjob, target)
for _, depname in ipairs(target:get("deps")) do
- _add_buildjobs_for_target_and_deps(buildjobs, rootjob, inserted, project.target(depname))
+ _add_batchjobs_for_target_and_deps(batchjobs, rootjob, inserted, project.target(depname))
end
inserted[target:name()] = true
end
end
--- get build jobs
-function _get_buildjobs(targetname)
+-- get batch jobs
+function _get_batchjobs(targetname)
-- get root targets
local targets_root = {}
@@ -205,24 +196,24 @@ function _get_buildjobs(targetname)
end
end
- -- generate build jobs for default or all targets
+ -- generate batch jobs for default or all targets
local inserted = {}
- local buildjobs = jobpool.new()
+ local batchjobs = jobpool.new()
for _, target in pairs(targets_root) do
- _add_buildjobs_for_target_and_deps(buildjobs, buildjobs:rootjob(), inserted, target)
+ _add_batchjobs_for_target_and_deps(batchjobs, batchjobs:rootjob(), inserted, target)
end
- return buildjobs
+ return batchjobs
end
-- the main entry
function main(targetname)
-- build all jobs
- local buildjobs = _get_buildjobs(targetname)
- print(buildjobs)
- if buildjobs and buildjobs:count() > 0 then
+ local batchjobs = _get_batchjobs(targetname)
+ print(batchjobs)
+ if batchjobs and batchjobs:count() > 0 then
environment.enter("toolchains")
- runjobs("build", buildjobs, {comax = option.get("jobs") or 1})
+ runjobs("build", batchjobs, {comax = option.get("jobs") or 1})
environment.leave("toolchains")
end
end