summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-09-29 23:12:19 +0800
committerruki <[email protected]>2020-09-29 23:12:19 +0800
commit8190a5609f21bf5ea90bec0a11afb183190a8a50 (patch)
treee6f4d6bd1e9a82a3b71b953237746b758d0d1f7b
parent045c1524737d8f12da869e99a13316e640519c56 (diff)
improve add_requires to support pkg~tag
-rw-r--r--CHANGELOG.md2
-rwxr-xr-xtests/projects/package/multiconfig/src/main.c7
-rw-r--r--tests/projects/package/multiconfig/test.lua7
-rw-r--r--tests/projects/package/multiconfig/xmake.lua19
-rw-r--r--xmake/actions/require/impl/package.lua50
-rw-r--r--xmake/actions/require/impl/repository.lua7
-rw-r--r--xmake/core/package/package.lua22
7 files changed, 80 insertions, 34 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 74c92787d..9886bcd9f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@
### Change
* [#958](https://github.com/xmake-io/xmake/issues/958): Improve mingw platform to support llvm-mingw toolchain
+* Improve `add_requires("zlib~xxx")` to support for installing multi-packages at same time
### Bugs fixed
@@ -839,6 +840,7 @@
### 改进
* [#958](https://github.com/xmake-io/xmake/issues/958): 改进mingw平台,增加对 llvm-mingw 工具链的支持,以及 arm64/arm 架构的支持
+* 增加 `add_requires("zlib~xxx")` 模式使得能够支持同时安装带有多种配置的同一个包,作为独立包存在
### Bugs修复
diff --git a/tests/projects/package/multiconfig/src/main.c b/tests/projects/package/multiconfig/src/main.c
new file mode 100755
index 000000000..9ae580511
--- /dev/null
+++ b/tests/projects/package/multiconfig/src/main.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, char** argv)
+{
+ printf("hello world!\n");
+ return 0;
+}
diff --git a/tests/projects/package/multiconfig/test.lua b/tests/projects/package/multiconfig/test.lua
new file mode 100644
index 000000000..a4b905689
--- /dev/null
+++ b/tests/projects/package/multiconfig/test.lua
@@ -0,0 +1,7 @@
+-- main entry
+function main(t)
+
+ -- TODO
+ -- build project
+-- t:build()
+end
diff --git a/tests/projects/package/multiconfig/xmake.lua b/tests/projects/package/multiconfig/xmake.lua
new file mode 100644
index 000000000..48d64da13
--- /dev/null
+++ b/tests/projects/package/multiconfig/xmake.lua
@@ -0,0 +1,19 @@
+add_requires("zlib", {system = false})
+add_requires("zlib", {system = false}) -- test repeat requires
+add_requires("zlib~debug", {system = false, debug = true})
+add_requires("zlib~shared", {system = false, configs = {shared = true}, alias = "zlib_shared"})
+
+target("test1")
+ set_kind("binary")
+ add_files("src/*.c")
+ add_packages("zlib")
+
+target("test2")
+ set_kind("binary")
+ add_files("src/*.c")
+ add_packages("zlib#debug")
+
+target("test3")
+ set_kind("binary")
+ add_files("src/*.c")
+ add_packages("zlib_shared")
diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua
index 1de05bd49..eb36b1467 100644
--- a/xmake/actions/require/impl/package.lua
+++ b/xmake/actions/require/impl/package.lua
@@ -38,15 +38,34 @@ import("repository")
--
-- parse require string
--
--- add_requires("zlib")
--- add_requires("tbox >=1.5.1", "zlib >=1.2.11")
--- add_requires("zlib master")
--- add_requires("xmake-repo@tbox >=1.5.1")
--- add_requires("aaa_bbb_ccc >=1.5.1 <1.6.0", {optional = true, alias = "mypkg", debug = true})
--- add_requires("tbox", {config = {coroutine = true, abc = "xxx"}})
--- add_requires("xmake::xmake-repo@tbox >=1.5.1")
--- add_requires("conan::OpenSSL/1.0.2n@conan/stable")
--- add_requires("brew::pcre2/libpcre2-8 10.x", {alias = "pcre2"})
+-- basic
+-- - add_requires("zlib")
+--
+-- semver
+-- - add_requires("tbox >=1.5.1", "zlib >=1.2.11")
+--
+-- git branch/tag
+-- - add_requires("zlib master")
+--
+-- with the given repository
+-- - add_requires("xmake-repo@tbox >=1.5.1")
+--
+-- with the given configs
+-- - add_requires("aaa_bbb_ccc >=1.5.1 <1.6.0", {optional = true, alias = "mypkg", debug = true})
+-- - add_requires("tbox", {config = {coroutine = true, abc = "xxx"}})
+--
+-- with namespace and the 3rd package manager
+-- - add_requires("xmake::xmake-repo@tbox >=1.5.1")
+-- - add_requires("vcpkg::ffmpeg")
+-- - add_requires("conan::OpenSSL/1.0.2n@conan/stable")
+-- - add_requires("conan::openssl/1.1.1g") -- new
+-- - add_requires("brew::pcre2/libpcre2-8 10.x", {alias = "pcre2"})
+--
+-- clone as a standalone package with the different configs
+-- we can install and use these three packages at the same time.
+-- - add_requires("zlib")
+-- - add_requires("zlib~debug", {debug = true})
+-- - add_requires("zlib~shared", {configs = {shared = true}, alias = "zlib_shared"})
--
-- {system = nil/true/false}:
-- nil: get local or system packages
@@ -169,11 +188,8 @@ end
-- load package package from repositories
function _load_package_from_repository(packagename, reponame)
-
- -- get package directory from the given package name
local packagedir, repo = repository.packagedir(packagename, reponame)
if packagedir then
- -- load it
return core_package.load_from_repository(packagename, repo, packagedir)
end
end
@@ -359,8 +375,6 @@ function _load_package(packagename, requireinfo, opt)
-- save this package package to cache
packages[packagename] = package
_g._PACKAGES = packages
-
- -- ok
return package
end
@@ -710,19 +724,11 @@ end
-- load requires
function load_requires(requires, requires_extra, parentinfo)
-
- -- parse requires
local requireinfos = {}
for _, require_str in ipairs(requires) do
-
- -- parse require info
local packagename, requireinfo = _parse_require(require_str, requires_extra, parentinfo)
-
- -- save this required package
table.insert(requireinfos, {name = packagename, info = requireinfo})
end
-
- -- ok
return requireinfos
end
diff --git a/xmake/actions/require/impl/repository.lua b/xmake/actions/require/impl/repository.lua
index 917709cac..7e9af63b1 100644
--- a/xmake/actions/require/impl/repository.lua
+++ b/xmake/actions/require/impl/repository.lua
@@ -54,6 +54,11 @@ end
-- get package directory from repositories
function packagedir(packagename, reponame)
+ -- strip trailng ~tag, e.g. zlib~debug
+ if packagename:find('~', 1, true) then
+ packagename = packagename:gsub("~.+$", "")
+ end
+
-- get it from cache it
local packagedirs = _g._PACKAGEDIRS or {}
local foundir = packagedirs[packagename]
@@ -99,8 +104,6 @@ function searchdirs(name)
end
end
end
-
- -- ok?
return packageinfos
end
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 5eeb8fc69..87e4b87b1 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -1279,18 +1279,21 @@ function package.load_from_project(packagename, project)
return nil, errors
end
+ -- strip trailng ~tag, e.g. zlib~debug
+ local realname = packagename
+ if realname:find('~', 1, true) then
+ realname = realname:gsub("~.+$", "")
+ end
+
-- not found?
- if not packages[packagename] then
+ local packageinfo = packages[realname]
+ if not packageinfo then
return
end
-- new an instance
- local instance = _instance.new(packagename, packages[packagename])
-
- -- save instance to the cache
+ local instance = _instance.new(packagename, packageinfo)
package._PACKAGES[packagename] = instance
-
- -- ok
return instance
end
@@ -1334,8 +1337,9 @@ function package.load_from_repository(packagename, repo, packagedir, packagefile
-- get the package info
local packageinfo = nil
- for name, info in pairs(results) do
- packagename = name -- use the real package name in package() definition
+ for _, info in pairs(results) do
+ -- @note we cannot use the name of package(), because we need support `xxx~tag` for add_requires("zlib~xxx")
+ -- so we use `xxx~tag` as the real package
packageinfo = info
break
end
@@ -1353,8 +1357,6 @@ function package.load_from_repository(packagename, repo, packagedir, packagefile
-- save instance to the cache
package._PACKAGES[packagename] = instance
-
- -- ok
return instance
end