summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-09-28 23:14:48 +0800
committerruki <[email protected]>2019-09-28 23:14:48 +0800
commit4df867463bac4c5987441696eabbf6a1f43ea9e4 (patch)
treef9fe0a04d8bbd96b846e2f86510795ddd8f0ae10
parent63eb20ffd810c38ebd5f725d492d81c4e9a6e32d (diff)
add new version tips
-rw-r--r--xmake/actions/build/statistics.lua10
-rw-r--r--xmake/actions/update/main.lua9
-rw-r--r--xmake/core/base/option.lua23
-rw-r--r--xmake/modules/private/action/update/fetch_version.lua (renamed from xmake/actions/update/get_version.lua)10
4 files changed, 45 insertions, 7 deletions
diff --git a/xmake/actions/build/statistics.lua b/xmake/actions/build/statistics.lua
index 5d7d518cc..e070f0805 100644
--- a/xmake/actions/build/statistics.lua
+++ b/xmake/actions/build/statistics.lua
@@ -23,6 +23,7 @@ import("core.base.option")
import("core.project.config")
import("core.platform.platform")
import("core.platform.environment")
+import("private.action.update.fetch_version")
-- statistics is enabled?
function _is_enabled()
@@ -119,6 +120,15 @@ function main()
print("post to traffic ok!")
end
+ -- fetch the lastest version
+ local versionfile = path.join(os.tmpdir(), "lastest_version")
+ if not os.isfile(versionfile) then
+ local fetchinfo = fetch_version()
+ if fetchinfo then
+ io.save(versionfile, fetchinfo)
+ end
+ end
+
-- download the xmake-stats releases to update the release stats info in github
local releasefile = outputdir .. ".release"
if not os.isfile(releasefile) then
diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua
index 8a476b180..7ed54c338 100644
--- a/xmake/actions/update/main.lua
+++ b/xmake/actions/update/main.lua
@@ -29,7 +29,7 @@ import("net.fasturl")
import("core.base.privilege")
import("privilege.sudo")
import("actions.require.impl.environment", {rootdir = os.programdir()})
-import("get_version")
+import("private.action.update.fetch_version")
-- the installer filename for windows
local win_installer_name = "xmake-installer.exe"
@@ -266,7 +266,10 @@ function main()
environment.enter()
-- has been installed?
- local is_official, mainurls, version, tags, branches = get_version(option.get("xmakever"))
+ local fetchinfo = assert(fetch_version(option.get("xmakever")), "cannot fetch xmake version info!")
+ local is_official = fetchinfo.is_official
+ local mainurls = fetchinfo.urls
+ local version = fetchinfo.version
if is_official and xmake.version():eq(version) then
cprint("${bright}xmake %s has been installed!", version)
return
@@ -312,7 +315,7 @@ function main()
{
function ()
os.tryrm(sourcedir)
- -- all user provided urls are considered as git url since check has been performed in get_version
+ -- all user provided urls are considered as git url since check has been performed in fetch_version
if is_official and not git.checkurl(url) then
os.mkdir(sourcedir)
http.download(url, path.join(sourcedir, win_installer_name))
diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua
index bf6a9df68..c3850ccd8 100644
--- a/xmake/core/base/option.lua
+++ b/xmake/core/base/option.lua
@@ -800,6 +800,26 @@ function option.defaults(task)
return defaults
end
+-- show update tips
+function option.show_update_tips()
+
+ -- show lastest version
+ local versionfile = path.join(os.tmpdir(), "lastest_version")
+ if os.isfile(versionfile) then
+ local versioninfo = io.load(versionfile)
+ if versioninfo and versioninfo.version and semver.compare(versioninfo.version, xmake._VERSION_SHORT) > 0 then
+ local updatetips = string.format([[
+ ╔════════════════════════════════════════════════════════════════════════════╗
+ ║ ${bright yellow}A new version of xmake is available!${clear} ║
+ ║ ║
+ ║ To update to the latest version ${bright}%s${clear}, run "xmake update". ║
+ ╚════════════════════════════════════════════════════════════════════════════╝
+]], versioninfo.version)
+ io.print(colors.translate(updatetips))
+ end
+ end
+end
+
-- show logo
function option.show_logo()
@@ -842,6 +862,9 @@ function option.show_logo()
-- show footer
io.print(colors.translate(footer))
+
+ -- show update tips
+ option.show_update_tips()
end
-- show the menu
diff --git a/xmake/actions/update/get_version.lua b/xmake/modules/private/action/update/fetch_version.lua
index 03450b1ad..4ddf304c7 100644
--- a/xmake/actions/update/get_version.lua
+++ b/xmake/modules/private/action/update/fetch_version.lua
@@ -14,8 +14,8 @@
--
-- Copyright (C) 2015 - 2019, TBOOX Open Source Group.
--
--- @author OpportunityLiu
--- @file get_version.lua
+-- @author OpportunityLiu, ruki
+-- @file fetch_version.lua
--
-- imports
@@ -36,8 +36,11 @@ local official_sources =
-- get version and url of provided xmakever
function main(xmakever)
+
+ -- init xmakever
xmakever = xmakever or "lastest"
+ -- parse url and commit
local commitish = nil
local custom_url = nil
local seg = xmakever:split('#', { plain = true, limit = 2, strict = true })
@@ -79,7 +82,6 @@ function main(xmakever)
break
end
end
-
- return (urls == official_sources), urls, (version or "master"), tags, branches
+ return {is_official = (urls == official_sources), urls = urls, version = (version or "master"), tags = tags, branches = branches}
end