diff options
| author | ruki <[email protected]> | 2024-05-11 10:12:18 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-05-11 10:12:18 +0800 |
| commit | c6cd8a29faa3dd564a36998f1a417451d68e2d8d (patch) | |
| tree | c9b854cf03d54c21116ce36ac6452d4d77818a09 /xmake/modules | |
| parent | 2e3a31be034dd4fab8cd0cb206efa30a35897020 (diff) | |
| parent | ac5b68d1509342c93637d7149f3c208daa49ae8d (diff) | |
Merge pull request #5086 from xmake-io/check
add check script for package
Diffstat (limited to 'xmake/modules')
4 files changed, 127 insertions, 36 deletions
diff --git a/xmake/modules/private/action/require/check.lua b/xmake/modules/private/action/require/check.lua index 44851d29d..3d6f3ead6 100644 --- a/xmake/modules/private/action/require/check.lua +++ b/xmake/modules/private/action/require/check.lua @@ -20,16 +20,16 @@ -- imports import("core.base.option") -import("core.base.task") -import("lib.detect.find_tool") -import("async.runjobs") +import("core.base.hashset") +import("core.base.json") +import("core.project.project") +import("core.package.package", {alias = "core_package"}) import("private.action.require.impl.package") import("private.action.require.impl.repository") -import("private.action.require.impl.environment") -import("private.action.require.impl.register_packages") import("private.action.require.impl.utils.get_requires") +import("private.action.require.impl.actions.check", {alias = "action_check"}) --- install packages +-- check the given package info function main(requires_raw) -- get requires and extra config @@ -39,36 +39,9 @@ function main(requires_raw) return end - -- find git - environment.enter() - local git = find_tool("git") - environment.leave() - - -- pull all repositories first if not exists - -- - -- attempt to install git from the builtin-packages first if git not found - -- - if git and (not repository.pulled() or option.get("upgrade")) then - task.run("repo", {update = true}) - end - - -- install packages - local packages = package.load_packages(requires, {requires_extra = requires_extra}) - if packages then - - -- fetch and register packages (with system) from local first - runjobs("fetch_packages", function (index) - local instance = packages[index] - if instance and (not option.get("force") or (option.get("shallow") and not instance:is_toplevel())) then - local oldenvs = os.getenvs() - instance:envs_enter() - instance:fetch() - os.setenvs(oldenvs) - end - end, {total = #packages, isolate = true}) - - -- register all required root packages to local cache - register_packages(packages) + -- check the given packages + for _, instance in irpairs(package.load_packages(requires, {requires_extra = requires_extra, nodeps = true})) do + action_check(instance) end end diff --git a/xmake/modules/private/action/require/impl/actions/check.lua b/xmake/modules/private/action/require/impl/actions/check.lua new file mode 100644 index 000000000..8eb6d7d96 --- /dev/null +++ b/xmake/modules/private/action/require/impl/actions/check.lua @@ -0,0 +1,41 @@ +--!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 check.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") + +-- check the given package +function main(package, opt) + opt = opt or {} + + -- we need not check it if this package is precompiled now + if package:is_precompiled() then + return + end + + -- do check + local script = package:script("check") + if script then + script(package) + end +end + + diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index 359392f71..bcd0169b1 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("net.fasturl") import("private.action.require.impl.package") import("private.action.require.impl.lock_packages") import("private.action.require.impl.register_packages") +import("private.action.require.impl.actions.check", {alias = "action_check"}) import("private.action.require.impl.actions.install", {alias = "action_install"}) import("private.action.require.impl.actions.download", {alias = "action_download"}) @@ -477,6 +478,7 @@ function _install_packages(packages_install, packages_download, installdeps) local downloaded = true if packages_download[tostring(instance)] then packages_downloading[index] = instance + action_check(instance) downloaded = action_download(instance) packages_downloading[index] = nil end @@ -488,6 +490,7 @@ function _install_packages(packages_install, packages_download, installdeps) assert(instance:is_precompiled(), "package(%s) should be precompiled", instance:name()) -- we need to disable built and re-download and re-install it instance:fallback_build() + action_check(instance) action_download(instance) action_install(instance) end diff --git a/xmake/modules/private/action/require/register.lua b/xmake/modules/private/action/require/register.lua new file mode 100644 index 000000000..040e5bcab --- /dev/null +++ b/xmake/modules/private/action/require/register.lua @@ -0,0 +1,74 @@ +--!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 register.lua +-- + +-- imports +import("core.base.option") +import("core.base.task") +import("lib.detect.find_tool") +import("async.runjobs") +import("private.action.require.impl.package") +import("private.action.require.impl.repository") +import("private.action.require.impl.environment") +import("private.action.require.impl.register_packages") +import("private.action.require.impl.utils.get_requires") + +-- register packages +function main(requires_raw) + + -- get requires and extra config + local requires_extra = nil + local requires, requires_extra = get_requires(requires_raw) + if not requires or #requires == 0 then + return + end + + -- find git + environment.enter() + local git = find_tool("git") + environment.leave() + + -- pull all repositories first if not exists + -- + -- attempt to install git from the builtin-packages first if git not found + -- + if git and (not repository.pulled() or option.get("upgrade")) then + task.run("repo", {update = true}) + end + + -- register packages + local packages = package.load_packages(requires, {requires_extra = requires_extra}) + if packages then + + -- fetch and register packages (with system) from local first + runjobs("fetch_packages", function (index) + local instance = packages[index] + if instance and (not option.get("force") or (option.get("shallow") and not instance:is_toplevel())) then + local oldenvs = os.getenvs() + instance:envs_enter() + instance:fetch() + os.setenvs(oldenvs) + end + end, {total = #packages, isolate = true}) + + -- register all required root packages to local cache + register_packages(packages) + end +end + |
