summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-03-28 21:44:00 +0800
committerruki <[email protected]>2020-03-28 21:44:00 +0800
commit33ea9536a16adbec42a738b30821a19fc7076c4a (patch)
treef9e818715f23622580e12a650dcaba9a7d20cb32
parent31bacc4f76101e6a865ec254c48d8bcba456378f (diff)
fix before_build jobs
-rw-r--r--xmake/actions/build/build.lua45
-rw-r--r--xmake/actions/build/build_files.lua20
-rw-r--r--xmake/actions/build/kinds/binary.lua2
-rw-r--r--xmake/actions/build/kinds/shared.lua2
-rw-r--r--xmake/actions/build/kinds/static.lua2
5 files changed, 36 insertions, 35 deletions
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua
index 55d871c38..11cb00783 100644
--- a/xmake/actions/build/build.lua
+++ b/xmake/actions/build/build.lua
@@ -39,12 +39,12 @@ end
function _add_batchjobs_builtin(batchjobs, rootjob, target)
-- uses the rules script?
- local job
+ local job, job_leaf
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
- job = assert(script(target, batchjobs, {rootjob = job or rootjob}), "rule(%s):on_build(): no returned job!", r:name())
+ job, job_leaf = assert(script(target, batchjobs, {rootjob = job or rootjob}), "rule(%s):on_build(): no returned job!", r:name())
else
job = batchjobs:addjob("rule/" .. r:name() .. "/build", function (index, total)
script(target, {progress = (index * 100) / total})
@@ -55,19 +55,20 @@ function _add_batchjobs_builtin(batchjobs, rootjob, target)
-- uses the builtin target script
if not job and not target:isphony() then
- job = import("kinds." .. target:targetkind(), {anonymous = true})(batchjobs, rootjob, target)
+ job, job_leaf = import("kinds." .. target:targetkind(), {anonymous = true})(batchjobs, rootjob, target)
end
- return job or rootjob
+ job = job or rootjob
+ return job, job_leaf or job
end
-- add batch jobs
function _add_batchjobs(batchjobs, rootjob, target)
- local job
+ local job, job_leaf
local script = target:script("build")
if not script then
-- do builtin batch jobs
- job = _add_batchjobs_builtin(batchjobs, rootjob, target)
+ job, job_leaf = _add_batchjobs_builtin(batchjobs, rootjob, target)
elseif target:extraconf("build", "batch") then
-- do custom batch script
-- e.g.
@@ -78,7 +79,7 @@ function _add_batchjobs(batchjobs, rootjob, target)
-- end, opt.rootjob)
-- end, {batch = true})
--
- job = assert(script(target, batchjobs, {rootjob = rootjob}), "target(%s):on_build(): no returned job!", target:name())
+ job, job_leaf = assert(script(target, batchjobs, {rootjob = rootjob}), "target(%s):on_build(): no returned job!", target:name())
else
-- do custom script directly
-- e.g.
@@ -92,7 +93,7 @@ function _add_batchjobs(batchjobs, rootjob, target)
script(target, {progress = (index * 100) / total})
end, rootjob)
end
- return job
+ return job, job_leaf or job
end
-- add batch jobs for the given target
@@ -127,10 +128,10 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target)
end, rootjob)
-- add batch jobs for target, @note only on_build script support batch jobs
- local job_build = _add_batchjobs(batchjobs, job_after_build, target)
+ local job_build, job_build_leaf = _add_batchjobs(batchjobs, job_after_build, target)
-- add before_build job for target
- local job_before_build = batchjobs:addjob(target:name() .. "/before_build", function (index, total)
+ batchjobs:addjob(target:name() .. "/before_build", function (index, total)
-- enter the environments of the target packages
for name, values in pairs(target:pkgenvs()) do
@@ -155,21 +156,21 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target)
before_build(target, {progress = progress})
end
end
- end, job_build)
- return job_before_build, job_after_build
+ end, job_build_leaf)
+ return job_build, job_after_build
end
-- add batch jobs for the given target and deps
-function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, inserted, target)
- local targetjob = inserted[target:name()]
- if targetjob then
- batchjobs:add(targetjob, rootjob)
+function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, jobrefs, target)
+ local targetjob_ref = jobrefs[target:name()]
+ if targetjob_ref then
+ batchjobs:add(targetjob_ref, rootjob)
else
- local targetjob_leaf, targetjob_root = _add_batchjobs_for_target(batchjobs, rootjob, target)
- if targetjob_leaf and targetjob_root then
- inserted[target:name()] = targetjob_root
+ local targetjob, targetjob_root = _add_batchjobs_for_target(batchjobs, rootjob, target)
+ if targetjob and targetjob_root then
+ jobrefs[target:name()] = targetjob_root
for _, depname in ipairs(target:get("deps")) do
- _add_batchjobs_for_target_and_deps(batchjobs, targetjob_leaf, inserted, project.target(depname))
+ _add_batchjobs_for_target_and_deps(batchjobs, targetjob, jobrefs, project.target(depname))
end
end
end
@@ -202,10 +203,10 @@ function get_batchjobs(targetname)
end
-- generate batch jobs for default or all targets
- local inserted = {}
+ local jobrefs = {}
local batchjobs = jobpool.new()
for _, target in pairs(targets_root) do
- _add_batchjobs_for_target_and_deps(batchjobs, batchjobs:rootjob(), inserted, target)
+ _add_batchjobs_for_target_and_deps(batchjobs, batchjobs:rootjob(), jobrefs, target)
end
return batchjobs
end
diff --git a/xmake/actions/build/build_files.lua b/xmake/actions/build/build_files.lua
index 521814a5f..76bf64f4c 100644
--- a/xmake/actions/build/build_files.lua
+++ b/xmake/actions/build/build_files.lua
@@ -99,16 +99,16 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target, filepatterns)
end
-- add batch jobs for the given target and deps
-function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, inserted, target, filepatterns)
- local targetjob = inserted[target:name()]
- if targetjob then
- batchjobs:add(targetjob, rootjob)
+function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, jobrefs, target, filepatterns)
+ local targetjob_ref = jobrefs[target:name()]
+ if targetjob_ref then
+ batchjobs:add(targetjob_ref, rootjob)
else
- local targetjob_leaf, targetjob_root = _add_batchjobs_for_target(batchjobs, rootjob, target, filepatterns)
- if targetjob_leaf and targetjob_root then
- inserted[target:name()] = targetjob_root
+ local targetjob, targetjob_root = _add_batchjobs_for_target(batchjobs, rootjob, target, filepatterns)
+ if targetjob and targetjob_root then
+ jobrefs[target:name()] = targetjob_root
for _, depname in ipairs(target:get("deps")) do
- _add_batchjobs_for_target_and_deps(batchjobs, targetjob_leaf, inserted, project.target(depname), filepatterns)
+ _add_batchjobs_for_target_and_deps(batchjobs, targetjob, jobrefs, project.target(depname), filepatterns)
end
end
end
@@ -141,10 +141,10 @@ function _get_batchjobs(targetname, filepatterns)
end
-- generate batch jobs for default or all targets
- local inserted = {}
+ local jobrefs = {}
local batchjobs = jobpool.new()
for _, target in pairs(targets_root) do
- _add_batchjobs_for_target_and_deps(batchjobs, batchjobs:rootjob(), inserted, target, filepatterns)
+ _add_batchjobs_for_target_and_deps(batchjobs, batchjobs:rootjob(), jobrefs, target, filepatterns)
end
return batchjobs
end
diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua
index ba8077122..7b4ee23ee 100644
--- a/xmake/actions/build/kinds/binary.lua
+++ b/xmake/actions/build/kinds/binary.lua
@@ -165,5 +165,5 @@ function main(batchjobs, rootjob, target)
-- unless call set_values("build.across_targets_in_parallel") to disable to build across targets in parallel.
--
local job_objects = add_batchjobs_for_object(batchjobs, job_link, target)
- return target:values("build.across_targets_in_parallel") == false and job_objects or job_link
+ return target:values("build.across_targets_in_parallel") == false and job_objects or job_link, job_objects
end
diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua
index 544f8fcbf..bec79f4fc 100644
--- a/xmake/actions/build/kinds/shared.lua
+++ b/xmake/actions/build/kinds/shared.lua
@@ -178,5 +178,5 @@ function main(batchjobs, rootjob, target)
-- unless call set_values("build.across_targets_in_parallel") to disable to build across targets in parallel.
--
local job_objects = add_batchjobs_for_object(batchjobs, job_link, target)
- return target:values("build.across_targets_in_parallel") == false and job_objects or job_link
+ return target:values("build.across_targets_in_parallel") == false and job_objects or job_link, job_objects
end
diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua
index a53bd9cca..8864f8ab4 100644
--- a/xmake/actions/build/kinds/static.lua
+++ b/xmake/actions/build/kinds/static.lua
@@ -174,5 +174,5 @@ function main(batchjobs, rootjob, target)
-- unless call set_values("build.across_targets_in_parallel") to disable to build across targets in parallel.
--
local job_objects = add_batchjobs_for_object(batchjobs, job_link, target)
- return target:values("build.across_targets_in_parallel") == false and job_objects or job_link
+ return target:values("build.across_targets_in_parallel") == false and job_objects or job_link, job_objects
end