diff options
| author | ruki <[email protected]> | 2021-08-21 10:16:45 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-08-21 10:16:45 +0800 |
| commit | 875fdfe22fb96ff5ef2b654b276acd363f2b906b (patch) | |
| tree | 4221aaa71bea36f1d555228e4bff0b68020d7ca0 | |
| parent | bc582fd4bdaee3add88a4e15f1764c7e11eec41c (diff) | |
improve lock packages
4 files changed, 43 insertions, 31 deletions
diff --git a/tests/projects/package/toolchain_muslcc/xmake-requires.lock b/tests/projects/package/toolchain_muslcc/xmake-requires.lock index d31ecd965..764165028 100644 --- a/tests/projects/package/toolchain_muslcc/xmake-requires.lock +++ b/tests/projects/package/toolchain_muslcc/xmake-requires.lock @@ -4,15 +4,15 @@ }, ["autoconf#ddbdd8b8f76d455a8c0ef45fffe37160"] = { arch = "x86_64", - buildhash = "01974c48f52d4d658f58852351743754", + buildhash = "cd4169a7cb484832b2f70d2174072ca2", name = "autoconf", plat = "macosx", repo = { branch = "master", - commit = "df6cad5cf5701de3705c7afce54d732e1f5b14b9", + commit = "d0e1f98585a4ec31b056fe3bda65a4fe37e0b375", url = "https://gitee.com/tboox/xmake-repo.git" }, - version = "2.69" + version = "2.71" }, ["automake#ddbdd8b8f76d455a8c0ef45fffe37160"] = { arch = "x86_64", @@ -21,7 +21,7 @@ plat = "macosx", repo = { branch = "master", - commit = "df6cad5cf5701de3705c7afce54d732e1f5b14b9", + commit = "d0e1f98585a4ec31b056fe3bda65a4fe37e0b375", url = "https://gitee.com/tboox/xmake-repo.git" }, version = "1.16.1" @@ -33,7 +33,7 @@ plat = "macosx", repo = { branch = "master", - commit = "df6cad5cf5701de3705c7afce54d732e1f5b14b9", + commit = "d0e1f98585a4ec31b056fe3bda65a4fe37e0b375", url = "https://gitee.com/tboox/xmake-repo.git" }, version = "3.21.0" @@ -45,7 +45,7 @@ plat = "macosx", repo = { branch = "master", - commit = "df6cad5cf5701de3705c7afce54d732e1f5b14b9", + commit = "d0e1f98585a4ec31b056fe3bda65a4fe37e0b375", url = "https://gitee.com/tboox/xmake-repo.git" }, version = "6.2.1" @@ -57,7 +57,7 @@ plat = "macosx", repo = { branch = "master", - commit = "df6cad5cf5701de3705c7afce54d732e1f5b14b9", + commit = "d0e1f98585a4ec31b056fe3bda65a4fe37e0b375", url = "https://gitee.com/tboox/xmake-repo.git" }, version = "0.22" @@ -69,7 +69,7 @@ plat = "cross", repo = { branch = "master", - commit = "df6cad5cf5701de3705c7afce54d732e1f5b14b9", + commit = "d0e1f98585a4ec31b056fe3bda65a4fe37e0b375", url = "https://gitee.com/tboox/xmake-repo.git" }, version = "v1.3.4" @@ -81,7 +81,7 @@ plat = "cross", repo = { branch = "master", - commit = "df6cad5cf5701de3705c7afce54d732e1f5b14b9", + commit = "d0e1f98585a4ec31b056fe3bda65a4fe37e0b375", url = "https://gitee.com/tboox/xmake-repo.git" }, version = "2.2.0" @@ -93,7 +93,7 @@ plat = "macosx", repo = { branch = "master", - commit = "df6cad5cf5701de3705c7afce54d732e1f5b14b9", + commit = "d0e1f98585a4ec31b056fe3bda65a4fe37e0b375", url = "https://gitee.com/tboox/xmake-repo.git" }, version = "2.4.6" @@ -105,7 +105,7 @@ plat = "macosx", repo = { branch = "master", - commit = "df6cad5cf5701de3705c7afce54d732e1f5b14b9", + commit = "d0e1f98585a4ec31b056fe3bda65a4fe37e0b375", url = "https://gitee.com/tboox/xmake-repo.git" }, version = "1.4.19" @@ -117,7 +117,7 @@ plat = "macosx", repo = { branch = "master", - commit = "df6cad5cf5701de3705c7afce54d732e1f5b14b9", + commit = "d0e1f98585a4ec31b056fe3bda65a4fe37e0b375", url = "https://gitee.com/tboox/xmake-repo.git" }, version = "20210202" @@ -129,7 +129,7 @@ plat = "macosx", repo = { branch = "master", - commit = "df6cad5cf5701de3705c7afce54d732e1f5b14b9", + commit = "d0e1f98585a4ec31b056fe3bda65a4fe37e0b375", url = "https://gitee.com/tboox/xmake-repo.git" }, version = "0.29.2" @@ -141,7 +141,7 @@ plat = "cross", repo = { branch = "master", - commit = "df6cad5cf5701de3705c7afce54d732e1f5b14b9", + commit = "d0e1f98585a4ec31b056fe3bda65a4fe37e0b375", url = "https://gitee.com/tboox/xmake-repo.git" }, version = "1.2.11" 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 |
