summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2026-08-09 17:57:20 +0800
committerruki <[email protected]>2026-08-09 18:28:59 +0800
commit7caece0cb3ee8ab207130edc17421d604610e686 (patch)
tree0c29dff7e79f0b455f707b9dec7de6ea1cabe2f8 /xmake/modules
parentcf62f410738a7489fe052d183bcf616ecf5f7067 (diff)
improve addon to import includes, rules and toolchains
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/private/action/require/impl/actions/install.lua12
-rw-r--r--xmake/modules/private/action/require/impl/package.lua19
-rw-r--r--xmake/modules/private/xrepo/action/remove.lua3
3 files changed, 26 insertions, 8 deletions
diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua
index 40ca225f0..629b37aff 100644
--- a/xmake/modules/private/action/require/impl/actions/install.lua
+++ b/xmake/modules/private/action/require/impl/actions/install.lua
@@ -503,8 +503,16 @@ function main(package)
-- register this addon, so that xmake can find its payloads, e.g. plugins
if package:is_addon() then
- addon.register(package:name(), package:version_str() or "latest",
- {description = package:description()})
+ local deps
+ for _, dep in ipairs(package:plaindeps() or {}) do
+ if dep:is_addon() then
+ deps = deps or {}
+ table.insert(deps, dep:name())
+ end
+ end
+ local ok, errors = addon.register(package:name(), package:version_str() or "latest",
+ {description = package:description(), deps = deps})
+ assert(ok, errors)
end
installed_now = true
end
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index e57850673..65d5f4153 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -209,11 +209,15 @@ function _load_package_from_repository(packagename, opt)
end
end
--- get the root directory of repositories for the given package kind
+-- get the root directory of repositories for the given package
--
-- e.g. "packages" (default), "addons", "plugins" (deprecated)
--
-function _get_repository_rootdir(packagekind)
+-- @note the addon packages are only searched from the `addons` root directory,
+-- and we need to set it explicitly, e.g. add_deps("foo", {kind = "addon"})
+--
+function _get_repository_rootdir(requireinfo, opt)
+ local packagekind = requireinfo.kind or opt.packagekind
if packagekind == "addon" then
return "addons"
elseif packagekind == "plugin" then
@@ -982,6 +986,12 @@ function _load_package(packagename, requireinfo, opt)
-- check circular dependency
opt = opt or {}
+
+ -- the `addon` and `self` names are reserved, we use them to reference the addon resources,
+ -- e.g. add_rules("@addon/esp32/flash"), import("@self.sdkconfig")
+ if packagename == "addon" or packagename == "self" then
+ raise("package(%s): the name `%s` is reserved by xmake for the addon references, please rename it!", packagename, packagename)
+ end
if opt.requirepath then
local splitinfo = opt.requirepath:split(".", {plain = true})
if #splitinfo > 3 and
@@ -1027,7 +1037,7 @@ function _load_package(packagename, requireinfo, opt)
plat = requireinfo.plat,
arch = requireinfo.arch,
name = requireinfo.reponame,
- rootdir = _get_repository_rootdir(opt.packagekind),
+ rootdir = _get_repository_rootdir(requireinfo, opt),
locked_repo = locked_requireinfo and locked_requireinfo.repo})
if package then
from_repo = true
@@ -1038,7 +1048,7 @@ function _load_package(packagename, requireinfo, opt)
if package and package:get("base") then
_load_package_from_base(package, package:get("base"), {
name = requireinfo.reponame,
- rootdir = _get_repository_rootdir(opt.packagekind),
+ rootdir = _get_repository_rootdir(requireinfo, opt),
locked_repo = locked_requireinfo and locked_requireinfo.repo})
end
@@ -1224,7 +1234,6 @@ function _load_packages(requires, opt)
parentinfo = requireinfo,
nodeps = opt.nodeps,
resolvedinfo = opt.resolvedinfo,
- packagekind = opt.packagekind,
system = false})
for _, dep in ipairs(plaindeps) do
dep:parents_add(package)
diff --git a/xmake/modules/private/xrepo/action/remove.lua b/xmake/modules/private/xrepo/action/remove.lua
index adfec92c0..ee078f225 100644
--- a/xmake/modules/private/xrepo/action/remove.lua
+++ b/xmake/modules/private/xrepo/action/remove.lua
@@ -48,6 +48,7 @@ function menu_options()
{nil, "addon", "k", nil, "Remove the given installed addon packages.",
"e.g.",
" - xrepo remove --addon serial-monitor" },
+ {'f', "force", "k", nil, "Force to remove the addon packages, even if they are depended on by the others." },
{nil, "all", "k", nil, "Remove all packages and ignore extra package configs.",
"If `--all` is enabled, the package name parameter will support lua pattern",
"e.g.",
@@ -200,7 +201,7 @@ end
-- remove the given installed addons
function _remove_addons(names)
for _, name in ipairs(names) do
- local ok, errors = addon.remove(name)
+ local ok, errors = addon.remove(name, {force = option.get("force")})
assert(ok, errors)
cprint("${color.success}remove ${bright}%s${clear} ok!", name)
end