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 | |
| parent | 2e3a31be034dd4fab8cd0cb206efa30a35897020 (diff) | |
| parent | ac5b68d1509342c93637d7149f3c208daa49ae8d (diff) | |
Merge pull request #5086 from xmake-io/check
add check script for package
| -rw-r--r-- | xmake/actions/config/main.lua | 6 | ||||
| -rw-r--r-- | xmake/actions/require/main.lua | 8 | ||||
| -rw-r--r-- | xmake/actions/require/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/check.lua | 45 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/actions/check.lua | 41 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/install_packages.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/register.lua | 74 |
8 files changed, 141 insertions, 40 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 327094039..9f0cc08fd 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -30,7 +30,7 @@ import("core.cache.localcache") import("scangen") import("menuconf", {alias = "menuconf_show"}) import("configfiles", {alias = "generate_configfiles"}) -import("private.action.require.check", {alias = "check_packages"}) +import("private.action.require.register", {alias = "register_packages"}) import("private.action.require.install", {alias = "install_packages"}) import("private.service.remote_build.action", {alias = "remote_build_action"}) @@ -384,13 +384,13 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) -- check configs _check_configs() - -- install and update packages + -- install and register packages local require_enable = option.boolean(option.get("require")) if (recheck or require_enable) then if require_enable ~= false then install_packages() else - check_packages() + register_packages() end end diff --git a/xmake/actions/require/main.lua b/xmake/actions/require/main.lua index 88cec846b..80e8b2a03 100644 --- a/xmake/actions/require/main.lua +++ b/xmake/actions/require/main.lua @@ -35,6 +35,7 @@ import("private.action.require.import", {alias = "import_packages"}) import("private.action.require.install") import("private.action.require.uninstall") import("private.action.require.download") +import("private.action.require.check") import("private.service.remote_build.action", {alias = "remote_build_action"}) -- @@ -110,7 +111,7 @@ function main() info(option.get("requires")) - -- fetch the library info of the given package + -- fetch the library info of the given packages elseif option.get("fetch") then fetch(option.get("requires")) @@ -120,6 +121,11 @@ function main() download(option.get("requires")) + -- check the given packages + elseif option.get("check") then + + check(option.get("requires")) + -- list all package dependencies in project elseif option.get("list") then diff --git a/xmake/actions/require/xmake.lua b/xmake/actions/require/xmake.lua index e3923b516..495f2e977 100644 --- a/xmake/actions/require/xmake.lua +++ b/xmake/actions/require/xmake.lua @@ -65,6 +65,9 @@ task("require") , {nil, "info", "k", nil, "Show the given package info.", "e.g.", " $ xmake require --info tbox" } + , {nil, "check", "k", nil, "Check whether the given package is supported", + "e.g.", + " $ xmake require --check tbox" } , {nil, "fetch", "k", nil, "Fetch the library info of given package.", "e.g.", " $ xmake require --fetch tbox" } diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 48c84145b..2d0fe989d 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -2663,6 +2663,7 @@ function package.apis() -- package.on_xxx "package.on_load" , "package.on_fetch" + , "package.on_check" , "package.on_download" , "package.on_install" , "package.on_test" 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 + |
