summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-09-30 00:04:08 +0800
committerruki <[email protected]>2023-09-30 00:04:08 +0800
commit9a6662aa86d5ea52d494d9662ff3b6482d4cf413 (patch)
tree9793c157b97e8e93eff9d807727f161f41589530
parentfa04e8acf20cf3b89679562acdc4d9f21aed3232 (diff)
remove cycle in original deps
-rw-r--r--xmake/core/tool/builder.lua29
1 files changed, 28 insertions, 1 deletions
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index e4421fde6..f07fc39d6 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -495,13 +495,36 @@ function builder:_sort_links_of_items(target, items)
if sortlinks then
local gh = graph.new(true)
local from
+ local original_deps = {}
for _, link in ipairs(links) do
local to = link
if from and to then
- gh:add_edge(from, to)
+ original_deps[from] = to
end
from = to
end
+ -- we need remove cycle in original links
+ -- e.g.
+ -- original_deps: a -> b -> c -> d -> e
+ -- new deps: e -> b
+ -- graph: a -> b -> c -> d e (remove d -> e)
+ -- /\ |
+ -- | |
+ -- --------------
+ local function remove_cycle_in_original_deps(f, t)
+ local k
+ local v = t
+ while v ~= f do
+ k = v
+ v = original_deps[v]
+ if v == nil then
+ break
+ end
+ end
+ if v == f and k ~= nil then
+ original_deps[k] = nil
+ end
+ end
local links_set = hashset.from(links)
for _, linkorder in ipairs(linkorders) do
local from
@@ -509,12 +532,16 @@ function builder:_sort_links_of_items(target, items)
if links_set:has(link) then
local to = link
if from and to then
+ remove_cycle_in_original_deps(from, to)
gh:add_edge(from, to)
end
from = to
end
end
end
+ for k, v in pairs(original_deps) do
+ gh:add_edge(k, v)
+ end
if not gh:empty() then
local cycle = gh:find_cycle()
if cycle then