summaryrefslogtreecommitdiff
path: root/xmake/modules/private
diff options
context:
space:
mode:
authorruki <[email protected]>2026-08-14 23:28:20 +0800
committerruki <[email protected]>2026-08-14 23:28:20 +0800
commita79cf74f920c088528d66a67a59b3d8eaa1d4f7a (patch)
treedca4cb0ca1fd210e04e8c59ffd9ab8c410747c1f /xmake/modules/private
parent6c246c12a09524780e5bfdc53bc27a892e4793a9 (diff)
autofetch addons
Diffstat (limited to 'xmake/modules/private')
-rw-r--r--xmake/modules/private/action/require/impl/install_packages.lua2
-rw-r--r--xmake/modules/private/action/require/impl/package.lua3
-rw-r--r--xmake/modules/private/addons/main.lua92
3 files changed, 97 insertions, 0 deletions
diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua
index 7ab247351..2d633109e 100644
--- a/xmake/modules/private/action/require/impl/install_packages.lua
+++ b/xmake/modules/private/action/require/impl/install_packages.lua
@@ -211,6 +211,8 @@ function _get_confirm(packages, opt)
-- show tips
if opt.toolchain then
cprint("${bright color.warning}note: ${clear}install or modify (m) these ${bright}toolchain${clear} packages first (pass -y to skip confirm)?")
+ elseif opt.packagekind == "addon" then
+ cprint("${bright color.warning}note: ${clear}install or modify (m) these ${bright}addons${clear} (pass -y to skip confirm)?")
else
cprint("${bright color.warning}note: ${clear}install or modify (m) these packages (pass -y to skip confirm)?")
end
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index 65d5f4153..1105384c8 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -1702,6 +1702,9 @@ function get_configs_str(package)
end
if requireinfo.kind then
table.insert(configs, requireinfo.kind)
+ elseif package:is_addon() then
+ -- @note the kind is only set for the dependencies, e.g. add_deps("foo", {kind = "addon"})
+ table.insert(configs, "addon")
end
local ignored_configs_for_buildhash = hashset.from(requireinfo.ignored_configs_for_buildhash or {})
local configs_overrided = requireinfo.configs_overrided or {}
diff --git a/xmake/modules/private/addons/main.lua b/xmake/modules/private/addons/main.lua
new file mode 100644
index 000000000..43a623e20
--- /dev/null
+++ b/xmake/modules/private/addons/main.lua
@@ -0,0 +1,92 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file main.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.package.addon")
+import("core.project.addons")
+
+-- the format version of the addons lock file
+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
+--
+function _get_requires(addonsinfo, locked)
+ local requires = {}
+ for _, requirestr in ipairs(addonsinfo.addons) do
+ local name = requirestr:split("%s")[1]
+ local lockinfo = locked and locked[name]
+ if lockinfo and lockinfo.version then
+ requirestr = name .. " " .. lockinfo.version
+ end
+ table.insert(requires, requirestr)
+ end
+ return requires
+end
+
+-- lock the installed addons, so that we always get the same ones
+--
+-- @note we get the installed versions from the addons registry, they are
+-- registered when installing them, @see core/package/addon.lua
+--
+function _lock_addons(projectdir, addonsinfo)
+ local lockinfo = {}
+ -- @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 addoninfo = installed[addon.dirname(name)]
+ if addoninfo then
+ lockinfo[name] = {version = addoninfo.version}
+ end
+ end
+ lockinfo.__meta__ = {version = LOCKVERSION}
+ io.save(addons.lockfile(projectdir), lockinfo, {orderkeys = true})
+end
+
+-- install the addons which the given project declares in its `xmake-addons.lua`
+--
+-- @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)
+ projectdir = projectdir or os.projectdir()
+ local addonsinfo = addons.load(projectdir)
+ if not addonsinfo or #addonsinfo.addons == 0 then
+ return
+ end
+
+ -- 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"}
+ 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)
+
+ -- and lock them, so that the other users get the same versions
+ _lock_addons(projectdir, addonsinfo)
+end