summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-08-14 23:45:05 +0800
committerruki <[email protected]>2021-08-14 23:45:05 +0800
commita19fc6d6da6627b5bdab702931ab6278e8cf8409 (patch)
tree0c99d4e17fdaa16c7f64795dcc867aa285ce9700
parent0795b09c48d770af91138edc417089830c1d4850 (diff)
sort table.keys
-rw-r--r--tests/projects/package/multiconfig/xmake-requires.lock5
-rw-r--r--tests/projects/package/multiconfig/xmake.lua1
-rw-r--r--xmake/core/base/serialize.lua3
-rw-r--r--xmake/core/base/table.lua15
-rw-r--r--xmake/core/project/project.lua2
-rw-r--r--xmake/core/sandbox/modules/import/core/project/project.lua2
-rw-r--r--xmake/modules/private/action/require/impl/install_packages.lua4
-rw-r--r--xmake/modules/private/action/require/impl/lock_packages.lua40
8 files changed, 69 insertions, 3 deletions
diff --git a/tests/projects/package/multiconfig/xmake-requires.lock b/tests/projects/package/multiconfig/xmake-requires.lock
new file mode 100644
index 000000000..5752aa15a
--- /dev/null
+++ b/tests/projects/package/multiconfig/xmake-requires.lock
@@ -0,0 +1,5 @@
+{
+ zlib = {
+ buildhash = "8e5b898b0f344715bac89cc6a1577506"
+ }
+} \ No newline at end of file
diff --git a/tests/projects/package/multiconfig/xmake.lua b/tests/projects/package/multiconfig/xmake.lua
index 09121e8d2..7aa2bdffb 100644
--- a/tests/projects/package/multiconfig/xmake.lua
+++ b/tests/projects/package/multiconfig/xmake.lua
@@ -2,6 +2,7 @@ add_requires("zlib", {system = false})
add_requires("zlib", {system = false}) -- test repeat requires
add_requires("zlib~debug", {system = false, debug = true})
add_requires("zlib~shared", {system = false, configs = {shared = true}, alias = "zlib_shared"})
+set_policy("package.requires_lock", true)
target("test1")
set_kind("binary")
diff --git a/xmake/core/base/serialize.lua b/xmake/core/base/serialize.lua
index 99486bf8c..a2d7b9ff9 100644
--- a/xmake/core/base/serialize.lua
+++ b/xmake/core/base/serialize.lua
@@ -123,7 +123,8 @@ function serialize._maketable(obj, opt, level, pathsegs, reftab)
local sformat = opt.indentstr and "[%q] = %s" or "[%q]=%s"
local nformat = opt.indentstr and "[%s] = %s" or "[%s]=%s"
local keywords = serialize._keywords()
- for k, v in pairs(serialized) do
+ local makepairs = opt.orderkeys and table.orderpairs or pairs
+ for k, v in makepairs(serialized) do
local format
-- serialize key
if type(k) == "string" then
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua
index c86a90988..01a6a4692 100644
--- a/xmake/core/base/table.lua
+++ b/xmake/core/base/table.lua
@@ -317,6 +317,21 @@ function table.orderkeys(tab)
return keys
end
+-- order key/value iterator
+--
+-- for k, v in table.orderpairs(t) do
+-- TODO
+-- end
+function table.orderpairs(t)
+ local orderkeys = table.orderkeys(t)
+ local i = 1
+ return function (t, k)
+ k = orderkeys[i]
+ i = i + 1
+ return k, t[k]
+ end, t, nil
+end
+
-- get values of a table
function table.values(tab)
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 138e847ba..e2d7f996a 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -1024,7 +1024,7 @@ function project.requireconfs_str()
end
-- get requires lockfile
-function project.requires_lockfile()
+function project.requireslock()
return path.join(project.directory(), "xmake-requires.lock")
end
diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua
index 1becb07a9..696bd0d91 100644
--- a/xmake/core/sandbox/modules/import/core/project/project.lua
+++ b/xmake/core/sandbox/modules/import/core/project/project.lua
@@ -63,7 +63,7 @@ sandbox_core_project.required_package = project.required_package
sandbox_core_project.required_packages = project.required_packages
sandbox_core_project.requires_str = project.requires_str
sandbox_core_project.requireconfs_str = project.requireconfs_str
-sandbox_core_project.requires_lockfile = project.requires_lockfile
+sandbox_core_project.requireslock = project.requireslock
sandbox_core_project.policy = project.policy
sandbox_core_project.tmpdir = project.tmpdir
sandbox_core_project.tmpfile = project.tmpfile
diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua
index 7e83ae939..79fb71c3f 100644
--- a/xmake/modules/private/action/require/impl/install_packages.lua
+++ b/xmake/modules/private/action/require/impl/install_packages.lua
@@ -30,6 +30,7 @@ import("actions.install", {alias = "action_install"})
import("actions.download", {alias = "action_download"})
import("net.fasturl")
import("private.action.require.impl.package")
+import("private.action.require.impl.lock_packages")
import("private.action.require.impl.register_packages")
-- sort packages urls
@@ -600,6 +601,9 @@ function main(requires, opt)
-- re-register and refresh all root packages to local cache,
-- because there may be some missing optional dependencies reinstalled
register_packages(packages)
+
+ -- lock packages
+ lock_packages(packages)
return packages
end
diff --git a/xmake/modules/private/action/require/impl/lock_packages.lua b/xmake/modules/private/action/require/impl/lock_packages.lua
new file mode 100644
index 000000000..fffb76dfa
--- /dev/null
+++ b/xmake/modules/private/action/require/impl/lock_packages.lua
@@ -0,0 +1,40 @@
+--!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 lock_packages.lua
+--
+
+-- imports
+import("core.project.project")
+
+-- lock package
+function _lock_package(instance)
+ local result = {}
+ result.buildhash = instance:buildhash()
+ return result
+end
+
+-- lock all required packages
+function main(packages)
+ local results = {}
+ for _, instance in ipairs(packages) do
+ results[instance:name()] = _lock_package(instance)
+ end
+ table.sort(results, function (a, b) return a.name < b.name end)
+ io.writefile(project.requireslock(), string.serialize(results, {orderkeys = true}))
+end
+