diff options
| author | ruki <[email protected]> | 2020-06-23 22:52:21 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-06-23 11:14:09 +0800 |
| commit | 873b532f381d4dddabe5370dcffef49816f9f808 (patch) | |
| tree | 48c1296414ba9eb0b3ec9e74bbd54d471c841910 | |
| parent | 1b43e9cd4f5a38025478ade0de3f044d7b1e9ee7 (diff) | |
add global proxy settings
| -rw-r--r-- | xmake/actions/global/xmake.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/devel/git/clone.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/devel/git/ls_remote.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/devel/git/pull.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/net/http/download.lua | 25 |
5 files changed, 57 insertions, 3 deletions
diff --git a/xmake/actions/global/xmake.lua b/xmake/actions/global/xmake.lua index 89293e75e..720b51066 100644 --- a/xmake/actions/global/xmake.lua +++ b/xmake/actions/global/xmake.lua @@ -49,6 +49,11 @@ task("global") return import("core.theme.theme.names")() end} , {nil, "debugger", "kv", "auto" , "The debugger program path." } + , {'x', "proxy", "kv", nil , "Use proxy on given port. [PROTOCOL://]HOST[:PORT]" + , " e.g." + , " - xmake g --proxy='http://host:port'" + , " - xmake g --proxy='https://host:port'" + , " - xmake g --proxy='socks5://host:port'" } -- package configuration , {category = "Package Configuration"} diff --git a/xmake/modules/devel/git/clone.lua b/xmake/modules/devel/git/clone.lua index 4285b392d..a2fb554fb 100644 --- a/xmake/modules/devel/git/clone.lua +++ b/xmake/modules/devel/git/clone.lua @@ -20,6 +20,7 @@ -- imports import("core.base.option") +import("core.base.global") import("lib.detect.find_tool") -- clone url @@ -75,6 +76,13 @@ function main(url, opt) table.insert(argv, path.translate(opt.outputdir)) end + -- use proxy? + local envs + local proxy = global.get("proxy") + if proxy then + envs = {ALL_PROXY = proxy} + end + -- clone it - os.vrunv(git.program, argv) + os.vrunv(git.program, argv, {envs = envs}) end diff --git a/xmake/modules/devel/git/ls_remote.lua b/xmake/modules/devel/git/ls_remote.lua index a52e0d68d..ebbb99d98 100644 --- a/xmake/modules/devel/git/ls_remote.lua +++ b/xmake/modules/devel/git/ls_remote.lua @@ -20,6 +20,7 @@ -- imports import("core.base.option") +import("core.base.global") import("lib.detect.find_tool") -- ls_remote to given branch, tag or commit @@ -55,8 +56,15 @@ function main(reftype, url) print("%s %s", git.program, os.args(argv)) end + -- use proxy? + local envs + local proxy = global.get("proxy") + if proxy then + envs = {ALL_PROXY = proxy} + end + -- get refs - local data = os.iorunv(git.program, argv) + local data = os.iorunv(git.program, argv, {envs = envs}) -- get commmits and tags local refs = {} diff --git a/xmake/modules/devel/git/pull.lua b/xmake/modules/devel/git/pull.lua index 7eba74114..6e0f0a735 100644 --- a/xmake/modules/devel/git/pull.lua +++ b/xmake/modules/devel/git/pull.lua @@ -20,6 +20,7 @@ -- imports import("core.base.option") +import("core.base.global") import("lib.detect.find_tool") -- pull remote commits @@ -63,8 +64,15 @@ function main(opt) oldir = os.cd(opt.repodir) end + -- use proxy? + local envs + local proxy = global.get("proxy") + if proxy then + envs = {ALL_PROXY = proxy} + end + -- pull it - os.vrunv(git.program, argv) + os.vrunv(git.program, argv, {envs = envs}) -- leave repository directory if oldir then diff --git a/xmake/modules/net/http/download.lua b/xmake/modules/net/http/download.lua index 6a292c20e..f85561d49 100644 --- a/xmake/modules/net/http/download.lua +++ b/xmake/modules/net/http/download.lua @@ -20,6 +20,7 @@ -- imports import("core.base.option") +import("core.base.global") import("lib.detect.find_tool") -- get user agent @@ -62,6 +63,13 @@ function _curl_download(tool, url, outputfile) table.insert(argv, "-fsSL") end + -- use proxy? + local proxy = global.get("proxy") + if proxy then + table.insert(argv, "-x") + table.insert(argv, proxy) + end + -- set user-agent local user_agent = _get_user_agent() if user_agent then @@ -99,6 +107,23 @@ function _wget_download(tool, url, outputfile) os.mkdir(outputdir) end + -- use proxy? + local proxy = global.get("proxy") + if proxy then + table.insert(argv, "-e") + table.insert(argv, "use_proxy=yes") + table.insert(argv, "-e") + if url:startswith("http://") then + table.insert(argv, "http_proxy=" .. proxy) + elseif url:startswith("https://") then + table.insert(argv, "https_proxy=" .. proxy) + elseif url:startswith("ftp://") then + table.insert(argv, "ftp_proxy=" .. proxy) + else + table.insert(argv, "http_proxy=" .. proxy) + end + end + -- set user-agent local user_agent = _get_user_agent() if user_agent then |
