From 115e83b7716ad866d0e885fd7d359358e539f519 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 14 May 2024 00:25:32 +0800 Subject: [PATCH] improve test.lua --- scripts/test.lua | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts/test.lua b/scripts/test.lua index 2020c5d74..71c2019bc 100644 --- a/scripts/test.lua +++ b/scripts/test.lua @@ -1,6 +1,7 @@ -- imports import("core.base.option") import("core.platform.platform") +import("core.package.package", {alias = "core_package"}) import("packages", {alias = "get_packages"}) -- the options @@ -39,6 +40,16 @@ local options = , {nil, "packages", "vs", nil, "The package list." } } +-- check package is supported? +function _check_package_is_supported() + for _, names in pairs(core_package.apis()) do + for _, name in ipairs(names) do + if type(name) == "string" and name == "package.on_check" then + return true + end + end + end +end -- require packages function _require_packages(argv, packages) @@ -163,11 +174,15 @@ function _require_packages(argv, packages) table.insert(check_argv, "--extra=" .. extra_str) local install_packages = {} - for _, package in ipairs(packages) do - local ok = os.vexecv("xmake", table.join(check_argv, package), {try = true}) - if ok == 0 then - table.insert(install_packages, package) + if _check_package_is_supported() then + for _, package in ipairs(packages) do + local ok = os.vexecv("xmake", table.join(check_argv, package), {try = true}) + if ok == 0 then + table.insert(install_packages, package) + end end + else + install_packages = packages end if #install_packages > 0 then os.vexecv("xmake", table.join(require_argv, install_packages))