diff options
| author | ruki <[email protected]> | 2023-11-09 22:52:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-11-09 22:52:02 +0800 |
| commit | 39c111a6987a04c49468cf6c1c3a192d60dd7b4c (patch) | |
| tree | 9fb3d873614dda17f9ce49083bd06b9af1a4b923 | |
| parent | 13795fa26f2699f464a2599ca61a41e2d413b7c0 (diff) | |
add network.mode policy
| -rw-r--r-- | xmake/core/project/policy.lua | 5 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/package/repository.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/repository.lua | 19 |
3 files changed, 28 insertions, 6 deletions
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index c0bf0e4e1..5d1e47c53 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -124,7 +124,10 @@ function policy.policies() -- Return zero as exit code on failure ["test.return_zero_on_failure"] = {description = "Return zero as the exit code on failure", default = false, type = "boolean"}, -- Show diagnosis info for checking build dependencies - ["diagnosis.check_build_deps"] = {description = "Show diagnosis info for checking build dependencies", default = false, type = "boolean"} + ["diagnosis.check_build_deps"] = {description = "Show diagnosis info for checking build dependencies", default = false, type = "boolean"}, + -- Set the network mode, e.g. public/private + -- private: it will disable fetch remote package repositories + ["network.mode"] = {description = "Set the network mode", type = "string"} } policy._POLICIES = policies end diff --git a/xmake/core/sandbox/modules/import/core/package/repository.lua b/xmake/core/sandbox/modules/import/core/package/repository.lua index 5c21f5de5..9f82b3e4d 100644 --- a/xmake/core/sandbox/modules/import/core/package/repository.lua +++ b/xmake/core/sandbox/modules/import/core/package/repository.lua @@ -107,6 +107,12 @@ function sandbox_core_package_repository.repositories(is_global) -- add global xmake repositories if is_global then + -- get the network mode + local network = project.policy("network.mode") + if network == nil then + network = global.get("network") + end + -- add artifacts urls local artifacts_urls = localcache.cache("repository"):get("artifacts_urls") if not artifacts_urls then @@ -117,7 +123,7 @@ function sandbox_core_package_repository.repositories(is_global) artifacts_urls = {"https://github.com/xmake-mirror/build-artifacts.git", "https://gitlab.com/xmake-mirror/build-artifacts.git", "https://gitee.com/xmake-mirror/build-artifacts.git"} - if global.get("network") ~= "private" then + if network ~= "private" then import("net.fasturl") fasturl.add(artifacts_urls) artifacts_urls = fasturl.sort(artifacts_urls) @@ -143,7 +149,7 @@ function sandbox_core_package_repository.repositories(is_global) mainurls = {"https://github.com/xmake-io/xmake-repo.git", "https://gitlab.com/tboox/xmake-repo.git", "https://gitee.com/tboox/xmake-repo.git"} - if global.get("network") ~= "private" then + if network ~= "private" then import("net.fasturl") fasturl.add(mainurls) mainurls = fasturl.sort(mainurls) diff --git a/xmake/modules/private/action/require/impl/repository.lua b/xmake/modules/private/action/require/impl/repository.lua index b57f8dfe4..98cd45bd2 100644 --- a/xmake/modules/private/action/require/impl/repository.lua +++ b/xmake/modules/private/action/require/impl/repository.lua @@ -22,6 +22,7 @@ import("core.base.option") import("core.base.global") import("core.project.config") +import("core.project.project") import("core.package.repository") import("devel.git") import("net.proxy") @@ -49,13 +50,19 @@ function _get_packagedir_from_locked_repo(packagename, locked_repo) repodir_local = path.join(config.directory(), "repositories", reponame) end + -- get the network mode? + local network = project.policy("network.mode") + if network == nil then + network = global.get("network") + end + -- clone repository to local local lastcommit if not os.isdir(repodir_local) then if repo_global then git.clone(repo_global:directory(), {verbose = option.get("verbose"), outputdir = repodir_local}) lastcommit = repo_global:commit() - elseif global.get("network") ~= "private" then + elseif network ~= "private" then local remoteurl = proxy.mirror(locked_repo.url) or locked_repo.url git.clone(remoteurl, {verbose = option.get("verbose"), branch = locked_repo.branch, outputdir = repodir_local}) else @@ -74,7 +81,7 @@ function _get_packagedir_from_locked_repo(packagename, locked_repo) -- try checkout to the given commit 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 + if network ~= "private" then -- pull the latest commit local remoteurl = proxy.mirror(locked_repo.url) or locked_repo.url git.pull({verbose = option.get("verbose"), remote = remoteurl, branch = locked_repo.branch, repodir = repodir_local}) @@ -116,7 +123,13 @@ end -- the remote repositories have been pulled? function pulled() - if global.get("network") ~= "private" then + + local network = project.policy("network.mode") + if network == nil then + network = global.get("network") + end + + if network ~= "private" then for _, repo in ipairs(repositories()) do if not os.isdir(repo:url()) then -- repository not found? or xmake has been re-installed |
