diff options
| author | ruki <[email protected]> | 2024-03-21 22:34:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-03-21 22:34:06 +0800 |
| commit | bbce1384f06f13fe3726ae67da24a07adee20fac (patch) | |
| tree | 19d26f577c230c80838f3518c4562376d0e42845 | |
| parent | aa129947e364c770c0239d0915ec3a400a112dbd (diff) | |
improve nim::find_package #4807
| -rw-r--r-- | xmake/modules/package/manager/nimble/find_package.lua | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/xmake/modules/package/manager/nimble/find_package.lua b/xmake/modules/package/manager/nimble/find_package.lua index 38eddefa6..1306c3097 100644 --- a/xmake/modules/package/manager/nimble/find_package.lua +++ b/xmake/modules/package/manager/nimble/find_package.lua @@ -26,6 +26,25 @@ import("core.project.target") import("lib.detect.find_tool") import("lib.detect.find_file") +-- parse package name and version +-- +-- e.g. +-- zip [0.3.1] +-- zip [(version: 0.3.1, checksum: 747aab3c43ecb7b50671cdd0ec3b2edc2c83494c)] +-- +function _parse_packageinfo(line) + local splitinfo = line:split("%s+") + local package_name = splitinfo[1] + local version_str = splitinfo[2] + if version_str then + local version = semver.match(version_str) + if version then + package_version = version:rawstr() + end + end + return package_name, package_version +end + -- find package using the nimble package manager -- -- @param name the package name @@ -43,15 +62,10 @@ function main(name, opt) local result local list = os.iorunv(nimble.program, {"list", "-i"}) for _, line in ipairs(list:split("\n", {plain = true})) do - local splitinfo = line:split("%s+") - local package_name = splitinfo[1] - local package_version = splitinfo[2] - if package_name == name and package_version then - if package_version then - package_version = package_version:match("%[(.+)%]") - end + local package_name, package_version = _parse_packageinfo(line) + if package_name == name then if opt.require_version then - if package_version and (opt.require_version == "latest" or semver.match(package_version, 1, opt.require_version)) then + if package_version and (opt.require_version == "latest" or semver.satisfies(package_version, opt.require_version)) then result = {version = package_version} break end |
