summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-02-03 22:23:55 +0800
committerruki <[email protected]>2021-02-03 22:23:55 +0800
commit70bc1847d47935ea48b68afc64ce13a337911409 (patch)
tree6c9a7713c28daddcd89ca57d02b070996fcb12c9
parent6933bd53b195c8e95fb18b1af40f623ab76dee54 (diff)
improve buildhash for package
-rw-r--r--xmake/actions/require/impl/actions/download.lua3
-rw-r--r--xmake/core/package/package.lua37
2 files changed, 33 insertions, 7 deletions
diff --git a/xmake/actions/require/impl/actions/download.lua b/xmake/actions/require/impl/actions/download.lua
index f9b332cbc..8c645eb80 100644
--- a/xmake/actions/require/impl/actions/download.lua
+++ b/xmake/actions/require/impl/actions/download.lua
@@ -97,9 +97,6 @@ function _download(package, url, sourcedir, url_alias, url_excludes)
-- https://github.com/xmake-io/xmake/issues/1009
--
local sourcehash = package:sourcehash(url_alias)
- if sourcehash then
- sourcehash = sourcehash:lower()
- end
assert(not package:verify() or not package:get("versions") or sourcehash, "cannot get source hash of %s in package(%s)", url, package:name())
-- the package file have been downloaded?
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 15eb0b144..242892271 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -31,6 +31,7 @@ local table = require("base/table")
local global = require("base/global")
local semver = require("base/semver")
local option = require("base/option")
+local hashset = require("base/hashset")
local scopeinfo = require("base/scopeinfo")
local interpreter = require("base/interpreter")
local memcache = require("cache/memcache")
@@ -239,8 +240,6 @@ end
-- get hash of the source package for the url_alias@version_str
function _instance:sourcehash(url_alias)
-
- -- get sourcehash
local versions = self:get("versions")
local version_str = self:version_str()
if versions and version_str then
@@ -252,6 +251,9 @@ function _instance:sourcehash(url_alias)
if not sourcehash then
sourcehash = versions[version_str]
end
+ if sourcehash then
+ sourcehash = sourcehash:lower()
+ end
return sourcehash
end
end
@@ -737,7 +739,8 @@ end
function _instance:buildhash()
local buildhash = self._BUILDHASH
if buildhash == nil then
- local function _get_buildhash(configs)
+ local function _get_buildhash(configs, opt)
+ opt = opt or {}
local str = self:plat() .. self:arch()
if configs then
-- since luajit v2.1, the key order of the table is random and undefined.
@@ -753,6 +756,21 @@ function _instance:buildhash()
configs_str = configs_str:gsub("\"", "")
str = str .. configs_str
end
+ if opt.sourcehash ~= false then
+ local sourcehashs = hashset.new()
+ for _, url in ipairs(self:urls()) do
+ local url_alias = self:url_alias(url)
+ local sourcehash = self:sourcehash(url_alias)
+ if sourcehash then
+ sourcehashs:insert(sourcehash)
+ end
+ end
+ if not sourcehashs:empty() then
+ for _, sourcehash in sourcehashs:keys() do
+ str = str .. "_" .. sourcehash
+ end
+ end
+ end
return hash.uuid4(str):gsub('-', ''):lower()
end
local function _get_installdir(...)
@@ -769,11 +787,22 @@ function _instance:buildhash()
if self:config("pic") then
local configs = table.copy(self:configs())
configs.pic = nil
- buildhash = _get_buildhash(configs)
+ buildhash = _get_buildhash(configs, {sourcehash = false})
if not os.isdir(_get_installdir(buildhash)) then
buildhash = nil
end
end
+
+ -- we need to be compatible with the hash value string for the previous xmake version
+ -- without sourcehash (< 2.5.2)
+ if not buildhash then
+ buildhash = _get_buildhash(self:configs(), {sourcehash = false})
+ if not os.isdir(_get_installdir(buildhash)) then
+ buildhash = nil
+ end
+ end
+
+ -- get build hash for current version
if not buildhash then
buildhash = _get_buildhash(self:configs())
end