From d023f3501a95bcd2c7475b578bed7585d8ed60d3 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 11 Oct 2024 00:55:26 +0800 Subject: [PATCH] rename to strhash --- xmake/core/base/hash.lua | 8 ++++---- xmake/core/sandbox/modules/hash.lua | 8 ++++---- xmake/includes/xrepo/xmake.lua | 4 ++-- xmake/modules/private/action/require/impl/repository.lua | 2 +- .../private/action/require/impl/utils/requirekey.lua | 2 +- xmake/plugins/pack/nsis/main.lua | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/xmake/core/base/hash.lua b/xmake/core/base/hash.lua index be831c2052..44502ad191 100644 --- a/xmake/core/base/hash.lua +++ b/xmake/core/base/hash.lua @@ -101,13 +101,13 @@ function hash.uuid(str) return hash.uuid4(str) end --- generate hash32, e.g. "91e8ecf1" -function hash.hash32(str) +-- generate hash32 from string, e.g. "91e8ecf1" +function hash.strhash32(str) return hash.uuid4(str):split("-", {plain = true})[1]:lower() end --- generate hash128, e.g. "91e8ecf1417f4edfa574e22d7d8d204a" -function hash.hash128(str) +-- generate hash128 from string, e.g. "91e8ecf1417f4edfa574e22d7d8d204a" +function hash.strhash128(str) return hash.uuid4(str):replace("-", "", {plain = true}):lower() end diff --git a/xmake/core/sandbox/modules/hash.lua b/xmake/core/sandbox/modules/hash.lua index 45fc5fb43d..50e2100cc1 100644 --- a/xmake/core/sandbox/modules/hash.lua +++ b/xmake/core/sandbox/modules/hash.lua @@ -89,8 +89,8 @@ function sandbox_hash.xxhash128(file_or_data) end -- generate hash32 from string -function sandbox_hash.hash32(str) - local hash32, errors = hash.hash32(str) +function sandbox_hash.strhash32(str) + local hash32, errors = hash.strhash32(str) if not hash32 then raise("cannot generate hash32 for %s, %s", str, errors or "unknown errors") end @@ -98,8 +98,8 @@ function sandbox_hash.hash32(str) end -- generate hash128 from string -function sandbox_hash.hash128(str) - local hash128, errors = hash.hash128(str) +function sandbox_hash.strhash128(str) + local hash128, errors = hash.strhash128(str) if not hash128 then raise("cannot generate hash128 for %s, %s", str, errors or "unknown errors") end diff --git a/xmake/includes/xrepo/xmake.lua b/xmake/includes/xrepo/xmake.lua index 9b3e0abaa3..2810dc5a80 100644 --- a/xmake/includes/xrepo/xmake.lua +++ b/xmake/includes/xrepo/xmake.lua @@ -32,7 +32,7 @@ -- @endcode -- function xrepo_addenvs(envs) - local packagename = "__xrepo_addenvs_" .. hash.hash32(tostring(envs)) + local packagename = "__xrepo_addenvs_" .. hash.strhash32(tostring(envs)) package(packagename) on_load(function (package) if type(envs) == "function" then @@ -61,7 +61,7 @@ end -- function xrepo_addenv(name, ...) local args = table.pack(...) - local packagename = "__xrepo_addenv_" .. name .. hash.hash32(table.concat(args)) + local packagename = "__xrepo_addenv_" .. name .. hash.strhash32(table.concat(args)) package(packagename) on_load(function (package) package:addenv(name, table.unpack(args)) diff --git a/xmake/modules/private/action/require/impl/repository.lua b/xmake/modules/private/action/require/impl/repository.lua index 001d2ec0a1..74b97efda9 100644 --- a/xmake/modules/private/action/require/impl/repository.lua +++ b/xmake/modules/private/action/require/impl/repository.lua @@ -38,7 +38,7 @@ function _get_packagedir_from_locked_repo(packagename, locked_repo) break end end - local reponame = hash.hash128(locked_repo.url .. (locked_repo.commit or "")) .. ".lock" + local reponame = hash.strhash128(locked_repo.url .. (locked_repo.commit or "")) .. ".lock" -- get local repodir local repodir_local diff --git a/xmake/modules/private/action/require/impl/utils/requirekey.lua b/xmake/modules/private/action/require/impl/utils/requirekey.lua index a8f435cdf2..13d31cd3a0 100644 --- a/xmake/modules/private/action/require/impl/utils/requirekey.lua +++ b/xmake/modules/private/action/require/impl/utils/requirekey.lua @@ -78,7 +78,7 @@ function main(requireinfo, opt) if key == "" then key = "_" -- we need to generate a fixed hash value end - return hash.hash32(key) + return hash.strhash32(key) else return key end diff --git a/xmake/plugins/pack/nsis/main.lua b/xmake/plugins/pack/nsis/main.lua index 1b49da3b5e..64c0020426 100644 --- a/xmake/plugins/pack/nsis/main.lua +++ b/xmake/plugins/pack/nsis/main.lua @@ -83,7 +83,7 @@ end -- get unique tag function _get_unique_tag(content) - return hash.hash32(content) + return hash.strhash32(content) end -- translate the file path