summaryrefslogtreecommitdiff
path: root/xmake/core/package
diff options
context:
space:
mode:
authorruki <[email protected]>2019-05-08 23:27:40 +0800
committerruki <[email protected]>2019-05-08 14:46:04 +0800
commit9841c79a19730ff807367b9d93c4fbaa34d920ad (patch)
treee55aa8a10bc30c7428fbd9be05f179f2c7334765 /xmake/core/package
parent1c147263e7f75806e3011bd370df8230a8e075c6 (diff)
improve package version
Diffstat (limited to 'xmake/core/package')
-rw-r--r--xmake/core/package/package.lua48
1 files changed, 30 insertions, 18 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 6e160ac93..eed3081a0 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -29,6 +29,7 @@ local path = require("base/path")
local utils = require("base/utils")
local table = require("base/table")
local global = require("base/global")
+local semver = require("base/semver")
local scopeinfo = require("base/scopeinfo")
local interpreter = require("base/interpreter")
local sandbox = require("sandbox/sandbox")
@@ -515,37 +516,48 @@ end
-- get the version
function _instance:version()
- return self._VERSION or {}
+ return self._VERSION
end
-- get the version string
function _instance:version_str()
- return self:version().raw or self:version().version
+ return self._VERSION_STR
end
--- the verson from tags, branches or versions?
-function _instance:version_from(...)
+-- get branch version
+function _instance:branch()
+ return self._BRANCH
+end
- -- from source?
- for _, source in ipairs({...}) do
- if self:version().source == source then
- return true
- end
- end
+-- get tag version
+function _instance:tag()
+ return self._TAG
end
--- set the version
+-- is git ref?
+function _instance:gitref()
+ return self:branch() or self:tag()
+end
+
+-- set the version, source: branches, tags, versions
function _instance:version_set(version, source)
- -- init package version
- if type(version) == "string" then
- version = {version = version, source = source}
- else
- version.source = source
+ -- save the semver version
+ local sv = semver.new(version)
+ if sv then
+ self._VERSION = sv
+ end
+
+ -- save branch and tag
+ if source == "branches" then
+ self._BRANCH = version
+ elseif source == "tags" then
+ self._TAG = version
end
- -- save version
- self._VERSION = version
+ -- save source and version string
+ self._SOURCE = source
+ self._VERSION_STR = version
end
-- get the require info