Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unknown package tips #5889

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 30 additions & 2 deletions xmake/modules/private/action/require/impl/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion xmake/modules/private/xrepo/quick_search/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading