diff options
| author | ruki <[email protected]> | 2021-08-19 23:50:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-08-19 23:50:02 +0800 |
| commit | 41213f3589000eb245aa33407ba971dbedc95c91 (patch) | |
| tree | 53fbfe2f83162a8c143d62a92c55bb14e03b5255 | |
| parent | 9112276d8065c9fdc0428bb4b44cf1b5794ab6d8 (diff) | |
add locked repo stub
| -rw-r--r-- | xmake/modules/private/action/require/impl/package.lua | 7 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/repository.lua | 58 |
2 files changed, 45 insertions, 20 deletions
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index e1c8d87cb..5084d2d29 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -195,8 +195,8 @@ function _load_package_from_project(packagename) end -- load package package from repositories -function _load_package_from_repository(packagename, reponame) - local packagedir, repo = repository.packagedir(packagename, reponame) +function _load_package_from_repository(packagename, opt) + local packagedir, repo = repository.packagedir(packagename, opt) if packagedir then return core_package.load_from_repository(packagename, repo, packagedir) end @@ -660,7 +660,8 @@ function _load_package(packagename, requireinfo, opt) -- load package from repositories local from_repo = false if not package then - package = _load_package_from_repository(packagename, requireinfo.reponame) + package = _load_package_from_repository(packagename, { + name = requireinfo.reponame, locked_repo = locked_requireinfo and locked_requireinfo.repo}) if package then from_repo = true end diff --git a/xmake/modules/private/action/require/impl/repository.lua b/xmake/modules/private/action/require/impl/repository.lua index 4dbf44e52..12a4772cf 100644 --- a/xmake/modules/private/action/require/impl/repository.lua +++ b/xmake/modules/private/action/require/impl/repository.lua @@ -22,6 +22,11 @@ import("core.base.global") import("core.package.repository") +-- get package directory from the locked repository +function _get_packagedir_from_locked_repo(packagename, locked_repo) +-- print(packagename, locked_repo) +end + -- get all repositories function repositories() if _g._REPOSITORIES then @@ -48,34 +53,53 @@ function pulled() end -- get package directory from repositories -function packagedir(packagename, reponame) +function packagedir(packagename, opt) -- strip trailng ~tag, e.g. zlib~debug + opt = opt or {} packagename = packagename:lower() if packagename:find('~', 1, true) then packagename = packagename:gsub("~.+$", "") end - -- get it from cache it - local packagedirs = _g._PACKAGEDIRS or {} - local foundir = packagedirs[packagename] - if foundir then - return foundir[1], foundir[2] + -- get cache key + local reponame = opt.name + 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 "") + end + local packagedirs = _g._PACKAGEDIRS + if not packagedirs then + packagedirs = {} + _g._PACKAGEDIRS = packagedirs end - -- find the package directory from repositories - for _, repo in ipairs(repositories()) do - local dir = path.join(repo:directory(), "packages", packagename:sub(1, 1), packagename) - if os.isdir(dir) and os.isfile(path.join(dir, "xmake.lua")) and (not reponame or reponame == repo:name()) then - foundir = {dir, repo} - break + -- get the package directory + local foundir = packagedirs[cachekey] + if not foundir then + + -- find the package directory from the locked repository + if locked_repo then + local dir, repo = _get_packagedir_from_locked_repo(packagename, locked_repo) + if dir and repo then + foundir = {dir, repo} + end end + + -- find the package directory from repositories + if not foundir then + for _, repo in ipairs(repositories()) do + local dir = path.join(repo:directory(), "packages", packagename:sub(1, 1), packagename) + if os.isdir(dir) and os.isfile(path.join(dir, "xmake.lua")) and (not reponame or reponame == repo:name()) then + foundir = {dir, repo} + break + end + end + end + packagedirs[cachekey] = foundir or {} end - if foundir then - packagedirs[packagename] = foundir - _g._PACKAGEDIRS = packagedirs - return foundir[1], foundir[2] - end + return foundir[1], foundir[2] end -- get artifacts manifest from repositories |
