Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve to sort instances #5061

Merged
merged 2 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions xmake/actions/config/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,24 @@ function _need_check(changed)
end

-- check target
function _check_target(target)
for _, depname in ipairs(target:get("deps")) do
assert(depname ~= target:name(), "the target(%s) cannot depend self!", depname)
local deptarget = project.target(depname)
assert(deptarget, "unknown target(%s) for %s.deps!", depname, target:name())
_check_target(deptarget)
function _check_target(target, checked_targets)
if not checked_targets[target:name()] then
checked_targets[target:name()] = target
for _, depname in ipairs(target:get("deps")) do
assert(depname ~= target:name(), "the target(%s) cannot depend self!", depname)
local deptarget = project.target(depname)
assert(deptarget, "unknown target(%s) for %s.deps!", depname, target:name())
_check_target(deptarget, checked_targets)
end
end
end

-- check targets
function _check_targets()
assert(not project.is_loaded(), "project and targets may have been loaded early!")
local checked_targets = {}
for _, target in pairs(project.targets()) do
_check_target(target)
_check_target(target, checked_targets)
end
end

Expand Down
54 changes: 27 additions & 27 deletions xmake/core/base/private/instance_deps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ function instance_deps.load_deps(instance, instances, deps, orderdeps, depspath,
continue_walk = walkdep(instance, depinst)
end
if continue_walk then
local depspath_sub
if depspath then
for idx, name in ipairs(depspath) do
if name == depname then
local circular_deps = table.slice(depspath, idx)
table.insert(circular_deps, depname)
os.raise("circular dependency(%s) detected!", table.concat(circular_deps, ", "))
end
end
depspath_sub = table.join(depspath, depname)
end
instance_deps.load_deps(depinst, instances, deps, orderdeps, depspath_sub, walkdep)
if not deps[depname] then
deps[depname] = depinst
local depspath_sub
if depspath then
for idx, name in ipairs(depspath) do
if name == depname then
local circular_deps = table.slice(depspath, idx)
table.insert(circular_deps, depname)
os.raise("circular dependency(%s) detected!", table.concat(circular_deps, ", "))
end
end
depspath_sub = table.join(depspath, depname)
end
instance_deps.load_deps(depinst, instances, deps, orderdeps, depspath_sub, walkdep)
table.insert(orderdeps, depinst)
end
end
Expand All @@ -75,25 +75,25 @@ end

-- sort the given instance with deps
function instance_deps._sort_instance(instance, instances, orderinstances, instancerefs, depspath)
for _, depname in ipairs(table.wrap(instance:get("deps"))) do
local depinst = instances[depname]
if depinst then
local depspath_sub
if depspath then
for idx, name in ipairs(depspath) do
if name == depname then
local circular_deps = table.slice(depspath, idx)
table.insert(circular_deps, depname)
os.raise("circular dependency(%s) detected!", table.concat(circular_deps, ", "))
if not instancerefs[instance:name()] then
instancerefs[instance:name()] = true
for _, depname in ipairs(table.wrap(instance:get("deps"))) do
local depinst = instances[depname]
if depinst then
local depspath_sub
if depspath then
for idx, name in ipairs(depspath) do
if name == depname then
local circular_deps = table.slice(depspath, idx)
table.insert(circular_deps, depname)
os.raise("circular dependency(%s) detected!", table.concat(circular_deps, ", "))
end
end
depspath_sub = table.join(depspath, depname)
end
depspath_sub = table.join(depspath, depname)
instance_deps._sort_instance(depinst, instances, orderinstances, instancerefs, depspath_sub)
end
instance_deps._sort_instance(depinst, instances, orderinstances, instancerefs, depspath_sub)
end
end
if not instancerefs[instance:name()] then
instancerefs[instance:name()] = true
table.insert(orderinstances, instance)
end
end
Expand Down
Loading