diff options
| author | ruki <[email protected]> | 2018-11-11 14:38:58 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-11-11 14:38:58 +0800 |
| commit | 7d5215f5807e37a23d350aaa11fc1e1b6464bd7e (patch) | |
| tree | faecf2918f19e8dce5a9831871485cfd450bd4cb | |
| parent | c6f8926ba3ed2557ddd66a6b03436a34a2aeb90b (diff) | |
impl xmake update on windows
| -rw-r--r-- | scripts/installer.nsi | 2 | ||||
| -rw-r--r-- | xmake/actions/require/impl/package.lua | 6 | ||||
| -rw-r--r-- | xmake/actions/update/main.lua | 65 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 19 |
4 files changed, 70 insertions, 22 deletions
diff --git a/scripts/installer.nsi b/scripts/installer.nsi index e1d57ef67..5606d6a29 100644 --- a/scripts/installer.nsi +++ b/scripts/installer.nsi @@ -14,7 +14,7 @@ ;--------------------------------
; The name of the installer
-Name "xmake"
+Name "xmake-v2.2.2"
; The file to write
OutFile "xmake.exe"
diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua index 89d39d5be..814378276 100644 --- a/xmake/actions/require/impl/package.lua +++ b/xmake/actions/require/impl/package.lua @@ -172,7 +172,9 @@ function _load_package(packagename, requireinfo) end -- load package from project first - package = _load_package_from_project(packagename) + if os.isfile(os.projectfile()) then + package = _load_package_from_project(packagename) + end -- load package from repositories if not package then @@ -242,7 +244,7 @@ function _load_packages(requires, opt) for packagename, requireinfo in pairs(load_requires(requires, opt.requires_extra, opt.parentinfo)) do -- attempt to get project option about this package - local packageopt = project.option(packagename) + local packageopt = os.isfile(os.projectfile()) and project.option(packagename) or nil if packageopt == nil or packageopt:enabled() then -- this package is enabled? -- load package package diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index c9834b4bd..b2c879b53 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -26,6 +26,7 @@ import("core.base.semver") import("core.base.option") import("core.base.task") +import("net.http") import("devel.git") import("net.fasturl") import("core.base.privilege") @@ -103,6 +104,15 @@ end -- do uninstall function _uninstall() if is_host("windows") then + local uninstaller = path.join(os.programdir(), "uninstall.exe") + if os.isfile(uninstaller) then + local proc = process.open(uninstaller) + if proc ~= nil then + process.close(proc) + end + else + raise("the uninstaller(%s) not found!", uninstaller) + end else if os.programdir():startswith("/usr/") then _sudo("rm -rf " .. os.programdir()) @@ -121,7 +131,7 @@ function _uninstall() end -- do install -function _install(sourcedir) +function _install(sourcedir, version) -- the install task local install_task = function () @@ -135,9 +145,15 @@ function _install(sourcedir) -- 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()) + local installer = "xmake-" .. version .. ".exe" + if os.isfile(installer) then + local proc = process.open(installer) + if proc ~= nil then + process.close(proc) + end + else + raise("the installer(%s) not found!", installer) + end else if os.programdir():startswith("/usr/") then os.vrun("make build") @@ -159,6 +175,7 @@ function _install(sourcedir) -- trace if ok then cprint("\r${yellow} => ${clear}install to %s .. ${green}ok", os.programdir()) + os.exec("xmake --version") else raise("install failed!") end @@ -170,19 +187,11 @@ function _install(sourcedir) else process.asyncrun(install_task) end - - -- show new version - os.exec("xmake --version") end -- main function main() - -- TODO not support on windows now! - if is_host("windows") then - raise("not support on windows!") - end - -- only uninstall it if option.get("uninstall") then @@ -215,6 +224,19 @@ function main() version = "master" end + -- has been installed? + if os.xmakever():eq(version) then + cprint("${bright}xmake %s has been installed!", version) + return + end + + -- cannot support to update dev/master on windows + if is_host("windows") and not version:find('.', 1, true) then + raise("not support to update %s on windows!", version) + else + mainurls = {format("https://github.com/tboox/xmake/releases/download/%s/xmake-%s.exe", version, version)} + end + -- trace print("update version: %s ..", version) @@ -227,11 +249,16 @@ function main() { function () os.tryrm(sourcedir) - if version:find('.', 1, true) then - git.clone(url, {outputdir = sourcedir}) - git.checkout(version, {repodir = sourcedir}) + if not git.checkurl(url) then + os.mkdir(sourcedir) + http.download(url, path.join(sourcedir, path.filename(url))) else - git.clone(url, {depth = 1, branch = version, outputdir = 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 end return true end, @@ -243,10 +270,10 @@ function main() } } if ok then - cprint("\r${yellow} => ${clear}clone %s .. ${green}ok", url) + cprint("\r${yellow} => ${clear}download %s .. ${green}ok", url) break else - cprint("\r${yellow} => ${clear}clone %s .. ${red}failed", url) + cprint("\r${yellow} => ${clear}download %s .. ${red}failed", url) end if not ok and idx == #mainurls then raise("download failed!") @@ -265,6 +292,6 @@ function main() environment.leave() -- do install - _install(sourcedir) + _install(sourcedir, version) end diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index 87886f0b6..e17cf9ac2 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -27,6 +27,7 @@ local io = require("base/io") local os = require("base/os") local utils = require("base/utils") local option = require("base/option") +local semver = require("base/semver") local sandbox = require("sandbox/sandbox") local vformat = require("sandbox/modules/vformat") @@ -434,6 +435,24 @@ function sandbox_os.readlink(symlink) return result end +-- get xmake version +function sandbox_os.xmakever() + + -- get it from cache first + if sandbox_os._XMAKEVER ~= nil then + return sandbox_os._XMAKEVER + end + + -- get xmakever + local xmakever = semver.new(xmake._VERSION_SHORT) + + -- save to cache + os._XMAKEVER = xmakever or false + + -- done + return xmakever +end + -- return module return sandbox_os |
