diff options
| author | ruki <[email protected]> | 2019-05-08 23:27:40 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-05-08 14:46:04 +0800 |
| commit | 9841c79a19730ff807367b9d93c4fbaa34d920ad (patch) | |
| tree | e55aa8a10bc30c7428fbd9be05f179f2c7334765 | |
| parent | 1c147263e7f75806e3011bd370df8230a8e075c6 (diff) | |
improve package version
| -rw-r--r-- | xmake/actions/require/impl/action/download.lua | 10 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 48 |
2 files changed, 35 insertions, 23 deletions
diff --git a/xmake/actions/require/impl/action/download.lua b/xmake/actions/require/impl/action/download.lua index b445156ee..1c5d519e5 100644 --- a/xmake/actions/require/impl/action/download.lua +++ b/xmake/actions/require/impl/action/download.lua @@ -60,19 +60,19 @@ function _checkout(package, url, sourcedir, url_alias) -- download package from branches? packagedir = path.join(sourcedir .. ".tmp", package:name()) - if package:version_from("branches") then + if package:branch() then -- only shadow clone this branch - git.clone(url, {depth = 1, branch = package:version_str(), outputdir = packagedir}) + git.clone(url, {depth = 1, branch = package:branch(), outputdir = packagedir}) - -- download package from revision, tag or version? + -- download package from revision or tag? else -- clone whole history and tags git.clone(url, {outputdir = packagedir}) -- attempt to checkout the given version - git.checkout(package:revision(url_alias) or package:version_str(), {repodir = packagedir}) + git.checkout(package:revision(url_alias) or package:tag(), {repodir = packagedir}) end -- move to source directory @@ -149,7 +149,7 @@ function _urls(package) table.insert(urls[2], url) end end - if package:version_from("tags", "branches") then + if package:gitref() then return table.join(urls[1], urls[2]) else return table.join(urls[2], urls[1]) 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 |
