summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2026-08-14 23:42:13 +0800
committerruki <[email protected]>2026-08-14 23:42:13 +0800
commit46141dbac176444bd1ed114ea419d4bb8e6d2e13 (patch)
tree5bb62ecf325bd4d42bcedd2440a35dddada97c57 /xmake/modules
parenta79cf74f920c088528d66a67a59b3d8eaa1d4f7a (diff)
update lock and version
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/private/action/require/impl/actions/install.lua4
-rw-r--r--xmake/modules/private/addons/main.lua56
2 files changed, 51 insertions, 9 deletions
diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua
index 65750c1bc..1a2e389b3 100644
--- a/xmake/modules/private/action/require/impl/actions/install.lua
+++ b/xmake/modules/private/action/require/impl/actions/install.lua
@@ -318,8 +318,12 @@ function _register_addon(package)
end
end
+ -- we also record where it comes from, so that the projects can lock it,
+ -- @see xmake/modules/private/addons/main.lua
+ local repo = package:repo()
addon.register(package:name(), package:version_str() or "latest",
{description = description, deps = deps,
+ repo = repo and {url = repo:url(), commit = repo:commit(), branch = repo:branch()} or nil,
manifest_deps = manifest and manifest.deps or nil,
globalmodules = manifest and #manifest.globalmodules > 0 and manifest.globalmodules or nil})
end
diff --git a/xmake/modules/private/addons/main.lua b/xmake/modules/private/addons/main.lua
index 43a623e20..1cdc2191d 100644
--- a/xmake/modules/private/addons/main.lua
+++ b/xmake/modules/private/addons/main.lua
@@ -28,15 +28,15 @@ local LOCKVERSION = "1.0"
-- get the requires of the declared addons
--
--- @note we always install the locked versions, the declared versions are only used
--- to resolve them when there is no lock yet, @see _lock_addons
+-- @note we install the locked versions, but the declaration is authoritative, so we
+-- resolve them again if the user has changed it or upgrades them
--
function _get_requires(addonsinfo, locked)
local requires = {}
for _, requirestr in ipairs(addonsinfo.addons) do
- local name = requirestr:split("%s")[1]
+ local name = addons.requirename(requirestr)
local lockinfo = locked and locked[name]
- if lockinfo and lockinfo.version then
+ if addons.locked_valid(requirestr, lockinfo) then
requirestr = name .. " " .. lockinfo.version
end
table.insert(requires, requirestr)
@@ -51,13 +51,20 @@ 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})
for _, requirestr in ipairs(addonsinfo.addons) do
- local name = requirestr:split("%s")[1]
+ local name = addons.requirename(requirestr)
local addoninfo = installed[addon.dirname(name)]
if addoninfo then
- lockinfo[name] = {version = addoninfo.version}
+ 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
end
lockinfo.__meta__ = {version = LOCKVERSION}
@@ -69,23 +76,54 @@ end
-- @note we are called from a sub-process, the project cannot be loaded until its
-- addons are installed, @see core/project/project.lua
--
-function main(projectdir)
+function main(projectdir, opt)
+ opt = opt or {}
projectdir = projectdir or os.projectdir()
local addonsinfo = addons.load(projectdir)
if not addonsinfo or #addonsinfo.addons == 0 then
return
end
+ -- upgrade them? we need to resolve the declared versions again
+ local locked = not opt.upgrade and addons.locked(projectdir) or nil
+
-- install them with xrepo, it installs the packages in its own working directory,
-- so we need not a project here
local argv = {"lua", "private.xrepo", "install", "--addon"}
+
+ -- this project declares its own repositories? we pass them to xrepo,
+ -- they are only used by this installation, we do not register them globally
+ local rcfile
+ if #addonsinfo.repositories > 0 then
+ rcfile = os.tmpfile() .. ".lua"
+ local file = io.open(rcfile, "w")
+ for _, repo in ipairs(addonsinfo.repositories) do
+ file:print("add_repositories(%q)", repo)
+ end
+ file:close()
+ table.insert(argv, "--includes=" .. rcfile)
+ end
+
for _, name in ipairs({"yes", "verbose", "diagnosis"}) do
if option.get(name) then
table.insert(argv, "--" .. name)
end
end
- table.join2(argv, _get_requires(addonsinfo, addons.locked(projectdir)))
- os.execv(os.programfile(), argv)
+ table.join2(argv, _get_requires(addonsinfo, locked))
+ try
+ {
+ function ()
+ os.execv(os.programfile(), argv)
+ end,
+ finally
+ {
+ function ()
+ if rcfile then
+ os.tryrm(rcfile)
+ end
+ end
+ }
+ }
-- and lock them, so that the other users get the same versions
_lock_addons(projectdir, addonsinfo)