summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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.lua36
-rw-r--r--xmake/plugins/doxygen/main.lua4
-rw-r--r--xmake/plugins/format/main.lua4
-rw-r--r--xmake/plugins/macro/main.lua4
-rw-r--r--xmake/rules/utils/glsl2spv/xmake.lua3
-rw-r--r--xmake/rules/utils/hlsl2spv/xmake.lua3
10 files changed, 66 insertions, 19 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..2b3788603 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")
@@ -84,17 +85,18 @@ end
function task._directories()
local dirs = task._DIRECTORIES
if dirs == nil then
- dirs = {
- path.join(global.directory(), "plugins"),
- path.join(os.programdir(), "plugins"),
- path.join(os.programdir(), "actions")}
-
- -- add the plugins of the installed addons, e.g. ~/.xmake/addons/<name>/<version>/plugins
+ -- add the plugins of the installed addons first, e.g. ~/.xmake/addons/<name>/<version>/plugins
--
-- we get them from the addons registry file directly,
-- so we do not need to scan the whole addons directory on startup
--
- table.join2(dirs, addon.payloads("plugins"))
+ -- @note the first one wins, so an addon is able to take over a deprecated
+ -- builtin plugin, e.g. `xmake format`
+ --
+ dirs = addon.payloads("plugins")
+ table.insert(dirs, path.join(global.directory(), "plugins"))
+ table.insert(dirs, path.join(os.programdir(), "plugins"))
+ table.insert(dirs, path.join(os.programdir(), "actions"))
task._DIRECTORIES = dirs
end
return dirs
@@ -401,8 +403,9 @@ end
-- is the given plugin conflicting with 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 always wins, @see task._directories(),
+-- but we need to report the conflicts of the addons, otherwise we do not know which
+-- plugin will be run
--
-- @param taskname the task name
-- @param taskfile the task file of the loaded plugin, it will be nil if it's the first one
@@ -413,16 +416,15 @@ function task._is_conflicting(taskname, taskfile, filepath)
return false
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
- end
-
+ -- we only report it if both of them come from the addons, taking over a builtin
+ -- plugin is expected, e.g. `xmake format` has been moved to an addon
+ --
-- @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)
+ local addondir = path.absolute(addon.installdir())
+ if path.absolute(taskfile):startswith(addondir) and path.absolute(filepath):startswith(addondir) then
+ utils.warning("plugin(%s) conflicts, we will use the first one!\n -> %s\n -> %s", taskname, taskfile, filepath)
+ end
return true
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
diff --git a/xmake/rules/utils/glsl2spv/xmake.lua b/xmake/rules/utils/glsl2spv/xmake.lua
index 01abc561a..0374c2fe6 100644
--- a/xmake/rules/utils/glsl2spv/xmake.lua
+++ b/xmake/rules/utils/glsl2spv/xmake.lua
@@ -43,6 +43,7 @@
--
rule("utils.glsl2spv")
set_extensions(".vert", ".tesc", ".tese", ".geom", ".comp", ".frag", ".comp", ".mesh", ".task", ".rgen", ".rint", ".rahit", ".rchit", ".rmiss", ".rcall", ".glsl")
+ add_orders("utils.glsl2spv", "c++.build.modules.scanner")
on_load(function (target)
local is_bin2c = target:extraconf("rules", "utils.glsl2spv", "bin2c")
if is_bin2c then
@@ -53,7 +54,7 @@ rule("utils.glsl2spv")
target:add("includedirs", headerdir)
end
end)
- before_buildcmd_file(function (target, batchcmds, sourcefile_glsl, opt)
+ on_preparecmd_file(function (target, batchcmds, sourcefile_glsl, opt)
import("lib.detect.find_tool")
import("rules.utils.bin2obj.utils", {alias = "bin2obj_utils", rootdir = os.programdir()})
import("rules.utils.bin2c.utils", {alias = "bin2c_utils", rootdir = os.programdir()})
diff --git a/xmake/rules/utils/hlsl2spv/xmake.lua b/xmake/rules/utils/hlsl2spv/xmake.lua
index 750574eac..5eab8b25d 100644
--- a/xmake/rules/utils/hlsl2spv/xmake.lua
+++ b/xmake/rules/utils/hlsl2spv/xmake.lua
@@ -43,6 +43,7 @@
--
rule("utils.hlsl2spv")
set_extensions(".hlsl")
+ add_orders("utils.hlsl2spv", "c++.build.modules.scanner")
on_load(function (target)
local is_bin2c = target:extraconf("rules", "utils.hlsl2spv", "bin2c")
if is_bin2c then
@@ -54,7 +55,7 @@ rule("utils.hlsl2spv")
end
end)
- before_buildcmd_file(function (target, batchcmds, sourcefile_hlsl, opt)
+ on_preparecmd_file(function (target, batchcmds, sourcefile_hlsl, opt)
import("lib.detect.find_tool")
import("rules.utils.bin2obj.utils", {alias = "bin2obj_utils", rootdir = os.programdir()})
import("rules.utils.bin2c.utils", {alias = "bin2c_utils", rootdir = os.programdir()})