summaryrefslogtreecommitdiff
path: root/xmake
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 /xmake
parent045c1524737d8f12da869e99a13316e640519c56 (diff)
improve add_requires to support pkg~tag
Diffstat (limited to 'xmake')
-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
3 files changed, 45 insertions, 34 deletions
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