summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2026-08-15 00:04:39 +0800
committerruki <[email protected]>2026-08-15 00:04:39 +0800
commitca9239022e1cba0faf054e8fe2f178a466149b04 (patch)
treef646b0c7348435a970bcd28f1cd4dcea2e59dec7 /xmake/modules
parentb13c11f9457e274eeb5e7c51547f619eb4aa6a68 (diff)
improve xrepo addon install
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/private/action/addon/impl/install_addons.lua30
-rw-r--r--xmake/modules/private/action/addon/impl/xrepo.lua54
2 files changed, 72 insertions, 12 deletions
diff --git a/xmake/modules/private/action/addon/impl/install_addons.lua b/xmake/modules/private/action/addon/impl/install_addons.lua
index 6ece11964..02bb87e2f 100644
--- a/xmake/modules/private/action/addon/impl/install_addons.lua
+++ b/xmake/modules/private/action/addon/impl/install_addons.lua
@@ -19,9 +19,9 @@
--
-- imports
-import("core.base.option")
import("core.package.addon")
import("core.project.addons")
+import("private.action.addon.impl.xrepo", {alias = "xrepo_addon"})
-- the format version of the addons lock file
local LOCKVERSION = "1.0"
@@ -68,7 +68,17 @@ function _lock_addons(projectdir, addonsinfo)
end
end
lockinfo.__meta__ = {version = LOCKVERSION}
- io.save(addons.lockfile(projectdir), lockinfo, {orderkeys = true})
+
+ -- @note we need to write it deterministically, the key order of a lua table is random,
+ -- otherwise the lock file would change even if nothing changed,
+ -- @see xmake/modules/private/action/require/impl/lock_packages.lua
+ local content = string.serialize(lockinfo, {orderkeys = true})
+ local tmpfile = os.tmpfile()
+ io.writefile(tmpfile, content, {encoding = "binary"})
+
+ -- and we only write it if the content is different, so we can keep the file time
+ os.cp(tmpfile, addons.lockfile(projectdir), {copy_if_different = true})
+ os.rm(tmpfile)
end
-- install the addons which the given project declares in its `xmake-addons.lua`
@@ -89,7 +99,6 @@ function main(projectdir, opt)
-- 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
@@ -101,26 +110,23 @@ function main(projectdir, opt)
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, locked))
try
{
function ()
- os.execv(os.programfile(), argv)
+ xrepo_addon("install", _get_requires(addonsinfo, locked), {includes = rcfile})
end,
finally
{
- function ()
+ -- @note try() swallows the errors if we do not re-raise them here
+ function (ok, errors)
if rcfile then
os.tryrm(rcfile)
end
+ if not ok then
+ raise(errors)
+ end
end
}
}
diff --git a/xmake/modules/private/action/addon/impl/xrepo.lua b/xmake/modules/private/action/addon/impl/xrepo.lua
new file mode 100644
index 000000000..34c1d2632
--- /dev/null
+++ b/xmake/modules/private/action/addon/impl/xrepo.lua
@@ -0,0 +1,54 @@
+--!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 xrepo.lua
+--
+
+-- imports
+import("core.base.option")
+
+-- run the given xrepo action for the addons
+--
+-- @note xrepo installs the packages in its own working project, so it works anywhere,
+-- and we need not implement the download/dependencies/confirm logic again
+--
+-- @param action the action name, e.g. "install", "search"
+-- @param names the addon names, urls or require strings, e.g. {"esp32-devel 1.0.x"}
+-- @param opt the options, e.g. {force = true, includes = "/tmp/xxx.lua", curdir = "/tmp"}
+--
+function main(action, names, opt)
+ opt = opt or {}
+ local argv = {"lua", "private.xrepo", action, "--addon"}
+
+ -- we need to pass the common options to the sub-process, e.g. -y, -v, -D
+ for _, name in ipairs({"yes", "verbose", "diagnosis"}) do
+ if option.get(name) then
+ table.insert(argv, "--" .. name)
+ end
+ end
+ if opt.force then
+ table.insert(argv, "--force")
+ end
+
+ -- the extra lua configuration files, e.g. the repositories which a project declares
+ if opt.includes then
+ table.insert(argv, "--includes=" .. opt.includes)
+ end
+
+ table.join2(argv, names)
+ os.execv(os.programfile(), argv, {curdir = opt.curdir})
+end