summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-08-18 22:59:19 +0800
committerruki <[email protected]>2026-08-18 22:59:19 +0800
commit2aa546158580815742081e447b9b7e8e1a198ede (patch)
tree543d30fe2fcaa7ba91987e3b3e2bf02939e178d1
parenta6150b0a9bc7cd24081185a1d5acbd6772d5e138 (diff)
move some plugins to addons
-rw-r--r--tests/actions/addon/custom-override/addon.lua2
-rw-r--r--tests/actions/addon/custom-override/plugins/format/main.lua3
-rw-r--r--tests/actions/addon/custom-override/plugins/format/xmake.lua6
-rw-r--r--tests/actions/addon/test.lua20
-rw-r--r--xmake/core/base/task.lua44
-rw-r--r--xmake/plugins/doxygen/main.lua4
-rw-r--r--xmake/plugins/format/main.lua4
-rw-r--r--xmake/plugins/macro/main.lua4
8 files changed, 74 insertions, 13 deletions
diff --git a/tests/actions/addon/custom-override/addon.lua b/tests/actions/addon/custom-override/addon.lua
new file mode 100644
index 000000000..3540b51f5
--- /dev/null
+++ b/tests/actions/addon/custom-override/addon.lua
@@ -0,0 +1,2 @@
+addon("custom-override")
+ set_description("the addon which takes over a builtin plugin")
diff --git a/tests/actions/addon/custom-override/plugins/format/main.lua b/tests/actions/addon/custom-override/plugins/format/main.lua
new file mode 100644
index 000000000..92f9b73b8
--- /dev/null
+++ b/tests/actions/addon/custom-override/plugins/format/main.lua
@@ -0,0 +1,3 @@
+function main()
+ print("hello from custom-override")
+end
diff --git a/tests/actions/addon/custom-override/plugins/format/xmake.lua b/tests/actions/addon/custom-override/plugins/format/xmake.lua
new file mode 100644
index 000000000..446e24db1
--- /dev/null
+++ b/tests/actions/addon/custom-override/plugins/format/xmake.lua
@@ -0,0 +1,6 @@
+-- @note `format` is a builtin plugin of xmake, we use it to test that an addon
+-- is able to take over a builtin plugin
+task("format")
+ set_category("plugin")
+ set_menu {usage = "xmake format", description = "Say hello instead of formatting.", options = {}}
+ on_run("main")
diff --git a/tests/actions/addon/test.lua b/tests/actions/addon/test.lua
index 05818a054..fcc5c2efc 100644
--- a/tests/actions/addon/test.lua
+++ b/tests/actions/addon/test.lua
@@ -467,6 +467,26 @@ function test_install_conflicts(t)
end)
end
+-- an addon is able to take over a builtin plugin, so we can move a deprecated builtin
+-- plugin to an addon, e.g. `xmake format`
+function test_install_override(t)
+
+ -- the builtin plugin is used if we do not install the addon
+ t:require_not(os.iorunv("xmake", {"format", "--help"}):find("Say hello instead of formatting", 1, true))
+
+ _with_addons({"custom-override"}, function ()
+ local out = os.iorunv("xmake", {"format"})
+ t:require(out:find("hello from custom-override", 1, true))
+
+ -- and it should not be reported as a conflict
+ t:require_not(out:find("conflicts", 1, true))
+ t:require(os.iorunv("xmake", {"format", "--help"}):find("Say hello instead of formatting", 1, true))
+ end)
+
+ -- the builtin plugin is used again after removing the addon
+ t:require_not(os.iorunv("xmake", {"format", "--help"}):find("Say hello instead of formatting", 1, true))
+end
+
-- the invalid installs should fail, and the `addon` name is reserved for the addon references
function test_invalid(t)
t:require_not(try { function () os.runv("xmake", {"addon", "--install", "-y", "addon-test-missing"}); return true end })
diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua
index 2cd1fa58a..ab5942e28 100644
--- a/xmake/core/base/task.lua
+++ b/xmake/core/base/task.lua
@@ -24,6 +24,7 @@ local task = task or {}
-- load modules
local os = require("base/os")
local table = require("base/table")
+local utils = require("base/utils")
local string = require("base/string")
local global = require("base/global")
local hashset = require("base/hashset")
@@ -399,31 +400,48 @@ function task.new(name, info)
return instance
end
--- is the given plugin conflicting with the loaded one?
+-- is the given task file from an addon?
+function task._is_from_addon(filepath)
+ return path.absolute(filepath):startswith(path.absolute(addon.installdir()))
+end
+
+-- is the given task file a builtin plugin? e.g. <programdir>/plugins/format/xmake.lua
+--
+-- @note the builtin actions, e.g. build, config, are not plugins, they are never overridable
+--
+function task._is_builtin_plugin(filepath)
+ return path.absolute(filepath):startswith(path.absolute(path.join(os.programdir(), "plugins")))
+end
+
+-- should we use the given plugin instead of the loaded one?
--
--- the plugins are not namespaced, so we need to report the conflicts of the addons,
--- otherwise we do not know which plugin will be run
+-- the plugins are not namespaced, so the first one wins, but an addon is able to take over
+-- a builtin plugin, otherwise the user cannot replace a deprecated builtin plugin,
+-- e.g. `xmake format` is provided by the format-plugin addon now
--
-- @param taskname the task name
-- @param taskfile the task file of the loaded plugin, it will be nil if it's the first one
-- @param filepath the task file of the plugin which we are loading
--
-function task._is_conflicting(taskname, taskfile, filepath)
+function task._is_overriding(taskname, taskfile, filepath)
if not taskfile then
- return false
+ return true
end
- -- we only report it if one of them comes from an addon, the builtin plugins
- -- and the plugins in the global directory are always overridable
- local addondir = path.absolute(addon.installdir())
- if not path.absolute(taskfile):startswith(addondir) and not path.absolute(filepath):startswith(addondir) then
- return false
+ -- the addon takes over the builtin plugin
+ if task._is_from_addon(filepath) and task._is_builtin_plugin(taskfile) then
+ return true
end
+ -- we only report the conflicts between the addons, we do not know which one is
+ -- expected, the plugins in the global directory always win, they are the user's own
+ --
-- @note we cannot raise errors here, otherwise all the commands will be broken,
-- and the user cannot even remove the conflicting addons
- utils.warning("plugin(%s) conflicts, we will use the first one!\n -> %s\n -> %s", taskname, taskfile, filepath)
- return true
+ if task._is_from_addon(taskfile) and task._is_from_addon(filepath) then
+ utils.warning("plugin(%s) conflicts, we will use the first one!\n -> %s\n -> %s", taskname, taskfile, filepath)
+ end
+ return false
end
-- clear the loaded tasks, e.g. some addons may be installed just now
@@ -452,7 +470,7 @@ function task.tasks()
local results, errors = task._load(filepath)
if results then
for taskname, taskinfo in pairs(results) do
- if not task._is_conflicting(taskname, taskfiles[taskname], filepath) then
+ if task._is_overriding(taskname, taskfiles[taskname], filepath) then
taskfiles[taskname] = filepath
tasks[taskname] = taskinfo
end
diff --git a/xmake/plugins/doxygen/main.lua b/xmake/plugins/doxygen/main.lua
index 80fd77675..b84754cb2 100644
--- a/xmake/plugins/doxygen/main.lua
+++ b/xmake/plugins/doxygen/main.lua
@@ -71,6 +71,10 @@ end
function main()
+ -- @note we cannot use utils.warning() here, it's queued and only shown at the end
+ cprint("${bright color.warning}${text.warning}: ${color.warning}the builtin `xmake doxygen` plugin is deprecated, " ..
+ "please use the doxygen-plugin addon: `xmake addon --install doxygen-plugin`")
+
-- load configuration
config.load()
diff --git a/xmake/plugins/format/main.lua b/xmake/plugins/format/main.lua
index 408de0421..c8f50a15e 100644
--- a/xmake/plugins/format/main.lua
+++ b/xmake/plugins/format/main.lua
@@ -103,6 +103,10 @@ end
-- main
function main()
+ -- @note we cannot use utils.warning() here, it's queued and only shown at the end
+ cprint("${bright color.warning}${text.warning}: ${color.warning}the builtin `xmake format` plugin is deprecated, " ..
+ "please use the format-plugin addon: `xmake addon --install format-plugin`")
+
-- load configuration
config.load()
diff --git a/xmake/plugins/macro/main.lua b/xmake/plugins/macro/main.lua
index 86b50e2da..6c2c8c734 100644
--- a/xmake/plugins/macro/main.lua
+++ b/xmake/plugins/macro/main.lua
@@ -309,6 +309,10 @@ end
-- main
function main()
+ -- @note we cannot use utils.warning() here, it's queued and only shown at the end
+ cprint("${bright color.warning}${text.warning}: ${color.warning}the builtin `xmake macro` plugin is deprecated, " ..
+ "please use the macro-plugin addon: `xmake addon --install macro-plugin`")
+
-- list macros
if option.get("list") then