summaryrefslogtreecommitdiff
path: root/xmake/core/base/hash.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-20 23:05:19 +0800
committerGitHub <[email protected]>2022-05-20 23:05:19 +0800
commit6cf488d207c3009aba6319759a2cc2fb6aa7a405 (patch)
treec61583cf363192611d4f0be291b9e1fbe8afd2ab /xmake/core/base/hash.lua
parentc6218b9b4cd17babf15fa46dbc65e895ace3e7d7 (diff)
parentd63ce0e016b58d03519f957d7ac9f36494c73486 (diff)
Merge pull request #2361 from xmake-io/buildcache
Add build cache instead of ccache
Diffstat (limited to 'xmake/core/base/hash.lua')
-rw-r--r--xmake/core/base/hash.lua48
1 files changed, 44 insertions, 4 deletions
diff --git a/xmake/core/base/hash.lua b/xmake/core/base/hash.lua
index 88bdbe673..74bbfd4cd 100644
--- a/xmake/core/base/hash.lua
+++ b/xmake/core/base/hash.lua
@@ -27,8 +27,9 @@ local utils = require("base/utils")
local bytes = require("base/bytes")
-- save metatable and builtin functions
-hash._md5 = hash._md5 or hash.md5
-hash._sha256 = hash._sha256 or hash.sha256
+hash._md5 = hash._md5 or hash.md5
+hash._sha = hash._sha or hash.sha
+hash._xxhash = hash._xxhash or hash.xxhash
-- make md5 from the given file or data
function hash.md5(file_or_data)
@@ -43,15 +44,54 @@ function hash.md5(file_or_data)
return hashstr, errors
end
+-- make sha1 from the given file or data
+function hash.sha1(file_or_data)
+ local hashstr, errors
+ if bytes.instance_of(file_or_data) then
+ local datasize = file_or_data:size()
+ local dataaddr = file_or_data:caddr()
+ hashstr, errors = hash._sha(160, dataaddr, datasize)
+ else
+ hashstr, errors = hash._sha(160, file_or_data)
+ end
+ return hashstr, errors
+end
+
-- make sha256 from the given file or data
function hash.sha256(file_or_data)
local hashstr, errors
if bytes.instance_of(file_or_data) then
local datasize = file_or_data:size()
local dataaddr = file_or_data:caddr()
- hashstr, errors = hash._sha256(dataaddr, datasize)
+ hashstr, errors = hash._sha(256, dataaddr, datasize)
+ else
+ hashstr, errors = hash._sha(256, file_or_data)
+ end
+ return hashstr, errors
+end
+
+-- make xxhash64 from the given file or data
+function hash.xxhash64(file_or_data)
+ local hashstr, errors
+ if bytes.instance_of(file_or_data) then
+ local datasize = file_or_data:size()
+ local dataaddr = file_or_data:caddr()
+ hashstr, errors = hash._xxhash(64, dataaddr, datasize)
+ else
+ hashstr, errors = hash._xxhash(64, file_or_data)
+ end
+ return hashstr, errors
+end
+
+-- make xxhash128 from the given file or data
+function hash.xxhash128(file_or_data)
+ local hashstr, errors
+ if bytes.instance_of(file_or_data) then
+ local datasize = file_or_data:size()
+ local dataaddr = file_or_data:caddr()
+ hashstr, errors = hash._xxhash(128, dataaddr, datasize)
else
- hashstr, errors = hash._sha256(file_or_data)
+ hashstr, errors = hash._xxhash(128, file_or_data)
end
return hashstr, errors
end