From 019744ba3a592cb0b0a89d275f96ed665531253f Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 27 Oct 2021 22:40:18 +0800 Subject: add nimble test --- tests/projects/nim/console_with_packages/src/main.nim | 3 --- tests/projects/nim/console_with_packages/xmake.lua | 8 -------- tests/projects/nim/native_package/src/main.nim | 3 +++ tests/projects/nim/native_package/xmake.lua | 8 ++++++++ tests/projects/nim/nimble_package/src/main.nim | 3 +++ tests/projects/nim/nimble_package/xmake.lua | 8 ++++++++ 6 files changed, 22 insertions(+), 11 deletions(-) delete mode 100644 tests/projects/nim/console_with_packages/src/main.nim delete mode 100644 tests/projects/nim/console_with_packages/xmake.lua create mode 100644 tests/projects/nim/native_package/src/main.nim create mode 100644 tests/projects/nim/native_package/xmake.lua create mode 100644 tests/projects/nim/nimble_package/src/main.nim create mode 100644 tests/projects/nim/nimble_package/xmake.lua diff --git a/tests/projects/nim/console_with_packages/src/main.nim b/tests/projects/nim/console_with_packages/src/main.nim deleted file mode 100644 index a3368303a..000000000 --- a/tests/projects/nim/console_with_packages/src/main.nim +++ /dev/null @@ -1,3 +0,0 @@ -proc zlibVersion(): cstring {.cdecl, importc} - -echo zlibVersion() diff --git a/tests/projects/nim/console_with_packages/xmake.lua b/tests/projects/nim/console_with_packages/xmake.lua deleted file mode 100644 index 924ee9632..000000000 --- a/tests/projects/nim/console_with_packages/xmake.lua +++ /dev/null @@ -1,8 +0,0 @@ -add_rules("mode.debug", "mode.release") - -add_requires("zlib") - -target("test") - set_kind("binary") - add_files("src/main.nim") - add_packages("zlib") diff --git a/tests/projects/nim/native_package/src/main.nim b/tests/projects/nim/native_package/src/main.nim new file mode 100644 index 000000000..a3368303a --- /dev/null +++ b/tests/projects/nim/native_package/src/main.nim @@ -0,0 +1,3 @@ +proc zlibVersion(): cstring {.cdecl, importc} + +echo zlibVersion() diff --git a/tests/projects/nim/native_package/xmake.lua b/tests/projects/nim/native_package/xmake.lua new file mode 100644 index 000000000..924ee9632 --- /dev/null +++ b/tests/projects/nim/native_package/xmake.lua @@ -0,0 +1,8 @@ +add_rules("mode.debug", "mode.release") + +add_requires("zlib") + +target("test") + set_kind("binary") + add_files("src/main.nim") + add_packages("zlib") diff --git a/tests/projects/nim/nimble_package/src/main.nim b/tests/projects/nim/nimble_package/src/main.nim new file mode 100644 index 000000000..b78aa2495 --- /dev/null +++ b/tests/projects/nim/nimble_package/src/main.nim @@ -0,0 +1,3 @@ +import zip/zlib + +echo zlibVersion() diff --git a/tests/projects/nim/nimble_package/xmake.lua b/tests/projects/nim/nimble_package/xmake.lua new file mode 100644 index 000000000..af3e0f0f5 --- /dev/null +++ b/tests/projects/nim/nimble_package/xmake.lua @@ -0,0 +1,8 @@ +add_rules("mode.debug", "mode.release") + +add_requires("nimble::zip") + +target("test") + set_kind("binary") + add_files("src/main.nim") + add_packages("nimble::zip") -- cgit v1.3.1 From 65b92a8486ebb5e36e7d4fb7c133fb9fe2f9a798 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 27 Oct 2021 22:40:39 +0800 Subject: add find_nimble --- xmake/modules/detect/tools/find_nimble.lua | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 xmake/modules/detect/tools/find_nimble.lua diff --git a/xmake/modules/detect/tools/find_nimble.lua b/xmake/modules/detect/tools/find_nimble.lua new file mode 100644 index 000000000..7d4364b64 --- /dev/null +++ b/xmake/modules/detect/tools/find_nimble.lua @@ -0,0 +1,52 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_nimble.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find nim +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local nim = find_nimble() +-- local nim, version = find_nimble({program = "nimble", version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "nimble", opt) + + -- find program version + local version = nil + if program and opt.version then + version = find_programver(program, opt) + end + return program, version +end -- cgit v1.3.1 From c871e3f603c6022c16659cca61f8995f29b5275e Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 27 Oct 2021 22:41:07 +0800 Subject: add nimble stub --- .../package/manager/nimble/find_package.lua | 41 ++++++++++++++++++++++ .../package/manager/nimble/install_package.lua | 41 ++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 xmake/modules/package/manager/nimble/find_package.lua create mode 100644 xmake/modules/package/manager/nimble/install_package.lua diff --git a/xmake/modules/package/manager/nimble/find_package.lua b/xmake/modules/package/manager/nimble/find_package.lua new file mode 100644 index 000000000..cb9d3884a --- /dev/null +++ b/xmake/modules/package/manager/nimble/find_package.lua @@ -0,0 +1,41 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_package.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("core.project.target") +import("lib.detect.find_tool") +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") +-- +function main(name, opt) + + -- find nimble + local nimble = find_tool("nimble") + if not nimble then + raise("nimble not found!") + end + +end diff --git a/xmake/modules/package/manager/nimble/install_package.lua b/xmake/modules/package/manager/nimble/install_package.lua new file mode 100644 index 000000000..57addc15a --- /dev/null +++ b/xmake/modules/package/manager/nimble/install_package.lua @@ -0,0 +1,41 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file install_package.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("lib.detect.find_tool") + +-- install package +-- +-- @param name the package name, e.g. nimble::zip +-- @param opt the options, e.g. { verbose = true, mode = "release", plat = , arch = , require_version = "x.x.x", buildhash = "xxxxxx"} +-- +-- @return true or false +-- +function main(name, opt) + + -- find nimble + local nimble = find_tool("nimble") + if not nimble then + raise("nimble not found!") + end + +end -- cgit v1.3.1 From cc80af774a9426d7775be165adb4aa00d8569ed6 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 27 Oct 2021 22:45:11 +0800 Subject: impl nimble/install_package --- tests/projects/nim/nimble_package/xmake.lua | 2 +- xmake/modules/package/manager/nimble/install_package.lua | 12 ++++++++++++ xmake/modules/private/action/require/impl/package.lua | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/projects/nim/nimble_package/xmake.lua b/tests/projects/nim/nimble_package/xmake.lua index af3e0f0f5..45e6f3132 100644 --- a/tests/projects/nim/nimble_package/xmake.lua +++ b/tests/projects/nim/nimble_package/xmake.lua @@ -1,6 +1,6 @@ add_rules("mode.debug", "mode.release") -add_requires("nimble::zip") +add_requires("nimble::zip >0.3") target("test") set_kind("binary") diff --git a/xmake/modules/package/manager/nimble/install_package.lua b/xmake/modules/package/manager/nimble/install_package.lua index 57addc15a..b5ba21438 100644 --- a/xmake/modules/package/manager/nimble/install_package.lua +++ b/xmake/modules/package/manager/nimble/install_package.lua @@ -38,4 +38,16 @@ function main(name, opt) raise("nimble not found!") end + -- install the given package + local argv = {"install", "-y"} + if option.get("verbose") then + table.insert(argv, "--verbose") + end + local require_str = name + if opt.require_version and opt.require_version ~= "latest" and opt.require_version ~= "master" then + name = name .. "@" + name = name .. opt.require_version + end + table.insert(argv, name) + os.vrunv(nimble.program, argv) end diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 5a43de562..77c20648b 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -339,7 +339,7 @@ function _select_package_version(package, requireinfo, locked_requireinfo) version = "latest" source = "version" end - if not version then + if not version and not package:is_thirdparty() then raise("package(%s): version(%s) not found!", package:name(), require_version) end return version, source -- cgit v1.3.1 From 20d47ee82092c9d92f18284cf6873bde6e65c2f3 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 27 Oct 2021 22:45:27 +0800 Subject: improve comments --- xmake/modules/package/manager/dub/install_package.lua | 2 +- xmake/modules/package/manager/nimble/install_package.lua | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/xmake/modules/package/manager/dub/install_package.lua b/xmake/modules/package/manager/dub/install_package.lua index 84406af5f..d459bfd92 100644 --- a/xmake/modules/package/manager/dub/install_package.lua +++ b/xmake/modules/package/manager/dub/install_package.lua @@ -26,7 +26,7 @@ import("lib.detect.find_tool") -- install package -- -- @param name the package name, e.g. dub::log --- @param opt the options, e.g. { verbose = true, mode = "release", plat = , arch = , require_version = "x.x.x", buildhash = "xxxxxx"} +-- @param opt the options, e.g. { verbose = true, mode = "release", plat = , arch = , require_version = "x.x.x"} -- -- @return true or false -- diff --git a/xmake/modules/package/manager/nimble/install_package.lua b/xmake/modules/package/manager/nimble/install_package.lua index b5ba21438..326758e8c 100644 --- a/xmake/modules/package/manager/nimble/install_package.lua +++ b/xmake/modules/package/manager/nimble/install_package.lua @@ -25,8 +25,13 @@ import("lib.detect.find_tool") -- install package -- +-- e.g. +-- add_requires("nimble::zip") +-- add_requires("nimble::zip >0.3") +-- add_requires("nimble::zip 0.3.1") +-- -- @param name the package name, e.g. nimble::zip --- @param opt the options, e.g. { verbose = true, mode = "release", plat = , arch = , require_version = "x.x.x", buildhash = "xxxxxx"} +-- @param opt the options, e.g. { verbose = true, mode = "release", plat = , arch = , require_version = "x.x.x"} -- -- @return true or false -- -- cgit v1.3.1 From 3225b2b74981dc87130966b0b6a4011f5e0eff6c Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 27 Oct 2021 22:52:03 +0800 Subject: impl nimble find_package --- xmake/modules/package/manager/dub/find_package.lua | 2 +- .../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 -- cgit v1.3.1