summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-08-15 19:26:52 +0800
committerruki <[email protected]>2026-08-15 19:26:52 +0800
commit65854acd5e7080dae4cac3e3b3ec1ce01e902ae7 (patch)
tree5f32e58a6fffc615927833e2e15b077a35ae1e5f
parent4c7c17c10f8a4270b27d90958544ce2886dc6052 (diff)
fix upgrade addon
-rw-r--r--xmake/core/package/addon.lua17
-rw-r--r--xmake/modules/private/action/addon/impl/install_addons.lua23
2 files changed, 28 insertions, 12 deletions
diff --git a/xmake/core/package/addon.lua b/xmake/core/package/addon.lua
index 71af9aceb..6e7d62eb4 100644
--- a/xmake/core/package/addon.lua
+++ b/xmake/core/package/addon.lua
@@ -496,9 +496,24 @@ end
-- @return the addons table, e.g. {["hello-world"] = {version = "latest", payloads = {"plugins"}}}
--
function addon.addons(opt)
- if opt and opt.force then
+ opt = opt or {}
+ if opt.force then
addon._registry({force = true})
end
+
+ -- get the really installed versions instead of the pinned ones? e.g. locking them
+ -- @note we do not cache it, the cache is the pinned view of this project
+ if opt.unpinned then
+ local addons = {}
+ for dirname, addoninfo in pairs(addon._registry()) do
+ local versioninfo = addoninfo.versions and addoninfo.versions[addoninfo.active]
+ if versioninfo then
+ addons[dirname] = versioninfo
+ end
+ end
+ return addons
+ end
+
local addons = addon._ADDONS
if addons == nil then
addons = {}
diff --git a/xmake/modules/private/action/addon/impl/install_addons.lua b/xmake/modules/private/action/addon/impl/install_addons.lua
index a20ed740b..0a288f1a3 100644
--- a/xmake/modules/private/action/addon/impl/install_addons.lua
+++ b/xmake/modules/private/action/addon/impl/install_addons.lua
@@ -49,20 +49,21 @@ end
function _lock_addons(projectdir, addonsinfo)
local lockinfo = {}
local locked = addons.locked(projectdir) or {}
- -- @note we need to reload the registry, they have been installed by another process
- local installed = addon.addons({force = true})
+
+ -- @note we need to reload the registry, they have been installed by another process,
+ -- and we must not see them through the locked versions, we are locking them right now,
+ -- e.g. `xmake addon --upgrade` pins the old ones before loading this project
+ local installed = addon.addons({force = true, unpinned = true})
for _, requirestr in ipairs(addonsinfo.addons) do
local name = addons.requirename(requirestr)
- local addoninfo = installed[addon.dirname(name)]
- if addoninfo then
- local oldversion = locked[name] and locked[name].version
- if oldversion and oldversion ~= addoninfo.version then
- cprint("${color.success}upgrade ${bright}%s${clear}: %s -> %s", name, oldversion, addoninfo.version)
- end
- -- we lock the repository too, so that the other users get it from the same source,
- -- @see xmake/modules/private/action/require/impl/lock_packages.lua
- lockinfo[name] = {version = addoninfo.version, repo = addoninfo.repo}
+ local addoninfo = assert(installed[addon.dirname(name)], "addon(%s) is not installed!", name)
+ local oldversion = locked[name] and locked[name].version
+ if oldversion and oldversion ~= addoninfo.version then
+ cprint("${color.success}upgrade ${bright}%s${clear}: %s -> %s", name, oldversion, addoninfo.version)
end
+ -- we lock the repository too, so that the other users get it from the same source,
+ -- @see xmake/modules/private/action/require/impl/lock_packages.lua
+ lockinfo[name] = {version = addoninfo.version, repo = addoninfo.repo}
end
lockinfo.__meta__ = {version = addons.lockfile_version()}