summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhu-rong <[email protected]>2024-04-25 15:48:16 +0800
committerzhu-rong <[email protected]>2024-04-25 15:49:43 +0800
commit83b2f487b643423fbd3d78207105c8dbaf9d0ced (patch)
tree47031c798c382dca8be5f7cff05127e9667be95a
parent979023e54bc5d11db19c0df7e181c3824f18dc41 (diff)
add "build.fence" policy for block job build
-rw-r--r--xmake/actions/build/build.lua32
-rw-r--r--xmake/core/project/policy.lua2
2 files changed, 31 insertions, 3 deletions
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua
index 43e28bf21..332a747ff 100644
--- a/xmake/actions/build/build.lua
+++ b/xmake/actions/build/build.lua
@@ -207,7 +207,7 @@ function _add_batchjobs_for_target(batchjobs, rootjob, target)
end
-- add batch jobs for the given target and deps
-function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, jobrefs, target)
+function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, jobrefs, target, before_job_refs)
local targetjob_ref = jobrefs[target:name()]
if targetjob_ref then
batchjobs:add(targetjob_ref, rootjob)
@@ -215,6 +215,7 @@ function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, jobrefs, target)
local job_build_before, job_build, job_build_after = _add_batchjobs_for_target(batchjobs, rootjob, target)
if job_build_before and job_build and job_build_after then
jobrefs[target:name()] = job_build_after
+ before_job_refs[target:name()] = job_build_before
for _, depname in ipairs(target:get("deps")) do
local dep = project.target(depname)
local targetjob = job_build
@@ -222,7 +223,7 @@ function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, jobrefs, target)
if dep:policy("build.across_targets_in_parallel") == false then
targetjob = job_build_before
end
- _add_batchjobs_for_target_and_deps(batchjobs, targetjob, jobrefs, dep)
+ _add_batchjobs_for_target_and_deps(batchjobs, targetjob, jobrefs, dep, before_job_refs)
end
end
end
@@ -274,10 +275,35 @@ function get_batchjobs(targetnames, group_pattern)
-- generate batch jobs for default or all targets
local jobrefs = {}
+ local before_job_refs = {}
local batchjobs = jobpool.new()
for _, target in pairs(targets_root) do
- _add_batchjobs_for_target_and_deps(batchjobs, batchjobs:rootjob(), jobrefs, target)
+ _add_batchjobs_for_target_and_deps(batchjobs, batchjobs:rootjob(), jobrefs, target, before_job_refs)
end
+
+ -- add fence
+ for _, target in pairs(project.targets()) do
+ local target_before_job = before_job_refs[target:name()]
+
+ if target_before_job then
+ -- collect fence
+ local fences = {}
+ for _, dep in ipairs(target:orderdeps()) do
+ if dep:policy("build.fence") == true then
+ fence_job = jobrefs[dep:name()]
+ table.insert(fences, fence_job)
+ end
+ end
+
+ -- add fence
+ if #fences > 0 then
+ for _, fence_job in ipairs(fences) do
+ batchjobs:add(fence_job, target_before_job)
+ end
+ end
+ end
+ end
+
return batchjobs
end
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua
index e99f02caf..4e495e449 100644
--- a/xmake/core/project/policy.lua
+++ b/xmake/core/project/policy.lua
@@ -40,6 +40,8 @@ function policy.policies()
["check.auto_map_flags"] = {description = "Enable map gcc flags to the current compiler and linker automatically.", default = true, type = "boolean"},
-- We will check the compatibility of target and package licenses
["check.target_package_licenses"] = {description = "Enable check the compatibility of target and package licenses.", default = true, type = "boolean"},
+ -- Provide a way to block all targets build that depends on self
+ ["build.fence"] = {description = "Block all targets build that depends on self.", default = false, type = "boolean"},
-- We can compile the source files for each target in parallel
["build.across_targets_in_parallel"] = {description = "Enable compile the source files for each target in parallel.", default = true, type = "boolean"},
-- Merge archive intead of linking for all dependent targets