diff options
| author | ruki <[email protected]> | 2025-01-09 00:56:25 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-01-09 00:56:25 +0800 |
| commit | 9c0f92f7cfcabe17fbb56c2f6bc1ea54a7223f82 (patch) | |
| tree | 555f80b76b9007e7dcbba42c405a7376abbd5545 /xmake | |
| parent | 7a4c72e8385d63e1588f8a1cd8b482cf8825d5fb (diff) | |
improve has_package
Diffstat (limited to 'xmake')
| -rw-r--r-- | xmake/core/project/project.lua | 15 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/has_package.lua | 15 |
2 files changed, 26 insertions, 4 deletions
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index b102f4423..43271c7b0 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -137,8 +137,19 @@ function project._api_has_package(interp, ...) -- only for loading targets local requires = project._memcache():get("requires") if requires then - for _, name in ipairs(table.pack(...)) do - local pkg = requires[name] + for _, packagename in ipairs(table.pack(...)) do + local pkg = requires[packagename] + -- attempt to get package with namespace + if pkg == nil and packagename:find("::", 1, true) then + local parts = packagename:split("::", {plain = true}) + local namespace_pkg = requires[parts[#parts]] + if namespace_pkg and namespace_pkg:namespace() then + local fullname = namespace_pkg:fullname() + if fullname:endswith(packagename) then + pkg = namespace_pkg + end + end + end if pkg and pkg:enabled() then return true end diff --git a/xmake/core/sandbox/modules/has_package.lua b/xmake/core/sandbox/modules/has_package.lua index 8d6c8ec3f..cb5d2822e 100644 --- a/xmake/core/sandbox/modules/has_package.lua +++ b/xmake/core/sandbox/modules/has_package.lua @@ -23,8 +23,19 @@ return function (...) require("sandbox/modules/import/core/sandbox/module").import("core.project.project") local requires = project.required_packages() if requires then - for _, name in ipairs(table.join(...)) do - local pkg = requires[name] + for _, packagename in ipairs(table.join(...)) do + local pkg = requires[packagename] + -- attempt to get package with namespace + if pkg == nil and packagename:find("::", 1, true) then + local parts = packagename:split("::", {plain = true}) + local namespace_pkg = requires[parts[#parts]] + if namespace_pkg and namespace_pkg:namespace() then + local fullname = namespace_pkg:fullname() + if fullname:endswith(packagename) then + pkg = namespace_pkg + end + end + end if pkg and pkg:enabled() then return true end |
