From 4df867463bac4c5987441696eabbf6a1f43ea9e4 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 28 Sep 2019 23:14:48 +0800 Subject: add new version tips --- xmake/actions/build/statistics.lua | 10 +++ xmake/actions/update/get_version.lua | 85 --------------------- xmake/actions/update/main.lua | 9 ++- xmake/core/base/option.lua | 23 ++++++ .../private/action/update/fetch_version.lua | 87 ++++++++++++++++++++++ 5 files changed, 126 insertions(+), 88 deletions(-) delete mode 100644 xmake/actions/update/get_version.lua create mode 100644 xmake/modules/private/action/update/fetch_version.lua 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/get_version.lua b/xmake/actions/update/get_version.lua deleted file mode 100644 index 03450b1ad..000000000 --- a/xmake/actions/update/get_version.lua +++ /dev/null @@ -1,85 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015 - 2019, TBOOX Open Source Group. --- --- @author OpportunityLiu --- @file get_version.lua --- - --- imports -import("core.base.semver") -import("core.base.option") -import("core.base.task") -import("net.http") -import("devel.git") -import("net.fasturl") - --- the official git sources for xmake -local official_sources = -{ - "https://github.com/xmake-io/xmake.git", - "https://gitlab.com/tboox/xmake.git", - "https://gitee.com/tboox/xmake.git" -} - --- get version and url of provided xmakever -function main(xmakever) - xmakever = xmakever or "lastest" - - local commitish = nil - local custom_url = nil - local seg = xmakever:split('#', { plain = true, limit = 2, strict = true }) - if #seg == 2 then - if #seg[1] ~= 0 then - custom_url = seg[1] - end - commitish = seg[2] - else - if xmakever:find(':', 1, true) then - custom_url = xmakever - else - commitish = xmakever - end - end - - local urls = nil - if custom_url then - urls = { git.asgiturl(custom_url) or custom_url } - vprint("using custom source: %s ..", urls[1] ) - else - urls = official_sources - end - commitish = (commitish and #commitish > 0) and commitish or "lastest" - - -- sort urls - if #urls > 1 then - fasturl.add(urls) - urls = fasturl.sort(urls) - end - - -- get version - local version = nil - local tags, branches - for _, url in ipairs(urls) do - tags, branches = git.refs(url) - if tags or branches then - version = semver.select(commitish, tags or {}, tags or {}, branches or {}) - break - end - end - - return (urls == official_sources), urls, (version or "master"), tags, branches -end - 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/modules/private/action/update/fetch_version.lua b/xmake/modules/private/action/update/fetch_version.lua new file mode 100644 index 000000000..4ddf304c7 --- /dev/null +++ b/xmake/modules/private/action/update/fetch_version.lua @@ -0,0 +1,87 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2019, TBOOX Open Source Group. +-- +-- @author OpportunityLiu, ruki +-- @file fetch_version.lua +-- + +-- imports +import("core.base.semver") +import("core.base.option") +import("core.base.task") +import("net.http") +import("devel.git") +import("net.fasturl") + +-- the official git sources for xmake +local official_sources = +{ + "https://github.com/xmake-io/xmake.git", + "https://gitlab.com/tboox/xmake.git", + "https://gitee.com/tboox/xmake.git" +} + +-- 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 }) + if #seg == 2 then + if #seg[1] ~= 0 then + custom_url = seg[1] + end + commitish = seg[2] + else + if xmakever:find(':', 1, true) then + custom_url = xmakever + else + commitish = xmakever + end + end + + local urls = nil + if custom_url then + urls = { git.asgiturl(custom_url) or custom_url } + vprint("using custom source: %s ..", urls[1] ) + else + urls = official_sources + end + commitish = (commitish and #commitish > 0) and commitish or "lastest" + + -- sort urls + if #urls > 1 then + fasturl.add(urls) + urls = fasturl.sort(urls) + end + + -- get version + local version = nil + local tags, branches + for _, url in ipairs(urls) do + tags, branches = git.refs(url) + if tags or branches then + version = semver.select(commitish, tags or {}, tags or {}, branches or {}) + break + end + end + return {is_official = (urls == official_sources), urls = urls, version = (version or "master"), tags = tags, branches = branches} +end + -- cgit v1.3.1