diff options
| author | ruki <[email protected]> | 2017-12-03 20:39:29 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-12-03 20:39:29 +0800 |
| commit | 06ff3989aaf30f63c7e0cd0a8e9b2d6133799b43 (patch) | |
| tree | 5b874e4cf80ef4cf4ee65ea8983320f9fd66a7a0 | |
| parent | da1d0ed5b5a78039c787ce89243f1c4d88c24334 (diff) | |
modify package version and sha256s api
| -rw-r--r-- | xmake/actions/require/action/download.lua | 7 | ||||
| -rw-r--r-- | xmake/actions/require/package.lua | 2 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 38 |
3 files changed, 35 insertions, 12 deletions
diff --git a/xmake/actions/require/action/download.lua b/xmake/actions/require/action/download.lua index da09c26a1..d92d03d85 100644 --- a/xmake/actions/require/action/download.lua +++ b/xmake/actions/require/action/download.lua @@ -90,9 +90,12 @@ function _download(package, url, sourcedir, url_alias) -- get package file local packagefile = path.filename(url) - -- the package file have been downloaded? + -- get sha256 local sha256 = package:sha256(url_alias) - if option.get("force") or not os.isfile(packagefile) or (sha256 and sha256 ~= hash.sha256(packagefile)) then + assert(sha256, "cannot get sha256 of %s in package(%s)", url, package:fullname()) + + -- the package file have been downloaded? + if option.get("force") or not os.isfile(packagefile) or sha256 ~= hash.sha256(packagefile) then -- attempt to remove package file first os.rm(packagefile) diff --git a/xmake/actions/require/package.lua b/xmake/actions/require/package.lua index b239f5e85..71b40c903 100644 --- a/xmake/actions/require/package.lua +++ b/xmake/actions/require/package.lua @@ -389,7 +389,7 @@ function _select_packages_version(packages) end -- select package version - local version, source = semver.select(package:requireinfo().version, package:get("versions"), refs.tags, refs.branches) + local version, source = semver.select(package:requireinfo().version, package:versions(), refs.tags, refs.branches) -- save version to package package:version_set(version, source) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 2ec11e527..6b5a7cf6e 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -133,16 +133,16 @@ end function _instance:sha256(url_alias) -- get sha256 - local sha256s = self:get("sha256s") + local versions = self:get("versions") local version_str = self:version_str() - if sha256s and version_str then + if versions and version_str then local sha256 = nil if url_alias then - sha256 = sha256s[url_alias .. "@" ..version_str] + sha256 = versions[url_alias .. ":" ..version_str] end if not sha256 then - sha256 = sha256s[version_str] + sha256 = versions[version_str] end -- ok? @@ -189,6 +189,30 @@ function _instance:installdir() return path.join(package.installdir(self:from("global")), self:fullname(), self:version_str()) end +-- get versions +function _instance:versions() + + -- make versions + if self._VERSIONS == nil then + + -- get versions + local versions = {} + for version, _ in pairs(table.wrap(self:get("versions"))) do + + -- remove the url alias prefix if exists + local pos = version:find(':', 1, true) + if pos then + version = version:sub(pos + 1, -1) + end + table.insert(versions, version) + end + + -- remove repeat + self._VERSIONS = table.unique(versions) + end + return self._VERSIONS +end + -- get the version function _instance:version() return self._VERSION or {} @@ -381,14 +405,12 @@ function package.apis() -- package.set_xxx "package.set_urls" , "package.set_kind" - , "package.set_versions" , "package.set_homepage" , "package.set_description" -- package.add_xxx , "package.add_deps" , "package.add_urls" , "package.add_imports" - , "package.add_versions" } , script = { @@ -409,10 +431,8 @@ function package.apis() } , dictionary = { - -- package.set_xxx - "package.set_sha256s" -- package.add_xxx - , "package.add_sha256s" + "package.add_versions" } } end |
