diff options
| author | ruki <[email protected]> | 2021-08-19 23:56:50 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-08-19 23:56:50 +0800 |
| commit | d96dd2ca564aca5ad0780feb9c14f57b76c693d2 (patch) | |
| tree | 66e6447710a7956d4a1ca5900729bc0e159b67df | |
| parent | 41213f3589000eb245aa33407ba971dbedc95c91 (diff) | |
lock repository
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/package/repository.lua | 19 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/repository.lua | 54 |
2 files changed, 57 insertions, 16 deletions
diff --git a/xmake/core/sandbox/modules/import/core/package/repository.lua b/xmake/core/sandbox/modules/import/core/package/repository.lua index 86f27b497..64135aa75 100644 --- a/xmake/core/sandbox/modules/import/core/package/repository.lua +++ b/xmake/core/sandbox/modules/import/core/package/repository.lua @@ -29,20 +29,13 @@ local repository = require("package/repository") local raise = require("sandbox/modules/raise") local import = require("sandbox/modules/import") --- get repository directory -function sandbox_core_package_repository.directory(is_global) - return repository.directory(is_global) -end - --- get repository url from the given name -function sandbox_core_package_repository.get(name, is_global) - return repository.get(name, is_global) -end +-- inherit some builtin interfaces +sandbox_core_package_repository.directory = repository.directory +sandbox_core_package_repository.get = repository.get +sandbox_core_package_repository.load = repository.load -- add repository url to the given name function sandbox_core_package_repository.add(name, url, branch, is_global) - - -- add it local ok, errors = repository.add(name, url, branch, is_global) if not ok then raise(errors) @@ -51,8 +44,6 @@ end -- remove repository from gobal or local directory function sandbox_core_package_repository.remove(name, is_global) - - -- remove it local ok, errors = repository.remove(name, is_global) if not ok then raise(errors) @@ -61,8 +52,6 @@ end -- clear all repositories from global or local directory function sandbox_core_package_repository.clear(is_global) - - -- clear all repositories local ok, errors = repository.clear(is_global) if not ok then raise(errors) diff --git a/xmake/modules/private/action/require/impl/repository.lua b/xmake/modules/private/action/require/impl/repository.lua index 12a4772cf..b38bc95d3 100644 --- a/xmake/modules/private/action/require/impl/repository.lua +++ b/xmake/modules/private/action/require/impl/repository.lua @@ -19,12 +19,64 @@ -- -- imports +import("core.base.option") import("core.base.global") +import("core.project.config") import("core.package.repository") +import("devel.git") -- get package directory from the locked repository function _get_packagedir_from_locked_repo(packagename, locked_repo) --- print(packagename, locked_repo) + print(packagename, locked_repo) + + -- find global repository directory + local repodir_global + for _, repo in ipairs(repositories()) do + if locked_repo.url == repo:url() and locked_repo.branch == repo:branch() then + repodir_global = repo:directory() + break + end + end + + -- clone repository to local + local reponame = path.basename(locked_repo.url) + 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}) + elseif global.get("network") ~= "private" then + git.clone(locked_repo.url, {verbose = option.get("verbose"), branch = locked_repo.branch, outputdir = repodir_local}) + else + wprint("we cannot lock repository(%s) in private network mode!", locked_repo.url) + return + 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"), 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 + + -- find package directory + local foundir + if ok then + local dir = path.join(repodir_local, "packages", packagename:sub(1, 1), packagename) + if os.isdir(dir) and os.isfile(path.join(dir, "xmake.lua")) then + local repo = repository.load(reponame, locked_repo.url, locked_repo.branch, false) + foundir = {dir, repo} + vprint("lock package(%s) in %s from repository(%s)/%s", packagename, dir, locked_repo.url, locked_repo.commit) + end + end + return foundir end -- get all repositories |
