summaryrefslogtreecommitdiff
path: root/xmake/modules/private/action/require/depgraph.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2026-04-20 17:35:48 +0800
committerGitHub <[email protected]>2026-04-20 17:35:48 +0800
commit55f8d448564f7cc198edb4db506ec7c18ca8f0f6 (patch)
tree6822b239d43091d20037a99b6ffa9fd7e449f1db /xmake/modules/private/action/require/depgraph.lua
parent3a1b4e1719ba50b259afa27b450f06c39548003d (diff)
parent4e3f6b16db88b9c1afad898a7f5dfeaecdfd0f27 (diff)
Merge pull request #7490 from xmake-io/show
Export target dependency graph as json/dot
Diffstat (limited to 'xmake/modules/private/action/require/depgraph.lua')
-rw-r--r--xmake/modules/private/action/require/depgraph.lua54
1 files changed, 45 insertions, 9 deletions
diff --git a/xmake/modules/private/action/require/depgraph.lua b/xmake/modules/private/action/require/depgraph.lua
index ba1fb9ff4..e022bdee4 100644
--- a/xmake/modules/private/action/require/depgraph.lua
+++ b/xmake/modules/private/action/require/depgraph.lua
@@ -41,6 +41,7 @@ function _collect_package_entry(instance)
return {
name = instance:fullname(),
version = instance:version_str(),
+ configs_str = package.get_configs_str(instance),
deps = deps
}
end
@@ -74,11 +75,27 @@ function _collect_package_graph(instances)
}
end
+-- format version and configs as a suffix string for plain output
+-- e.g. " v1.3.2 [shared:y, debug:n]"
+function _format_package_suffix(entry)
+ local parts = {}
+ if entry.version then
+ table.insert(parts, entry.version)
+ end
+ if entry.configs_str and #entry.configs_str > 0 then
+ table.insert(parts, entry.configs_str)
+ end
+ if #parts > 0 then
+ return " " .. table.concat(parts, " ")
+ end
+ return ""
+end
+
-- print dependency tree recursively
--
-- e.g.
--- libpng
--- \-- zlib
+-- libpng v1.6.56
+-- \-- zlib v1.3.2
--
-- already expanded subtrees are marked with (*) to avoid duplication
--
@@ -91,11 +108,24 @@ function _print_dep_tree(packages_map, name, prefix, expanded)
local connector = is_last and "\\-- " or "|-- "
local next_prefix = prefix .. (is_last and " " or "| ")
local dep_entry = packages_map[dep]
- local dep_deps = dep_entry and dep_entry.deps or {}
- if expanded[dep] and #dep_deps > 0 then
- cprint("%s%s${color.dump.reference}%s${clear} ${dim}(*)${clear}", prefix, connector, dep)
+ local suffix = dep_entry and _format_package_suffix(dep_entry) or ""
+ if expanded[dep] then
+ -- already expanded, show with (*) and list direct children as references
+ local dep_deps = dep_entry and dep_entry.deps or {}
+ if #dep_deps > 0 then
+ cprint("%s%s${color.dump.reference}%s${clear}${dim}%s${clear}", prefix, connector, dep, suffix)
+ for j, subdep in ipairs(dep_deps) do
+ local sub_is_last = (j == #dep_deps)
+ local sub_connector = sub_is_last and "\\-- " or "|-- "
+ local sub_entry = packages_map[subdep]
+ local sub_suffix = sub_entry and _format_package_suffix(sub_entry) or ""
+ cprint("%s%s${dim}%s%s (*)${clear}", next_prefix, sub_connector, subdep, sub_suffix)
+ end
+ else
+ cprint("%s%s${color.dump.reference}%s${clear}${dim}%s (*)${clear}", prefix, connector, dep, suffix)
+ end
else
- cprint("%s%s${color.dump.reference}%s${clear}", prefix, connector, dep)
+ cprint("%s%s${color.dump.reference}%s${clear}${dim}%s${clear}", prefix, connector, dep, suffix)
_print_dep_tree(packages_map, dep, next_prefix, expanded)
end
end
@@ -109,7 +139,9 @@ function _print_package_graph(graph)
end
local expanded = {}
for _, root in ipairs(graph.root_packages) do
- cprint("${color.dump.string}%s${clear}", root)
+ local entry = packages_map[root]
+ local suffix = entry and _format_package_suffix(entry) or ""
+ cprint("${color.dump.string}%s${clear}${dim}%s${clear}", root, suffix)
_print_dep_tree(packages_map, root, "", expanded)
end
end
@@ -139,7 +171,7 @@ end
-- show the given package dependency graph
--
-- supported output formats (via --format):
--- tree (default): ASCII tree view
+-- plain (default): ASCII tree view
-- json: structured JSON output
-- dot: graphviz DOT format
--
@@ -164,8 +196,12 @@ function main(requires_raw)
local graph = _collect_package_graph(instances)
-- output in the specified format
- local format = option.get("format") or "tree"
+ local format = option.get("format") or "plain"
if format == "json" then
+ -- strip configs_str, it's only for plain display
+ for _, pkg in ipairs(graph.packages) do
+ pkg.configs_str = nil
+ end
print(json.encode(graph, {pretty = true, orderkeys = true}))
elseif format == "dot" then
_print_dot_graph(graph)