summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-04-18 21:52:57 +0800
committerruki <[email protected]>2026-04-20 09:35:36 +0800
commitfea8ad3d654e497ba83315f26902647dd64f561e (patch)
tree7576a6c7b0005da49bc381769af96fabb038f11c
parent51be800bddfa199774206393cb8d7e0749f59756 (diff)
add --dot output
-rw-r--r--tests/plugins/show/src/core.c (renamed from tests/projects/plugins/show/depgraph/src/core.c)0
-rw-r--r--tests/plugins/show/src/main.c (renamed from tests/projects/plugins/show/depgraph/src/main.c)0
-rw-r--r--tests/plugins/show/src/ui.c (renamed from tests/projects/plugins/show/depgraph/src/ui.c)0
-rw-r--r--tests/plugins/show/test.lua58
-rw-r--r--tests/plugins/show/xmake.lua (renamed from tests/projects/plugins/show/depgraph/xmake.lua)0
-rw-r--r--tests/projects/plugins/show/depgraph/test.lua33
-rw-r--r--xmake/plugins/show/info/depgraph.lua58
-rw-r--r--xmake/plugins/show/xmake.lua1
8 files changed, 101 insertions, 49 deletions
diff --git a/tests/projects/plugins/show/depgraph/src/core.c b/tests/plugins/show/src/core.c
index 87a413095..87a413095 100644
--- a/tests/projects/plugins/show/depgraph/src/core.c
+++ b/tests/plugins/show/src/core.c
diff --git a/tests/projects/plugins/show/depgraph/src/main.c b/tests/plugins/show/src/main.c
index 78f2de106..78f2de106 100644
--- a/tests/projects/plugins/show/depgraph/src/main.c
+++ b/tests/plugins/show/src/main.c
diff --git a/tests/projects/plugins/show/depgraph/src/ui.c b/tests/plugins/show/src/ui.c
index c15794f4d..c15794f4d 100644
--- a/tests/projects/plugins/show/depgraph/src/ui.c
+++ b/tests/plugins/show/src/ui.c
diff --git a/tests/plugins/show/test.lua b/tests/plugins/show/test.lua
new file mode 100644
index 000000000..451b13ade
--- /dev/null
+++ b/tests/plugins/show/test.lua
@@ -0,0 +1,58 @@
+import("core.base.json")
+
+function test_depgraph_json(t)
+ local outdata = os.iorunv("xmake", {"show", "--info=depgraph", "--json"})
+ local graph = json.decode(outdata)
+
+ t:are_equal(graph.root_targets, {"app"})
+ t:require(#graph.targets == 3)
+
+ local entries = {}
+ for _, target in ipairs(graph.targets) do
+ entries[target.name] = target
+ end
+ t:are_equal(entries.core.deps, {})
+ t:are_equal(entries.ui.deps, {"core"})
+ t:are_equal(entries.app.deps, {"core", "ui"})
+end
+
+function test_depgraph_json_for_single_target(t)
+ local outdata = os.iorunv("xmake", {"show", "--info=depgraph", "--target=app", "--json", })
+ local graph = json.decode(outdata)
+
+ t:are_equal(graph.root_targets, {"app"})
+ t:require(#graph.targets == 3)
+
+ local names = {}
+ for _, target in ipairs(graph.targets) do
+ table.insert(names, target.name)
+ end
+ t:are_equal(names, {"core", "ui", "app"})
+end
+
+function test_depgraph_tree(t)
+ local outdata = os.iorunv("xmake", {"show", "--info=depgraph", })
+ t:require(outdata:find("app", 1, true))
+ t:require(outdata:find("core", 1, true))
+ t:require(outdata:find("ui", 1, true))
+ t:require(outdata:find("├── ", 1, true) or outdata:find("+-- ", 1, true))
+ t:require(outdata:find("└── ", 1, true) or outdata:find("\\-- ", 1, true))
+end
+
+function test_depgraph_dot(t)
+ local outdata = os.iorunv("xmake", {"show", "--info=depgraph", "--dot", })
+ t:require(outdata:find("digraph {", 1, true))
+ t:require(outdata:find('"core"', 1, true))
+ t:require(outdata:find('"ui" -> "core"', 1, true))
+ t:require(outdata:find('"app" -> "core"', 1, true))
+ t:require(outdata:find('"app" -> "ui"', 1, true))
+ t:require(outdata:find("}", 1, true))
+end
+
+function test_depgraph_dot_for_single_target(t)
+ local outdata = os.iorunv("xmake", {"show", "--info=depgraph", "--target=ui", "--dot", })
+ t:require(outdata:find("digraph {", 1, true))
+ t:require(outdata:find('"core"', 1, true))
+ t:require(outdata:find('"ui" -> "core"', 1, true))
+ t:require(not outdata:find('"app"', 1, true))
+end
diff --git a/tests/projects/plugins/show/depgraph/xmake.lua b/tests/plugins/show/xmake.lua
index 7077424f3..7077424f3 100644
--- a/tests/projects/plugins/show/depgraph/xmake.lua
+++ b/tests/plugins/show/xmake.lua
diff --git a/tests/projects/plugins/show/depgraph/test.lua b/tests/projects/plugins/show/depgraph/test.lua
deleted file mode 100644
index 229e715de..000000000
--- a/tests/projects/plugins/show/depgraph/test.lua
+++ /dev/null
@@ -1,33 +0,0 @@
-import("core.base.json")
-
-function test_depgraph_json(t)
- local outdata = os.iorunv("xmake", {"show", "--info=depgraph", "--json"})
- local graph = json.decode(outdata)
-
- t:are_equal(graph.root_targets, {"app"})
- t:require(#graph.targets == 3)
-
- local entries = {}
- for _, target in ipairs(graph.targets) do
- entries[target.name] = target
- end
- t:are_equal(entries.core.deps, {})
- t:are_equal(entries.core.kind, "static")
- t:are_equal(entries.ui.deps, {"core"})
- t:are_equal(entries.app.deps, {"core", "ui"})
- t:are_equal(entries.app.kind, "binary")
-end
-
-function test_depgraph_json_for_single_target(t)
- local outdata = os.iorunv("xmake", {"show", "--info=depgraph", "--target=app", "--json"})
- local graph = json.decode(outdata)
-
- t:are_equal(graph.root_targets, {"app"})
- t:require(#graph.targets == 3)
-
- local names = {}
- for _, target in ipairs(graph.targets) do
- table.insert(names, target.name)
- end
- t:are_equal(names, {"core", "ui", "app"})
-end
diff --git a/xmake/plugins/show/info/depgraph.lua b/xmake/plugins/show/info/depgraph.lua
index 60e667002..199754772 100644
--- a/xmake/plugins/show/info/depgraph.lua
+++ b/xmake/plugins/show/info/depgraph.lua
@@ -28,12 +28,8 @@ import("private.detect.check_targetname")
function _collect_target_entry(target)
local deps = table.wrap(target:get("deps"))
json.mark_as_array(deps)
-
return {
name = target:name(),
- kind = target:kind(),
- group = target:get("group"),
- default = target:is_default(),
deps = deps
}
end
@@ -83,22 +79,49 @@ function _collect_target_graph(root_target)
}
end
+function _print_dep_tree(targets_map, name, prefix, expanded)
+ expanded[name] = true
+ local entry = targets_map[name]
+ local deps = entry and entry.deps or {}
+ for i, dep in ipairs(deps) do
+ local is_last = (i == #deps)
+ local connector = is_last and "└── " or "├── "
+ local next_prefix = prefix .. (is_last and " " or "│ ")
+ local dep_entry = targets_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.string}%s${clear} ${dim}(*)${clear}", prefix, connector, dep)
+ else
+ cprint("%s%s${color.dump.string}%s${clear}", prefix, connector, dep)
+ _print_dep_tree(targets_map, dep, next_prefix, expanded)
+ end
+ end
+end
+
function _print_target_graph(graph)
- print("The dependency graph of targets:")
- cprint("")
- cprint(" ${color.dump.string}root targets${clear}: %s", table.concat(graph.root_targets, ", "))
- cprint("")
+ local targets_map = {}
for _, target in ipairs(graph.targets) do
- cprint(" ${color.dump.string}%s${clear}:", target.name)
- cprint(" ${dim}kind${clear}: %s", target.kind)
- if target.group then
- cprint(" ${dim}group${clear}: %s", target.group)
- end
- cprint(" ${dim}default${clear}: %s", tostring(target.default))
- if #target.deps > 0 then
- cprint(" ${dim}deps${clear}: %s", table.concat(target.deps, ", "))
+ targets_map[target.name] = target
+ end
+ local expanded = {}
+ for _, root in ipairs(graph.root_targets) do
+ cprint("${color.dump.string}%s${clear}", root)
+ _print_dep_tree(targets_map, root, "", expanded)
+ end
+end
+
+function _print_dot_graph(graph)
+ print("digraph {")
+ for _, target in ipairs(graph.targets) do
+ if #target.deps == 0 then
+ print(string.format(" \"%s\"", target.name))
+ else
+ for _, dep in ipairs(target.deps) do
+ print(string.format(" \"%s\" -> \"%s\"", target.name, dep))
+ end
end
end
+ print("}")
end
function main(name)
@@ -110,12 +133,15 @@ function main(name)
end
local graph = _collect_target_graph(root_target)
+ assert(not (option.get("json") and option.get("dot")), "--json and --dot are mutually exclusive")
if option.get("json") then
local json_opt
if option.get("pretty") then
json_opt = {pretty = true, orderkeys = true}
end
print(json.encode(graph, json_opt))
+ elseif option.get("dot") then
+ _print_dot_graph(graph)
else
_print_target_graph(graph)
end
diff --git a/xmake/plugins/show/xmake.lua b/xmake/plugins/show/xmake.lua
index 77d2be2b3..de7a5a1c5 100644
--- a/xmake/plugins/show/xmake.lua
+++ b/xmake/plugins/show/xmake.lua
@@ -32,6 +32,7 @@ task("show")
{'g', "group", "kv", nil, "Filter targets by the given group name."},
{nil, "json", "k", false, "Show information with json format."},
{nil, "pretty", "k", false, "Enable pretty formatted json output."},
+ {nil, "dot", "k", false, "Output dependency graph in graphviz DOT format."},
{'i', "info", "kv", nil, "Show the given information.",
values = function (complete, opt)
return import("list").infos()