summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2021-10-27 11:48:59 +0800
committerGitHub <[email protected]>2021-10-27 11:48:59 +0800
commit9d80ed11e7b8ea3604c85aa3d5a8d42dd591ea02 (patch)
tree7f2a05ec41dc3a5efaba1cd097cbd8f5a971426d /xmake/modules
parent71217ef2ce95a70aad0fd1cad05eb462b4612a5b (diff)
parent3225b2b74981dc87130966b0b6a4011f5e0eff6c (diff)
Merge pull request #1778 from xmake-io/nimble
Add Nimble package support
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/detect/tools/find_nimble.lua52
-rw-r--r--xmake/modules/package/manager/dub/find_package.lua2
-rw-r--r--xmake/modules/package/manager/dub/install_package.lua2
-rw-r--r--xmake/modules/package/manager/nimble/find_package.lua67
-rw-r--r--xmake/modules/package/manager/nimble/install_package.lua58
-rw-r--r--xmake/modules/private/action/require/impl/package.lua2
6 files changed, 180 insertions, 3 deletions
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
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/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/find_package.lua b/xmake/modules/package/manager/nimble/find_package.lua
new file mode 100644
index 000000000..c39d6ed34
--- /dev/null
+++ b/xmake/modules/package/manager/nimble/find_package.lua
@@ -0,0 +1,67 @@
+--!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.base.semver")
+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, require_version = "1.12.x")
+--
+function main(name, opt)
+
+ -- find nimble
+ local nimble = find_tool("nimble")
+ if not nimble then
+ 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
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..326758e8c
--- /dev/null
+++ b/xmake/modules/package/manager/nimble/install_package.lua
@@ -0,0 +1,58 @@
+--!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
+--
+-- 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"}
+--
+-- @return true or false
+--
+function main(name, opt)
+
+ -- find nimble
+ local nimble = find_tool("nimble")
+ if not nimble then
+ 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