summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkaps316 <[email protected]>2026-04-11 21:28:37 +0530
committerruki <[email protected]>2026-04-20 09:35:36 +0800
commitf2179c9ccf0d199af1ea2c3320945f20a2f12f6e (patch)
treec173df0a373be2a713eed0802151af8404baff0a
parent8512dce671af24d2f293728bfdb9e65f81e5ed38 (diff)
Address code review feedback by waruqi: refactor parameter parsing, remove local functions, and use simpler test env
-rw-r--r--tests/plugins/show/test.lua14
-rw-r--r--xmake/plugins/show/info/depgraph.lua (renamed from xmake/plugins/show/info/target_graph.lua)8
-rw-r--r--xmake/plugins/show/main.lua24
-rw-r--r--xmake/plugins/show/xmake.lua2
4 files changed, 21 insertions, 27 deletions
diff --git a/tests/plugins/show/test.lua b/tests/plugins/show/test.lua
index 0c0f783e6..4bffa5bff 100644
--- a/tests/plugins/show/test.lua
+++ b/tests/plugins/show/test.lua
@@ -1,13 +1,5 @@
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")
@@ -42,8 +34,7 @@ function test_target_graph_json(t)
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 outdata = os.iorunv("xmake", {"show", "-P", tempdir, "--info=depgraph", "--json"})
local graph = json.decode(outdata)
t:are_equal(graph.root_targets, {"app"})
@@ -70,8 +61,7 @@ function test_target_graph_json_for_single_target(t)
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 outdata = os.iorunv("xmake", {"show", "-P", tempdir, "--info=depgraph", "--target=app", "--json"})
local graph = json.decode(outdata)
t:are_equal(graph.root_targets, {"app"})
diff --git a/xmake/plugins/show/info/target_graph.lua b/xmake/plugins/show/info/depgraph.lua
index 30c977fc3..cd5f3ad69 100644
--- a/xmake/plugins/show/info/target_graph.lua
+++ b/xmake/plugins/show/info/depgraph.lua
@@ -15,7 +15,7 @@
-- Copyright (C) 2015-present, Xmake Open Source Community.
--
-- @author ruki
--- @file target_graph.lua
+-- @file depgraph.lua
--
-- imports
@@ -25,7 +25,7 @@ import("core.project.config")
import("core.project.project")
import("private.detect.check_targetname")
-local function _collect_target_entry(target)
+function _collect_target_entry(target)
local deps = {}
for _, dep in pairs(target:deps() or {}) do
table.insert(deps, dep:name())
@@ -47,7 +47,7 @@ local function _collect_target_entry(target)
}
end
-local function _collect_target_graph(root_target)
+function _collect_target_graph(root_target)
local targets = {}
local selected = {}
if root_target then
@@ -91,7 +91,7 @@ local function _collect_target_graph(root_target)
}
end
-local function _print_target_graph(graph)
+function _print_target_graph(graph)
print("The dependency graph of targets:")
for _, target in ipairs(graph.targets) do
local deps = #target.deps > 0 and table.concat(target.deps, ", ") or "(none)"
diff --git a/xmake/plugins/show/main.lua b/xmake/plugins/show/main.lua
index 2b337b13e..7e04b7a43 100644
--- a/xmake/plugins/show/main.lua
+++ b/xmake/plugins/show/main.lua
@@ -32,16 +32,20 @@ function main()
local listname = option.get("list")
if listname then
return _show_list(listname)
- elseif option.get("target_graph") then
- return assert(import("info.target_graph", {try = true, anonymous = true}))(option.get("target"))
- else
- -- show the information of the given object
- for _, filepath in ipairs(os.files(path.join(os.scriptdir(), "info", "*.lua"))) do
- local name = path.basename(filepath)
- if option.get(name) then
- local show_info = assert(import("info." .. name, {try = true, anonymous = true}), "unknown option name(%s)", name)
- return show_info(option.get(name))
- end
+ end
+
+ local infoname = option.get("info")
+ if infoname then
+ local show_info = assert(import("info." .. infoname, {try = true, anonymous = true}), "unknown info name(%s)", infoname)
+ return show_info(option.get("target"))
+ end
+
+ -- fallback to legacy options format
+ for _, filepath in ipairs(os.files(path.join(os.scriptdir(), "info", "*.lua"))) do
+ local name = path.basename(filepath)
+ if option.get(name) then
+ local show_info = assert(import("info." .. name, {try = true, anonymous = true}), "unknown option name(%s)", name)
+ return show_info(option.get(name))
end
end
diff --git a/xmake/plugins/show/xmake.lua b/xmake/plugins/show/xmake.lua
index 3e3709877..cb16ff207 100644
--- a/xmake/plugins/show/xmake.lua
+++ b/xmake/plugins/show/xmake.lua
@@ -32,7 +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, "target_graph", "k", false, "Show the dependency graph of targets."},
+ {'i', "info", "kv", nil, "Show the given information."},
{'t', "target", "kv", nil, "Show the information of the given target.",
values = function (complete, opt)
return import("private.utils.complete_helper.targets")(complete, opt)