summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-04-14 21:23:04 +0800
committerruki <[email protected]>2019-04-14 21:23:04 +0800
commitd489e5be3ccba6298964bb73893486bea4feb0d6 (patch)
tree9f03fdbfe385f2b98cebda70255fc6b0d4559b1f
parent9e6f1bb93987f6eb8e4b0c73e4bb4b3bf6004a18 (diff)
improve semver
-rw-r--r--core/src/xmake/machine.c2
-rw-r--r--xmake/actions/build/statistics.lua3
-rw-r--r--xmake/core/base/semver.lua24
-rw-r--r--xmake/core/base/xmake.lua2
4 files changed, 26 insertions, 5 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
index 02334ba9b..9c9cccec9 100644
--- a/core/src/xmake/machine.c
+++ b/core/src/xmake/machine.c
@@ -579,7 +579,7 @@ xm_machine_ref_t xm_machine_init()
// init version string
tb_char_t version_cstr[256] = {0};
- tb_snprintf(version_cstr, sizeof(version_cstr), "%u.%u.%u.%llu", version->major, version->minor, version->alter, version->build);
+ tb_snprintf(version_cstr, sizeof(version_cstr), "%u.%u.%u+%llu", version->major, version->minor, version->alter, version->build);
lua_pushstring(machine->lua, version_cstr);
lua_setglobal(machine->lua, "_VERSION");
diff --git a/xmake/actions/build/statistics.lua b/xmake/actions/build/statistics.lua
index 804092763..a3a2a2268 100644
--- a/xmake/actions/build/statistics.lua
+++ b/xmake/actions/build/statistics.lua
@@ -123,8 +123,7 @@ function main()
local releasefile = outputdir .. ".release"
if not os.isfile(releasefile) then
import("net.http.download")
- local xmakever = xmake.version()
- download(format("https://github.com/xmake-io/xmake-stats/releases/download/v%d.%d.%d/%s", xmakever:major(), xmakever:minor(), xmakever:patch(), os.host()), releasefile)
+ download(format("https://github.com/xmake-io/xmake-stats/releases/download/v%s/%s", xmake:version():shortstr(), os.host()), releasefile)
print("post to releases ok!")
end
diff --git a/xmake/core/base/semver.lua b/xmake/core/base/semver.lua
index e50c70a6c..c6e1a563c 100644
--- a/xmake/core/base/semver.lua
+++ b/xmake/core/base/semver.lua
@@ -36,7 +36,7 @@ function _instance:get(name)
end
end
--- get the major version
+-- get the major version, e.g. v{major}.{minor}.{patch}
function _instance:major()
return self:get("major")
end
@@ -51,11 +51,33 @@ function _instance:patch()
return self:get("patch")
end
+-- get the build version, e.g. v1.0.1+{build}
+function _instance:build()
+ return self:get("build")
+end
+
+-- get the prerelease version, e.g. v1.0.1-{prerelease}
+function _instance:prerelease()
+ return self:get("prerelease")
+end
+
-- get the raw version string
function _instance:rawstr()
return self:get("raw")
end
+-- get the short version string
+function _instance:shortstr()
+ local str = self:major()
+ if self:minor() then
+ str = str .. "." .. self:minor()
+ end
+ if self:patch() then
+ str = str .. "." .. self:patch()
+ end
+ return str
+end
+
-- satisfies the given semantic version(.e.g '> 1.0 < 2.0', '~1.5')?
function _instance:satisfies(version)
return semver.satisfies(self:rawstr(), version)
diff --git a/xmake/core/base/xmake.lua b/xmake/core/base/xmake.lua
index 196097783..d0c2ca124 100644
--- a/xmake/core/base/xmake.lua
+++ b/xmake/core/base/xmake.lua
@@ -27,7 +27,7 @@ local semver = require("base/semver")
-- get xmake version
function xmake.version()
if xmake._VERSION_CACHE == nil then
- xmake._VERSION_CACHE = semver.new(_VERSION_SHORT) or false
+ xmake._VERSION_CACHE = semver.new(xmake._VERSION) or false
end
return xmake._VERSION_CACHE or nil
end