diff options
| author | ruki <[email protected]> | 2025-04-05 22:07:22 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-04-08 15:31:57 +0800 |
| commit | 529f59f911ddba8a2ef015f50df7a9582dd2bdb4 (patch) | |
| tree | c810dc81e35a1d8367198a0120691b5de399986e | |
| parent | e6a81c6a5c84842d6f5b54cfd6d4cdd97f45eef9 (diff) | |
sort file rules
| -rw-r--r-- | xmake/actions/build/target_utils.lua | 64 | ||||
| -rw-r--r-- | xmake/modules/private/utils/rule.lua | 36 |
2 files changed, 64 insertions, 36 deletions
diff --git a/xmake/actions/build/target_utils.lua b/xmake/actions/build/target_utils.lua index 4c33b5adf..3d71ff55e 100644 --- a/xmake/actions/build/target_utils.lua +++ b/xmake/actions/build/target_utils.lua @@ -215,28 +215,14 @@ function add_targetjobs_with_stage(jobgraph, target, stage, opt) end end) - -- sort build rules, TODO deps - for _, instance in ipairs(instances) do - local orders = table.wrap(instance:get("orders")) - if #orders > 0 then - for _, order in ipairs(orders) do - local joborders = {} - for _, rulename in ipairs(order) do - local script_group = group_name .. "/" .. rulename - if jobgraph:has(script_group) then - table.insert(joborders, script_group) - end - end - if #joborders > 0 then - jobgraph:add_orders(joborders) - end - end - end + -- no any new jobs + if jobgraph:size() == jobsize then + return end - if jobgraph:size() > jobsize then - return group_name - end + -- sort build rules + rule_utils.build_orders_in_jobgraph(jobgraph, instances, {root_group = group_name}) + return group_name end -- add target jobs for the given target @@ -517,8 +503,6 @@ function add_filejobs_with_stage(jobgraph, target, sourcebatches, stage, opt) end end - -- TODO sort rules and jobs - -- call target and rules script local jobsize = jobgraph:size() jobgraph:group(group_name, function () @@ -530,26 +514,34 @@ function add_filejobs_with_stage(jobgraph, target, sourcebatches, stage, opt) } local has_target_script = false for _, instance in ipairs(instances) do - if instance == target then - for _, sourcebatch in ipairs(sourcebatches_for_target) do - local has_script = add_filejobs_for_script(jobgraph, target, instance, sourcebatch, script_opt) - -- if custom target.on_build_file[s] exists, we need to ignore all scripts in rules - if has_script and stage == "" then - has_target_script = true + local script_group = group_name .. "/" .. instance:fullname() + jobgraph:group(script_group, function () + if instance == target then + for _, sourcebatch in ipairs(sourcebatches_for_target) do + local has_script = add_filejobs_for_script(jobgraph, target, instance, sourcebatch, script_opt) + -- if custom target.on_build_file[s] exists, we need to ignore all scripts in rules + if has_script and stage == "" then + has_target_script = true + end + end + elseif not has_target_script then -- rule + local sourcebatch = sourcebatches_map[instance] + if sourcebatch then + add_filejobs_for_script(jobgraph, target, instance, sourcebatch, script_opt) end end - elseif not has_target_script then -- rule - local sourcebatch = sourcebatches_map[instance] - if sourcebatch then - add_filejobs_for_script(jobgraph, target, instance, sourcebatch, script_opt) - end - end + end) end end) - if jobgraph:size() > jobsize then - return group_name + -- no any new jobs + if jobgraph:size() == jobsize then + return end + + -- sort build rules + rule_utils.build_orders_in_jobgraph(jobgraph, instances, {root_group = group_name}) + return group_name end -- add file jobs for the given target diff --git a/xmake/modules/private/utils/rule.lua b/xmake/modules/private/utils/rule.lua index 19706ad04..531486f61 100644 --- a/xmake/modules/private/utils/rule.lua +++ b/xmake/modules/private/utils/rule.lua @@ -32,3 +32,39 @@ function get_rule(target, rulename) return ruleinst end +-- build rules orders in jobgraph, we need to add rule job with groups +-- +-- like this: +-- @code +-- local root_group = "" +-- for _, ruleinst in ipairs(rules) do +-- local script_group = root_group .. "/" .. ruleinst:fullname() +-- jobgraph:group(script_group, function () +-- jobgraph:add("xxx", function (index, total, opt) +-- -- call rule script +-- end) +-- end) +-- end +-- +function build_orders_in_jobgraph(jobgraph, rules, opt) + opt = opt or {} + local root_group = assert(opt.root_group) + for _, ruleinst in ipairs(rules) do + local orders = table.wrap(ruleinst:get("orders")) + if #orders > 0 then + for _, order in ipairs(orders) do + local joborders = {} + for _, rulename in ipairs(order) do + local script_group = root_group .. "/" .. rulename + if jobgraph:has(script_group) then + table.insert(joborders, script_group) + end + end + if #joborders > 0 then + jobgraph:add_orders(joborders) + end + end + end + end +end + |
