diff options
| author | ruki <[email protected]> | 2022-01-25 22:36:56 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-01-25 22:36:56 +0800 |
| commit | 88549acb5e2e3e409b72ff876e32c589c3ea851f (patch) | |
| tree | 6042e8ce13436411cc9f21586c902bbdd5be7c3a | |
| parent | db60a26fa1334c1175c8a2a549a67b827a01978a (diff) | |
support base package
| -rwxr-xr-x | tests/projects/package/inherit_base/src/main.c | 7 | ||||
| -rw-r--r-- | tests/projects/package/inherit_base/test.lua | 10 | ||||
| -rw-r--r-- | tests/projects/package/inherit_base/xmake.lua | 11 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 19 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/package.lua | 17 |
5 files changed, 60 insertions, 4 deletions
diff --git a/tests/projects/package/inherit_base/src/main.c b/tests/projects/package/inherit_base/src/main.c new file mode 100755 index 000000000..9ae580511 --- /dev/null +++ b/tests/projects/package/inherit_base/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/inherit_base/test.lua b/tests/projects/package/inherit_base/test.lua new file mode 100644 index 000000000..a6690754b --- /dev/null +++ b/tests/projects/package/inherit_base/test.lua @@ -0,0 +1,10 @@ +function main(t) + -- freebsd ci is slower + if is_host("bsd") then + return + end + -- only for x86/x64, because it will take too long time on ci with arm/mips + if os.subarch():startswith("x") or os.subarch() == "i386" then + t:build() + end +end diff --git a/tests/projects/package/inherit_base/xmake.lua b/tests/projects/package/inherit_base/xmake.lua new file mode 100644 index 000000000..3eea30f03 --- /dev/null +++ b/tests/projects/package/inherit_base/xmake.lua @@ -0,0 +1,11 @@ +package("myzlib") + set_base("zlib") + set_urls("https://github.com/madler/zlib.git") +package_end() + +add_requires("myzlib", {system = false, alias = "zlib"}) + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("zlib") diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 379d1ddea..73b2731dd 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -68,11 +68,17 @@ function _instance:type() return "package" end --- get the package configure -function _instance:get(name) +-- get the base package +function _instance:base() + return self._BASE +end - -- get it from info first +-- get the package configuration +function _instance:get(name) local value = self._INFO:get(name) + if value == nil and self:base() then + value = self:base():get(name) + end if value ~= nil then return value end @@ -90,7 +96,11 @@ end -- get the extra configuration function _instance:extraconf(name, item, key) - return self._INFO:extraconf(name, item, key) + local conf = self._INFO:extraconf(name, item, key) + if conf == nil and self:base() then + conf = self:base():extraconf(name, item, key) + end + return conf end -- set the extra configuration @@ -1811,6 +1821,7 @@ function package.apis() , "package.set_kind" , "package.set_plat" -- deprecated , "package.set_arch" -- deprecated + , "package.set_base" , "package.set_license" , "package.set_homepage" , "package.set_description" diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 07e2abc34..3534723d2 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -217,6 +217,17 @@ function _load_package_from_repository(packagename, opt) end end +-- load package package from base +function _load_package_from_base(package, basename, opt) + local package_base = _load_package_from_project(basename) + if not package_base then + package_base = _load_package_from_repository(basename, opt) + end + if package_base then + package._BASE = package_base + end +end + -- has locked requires? function _has_locked_requires(opt) opt = opt or {} @@ -700,6 +711,12 @@ function _load_package(packagename, requireinfo, opt) end end + -- load base package + if package and package:get("base") then + _load_package_from_base(package, package:get("base", { + name = requireinfo.reponame, locked_repo = locked_requireinfo and locked_requireinfo.repo})) + end + -- load package from system local system = requireinfo.system if system == nil then |
