summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-11-27 00:45:33 +0800
committerruki <[email protected]>2024-11-27 00:45:33 +0800
commit35422e3877f65a126177f1f25ea712eda2f47ff5 (patch)
treebd651702b02fb5fb5dabf35719c5bf238156e568
parentc4d249edd48667214a08900e5e9f6b2a7222552a (diff)
improve tips
-rw-r--r--xmake/modules/private/action/require/impl/install_packages.lua21
-rw-r--r--xmake/modules/private/action/require/impl/package.lua32
2 files changed, 31 insertions, 22 deletions
diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua
index 005ca0fe5..8dbff89aa 100644
--- a/xmake/modules/private/action/require/impl/install_packages.lua
+++ b/xmake/modules/private/action/require/impl/install_packages.lua
@@ -29,7 +29,6 @@ import("utils.progress")
import("net.fasturl")
import("private.action.require.impl.package")
import("private.action.require.impl.lock_packages")
-import("private.action.require.impl.search_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"})
@@ -682,24 +681,6 @@ function _get_package_installdeps(packages)
return installdeps
end
--- get possible package
-function _get_possible_package(packagename)
- local packages_possible = search_packages("*", {description = false})
- if packages_possible then
- packages_possible = packages_possible["*"]
- end
- local result
- local distance_min
- for name, info in pairs(packages_possible) do
- local distance = packagename:levenshtein(info.name)
- if distance_min == nil or distance < distance_min and distance < 5 then
- distance_min = distance
- result = info
- end
- end
- return result
-end
-
-- install packages
function _install_packages(requires, opt)
opt = opt or {}
@@ -765,7 +746,7 @@ function _install_packages(requires, opt)
cprint("${bright color.warning}note: ${clear}the following packages were not found in any repository (check if they are spelled correctly):")
for _, instance in ipairs(packages_unknown) do
local tips
- local possible_package = _get_possible_package(instance:name())
+ local possible_package = package.get_possible_package(instance:name())
if possible_package then
tips = string.format(", maybe ${bright}%s %s${clear} in %s", possible_package.name, possible_package.version, possible_package.reponame)
end
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index 34d7f8d22..5c0d1bf3d 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -32,6 +32,7 @@ import("core.platform.platform")
import("core.package.package", {alias = "core_package"})
import("devel.git")
import("private.action.require.impl.repository")
+import("private.action.require.impl.search_packages")
import("private.action.require.impl.utils.requirekey", {alias = "_get_requirekey"})
-- get memcache
@@ -967,8 +968,17 @@ function _load_package(packagename, requireinfo, opt)
package = _load_package_from_system(packagename)
end
- -- check
- assert(package, "package(%s) not found!", packagename)
+ -- check unknown package
+ if not package then
+ cprint("${bright color.warning}note: ${clear}the following packages were not found in any repository (check if they are spelled correctly):")
+ local tips
+ local possible_package = get_possible_package(packagename)
+ if possible_package then
+ tips = string.format(", maybe ${bright}%s %s${clear} in %s", possible_package.name, possible_package.version, possible_package.reponame)
+ end
+ cprint(" -> %s%s", packagename, tips or "")
+ raise("package(%s) not found!", packagename)
+ end
-- init requireinfo
_init_requireinfo(requireinfo, package, {is_toplevel = not opt.parentinfo})
@@ -1284,6 +1294,24 @@ function _compatible_with_previous_librarydeps(package, opt)
return is_compatible
end
+-- get possible package
+function get_possible_package(packagename)
+ local packages_possible = search_packages("*", {description = false})
+ if packages_possible then
+ packages_possible = packages_possible["*"]
+ end
+ local result
+ local distance_min
+ for name, info in pairs(packages_possible) do
+ local distance = packagename:levenshtein(info.name)
+ if distance_min == nil or distance < distance_min and distance < 5 then
+ distance_min = distance
+ result = info
+ end
+ end
+ return result
+end
+
-- the cache directory
function cachedir()
return path.join(global.directory(), "cache", "packages")