summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2026-01-15 06:45:55 +0800
committerGitHub <[email protected]>2026-01-15 06:45:55 +0800
commit6a282204b4d2d27f987ff6b9c2ebf7a680ab7971 (patch)
treeec291e03ad6f9e2df0963ab7035a93c74c5866ce /xmake/modules
parent6889b866db029a4d3ca5ed9a22238eb6d672657e (diff)
parent530e5a95527fc004bc70027e413cb91d15aa0a8a (diff)
Merge pull request #7216 from xmake-io/requirelock
Improve requirelock
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/private/action/require/impl/lock_packages.lua25
1 files changed, 15 insertions, 10 deletions
diff --git a/xmake/modules/private/action/require/impl/lock_packages.lua b/xmake/modules/private/action/require/impl/lock_packages.lua
index f51092b47..61cc19a85 100644
--- a/xmake/modules/private/action/require/impl/lock_packages.lua
+++ b/xmake/modules/private/action/require/impl/lock_packages.lua
@@ -39,15 +39,10 @@ function _lock_package(instance)
result.branch = instance:branch()
result.tag = instance:tag()
if repo then
- local lastcommit
- local manifest = instance:manifest_load()
- if manifest and manifest.repo then
- lastcommit = manifest.repo.commit
- end
- if not lastcommit then
- lastcommit = repo:commit()
- end
- result.repo = {url = repo:url(), commit = lastcommit, branch = repo:branch()}
+ -- Even when locking pre-compiled packages,
+ -- we always use the repo and commit info in the current repository (instead of precompiled-artifacts manifest)
+ -- to ensure that the repo information remains stable when reverting to source code installation.
+ result.repo = {url = repo:url(), commit = repo:commit(), branch = repo:branch()}
end
return result
end
@@ -66,7 +61,17 @@ function main(packages)
local packagelock_key = _get_packagelock_key(instance)
results[key][packagelock_key] = _lock_package(instance)
end
- io.writefile(project.requireslock(), string.serialize(results, {orderkeys = true}), {encoding = "binary"})
+ -- write to temporary file first, then copy if content is different
+ local lockfile = project.requireslock()
+ local content = string.serialize(results, {orderkeys = true})
+ local tmpfile = os.tmpfile()
+
+ -- write to temporary file
+ io.writefile(tmpfile, content, {encoding = "binary"})
+
+ -- copy to target file only if content is different
+ os.cp(tmpfile, lockfile, {copy_if_different = true})
+ os.rm(tmpfile)
end
end