diff options
| author | ruki <[email protected]> | 2021-08-19 22:21:53 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-08-19 22:21:53 +0800 |
| commit | 9c096fc45a4fb8ac817eb48ab8e762e2b41ab259 (patch) | |
| tree | bebf40a98ed31b8b7b94231976a26637614b80a1 /xmake/modules/private/action/require/impl/lock_packages.lua | |
| parent | 69da74c43e934650eb797ec51f6b7c91fd419642 (diff) | |
| parent | 0eac4a64692796d99a1a30f206a2d21463e0acf6 (diff) | |
Merge pull request #1587 from xmake-io/requireslock
Support xmake-requires.lock to lock all required packages
Diffstat (limited to 'xmake/modules/private/action/require/impl/lock_packages.lua')
| -rw-r--r-- | xmake/modules/private/action/require/impl/lock_packages.lua | 64 |
1 files changed, 64 insertions, 0 deletions
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..18dabcac4 --- /dev/null +++ b/xmake/modules/private/action/require/impl/lock_packages.lua @@ -0,0 +1,64 @@ +--!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") +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 requireinfo = instance:requireinfo() + return requireinfo and requireinfo.requirekey +end + +-- lock package +function _lock_package(instance) + local result = {} + local repo = instance:repo() + result.name = instance:name() + result.plat = instance:plat() + result.arch = instance:arch() + result.version = instance:version_str() + result.buildhash = instance:buildhash() + result.branch = instance:branch() + result.tag = instance:tag() + if repo then + local lastcommit = git.lastcommit({repodir = repo:directory()}) + result.repo = {url = repo:url(), commit = lastcommit, branch = repo:branch()} + end + return result +end + +-- lock all required packages +function main(packages) + if project.policy("package.requires_lock") then + local results = {__meta__ = {}} + results.__meta__.version = project.requireslock_version() + for _, instance in ipairs(packages) do + local packagelock_key = _get_packagelock_key(instance) + results[packagelock_key] = _lock_package(instance) + end + io.writefile(project.requireslock(), string.serialize(results, {orderkeys = true})) + end +end + |
