summaryrefslogtreecommitdiff
path: root/tests/plugins
diff options
context:
space:
mode:
authorAkaps316 <[email protected]>2026-04-11 11:43:14 +0530
committerruki <[email protected]>2026-04-20 09:35:36 +0800
commit8512dce671af24d2f293728bfdb9e65f81e5ed38 (patch)
tree2028395b1f6f1127ed15ad94ad0ecfafe4ffbed7 /tests/plugins
parent3a1b4e1719ba50b259afa27b450f06c39548003d (diff)
feat(show): export target dependency graph as JSON
Add a graph-oriented mode to `xmake show` for exporting target\ndependency relationships as JSON.\n\nThis adds `--target_graph` support for whole-project output and\noptional root-target filtering with `--target`.\n\nAdd a plugin test covering full-graph and single-target graph export.\n\nRefs #7475
Diffstat (limited to 'tests/plugins')
-rw-r--r--tests/plugins/show/test.lua85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/plugins/show/test.lua b/tests/plugins/show/test.lua
new file mode 100644
index 000000000..0c0f783e6
--- /dev/null
+++ b/tests/plugins/show/test.lua
@@ -0,0 +1,85 @@
+import("core.base.json")
+
+local function _prepare_xmake_env()
+ local xmake = path.absolute(os.programfile())
+ local xmake_program_dir = path.absolute(os.programdir())
+ os.setenv("XMAKE_PROGRAM_FILE", xmake)
+ os.setenv("XMAKE_PROGRAM_DIR", xmake_program_dir)
+ return xmake
+end
+
+local function _create_project(tempdir)
+ io.writefile(path.join(tempdir, "xmake.lua"), [[
+add_rules("mode.debug", "mode.release")
+
+target("core")
+ set_kind("static")
+ add_files("src/core.c")
+
+target("ui")
+ set_kind("static")
+ add_deps("core")
+ add_files("src/ui.c")
+
+target("app")
+ set_kind("binary")
+ add_deps("core", "ui")
+ add_files("src/main.c")
+]])
+ os.mkdir(path.join(tempdir, "src"))
+ io.writefile(path.join(tempdir, "src", "core.c"), "int core(void) { return 0; }\n")
+ io.writefile(path.join(tempdir, "src", "ui.c"), "int ui(void) { return 0; }\n")
+ io.writefile(path.join(tempdir, "src", "main.c"), "int main(void) { return 0; }\n")
+end
+
+function test_target_graph_json(t)
+ local tempdir = os.tmpfile()
+ os.mkdir(tempdir)
+ _create_project(tempdir)
+
+ local homedir = path.join(tempdir, "home")
+ os.setenv("HOME", homedir)
+ os.mkdir(homedir)
+ os.mkdir(path.join(homedir, ".xmake"))
+
+ local xmake = _prepare_xmake_env()
+ local outdata = os.iorunv(xmake, {"show", "-P", tempdir, "--target_graph", "--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"})
+ t:are_equal(entries.app.orderdeps, {"core", "ui"})
+ t:are_equal(entries.app.kind, "binary")
+end
+
+function test_target_graph_json_for_single_target(t)
+ local tempdir = os.tmpfile()
+ os.mkdir(tempdir)
+ _create_project(tempdir)
+
+ local homedir = path.join(tempdir, "home")
+ os.setenv("HOME", homedir)
+ os.mkdir(homedir)
+ os.mkdir(path.join(homedir, ".xmake"))
+
+ local xmake = _prepare_xmake_env()
+ local outdata = os.iorunv(xmake, {"show", "-P", tempdir, "--target_graph", "--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