diff options
| author | ruki <[email protected]> | 2021-10-27 22:52:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-10-27 22:52:03 +0800 |
| commit | 3225b2b74981dc87130966b0b6a4011f5e0eff6c (patch) | |
| tree | 7f2a05ec41dc3a5efaba1cd097cbd8f5a971426d | |
| parent | 20d47ee82092c9d92f18284cf6873bde6e65c2f3 (diff) | |
impl nimble find_package
| -rw-r--r-- | xmake/modules/package/manager/dub/find_package.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/package/manager/nimble/find_package.lua | 28 |
2 files changed, 28 insertions, 2 deletions
diff --git a/xmake/modules/package/manager/dub/find_package.lua b/xmake/modules/package/manager/dub/find_package.lua index 8543a8bfb..5d49d695e 100644 --- a/xmake/modules/package/manager/dub/find_package.lua +++ b/xmake/modules/package/manager/dub/find_package.lua @@ -30,7 +30,7 @@ import("lib.detect.find_file") -- find package using the dub package manager -- -- @param name the package name --- @param opt the options, e.g. {verbose = true, version = "1.12.x") +-- @param opt the options, e.g. {verbose = true, require_version = "1.12.x") -- function main(name, opt) diff --git a/xmake/modules/package/manager/nimble/find_package.lua b/xmake/modules/package/manager/nimble/find_package.lua index cb9d3884a..c39d6ed34 100644 --- a/xmake/modules/package/manager/nimble/find_package.lua +++ b/xmake/modules/package/manager/nimble/find_package.lua @@ -20,6 +20,7 @@ -- imports import("core.base.option") +import("core.base.semver") import("core.project.config") import("core.project.target") import("lib.detect.find_tool") @@ -28,7 +29,7 @@ import("lib.detect.find_file") -- find package using the nimble package manager -- -- @param name the package name --- @param opt the options, e.g. {verbose = true, version = "1.12.x") +-- @param opt the options, e.g. {verbose = true, require_version = "1.12.x") -- function main(name, opt) @@ -38,4 +39,29 @@ function main(name, opt) raise("nimble not found!") end + -- find it from all installed package list + 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 + if opt.require_version then + if package_version and (opt.require_version == "latest" or semver.match(package_version, 1, opt.require_version)) then + result = {version = package_version} + break + end + else + result = {} + break + end + end + end + -- @note we need not return links and includedirs information, + -- because it's nim source code package and nim will find them automatically + return result end |
