diff options
Diffstat (limited to 'xmake/modules')
4 files changed, 178 insertions, 28 deletions
diff --git a/xmake/modules/devel/git/lastcommit.lua b/xmake/modules/devel/git/lastcommit.lua new file mode 100644 index 000000000..876812f86 --- /dev/null +++ b/xmake/modules/devel/git/lastcommit.lua @@ -0,0 +1,77 @@ +--!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 lastcommit.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_tool") +import("net.proxy") + +-- get last commit in git repository +-- +-- @param opt the options, e.g. {repodir = ..} +-- +-- @return the last commit +-- +-- @code +-- +-- import("devel.git") +-- +-- local lastcommit = git.lastcommit({repodir = ..}) +-- +-- @endcode +-- +function main(opt) + + -- find git + local git = assert(find_tool("git"), "git not found!") + + -- init arguments + local argv = {"rev-parse", "HEAD"} + + -- trace + if option.get("verbose") then + print("%s %s", git.program, os.args(argv)) + end + + -- use proxy? + local envs + local proxy_conf = proxy.config(url) + if proxy_conf then + envs = {ALL_PROXY = proxy_conf} + end + + -- enter repository directory + local oldir = nil + if opt.repodir then + oldir = os.cd(opt.repodir) + end + + -- get last commit + local lastcommit = os.iorunv(git.program, argv, {envs = envs}) + if lastcommit then + lastcommit = lastcommit:trim() + end + + -- leave repository directory + if oldir then + os.cd(oldir) + end + return lastcommit +end diff --git a/xmake/modules/private/action/require/impl/lock_packages.lua b/xmake/modules/private/action/require/impl/lock_packages.lua index 8d1e0ebdd..972c5c48b 100644 --- a/xmake/modules/private/action/require/impl/lock_packages.lua +++ b/xmake/modules/private/action/require/impl/lock_packages.lua @@ -20,16 +20,53 @@ -- imports import("core.project.project") +import("devel.git") +import("private.action.require.impl.utils.filter") +import("private.action.require.impl.utils.requirekey") + +-- get package key +function _get_packagekey(instance) + local requireinfo = instance:requireinfo() + local requirestr = requireinfo.originstr + local plat = instance:plat() + local arch = instance:arch() + local key = requirekey(requireinfo, {plat = instance:plat(), arch = instance:arch()}) + return string.format("%s#%s", requirestr, key) +end -- lock package function _lock_package(instance) - local result = {} - result.name = instance:name() - result.plat = instance:plat() - result.arch = instance:arch() - result.kind = instance:kind() - result.buildhash = instance:buildhash() - result.version = instance:version_str() + local result = {} + local repo = instance:repo() + result.name = instance:name() + result.plat = instance:plat() + result.arch = instance:arch() + result.kind = instance:kind() + result.version = instance:version_str() + result.buildhash = instance:buildhash() + result.configs = instance:configs() + result.is_built = instance:is_built() + if repo then + local lastcommit = git.lastcommit({repodir = repo:directory()}) + result.repo = repo:url() .. "#" .. lastcommit + end + for _, url in ipairs(instance:urls()) do + result.urls = result.urls or {} + local url_alias = instance:url_alias(url) + url = filter.handle(url, instance) + if git.asgiturl(url) then + local revision = instance:revision(url_alias) or instance:tag() or instance:version_str() + url = url .. "#" .. revision + else + local sourcehash = instance:sourcehash(url_alias) + url = url .. "#" .. sourcehash + end + table.insert(result.urls, url) + end + for _, dep in ipairs(instance:plaindeps()) do + result.deps = result.deps or {} + table.insert(result.deps, _get_packagekey(dep)) + end return result end @@ -37,7 +74,8 @@ end function main(packages) local results = {} for _, instance in ipairs(packages) do - results[instance:displayname()] = _lock_package(instance) + local packagekey = _get_packagekey(instance) + results[packagekey] = _lock_package(instance) end io.writefile(project.requireslock(), string.serialize(results, {orderkeys = true})) end diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 612911429..d94629ce8 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -30,6 +30,7 @@ import("core.tool.toolchain") import("core.package.package", {alias = "core_package"}) import("devel.git") import("private.action.require.impl.repository") +import("private.action.require.impl.utils.requirekey") -- get memcache function _memcache() @@ -477,26 +478,10 @@ end -- get package key function _get_packagekey(packagename, requireinfo, version) - local key = packagename .. "/" .. (version or requireinfo.version) - if requireinfo.plat then - key = key .. "/" .. requireinfo.plat - end - if requireinfo.arch then - key = key .. "/" .. requireinfo.arch - 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 key + return requirekey(requireinfo, {name = packagename, + plat = requireinfo.plat, + arch = requireinfo.arch, + version = version or requireinfo.version}) end -- inherit some builtin configs of parent package if these config values are not default value 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 |
