diff options
| author | ruki <[email protected]> | 2018-11-11 00:45:08 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-11-11 00:45:08 +0800 |
| commit | e5818c9ac51fb7000b04e4ac1021fb27e550b0a9 (patch) | |
| tree | 04ddc17e093d18c19fd1f909481d1bfafcb5f566 | |
| parent | 53e2cf31fdc5adcb4949b9c54a81527a99d4171a (diff) | |
impl xmake update
| -rw-r--r-- | xmake/actions/update/main.lua | 104 | ||||
| -rw-r--r-- | xmake/actions/update/xmake.lua | 8 |
2 files changed, 107 insertions, 5 deletions
diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 74b78c284..56394e125 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -23,10 +23,114 @@ -- -- imports +import("core.base.semver") import("core.base.option") +import("core.base.task") +import("devel.git") +import("net.fasturl") +import("actions.require.impl.environment", {rootdir = os.programdir()}) + +-- do uninstall +function _uninstall() +end + +-- do install +function _install(sourcedir) + + -- trace + cprintf("${yellow} => ${clear}installing ..") + io.flush() + + -- install it + os.cd(sourcedir) + if is_host("windows") then + os.vrun("xmake -P core") + os.cp("xmake", os.programdir()) + os.cp("core/build/xmake.exe", os.programfile()) + else + if os.programdir():startswith("/usr/") then + os.vrun("make build") + os.vrun("make install") -- TODO sudo + else + os.vrun("./scripts/get.sh __local__") + end + end + + -- trace + cprint("\r${yellow} => ${clear}install to %s .. ${green}ok", os.programdir()) +end -- main function main() + -- only uninstall it + if option.get("uninstall") then + return _uninstall() + end + + -- enter environment + environment.enter() + + -- sort main urls + local mainurls = {"https://github.com/tboox/xmake.git", "https://gitlab.com/tboox/xmake.git", "https://gitee.com/tboox/xmake.git"} + fasturl.add(mainurls) + mainurls = fasturl.sort(mainurls) + + -- get version + local version = nil + for _, url in ipairs(mainurls) do + local tags, branches = git.refs(url) + if tags or branches then + version = semver.select(option.get("xmakever") or "lastest", tags or {}, tags or {}, branches or {}) + break + end + end + if not version then + version = "master" + end + + -- trace + print("update version: %s ..", version) + + -- download the source code + local sourcedir = path.join(os.tmpdir(), "xmakesrc", version) + for idx, url in ipairs(mainurls) do + cprintf("${yellow} => ${clear}clone %s ..", url) + io.flush() + local ok = try + { + function () + os.tryrm(sourcedir) + if version:find('.', 1, true) then + git.clone(url, {outputdir = sourcedir}) + git.checkout(version, {repodir = sourcedir}) + else + git.clone(url, {depth = 1, branch = version, outputdir = sourcedir}) + end + return true + end, + catch + { + function (errors) + vprint(errors) + end + } + } + if ok then + cprint("\r${yellow} => ${clear}clone %s .. ${green}ok", url) + break + else + cprint("\r${yellow} => ${clear}clone %s .. ${red}failed", url) + end + if not ok and idx == #mainurls then + raise("download failed!") + end + end + + -- leave environment + environment.leave() + + -- do install + _install(sourcedir) end diff --git a/xmake/actions/update/xmake.lua b/xmake/actions/update/xmake.lua index fa47a2336..d88320a48 100644 --- a/xmake/actions/update/xmake.lua +++ b/xmake/actions/update/xmake.lua @@ -42,11 +42,9 @@ task("update") -- options , options = { - {'b', "branch", "k", nil, "Update the given branch version." } - , {'u', "uninstall", "k", nil, "Uninstall the current xmake program." } - - , { } - , {nil, "version", "v", nil, "The given xmake version." } + {nil, "uninstall", "k", nil, "Uninstall the current xmake program." } + , { } + , {nil, "xmakever", "v", nil, "The given xmake version. (e.g. ~2.2.3, dev, master)" } } } |
