diff options
| author | ruki <[email protected]> | 2024-11-26 22:57:31 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-11-26 22:57:31 +0800 |
| commit | 2e5a83a3a13dd34ed36cac43a0262c036ecb1259 (patch) | |
| tree | bf3b52f7a58213f10127891f9fdd18b747878787 | |
| parent | 7bdfaf44792d6af75081a3a8316515dc72dca0d6 (diff) | |
| parent | 35422e3877f65a126177f1f25ea712eda2f47ff5 (diff) | |
Merge pull request #5889 from xmake-io/package
add unknown package tips
3 files changed, 37 insertions, 4 deletions
diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index ba1ccdbd8..8dbff89aa 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -745,7 +745,12 @@ function _install_packages(requires, opt) if #packages_unknown > 0 then 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 - print(" -> %s", instance:displayname()) + local tips + 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 + cprint(" -> %s%s", instance:displayname(), tips or "") end has_errors = true 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") diff --git a/xmake/modules/private/xrepo/quick_search/cache.lua b/xmake/modules/private/xrepo/quick_search/cache.lua index 9ba142076..ceefad3fc 100644 --- a/xmake/modules/private/xrepo/quick_search/cache.lua +++ b/xmake/modules/private/xrepo/quick_search/cache.lua @@ -88,7 +88,7 @@ function find(name, opt) if opt.prefix then found = packagename:startswith(name) else - found = packagename:find(name) + found = packagename:find(path.pattern(name)) end if not found and opt.description and packagedata.description and packagedata.description:find(name) then found = true |
