summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-10-08 17:35:46 +0800
committerruki <[email protected]>2022-10-08 17:35:46 +0800
commit35aa721e0eb879324e5f985a085d51ddfb251e05 (patch)
tree580b343139e30c802cb57e8a4ad2e4ddb2bf37ca
parentae84c24d057752b7d3fe2101020e97e697fdd70d (diff)
improve target:pkgs
-rw-r--r--xmake/core/project/target.lua30
1 files changed, 17 insertions, 13 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 22ddd267c..08fa6593c 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -876,24 +876,28 @@ function _instance:orderopts(opt)
end
-- get the enabled package
-function _instance:pkg(name)
- return self:pkgs()[name]
+function _instance:pkg(name, opt)
+ return self:pkgs(opt)[name]
end
-- get the enabled packages
-function _instance:pkgs()
-
- -- attempt to get it from cache first
- if self._PKGS_ENABLED then
- return self._PKGS_ENABLED
+function _instance:pkgs(opt)
+ opt = opt or {}
+ local cachekey = "pkgs"
+ if opt.public then
+ cachekey = cachekey .. "_public"
+ elseif opt.interface then
+ cachekey = cachekey .. "_interface"
end
-
- -- load packages if be enabled
- self._PKGS_ENABLED = {}
- for _, pkg in ipairs(self:orderpkgs()) do
- self._PKGS_ENABLED[pkg:name()] = pkg
+ local packages = self:_memcache():get(cachekey)
+ if not packages then
+ packages = {}
+ for _, pkg in ipairs(self:orderpkgs(opt)) do
+ packages[pkg:name()] = pkg
+ end
+ self:_memcache():set(cachekey, packages)
end
- return self._PKGS_ENABLED
+ return packages
end
-- get the required packages with {interface|public = ..}