summaryrefslogtreecommitdiff
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
parent56c0819b70ee17f8f8f1f5d27d2f905ee34bb726 (diff)
support dub package manager
-rw-r--r--CHANGELOG.md4
-rw-r--r--tests/projects/dlang/console_with_pkgs/src/main.d10
-rw-r--r--tests/projects/dlang/console_with_pkgs/xmake.lua7
-rw-r--r--xmake/languages/dlang/xmake.lua1
-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
7 files changed, 183 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bd9a57861..ea4020b51 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,8 @@
* [#887](https://github.com/xmake-io/xmake/pull/887): Support zig compiler
* [#893](https://github.com/xmake-io/xmake/issues/893): Add json module
* [#898](https://github.com/xmake-io/xmake/issues/898): Support cross-compilation for golang
+* [#275](https://github.com/xmake-io/xmake/issues/275): Support go package manager to install go packages
+* [#581](https://github.com/xmake-io/xmake/issues/581): Support dub package manager to install dlang packages
## v2.3.5
@@ -786,6 +788,8 @@
* [#887](https://github.com/xmake-io/xmake/pull/887): 支持zig编译器
* [#893](https://github.com/xmake-io/xmake/issues/893): 添加json模块
* [#898](https://github.com/xmake-io/xmake/issues/898): 改进golang项目构建,支持交叉编译
+* [#275](https://github.com/xmake-io/xmake/issues/275): 支持go包管理器去集成第三方go依赖包
+* [#581](https://github.com/xmake-io/xmake/issues/581): 支持dub包管理器去集成第三方dlang依赖包
## v2.3.5
diff --git a/tests/projects/dlang/console_with_pkgs/src/main.d b/tests/projects/dlang/console_with_pkgs/src/main.d
index 524c4f94c..39faa328e 100644
--- a/tests/projects/dlang/console_with_pkgs/src/main.d
+++ b/tests/projects/dlang/console_with_pkgs/src/main.d
@@ -1,6 +1,14 @@
import std.stdio;
+import std.datetime;
+import util.log;
+import dateparser;
void main()
{
- writeln("hello world!");
+ log = Log(stderrLogger, stdoutLogger(LogLevel.info), fileLogger("log"));
+ log.info("hello xmake");
+
+ assert(parse("2003-09-25") == SysTime(DateTime(2003, 9, 25)));
+ assert(parse("09/25/2003") == SysTime(DateTime(2003, 9, 25)));
+ assert(parse("Sep 2003") == SysTime(DateTime(2003, 9, 1)));
}
diff --git a/tests/projects/dlang/console_with_pkgs/xmake.lua b/tests/projects/dlang/console_with_pkgs/xmake.lua
index b1b8e0bfb..89592ecd5 100644
--- a/tests/projects/dlang/console_with_pkgs/xmake.lua
+++ b/tests/projects/dlang/console_with_pkgs/xmake.lua
@@ -1,6 +1,13 @@
add_rules("mode.debug", "mode.release")
+add_requires("dub::log 0.4.3", {alias = "log"})
+add_requires("dub::dateparser", {alias = "dateparser"})
+add_requires("dub::emsi_containers", {alias = "emsi_containers"})
+add_requires("dub::stdx-allocator", {alias = "stdx-allocator"})
+add_requires("dub::mir-core", {alias = "mir-core"})
+
target("test")
set_kind("binary")
add_files("src/*.d")
+ add_packages("log", "dateparser", "emsi_containers", "stdx-allocator", "mir-core")
diff --git a/xmake/languages/dlang/xmake.lua b/xmake/languages/dlang/xmake.lua
index 2bc283286..4653a4b4c 100644
--- a/xmake/languages/dlang/xmake.lua
+++ b/xmake/languages/dlang/xmake.lua
@@ -59,6 +59,7 @@ language("dlang")
, "target.optimize:check"
, "target.vectorexts:check"
, "target.includedirs"
+ , "option.includedirs"
, "toolchain.includedirs"
}
, binary =
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)