summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2021-08-21 10:16:45 +0800
committerruki <[email protected]>2021-08-21 10:16:45 +0800
commit875fdfe22fb96ff5ef2b654b276acd363f2b906b (patch)
tree4221aaa71bea36f1d555228e4bff0b68020d7ca0 /xmake/modules
parentbc582fd4bdaee3add88a4e15f1764c7e11eec41c (diff)
improve lock packages
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/private/action/require/impl/install_packages.lua4
-rw-r--r--xmake/modules/private/action/require/impl/lock_packages.lua6
-rw-r--r--xmake/modules/private/action/require/impl/repository.lua36
3 files changed, 29 insertions, 17 deletions
diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua
index 75ca4414e..79fb71c3f 100644
--- a/xmake/modules/private/action/require/impl/install_packages.lua
+++ b/xmake/modules/private/action/require/impl/install_packages.lua
@@ -603,9 +603,7 @@ function main(requires, opt)
register_packages(packages)
-- lock packages
- if #packages_install > 0 then
- lock_packages(packages)
- end
+ lock_packages(packages)
return packages
end
diff --git a/xmake/modules/private/action/require/impl/lock_packages.lua b/xmake/modules/private/action/require/impl/lock_packages.lua
index 18dabcac4..05debf6f2 100644
--- a/xmake/modules/private/action/require/impl/lock_packages.lua
+++ b/xmake/modules/private/action/require/impl/lock_packages.lua
@@ -43,7 +43,11 @@ function _lock_package(instance)
result.branch = instance:branch()
result.tag = instance:tag()
if repo then
- local lastcommit = git.lastcommit({repodir = repo:directory()})
+ local lastcommit = try {function()
+ if os.isdir(path.join(repo:directory(), ".git")) then
+ return git.lastcommit({repodir = repo:directory()})
+ end
+ end}
result.repo = {url = repo:url(), commit = lastcommit, branch = repo:branch()}
end
return result
diff --git a/xmake/modules/private/action/require/impl/repository.lua b/xmake/modules/private/action/require/impl/repository.lua
index 528aebc54..1acbfb618 100644
--- a/xmake/modules/private/action/require/impl/repository.lua
+++ b/xmake/modules/private/action/require/impl/repository.lua
@@ -38,8 +38,15 @@ function _get_packagedir_from_locked_repo(packagename, locked_repo)
end
local reponame = hash.uuid(locked_repo.url):gsub("%-", ""):lower() .. ".lock"
+ -- get local repodir
+ local repodir_local
+ if os.isdir(locked_repo.url) then
+ repodir_local = locked_repo.url
+ else
+ repodir_local = path.join(config.directory(), "repositories", reponame)
+ end
+
-- clone repository to local
- local repodir_local = path.join(config.directory(), "repositories", reponame)
if not os.isdir(repodir_local) then
if repodir_global then
git.clone(repodir_global, {verbose = option.get("verbose"), outputdir = repodir_local})
@@ -51,17 +58,20 @@ function _get_packagedir_from_locked_repo(packagename, locked_repo)
end
end
- -- try checkout to the given commit
- local ok = try {function () git.checkout(locked_repo.commit, {verbose = option.get("verbose"), repodir = repodir_local}); return true end}
- if not ok then
- if global.get("network") ~= "private" then
- -- pull the latest commit
- git.pull({verbose = option.get("verbose"), remote = locked_repo.url, branch = locked_repo.branch, repodir = repodir_local})
- -- re-checkout to the given commit
- ok = try {function () git.checkout(locked_repo.commit, {verbose = option.get("verbose"), repodir = repodir_local}); return true end}
- else
- wprint("we cannot lock repository(%s) in private network mode!", locked_repo.url)
- return
+ -- lock commit
+ if locked_repo.commit and os.isdir(path.join(repodir_local, ".git")) then
+ -- try checkout to the given commit
+ local ok = try {function () git.checkout(locked_repo.commit, {verbose = option.get("verbose"), repodir = repodir_local}); return true end}
+ if not ok then
+ if global.get("network") ~= "private" then
+ -- pull the latest commit
+ git.pull({verbose = option.get("verbose"), remote = locked_repo.url, branch = locked_repo.branch, repodir = repodir_local})
+ -- re-checkout to the given commit
+ ok = try {function () git.checkout(locked_repo.commit, {verbose = option.get("verbose"), repodir = repodir_local}); return true end}
+ else
+ wprint("we cannot lock repository(%s) in private network mode!", locked_repo.url)
+ return
+ end
end
end
@@ -118,7 +128,7 @@ function packagedir(packagename, opt)
local cachekey = packagename
local locked_repo = opt.locked_repo
if locked_repo then
- cachekey = cachekey .. locked_repo.url .. locked_repo.commit .. (locked_repo.branch or "")
+ cachekey = cachekey .. locked_repo.url .. (locked_repo.commit or "") .. (locked_repo.branch or "")
end
local packagedirs = _g._PACKAGEDIRS
if not packagedirs then