summaryrefslogtreecommitdiff
path: root/xmake/modules/package/manager
diff options
context:
space:
mode:
authorruki <[email protected]>2020-07-25 23:22:11 +0800
committerruki <[email protected]>2020-07-25 23:22:11 +0800
commit9444d665d8ed9f2a23c265ffe6dacecda2485820 (patch)
tree9eaec0b8a4665fd7fe07a16c3ac82c390b5b8fb6 /xmake/modules/package/manager
parent56c0819b70ee17f8f8f1f5d27d2f905ee34bb726 (diff)
support dub package manager
Diffstat (limited to 'xmake/modules/package/manager')
-rw-r--r--xmake/modules/package/manager/dub/find_package.lua88
-rw-r--r--xmake/modules/package/manager/dub/install_package.lua72
-rw-r--r--xmake/modules/package/manager/go/install_package.lua6
3 files changed, 162 insertions, 4 deletions
diff --git a/xmake/modules/package/manager/dub/find_package.lua b/xmake/modules/package/manager/dub/find_package.lua
new file mode 100644
index 000000000..f608f73fe
--- /dev/null
+++ b/xmake/modules/package/manager/dub/find_package.lua
@@ -0,0 +1,88 @@
+--!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-2020, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file find_package.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.base.semver")
+import("core.base.json")
+import("core.project.config")
+import("core.project.target")
+import("lib.detect.find_tool")
+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")
+--
+function main(name, opt)
+
+ -- find dub
+ local dub = find_tool("dub")
+ if not dub then
+ raise("dub not found!")
+ end
+
+ -- get the library pattern
+ local libpattern = (opt.plat == "windows") and "*.lib" or "*.a"
+
+ -- find package
+ local result
+ local pkglist = os.iorunv(dub.program, {"list"})
+ if pkglist then
+ local pkgdir
+ for _, line in ipairs(pkglist:split('\n', {plain = true})) do
+ local pkginfo = line:split(':', {plain = true})
+ if #pkginfo == 2 then
+ local pkgkey = pkginfo[1]:trim():split(' ', {plain = true})
+ local pkgpath = pkginfo[2]:trim()
+ if #pkgkey == 2 then
+ local pkgname = pkgkey[1]:trim()
+ local pkgversion = pkgkey[2]:trim()
+ if pkgname == name and find_file(libpattern, pkgpath) and
+ (not opt.version or opt.version == "latest" or opt.version == "master" or semver.satisfies(pkgversion, opt.version)) then
+ pkgdir = pkgpath
+ break
+ end
+ end
+ end
+ end
+ if pkgdir then
+ local links = {}
+ for _, libraryfile in ipairs(os.files(path.join(pkgdir, libpattern))) do
+ table.insert(links, target.linkname(path.filename(libraryfile)))
+ end
+ local includedirs = {}
+ local dubjson = path.join(pkgdir, "dub.json")
+ if os.isfile(dubjson) then
+ dubjson = json.loadfile(dubjson)
+ if dubjson and dubjson.importPaths then
+ for _, importPath in ipairs(dubjson.importPaths) do
+ table.insert(includedirs, path.join(pkgdir, importPath))
+ end
+ end
+ end
+ if #includedirs > 0 and #links > 0 then
+ result = {version = opt.version, links = links, linkdirs = pkgdir, includedirs = includedirs}
+ end
+ end
+ end
+ return result
+end
diff --git a/xmake/modules/package/manager/dub/install_package.lua b/xmake/modules/package/manager/dub/install_package.lua
new file mode 100644
index 000000000..352fdae23
--- /dev/null
+++ b/xmake/modules/package/manager/dub/install_package.lua
@@ -0,0 +1,72 @@
+--!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-2020, 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. dub::log
+-- @param opt the options, e.g. { verbose = true, mode = "release", plat = , arch = , version = "x.x.x", buildhash = "xxxxxx"}
+--
+-- @return true or false
+--
+function main(name, opt)
+
+ -- find dub
+ local dub = find_tool("dub")
+ if not dub then
+ raise("dub not found!")
+ end
+
+ -- fetch the given package
+ local argv = {"fetch", name}
+ if option.get("verbose") then
+ table.insert(argv, "-v")
+ end
+ if opt.version and opt.version ~= "latest" and opt.version ~= "master" then
+ table.insert(argv, "--version=" .. opt.version)
+ end
+ os.vrunv(dub.program, argv)
+
+ -- build the given package
+ argv = {"build", name, "-y"}
+ if opt.mode == "debug" then
+ table.insert(argv, "--build=debug")
+ else
+ table.insert(argv, "--build=release")
+ end
+ if option.get("verbose") then
+ table.insert(argv, "-v")
+ end
+ local archs = {x86_64 = "x86_64",
+ x64 = "x86_64",
+ i386 = "x86",
+ x86 = "x86"}
+ local arch = archs[opt.arch]
+ if arch then
+ table.insert(argv, "--arch=" .. arch)
+ else
+ raise("cannot install package(%s) for arch(%s)!", name, opt.arch)
+ end
+ os.vrunv(dub.program, argv)
+end
diff --git a/xmake/modules/package/manager/go/install_package.lua b/xmake/modules/package/manager/go/install_package.lua
index e8b8a1d37..e6caeae4d 100644
--- a/xmake/modules/package/manager/go/install_package.lua
+++ b/xmake/modules/package/manager/go/install_package.lua
@@ -61,10 +61,8 @@ function main(name, opt)
end
-- get plat and arch
- local plat = opt.plat or config.plat() or os.host()
- local arch = opt.arch or config.arch() or os.arch()
- local goos = goenv.GOOS(plat)
- local goarch = goenv.GOARCH(arch)
+ local goos = goenv.GOOS(opt.plat)
+ local goarch = goenv.GOARCH(opt.arch)
-- get go package to cachedir/pkg/${goos}_${goarch}/github.com/xxx/*.a
local cachedir = _go_get_cachedir(name, opt)