From dd717cd8219f0774ecb717f44d6ba3f182f29c99 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 15 Aug 2021 23:38:15 +0800 Subject: improve xmake-requires.lock --- .../action/require/impl/utils/requirekey.lua | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 xmake/modules/private/action/require/impl/utils/requirekey.lua (limited to 'xmake/modules/private/action/require/impl/utils/requirekey.lua') diff --git a/xmake/modules/private/action/require/impl/utils/requirekey.lua b/xmake/modules/private/action/require/impl/utils/requirekey.lua new file mode 100644 index 000000000..e39da12ba --- /dev/null +++ b/xmake/modules/private/action/require/impl/utils/requirekey.lua @@ -0,0 +1,50 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file requirekey.lua +-- + +-- get require key from requireinfo +function main(requireinfo, opt) + opt = opt or {} + local key = "" + if opt.name then + key = key .. "/" .. opt.name + end + if opt.plat then + key = key .. "/" .. opt.plat + end + if opt.arch then + key = key .. "/" .. opt.arch + end + if opt.version then + key = key .. "/" .. opt.version + end + if requireinfo.label then + key = key .. "/" .. requireinfo.label + end + local configs = requireinfo.configs + if configs then + local configs_order = {} + for k, v in pairs(configs) do + table.insert(configs_order, k .. "=" .. tostring(v)) + end + table.sort(configs_order) + key = key .. ":" .. string.serialize(configs_order, true) + end + return hash.uuid(key):gsub("%-", ""):lower() +end -- cgit v1.3.1 From 139d4b590a4ad763f0c9e43f59e8281383e4212b Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 18 Aug 2021 00:46:14 +0800 Subject: improve requirekey --- xmake/core/package/package.lua | 10 +++++----- xmake/modules/private/action/require/impl/lock_packages.lua | 5 ++++- xmake/modules/private/action/require/impl/package.lua | 8 ++++++-- xmake/modules/private/action/require/impl/utils/requirekey.lua | 9 ++++++++- 4 files changed, 23 insertions(+), 9 deletions(-) (limited to 'xmake/modules/private/action/require/impl/utils/requirekey.lua') diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index fefa4eb17..5724da656 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -115,10 +115,10 @@ function _instance:plat() return os.subhost() end local requireinfo = self:requireinfo() - if not plat and requireinfo and requireinfo.plat then + if requireinfo and requireinfo.plat then return requireinfo.plat end - return self:get("plat") or package._target_plat() + return package._target_plat() end -- get the architecture of package @@ -145,7 +145,7 @@ function _instance:targetarch() if requireinfo and requireinfo.arch then return requireinfo.arch end - return self:get("arch") or package._target_arch() + return package._target_arch() end -- get the build mode @@ -1703,8 +1703,8 @@ function package.apis() -- package.set_xxx "package.set_urls" , "package.set_kind" - , "package.set_plat" - , "package.set_arch" + , "package.set_plat" -- deprecated + , "package.set_arch" -- deprecated , "package.set_license" , "package.set_homepage" , "package.set_description" diff --git a/xmake/modules/private/action/require/impl/lock_packages.lua b/xmake/modules/private/action/require/impl/lock_packages.lua index e624f8d1a..7640e7562 100644 --- a/xmake/modules/private/action/require/impl/lock_packages.lua +++ b/xmake/modules/private/action/require/impl/lock_packages.lua @@ -20,15 +20,18 @@ -- imports import("core.project.project") +import("core.project.config") import("devel.git") import("private.action.require.impl.utils.filter") import("private.action.require.impl.utils.requirekey") -- get locked package key function _get_packagelock_key(instance) + local plat = config.plat() or os.subhost() + local arch = config.arch() or os.subarch() local requireinfo = instance:requireinfo() local requirestr = requireinfo.originstr - local key = requirekey(requireinfo, {plat = instance:plat(), arch = instance:arch()}) + local key = requirekey(requireinfo, {hash = true, plat = plat, arch = arch}) return string.format("%s#%s", requirestr, key) end diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 554033496..5dc0ff451 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -26,6 +26,7 @@ import("core.base.hashset") import("private.utils.progress") import("core.cache.memcache") import("core.project.project") +import("core.project.config") import("core.tool.toolchain") import("core.package.package", {alias = "core_package"}) import("devel.git") @@ -505,8 +506,10 @@ end -- get locked package key function _get_packagelock_key(requireinfo) + local plat = config.plat() or os.subhost() + local arch = config.arch() or os.subarch() local requirestr = requireinfo.originstr - local key = _get_requirekey(requireinfo, {plat = requireinfo.plat, arch = requireinfo.arch}) + local key = _get_requirekey(requireinfo, {hash = true, plat = plat, arch = arch}) return string.format("%s#%s", requirestr, key) end @@ -662,11 +665,12 @@ function _load_package(packagename, requireinfo, opt) -- finish requireinfo _finish_requireinfo(requireinfo, package) + --[[ -- get requirekey if _has_locked_requires() then local requirekey = _get_packagelock_key(requireinfo) print("requirekey", requirekey) - end + end]] -- select package version local version, source = _select_package_version(package, requireinfo) diff --git a/xmake/modules/private/action/require/impl/utils/requirekey.lua b/xmake/modules/private/action/require/impl/utils/requirekey.lua index e39da12ba..b07e4d50d 100644 --- a/xmake/modules/private/action/require/impl/utils/requirekey.lua +++ b/xmake/modules/private/action/require/impl/utils/requirekey.lua @@ -37,6 +37,9 @@ function main(requireinfo, opt) if requireinfo.label then key = key .. "/" .. requireinfo.label end + if key:startswith("/") then + key = key:sub(2) + end local configs = requireinfo.configs if configs then local configs_order = {} @@ -46,5 +49,9 @@ function main(requireinfo, opt) table.sort(configs_order) key = key .. ":" .. string.serialize(configs_order, true) end - return hash.uuid(key):gsub("%-", ""):lower() + if opt.hash then + return hash.uuid(key):gsub("%-", ""):lower() + else + return key + end end -- cgit v1.3.1 From 5e73fb8a86de1a6e10739d3c348d40607942c165 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 21 Aug 2021 16:38:06 +0800 Subject: improve requirekey --- .../package/toolchain_muslcc/xmake-requires.lock | 24 +++++++++++----------- .../private/action/require/impl/package.lua | 6 ++---- .../action/require/impl/utils/requirekey.lua | 3 +++ 3 files changed, 17 insertions(+), 16 deletions(-) (limited to 'xmake/modules/private/action/require/impl/utils/requirekey.lua') diff --git a/tests/projects/package/toolchain_muslcc/xmake-requires.lock b/tests/projects/package/toolchain_muslcc/xmake-requires.lock index 4379fdf79..4a07f4618 100644 --- a/tests/projects/package/toolchain_muslcc/xmake-requires.lock +++ b/tests/projects/package/toolchain_muslcc/xmake-requires.lock @@ -3,7 +3,7 @@ version = "1.0" }, ["macosx|x86_64"] = { - ["autoconf#ddbdd8b8f76d455a8c0ef45fffe37160"] = { + ["autoconf#31fecfc4f022419cba33d3f9fc3cc783"] = { buildhash = "cd4169a7cb484832b2f70d2174072ca2", repo = { branch = "master", @@ -12,7 +12,7 @@ }, version = "2.71" }, - ["automake#ddbdd8b8f76d455a8c0ef45fffe37160"] = { + ["automake#31fecfc4f022419cba33d3f9fc3cc783"] = { buildhash = "5b4ee7b727764ece8aa3e149603cfc7a", repo = { branch = "master", @@ -21,7 +21,7 @@ }, version = "1.16.4" }, - ["cmake#ddbdd8b8f76d455a8c0ef45fffe37160"] = { + ["cmake#31fecfc4f022419cba33d3f9fc3cc783"] = { buildhash = "a6d18f8c0bf347d980f8bb762583c91a", repo = { branch = "master", @@ -30,7 +30,7 @@ }, version = "3.21.0" }, - ["gmp#ddbdd8b8f76d455a8c0ef45fffe37160"] = { + ["gmp#31fecfc4f022419cba33d3f9fc3cc783"] = { buildhash = "7dd9c224447e46698ac73d29f58b1d73", repo = { branch = "master", @@ -39,7 +39,7 @@ }, version = "6.2.1" }, - ["libisl 0.22#3dd996fa365042e39791030c4e1cad52"] = { + ["libisl 0.22#671145042a9f4a96a5387ebff97a207d"] = { buildhash = "f649e1fb365e442e8f79f372fd91483b", repo = { branch = "master", @@ -48,7 +48,7 @@ }, version = "0.22" }, - ["libogg#ddbdd8b8f76d455a8c0ef45fffe37160"] = { + ["libogg#31fecfc4f022419cba33d3f9fc3cc783"] = { buildhash = "d894fc29f2fb4c45a0f48bc2c6ece273", repo = { branch = "master", @@ -57,7 +57,7 @@ }, version = "v1.3.4" }, - ["libplist#ddbdd8b8f76d455a8c0ef45fffe37160"] = { + ["libplist#31fecfc4f022419cba33d3f9fc3cc783"] = { buildhash = "0c01b22920be4876b1de74629194eb8f", repo = { branch = "master", @@ -66,7 +66,7 @@ }, version = "2.2.0" }, - ["libtool#ddbdd8b8f76d455a8c0ef45fffe37160"] = { + ["libtool#31fecfc4f022419cba33d3f9fc3cc783"] = { buildhash = "64584ec84a4743ecb740b598b263ffa6", repo = { branch = "master", @@ -75,7 +75,7 @@ }, version = "2.4.6" }, - ["m4#ddbdd8b8f76d455a8c0ef45fffe37160"] = { + ["m4#31fecfc4f022419cba33d3f9fc3cc783"] = { buildhash = "fd0e83e5759b442a970327ebb1c89793", repo = { branch = "master", @@ -84,7 +84,7 @@ }, version = "1.4.19" }, - ["muslcc#ddbdd8b8f76d455a8c0ef45fffe37160"] = { + ["muslcc#31fecfc4f022419cba33d3f9fc3cc783"] = { buildhash = "11062c09ebeb484594488ad73ddbcd1f", repo = { branch = "master", @@ -93,7 +93,7 @@ }, version = "20210202" }, - ["pkg-config#ddbdd8b8f76d455a8c0ef45fffe37160"] = { + ["pkg-config#31fecfc4f022419cba33d3f9fc3cc783"] = { buildhash = "84fd7f9b9f7a47709512cfc85cd9e5f7", repo = { branch = "master", @@ -102,7 +102,7 @@ }, version = "0.29.2" }, - ["zlib#ddbdd8b8f76d455a8c0ef45fffe37160"] = { + ["zlib#31fecfc4f022419cba33d3f9fc3cc783"] = { buildhash = "be90a245b8bb48e6b08a1a15bdcad467", repo = { branch = "master", diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index d5d893658..55085d4f1 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -530,10 +530,8 @@ end -- get locked package key function _get_packagelock_key(requireinfo) - local plat = config.plat() or os.subhost() - local arch = config.arch() or os.subarch() local requirestr = requireinfo.originstr - local key = _get_requirekey(requireinfo, {hash = true, plat = plat, arch = arch}) + local key = _get_requirekey(requireinfo, {hash = true}) return string.format("%s#%s", requirestr, key) end @@ -648,7 +646,7 @@ function _load_package(packagename, requireinfo, opt) requireinfo.label = splitinfo[2] end - -- sve requirekey + -- save requirekey local requirekey = _get_packagelock_key(requireinfo) requireinfo.requirekey = requirekey diff --git a/xmake/modules/private/action/require/impl/utils/requirekey.lua b/xmake/modules/private/action/require/impl/utils/requirekey.lua index b07e4d50d..230a53acb 100644 --- a/xmake/modules/private/action/require/impl/utils/requirekey.lua +++ b/xmake/modules/private/action/require/impl/utils/requirekey.lua @@ -50,6 +50,9 @@ function main(requireinfo, opt) key = key .. ":" .. string.serialize(configs_order, true) end if opt.hash then + if key == "" then + key = "_" + end return hash.uuid(key):gsub("%-", ""):lower() else return key -- cgit v1.3.1 From 38c33512003a92adfc8cba6f50409d9e78df3868 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 21 Aug 2021 16:41:45 +0800 Subject: improve requirekey --- .../package/multiconfig/xmake-requires.lock | 12 +++++------ .../package/toolchain_muslcc/xmake-requires.lock | 24 +++++++++++----------- .../action/require/impl/utils/requirekey.lua | 4 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) (limited to 'xmake/modules/private/action/require/impl/utils/requirekey.lua') diff --git a/tests/projects/package/multiconfig/xmake-requires.lock b/tests/projects/package/multiconfig/xmake-requires.lock index 6b10a5235..e162c68b2 100644 --- a/tests/projects/package/multiconfig/xmake-requires.lock +++ b/tests/projects/package/multiconfig/xmake-requires.lock @@ -3,29 +3,29 @@ version = "1.0" }, ["macosx|x86_64"] = { - ["zlib#ddbdd8b8f76d455a8c0ef45fffe37160"] = { + ["zlib#31fecfc4"] = { buildhash = "b76a297309d14c09b42cfe3927260a51", repo = { branch = "master", - commit = "d0e1f98585a4ec31b056fe3bda65a4fe37e0b375", + commit = "eda7adee81bac151f87c507030cc0dd8ab299462", url = "https://gitee.com/tboox/xmake-repo.git" }, version = "1.2.11" }, - ["zlib~debug#d72a8a937b694e449bce540c8eb65a8a"] = { + ["zlib~debug#55833b12"] = { buildhash = "e6a6fa6a86ad4fc7ae3c2cf7c60cc084", repo = { branch = "master", - commit = "d0e1f98585a4ec31b056fe3bda65a4fe37e0b375", + commit = "eda7adee81bac151f87c507030cc0dd8ab299462", url = "https://gitee.com/tboox/xmake-repo.git" }, version = "1.2.11" }, - ["zlib~shared#b286744a1898416faad2e5cab0104b2f"] = { + ["zlib~shared#b6ab42cb"] = { buildhash = "8e5b898b0f344715bac89cc6a1577506", repo = { branch = "master", - commit = "d0e1f98585a4ec31b056fe3bda65a4fe37e0b375", + commit = "eda7adee81bac151f87c507030cc0dd8ab299462", url = "https://gitee.com/tboox/xmake-repo.git" }, version = "1.2.11" diff --git a/tests/projects/package/toolchain_muslcc/xmake-requires.lock b/tests/projects/package/toolchain_muslcc/xmake-requires.lock index 4a07f4618..8c55e49ea 100644 --- a/tests/projects/package/toolchain_muslcc/xmake-requires.lock +++ b/tests/projects/package/toolchain_muslcc/xmake-requires.lock @@ -3,7 +3,7 @@ version = "1.0" }, ["macosx|x86_64"] = { - ["autoconf#31fecfc4f022419cba33d3f9fc3cc783"] = { + ["autoconf#31fecfc4"] = { buildhash = "cd4169a7cb484832b2f70d2174072ca2", repo = { branch = "master", @@ -12,7 +12,7 @@ }, version = "2.71" }, - ["automake#31fecfc4f022419cba33d3f9fc3cc783"] = { + ["automake#31fecfc4"] = { buildhash = "5b4ee7b727764ece8aa3e149603cfc7a", repo = { branch = "master", @@ -21,7 +21,7 @@ }, version = "1.16.4" }, - ["cmake#31fecfc4f022419cba33d3f9fc3cc783"] = { + ["cmake#31fecfc4"] = { buildhash = "a6d18f8c0bf347d980f8bb762583c91a", repo = { branch = "master", @@ -30,7 +30,7 @@ }, version = "3.21.0" }, - ["gmp#31fecfc4f022419cba33d3f9fc3cc783"] = { + ["gmp#31fecfc4"] = { buildhash = "7dd9c224447e46698ac73d29f58b1d73", repo = { branch = "master", @@ -39,7 +39,7 @@ }, version = "6.2.1" }, - ["libisl 0.22#671145042a9f4a96a5387ebff97a207d"] = { + ["libisl 0.22#67114504"] = { buildhash = "f649e1fb365e442e8f79f372fd91483b", repo = { branch = "master", @@ -48,7 +48,7 @@ }, version = "0.22" }, - ["libogg#31fecfc4f022419cba33d3f9fc3cc783"] = { + ["libogg#31fecfc4"] = { buildhash = "d894fc29f2fb4c45a0f48bc2c6ece273", repo = { branch = "master", @@ -57,7 +57,7 @@ }, version = "v1.3.4" }, - ["libplist#31fecfc4f022419cba33d3f9fc3cc783"] = { + ["libplist#31fecfc4"] = { buildhash = "0c01b22920be4876b1de74629194eb8f", repo = { branch = "master", @@ -66,7 +66,7 @@ }, version = "2.2.0" }, - ["libtool#31fecfc4f022419cba33d3f9fc3cc783"] = { + ["libtool#31fecfc4"] = { buildhash = "64584ec84a4743ecb740b598b263ffa6", repo = { branch = "master", @@ -75,7 +75,7 @@ }, version = "2.4.6" }, - ["m4#31fecfc4f022419cba33d3f9fc3cc783"] = { + ["m4#31fecfc4"] = { buildhash = "fd0e83e5759b442a970327ebb1c89793", repo = { branch = "master", @@ -84,7 +84,7 @@ }, version = "1.4.19" }, - ["muslcc#31fecfc4f022419cba33d3f9fc3cc783"] = { + ["muslcc#31fecfc4"] = { buildhash = "11062c09ebeb484594488ad73ddbcd1f", repo = { branch = "master", @@ -93,7 +93,7 @@ }, version = "20210202" }, - ["pkg-config#31fecfc4f022419cba33d3f9fc3cc783"] = { + ["pkg-config#31fecfc4"] = { buildhash = "84fd7f9b9f7a47709512cfc85cd9e5f7", repo = { branch = "master", @@ -102,7 +102,7 @@ }, version = "0.29.2" }, - ["zlib#31fecfc4f022419cba33d3f9fc3cc783"] = { + ["zlib#31fecfc4"] = { buildhash = "be90a245b8bb48e6b08a1a15bdcad467", repo = { branch = "master", diff --git a/xmake/modules/private/action/require/impl/utils/requirekey.lua b/xmake/modules/private/action/require/impl/utils/requirekey.lua index 230a53acb..d1792e50c 100644 --- a/xmake/modules/private/action/require/impl/utils/requirekey.lua +++ b/xmake/modules/private/action/require/impl/utils/requirekey.lua @@ -51,9 +51,9 @@ function main(requireinfo, opt) end if opt.hash then if key == "" then - key = "_" + key = "_" -- we need generate a fixed hash value end - return hash.uuid(key):gsub("%-", ""):lower() + return hash.uuid(key):split("-", {plain = true})[1]:lower() else return key end -- cgit v1.3.1